UNPKG

@abaplint/core

Version:
75 lines 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StartAtTab = exports.StartAtTabConf = void 0; const issue_1 = require("../issue"); const _statement_1 = require("../abap/2_statements/statements/_statement"); const statements_1 = require("../abap/2_statements/statements"); const _abap_rule_1 = require("./_abap_rule"); const _basic_rule_config_1 = require("./_basic_rule_config"); const _irule_1 = require("./_irule"); class StartAtTabConf extends _basic_rule_config_1.BasicRuleConfig { } exports.StartAtTabConf = StartAtTabConf; class StartAtTab extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new StartAtTabConf(); } getMetadata() { return { key: "start_at_tab", title: "Start at tab", shortDescription: `Checks that statements start at tabstops.`, extendedInformation: `Reports max 100 issues per file https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#indent-and-snap-to-tab`, tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile], badExample: ` WRITE a.`, goodExample: ` WRITE a.`, }; } getMessage() { return "Start statement at tab position"; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { const issues = []; let inType = false; let previous = undefined; const raw = file.getRawRows(); for (const statement of file.getStatements()) { if (statement.get() instanceof _statement_1.Comment) { continue; } else if (statement.get() instanceof statements_1.TypeBegin) { inType = true; } else if (statement.get() instanceof statements_1.TypeEnd) { inType = false; } else if (inType) { continue; } const pos = statement.getStart(); if (previous !== undefined && pos.getRow() === previous.getRow()) { continue; } // just skip rows that contains tabs, this will be reported by the contains_tab rule if ((pos.getCol() - 1) % 2 !== 0 && raw[pos.getRow() - 1].includes("\t") === false) { const issue = issue_1.Issue.atPosition(file, pos, this.getMessage(), this.getMetadata().key, this.conf.severity); issues.push(issue); if (issues.length >= 100) { return issues; // only max 100 issues perfile } } previous = pos; } return issues; } } exports.StartAtTab = StartAtTab; //# sourceMappingURL=start_at_tab.js.map