All files / src/rules method_overwrites_builtin.ts

100% Statements 23/23
100% Branches 2/2
100% Functions 5/5
100% Lines 23/23

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   7265x     21662x                   7008x       114x       132x 132x   132x 75x   132x 28x     132x 132x 33x 3x 3x       132x    
import {ABAPFile, Issue} from "..";
import {InfoMethodDefinition} from "../abap/4_file_information/_abap_file_information";
import {BuiltIn} from "../abap/5_syntax/_builtin";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IRuleMetadata, RuleTag} from "./_irule";
 
export class MethodOverwritesBuiltInConf extends BasicRuleConfig {
}
 
export class MethodOverwritesBuiltIn extends ABAPRule {
 
  private conf = new MethodOverwritesBuiltInConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "method_overwrites_builtin",
      title: "Method name overwrites builtin function",
      shortDescription: `Checks Method names that overwrite builtin SAP functions`,
      extendedInformation: `https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-us/abenbuilt_in_functions_overview.htm`,
      tags: [RuleTag.Naming, RuleTag.SingleFile],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: MethodOverwritesBuiltInConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile): Issue[] {
    const issues: Issue[] = [];
    let methods: InfoMethodDefinition[] = [];
 
    for (const classDef of file.getInfo().listClassDefinitions()) {
      methods = methods.concat(classDef.methods);
    }
    for (const intfDef of file.getInfo().listInterfaceDefinitions()) {
      methods = methods.concat(intfDef.methods);
    }
 
    const builtIn = new BuiltIn();
    for (const method of methods) {
      if (builtIn.searchBuiltin(method.name.toUpperCase())) {
        const message = `Method name "${method.name}" overwrites built-in SAP function name`;
        issues.push(Issue.atIdentifier(method.identifier, message, this.getMetadata().key));
      }
    }
 
    return issues;
  }
}