All files / src/rules pragma_placement.ts

96.49% Statements 55/57
90% Branches 9/10
100% Functions 5/5
96.49% Lines 55/57

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 571x 1x 1x 1x 1x 1x 1x 1x 1x 7673x 7673x 7673x 7673x 22874x 22874x 22874x 22874x 22874x 22874x 22874x 22874x 22874x 7673x 7673x 7364x 7364x 7673x 7673x 140x 140x 7673x 7673x 155x 155x 155x 851x 849x 849x 2x 2x 2x 2x     2x 1x 1x 1x 1x 1x 2x 2x 155x 155x 155x 7673x 7673x
import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {RuleTag, IRuleMetadata} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class PragmaPlacementConf extends BasicRuleConfig {
}
 
export class PragmaPlacement extends ABAPRule {
  private conf = new PragmaPlacementConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "pragma_placement",
      title: "Pragma Placement",
      shortDescription: `Place pragmas at end of statements`,
      tags: [RuleTag.SingleFile],
      badExample: `DATA field ##NO_TEXT TYPE i.`,
      goodExample: `DATA field TYPE i ##NO_TEXT.`,
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: PragmaPlacementConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    for (const s of file.getStatements()) {
      if (s.getPragmas().length === 0) {
        continue;
      }
 
      for (const p of s.getPragmas()) {
        const children = s.getChildren();
        if (children.length === 1) {
          break; // empty statement with pragma
        }
        if (children[children.length - 2].getLastToken().getStart().isAfter(p.getStart())) {
          const message = "Place pragma at end of statement";
          const issue = Issue.atStatement(file, s, message, this.getMetadata().key, this.conf.severity);
          issues.push(issue);
          continue; // max one finding per statement
        }
      }
    }
 
    return issues;
  }
 
}