@abaplint/core 2.120.109 → 2.120.111
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 +24 -0
- 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/_current_scope.js +64 -0
- package/build/src/abap/5_syntax/expressions/for.js +38 -4
- package/build/src/abap/5_syntax/expressions/inline_field_definition.js +2 -2
- package/build/src/abap/5_syntax/expressions/inline_loop_definition.js +18 -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/statements/loop.js +12 -1
- package/build/src/abap/5_syntax/statements/move.js +8 -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 +4 -0
- package/build/src/rules/sort_required.js +487 -0
- package/build/src/rules/suspicious_loop.js +333 -0
- package/build/src/rules/unhandled_classic_exception.js +278 -0
- package/package.json +2 -2
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SuspiciousLoop = exports.SuspiciousLoopConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
39
|
+
const Structures = __importStar(require("../abap/3_structures/structures"));
|
|
40
|
+
const nodes_1 = require("../abap/nodes");
|
|
41
|
+
const _reference_1 = require("../abap/5_syntax/_reference");
|
|
42
|
+
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
|
|
43
|
+
const issue_1 = require("../issue");
|
|
44
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
45
|
+
const severity_1 = require("../severity");
|
|
46
|
+
const _procedure_analysis_1 = require("./_procedure_analysis");
|
|
47
|
+
class SuspiciousLoopConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
48
|
+
constructor() {
|
|
49
|
+
super(...arguments);
|
|
50
|
+
this.severity = severity_1.Severity.Warning;
|
|
51
|
+
/** Report WHILE loops whose condition the loop body never changes, or sets to the same value in every iteration.
|
|
52
|
+
* The loop runs zero times, once or forever */
|
|
53
|
+
this.unchangedCondition = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.SuspiciousLoopConf = SuspiciousLoopConf;
|
|
57
|
+
const NESTED_LOOPS = [Structures.Loop, Structures.Do, Structures.While, Structures.Select,
|
|
58
|
+
Structures.Provide, Structures.LoopAtScreen, Structures.LoopExtract];
|
|
59
|
+
/** statements that leave the loop, or may leave it, wherever they are in the loop body */
|
|
60
|
+
const LEAVING = [Statements.Return, Statements.Raise, Statements.Message, Statements.Leave,
|
|
61
|
+
Statements.Submit, Statements.Stop, Statements.Reject];
|
|
62
|
+
/** statements which run no other code than the method calls they contain */
|
|
63
|
+
const CALLING = [Statements.Call, Statements.Move, Statements.If, Statements.ElseIf,
|
|
64
|
+
Statements.Case, Statements.When, Statements.Append, Statements.InsertInternal, Statements.Concatenate];
|
|
65
|
+
class SuspiciousLoop {
|
|
66
|
+
constructor() {
|
|
67
|
+
this.conf = new SuspiciousLoopConf();
|
|
68
|
+
}
|
|
69
|
+
getMetadata() {
|
|
70
|
+
return {
|
|
71
|
+
key: "suspicious_loop",
|
|
72
|
+
title: "Suspicious loop",
|
|
73
|
+
shortDescription: `Finds WHILE loops whose condition the loop body never changes`,
|
|
74
|
+
extendedInformation: `Option unchangedCondition: reports a WHILE loop when the loop body cannot change its condition
|
|
75
|
+
after the first iteration. Then the loop runs zero times, once or forever.
|
|
76
|
+
|
|
77
|
+
The condition may read local variables of the METHOD, FORM or FUNCTION, constants, builtin functions
|
|
78
|
+
like lines( ), and attributes and parameters without ->. Each local variable in it is either
|
|
79
|
+
* not written in the loop body, or
|
|
80
|
+
* only written by var = source. directly in the loop body, not in a nested block, where the source is
|
|
81
|
+
the same in every iteration: no method calls, field symbols or ->*, and it only reads constants,
|
|
82
|
+
local variables that the loop body does not write, and other data that the loop body does not write.
|
|
83
|
+
Attributes and parameters in the condition must not be written in the loop body either.
|
|
84
|
+
|
|
85
|
+
When the condition or a source reads data that is not local, the loop body must not call methods,
|
|
86
|
+
functions or forms, except instance methods via local reference variables, and must not write via
|
|
87
|
+
field symbols or ->*. A source that reads local->attribute also needs that the loop body calls no
|
|
88
|
+
method via that local.
|
|
89
|
+
|
|
90
|
+
Not reported: conditions with system fields like sy-subrc, field symbols, -> or method calls, local
|
|
91
|
+
variables whose address is taken, loop bodies with EXIT, RETURN, RAISE, MESSAGE, LEAVE, SUBMIT, STOP or
|
|
92
|
+
REJECT, and, when the condition variables are written, loop bodies with CONTINUE or CHECK.
|
|
93
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
94
|
+
INCLUDE, test seams, enhancements or native SQL.`,
|
|
95
|
+
tags: [],
|
|
96
|
+
badExample: `DATA(lo_x) = previous.
|
|
97
|
+
WHILE lo_x IS BOUND.
|
|
98
|
+
result = result && lo_x->get_text( ).
|
|
99
|
+
lo_x = previous->previous.
|
|
100
|
+
ENDWHILE.`,
|
|
101
|
+
goodExample: `DATA(lo_x) = previous.
|
|
102
|
+
WHILE lo_x IS BOUND.
|
|
103
|
+
result = result && lo_x->get_text( ).
|
|
104
|
+
lo_x = lo_x->previous.
|
|
105
|
+
ENDWHILE.`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
getConfig() {
|
|
109
|
+
return this.conf;
|
|
110
|
+
}
|
|
111
|
+
setConfig(conf) {
|
|
112
|
+
this.conf = conf;
|
|
113
|
+
}
|
|
114
|
+
initialize(reg) {
|
|
115
|
+
this.reg = reg;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
run(obj) {
|
|
119
|
+
if (this.conf.unchangedCondition === false) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
123
|
+
if (analysis === undefined) {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
const issues = [];
|
|
127
|
+
for (const procedure of analysis.procedures) {
|
|
128
|
+
if (procedure.supported === false) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
for (const loop of procedure.structure.findAllStructuresRecursive(Structures.While)) {
|
|
132
|
+
const issue = this.unchangedCondition(procedure, loop);
|
|
133
|
+
if (issue !== undefined) {
|
|
134
|
+
issues.push(issue);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return issues;
|
|
139
|
+
}
|
|
140
|
+
////////////////
|
|
141
|
+
unchangedCondition(procedure, loop) {
|
|
142
|
+
const statement = loop.findDirectStatement(Statements.While);
|
|
143
|
+
const end = loop.findDirectStatement(Statements.EndWhile);
|
|
144
|
+
const cond = statement === null || statement === void 0 ? void 0 : statement.findDirectExpression(Expressions.Cond);
|
|
145
|
+
if (statement === undefined || end === undefined || cond === undefined
|
|
146
|
+
|| statement.findDirectTokenByText("VARY") !== undefined
|
|
147
|
+
|| cond.getAllTokens().some(t => t.getStr() === "->")) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
const reads = this.reads(procedure, cond);
|
|
151
|
+
if (reads === undefined || reads.locals.length + reads.others.length === 0) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
const from = procedure.index(statement);
|
|
155
|
+
const to = procedure.index(end);
|
|
156
|
+
const body = loop.findDirectStructure(Structures.Body);
|
|
157
|
+
let continues = false;
|
|
158
|
+
for (const found of body === undefined ? [] : this.loopControl(body, false)) {
|
|
159
|
+
const type = found.get();
|
|
160
|
+
if (type instanceof Statements.Continue || type instanceof Statements.Check) {
|
|
161
|
+
continues = true;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (reads.others.some(o => this.writtenIn(procedure, o, from, to))
|
|
168
|
+
|| (reads.others.length > 0 && this.mayChangeOtherData(procedure, from, to, []))) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
let written = undefined;
|
|
172
|
+
for (const variable of reads.locals) {
|
|
173
|
+
for (const write of variable.writes()) {
|
|
174
|
+
if (write.index <= from || write.index >= to) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
else if (continues || body === undefined
|
|
178
|
+
|| this.sameValueWrite(procedure, write.statement, write.token, body, from, to) === false) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
written = variable.identifier.getName();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const names = [...reads.locals.map(v => v.identifier.getName()), ...reads.others.map(o => o.getName())].join(", ");
|
|
185
|
+
const message = written === undefined
|
|
186
|
+
? `WHILE condition never changes, the loop body does not write ${names}, the loop runs zero times or forever`
|
|
187
|
+
: `WHILE condition does not change after the first iteration, the loop body sets ${written} `
|
|
188
|
+
+ `to the same value in every iteration, the loop runs once or forever`;
|
|
189
|
+
return issue_1.Issue.atStatement(procedure.file, statement, message, this.getMetadata().key, this.conf.severity);
|
|
190
|
+
}
|
|
191
|
+
/** data read by the condition or source, undefined if it reads anything that can change unseen */
|
|
192
|
+
reads(procedure, node) {
|
|
193
|
+
var _a;
|
|
194
|
+
if (node.findFirstExpression(Expressions.SourceFieldSymbol) !== undefined
|
|
195
|
+
|| node.findFirstExpression(Expressions.Dereference) !== undefined
|
|
196
|
+
|| node.findFirstExpression(Expressions.NewObject) !== undefined) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
for (const call of node.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
200
|
+
if (this.isBuiltinCall(procedure, call) === false) {
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const ret = { locals: [], others: [], receivers: [] };
|
|
205
|
+
const tokens = node.getAllTokens();
|
|
206
|
+
for (const field of [...node.findAllExpressionsRecursive(Expressions.SourceField),
|
|
207
|
+
...node.findAllExpressionsRecursive(Expressions.AttributeName)]) {
|
|
208
|
+
const token = field.getFirstToken();
|
|
209
|
+
const identifier = procedure.identifierAt(token);
|
|
210
|
+
if ((0, _procedure_analysis_1.isImmutable)(identifier)) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const local = procedure.local(identifier);
|
|
214
|
+
if (local !== undefined) {
|
|
215
|
+
if (local.escapes()) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
if (ret.locals.includes(local) === false) {
|
|
219
|
+
ret.locals.push(local);
|
|
220
|
+
}
|
|
221
|
+
const index = tokens.findIndex(t => t.getStart().equals(token.getStart()));
|
|
222
|
+
if (((_a = tokens[index + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "->") {
|
|
223
|
+
ret.receivers.push(local);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (!(identifier instanceof _typed_identifier_1.TypedIdentifier)
|
|
227
|
+
|| identifier.getMeta().includes("built-in" /* IdentifierMeta.BuiltIn */)) {
|
|
228
|
+
// unknown, or system fields like sy-subrc, which change without a write reference
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
else if (ret.others.includes(identifier) === false) {
|
|
232
|
+
ret.others.push(identifier);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return ret;
|
|
236
|
+
}
|
|
237
|
+
isBuiltinCall(procedure, call) {
|
|
238
|
+
var _a;
|
|
239
|
+
const name = (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
240
|
+
if (name === undefined) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const references = procedure.analysis.referencesAt(procedure.file.getFilename(), name);
|
|
244
|
+
return references.length > 0 && references.every(r => r.referenceType === _reference_1.ReferenceType.BuiltinMethodReference);
|
|
245
|
+
}
|
|
246
|
+
/** statements in the loop body that leave the loop or go to its next iteration */
|
|
247
|
+
loopControl(node, nested) {
|
|
248
|
+
const ret = [];
|
|
249
|
+
for (const child of node.getChildren()) {
|
|
250
|
+
if (child instanceof nodes_1.StructureNode) {
|
|
251
|
+
ret.push(...this.loopControl(child, nested || NESTED_LOOPS.some(l => child.get() instanceof l)));
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const type = child.get();
|
|
255
|
+
if (LEAVING.some(l => type instanceof l)
|
|
256
|
+
|| (nested === false && (type instanceof Statements.Exit
|
|
257
|
+
|| type instanceof Statements.Continue || type instanceof Statements.Check))) {
|
|
258
|
+
ret.push(child);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return ret;
|
|
262
|
+
}
|
|
263
|
+
/** var = source. directly in the loop body, the source has the same value in every iteration */
|
|
264
|
+
sameValueWrite(procedure, statement, token, body, from, to) {
|
|
265
|
+
const move = (0, _procedure_analysis_1.plainMove)(statement);
|
|
266
|
+
if (move === undefined || move.operator !== "=" || (0, _procedure_analysis_1.singleTarget)(move.target) !== token
|
|
267
|
+
|| procedure.block(statement) !== body || procedure.isSimple(statement) === false) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
const reads = this.reads(procedure, move.source);
|
|
271
|
+
if (reads === undefined
|
|
272
|
+
|| reads.locals.some(l => l.writes().some(w => w.index > from && w.index < to))
|
|
273
|
+
|| reads.others.some(o => this.writtenIn(procedure, o, from, to))) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
return reads.others.length === 0 || this.mayChangeOtherData(procedure, from, to, reads.receivers) === false;
|
|
277
|
+
}
|
|
278
|
+
writtenIn(procedure, identifier, from, to) {
|
|
279
|
+
for (const reference of procedure.analysis.referencesTo(identifier)) {
|
|
280
|
+
if (reference.referenceType !== _reference_1.ReferenceType.DataWriteReference || !procedure.contains(reference.position)) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const statement = procedure.statementOf(reference.position.getToken());
|
|
284
|
+
const index = statement === undefined ? -1 : procedure.index(statement);
|
|
285
|
+
if (index > from && index < to) {
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
/** the loop body calls methods, functions or forms, or writes via field symbols or ->*, which can change
|
|
292
|
+
* attributes and other data that is not local; instance methods via local reference variables are accepted,
|
|
293
|
+
* unless the variable is one of the receivers */
|
|
294
|
+
mayChangeOtherData(procedure, from, to, receivers) {
|
|
295
|
+
for (let index = from + 1; index < to; index++) {
|
|
296
|
+
const statement = procedure.statements[index];
|
|
297
|
+
if (statement.findFirstExpression(Expressions.TargetFieldSymbol) !== undefined
|
|
298
|
+
|| statement.findFirstExpression(Expressions.Dereference) !== undefined) {
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
else if (procedure.isCallFree(statement)) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const type = statement.get();
|
|
305
|
+
if (!CALLING.some(c => type instanceof c) || statement.findFirstExpression(Expressions.NewObject) !== undefined) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
const tokens = procedure.tokensOf(statement);
|
|
309
|
+
const methodSource = statement.findDirectExpression(Expressions.MethodSource);
|
|
310
|
+
if (methodSource !== undefined && this.localReceiver(procedure, tokens, methodSource.getLastToken(), receivers) === false) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
for (const call of statement.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
314
|
+
if (this.isBuiltinCall(procedure, call) === false
|
|
315
|
+
&& this.localReceiver(procedure, tokens, call.getFirstToken(), receivers) === false) {
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
/** the method name token is preceded by local->, a local reference variable that is not one of the receivers */
|
|
323
|
+
localReceiver(procedure, tokens, name, receivers) {
|
|
324
|
+
const index = tokens.findIndex(t => t.getStart().equals(name.getStart()));
|
|
325
|
+
if (index < 2 || tokens[index - 1].getStr() !== "->") {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
const local = procedure.local(procedure.identifierAt(tokens[index - 2]));
|
|
329
|
+
return local !== undefined && receivers.includes(local) === false;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
exports.SuspiciousLoop = SuspiciousLoop;
|
|
333
|
+
//# sourceMappingURL=suspicious_loop.js.map
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.UnhandledClassicException = exports.UnhandledClassicExceptionConf = void 0;
|
|
37
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
38
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
39
|
+
const issue_1 = require("../issue");
|
|
40
|
+
const _abap_rule_1 = require("./_abap_rule");
|
|
41
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
42
|
+
const severity_1 = require("../severity");
|
|
43
|
+
const _irule_1 = require("./_irule");
|
|
44
|
+
const syntax_1 = require("../abap/5_syntax/syntax");
|
|
45
|
+
const _reference_1 = require("../abap/5_syntax/_reference");
|
|
46
|
+
const types_1 = require("../abap/types");
|
|
47
|
+
const virtual_position_1 = require("../virtual_position");
|
|
48
|
+
class UnhandledClassicExceptionConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(...arguments);
|
|
51
|
+
this.severity = severity_1.Severity.Warning;
|
|
52
|
+
/** Report an EXCEPTIONS list without OTHERS, unless the method or function module is known and all its exceptions are listed */
|
|
53
|
+
this.missingOthers = true;
|
|
54
|
+
/** Report a call without EXCEPTIONS, including a functional call, of a method or function module that declares classic exceptions */
|
|
55
|
+
this.missingExceptions = true;
|
|
56
|
+
/** missingExceptions: do not report a method call whose arguments are all literals or me, like describe_by_name( 'T100' ) */
|
|
57
|
+
this.allowLiteralArguments = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.UnhandledClassicExceptionConf = UnhandledClassicExceptionConf;
|
|
61
|
+
class UnhandledClassicException extends _abap_rule_1.ABAPRule {
|
|
62
|
+
constructor() {
|
|
63
|
+
super(...arguments);
|
|
64
|
+
this.conf = new UnhandledClassicExceptionConf();
|
|
65
|
+
}
|
|
66
|
+
getMetadata() {
|
|
67
|
+
return {
|
|
68
|
+
key: "unhandled_classic_exception",
|
|
69
|
+
title: "Unhandled classic exception",
|
|
70
|
+
shortDescription: `Finds calls that do not map every classic exception the callee can raise`,
|
|
71
|
+
extendedInformation: `A classic exception that is raised with RAISE and not mapped in the EXCEPTIONS addition of the call
|
|
72
|
+
ends in the runtime error RAISE_EXCEPTION. TRY ... CATCH cx_root does not catch it.
|
|
73
|
+
|
|
74
|
+
missingOthers: reports CALL FUNCTION and method calls with an EXCEPTIONS list without OTHERS.
|
|
75
|
+
Not reported if the function module or method is known and every exception it declares is listed,
|
|
76
|
+
for CALL FUNCTION ... DESTINATION this includes SYSTEM_FAILURE and COMMUNICATION_FAILURE.
|
|
77
|
+
CALL FUNCTION ... STARTING NEW TASK, IN UPDATE TASK and IN BACKGROUND are not checked.
|
|
78
|
+
|
|
79
|
+
missingExceptions: reports calls without EXCEPTIONS of a method or function module that declares classic exceptions,
|
|
80
|
+
this includes functional calls, which cannot have EXCEPTIONS.
|
|
81
|
+
With allowLiteralArguments, a method call whose arguments are all literals or me is not reported.
|
|
82
|
+
|
|
83
|
+
Signatures are taken from the registry, including dependencies. Methods and function modules that are not
|
|
84
|
+
found (void) are only checked by missingOthers.
|
|
85
|
+
|
|
86
|
+
Does not report any issues if the code contains syntax errors`,
|
|
87
|
+
tags: [_irule_1.RuleTag.Syntax],
|
|
88
|
+
badExample: `CALL FUNCTION 'Z_READ'
|
|
89
|
+
EXCEPTIONS
|
|
90
|
+
not_found = 1.
|
|
91
|
+
|
|
92
|
+
lo_type = cl_abap_typedescr=>describe_by_name( lv_name ).`,
|
|
93
|
+
goodExample: `CALL FUNCTION 'Z_READ'
|
|
94
|
+
EXCEPTIONS
|
|
95
|
+
not_found = 1
|
|
96
|
+
OTHERS = 2.
|
|
97
|
+
|
|
98
|
+
cl_abap_typedescr=>describe_by_name(
|
|
99
|
+
EXPORTING
|
|
100
|
+
p_name = lv_name
|
|
101
|
+
RECEIVING
|
|
102
|
+
p_descr_ref = lo_type
|
|
103
|
+
EXCEPTIONS
|
|
104
|
+
type_not_found = 1
|
|
105
|
+
OTHERS = 2 ).`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
initialize(reg) {
|
|
109
|
+
super.initialize(reg);
|
|
110
|
+
this.functionModules = undefined;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
getConfig() {
|
|
114
|
+
return this.conf;
|
|
115
|
+
}
|
|
116
|
+
setConfig(conf) {
|
|
117
|
+
this.conf = conf;
|
|
118
|
+
}
|
|
119
|
+
runParsed(file, obj) {
|
|
120
|
+
var _a;
|
|
121
|
+
if (obj.getType() === "INTF" || file.getStructure() === undefined) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
const syntax = new syntax_1.SyntaxLogic(this.reg, obj).run();
|
|
125
|
+
if (syntax.issues.length > 0) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const methods = new Map();
|
|
129
|
+
this.findMethodReferences(syntax.spaghetti.getTop(), file.getFilename(), methods);
|
|
130
|
+
const issues = [];
|
|
131
|
+
for (const statement of file.getStatements()) {
|
|
132
|
+
if (statement.get() instanceof Statements.CallFunction) {
|
|
133
|
+
issues.push(...this.checkCallFunction(statement, file));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (statement.get() instanceof Statements.Call) {
|
|
137
|
+
const source = statement.findDirectExpression(Expressions.MethodSource);
|
|
138
|
+
const body = statement.findDirectExpression(Expressions.MethodCallBody);
|
|
139
|
+
const nameNode = source === null || source === void 0 ? void 0 : source.getLastChild();
|
|
140
|
+
if (nameNode) {
|
|
141
|
+
const token = nameNode.getFirstToken();
|
|
142
|
+
const callee = nameNode.get() instanceof Expressions.Dynamic ? undefined : this.findMethod(methods, token);
|
|
143
|
+
const issue = this.checkCall(file, token, callee, body === null || body === void 0 ? void 0 : body.findDirectExpression(Expressions.MethodParameters), (body === null || body === void 0 ? void 0 : body.findDirectTokenByText("EXCEPTION-TABLE")) !== undefined, false, this.onlyLiterals(body));
|
|
144
|
+
if (issue) {
|
|
145
|
+
issues.push(issue);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const call of statement.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
150
|
+
const token = (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
151
|
+
if (token === undefined) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const param = call.findDirectExpression(Expressions.MethodCallParam);
|
|
155
|
+
const parameters = param === null || param === void 0 ? void 0 : param.findDirectExpression(Expressions.MethodParameters);
|
|
156
|
+
const issue = this.checkCall(file, token, this.findMethod(methods, token), parameters, false, false, this.onlyLiterals(param));
|
|
157
|
+
if (issue) {
|
|
158
|
+
issues.push(issue);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return issues;
|
|
163
|
+
}
|
|
164
|
+
checkCallFunction(statement, file) {
|
|
165
|
+
if (statement.findDirectTokenByText("STARTING")
|
|
166
|
+
|| statement.findDirectTokenByText("UPDATE")
|
|
167
|
+
|| statement.findDirectTokenByText("BACKGROUND")) {
|
|
168
|
+
return [];
|
|
169
|
+
}
|
|
170
|
+
const nameNode = statement.findDirectExpression(Expressions.FunctionName);
|
|
171
|
+
if (nameNode === undefined) {
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
let callee = undefined;
|
|
175
|
+
if (nameNode.findFirstExpression(Expressions.FieldChain) === undefined) {
|
|
176
|
+
const name = nameNode.concatTokens().replace(/'/g, "").replace(/`/g, "");
|
|
177
|
+
const module = this.findFunctionModule(name);
|
|
178
|
+
if (module) {
|
|
179
|
+
callee = {
|
|
180
|
+
name: module.getName(),
|
|
181
|
+
exceptions: module.isClassBasedExceptions() ? [] : module.getExceptions().map(e => e.toUpperCase()),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const issue = this.checkCall(file, nameNode.getFirstToken(), callee, statement.findDirectExpression(Expressions.FunctionParameters), statement.findDirectTokenByText("EXCEPTION-TABLE") !== undefined, statement.findDirectExpression(Expressions.Destination) !== undefined, false);
|
|
186
|
+
return issue ? [issue] : [];
|
|
187
|
+
}
|
|
188
|
+
checkCall(file, token, callee, parameters, exceptionTable, destination, onlyLiterals) {
|
|
189
|
+
if (exceptionTable === true) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
const list = parameters === null || parameters === void 0 ? void 0 : parameters.findDirectExpression(Expressions.ParameterListExceptions);
|
|
193
|
+
if (list === undefined) {
|
|
194
|
+
if (this.conf.missingExceptions === false
|
|
195
|
+
|| callee === undefined
|
|
196
|
+
|| callee.exceptions.length === 0
|
|
197
|
+
|| (this.conf.allowLiteralArguments === true && onlyLiterals === true)) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
const message = `Classic exceptions of "${callee.name}" not handled: ${callee.exceptions.join(", ")}, call it with EXCEPTIONS`;
|
|
201
|
+
return issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
|
|
202
|
+
}
|
|
203
|
+
if (this.conf.missingOthers === false) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
const listed = list.findDirectExpressions(Expressions.ParameterException)
|
|
207
|
+
.map(e => e.getFirstChild().concatTokens().toUpperCase());
|
|
208
|
+
if (listed.includes("OTHERS")) {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
const position = parameters.findDirectTokenByText("EXCEPTIONS") || list.getFirstToken();
|
|
212
|
+
if (callee === undefined) {
|
|
213
|
+
const message = "EXCEPTIONS without OTHERS, an exception that is not listed ends in a runtime error";
|
|
214
|
+
return issue_1.Issue.atToken(file, position, message, this.getMetadata().key, this.conf.severity);
|
|
215
|
+
}
|
|
216
|
+
const expected = [...callee.exceptions];
|
|
217
|
+
if (destination === true) {
|
|
218
|
+
expected.push("SYSTEM_FAILURE", "COMMUNICATION_FAILURE");
|
|
219
|
+
}
|
|
220
|
+
const missing = expected.filter(e => listed.includes(e) === false);
|
|
221
|
+
if (missing.length === 0) {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
const message = `EXCEPTIONS without OTHERS, not mapped: ${missing.join(", ")}`;
|
|
225
|
+
return issue_1.Issue.atToken(file, position, message, this.getMetadata().key, this.conf.severity);
|
|
226
|
+
}
|
|
227
|
+
/** true if the call has arguments and all of them are literals or me, like describe_by_name( 'T100' ) */
|
|
228
|
+
onlyLiterals(node) {
|
|
229
|
+
if (node === undefined || node.findFirstExpression(Expressions.MethodCall) !== undefined) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const sources = node.findAllExpressions(Expressions.Source);
|
|
233
|
+
return sources.length > 0
|
|
234
|
+
&& sources.every(s => { var _a; return (s.getChildren().length === 1 && ((_a = s.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.Constant)
|
|
235
|
+
|| s.concatTokens().toUpperCase() === "ME"; });
|
|
236
|
+
}
|
|
237
|
+
findMethod(methods, token) {
|
|
238
|
+
const method = methods.get(UnhandledClassicException.positionKey(token.getStart()));
|
|
239
|
+
if (method === undefined) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
name: method.getName(),
|
|
244
|
+
exceptions: method.getExceptions().map(e => e.toUpperCase()),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
findMethodReferences(node, filename, found) {
|
|
248
|
+
for (const r of node.getData().references) {
|
|
249
|
+
if (r.referenceType === _reference_1.ReferenceType.MethodReference
|
|
250
|
+
&& r.position.getFilename() === filename
|
|
251
|
+
&& r.resolved instanceof types_1.MethodDefinition) {
|
|
252
|
+
found.set(UnhandledClassicException.positionKey(r.position.getStart()), r.resolved);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
for (const child of node.getChildren()) {
|
|
256
|
+
this.findMethodReferences(child, filename, found);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
findFunctionModule(name) {
|
|
260
|
+
if (this.functionModules === undefined) {
|
|
261
|
+
this.functionModules = new Map();
|
|
262
|
+
for (const fugr of this.reg.getObjectsByType("FUGR")) {
|
|
263
|
+
for (const module of fugr.getModules()) {
|
|
264
|
+
this.functionModules.set(module.getName().toUpperCase(), module);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return this.functionModules.get(name.toUpperCase());
|
|
269
|
+
}
|
|
270
|
+
static positionKey(p) {
|
|
271
|
+
if (p instanceof virtual_position_1.VirtualPosition) {
|
|
272
|
+
return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
|
|
273
|
+
}
|
|
274
|
+
return p.getRow() + ":" + p.getCol();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.UnhandledClassicException = UnhandledClassicException;
|
|
278
|
+
//# sourceMappingURL=unhandled_classic_exception.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/core",
|
|
3
|
-
"version": "2.120.
|
|
3
|
+
"version": "2.120.111",
|
|
4
4
|
"description": "abaplint - Core API",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/abaplint.d.ts",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@types/node": "^24.13.3",
|
|
59
59
|
"c8": "^12.0.0",
|
|
60
60
|
"chai": "^4.5.0",
|
|
61
|
-
"eslint": "^
|
|
61
|
+
"eslint": "^10.15.0",
|
|
62
62
|
"mocha": "^12.0.3",
|
|
63
63
|
"rimraf": "^6.1.4",
|
|
64
64
|
"source-map-support": "^0.5.21",
|