@abaplint/core
Version:
abaplint - Core API
84 lines (81 loc) • 4.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StrictSQL = exports.StrictSQLConf = void 0;
const Statements = require("../abap/2_statements/statements");
const Expressions = require("../abap/2_statements/expressions");
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const version_1 = require("../version");
const _irule_1 = require("./_irule");
const edit_helper_1 = require("../edit_helper");
class StrictSQLConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.StrictSQLConf = StrictSQLConf;
class StrictSQL extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new StrictSQLConf();
}
getMetadata() {
return {
key: "strict_sql",
title: "Strict SQL",
shortDescription: `Strict SQL`,
extendedInformation: `https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abapinto_clause.htm
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenopensql_strict_mode_750.htm
Also see separate rule sql_escape_host_variables
Activates from v750 and up`,
tags: [_irule_1.RuleTag.Upport, _irule_1.RuleTag.Quickfix],
badExample: `SELECT * FROM ztabl INTO TABLE @rt_content WHERE type = @iv_type ORDER BY PRIMARY KEY.`,
goodExample: `SELECT * FROM ztabl WHERE type = @iv_type ORDER BY PRIMARY KEY INTO TABLE @rt_content.`,
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file, obj) {
const issues = [];
const type = obj.getType();
if (type === "INTF" || type === "TYPE") {
return [];
}
if (this.reg.getConfig().getVersion() < version_1.Version.v750
&& this.reg.getConfig().getVersion() !== version_1.Version.Cloud) {
return [];
}
for (const s of file.getStatements()) {
if (s.get() instanceof Statements.Select
|| s.get() instanceof Statements.SelectLoop) {
const expr = s.findDirectExpression(Expressions.Select);
const where = expr === null || expr === void 0 ? void 0 : expr.findDirectExpression(Expressions.SQLCond);
const order = expr === null || expr === void 0 ? void 0 : expr.findDirectExpression(Expressions.SQLOrderBy);
const into = (expr === null || expr === void 0 ? void 0 : expr.findDirectExpression(Expressions.SQLIntoStructure))
|| (expr === null || expr === void 0 ? void 0 : expr.findDirectExpression(Expressions.SQLIntoList))
|| (expr === null || expr === void 0 ? void 0 : expr.findDirectExpression(Expressions.SQLIntoTable));
if (into === undefined || where === undefined) {
continue;
}
else if (where.getFirstToken().getStart().isBefore(into.getFirstToken().getStart())) {
continue;
}
const fix1 = edit_helper_1.EditHelper.deleteRange(file, into.getFirstToken().getStart(), into.getLastToken().getEnd());
let last = where.getLastToken();
if (order && order.getLastToken().getEnd().isAfter(last.getEnd())) {
last = order.getLastToken();
}
const fix2 = edit_helper_1.EditHelper.insertAt(file, last.getEnd(), " " + into.concatTokens());
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
const message = "INTO/APPENDING must be last in strict SQL";
const issue = issue_1.Issue.atToken(file, s.getFirstToken(), message, this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
}
}
return issues;
}
}
exports.StrictSQL = StrictSQL;
//# sourceMappingURL=strict_sql.js.map