UNPKG

@abaplint/core

Version:
73 lines 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SuperfluousValue = exports.SuperfluousValueConf = void 0; const issue_1 = require("../issue"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const Expressions = require("../abap/2_statements/expressions"); const Statements = require("../abap/2_statements/statements"); const _irule_1 = require("./_irule"); const version_1 = require("../version"); class SuperfluousValueConf extends _basic_rule_config_1.BasicRuleConfig { } exports.SuperfluousValueConf = SuperfluousValueConf; class SuperfluousValue extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new SuperfluousValueConf(); } getMetadata() { return { key: "superfluous_value", title: "Superfluous VALUE", shortDescription: `Find superfluous VALUE expressions`, extendedInformation: `Left hand side is inline, VALUE is inferred, value body is simple, from v740sp02 and up`, tags: [_irule_1.RuleTag.SingleFile], badExample: `DATA(message_entry) = VALUE #( message_table[ msgno = msgno ] ).`, goodExample: `DATA(message_entry) = message_table[ msgno = msgno ].`, }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { var _a, _b; const output = []; if (this.reg.getConfig().getVersion() < version_1.Version.v740sp02 && this.reg.getConfig().getVersion() !== version_1.Version.Cloud) { return []; } const struc = file.getStructure(); if (struc === undefined) { return []; // syntax error } for (const m of struc.findAllStatements(Statements.Move)) { if (((_a = m.findDirectExpression(Expressions.Target)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.InlineData)) === undefined) { continue; } const source = m.findDirectExpression(Expressions.Source); if (source === undefined) { continue; } const type = (_b = source.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _b === void 0 ? void 0 : _b.concatTokens(); if (type !== "#") { continue; } const body = source.findDirectExpression(Expressions.ValueBody); if (body === undefined) { continue; } if (body.getChildren().length === 1) { const message = "Superfluous VALUE expression"; const issue = issue_1.Issue.atStatement(file, m, message, this.getMetadata().key, this.conf.severity); output.push(issue); } } return output; } } exports.SuperfluousValue = SuperfluousValue; //# sourceMappingURL=superfluous_value.js.map