@abaplint/core 2.120.110 → 2.120.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/abaplint.d.ts +12 -0
- package/build/src/abap/2_statements/expressions/loop_group_by.js +1 -1
- package/build/src/abap/2_statements/statements/authority_check.js +1 -1
- package/build/src/abap/2_statements/statements/commit.js +1 -1
- package/build/src/abap/2_statements/statements/convert.js +2 -2
- package/build/src/abap/2_statements/statements/do.js +2 -1
- package/build/src/abap/2_statements/statements/exit.js +2 -1
- package/build/src/abap/2_statements/statements/get_time.js +3 -2
- package/build/src/abap/2_statements/statements/perform.js +1 -1
- package/build/src/abap/2_statements/statements/rollback.js +1 -1
- package/build/src/abap/2_statements/statements/wait.js +1 -1
- package/build/src/abap/5_syntax/_builtin_call.js +98 -0
- package/build/src/abap/5_syntax/_current_scope.js +15 -0
- package/build/src/abap/5_syntax/_object_oriented.js +11 -0
- package/build/src/abap/5_syntax/basic_types.js +30 -0
- package/build/src/abap/5_syntax/expressions/_substring.js +5 -4
- package/build/src/abap/5_syntax/expressions/compare.js +17 -31
- package/build/src/abap/5_syntax/expressions/cond_body.js +7 -0
- package/build/src/abap/5_syntax/expressions/for.js +32 -4
- package/build/src/abap/5_syntax/expressions/inline_loop_definition.js +8 -3
- package/build/src/abap/5_syntax/expressions/loop_group_by.js +123 -13
- package/build/src/abap/5_syntax/expressions/select.js +34 -2
- package/build/src/abap/5_syntax/expressions/source.js +46 -0
- package/build/src/abap/5_syntax/expressions/switch_body.js +6 -0
- package/build/src/abap/5_syntax/statements/loop.js +12 -1
- package/build/src/abap/5_syntax/statements/message.js +10 -0
- package/build/src/abap/5_syntax/statements/move.js +8 -0
- package/build/src/abap/5_syntax/statements/raise.js +5 -0
- package/build/src/abap/5_syntax/statements/write.js +10 -0
- package/build/src/abap/5_syntax/syntax.js +7 -0
- package/build/src/abap/types/event_definition.js +12 -0
- package/build/src/abap/types/function_module_definition.js +16 -0
- package/build/src/registry.js +1 -1
- package/build/src/rules/downport.js +5 -0
- package/build/src/rules/function_module_parameter_names.js +139 -0
- package/build/src/rules/index.js +2 -0
- package/build/src/rules/loop_target_misuse.js +268 -4
- package/build/src/rules/redundant_conversion.js +15 -3
- package/build/src/rules/rfc_error_handling.js +63 -13
- package/build/src/rules/unhandled_classic_exception.js +305 -0
- package/package.json +1 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FunctionModuleParameterNames = exports.FunctionModuleParameterNamesConf = void 0;
|
|
4
|
+
const issue_1 = require("../issue");
|
|
5
|
+
const _irule_1 = require("./_irule");
|
|
6
|
+
const function_group_1 = require("../objects/function_group");
|
|
7
|
+
const _naming_rule_config_1 = require("./_naming_rule_config");
|
|
8
|
+
const name_validator_1 = require("../utils/name_validator");
|
|
9
|
+
const function_module_definition_1 = require("../abap/types/function_module_definition");
|
|
10
|
+
const position_1 = require("../position");
|
|
11
|
+
class FunctionModuleParameterNamesConf extends _naming_rule_config_1.NamingRuleConfig {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
/** The pattern for importing parameters */
|
|
15
|
+
this.importing = "^I._.+$";
|
|
16
|
+
/** The pattern for exporting parameters */
|
|
17
|
+
this.exporting = "^E._.+$";
|
|
18
|
+
/** The pattern for changing parameters */
|
|
19
|
+
this.changing = "^C._.+$";
|
|
20
|
+
/** The pattern for tables parameters */
|
|
21
|
+
this.tables = "^T._.+$";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.FunctionModuleParameterNamesConf = FunctionModuleParameterNamesConf;
|
|
25
|
+
class FunctionModuleParameterNames {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.conf = new FunctionModuleParameterNamesConf();
|
|
28
|
+
this.regex = this.compile();
|
|
29
|
+
}
|
|
30
|
+
getMetadata() {
|
|
31
|
+
return {
|
|
32
|
+
key: "function_module_parameter_names",
|
|
33
|
+
title: "Function module parameter naming conventions",
|
|
34
|
+
shortDescription: `Allows you to enforce a pattern, such as a prefix, for function module parameter names`,
|
|
35
|
+
extendedInformation: `Checks the parameters of function modules in function groups,
|
|
36
|
+
with a separate pattern for importing, exporting, changing and tables parameters.`,
|
|
37
|
+
tags: [_irule_1.RuleTag.Naming, _irule_1.RuleTag.SingleFile],
|
|
38
|
+
badExample: `FUNCTION z_get_name.
|
|
39
|
+
*" IMPORTING
|
|
40
|
+
*" VALUE(CUSTOMER) TYPE STRING
|
|
41
|
+
*" EXPORTING
|
|
42
|
+
*" VALUE(NAME) TYPE STRING
|
|
43
|
+
ENDFUNCTION.`,
|
|
44
|
+
goodExample: `FUNCTION z_get_name.
|
|
45
|
+
*" IMPORTING
|
|
46
|
+
*" VALUE(IV_CUSTOMER) TYPE STRING
|
|
47
|
+
*" EXPORTING
|
|
48
|
+
*" VALUE(EV_NAME) TYPE STRING
|
|
49
|
+
ENDFUNCTION.`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
getDescription(expected, actual) {
|
|
53
|
+
return this.conf.patternKind === "required" ?
|
|
54
|
+
"Function module parameter name does not match pattern " + expected + ": " + actual :
|
|
55
|
+
"Function module parameter name must not match pattern " + expected + ": " + actual;
|
|
56
|
+
}
|
|
57
|
+
getConfig() {
|
|
58
|
+
return this.conf;
|
|
59
|
+
}
|
|
60
|
+
setConfig(conf) {
|
|
61
|
+
this.conf = conf;
|
|
62
|
+
this.regex = this.compile();
|
|
63
|
+
}
|
|
64
|
+
compile() {
|
|
65
|
+
return {
|
|
66
|
+
importing: new RegExp(this.conf.importing, "i"),
|
|
67
|
+
exporting: new RegExp(this.conf.exporting, "i"),
|
|
68
|
+
changing: new RegExp(this.conf.changing, "i"),
|
|
69
|
+
tables: new RegExp(this.conf.tables, "i"),
|
|
70
|
+
ignorePatterns: name_validator_1.NameValidator.compileIgnorePatterns(this.conf),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
initialize(_reg) {
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
run(obj) {
|
|
77
|
+
if (this.conf.patternKind === undefined) {
|
|
78
|
+
this.conf.patternKind = "required";
|
|
79
|
+
}
|
|
80
|
+
if (!(obj instanceof function_group_1.FunctionGroup)) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
let ret = [];
|
|
84
|
+
for (const module of obj.getModules()) {
|
|
85
|
+
ret = ret.concat(this.checkModule(obj, module));
|
|
86
|
+
}
|
|
87
|
+
return ret;
|
|
88
|
+
}
|
|
89
|
+
checkModule(obj, module) {
|
|
90
|
+
const ret = [];
|
|
91
|
+
for (const p of module.getParameters()) {
|
|
92
|
+
let expected;
|
|
93
|
+
let regex;
|
|
94
|
+
switch (p.direction) {
|
|
95
|
+
case function_module_definition_1.FunctionModuleParameterDirection.importing:
|
|
96
|
+
expected = this.conf.importing;
|
|
97
|
+
regex = this.regex.importing;
|
|
98
|
+
break;
|
|
99
|
+
case function_module_definition_1.FunctionModuleParameterDirection.exporting:
|
|
100
|
+
expected = this.conf.exporting;
|
|
101
|
+
regex = this.regex.exporting;
|
|
102
|
+
break;
|
|
103
|
+
case function_module_definition_1.FunctionModuleParameterDirection.changing:
|
|
104
|
+
expected = this.conf.changing;
|
|
105
|
+
regex = this.regex.changing;
|
|
106
|
+
break;
|
|
107
|
+
case function_module_definition_1.FunctionModuleParameterDirection.tables:
|
|
108
|
+
expected = this.conf.tables;
|
|
109
|
+
regex = this.regex.tables;
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const issue = this.checkParameter(obj, module, p, expected, regex);
|
|
115
|
+
if (issue) {
|
|
116
|
+
ret.push(issue);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return ret;
|
|
120
|
+
}
|
|
121
|
+
checkParameter(obj, module, param, expected, regex) {
|
|
122
|
+
if (!name_validator_1.NameValidator.violatesRule(param.name, regex, this.conf, this.regex.ignorePatterns)) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
// the parameter is only defined in the XML, so report at the start of the module file, if it exists
|
|
126
|
+
const file = this.findModuleFile(obj, module) || obj.getMainABAPFile();
|
|
127
|
+
if (file === undefined) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const message = this.getDescription(expected, param.name);
|
|
131
|
+
return issue_1.Issue.atPosition(file, new position_1.Position(1, 1), message, this.getMetadata().key, this.conf.severity);
|
|
132
|
+
}
|
|
133
|
+
findModuleFile(obj, module) {
|
|
134
|
+
const search = "." + module.getName().toLowerCase().replace(/\//g, "#") + ".abap";
|
|
135
|
+
return obj.getABAPFiles().find(f => f.getFilename().toLowerCase().endsWith(search));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.FunctionModuleParameterNames = FunctionModuleParameterNames;
|
|
139
|
+
//# sourceMappingURL=function_module_parameter_names.js.map
|
package/build/src/rules/index.js
CHANGED
|
@@ -102,6 +102,7 @@ __exportStar(require("./forbidden_void_type"), exports);
|
|
|
102
102
|
__exportStar(require("./form_tables_obsolete"), exports);
|
|
103
103
|
__exportStar(require("./fully_type_constants"), exports);
|
|
104
104
|
__exportStar(require("./fully_type_itabs"), exports);
|
|
105
|
+
__exportStar(require("./function_module_parameter_names"), exports);
|
|
105
106
|
__exportStar(require("./function_module_recommendations"), exports);
|
|
106
107
|
__exportStar(require("./functional_writing"), exports);
|
|
107
108
|
__exportStar(require("./generic_regex"), exports);
|
|
@@ -230,6 +231,7 @@ __exportStar(require("./try_without_catch"), exports);
|
|
|
230
231
|
__exportStar(require("./type_form_parameters"), exports);
|
|
231
232
|
__exportStar(require("./types_naming"), exports);
|
|
232
233
|
__exportStar(require("./uncaught_exception"), exports);
|
|
234
|
+
__exportStar(require("./unhandled_classic_exception"), exports);
|
|
233
235
|
__exportStar(require("./unit_test_assertions"), exports);
|
|
234
236
|
__exportStar(require("./unknown_types"), exports);
|
|
235
237
|
__exportStar(require("./unnecessary_chaining"), exports);
|
|
@@ -40,6 +40,7 @@ const issue_1 = require("../issue");
|
|
|
40
40
|
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
41
41
|
const _abap_rule_1 = require("./_abap_rule");
|
|
42
42
|
const _irule_1 = require("./_irule");
|
|
43
|
+
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
43
44
|
class LoopTargetMisuseConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
44
45
|
constructor() {
|
|
45
46
|
super(...arguments);
|
|
@@ -48,6 +49,9 @@ class LoopTargetMisuseConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
|
48
49
|
/** Report LOOP AT ... INTO <fs> and READ TABLE ... INTO <fs> when the local field symbol is only bound by ASSIGNING,
|
|
49
50
|
* so the statement overwrites a table row */
|
|
50
51
|
this.intoFieldSymbol = true;
|
|
52
|
+
/** Report a field symbol of LOOP AT ... ASSIGNING used after ENDLOOP, and a field symbol of READ TABLE ... ASSIGNING
|
|
53
|
+
* used after the check of sy-subrc, outside the branch that found the row */
|
|
54
|
+
this.usedAfterLoop = true;
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
exports.LoopTargetMisuseConf = LoopTargetMisuseConf;
|
|
@@ -73,7 +77,21 @@ Option intoFieldSymbol: LOOP AT ... INTO <fs> or READ TABLE ... INTO <fs>. INTO
|
|
|
73
77
|
into the data object the field symbol points to. When <fs> was bound by ASSIGNING, that data
|
|
74
78
|
object is a row of a table, and the statement overwrites it. ASSIGNING was meant.
|
|
75
79
|
Reported only for a field symbol declared in the method, form or function module, and only when
|
|
76
|
-
no ASSIGN and no STRUCTURE ... DEFAULT binds it there, so it can only point to a table row
|
|
80
|
+
no ASSIGN and no STRUCTURE ... DEFAULT binds it there, so it can only point to a table row.
|
|
81
|
+
|
|
82
|
+
Option usedAfterLoop: a field symbol of LOOP AT ... ASSIGNING used after ENDLOOP. It points to
|
|
83
|
+
the last row the loop processed. When the loop processed no row, it is not assigned, and the use
|
|
84
|
+
raises GETWA_NOT_ASSIGNED, or it still points to what it was bound to before the loop.
|
|
85
|
+
Also a field symbol of READ TABLE ... ASSIGNING used after sy-subrc was checked, outside the
|
|
86
|
+
branch of that check. When the READ fails, the field symbol keeps its previous binding.
|
|
87
|
+
Reported at the first such use in the method, form or function module.
|
|
88
|
+
Not reported: a use inside IF, ELSEIF, CASE or WHILE whose condition reads sy-subrc, the table of
|
|
89
|
+
the loop or a variable the loop body sets (a flag), a use after such a check that leaves with
|
|
90
|
+
RETURN, EXIT, CONTINUE, CHECK, RAISE or MESSAGE or that does not use the field symbol, a use after
|
|
91
|
+
CHECK or ASSERT of such a condition, and any use after IS ASSIGNED, UNASSIGN or another binding of
|
|
92
|
+
the field symbol, or after a macro call. Work areas of INTO are not checked, they keep a value.
|
|
93
|
+
A READ TABLE whose sy-subrc is not checked at all is left to check_subrc, a LOOP inside a LOOP
|
|
94
|
+
with the same field symbol to the option nestedLoop.`,
|
|
77
95
|
tags: [_irule_1.RuleTag.SingleFile],
|
|
78
96
|
badExample: `LOOP AT lt_header INTO ls_row.
|
|
79
97
|
LOOP AT lt_items INTO ls_row WHERE parent = ls_row-id.
|
|
@@ -85,7 +103,12 @@ ENDLOOP.
|
|
|
85
103
|
|
|
86
104
|
LOOP AT lt_a ASSIGNING <ls_a>.
|
|
87
105
|
ENDLOOP.
|
|
88
|
-
READ TABLE lt_a INTO <ls_a> INDEX 1
|
|
106
|
+
READ TABLE lt_a INTO <ls_a> INDEX 1.
|
|
107
|
+
|
|
108
|
+
LOOP AT lt_a ASSIGNING <ls_a> WHERE id = lv_id.
|
|
109
|
+
EXIT.
|
|
110
|
+
ENDLOOP.
|
|
111
|
+
<ls_a>-flag = abap_true.`,
|
|
89
112
|
goodExample: `LOOP AT lt_header INTO ls_row.
|
|
90
113
|
LOOP AT lt_items INTO ls_item WHERE parent = ls_row-id.
|
|
91
114
|
lv_sum = lv_sum + ls_item-amount.
|
|
@@ -96,7 +119,14 @@ ENDLOOP.
|
|
|
96
119
|
|
|
97
120
|
LOOP AT lt_a ASSIGNING <ls_a>.
|
|
98
121
|
ENDLOOP.
|
|
99
|
-
READ TABLE lt_a ASSIGNING <ls_a> INDEX 1
|
|
122
|
+
READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.
|
|
123
|
+
|
|
124
|
+
LOOP AT lt_a ASSIGNING <ls_a> WHERE id = lv_id.
|
|
125
|
+
EXIT.
|
|
126
|
+
ENDLOOP.
|
|
127
|
+
IF sy-subrc = 0.
|
|
128
|
+
<ls_a>-flag = abap_true.
|
|
129
|
+
ENDIF.`,
|
|
100
130
|
};
|
|
101
131
|
}
|
|
102
132
|
getConfig() {
|
|
@@ -114,6 +144,14 @@ READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.`,
|
|
|
114
144
|
if (this.conf.intoFieldSymbol !== false) {
|
|
115
145
|
issues.push(...this.checkIntoFieldSymbol(file, statements));
|
|
116
146
|
}
|
|
147
|
+
if (this.conf.usedAfterLoop !== false) {
|
|
148
|
+
for (const issue of this.checkUsedAfterLoop(file, statements)) {
|
|
149
|
+
// a READ TABLE ... INTO <fs> after the loop is already reported by the option intoFieldSymbol
|
|
150
|
+
if (issues.some(i => i.getStart().equals(issue.getStart())) === false) {
|
|
151
|
+
issues.push(issue);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
117
155
|
return issues;
|
|
118
156
|
}
|
|
119
157
|
////////////////
|
|
@@ -170,7 +208,7 @@ READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.`,
|
|
|
170
208
|
let depth = 0;
|
|
171
209
|
for (let i = index + 1; i < statements.length && this.isBlockBoundary(statements[i]) === false; i++) {
|
|
172
210
|
const s = statements[i].get();
|
|
173
|
-
if (s instanceof Statements.Loop) {
|
|
211
|
+
if (s instanceof Statements.Loop || s instanceof Statements.LoopAtScreen || s instanceof Statements.LoopExtract) {
|
|
174
212
|
depth++;
|
|
175
213
|
}
|
|
176
214
|
else if (s instanceof Statements.EndLoop) {
|
|
@@ -279,6 +317,232 @@ READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.`,
|
|
|
279
317
|
var _a;
|
|
280
318
|
return (_a = fsTarget.findFirstExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
|
|
281
319
|
}
|
|
320
|
+
checkUsedAfterLoop(file, statements) {
|
|
321
|
+
var _a;
|
|
322
|
+
const issues = [];
|
|
323
|
+
// the field symbols of the open LOOPs, undefined for a LOOP without field symbol
|
|
324
|
+
let open = [];
|
|
325
|
+
for (let i = 0; i < statements.length; i++) {
|
|
326
|
+
const statement = statements[i];
|
|
327
|
+
const s = statement.get();
|
|
328
|
+
if (this.isBlockBoundary(statement)) {
|
|
329
|
+
open = [];
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
else if (s instanceof Statements.EndLoop) {
|
|
333
|
+
open.pop();
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
let use = undefined;
|
|
337
|
+
let name = undefined;
|
|
338
|
+
let what = "";
|
|
339
|
+
if (s instanceof Statements.Loop) {
|
|
340
|
+
const node = this.loopTarget(statement);
|
|
341
|
+
name = (node === null || node === void 0 ? void 0 : node.get()) instanceof Expressions.FSTarget ? this.targetName(node) : undefined;
|
|
342
|
+
const end = this.findEndLoop(statements, i);
|
|
343
|
+
// a LOOP inside a LOOP with the same field symbol is left to the option nestedLoop
|
|
344
|
+
if (name !== undefined && end !== undefined && open.includes(name) === false) {
|
|
345
|
+
const guards = this.loopGuards(statements, i, end, name);
|
|
346
|
+
use = this.findUncheckedUse(statements, end + 1, name, guards, false);
|
|
347
|
+
what = `after ENDLOOP, it points to the last row, or is not assigned when the loop processed no row`;
|
|
348
|
+
}
|
|
349
|
+
open.push(name);
|
|
350
|
+
}
|
|
351
|
+
else if (s instanceof Statements.LoopAtScreen || s instanceof Statements.LoopExtract) {
|
|
352
|
+
open.push(undefined);
|
|
353
|
+
}
|
|
354
|
+
else if (s instanceof Statements.ReadTable) {
|
|
355
|
+
const fs = (_a = statement.findDirectExpression(Expressions.ReadTableTarget)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.FSTarget);
|
|
356
|
+
name = fs ? this.targetName(fs) : undefined;
|
|
357
|
+
if (name !== undefined) {
|
|
358
|
+
use = this.findUncheckedUse(statements, i + 1, name, new Set(), true);
|
|
359
|
+
what = `outside the check of sy-subrc, when the READ TABLE fails it is not assigned or points to an earlier row`;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (use !== undefined && name !== undefined) {
|
|
363
|
+
const token = statements[use].getTokens().find(t => t.getStr().toUpperCase() === name);
|
|
364
|
+
const message = `${token === null || token === void 0 ? void 0 : token.getStr()} is used ${what}`;
|
|
365
|
+
issues.push(issue_1.Issue.atStatement(file, statements[use], message, this.getMetadata().key, this.conf.severity));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return issues;
|
|
369
|
+
}
|
|
370
|
+
/** upper case names of the variables whose check counts as a check that the LOOP processed a row:
|
|
371
|
+
* the table and the variables the loop body writes */
|
|
372
|
+
loopGuards(statements, loop, end, name) {
|
|
373
|
+
var _a;
|
|
374
|
+
const guards = new Set();
|
|
375
|
+
const first = (_a = statements[loop].findDirectExpression(Expressions.LoopSource)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr().toUpperCase();
|
|
376
|
+
if (first !== undefined) {
|
|
377
|
+
guards.add(first);
|
|
378
|
+
}
|
|
379
|
+
for (let i = loop + 1; i < end; i++) {
|
|
380
|
+
for (const target of statements[i].findAllExpressions(Expressions.Target)) {
|
|
381
|
+
guards.add(this.firstName(target));
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
guards.delete(name);
|
|
385
|
+
return guards;
|
|
386
|
+
}
|
|
387
|
+
/** upper case name of the variable a Target writes, also declared inline */
|
|
388
|
+
firstName(target) {
|
|
389
|
+
const inline = target.findFirstExpression(Expressions.TargetField);
|
|
390
|
+
return (inline ? inline.getFirstToken() : target.getFirstToken()).getStr().toUpperCase();
|
|
391
|
+
}
|
|
392
|
+
/** index of the first statement from the index on that uses the field symbol without a check before it,
|
|
393
|
+
* looking until the end of the method, form or function module or until the field symbol is bound again.
|
|
394
|
+
* With checkFirst, only a use after a check is returned, an unchecked READ TABLE is left to check_subrc */
|
|
395
|
+
findUncheckedUse(statements, from, name, guards, checkFirst) {
|
|
396
|
+
const frames = [];
|
|
397
|
+
let checked = false;
|
|
398
|
+
let sawCheck = false;
|
|
399
|
+
for (let i = from; i < statements.length && this.isBlockBoundary(statements[i]) === false; i++) {
|
|
400
|
+
const statement = statements[i];
|
|
401
|
+
const s = statement.get();
|
|
402
|
+
if (s instanceof _statement_1.MacroCall || s instanceof _statement_1.Unknown || this.bindsOrTests(statement, name)) {
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
405
|
+
const isCondition = s instanceof Statements.If || s instanceof Statements.ElseIf || s instanceof Statements.Case
|
|
406
|
+
|| s instanceof Statements.When || s instanceof Statements.While
|
|
407
|
+
|| s instanceof Statements.Check || s instanceof Statements.Assert;
|
|
408
|
+
const guard = isCondition && this.isGuard(statement, guards);
|
|
409
|
+
sawCheck = sawCheck || guard;
|
|
410
|
+
if ((s instanceof Statements.Check || s instanceof Statements.Assert) && guard) {
|
|
411
|
+
checked = true;
|
|
412
|
+
}
|
|
413
|
+
if (s instanceof Statements.FieldSymbol === false && this.mentions(statement, name)) {
|
|
414
|
+
if (guard || checked || frames.some(f => f.guard)) {
|
|
415
|
+
frames.forEach(f => f.uses = true);
|
|
416
|
+
}
|
|
417
|
+
else if (checkFirst === false || sawCheck === true) {
|
|
418
|
+
return i;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (guard || frames.some(f => f.guard)) {
|
|
422
|
+
// a flag set where the check holds, like lv_found = abap_true, checks it as well
|
|
423
|
+
for (const target of statement.findAllExpressions(Expressions.Target)) {
|
|
424
|
+
guards.add(this.firstName(target));
|
|
425
|
+
}
|
|
426
|
+
guards.delete(name);
|
|
427
|
+
}
|
|
428
|
+
if (this.leaves(statement)) {
|
|
429
|
+
frames.forEach(f => f.leaves = true);
|
|
430
|
+
}
|
|
431
|
+
if (this.opensBlock(statement)) {
|
|
432
|
+
frames.push({ guard, uses: false, leaves: false });
|
|
433
|
+
}
|
|
434
|
+
else if (this.isBranch(statement)) {
|
|
435
|
+
if (frames.length === 0) {
|
|
436
|
+
// another branch of a block around the binding, it does not run after it
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
frames[frames.length - 1].guard = frames[frames.length - 1].guard || guard;
|
|
440
|
+
}
|
|
441
|
+
else if (this.closesBlock(statement)) {
|
|
442
|
+
const frame = frames.pop();
|
|
443
|
+
// IF sy-subrc <> 0. RETURN. ENDIF., or a check that sets a flag
|
|
444
|
+
if (frame && frame.guard && (frame.leaves || frame.uses === false)) {
|
|
445
|
+
checked = true;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
451
|
+
/** true when the statement binds the field symbol again, unassigns it, or checks IS ASSIGNED */
|
|
452
|
+
bindsOrTests(statement, name) {
|
|
453
|
+
if (statement.get() instanceof Statements.Unassign && this.mentions(statement, name)) {
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
for (const fsTarget of statement.findAllExpressions(Expressions.FSTarget)) {
|
|
457
|
+
if (this.targetName(fsTarget) === name) {
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
const tokens = statement.getTokens().map(t => t.getStr().toUpperCase());
|
|
462
|
+
for (let i = 0; i < tokens.length - 2; i++) {
|
|
463
|
+
if (tokens[i] === name && tokens[i + 1] === "IS"
|
|
464
|
+
&& (tokens[i + 2] === "ASSIGNED" || (tokens[i + 2] === "NOT" && tokens[i + 3] === "ASSIGNED"))) {
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
/** true when the condition reads sy-subrc or one of the variables */
|
|
471
|
+
isGuard(statement, guards) {
|
|
472
|
+
var _a, _b;
|
|
473
|
+
const tokens = statement.getTokens();
|
|
474
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
475
|
+
const str = tokens[i].getStr().toUpperCase();
|
|
476
|
+
const previous = i > 0 ? tokens[i - 1].getStr() : "";
|
|
477
|
+
if (["-", "->", "=>", "~"].includes(previous)) {
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if ((str === "SY" && ((_a = tokens[i + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "-" && ((_b = tokens[i + 2]) === null || _b === void 0 ? void 0 : _b.getStr().toUpperCase()) === "SUBRC")
|
|
481
|
+
|| guards.has(str)) {
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
mentions(statement, name) {
|
|
488
|
+
return statement.getTokens().some(t => t.getStr().toUpperCase() === name);
|
|
489
|
+
}
|
|
490
|
+
/** true for a statement that can leave the current block, a call of a method named like RAISE counts */
|
|
491
|
+
leaves(statement) {
|
|
492
|
+
const s = statement.get();
|
|
493
|
+
return s instanceof Statements.Return
|
|
494
|
+
|| s instanceof Statements.Exit
|
|
495
|
+
|| s instanceof Statements.Continue
|
|
496
|
+
|| s instanceof Statements.Check
|
|
497
|
+
|| s instanceof Statements.Raise
|
|
498
|
+
|| s instanceof Statements.Leave
|
|
499
|
+
|| s instanceof Statements.Message
|
|
500
|
+
|| s instanceof Statements.Assert
|
|
501
|
+
|| (s instanceof Statements.Call && statement.getTokens().some(t => /raise/i.test(t.getStr())));
|
|
502
|
+
}
|
|
503
|
+
opensBlock(statement) {
|
|
504
|
+
const s = statement.get();
|
|
505
|
+
return s instanceof Statements.If
|
|
506
|
+
|| s instanceof Statements.Case
|
|
507
|
+
|| s instanceof Statements.CaseType
|
|
508
|
+
|| s instanceof Statements.Loop
|
|
509
|
+
|| s instanceof Statements.LoopAtScreen
|
|
510
|
+
|| s instanceof Statements.LoopExtract
|
|
511
|
+
|| s instanceof Statements.Do
|
|
512
|
+
|| s instanceof Statements.While
|
|
513
|
+
|| s instanceof Statements.Try
|
|
514
|
+
|| s instanceof Statements.SelectLoop
|
|
515
|
+
|| s instanceof Statements.At
|
|
516
|
+
|| s instanceof Statements.AtFirst
|
|
517
|
+
|| s instanceof Statements.AtLast
|
|
518
|
+
|| s instanceof Statements.OnChange
|
|
519
|
+
|| s instanceof Statements.Provide
|
|
520
|
+
|| s instanceof Statements.CatchSystemExceptions;
|
|
521
|
+
}
|
|
522
|
+
isBranch(statement) {
|
|
523
|
+
const s = statement.get();
|
|
524
|
+
return s instanceof Statements.ElseIf
|
|
525
|
+
|| s instanceof Statements.Else
|
|
526
|
+
|| s instanceof Statements.When
|
|
527
|
+
|| s instanceof Statements.WhenOthers
|
|
528
|
+
|| s instanceof Statements.WhenType
|
|
529
|
+
|| s instanceof Statements.Catch
|
|
530
|
+
|| s instanceof Statements.Cleanup;
|
|
531
|
+
}
|
|
532
|
+
closesBlock(statement) {
|
|
533
|
+
const s = statement.get();
|
|
534
|
+
return s instanceof Statements.EndIf
|
|
535
|
+
|| s instanceof Statements.EndCase
|
|
536
|
+
|| s instanceof Statements.EndLoop
|
|
537
|
+
|| s instanceof Statements.EndDo
|
|
538
|
+
|| s instanceof Statements.EndWhile
|
|
539
|
+
|| s instanceof Statements.EndTry
|
|
540
|
+
|| s instanceof Statements.EndSelect
|
|
541
|
+
|| s instanceof Statements.EndAt
|
|
542
|
+
|| s instanceof Statements.EndOn
|
|
543
|
+
|| s instanceof Statements.EndProvide
|
|
544
|
+
|| s instanceof Statements.EndCatch;
|
|
545
|
+
}
|
|
282
546
|
isBlockBoundary(statement) {
|
|
283
547
|
return this.startsBlock(statement) || this.endsBlock(statement);
|
|
284
548
|
}
|
|
@@ -109,8 +109,16 @@ text = text.`,
|
|
|
109
109
|
if (structure === undefined) {
|
|
110
110
|
continue;
|
|
111
111
|
}
|
|
112
|
+
const sources = structure.findAllExpressionsRecursive(Expressions.Source);
|
|
113
|
+
// Sources that are an operand of an enclosing Source, e.g. "2 * CONV i( a + b )" or "- CONV i( a + b )"
|
|
114
|
+
const operands = new Set();
|
|
115
|
+
for (const source of sources) {
|
|
116
|
+
if (source.getChildren().length > 1) {
|
|
117
|
+
source.findDirectExpressions(Expressions.Source).forEach(operand => operands.add(operand));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
112
120
|
// recursive, a CONV can be the argument of a built-in function, which is itself a Source
|
|
113
|
-
for (const source of
|
|
121
|
+
for (const source of sources) {
|
|
114
122
|
if (source.getFirstToken().getStr().toUpperCase() !== "CONV") {
|
|
115
123
|
continue;
|
|
116
124
|
}
|
|
@@ -143,8 +151,12 @@ text = text.`,
|
|
|
143
151
|
if (closingParen === undefined) {
|
|
144
152
|
continue;
|
|
145
153
|
}
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
// parentheses are only needed when the CONV takes part in a surrounding operation,
|
|
155
|
+
// "CONV type ( body )" alone has 5 children, more means a trailing operator
|
|
156
|
+
const partOfOperation = source.getChildren().length !== 5 || operands.has(source);
|
|
157
|
+
const preserveParentheses = partOfOperation
|
|
158
|
+
&& (bodySource.findDirectExpression(Expressions.ArithOperator) !== undefined
|
|
159
|
+
|| bodySource.findDirectTokenByText("&&") !== undefined);
|
|
148
160
|
// Apply the later edit first so the original positions remain valid when
|
|
149
161
|
// both parts of the CONV wrapper are changed on the same line.
|
|
150
162
|
const fix = edit_helper_1.EditHelper.merge(edit_helper_1.EditHelper.replaceRange(file, bodySource.getLastToken().getEnd(), closingParen.getEnd(), preserveParentheses ? ")" : ""), edit_helper_1.EditHelper.replaceRange(file, source.getFirstToken().getStart(), bodySource.getFirstToken().getStart(), preserveParentheses ? "(" : ""));
|
|
@@ -41,6 +41,15 @@ const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
|
41
41
|
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
42
42
|
const _irule_1 = require("./_irule");
|
|
43
43
|
class RFCErrorHandlingConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
44
|
+
constructor() {
|
|
45
|
+
super(...arguments);
|
|
46
|
+
/** Also check CALL FUNCTION ... STARTING NEW TASK without DESTINATION, an asynchronous RFC to the destination NONE */
|
|
47
|
+
this.startingNewTask = true;
|
|
48
|
+
/** Report error_message in the EXCEPTIONS of an RFC call, it is ignored in RFC */
|
|
49
|
+
this.errorMessage = true;
|
|
50
|
+
/** Report SYSTEM_FAILURE and COMMUNICATION_FAILURE without the addition MESSAGE, the error text is lost */
|
|
51
|
+
this.requireMessage = false;
|
|
52
|
+
}
|
|
44
53
|
}
|
|
45
54
|
exports.RFCErrorHandlingConf = RFCErrorHandlingConf;
|
|
46
55
|
class RFCErrorHandling extends _abap_rule_1.ABAPRule {
|
|
@@ -56,11 +65,35 @@ class RFCErrorHandling extends _abap_rule_1.ABAPRule {
|
|
|
56
65
|
shortDescription: `Checks that exceptions 'system_failure' and 'communication_failure' are handled in RFC calls`,
|
|
57
66
|
extendedInformation: `RESOURCE_FAILURE is also required for asynchronous calls with DESTINATION IN GROUP.
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
Checked are CALL FUNCTION ... DESTINATION and, with startingNewTask, CALL FUNCTION ... STARTING NEW TASK
|
|
69
|
+
without DESTINATION, which is an asynchronous RFC to the destination NONE.
|
|
70
|
+
CALL FUNCTION ... IN BACKGROUND TASK is not checked, it cannot have EXCEPTIONS.
|
|
71
|
+
|
|
72
|
+
errorMessage: reports error_message in the EXCEPTIONS of an RFC call. It is ignored in RFC, a message of
|
|
73
|
+
type A, E or X ends the called function module and raises SYSTEM_FAILURE, use system_failure = n MESSAGE msg
|
|
74
|
+
to get the message text. Exception: with a DESTINATION that is blank at runtime, the call is local.
|
|
75
|
+
|
|
76
|
+
requireMessage: reports SYSTEM_FAILURE and COMMUNICATION_FAILURE without the addition MESSAGE.
|
|
77
|
+
|
|
78
|
+
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenrfc_exception.html
|
|
79
|
+
https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapcall_function_destination_para.html`,
|
|
60
80
|
badExample: `CALL FUNCTION 'ZRFC'
|
|
61
|
-
DESTINATION lv_rfc
|
|
81
|
+
DESTINATION lv_rfc.
|
|
82
|
+
|
|
83
|
+
CALL FUNCTION 'ZRFC'
|
|
84
|
+
STARTING NEW TASK 'TASK'
|
|
85
|
+
EXCEPTIONS
|
|
86
|
+
error_message = 1
|
|
87
|
+
OTHERS = 2.`,
|
|
62
88
|
goodExample: `CALL FUNCTION 'ZRFC'
|
|
63
89
|
DESTINATION lv_rfc
|
|
90
|
+
EXCEPTIONS
|
|
91
|
+
system_failure = 1 MESSAGE msg
|
|
92
|
+
communication_failure = 2 MESSAGE msg
|
|
93
|
+
OTHERS = 3.
|
|
94
|
+
|
|
95
|
+
CALL FUNCTION 'ZRFC'
|
|
96
|
+
STARTING NEW TASK 'TASK'
|
|
64
97
|
EXCEPTIONS
|
|
65
98
|
system_failure = 1 MESSAGE msg
|
|
66
99
|
communication_failure = 2 MESSAGE msg
|
|
@@ -85,28 +118,45 @@ https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenrfc_exceptio
|
|
|
85
118
|
continue;
|
|
86
119
|
}
|
|
87
120
|
const destination = stat.findFirstExpression(Expressions.Destination);
|
|
88
|
-
|
|
121
|
+
const starting = stat.findDirectTokenByText("STARTING") !== undefined;
|
|
122
|
+
if (destination === undefined && (starting === false || this.conf.startingNewTask === false)) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (stat.findDirectTokenByText("BACKGROUND") !== undefined) {
|
|
126
|
+
// transactional RFC, it has no EXCEPTIONS
|
|
89
127
|
continue;
|
|
90
128
|
}
|
|
91
|
-
const requireResourceFailure =
|
|
92
|
-
&& destination.findDirectTokenByText("GROUP") !== undefined;
|
|
129
|
+
const requireResourceFailure = starting === true
|
|
130
|
+
&& (destination === null || destination === void 0 ? void 0 : destination.findDirectTokenByText("GROUP")) !== undefined;
|
|
93
131
|
const list = stat.findFirstExpression(Expressions.ParameterListExceptions);
|
|
94
132
|
if (list === undefined) {
|
|
95
133
|
const issue = issue_1.Issue.atToken(file, token, this.getMessage(requireResourceFailure), this.getMetadata().key, this.conf.severity);
|
|
96
134
|
output.push(issue);
|
|
97
135
|
continue;
|
|
98
136
|
}
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
names.push(par.getFirstToken().getStr().toUpperCase());
|
|
137
|
+
const exceptions = new Map();
|
|
138
|
+
for (const exception of list.findDirectExpressions(Expressions.ParameterException)) {
|
|
139
|
+
exceptions.set(exception.getFirstToken().getStr().toUpperCase(), exception);
|
|
103
140
|
}
|
|
104
|
-
if (
|
|
105
|
-
||
|
|
106
|
-
|| (requireResourceFailure &&
|
|
141
|
+
if (exceptions.has("SYSTEM_FAILURE") === false
|
|
142
|
+
|| exceptions.has("COMMUNICATION_FAILURE") === false
|
|
143
|
+
|| (requireResourceFailure && exceptions.has("RESOURCE_FAILURE") === false)) {
|
|
107
144
|
const issue = issue_1.Issue.atToken(file, token, this.getMessage(requireResourceFailure), this.getMetadata().key, this.conf.severity);
|
|
108
145
|
output.push(issue);
|
|
109
|
-
|
|
146
|
+
}
|
|
147
|
+
const errorMessage = exceptions.get("ERROR_MESSAGE");
|
|
148
|
+
if (this.conf.errorMessage !== false && errorMessage !== undefined) {
|
|
149
|
+
const message = "error_message is ignored in RFC, messages of type A, E and X raise SYSTEM_FAILURE, use system_failure = n MESSAGE msg";
|
|
150
|
+
output.push(issue_1.Issue.atToken(file, errorMessage.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
|
|
151
|
+
}
|
|
152
|
+
if (this.conf.requireMessage === true) {
|
|
153
|
+
for (const name of ["SYSTEM_FAILURE", "COMMUNICATION_FAILURE"]) {
|
|
154
|
+
const exception = exceptions.get(name);
|
|
155
|
+
if (exception !== undefined && exception.findDirectTokenByText("MESSAGE") === undefined) {
|
|
156
|
+
const message = `${name} without MESSAGE, the error text is lost, use ${name.toLowerCase()} = n MESSAGE msg`;
|
|
157
|
+
output.push(issue_1.Issue.atToken(file, exception.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
110
160
|
}
|
|
111
161
|
}
|
|
112
162
|
return output;
|