All files / src/rules check_syntax.ts

100% Statements 60/60
100% Branches 11/11
100% Functions 6/6
100% Lines 60/60

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 601x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 17238x 17238x 17238x 17238x 17238x 84862x 84862x 84862x 84862x 84862x 84862x 84862x 17238x 17238x 16651x 16651x 17238x 17238x 278x 278x 278x 17238x 17238x 277x 277x 17238x 17238x 375x 84x 84x 291x 291x 291x 291x 291x 375x 1x 1x 1x 1x 1x 1x 291x 291x 291x 17238x 17238x
import {IRegistry} from "../_iregistry";
import {SyntaxLogic} from "../abap/5_syntax/syntax";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IObject} from "../objects/_iobject";
import {ABAPObject} from "../objects/_abap_object";
import {Issue} from "../issue";
import {RuleTag, IRuleMetadata, IRule} from "./_irule";
import {Severity} from "../severity";
import {CheckSyntaxKey} from "../abap/5_syntax/_syntax_input";
 
export class CheckSyntaxConf extends BasicRuleConfig {
}
 
export class CheckSyntax implements IRule {
  private reg: IRegistry;
  private conf = new CheckSyntaxConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: CheckSyntaxKey,
      title: "Check syntax",
      shortDescription: `Enables syntax check and variable resolution`,
      tags: [RuleTag.Syntax],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public initialize(reg: IRegistry) {
    this.reg = reg;
    return this;
  }
 
  public setConfig(conf: CheckSyntaxConf) {
    this.conf = conf;
  }
 
  public run(obj: IObject): Issue[] {
    if (!(obj instanceof ABAPObject)) {
      return [];
    }
 
    const issues = new SyntaxLogic(this.reg, obj).run().issues;
 
// the syntax logic does not know the rule severity when its run
    if (this.conf.severity
        && this.conf.severity !== Severity.Error) {
      issues.forEach((value: Issue, index: number) => {
        const data = value.getData();
        data.severity = this.conf.severity!;
        issues[index] = new Issue(data);
      });
    }
 
    return issues;
  }
 
}