All files / src/rules check_transformation_exists.ts

100% Statements 27/27
100% Branches 8/8
100% Functions 6/6
100% Lines 27/27

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 7269x     21659x                 1x       7008x       114x       132x   132x 132x 13x     119x 710x 3x 3x 1x   2x 2x 1x 1x         119x        
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;
  }
 
}