All files / src/rules type_form_parameters.ts

100% Statements 61/61
100% Branches 12/12
100% Functions 6/6
100% Lines 61/61

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 621x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10423x 10423x 10423x 10423x 10423x 31099x 31099x 31099x 31099x 31099x 31099x 31099x 31099x 31099x 31099x 31099x 10423x 10423x 3x 3x 10423x 10423x 9906x 9906x 10423x 10423x 243x 243x 10423x 10423x 260x 260x 260x 260x 63x 63x 197x 260x 5x 3x 3x 3x 3x 5x 197x 197x 197x 10423x 10423x  
import {Issue} from "../issue";
import {Class} from "../objects";
import {BasicRuleConfig} from "./_basic_rule_config";
import {ABAPRule} from "./_abap_rule";
import * as Expressions from "../abap/2_statements/expressions";
import {ABAPObject} from "../objects/_abap_object";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class TypeFormParametersConf extends BasicRuleConfig {
}
 
export class TypeFormParameters extends ABAPRule {
 
  private conf = new TypeFormParametersConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "type_form_parameters",
      title: "Type FORM parameters",
      shortDescription: `Checks for untyped FORM parameters`,
      tags: [RuleTag.SingleFile],
      badExample: `FORM foo USING bar.
ENDFORM.`,
      goodExample: `FORM foo USING bar TYPE string.
ENDFORM.`,
    };
  }
 
  private getDescription(parameterName: string): string {
    return "Add TYPE for FORM parameter \"" + parameterName + "\"";
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: TypeFormParametersConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile, obj: ABAPObject) {
    const ret: Issue[] = [];
 
    const stru = file.getStructure();
    if (obj instanceof Class || stru === undefined) {
      return ret;
    }
 
    for (const formparam of stru.findAllExpressions(Expressions.FormParam)) {
      if (formparam.findFirstExpression(Expressions.FormParamType) === undefined) {
        const token = formparam.getFirstToken();
        const issue = Issue.atToken(file, token, this.getDescription(token.getStr()), this.getMetadata().key, this.conf.severity);
        ret.push(issue);
      }
    }
 
    return ret;
  }
 
}