All files / src/rules check_syntax.ts

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

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 591x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10343x 10343x 10343x 10343x 10343x 30854x 30854x 30854x 30854x 30854x 30854x 30854x 10343x 10343x 9829x 9829x 10343x 10343x 243x 243x 243x 10343x 10343x 242x 242x 10343x 10343x 309x 62x 62x 247x 247x 247x 247x 247x 309x 1x 1x 1x 1x 1x 1x 247x 247x 247x 10343x 10343x
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";
 
export class CheckSyntaxConf extends BasicRuleConfig {
}
 
export class CheckSyntax implements IRule {
  private reg: IRegistry;
  private conf = new CheckSyntaxConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "check_syntax",
      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;
  }
 
}