All files / src/rules max_one_method_parameter_per_line.ts

100% Statements 65/65
100% Branches 14/14
100% Functions 5/5
100% Lines 65/65

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 56 57 58 59 60 61 62 63 64 651x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10327x 10327x 10327x 10327x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 10327x 10327x 9814x 9814x 10327x 10327x 241x 241x 10327x 10327x 257x 257x 257x 55x 55x 25x 20x 20x 20x 5x 25x 1x 1x 1x 5x 5x 5x 55x 257x 257x 257x 10327x 10327x
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";
import {ExpressionNode} from "../abap/nodes/expression_node";
 
export class MaxOneMethodParameterPerLineConf extends BasicRuleConfig {
}
 
export class MaxOneMethodParameterPerLine extends ABAPRule {
  private conf = new MaxOneMethodParameterPerLineConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "max_one_method_parameter_per_line",
      title: "Max one method parameter definition per line",
      shortDescription: `Keep max one method parameter description per line`,
      tags: [RuleTag.SingleFile, RuleTag.Whitespace],
      badExample: `
METHODS apps_scope_token
  IMPORTING
    body TYPE bodyapps_scope_token client_id TYPE str.`,
      goodExample: `
METHODS apps_scope_token
  IMPORTING
    body      TYPE bodyapps_scope_token
    client_id TYPE str.`,
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: MaxOneMethodParameterPerLineConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    for (const statement of file.getStructure()?.findAllStatements(Statements.MethodDef) || []) {
      let prev: ExpressionNode | undefined = undefined;
      for (const p of statement.findAllExpressions(Expressions.MethodParam)) {
        if (prev === undefined) {
          prev = p;
          continue;
        }
 
        if (prev.getFirstToken().getStart().getRow() === p.getFirstToken().getStart().getRow()) {
          const issue = Issue.atToken(file, prev.getFirstToken(), this.getMetadata().title, this.getMetadata().key, this.conf.severity);
          issues.push(issue);
        }
 
        prev = p;
      }
    }
 
    return issues;
  }
 
}