All files / src/rules msag_consistency.ts

85.19% Statements 23/27
66.67% Branches 4/6
100% Functions 7/7
85.19% Lines 23/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 62 63 641x 1x   1x     1x   1x     1x 7272x     21674x               1x       7013x       114x       117x       135x   135x 132x     3x   1x 1x 1x 1x 1x   1x               3x    
import {Issue} from "../issue";
import {BasicRuleConfig} from "./_basic_rule_config";
import {IRegistry} from "../_iregistry";
import {MessageClass} from "../objects";
import {IRule} from "./_irule";
import {IObject} from "../objects/_iobject";
import {Position} from "../position";
 
export class MSAGConsistencyConf extends BasicRuleConfig {
}
 
export class MSAGConsistency implements IRule {
  private conf = new MSAGConsistencyConf();
 
  public getMetadata() {
    return {
      key: "msag_consistency",
      title: "MSAG consistency check",
      shortDescription: `Checks the validity of messages in message classes`,
    };
  }
 
  private getDescription(reason: string): string {
    return "Message class invalid: " + reason;
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: MSAGConsistencyConf) {
    this.conf = conf;
  }
 
  public initialize(_reg: IRegistry) {
    return this;
  }
 
  public run(obj: IObject): Issue[] {
    const issues: Issue[] = [];
 
    if (!(obj instanceof MessageClass)) {
      return [];
    }
 
    for (const message of obj.getMessages()) {
// todo, get the right positions in xml file
      Eif (!message.getNumber().match(/\d\d\d/)) {
        const text = this.getDescription("Message number must be 3 digits: message " + message.getNumber());
        const position = new Position(1, 1);
        const issue = Issue.atPosition(obj.getFiles()[0], position, text, this.getMetadata().key, this.conf.severity);
        issues.push(issue);
      }
      Iif (message.getMessage() === "") {
        const text = "Message text empty: message " + message.getNumber();
        const position = new Position(1, 1);
        const issue = Issue.atPosition(obj.getFiles()[0], position, text, this.getMetadata().key, this.conf.severity);
        issues.push(issue);
      }
    }
 
    return issues;
  }
}