UNPKG

@abaplint/core

Version:
74 lines (73 loc) 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnusedMacros = exports.UnusedMacrosConf = void 0; const issue_1 = require("../issue"); const _basic_rule_config_1 = require("./_basic_rule_config"); const _irule_1 = require("./_irule"); const _abap_object_1 = require("../objects/_abap_object"); const edit_helper_1 = require("../edit_helper"); class UnusedMacrosConf extends _basic_rule_config_1.BasicRuleConfig { constructor() { super(...arguments); /** skip specific names, case insensitive * @uniqueItems true */ this.skipNames = []; } } exports.UnusedMacrosConf = UnusedMacrosConf; class UnusedMacros { constructor() { this.conf = new UnusedMacrosConf(); } getMetadata() { return { key: "unused_macros", title: "Unused macros", shortDescription: `Checks for unused macro definitions definitions`, tags: [_irule_1.RuleTag.Quickfix], badExample: `DEFINE foobar1. WRITE 'hello'. END-OF-DEFINITION.`, goodExample: `DEFINE foobar2. WRITE 'hello'. END-OF-DEFINITION. foobar2.`, }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; if (this.conf.skipNames === undefined) { this.conf.skipNames = []; } } initialize(reg) { this.reg = reg; return this; } run(obj) { var _a; const result = []; if (!(obj instanceof _abap_object_1.ABAPObject)) { return []; } const references = this.reg.getMacroReferences(); for (const file of obj.getABAPFiles()) { for (const macroToken of references.listDefinitionsByFile(file.getFilename())) { const usages = references.listUsagesbyMacro(file.getFilename(), macroToken); if (usages.length === 0 && ((_a = this.conf.skipNames) === null || _a === void 0 ? void 0 : _a.includes(macroToken.getStr().toUpperCase())) === false) { const message = "Unused macro definition: " + macroToken.getStr(); const pos = references.getDefinitionRange(file.getFilename(), macroToken); const fix = edit_helper_1.EditHelper.deleteRange(file, pos.start, pos.end); result.push(issue_1.Issue.atToken(file, macroToken, message, this.getMetadata().key, this.conf.severity, fix)); } } } return result; } } exports.UnusedMacros = UnusedMacros; //# sourceMappingURL=unused_macros.js.map