@abaplint/core
Version:
abaplint - Core API
71 lines • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MacroNaming = exports.MacroNamingConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const Statements = require("../abap/2_statements/statements");
const Expressions = require("../abap/2_statements/expressions");
const _basic_rule_config_1 = require("./_basic_rule_config");
const _irule_1 = require("./_irule");
const objects_1 = require("../objects");
class MacroNamingConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** The pattern for macros, case insensitive */
this.pattern = "^_.+$";
}
}
exports.MacroNamingConf = MacroNamingConf;
class MacroNaming extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new MacroNamingConf();
}
getMetadata() {
return {
key: "macro_naming",
title: "Macro naming conventions",
shortDescription: `Allows you to enforce a pattern for macro definitions`,
extendedInformation: `Use rule "avoid_use" to avoid macros altogether.`,
tags: [_irule_1.RuleTag.Naming, _irule_1.RuleTag.SingleFile],
badExample: `DEFINE something.
END-OF-DEFINITION.`,
goodExample: `DEFINE _something.
END-OF-DEFINITION.`,
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file, obj) {
const issues = [];
const testRegex = new RegExp(this.conf.pattern, "i");
if (obj instanceof objects_1.TypePool) {
return [];
}
for (const stat of file.getStatements()) {
if (!(stat.get() instanceof Statements.Define)) {
continue;
}
const expr = stat.findDirectExpression(Expressions.MacroName);
if (expr === undefined) {
continue;
}
const token = expr.getFirstToken();
if (testRegex.exec(token.getStr())) {
continue;
}
else {
const message = "Bad macro name naming, expected \"" + this.conf.pattern + "\", got \"" + token.getStr() + "\"";
const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
}
return issues;
}
}
exports.MacroNaming = MacroNaming;
//# sourceMappingURL=macro_naming.js.map