UNPKG

@abaplint/core

Version:
68 lines 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OmitPrecedingZeros = exports.OmitPrecedingZerosConf = void 0; const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const issue_1 = require("../issue"); const Expressions = require("../abap/2_statements/expressions"); const _irule_1 = require("./_irule"); const statements_1 = require("../abap/2_statements/statements"); const edit_helper_1 = require("../edit_helper"); class OmitPrecedingZerosConf extends _basic_rule_config_1.BasicRuleConfig { } exports.OmitPrecedingZerosConf = OmitPrecedingZerosConf; class OmitPrecedingZeros extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new OmitPrecedingZerosConf(); } getMetadata() { return { key: "omit_preceding_zeros", title: "Omit preceding zeros", shortDescription: `Omit preceding zeros from integer constants`, tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix], badExample: `int = -001.`, goodExample: `int = -1.`, }; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { var _a; const issues = []; const message = "Omit preceding zeros"; for (const s of file.getStatements()) { for (const i of s.findAllExpressions(Expressions.Integer)) { const token = i.getLastToken(); const str = token.getStr(); if (str.length > 1 && str.startsWith("0")) { if (s.get() instanceof statements_1.CallScreen || s.get() instanceof statements_1.SetScreen) { continue; } const replace = str.replace(/^0+/, ""); const fix = edit_helper_1.EditHelper.replaceRange(file, token.getStart(), token.getEnd(), replace); const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.getConfig().severity, fix); issues.push(issue); } } for (const i of s.findAllExpressions(Expressions.ParameterException)) { const token = (_a = i.findDirectExpression(Expressions.SimpleName)) === null || _a === void 0 ? void 0 : _a.getFirstToken(); const str = token === null || token === void 0 ? void 0 : token.getStr(); if (token && str && str.length > 1 && str.startsWith("0")) { const replace = str.replace(/^0+/, ""); const fix = edit_helper_1.EditHelper.replaceRange(file, token.getStart(), token.getEnd(), replace); const issue = issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.getConfig().severity, fix); issues.push(issue); } } } return issues; } } exports.OmitPrecedingZeros = OmitPrecedingZeros; //# sourceMappingURL=omit_preceding_zeros.js.map