All files / src/rules no_macros.ts

100% Statements 51/51
100% Branches 7/7
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 51 521x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11087x 11087x 11087x 11087x 11087x 43696x 43696x 43696x 43696x 43696x 43696x 43696x 43696x 43696x 43696x 43696x 43696x 43696x 43696x 11087x 11087x 10568x 10568x 11087x 11087x 244x 244x 11087x 11087x 267x 267x 267x 1487x 7x 7x 1487x 267x 267x 267x 11087x 11087x  
import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import * as Statements from "../abap/2_statements/statements";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class NoMacrosConf extends BasicRuleConfig {
}
 
export class NoMacros extends ABAPRule {
 
  private conf = new NoMacrosConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "no_macros",
      title: "No macros",
      shortDescription: `Checks that macros are not used`,
      extendedInformation: `Macros reduce readability and are difficult to debug, use methods or form routines instead.
 
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenmacros_guidl.htm`,
      tags: [RuleTag.SingleFile],
      badExample: `DEFINE _macro.
  WRITE 'hello'.
END-OF-DEFINITION.`,
      goodExample: `WRITE 'hello'.`,
    };
  }
 
  public getConfig(): NoMacrosConf {
    return this.conf;
  }
 
  public setConfig(conf: NoMacrosConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    for (const stat of file.getStatements()) {
      if (stat.get() instanceof Statements.Define) {
        issues.push(Issue.atStatement(file, stat, "Do not define macros", this.getMetadata().key, this.conf.severity));
      }
    }
 
    return issues;
  }
 
}