All files / src/rules check_transformation_exists.ts

100% Statements 61/61
100% Branches 14/14
100% Functions 6/6
100% Lines 61/61

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 7657x 7657x 7657x 7657x 22814x 22814x 22814x 22814x 22814x 22814x 22814x 7657x 7657x 1x 1x 7657x 7657x 7346x 7346x 7657x 7657x 139x 139x 7657x 7657x 153x 153x 153x 153x 13x 13x 140x 153x 823x 3x 3x 1x 1x 2x 3x 1x 1x 1x 3x 823x 140x 140x 140x 7657x 7657x  
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 name = s.findFirstExpression(NamespaceSimpleName);
        if (name === undefined) {
          continue;
        }
        const tok = name.getFirstToken();
        if (this.reg.getObject("XSLT", tok.getStr()) === undefined) {
          const issue = Issue.atToken(file, tok, this.getDescription(tok.getStr()), this.getMetadata().key);
          output.push(issue);
        }
      }
    }
 
    return output;
  }
 
}