@abaplint/core
Version:
abaplint - Core API
82 lines • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ForbiddenIdentifier = exports.ForbiddenIdentifierConf = void 0;
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const issue_1 = require("../issue");
const nodes_1 = require("../abap/nodes");
const _irule_1 = require("./_irule");
class ForbiddenIdentifierConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** List of forbideen identifiers, array of string regex
* @uniqueItems true
*/
this.check = [];
}
}
exports.ForbiddenIdentifierConf = ForbiddenIdentifierConf;
class ForbiddenIdentifier extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new ForbiddenIdentifierConf();
}
getMetadata() {
return {
key: "forbidden_identifier",
title: "Forbidden Identifier",
shortDescription: `Forbid use of specified identifiers, list of regex.`,
extendedInformation: `Used in the transpiler to find javascript keywords in ABAP identifiers,
https://github.com/abaplint/transpiler/blob/bda94b8b56e2b7f2f87be2168f12361aa530220e/packages/transpiler/src/validation.ts#L44`,
tags: [_irule_1.RuleTag.SingleFile],
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
if (this.conf.check === undefined) {
this.conf.check = [];
}
}
runParsed(file) {
if (this.conf.check.length === 0) {
return [];
}
let ret = [];
for (const s of file.getStatements()) {
ret = ret.concat(this.traverse(s, file));
}
return ret;
}
traverse(node, file) {
let ret = [];
for (const c of node.getChildren()) {
if (c instanceof nodes_1.TokenNodeRegex) {
ret = ret.concat(this.check(c.get(), file));
}
else if (c instanceof nodes_1.TokenNode) {
continue;
}
else {
ret = ret.concat(this.traverse(c, file));
}
}
return ret;
}
check(token, file) {
const str = token.getStr();
const ret = [];
for (const c of this.conf.check) {
const reg = new RegExp(c, "i");
if (reg.exec(str)) {
const message = "Identifer \"" + str + "\" not allowed";
ret.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity));
}
}
return ret;
}
}
exports.ForbiddenIdentifier = ForbiddenIdentifier;
//# sourceMappingURL=forbidden_identifier.js.map