@abaplint/core
Version:
abaplint - Core API
72 lines (70 loc) • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MaxOneStatement = exports.MaxOneStatementConf = void 0;
const issue_1 = require("../issue");
const _statement_1 = require("../abap/2_statements/statements/_statement");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const edit_helper_1 = require("../edit_helper");
const _irule_1 = require("./_irule");
const virtual_position_1 = require("../virtual_position");
class MaxOneStatementConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.MaxOneStatementConf = MaxOneStatementConf;
class MaxOneStatement extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new MaxOneStatementConf();
}
getMetadata() {
return {
key: "max_one_statement",
title: "Max one statement per line",
shortDescription: `Checks that each line contains only a single statement.`,
extendedInformation: `Does not report empty statements, use rule empty_statement for detecting empty statements.
Does not report anything for chained statements.
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#no-more-than-one-statement-per-line
https://docs.abapopenchecks.org/checks/11/`,
tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
badExample: `WRITE foo. WRITE bar.`,
goodExample: `WRITE foo.\nWRITE bar.`,
};
}
getMessage() {
return "Only one statement is allowed per line";
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
let prev = 0;
let reported = 0;
for (const statement of file.getStatements()) {
const term = statement.getTerminator();
if (statement.get() instanceof _statement_1.Comment
|| statement.get() instanceof _statement_1.NativeSQL
|| term === ",") {
continue;
}
const pos = statement.getStart();
if (pos instanceof virtual_position_1.VirtualPosition) {
continue;
}
const row = pos.getRow();
if (prev === row && row !== reported && statement.getFirstToken().getStr() !== ".") {
const fix = edit_helper_1.EditHelper.insertAt(file, pos, "\n");
const issue = issue_1.Issue.atPosition(file, pos, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
reported = row;
}
prev = row;
}
return issues;
}
}
exports.MaxOneStatement = MaxOneStatement;
//# sourceMappingURL=max_one_statement.js.map