All files / src/rules parser_bad_exceptions.ts

96.49% Statements 55/57
83.33% Branches 10/12
100% Functions 5/5
96.49% Lines 55/57

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 571x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11508x 11508x 11508x 11508x 34364x 34364x 34364x 34364x 34364x 34364x 34364x 34364x 34364x 34364x 34364x 11508x 11508x 11006x 11006x 11508x 11508x 235x 235x 11508x 11508x 247x 247x 247x 1383x 1382x 1382x 1383x 1383x     1x 1x 1x 1x 247x 247x 247x 11508x 11508x
import * as Statements from "../abap/2_statements/statements";
import * as Expressions from "../abap/2_statements/expressions";
import {Issue} from "../issue";
import {ABAPRule} from "./_abap_rule";
import {BasicRuleConfig} from "./_basic_rule_config";
import {RuleTag, IRuleMetadata} from "./_irule";
import {ABAPFile} from "../abap/abap_file";
 
// todo: this rule needs refactoring
 
export class ParserBadExceptionsConf extends BasicRuleConfig {
}
 
export class ParserBadExceptions extends ABAPRule {
  private conf = new ParserBadExceptionsConf();
 
  public getMetadata(): IRuleMetadata {
    return {
      key: "parser_bad_exceptions",
      title: "Parser Error, bad EXCEPTIONS in CALL FUNCTION",
      shortDescription: `Checks for syntax not recognized by abaplint, related to EXCEPTIONS in CALL FUNCTION.`,
      tags: [RuleTag.Syntax, RuleTag.SingleFile],
      /*
      badExample: `IF ( foo = 'bar').`,
      goodExample: `IF ( foo = 'bar' ).`,
      */
    };
  }
 
  public getConfig() {
    return this.conf;
  }
 
  public setConfig(conf: ParserBadExceptionsConf) {
    this.conf = conf;
  }
 
  public runParsed(file: ABAPFile) {
    const issues: Issue[] = [];
 
    for (const statement of file.getStatements()) {
      if (!(statement.get() instanceof Statements.CallFunction)) {
        continue;
      }
      const found = statement.findDirectExpression(Expressions.FunctionParameters)?.findDirectExpression(Expressions.Field);
      if (found === undefined) {
        continue;
      }
 
      const message = "Bad EXCEPTIONS syntax in CALL FUNCTION";
      issues.push(Issue.atToken(file, found.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
    }
 
    return issues;
  }
 
}