All files / src/rules aff_and_xml.ts

100% Statements 63/63
100% Branches 13/13
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 11715x 11715x 11715x 11715x 11715x 57347x 57347x 57347x 57347x 57347x 57347x 57347x 57347x 11715x 11715x 11175x 11175x 11715x 11715x 253x 253x 11715x 11715x 257x 257x 11715x 11715x 345x 345x 345x 345x 345x 345x 345x 378x 378x 6x 378x 90x 90x 378x 345x 345x 1x 1x 1x 1x 1x 1x 344x 344x 344x 11715x 11715x  
import {Issue} from "../issue";
import {IRule, IRuleMetadata, RuleTag} from "./_irule";
import {IObject} from "../objects/_iobject";
import {IRegistry} from "../_iregistry";
import {BasicRuleConfig} from "./_basic_rule_config";
 
export class AFFAndXMLConf extends BasicRuleConfig {
}
 
export class AFFAndXML implements IRule {
 
  private conf = new AFFAndXMLConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "aff_and_xml",
      title: "AFF and XML",
      shortDescription: `Checks for objects that have both AFF (.json) and XML (.xml) files`,
      extendedInformation: `If an object has both an ABAP file format JSON file and an XML file, the XML file should be removed`,
      tags: [RuleTag.Syntax],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: AFFAndXMLConf) {
    this.conf = conf;
  }
 
  public initialize(_reg: IRegistry) {
    return this;
  }
 
  public run(obj: IObject): Issue[] {
    const files = obj.getFiles();
 
    let hasJSON = false;
    let hasXML = false;
    const type = obj.getType().toLowerCase();
 
    for (const file of files) {
      const filename = file.getFilename().toLowerCase();
      if (filename.endsWith("." + type + ".json")) {
        hasJSON = true;
      } else if (filename.endsWith("." + type + ".xml")) {
        hasXML = true;
      }
    }
 
    if (hasJSON && hasXML) {
      const xmlFile = obj.getXMLFile();
      if (xmlFile) {
        const message = "Object has both AFF JSON and XML files, remove the XML";
        return [Issue.atRow(xmlFile, 1, message, this.getMetadata().key, this.conf.severity)];
      }
    }
 
    return [];
  }
 
}