UNPKG

@abaplint/core

Version:
62 lines 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WhitespaceEnd = exports.WhitespaceEndConf = void 0; const issue_1 = require("../issue"); const position_1 = require("../position"); const _basic_rule_config_1 = require("./_basic_rule_config"); const edit_helper_1 = require("../edit_helper"); const _irule_1 = require("./_irule"); const objects_1 = require("../objects"); class WhitespaceEndConf extends _basic_rule_config_1.BasicRuleConfig { } exports.WhitespaceEndConf = WhitespaceEndConf; class WhitespaceEnd { constructor() { this.conf = new WhitespaceEndConf(); } getMetadata() { return { key: "whitespace_end", title: "Whitespace at end of line", shortDescription: `Checks for redundant whitespace at the end of each line.`, extendedInformation: `SMIM and W3MI files are not checked.`, tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile], badExample: `WRITE 'hello'. `, goodExample: `WRITE 'hello'.`, }; } getMessage() { return "Remove whitespace at end of line"; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } initialize(_reg) { return this; } run(obj) { const issues = []; for (const file of obj.getFiles()) { if (obj instanceof objects_1.MIMEObject || obj instanceof objects_1.WebMIME) { continue; } const rows = file.getRawRows(); for (let i = 0; i < rows.length; i++) { if (rows[i].endsWith(" ") || rows[i].endsWith(" \r")) { const match = / +\r?$/.exec(rows[i]); const start = new position_1.Position(i + 1, match.index + 1); const end = new position_1.Position(i + 1, rows[i].length + 1); const fix = edit_helper_1.EditHelper.deleteRange(file, start, end); const issue = issue_1.Issue.atRange(file, start, end, this.getMessage(), this.getMetadata().key, this.conf.severity, fix); issues.push(issue); } } } return issues; } } exports.WhitespaceEnd = WhitespaceEnd; //# sourceMappingURL=whitespace_end.js.map