All files / src/rules no_external_form_calls.ts

100% Statements 54/54
100% Branches 11/11
100% Functions 5/5
100% Lines 54/54

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 541x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8922x 8922x 8922x 8922x 8922x 349040x 349040x 349040x 349040x 349040x 349040x 349040x 349040x 349040x 349040x 8922x 8922x 8485x 8485x 8922x 8922x 202x 202x 8922x 8922x 219x 219x 219x 219x 12x 12x 207x 219x 3x 2x 2x 2x 3x 207x 207x 207x 8922x 8922x
import * as Statements from "../abap/2_statements/statements";
import * as Expressions from "../abap/2_statements/expressions";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {Issue} from "../issue";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class NoExternalFormCallsConf extends BasicRuleConfig {
}
 
export class NoExternalFormCalls extends ABAPRule {
 
  private conf = new NoExternalFormCallsConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "no_external_form_calls",
      title: "No external FORM calls",
      shortDescription: `Detect external form calls`,
      badExample: `PERFORM foo IN PROGRAM bar.
 
PERFORM foo(bar).`,
      tags: [RuleTag.SingleFile],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: NoExternalFormCallsConf): void {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    const stru = file.getStructure();
    if (stru === undefined) {
      return issues; // parser error
    }
 
    for (const p of stru.findAllStatements(Statements.Perform)) {
      if (p.findDirectExpression(Expressions.IncludeName) || p.findDirectTokenByText("PROGRAM")) {
        const message = "No external FORM calls";
        issues.push(Issue.atStatement(file, p, message, this.getMetadata().key, this.conf.severity));
      }
    }
 
    return issues;
  }
 
}