All files / src/rules no_chained_assignment.ts

100% Statements 55/55
100% Branches 9/9
100% Functions 5/5
100% Lines 55/55

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 10998x 10998x 10998x 10998x 10998x 32805x 32805x 32805x 32805x 32805x 32805x 32805x 32805x 32805x 32805x 32805x 10998x 10998x 10447x 10447x 10998x 10998x 260x 260x 10998x 10998x 273x 273x 273x 1539x 1524x 1524x 15x 1539x 1x 1x 1x 1x 1539x 273x 273x 273x 10998x 10998x  
import * as Expressions from "../abap/2_statements/expressions";
import * as Statements from "../abap/2_statements/statements";
import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class NoChainedAssignmentConf extends BasicRuleConfig {
}
 
export class NoChainedAssignment extends ABAPRule {
 
  private conf = new NoChainedAssignmentConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "no_chained_assignment",
      title: "No chained assignment",
      shortDescription: `Find chained assingments and reports issues`,
      extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-chain-assignments`,
      tags: [RuleTag.SingleFile, RuleTag.Styleguide],
      badExample: `var1 = var2 = var3.`,
      goodExample: `var2 = var3.
var1 = var2.`,
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: NoChainedAssignmentConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    for (const s of file.getStatements()) {
      if (!(s.get() instanceof Statements.Move)) {
        continue;
      }
 
      if (s.findDirectExpressions(Expressions.Target).length >= 2) {
        const message = "No chained assignment";
        const issue = Issue.atStatement(file, s, message, this.getMetadata().key);
        issues.push(issue);
      }
    }
 
    return issues;
  }
 
}