@abaplint/core
Version:
abaplint - Core API
80 lines (79 loc) • 3.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AmbiguousStatement = exports.AmbiguousStatementConf = 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 combi_1 = require("../abap/2_statements/combi");
const version_1 = require("../version");
const _irule_1 = require("./_irule");
class AmbiguousStatementConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.AmbiguousStatementConf = AmbiguousStatementConf;
class AmbiguousStatement extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new AmbiguousStatementConf();
}
getMetadata() {
return {
key: "ambiguous_statement",
title: "Check for ambigious statements",
shortDescription: `Checks for ambiguity between deleting or modifying from internal and database table
Add "TABLE" keyword or "@" for escaping SQL variables
Only works if the target version is 740sp05 or above`,
tags: [_irule_1.RuleTag.SingleFile],
badExample: `DELETE foo FROM bar.
MODIFY foo FROM bar.`,
goodExample: `DELETE foo FROM @bar.
DELETE TABLE itab FROM 2.
MODIFY zfoo FROM @wa.
MODIFY TABLE foo FROM bar.`,
};
}
getMessage() {
return "Ambiguous statement. Use explicit syntax.";
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
if (this.reg.getConfig().getVersion() < version_1.Version.v740sp05) {
return [];
}
for (const statement of file.getStatements()) {
let match = false;
if (statement.get() instanceof Statements.DeleteDatabase) {
match = this.tryMatch(statement, this.reg, Statements.DeleteInternal);
}
else if (statement.get() instanceof Statements.DeleteInternal) {
match = this.tryMatch(statement, this.reg, Statements.DeleteDatabase);
}
else if (statement.get() instanceof Statements.ModifyInternal) {
match = this.tryMatch(statement, this.reg, Statements.ModifyDatabase);
}
else if (statement.get() instanceof Statements.ModifyDatabase) {
match = this.tryMatch(statement, this.reg, Statements.ModifyInternal);
}
if (match) {
const issue = issue_1.Issue.atStatement(file, statement, this.getMessage(), this.getMetadata().key, this.conf.severity);
issues.push(issue);
}
}
return issues;
}
tryMatch(st, reg, type1) {
const ver = reg.getConfig().getVersion();
const tokens = st.getTokens().slice(0);
tokens.pop();
const match = combi_1.Combi.run(new type1().getMatcher(), tokens, ver);
return match !== undefined;
}
}
exports.AmbiguousStatement = AmbiguousStatement;
//# sourceMappingURL=ambiguous_statement.js.map