@abaplint/core
Version:
abaplint - Core API
70 lines • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DbOperationInLoop = exports.DbOperationInLoopConf = void 0;
const Statements = require("../abap/2_statements/statements");
const Structures = require("../abap/3_structures/structures");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const issue_1 = require("../issue");
const _irule_1 = require("./_irule");
class DbOperationInLoopConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.DbOperationInLoopConf = DbOperationInLoopConf;
class DbOperationInLoop extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new DbOperationInLoopConf();
}
getMetadata() {
return {
key: "db_operation_in_loop",
title: "Database operation in loop",
shortDescription: `Database operation in LOOP/DO/WHILE`,
tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Performance],
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
const stru = file.getStructure();
if (stru === undefined) {
return issues;
}
const loops = stru.findAllStructures(Structures.Loop);
loops.push(...stru.findAllStructures(Structures.Do));
loops.push(...stru.findAllStructures(Structures.While));
for (const l of loops) {
let found = undefined;
if (found === undefined) {
found = l.findFirstStatement(Statements.Select);
}
if (found === undefined) {
found = l.findFirstStatement(Statements.SelectLoop);
}
if (found === undefined) {
found = l.findFirstStatement(Statements.InsertDatabase);
}
if (found === undefined) {
found = l.findFirstStatement(Statements.DeleteDatabase);
}
if (found === undefined) {
found = l.findFirstStatement(Statements.UpdateDatabase);
}
if (found === undefined) {
found = l.findFirstStatement(Statements.ModifyDatabase);
}
if (found) {
const message = "Database operation in loop";
issues.push(issue_1.Issue.atStatement(file, found, message, this.getMetadata().key, this.conf.severity));
}
}
return issues;
}
}
exports.DbOperationInLoop = DbOperationInLoop;
//# sourceMappingURL=db_operation_in_loop.js.map