UNPKG

@abaplint/core

Version:
94 lines 3.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SpaceBeforeDot = exports.SpaceBeforeDotConf = void 0; const issue_1 = require("../issue"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const Statements = require("../abap/2_statements/statements"); const objects_1 = require("../objects"); const tokens_1 = require("../abap/1_lexer/tokens"); const position_1 = require("../position"); const edit_helper_1 = require("../edit_helper"); const _irule_1 = require("./_irule"); const ddic_1 = require("../ddic"); class SpaceBeforeDotConf extends _basic_rule_config_1.BasicRuleConfig { constructor() { super(...arguments); this.ignoreGlobalDefinition = true; this.ignoreExceptions = true; } } exports.SpaceBeforeDotConf = SpaceBeforeDotConf; class SpaceBeforeDot extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new SpaceBeforeDotConf(); } getMetadata() { return { key: "space_before_dot", title: "Space before dot", shortDescription: `Checks for extra spaces before dots at the ends of statements`, extendedInformation: ` https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#be-consistent https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#condense-your-code`, tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile], badExample: `WRITE bar .`, goodExample: `WRITE bar.`, }; } getMessage() { return "Remove space before \",\" or \".\""; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file, obj) { const issues = []; let prev = undefined; let startRow = 0; if (file.getStructure() === undefined) { // some parser error exists in file return []; } const ddic = new ddic_1.DDIC(this.reg); if (this.conf.ignoreGlobalDefinition) { const structure = file.getStructure(); if (obj instanceof objects_1.Class && structure !== undefined) { const endclass = structure.findFirstStatement(Statements.EndClass); if (endclass !== undefined) { startRow = endclass.getFirstToken().getRow(); } const definition = obj.getClassDefinition(); if (definition !== undefined && this.conf.ignoreExceptions && ddic.isException(definition, obj)) { return []; } } else if (obj instanceof objects_1.Interface && structure !== undefined) { const endinterface = structure.findFirstStatement(Statements.EndInterface); if (endinterface !== undefined) { startRow = endinterface.getFirstToken().getRow(); } } } for (const t of file.getTokens()) { if (t.getRow() < startRow) { continue; } if (prev !== undefined && t instanceof tokens_1.Punctuation && prev.getCol() + prev.getStr().length < t.getCol()) { const start = new position_1.Position(t.getStart().getRow(), prev.getEnd().getCol()); const end = new position_1.Position(t.getStart().getRow(), t.getStart().getCol()); 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); } prev = t; } return issues; } } exports.SpaceBeforeDot = SpaceBeforeDot; //# sourceMappingURL=space_before_dot.js.map