@abaplint/core
Version:
abaplint - Core API
86 lines (85 loc) • 3.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmptyLineinStatement = exports.EmptyLineinStatementConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const tokens_1 = require("../abap/1_lexer/tokens");
const _statement_1 = require("../abap/2_statements/statements/_statement");
const edit_helper_1 = require("../edit_helper");
const _irule_1 = require("./_irule");
const position_1 = require("../position");
class EmptyLineinStatementConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** Allow changed empty lines in chanined statements */
this.allowChained = false;
}
}
exports.EmptyLineinStatementConf = EmptyLineinStatementConf;
class EmptyLineinStatement extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new EmptyLineinStatementConf();
}
getMetadata() {
return {
key: "empty_line_in_statement",
title: "Find empty lines in statements",
shortDescription: `Checks that statements do not contain empty lines.`,
extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#dont-obsess-with-separating-blank-lines
https://docs.abapopenchecks.org/checks/41/`,
tags: [_irule_1.RuleTag.Quickfix, _irule_1.RuleTag.Whitespace, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide],
badExample: `WRITE\n\nhello.`,
goodExample: `WRITE hello.`,
};
}
getMessage() {
return "Remove empty line in statement";
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
const stru = file.getStructure();
if (stru === undefined) {
return [];
}
for (const s of file.getStatements()) {
if (s.get() instanceof _statement_1.Unknown
|| s.get() instanceof _statement_1.NativeSQL) {
return []; // skip the file if there are parser errors or native/sqlscript
}
}
let prevLine = undefined;
for (const t of file.getTokens()) {
if (prevLine === undefined && t instanceof tokens_1.Comment) {
continue;
}
else if (prevLine === undefined) {
prevLine = t.getRow();
}
if (prevLine && t.getRow() - prevLine >= 2) {
const fix = edit_helper_1.EditHelper.deleteRange(file, new position_1.Position(prevLine + 1, 1), t.getStart());
const issue = issue_1.Issue.atToken(file, t, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
}
if (t instanceof tokens_1.Punctuation && t.getStr() === ".") {
prevLine = undefined;
}
else if (this.conf.allowChained === true && t instanceof tokens_1.Punctuation && t.getStr() === ",") {
prevLine = undefined;
}
else {
prevLine = t.getRow();
}
}
return issues;
}
}
exports.EmptyLineinStatement = EmptyLineinStatement;
//# sourceMappingURL=empty_line_in_statement.js.map