All files / src/rules identical_move.ts

100% Statements 56/56
81.81% Branches 9/11
100% Functions 5/5
100% Lines 56/56

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 54 55 561x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14684x 14684x 14684x 14684x 14684x 156869x 156869x 156869x 156869x 156869x 156869x 156869x 156869x 156869x 156869x 156869x 14684x 14684x 14120x 14120x 14684x 14684x 264x 264x 14684x 14684x 294x 294x 294x 1662x 1662x 19x 19x 19x 2x 2x 2x 19x 1662x 294x 294x 294x 14684x 14684x
import * as Statements from "../abap/2_statements/statements";
import * as Expressions from "../abap/2_statements/expressions";
import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IObject} from "../objects/_iobject";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class IdenticalMoveConf extends BasicRuleConfig {
}
 
export class IdenticalMove extends ABAPRule {
 
  private conf = new IdenticalMoveConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "identical_move",
      title: "Identical move",
      shortDescription: `Moving the same value from left to right or right to left is redundant.`,
      tags: [RuleTag.SingleFile],
      badExample: `DATA lv_value TYPE i.
lv_value = lv_value.`,
      goodExample: `DATA lv_value TYPE i.
lv_value = 5.`,
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: IdenticalMoveConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile, _obj: IObject) {
    const issues: Issue[] = [];
 
    for (const statement of file.getStatements()) {
      const statementType = statement.get();
      if (statementType instanceof Statements.Move) {
        const source = statement.findDirectExpression(Expressions.Source)?.concatTokens().toUpperCase();
        const target = statement.findDirectExpression(Expressions.Target)?.concatTokens().toUpperCase();
        if (source === target && source !== undefined) {
          const message = `Identical MOVE from "${source}" to "${target}"`;
          issues.push(Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
        }
      }
    }
 
    return issues;
  }
 
}