UNPKG

@abaplint/core

Version:
138 lines 5.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ForbiddenPseudoAndPragma = exports.ForbiddenPseudoAndPragmaConf = void 0; const Statements = require("../abap/2_statements/statements"); const Expressions = require("../abap/2_statements/expressions"); const issue_1 = require("../issue"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const edit_helper_1 = require("../edit_helper"); const _irule_1 = require("./_irule"); const _statement_1 = require("../abap/2_statements/statements/_statement"); class ForbiddenPseudoAndPragmaConf extends _basic_rule_config_1.BasicRuleConfig { constructor() { super(...arguments); /** @uniqueItems true */ this.pseudo = [`"#EC *`]; /** @uniqueItems true */ this.pragmas = []; this.ignoreGlobalClassDefinition = false; this.ignoreGlobalInterface = false; } } exports.ForbiddenPseudoAndPragmaConf = ForbiddenPseudoAndPragmaConf; class ForbiddenPseudoAndPragma extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new ForbiddenPseudoAndPragmaConf(); } getMetadata() { return { key: "forbidden_pseudo_and_pragma", title: "Forbidden pseudo comments and pragma", shortDescription: `Checks for unwanted pseudo comments and pragma`, tags: [_irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile], badExample: `DATA i TYPE i. "#EC *`, goodExample: `DATA i TYPE i.`, }; } getConfig() { // @ts-ignore if (this.conf === true) { this.conf = new ForbiddenPseudoAndPragmaConf(); } if (this.conf.pseudo === undefined) { this.conf.pseudo = []; } if (this.conf.pragmas === undefined) { this.conf.pragmas = []; } return this.conf; } setConfig(conf) { this.conf = conf; } // todo, this method could use some refactoring // note that the top loop is on the configuration, which makes the default config run fast runParsed(file) { let skip = false; const issues = []; for (const p of this.conf.pragmas) { for (const s of file.getStatements()) { if (this.conf.ignoreGlobalClassDefinition === true) { if (s.get() instanceof Statements.ClassDefinition && s.findFirstExpression(Expressions.ClassGlobal)) { skip = true; continue; } else if (skip === true && s.get() instanceof Statements.EndClass) { skip = false; continue; } } if (this.conf.ignoreGlobalInterface === true) { if (s.get() instanceof Statements.Interface && s.findFirstExpression(Expressions.ClassGlobal)) { skip = true; continue; } else if (skip === true && s.get() instanceof Statements.EndInterface) { skip = false; continue; } } if (skip === true) { continue; } const list = s.getPragmas(); const found = list.find((a) => a.getStr().toUpperCase() === p.toUpperCase()); if (found) { const fix = edit_helper_1.EditHelper.deleteToken(file, found); const message = "Forbidden pragma"; issues.push(issue_1.Issue.atToken(file, found, message, this.getMetadata().key, this.conf.severity, fix)); } } } skip = false; for (const p of this.conf.pseudo) { for (const s of file.getStatements()) { if (this.conf.ignoreGlobalClassDefinition === true) { if (s.get() instanceof Statements.ClassDefinition && s.findFirstExpression(Expressions.ClassGlobal)) { skip = true; continue; } else if (skip === true && s.get() instanceof Statements.EndClass) { skip = false; continue; } } if (this.conf.ignoreGlobalInterface === true) { if (s.get() instanceof Statements.Interface && s.findFirstExpression(Expressions.ClassGlobal)) { skip = true; continue; } else if (skip === true && s.get() instanceof Statements.EndInterface) { skip = false; continue; } } if (skip === true) { continue; } if (!(s.get() instanceof _statement_1.Comment)) { continue; } if (s.concatTokens().toUpperCase().includes(p.toUpperCase())) { const fix = edit_helper_1.EditHelper.deleteStatement(file, s); const message = "Forbidden pseudo comment"; issues.push(issue_1.Issue.atStatement(file, s, message, this.getMetadata().key, this.conf.severity, fix)); } } } return issues; } } exports.ForbiddenPseudoAndPragma = ForbiddenPseudoAndPragma; //# sourceMappingURL=forbidden_pseudo_and_pragma.js.map