All files / src/rules check_include.ts

96.87% Statements 62/64
87.5% Branches 14/16
100% Functions 7/7
96.87% Lines 62/64

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641x 1x 1x 1x 1x 1x 1x 1x 1x 1x 27350x 27350x 27350x 1x 13684x 13684x 13684x 13684x 13684x 13684x 40852x 40852x 40852x 40852x 40852x 40852x 40852x 40852x 40852x 40852x 40852x 40852x 13684x 13684x 13660x 13660x 13684x 13684x 240x 240x 13684x 13684x 252x 252x 252x 252x 13684x 13684x 331x 71x 71x 260x 331x     260x 260x 331x 269x 269x 260x 260x 13684x 13684x
import {IRegistry} from "../_iregistry";
import {BasicRuleConfig} from "./_basic_rule_config";
import {ABAPObject} from "../objects/_abap_object";
import {IncludeGraph} from "../utils/include_graph";
import {IRule, IRuleMetadata, RuleTag} from "./_irule";
import {Issue} from "../issue";
import {IObject} from "../objects/_iobject";
import {Program} from "../objects";
import {Severity} from "../severity";
 
export class CheckIncludeConf extends BasicRuleConfig {
  public allowUnused?: boolean = false;
}
 
export class CheckInclude implements IRule {
  private reg: IRegistry;
  private conf = new CheckIncludeConf();
  private graph: IncludeGraph;
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "check_include",
      title: "Check INCLUDEs",
      shortDescription: `Checks INCLUDE statements`,
      extendedInformation: `
* Reports unused includes
* Errors if the includes are not found
* Error if including a main program
* Skips ZX* includes`,
      tags: [RuleTag.Syntax],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: CheckIncludeConf) {
    this.conf = conf;
  }
 
  public initialize(reg: IRegistry) {
    this.reg = reg;
    this.graph = new IncludeGraph(this.reg, this.getConfig().severity || Severity.Error, this.getConfig().allowUnused || false);
    return this;
  }
 
  public run(obj: IObject): readonly Issue[] {
    if (!(obj instanceof ABAPObject)) {
      return [];
    }
 
    if (obj instanceof Program && obj.isInclude() === true && obj.getName().startsWith("ZX")) {
      return [];
    }
 
    let ret: Issue[] = [];
    for (const file of obj.getABAPFiles()) {
      ret = ret.concat(this.graph.getIssuesFile(file));
    }
    return ret;
  }
 
}