All files / src/rules release_idoc.ts

100% Statements 62/62
100% Branches 15/15
100% Functions 7/7
100% Lines 62/62

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 10999x 10999x 10999x 10999x 32799x 32799x 32799x 32799x 32799x 32799x 10999x 10999x 2x 2x 10999x 10999x 10445x 10445x 10999x 10999x 260x 260x 10999x 10999x 260x 260x 10999x 10999x 330x 330x 330x 258x 258x 72x 330x 20x 18x 18x 330x 50x 50x 4x 330x 2x 2x 2x 2x 2x 2x 330x 10999x
import {Issue} from "../issue";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IObject} from "../objects/_iobject";
import {IRule} from "./_irule";
import * as Objects from "../objects";
import {Position} from "../position";
import {IRegistry} from "../_iregistry";
 
export class ReleaseIdocConf extends BasicRuleConfig {
}
 
export class ReleaseIdoc implements IRule {
  private conf = new ReleaseIdocConf();
 
  public getMetadata() {
    return {
      key: "release_idoc",
      title: "Release iDoc",
      shortDescription: `Checks idoc types and segments are set to status released`,
    };
  }
 
  private getMessage(): string {
    return "Idoc type/segement status must be set to released";
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: ReleaseIdocConf) {
    this.conf = conf;
  }
 
  public initialize(_reg: IRegistry) {
    return this;
  }
 
  public run(obj: IObject): Issue[] {
 
    const file = obj.getXMLFile();
    if (file === undefined) {
      return [];
    }
 
    if (obj instanceof Objects.Table) {
      if (file.getRaw().includes("<SEGMENTDEFINITION>") === false) {
        return [];
      }
    } else if (!(obj instanceof Objects.Idoc)) {
      return [];
    }
 
    if (file.getRaw().includes("<CLOSED>X</CLOSED>") === false) {
      const position = new Position(1, 1);
      const issue = Issue.atPosition(obj.getFiles()[0], position, this.getMessage(), this.getMetadata().key, this.conf.severity);
      return [issue];
    } else {
      return [];
    }
  }
}