UNPKG

@abaplint/core

Version:
73 lines 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InvalidTableIndex = exports.InvalidTableIndexConf = void 0; const issue_1 = require("../issue"); const Expressions = require("../abap/2_statements/expressions"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const _irule_1 = require("./_irule"); const edit_helper_1 = require("../edit_helper"); const statements_1 = require("../abap/2_statements/statements"); class InvalidTableIndexConf extends _basic_rule_config_1.BasicRuleConfig { } exports.InvalidTableIndexConf = InvalidTableIndexConf; class InvalidTableIndex extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new InvalidTableIndexConf(); } getMetadata() { return { key: "invalid_table_index", title: "Invalid Table Index", shortDescription: `Issues error for constant table index zero, as ABAP starts from 1`, tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix], badExample: `DATA(first) = table[ 0 ]. READ TABLE gt_stack ASSIGNING <ls_stack> INDEX 0.`, goodExample: `DATA(first) = table[ 1 ]. READ TABLE gt_stack ASSIGNING <ls_stack> INDEX 1.`, }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { var _a, _b, _c, _d, _e, _f; const issues = []; const stru = file.getStructure(); if (stru === undefined) { return issues; // parser error } const expr = stru.findAllExpressionsRecursive(Expressions.TableExpression); for (const e of expr) { const token = (_c = (_b = (_a = e.findDirectExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Constant)) === null || _b === void 0 ? void 0 : _b.findFirstExpression(Expressions.Integer)) === null || _c === void 0 ? void 0 : _c.getFirstToken(); if (token === undefined) { continue; } if (token.getStr() === "0") { const message = "Table index starts from 1"; const fix = edit_helper_1.EditHelper.replaceToken(file, token, "1"); const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity, fix); issues.push(issue); } } for (const rt of stru.findAllStatements(statements_1.ReadTable)) { const token = (_f = (_e = (_d = rt.findExpressionAfterToken("INDEX")) === null || _d === void 0 ? void 0 : _d.findDirectExpression(Expressions.Constant)) === null || _e === void 0 ? void 0 : _e.findFirstExpression(Expressions.Integer)) === null || _f === void 0 ? void 0 : _f.getFirstToken(); if (token === undefined) { continue; } if (token.getStr() === "0") { const message = "Table index starts from 1"; const fix = edit_helper_1.EditHelper.replaceToken(file, token, "1"); const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity, fix); issues.push(issue); } } return issues; } } exports.InvalidTableIndex = InvalidTableIndex; //# sourceMappingURL=invalid_table_index.js.map