All files / src/rules no_aliases.ts

100% Statements 51/51
100% Branches 10/10
100% Functions 5/5
100% Lines 51/51

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 511x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11513x 11513x 11513x 11513x 34393x 34393x 34393x 34393x 34393x 34393x 34393x 34393x 11513x 11513x 11012x 11012x 11513x 11513x 235x 235x 11513x 11513x 249x 249x 249x 249x 249x 1395x 12x 1x 1x 11x 11x 11x 1395x 249x 249x 249x 11513x 11513x
import {Issue} from "../issue";
import {BasicRuleConfig} from "./_basic_rule_config";
import {ABAPRule} from "./_abap_rule";
import * as Statements from "../abap/2_statements/statements";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
import {StatementNode} from "../abap/nodes";
 
export class NoAliasesConf extends BasicRuleConfig {
}
 
export class NoAliases extends ABAPRule {
  private conf = new NoAliasesConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "no_aliases",
      title: "No ALIASES",
      shortDescription: `Detects use of the ALIAS statement`,
      extendedInformation: `Only one issue is reported for chained statements`,
      tags: [RuleTag.SingleFile],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: NoAliasesConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    const message = "Do not use ALIASES";
    let prev: StatementNode | undefined = undefined;
    for (const stat of file.getStatements()) {
      if (stat.get() instanceof Statements.Aliases) {
        if (prev && prev.getColon() === stat.getColon()) {
          continue;
        }
        issues.push(Issue.atStatement(file, stat, message, this.getMetadata().key, this.conf.severity));
        prev = stat;
      }
    }
 
    return issues;
  }
 
}