All files / src/rules cds_parser_error.ts

100% Statements 54/54
93.75% Branches 15/16
100% Functions 6/6
100% Lines 54/54

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 541x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21092x 21092x 21092x 21092x 63019x 63019x 63019x 63019x 63019x 63019x 63019x 63019x 21092x 21092x 20198x 20198x 21092x 21092x 374x 374x 21092x 21092x 380x 380x 21092x 21092x 590x 590x 590x 590x 590x 13x 13x 13x 5x 5x 5x 5x 13x 590x 590x 590x 21092x 21092x
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";
import {CDSMetadataExtension, CDSType, DataDefinition} from "../objects";
 
export class CDSParserErrorConf extends BasicRuleConfig {
}
 
export class CDSParserError implements IRule {
  private conf = new CDSParserErrorConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "cds_parser_error",
      title: "CDS Parser Error",
      shortDescription: `CDS parsing`,
      extendedInformation: `Parses CDS and issues parser errors`,
      tags: [RuleTag.Syntax, RuleTag.SingleFile],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: CDSParserErrorConf) {
    this.conf = conf;
  }
 
  public initialize(_reg: IRegistry): IRule {
    return this;
  }
 
  public run(object: IObject): Issue[] {
    const issues: Issue[] = [];
 
    if ((object.getType() === "DDLS" && object instanceof DataDefinition) ||
        (object.getType() === "DDLX" && object instanceof CDSMetadataExtension) ||
        (object.getType() === "DRTY" && object instanceof CDSType)) {
      const hasError = object.hasParserError();
      const file = object.findSourceFile();
      if (hasError === true && file) {
        const empty = file.getRaw().length === 0 ? ", empty file" : "";
        const message = "CDS Parser error" + empty;
        issues.push(Issue.atRow(file, 1, message, this.getMetadata().key, this.getConfig().severity));
      }
    }
 
    return issues;
  }
 
}