UNPKG

@abaplint/core

Version:
84 lines 3.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Exporting = exports.ExportingConf = void 0; const issue_1 = require("../issue"); const _irule_1 = require("./_irule"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const expressions_1 = require("../abap/2_statements/expressions"); const edit_helper_1 = require("../edit_helper"); class ExportingConf extends _basic_rule_config_1.BasicRuleConfig { } exports.ExportingConf = ExportingConf; class Exporting extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new ExportingConf(); } getMetadata() { return { key: "exporting", title: "EXPORTING can be omitted", shortDescription: `Detects EXPORTING statements which can be omitted.`, badExample: `call_method( EXPORTING foo = bar ).`, goodExample: `call_method( foo = bar ).`, extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#omit-the-optional-keyword-exporting https://docs.abapopenchecks.org/checks/30/`, tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile], }; } getMessage() { return "The EXPORTING keyword can be omitted"; } runParsed(file, obj) { let issues = []; if (obj.getType() === "INTF") { return []; } for (const statement of file.getStatements()) { const expressions = statement.findAllExpressionsMulti([expressions_1.MethodCallBody, expressions_1.MethodCall]); for (const b of expressions) { if (b.get() instanceof expressions_1.MethodCallBody) { if (b.getFirstToken().getStr() !== "(") { continue; } issues = issues.concat(this.check(b, file)); } else if (b.get() instanceof expressions_1.MethodCall) { issues = issues.concat(this.check(b, file)); } } } return issues; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } check(node, file) { const e = node.findFirstExpression(expressions_1.MethodParameters); if (e === undefined) { return []; } if (e.getFirstToken().getStr().toUpperCase() !== "EXPORTING") { return []; } const tokens = e.getDirectTokens(); const strings = tokens.map(t => t.getStr().toUpperCase()); if (strings[0] === "EXPORTING" && strings.includes("IMPORTING") === false && strings.includes("RECEIVING") === false && strings.includes("EXCEPTIONS") === false && strings.includes("CHANGING") === false) { const next = e.getAllTokens()[1]; const fix = edit_helper_1.EditHelper.deleteRange(file, tokens[0].getStart(), next.getStart()); const issue = issue_1.Issue.atToken(file, tokens[0], this.getMessage(), this.getMetadata().key, this.conf.severity, fix); return [issue]; } return []; } } exports.Exporting = Exporting; //# sourceMappingURL=exporting.js.map