UNPKG

@abaplint/core

Version:
90 lines 3.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NewlineBetweenMethods = exports.NewlineBetweenMethodsConf = exports.NewlineLogic = void 0; const issue_1 = require("../issue"); const _basic_rule_config_1 = require("./_basic_rule_config"); const _abap_rule_1 = require("./_abap_rule"); const sequential_blank_1 = require("./sequential_blank"); const Statements = require("../abap/2_statements/statements"); const _irule_1 = require("./_irule"); var NewlineLogic; (function (NewlineLogic) { NewlineLogic["Exact"] = "exact"; NewlineLogic["Less"] = "less"; })(NewlineLogic || (exports.NewlineLogic = NewlineLogic = {})); class NewlineBetweenMethodsConf extends _basic_rule_config_1.BasicRuleConfig { constructor() { super(...arguments); /** Amount of newlines, works in conjunction with "newlineLogic" */ this.count = 3; /** * Exact: the exact number of required newlines between methods is defined by "newlineAmount" * * Less: the required number of newlines has to be less than "newlineAmount" */ this.logic = NewlineLogic.Less; } } exports.NewlineBetweenMethodsConf = NewlineBetweenMethodsConf; class NewlineBetweenMethods extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new NewlineBetweenMethodsConf(); } getMetadata() { return { key: "newline_between_methods", title: "New line between methods", shortDescription: `Checks for newlines between method implementations.`, tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.SingleFile], }; } getMessage() { switch (this.conf.logic) { case NewlineLogic.Exact: return `Exactly ${this.conf.count} newlines are required in between methods`; case NewlineLogic.Less: return `Less than ${this.conf.count} newlines and at least a single newline are required in between methods`; default: return ""; } } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { var _a; const issues = []; const rows = file.getRawRows(); if (!this.isConfigurationValid()) { return []; } for (const statement of file.getStatements()) { let nextRow = statement.getStart().getRow(); if (!(statement.get() instanceof Statements.EndMethod) || ((_a = rows[nextRow]) === null || _a === void 0 ? void 0 : _a.toUpperCase().includes("ENDCLASS."))) { continue; } let counter = 0; while (sequential_blank_1.SequentialBlank.isBlankOrWhitespace(rows[nextRow]) && (counter <= this.conf.count + 1)) { counter++; nextRow++; } if ((counter !== this.conf.count && this.conf.logic === NewlineLogic.Exact) || (counter >= this.conf.count && this.conf.logic === NewlineLogic.Less) || counter === 0) { issues.push(issue_1.Issue.atStatement(file, statement, this.getMessage(), this.getMetadata().key, this.conf.severity)); } } return issues; } isConfigurationValid() { if (this.conf.count < 1 || (this.conf.count === 1 && this.conf.logic === NewlineLogic.Less)) { return false; } else { return true; } } } exports.NewlineBetweenMethods = NewlineBetweenMethods; //# sourceMappingURL=newline_between_methods.js.map