UNPKG

@abaplint/core

Version:
89 lines 3.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NamesNoDash = exports.NamesNoDashConf = void 0; const Statements = require("../abap/2_statements/statements"); const Expressions = require("../abap/2_statements/expressions"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const issue_1 = require("../issue"); const tokens_1 = require("../abap/1_lexer/tokens"); const expressions_1 = require("../abap/2_statements/expressions"); const _irule_1 = require("./_irule"); class NamesNoDashConf extends _basic_rule_config_1.BasicRuleConfig { } exports.NamesNoDashConf = NamesNoDashConf; // todo, also check for other characters like %&$, rename rule? and extend to more kinds of identifiers? class NamesNoDash extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new NamesNoDashConf(); } getMetadata() { return { key: "names_no_dash", title: "No dashes in FORM and DATA names", shortDescription: `Checks for a "-" in FORM, DATA, PARAMETER and SELECT-OPTION names`, tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Naming], badExample: "DATA foo-bar TYPE i.", goodExample: "DATA foobar TYPE i.", }; } getMessage() { return "No dash allowed in FORM and DATA names"; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file, obj) { const issues = []; const struc = file.getStructure(); if (struc === undefined) { return issues; } if (obj.getType() !== "CLAS" && obj.getType() !== "INTF") { for (const form of struc.findAllStatements(Statements.Form)) { const expr = form.findFirstExpression(expressions_1.FormName); for (const token of expr.getTokens()) { if (token instanceof tokens_1.Dash || token instanceof tokens_1.DashW) { const issue = issue_1.Issue.atToken(file, token, this.getMessage(), this.getMetadata().key, this.conf.severity); issues.push(issue); break; } } } for (const form of struc.findAllStatements(Statements.Parameter)) { const expr = form.findFirstExpression(Expressions.FieldSub); for (const token of expr.getTokens()) { if (token instanceof tokens_1.Dash || token instanceof tokens_1.DashW) { const issue = issue_1.Issue.atToken(file, token, this.getMessage(), this.getMetadata().key, this.conf.severity); issues.push(issue); break; } } } for (const form of struc.findAllStatements(Statements.SelectOption)) { const expr = form.findFirstExpression(Expressions.FieldSub); for (const token of expr.getTokens()) { if (token instanceof tokens_1.Dash || token instanceof tokens_1.DashW) { const issue = issue_1.Issue.atToken(file, token, this.getMessage(), this.getMetadata().key, this.conf.severity); issues.push(issue); break; } } } } for (const name of struc.findAllExpressions(Expressions.DefinitionName)) { const text = name.concatTokens(); if (text.includes("-")) { const issue = issue_1.Issue.atToken(file, name.getFirstToken(), this.getMessage(), this.getMetadata().key, this.conf.severity); issues.push(issue); } } return issues; } } exports.NamesNoDash = NamesNoDash; //# sourceMappingURL=names_no_dash.js.map