All files / src/rules bdef_parser_error.ts

100% Statements 51/51
100% Branches 11/11
100% Functions 6/6
100% Lines 51/51

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 521x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14684x 14684x 14684x 14684x 43909x 43909x 43909x 43909x 43909x 43909x 43909x 43909x 14684x 14684x 14122x 14122x 14684x 14684x 264x 264x 14684x 14684x 267x 267x 14684x 14684x 364x 364x 364x 5x 5x 2x 2x 2x 2x 5x 364x 364x 364x 14684x 14684x  
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 {BehaviorDefinition} from "../objects";
 
export class BDEFParserErrorConf extends BasicRuleConfig {
}
 
export class BDEFParserError implements IRule {
  private conf = new BDEFParserErrorConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "bdef_parser_error",
      title: "BDEF Parser Error",
      shortDescription: `BDEF parsing`,
      extendedInformation: `Parses behavior definitions and issues parser errors`,
      tags: [RuleTag.Syntax, RuleTag.SingleFile],
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: BDEFParserErrorConf) {
    this.conf = conf;
  }
 
  public initialize(_reg: IRegistry): IRule {
    return this;
  }
 
  public run(object: IObject): Issue[] {
    const issues: Issue[] = [];
 
    if (object instanceof BehaviorDefinition) {
      const file = object.findSourceFile();
      if (object.hasParserError() === true && file) {
        const empty = file.getRaw().length === 0 ? ", empty file" : "";
        const message = "BDEF Parser error" + empty;
        issues.push(Issue.atRow(file, 1, message, this.getMetadata().key, this.getConfig().severity));
      }
    }
 
    return issues;
  }
 
}