All files / src/rules no_aliases.ts

100% Statements 60/60
100% Branches 14/14
100% Functions 7/7
100% Lines 60/60

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 611x 1x 1x 1x 1x 1x 1x 1x 24025x 24025x 24025x 24025x 1x 12013x 12013x 12013x 12013x 35898x 35898x 35898x 35898x 35898x 35898x 35898x 12013x 12013x 11503x 11503x 12013x 12013x 240x 240x 12013x 12013x 257x 257x 257x 257x 129x 12x 2x 2x 10x 10x 129x 257x 257x 57x 5x 5x 57x 257x 257x 257x 12013x 12013x 12x 12x 12013x 12013x  
import {Issue} from "../issue";
import {BasicRuleConfig} from "./_basic_rule_config";
import {ABAPRule} from "./_abap_rule";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
import {InfoAlias} from "../abap/4_file_information/_abap_file_information";
import {Visibility} from "../abap/4_file_information/visibility";
 
export class NoAliasesConf extends BasicRuleConfig {
  /** Skip reporting aliases in private sections. */
  public ignorePrivate: boolean = false;
}
 
export class NoAliases extends ABAPRule {
  private conf = new NoAliasesConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "no_aliases",
      title: "No ALIASES",
      shortDescription: `Detects use of the ALIAS statement`,
      tags: [RuleTag.SingleFile],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: NoAliasesConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    const message = "Do not use ALIASES";
    for (const classDef of file.getInfo().listClassDefinitions()) {
      for (const alias of classDef.aliases) {
        if (this.skipAlias(alias)) {
          continue;
        }
        issues.push(Issue.atIdentifier(alias.identifier, message, this.getMetadata().key, this.conf.severity));
      }
    }
 
    for (const interfaceDef of file.getInfo().listInterfaceDefinitions()) {
      for (const alias of interfaceDef.aliases) {
        issues.push(Issue.atIdentifier(alias.identifier, message, this.getMetadata().key, this.conf.severity));
      }
    }
 
    return issues;
  }
 
  private skipAlias(alias: InfoAlias): boolean {
    return this.conf.ignorePrivate === true && alias.visibility === Visibility.Private;
  }
 
}