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 11629x 11629x 11629x 11629x 90179x 90179x 90179x 90179x 90179x 90179x 90179x 11629x 11629x 1x 1x 11629x 11629x 11089x 11089x 11629x 11629x 252x 252x 11629x 11629x 275x 275x 275x 275x 13x 13x 262x 275x 1535x 4x 4x 1x 1x 3x 3x 3x 4x 1x 1x 1x 4x 1535x 262x 262x 262x 11629x 11629x  
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;
  }
 
}