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 11460x 11460x 11460x 11460x 34239x 34239x 34239x 34239x 34239x 34239x 34239x 34239x 34239x 34239x 34239x 11460x 11460x 10935x 10935x 11460x 11460x 247x 247x 11460x 11460x 270x 270x 270x     270x 270x 270x 1529x 1529x 2x 2x 1529x 270x 270x 270x 11460x 11460x
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 {Release, releaseAtLeast} 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 (!releaseAtLeast(this.reg.getConfig().getRelease(), Release.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;
  }
 
}