UNPKG

@abaplint/core

Version:
74 lines 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SequentialBlank = exports.SequentialBlankConf = void 0; const issue_1 = require("../issue"); const position_1 = require("../position"); 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"); class SequentialBlankConf extends _basic_rule_config_1.BasicRuleConfig { constructor() { super(...arguments); /** An equal or higher number of sequential blank lines will trigger a violation. * Example: if lines = 3, a maximum of 2 is allowed. */ this.lines = 4; } } exports.SequentialBlankConf = SequentialBlankConf; class SequentialBlank extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new SequentialBlankConf(); } static isBlankOrWhitespace(line) { return /^\s*$/.test(line); } getMetadata() { return { key: "sequential_blank", title: "Sequential blank lines", shortDescription: `Checks that code does not contain more than the configured number of blank lines in a row.`, tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile], }; } getMessage() { return "Remove sequential blank lines"; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { const issues = []; const rows = file.getRawRows(); let blanks = 0; for (let i = 0; i < rows.length; i++) { if (SequentialBlank.isBlankOrWhitespace(rows[i])) { blanks++; } else { blanks = 0; } if (blanks === this.conf.lines) { let blankCounter = 1; while (i + blankCounter < rows.length && SequentialBlank.isBlankOrWhitespace(rows[i + blankCounter])) { ++blankCounter; } const reportPos = new position_1.Position(i + 1, 1); // fix has to start at end of previous row for it to properly delete the first row const startPos = new position_1.Position(i, rows[i].length + 1); const endPos = new position_1.Position(i + blankCounter, rows[i + blankCounter - 1].length + 1); const fix = edit_helper_1.EditHelper.deleteRange(file, startPos, endPos); const issue = issue_1.Issue.atPosition(file, reportPos, this.getMessage(), this.getMetadata().key, this.conf.severity, fix); issues.push(issue); } } return issues; } } exports.SequentialBlank = SequentialBlank; //# sourceMappingURL=sequential_blank.js.map