All files / src/rules prefer_corresponding.ts

96.29% Statements 52/54
88.88% Branches 8/9
100% Functions 5/5
96.29% Lines 52/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 11280x 11280x 11280x 11280x 33683x 33683x 33683x 33683x 33683x 33683x 33683x 33683x 33683x 33683x 33683x 11280x 11280x 10791x 10791x 11280x 11280x 229x 229x 11280x 11280x 243x 243x 243x     243x 243x 243x 1371x 1371x 2x 2x 1371x 243x 243x 243x 11280x 11280x
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 {Version} from "../version";
 
export class PreferCorrespondingConf extends BasicRuleConfig {
}
 
export class PreferCorresponding extends ABAPRule {
  private conf = new PreferCorrespondingConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "prefer_corresponding",
      title: "Prefer corresponding( ) to MOVE-CORRESPONDING",
      shortDescription: `Prefer corresponding( ) to MOVE-CORRESPONDING, from v740sp05 and up`,
      extendedInformation:
        `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#prefer-functional-to-procedural-language-constructs`,
      tags: [RuleTag.SingleFile, RuleTag.Upport, RuleTag.Styleguide],
      badExample: `MOVE-CORRESPONDING foo TO bar.`,
      goodExample: `bar = CORRESPONDING #( foo ).`,
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: PreferCorrespondingConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    if (this.reg.getConfig().getVersion() < Version.v740sp05) {
      return issues;
    }
 
    const message = "Use CORRESPONDING type( ... ) instead of MOVE-CORRESPONDING";
    for (const stat of file.getStatements()) {
      if (stat.get() instanceof Statements.MoveCorresponding
          && stat.getChildren().length === 7) {
        issues.push(Issue.atStatement(file, stat, message, this.getMetadata().key, this.conf.severity));
      }
    }
 
    return issues;
  }
 
}