@abaplint/core
Version:
abaplint - Core API
57 lines • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AllowedObjectNaming = exports.AllowedObjectNamingConf = void 0;
const issue_1 = require("../issue");
const _irule_1 = require("./_irule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const NAME_REGEX = /^(\/[A-Z_\d]{3,8}\/)?[A-Z_\d<> ]+$/i;
class AllowedObjectNamingConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.AllowedObjectNamingConf = AllowedObjectNamingConf;
class AllowedObjectNaming {
constructor() {
this.conf = new AllowedObjectNamingConf();
}
getMetadata() {
return {
key: "allowed_object_naming",
title: "Allowed object naming",
shortDescription: `Enforces basic name length and namespace restrictions, see note SAP 104010`,
tags: [_irule_1.RuleTag.Naming, _irule_1.RuleTag.SingleFile],
};
}
initialize(_reg) {
return this;
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
run(obj) {
const allowed = obj.getAllowedNaming();
const name = obj.getName();
let message = "";
if (name.length > allowed.maxLength) {
message = "Name exceeds max length";
}
else if (allowed.allowNamespace === false && name.indexOf("/") >= 0) {
message = "Namespace not allowed for object type";
}
else if (allowed.customRegex !== undefined) {
if (name.match(allowed.customRegex) === null) {
message = "Name not allowed";
}
}
else if (name.match(NAME_REGEX) === null) {
message = "Name not allowed";
}
if (message.length > 0) {
return [issue_1.Issue.atRow(obj.getFiles()[0], 1, message, this.getMetadata().key, this.conf.severity)];
}
return [];
}
}
exports.AllowedObjectNaming = AllowedObjectNaming;
//# sourceMappingURL=allowed_object_naming.js.map