All files / src/rules identical_form_names.ts

100% Statements 62/62
100% Branches 13/13
100% Functions 6/6
100% Lines 62/62

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 10503x 10503x 10503x 10503x 10503x 31330x 31330x 31330x 31330x 31330x 31330x 31330x 10503x 10503x 9970x 9970x 10503x 10503x 251x 251x 10503x 10503x 258x 258x 10503x 10503x 324x 62x 62x 262x 262x 262x 262x 324x 269x 44x 44x 2x 2x 2x 44x 42x 42x 44x 269x 262x 262x 262x 10503x 10503x
import {Issue} from "../issue";
import {IRule, IRuleMetadata, RuleTag} from "./_irule";
import {IObject} from "../objects/_iobject";
import {IRegistry} from "../_iregistry";
import {BasicRuleConfig} from "./_basic_rule_config";
import {ABAPObject} from "../objects/_abap_object";
 
export class IdenticalFormNamesConf extends BasicRuleConfig {
}
 
// todo: deprecation candidate? this is/should be handled by the syntax check?
 
export class IdenticalFormNames implements IRule {
 
  private conf = new IdenticalFormNamesConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "identical_form_names",
      title: "Identical FORM names",
      shortDescription: `Detects identically named FORMs`,
      tags: [RuleTag.Syntax],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: IdenticalFormNamesConf) {
    this.conf = conf;
  }
 
  public initialize(_reg: IRegistry) {
    return this;
  }
 
  public run(obj: IObject): Issue[] {
    if (!(obj instanceof ABAPObject)) {
      return [];
    }
 
    const ret: Issue[] = [];
    const found: string[] = [];
 
    for (const file of obj.getABAPFiles()) {
      for (const form of file.getInfo().listFormDefinitions()) {
        const name = form.name.toUpperCase();
        if (found.indexOf(name) >= 0) {
          const message = "Identical FORM Names: \"" + name + "\"";
          const issue = Issue.atIdentifier(form.identifier, message, this.getMetadata().key, this.conf.severity);
          ret.push(issue);
        } else {
          found.push(name);
        }
      }
    }
 
    return ret;
  }
 
}