UNPKG

@abaplint/core

Version:
67 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WhenOthersLast = exports.WhenOthersLastConf = void 0; const issue_1 = require("../issue"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const Statements = require("../abap/2_statements/statements"); const Structures = require("../abap/3_structures/structures"); const _irule_1 = require("./_irule"); class WhenOthersLastConf extends _basic_rule_config_1.BasicRuleConfig { } exports.WhenOthersLastConf = WhenOthersLastConf; class WhenOthersLast extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new WhenOthersLastConf(); } getMetadata() { return { key: "when_others_last", title: "WHEN OTHERS last", shortDescription: `Checks that WHEN OTHERS is placed the last within a CASE statement.`, tags: [_irule_1.RuleTag.SingleFile], badExample: `CASE bar. WHEN OTHERS. WHEN 2. ENDCASE.`, goodExample: `CASE bar. WHEN 2. WHEN OTHERS. ENDCASE.`, }; } getMessage() { return "WHEN OTHERS should be the last branch in a CASE statement."; } runParsed(file) { const issues = []; const struc = file.getStructure(); if (struc === undefined) { return []; } const cases = struc.findAllStructures(Structures.Case); for (const c of cases) { const whentop = c.findDirectStructures(Structures.When); for (let i = 0; i < whentop.length - 1; i++) { const whens = whentop[i].findDirectStatements(Statements.When).concat(whentop[i].findDirectStatements(Statements.WhenOthers)); for (const when of whens) { if (when.get() instanceof Statements.WhenOthers) { const start = when.getFirstToken().getStart(); const issue = issue_1.Issue.atPosition(file, start, this.getMessage(), this.getMetadata().key, this.conf.severity); issues.push(issue); } } } } return issues; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } } exports.WhenOthersLast = WhenOthersLast; //# sourceMappingURL=when_others_last.js.map