@abaplint/core
Version:
abaplint - Core API
185 lines (184 loc) • 8.38 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChainMainlyDeclarations = exports.ChainMainlyDeclarationsConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const Statements = require("../abap/2_statements/statements");
const _irule_1 = require("./_irule");
const edit_helper_1 = require("../edit_helper");
class ChainMainlyDeclarationsConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** Allow definition statements to be chained */
this.definitions = true;
/** Allow WRITE statements to be chained */
this.write = true;
/** Allow MOVE statements to be chained */
this.move = true;
/** Allow REFRESH statements to be chained */
this.refresh = true;
/** Allow UNASSIGN statements to be chained */
this.unassign = true;
/** Allow CLEAR statements to be chained */
this.clear = true;
/** Allow HIDE statements to be chained */
this.hide = true;
/** Allow FREE statements to be chained */
this.free = true;
/** Allow INCLUDE statements to be chained */
this.include = true;
/** Allow CHECK statements to be chained */
this.check = true;
/** Allow SORT statements to be chained */
this.sort = true;
}
}
exports.ChainMainlyDeclarationsConf = ChainMainlyDeclarationsConf;
class ChainMainlyDeclarations extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new ChainMainlyDeclarationsConf();
}
getMetadata() {
return {
key: "chain_mainly_declarations",
title: "Chain mainly declarations",
shortDescription: `Chain mainly declarations, allows chaining for the configured statements, reports errors for other statements.`,
extendedInformation: `
https://docs.abapopenchecks.org/checks/23/
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenchained_statements_guidl.htm
`,
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
badExample: `CALL METHOD: bar.`,
goodExample: `CALL METHOD bar.`,
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
var _a;
const issues = [];
const structure = file.getStructure();
if (structure === undefined) {
return [];
}
let previousRow;
for (const statementNode of structure.findAllStatementNodes()) {
const colon = statementNode.getColon();
if (colon === undefined) {
continue;
}
const statement = statementNode.get();
if (this.conf.definitions === true
&& (statement instanceof Statements.ClassData
|| statement instanceof Statements.ClassDataBegin
|| statement instanceof Statements.ClassDataEnd
|| statement instanceof Statements.Static
|| statement instanceof Statements.StaticBegin
|| statement instanceof Statements.StaticEnd
|| statement instanceof Statements.Local
|| statement instanceof Statements.Constant
|| statement instanceof Statements.ConstantBegin
|| statement instanceof Statements.ConstantEnd
|| statement instanceof Statements.Controls
|| statement instanceof Statements.Parameter
|| statement instanceof Statements.SelectOption
|| statement instanceof Statements.SelectionScreen
|| statement instanceof Statements.Aliases
|| statement instanceof Statements.Tables
|| statement instanceof Statements.MethodDef
|| statement instanceof Statements.InterfaceDef
|| statement instanceof Statements.Type
|| statement instanceof Statements.TypeBegin
|| statement instanceof Statements.TypeEnd
|| statement instanceof Statements.TypeEnumBegin
|| statement instanceof Statements.TypeEnumEnd
|| statement instanceof Statements.TypeEnum
|| statement instanceof Statements.Events
|| statement instanceof Statements.Ranges
|| statement instanceof Statements.TypePools
|| statement instanceof Statements.FieldSymbol
|| statement instanceof Statements.Data
|| statement instanceof Statements.DataBegin
|| statement instanceof Statements.DataEnd)) {
continue;
}
else if (this.conf.write === true && statement instanceof Statements.Write) {
continue;
}
else if (this.conf.move === true && statement instanceof Statements.Move) {
continue;
}
else if (this.conf.refresh === true && statement instanceof Statements.Refresh) {
continue;
}
else if (this.conf.unassign === true && statement instanceof Statements.Unassign) {
continue;
}
else if (this.conf.clear === true && statement instanceof Statements.Clear) {
continue;
}
else if (this.conf.hide === true && statement instanceof Statements.Hide) {
continue;
}
else if (this.conf.free === true && statement instanceof Statements.Free) {
continue;
}
else if (this.conf.include === true && statement instanceof Statements.Include) {
continue;
}
else if (this.conf.check === true && statement instanceof Statements.Check) {
continue;
}
else if (this.conf.sort === true && statement instanceof Statements.Sort) {
continue;
}
let prevFix;
if (previousRow === colon.getStart().getRow()) {
prevFix = (_a = issues.pop()) === null || _a === void 0 ? void 0 : _a.getDefaultFix();
}
const fix = this.getFix(file, statement, statementNode, prevFix);
const message = "Chain mainly declarations";
issues.push(issue_1.Issue.atToken(file, statementNode.getFirstToken(), message, this.getMetadata().key, this.conf.severity, fix));
previousRow = statementNode.getColon().getStart().getRow();
}
return issues;
}
getFix(file, statement, statementNode, prevFix) {
if (statement instanceof Statements.ClassDataBegin ||
statement instanceof Statements.ClassDataEnd ||
statement instanceof Statements.StaticBegin ||
statement instanceof Statements.StaticEnd ||
statement instanceof Statements.ConstantBegin ||
statement instanceof Statements.ConstantEnd ||
statement instanceof Statements.TypeBegin ||
statement instanceof Statements.TypeEnd ||
statement instanceof Statements.TypeEnumBegin ||
statement instanceof Statements.TypeEnumEnd ||
statement instanceof Statements.DataBegin ||
statement instanceof Statements.DataEnd) {
return undefined;
}
let replacement = statementNode.concatTokens();
replacement = replacement.replace(",", ".");
let start;
if (prevFix === undefined) {
start = statementNode.getStart();
}
else {
start = statementNode.getTokens()[1].getStart();
}
let fix = edit_helper_1.EditHelper.replaceRange(file, start, statementNode.getEnd(), replacement);
if (prevFix !== undefined) {
fix = edit_helper_1.EditHelper.merge(fix, prevFix);
}
return fix;
}
}
exports.ChainMainlyDeclarations = ChainMainlyDeclarations;
//# sourceMappingURL=chain_mainly_declarations.js.map