@abaplint/core
Version:
abaplint - Core API
72 lines • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnnecessaryChaining = exports.UnnecessaryChainingConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const _irule_1 = require("./_irule");
const edit_helper_1 = require("../edit_helper");
const _statement_1 = require("../abap/2_statements/statements/_statement");
class UnnecessaryChainingConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.UnnecessaryChainingConf = UnnecessaryChainingConf;
class UnnecessaryChaining extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new UnnecessaryChainingConf();
}
getMetadata() {
return {
key: "unnecessary_chaining",
title: "Unnecessary Chaining",
shortDescription: `Find unnecessary chaining, all statements are checked`,
extendedInformation: ``,
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
badExample: `WRITE: bar.`,
goodExample: `WRITE bar.`,
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
const statements = file.getStatements();
for (let i = 0; i < statements.length; i++) {
const colon = statements[i].getColon();
if (colon === undefined) {
continue;
}
let j = 1;
let nextStatement = statements[i + j];
while ((nextStatement === null || nextStatement === void 0 ? void 0 : nextStatement.get()) instanceof _statement_1.Comment) {
j++;
nextStatement = statements[i + j];
}
j = 1;
let prevStatement = statements[i - j];
while ((prevStatement === null || prevStatement === void 0 ? void 0 : prevStatement.get()) instanceof _statement_1.Comment) {
j++;
prevStatement = statements[i - j];
}
const next = nextStatement === null || nextStatement === void 0 ? void 0 : nextStatement.getColon();
const prev = prevStatement === null || prevStatement === void 0 ? void 0 : prevStatement.getColon();
if (next !== undefined && colon.getStart().equals(next.getStart())) {
continue;
}
else if (prev !== undefined && colon.getStart().equals(prev.getStart())) {
continue;
}
const fix = edit_helper_1.EditHelper.deleteRange(file, colon.getStart(), colon.getEnd());
const message = "Unnecessary chaining";
const issue = issue_1.Issue.atToken(file, colon, message, this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
}
return issues;
}
}
exports.UnnecessaryChaining = UnnecessaryChaining;
//# sourceMappingURL=unnecessary_chaining.js.map