All files / src/rules method_overwrites_builtin.ts

100% Statements 55/55
100% Branches 8/8
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 551x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10327x 10327x 10327x 10327x 10327x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 30812x 10327x 10327x 9814x 9814x 10327x 10327x 241x 241x 10327x 10327x 256x 256x 256x 256x 118x 118x 256x 256x 256x 46x 2x 2x 2x 46x 256x 256x 256x 10327x
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
 
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#avoid-obscuring-built-in-functions
 
Interface method names are ignored`,
      tags: [RuleTag.Naming, RuleTag.SingleFile, RuleTag.Styleguide],
    };
  }
 
  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);
    }
 
    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;
  }
}