@abaplint/core
Version:
abaplint - Core API
79 lines • 3.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalClassNaming = exports.LocalClassNamingConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _naming_rule_config_1 = require("./_naming_rule_config");
const name_validator_1 = require("../utils/name_validator");
const _irule_1 = require("./_irule");
const ddic_1 = require("../ddic");
class LocalClassNamingConf extends _naming_rule_config_1.NamingRuleConfig {
constructor() {
super(...arguments);
/** The pattern for local class names */
this.local = "^LCL_.+$";
/** The pattern for local exception names */
this.exception = "^LCX_.+$";
/** The pattern for local test class names */
this.test = "^LTCL_.+$";
}
}
exports.LocalClassNamingConf = LocalClassNamingConf;
class LocalClassNaming extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new LocalClassNamingConf();
}
getMetadata() {
return {
key: "local_class_naming",
title: "Local class naming conventions",
shortDescription: `Allows you to enforce a pattern, such as a prefix, for local class names.`,
tags: [_irule_1.RuleTag.Naming, _irule_1.RuleTag.SingleFile],
};
}
getDescription(expected, actual) {
return this.conf.patternKind === "required" ?
"Local class name does not match pattern " + expected + ": " + actual :
"Local class name must not match pattern " + expected + ": " + actual;
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file, obj) {
const issues = [];
if (this.conf.patternKind === undefined) {
this.conf.patternKind = "required";
}
const ddic = new ddic_1.DDIC(this.reg);
for (const classDef of file.getInfo().listClassDefinitions()) {
if (classDef.isGlobal) {
continue;
}
const className = classDef.name;
let expected = "";
if (classDef.isForTesting) {
expected = this.conf.test;
}
else if (ddic.isException(classDef, obj)) {
expected = this.conf.exception;
}
else {
expected = this.conf.local;
}
if (expected === undefined || expected.length === 0) {
continue;
}
const regex = new RegExp(expected, "i");
if (name_validator_1.NameValidator.violatesRule(className, regex, this.conf)) {
issues.push(issue_1.Issue.atIdentifier(classDef.identifier, this.getDescription(expected, className), this.getMetadata().key, this.conf.severity));
}
}
return issues;
}
}
exports.LocalClassNaming = LocalClassNaming;
//# sourceMappingURL=local_class_naming.js.map