UNPKG

@abaplint/core

Version:
81 lines (80 loc) 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CheckComments = exports.CheckCommentsConf = void 0; const issue_1 = require("../issue"); const _statement_1 = require("../abap/2_statements/statements/_statement"); const _basic_rule_config_1 = require("./_basic_rule_config"); const _abap_rule_1 = require("./_abap_rule"); const _irule_1 = require("./_irule"); class CheckCommentsConf extends _basic_rule_config_1.BasicRuleConfig { constructor() { super(...arguments); /** Allows the use of end-of-line comments. */ this.allowEndOfLine = false; } } exports.CheckCommentsConf = CheckCommentsConf; var IssueType; (function (IssueType) { IssueType[IssueType["EndOfLine"] = 0] = "EndOfLine"; })(IssueType || (IssueType = {})); class CheckComments extends _abap_rule_1.ABAPRule { constructor() { super(...arguments); this.conf = new CheckCommentsConf(); } getMetadata() { return { key: "check_comments", title: "Check Comments", shortDescription: ` Various checks for comment usage.`, extendedInformation: ` Detects end of line comments. Comments starting with "#EC" or "##" are ignored https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#put-comments-before-the-statement-they-relate-to`, tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile], badExample: `WRITE 2. " descriptive comment`, goodExample: `" descriptive comment\nWRITE 2.`, }; } getDescription(issueType) { switch (issueType) { case IssueType.EndOfLine: return `Do not use end of line comments - move comment to previous row instead`; default: return ""; } } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } runParsed(file) { const issues = []; const rows = file.getRawRows(); if (this.conf.allowEndOfLine === true) { return []; } const commentRows = []; for (let i = 0; i < rows.length; i++) { const row = rows[i]; if (row.trim().startsWith("*") || row.trim().startsWith(`"`)) { commentRows.push(i); } } const statements = file.getStatements(); for (let i = statements.length - 1; i >= 0; i--) { const statement = statements[i]; if (statement.get() instanceof _statement_1.Comment && !commentRows.includes(statement.getStart().getRow() - 1)) { if (statement.getFirstToken().getStr().startsWith(`"#EC`) || statement.getFirstToken().getStr().startsWith(`"##`)) { continue; } issues.push(issue_1.Issue.atStatement(file, statement, this.getDescription(IssueType.EndOfLine), this.getMetadata().key, this.conf.severity)); } } return issues; } } exports.CheckComments = CheckComments; //# sourceMappingURL=check_comments.js.map