@abaplint/core
Version:
abaplint - Core API
130 lines • 4.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectNaming = exports.ObjectNamingConf = void 0;
const issue_1 = require("../issue");
const _naming_rule_config_1 = require("./_naming_rule_config");
const _irule_1 = require("./_irule");
const name_validator_1 = require("../utils/name_validator");
class ObjectNamingConf extends _naming_rule_config_1.NamingRuleConfig {
constructor() {
super(...arguments);
/** The regex pattern for global class names */
this.clas = "^ZC(L|X)";
/** The regex pattern for global interface names */
this.intf = "^ZIF";
/** The regex pattern for program (report) names */
this.prog = "^Z";
/** The regex pattern for function group names */
this.fugr = "^Z";
/** The regex pattern for DDIC table names */
this.tabl = "^Z";
/** The regex pattern for DDIC table type names */
this.ttyp = "^Z";
/** The regex pattern for data element names */
this.dtel = "^Z";
/** The regex pattern for domain names */
this.doma = "^Z";
/** The regex pattern for message class names */
this.msag = "^Z";
/** The regex pattern for transaction names */
this.tran = "^Z";
/** The regex pattern for lock object names */
this.enqu = "^EZ";
/** The regex pattern for authorization object names */
this.auth = "^Z";
/** The regex pattern for package interface names */
this.pinf = "^Z";
/** The regex pattern for idoc names */
this.idoc = "^Z";
/** The regex pattern for transformation names */
this.xslt = "^Z";
/** The regex pattern for smartform names */
this.ssfo = "^Z";
/** The regex pattern for smartstyle names */
this.ssst = "^Z";
/** The regex pattern for search helps */
this.shlp = "^Z";
/** The regex pattern for BADI Implementation */
this.sxci = "^Z";
/** The regex pattern for Enhancement Spot */
this.enhs = "^Z";
/** The regex pattern for Enhancement Implementation */
this.enho = "^Z";
/** The regex pattern for Customer enhancement projects */
this.cmod = "^Z";
/** The regex pattern for SAPscript form */
this.form = "^Z";
/** The regex pattern for Adobe Form Definition */
this.sfpf = "^Z";
/** The regex pattern for Adobe Interface Definition */
this.sfpi = "^Z";
/** The regex pattern for ABAP Query: Query */
this.aqqu = "^Z";
/** The regex pattern for ABAP Query: Functional area */
this.aqsg = "^Z";
/** The regex pattern for ABAP Query: User group */
this.aqbg = "^Z";
/** The regex pattern for Authorization Object */
this.suso = "^Z";
/** The regex pattern for Authorization Group */
this.sucu = "^Z";
/** The regex pattern for Web Dynpro Application */
this.wdya = "^Z";
/** The regex pattern for Web Dynpro Component */
this.wdyn = "^Z";
}
}
exports.ObjectNamingConf = ObjectNamingConf;
class ObjectNaming {
constructor() {
this.conf = new ObjectNamingConf();
}
getMetadata() {
return {
key: "object_naming",
title: "Object naming conventions",
shortDescription: `Allows you to enforce a pattern, such as a prefix, for object names`,
tags: [_irule_1.RuleTag.Naming],
};
}
getDescription(expected, actual) {
return this.conf.patternKind === "required" ?
"Object name does not match pattern " + expected + ": " + actual :
"Object name must not match pattern " + expected + ": " + actual;
}
getConfig() {
if (typeof this.conf === "boolean" && this.conf === true) {
return new ObjectNamingConf();
}
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
initialize(_reg) {
return this;
}
run(obj) {
let message = undefined;
if (this.conf.patternKind === undefined) {
this.conf.patternKind = "required";
}
const abapType = obj.getType().toLowerCase();
const config = this.getConfig();
// @ts-ignore
const pattern = config[abapType];
if (pattern === undefined) {
return [];
}
const regex = new RegExp(pattern, "i");
if (name_validator_1.NameValidator.violatesRule(obj.getName(), regex, this.conf)) {
message = this.getDescription(pattern, obj.getName());
}
if (message) {
return [issue_1.Issue.atRow(obj.getFiles()[0], 1, message, this.getMetadata().key, this.conf.severity)];
}
return [];
}
}
exports.ObjectNaming = ObjectNaming;
//# sourceMappingURL=object_naming.js.map