All files / src/rules local_testclass_location.ts

85% Statements 17/20
85.71% Branches 6/7
83.33% Functions 5/6
85% Lines 17/20

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   7264x     21658x                         7008x       114x       128x   128x 96x     32x 29x           32x      
import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {Class} from "../objects";
import {IObject} from "../objects/_iobject";
import {IRuleMetadata, RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class LocalTestclassLocationConf extends BasicRuleConfig {
}
 
export class LocalTestclassLocation extends ABAPRule {
 
  private conf = new LocalTestclassLocationConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "local_testclass_location",
      title: "Local testclass location",
      shortDescription: `Checks that local test classes are placed in the test include.`,
      tags: [RuleTag.SingleFile],
    };
  }
 
  private getDescription(className: string): string {
    return "Place local testclass \"" + className + "\" in the testclass include";
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: LocalTestclassLocationConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile, obj: IObject) {
    const issues: Issue[] = [];
 
    if (!(obj instanceof Class)) {
      return [];
    }
 
    for (const c of file.getInfo().listClassDefinitions()) {
      Iif (c.isLocal && c.isForTesting && !file.getFilename().includes(".testclasses.abap")) {
        const issue = Issue.atIdentifier(c.identifier, this.getDescription(c.name), this.getMetadata().key, this.conf.severity);
        issues.push(issue);
      }
    }
 
    return issues;
  }
 
}