All files / src/rules local_testclass_location.ts

90.74% Statements 49/54
91.67% Branches 11/12
83.33% Functions 5/6
90.74% Lines 49/54

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 1x 1x 1x 1x 7652x 7652x 7652x 7652x 7652x 22813x 22813x 22813x 22813x 22813x 22813x 22813x 7652x 7652x     7652x 7652x 7346x 7346x 7652x 7652x 139x 139x 7652x 7652x 149x 149x 149x 115x 115x 34x 149x 31x       31x 34x 34x 34x 7652x 7652x
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()) {
      if (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;
  }
 
}