UNPKG

@abaplint/core

Version:
75 lines (74 loc) 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CDSAssociationName = exports.CDSAssociationNameConf = 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"); class CDSAssociationNameConf extends _basic_rule_config_1.BasicRuleConfig { } exports.CDSAssociationNameConf = CDSAssociationNameConf; class CDSAssociationName { constructor() { this.conf = new CDSAssociationNameConf(); } getMetadata() { return { key: "cds_association_name", title: "CDS Association Name", shortDescription: `CDS association names should start with an underscore`, extendedInformation: `By convention, CDS association names must start with an underscore character. https://help.sap.com/docs/abap-cloud/abap-data-models/cds-associations`, tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Naming], badExample: `define view entity test as select from source association [1..1] to target as Assoc on Assoc.id = source.id { key id }`, goodExample: `define view entity test as select from source association [1..1] to target as _Assoc on _Assoc.id = source.id { 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 issues = []; for (const assoc of tree.findAllExpressions(expressions_1.CDSAssociation)) { const asExpr = assoc.findFirstExpression(expressions_1.CDSAs); if (asExpr === undefined) { continue; } const nameExpr = asExpr.findDirectExpression(expressions_1.CDSName); if (nameExpr === undefined) { continue; } const name = nameExpr.getFirstToken().getStr(); if (!name.startsWith("_")) { const token = nameExpr.getFirstToken(); const message = `CDS association name "${name}" should start with an underscore`; issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.getConfig().severity)); } } return issues; } } exports.CDSAssociationName = CDSAssociationName; //# sourceMappingURL=cds_association_name.js.map