All files / src/rules check_transformation_exists.ts

100% Statements 63/63
100% Branches 15/15
100% Functions 6/6
100% Lines 63/63

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 62 63 641x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19563x 19563x 19563x 19563x 133864x 133864x 133864x 133864x 133864x 133864x 133864x 19563x 19563x 1x 1x 19563x 19563x 18808x 18808x 19563x 19563x 358x 358x 19563x 19563x 362x 362x 362x 362x 13x 13x 349x 362x 2355x 4x 4x 1x 1x 3x 3x 3x 4x 1x 1x 1x 4x 2355x 349x 349x 349x 19563x 19563x  
import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {CallTransformation} from "../abap/2_statements/statements";
import {NamespaceSimpleName} from "../abap/2_statements/expressions";
import {RuleTag} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
export class CheckTransformationExistsConf extends BasicRuleConfig {
}
 
export class CheckTransformationExists extends ABAPRule {
  private conf = new CheckTransformationExistsConf();
 
  public getMetadata() {
    return {
      key: "check_transformation_exists",
      title: "Check transformation exists",
      shortDescription: `Checks that used XSLT transformations exist.`,
      tags: [RuleTag.Syntax],
    };
  }
 
  private getDescription(name: string): string {
    return "Transformation \"" + name + "\" not found";
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: CheckTransformationExistsConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const output: Issue[] = [];
 
    const struc = file.getStructure();
    if (struc === undefined) {
      return [];
    }
 
    for (const s of file.getStatements()) {
      if (s.get() instanceof CallTransformation) {
        const nameExpression = s.findFirstExpression(NamespaceSimpleName);
        if (nameExpression === undefined) {
          continue;
        }
        const tok = nameExpression.getFirstToken();
        const name = tok.getStr();
        if (this.reg.inErrorNamespace(name) === true
            && this.reg.getObject("XSLT", name) === undefined) {
          const issue = Issue.atToken(file, tok, this.getDescription(name), this.getMetadata().key);
          output.push(issue);
        }
      }
    }
 
    return output;
  }
 
}