@abaplint/core
Version:
abaplint - Core API
75 lines • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Nesting = exports.NestingConf = void 0;
const issue_1 = require("../issue");
const Statements = require("../abap/2_statements/statements");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const _irule_1 = require("./_irule");
class NestingConf extends _basic_rule_config_1.BasicRuleConfig {
constructor() {
super(...arguments);
/** Maximum allowed nesting depth */
this.depth = 5;
}
}
exports.NestingConf = NestingConf;
class Nesting extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new NestingConf();
}
getMetadata() {
return {
key: "nesting",
title: "Check nesting depth",
shortDescription: `Checks for methods exceeding a maximum nesting depth`,
extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#keep-the-nesting-depth-low
https://docs.abapopenchecks.org/checks/74/`,
tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
};
}
getDescription(max) {
return "Reduce nesting depth to max " + max;
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
let depth = 0;
for (const statement of file.getStatements()) {
const type = statement.get();
if (type instanceof Statements.If
|| type instanceof Statements.Case
|| type instanceof Statements.While
|| type instanceof Statements.Loop
|| type instanceof Statements.SelectLoop
|| type instanceof Statements.Do
|| type instanceof Statements.Try) {
depth = depth + 1;
}
else if (type instanceof Statements.EndIf
|| type instanceof Statements.EndCase
|| type instanceof Statements.EndWhile
|| type instanceof Statements.EndLoop
|| type instanceof Statements.EndSelect
|| type instanceof Statements.EndDo
|| type instanceof Statements.EndTry) {
depth = depth - 1;
}
if (depth > this.conf.depth) {
const pos = statement.getFirstToken().getStart();
const issue = issue_1.Issue.atPosition(file, pos, this.getDescription(this.conf.depth.toString()), this.getMetadata().key, this.conf.severity);
issues.push(issue);
break; // only one finding per file
}
}
return issues;
}
}
exports.Nesting = Nesting;
//# sourceMappingURL=nesting.js.map