UNPKG

@abaplint/core

Version:
132 lines (130 loc) 5.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CDSNaming = exports.CDSNamingConf = void 0; const issue_1 = require("../issue"); const _irule_1 = require("./_irule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const objects_1 = require("../objects"); const expressions_1 = require("../cds/expressions"); const cds_name_1 = require("../cds/expressions/cds_name"); class CDSNamingConf extends _basic_rule_config_1.BasicRuleConfig { constructor() { super(...arguments); /** Expected prefix for basic interface views */ this.basicInterfaceView = "ZI_"; /** Expected prefix for composite interface views */ this.compositeInterfaceView = "ZI_"; /** Expected prefix for consumption views */ this.consumptionView = "ZC_"; /** Expected prefix for basic restricted reuse views */ this.basicRestrictedReuseView = "ZR_"; /** Expected prefix for composite restricted reuse views */ this.compositeRestrictedReuseView = "ZR_"; /** Expected prefix for private views */ this.privateView = "ZP_"; /** Expected prefix for remote API views */ this.remoteAPIView = "ZA_"; /** Expected prefix for view extends */ this.viewExtend = "ZX_"; /** Expected prefix for extension include views */ this.extensionIncludeView = "ZE_"; /** Expected prefix for derivation functions */ this.derivationFunction = "ZF_"; /** Expected prefix for abstract entities */ this.abstractEntity = "ZD_"; } } exports.CDSNamingConf = CDSNamingConf; class CDSNaming { constructor() { this.conf = new CDSNamingConf(); } getMetadata() { return { key: "cds_naming", title: "CDS Naming", shortDescription: `Checks CDS naming conventions based on the VDM prefix rules`, extendedInformation: `Validates that CDS entity names follow the expected prefix conventions: I_ for interface views, C_ for consumption views, R_ for restricted reuse views, P_ for private views, A_ for remote API views, X_ for view extends, E_ for extension include views, F_ for derivation functions, D_ for abstract entities. Names must also start with Z after the prefix (custom namespace). https://help.sap.com/docs/SAP_S4HANA_ON-PREMISE/ee6ff9b281d8448f96b4fe6c89f2bdc8/8a8cee943ef944fe8936f4cc60ba9bc1.html`, tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Naming], badExample: `define view entity ZMY_VIEW as select from source { key id }`, goodExample: `define view entity ZI_MY_VIEW as select from source { key id }`, }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } initialize(_reg) { return this; } run(o) { if (o.getType() !== "DDLS" || !(o instanceof objects_1.DataDefinition)) { return []; } const tree = o.getTree(); if (tree === undefined) { return []; } const file = o.findSourceFile(); if (file === undefined) { return []; } const name = this.getCDSName(tree); if (name === undefined) { return []; } const nameStr = name.toUpperCase(); const allowedPrefixes = this.getAllowedPrefixes(tree); if (allowedPrefixes.length === 0) { return []; } const matched = allowedPrefixes.some(p => nameStr.startsWith(p.toUpperCase())); if (!matched) { const prefixList = [...new Set(allowedPrefixes)].join(", "); const message = `CDS name "${name}" should have one of the expected prefixes: ${prefixList}`; return [issue_1.Issue.atRow(file, 1, message, this.getMetadata().key, this.getConfig().severity)]; } return []; } getCDSName(tree) { const nameNodes = tree.findDirectExpressions(cds_name_1.CDSName); if (nameNodes.length > 0) { return nameNodes[0].getFirstToken().getStr(); } return undefined; } getAllowedPrefixes(tree) { const root = tree.get(); if (root instanceof expressions_1.CDSExtendView) { return [this.conf.viewExtend]; } if (root instanceof expressions_1.CDSDefineAbstract) { return [this.conf.abstractEntity]; } if (root instanceof expressions_1.CDSDefineTableFunction) { return [this.conf.derivationFunction]; } if (root instanceof expressions_1.CDSDefineView || root instanceof expressions_1.CDSDefineProjection || root instanceof expressions_1.CDSDefineCustom) { return [ this.conf.basicInterfaceView, this.conf.compositeInterfaceView, this.conf.consumptionView, this.conf.basicRestrictedReuseView, this.conf.compositeRestrictedReuseView, this.conf.privateView, this.conf.remoteAPIView, this.conf.extensionIncludeView, ]; } return []; } } exports.CDSNaming = CDSNaming; //# sourceMappingURL=cds_naming.js.map