@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,305 @@
|
|
|
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
|
+
/** Report CALL FUNCTION without error_message, the policy "always list error_message", for code that runs outside dialog */
|
|
59
|
+
this.missingErrorMessage = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.UnhandledClassicExceptionConf = UnhandledClassicExceptionConf;
|
|
63
|
+
class UnhandledClassicException extends _abap_rule_1.ABAPRule {
|
|
64
|
+
constructor() {
|
|
65
|
+
super(...arguments);
|
|
66
|
+
this.conf = new UnhandledClassicExceptionConf();
|
|
67
|
+
}
|
|
68
|
+
getMetadata() {
|
|
69
|
+
return {
|
|
70
|
+
key: "unhandled_classic_exception",
|
|
71
|
+
title: "Unhandled classic exception",
|
|
72
|
+
shortDescription: `Finds calls that do not map every classic exception the callee can raise`,
|
|
73
|
+
extendedInformation: `A classic exception that is raised with RAISE and not mapped in the EXCEPTIONS addition of the call
|
|
74
|
+
ends in the runtime error RAISE_EXCEPTION. TRY ... CATCH cx_root does not catch it.
|
|
75
|
+
|
|
76
|
+
missingOthers: reports CALL FUNCTION and method calls with an EXCEPTIONS list without OTHERS.
|
|
77
|
+
Not reported if the function module or method is known and every exception it declares is listed,
|
|
78
|
+
for CALL FUNCTION ... DESTINATION this includes SYSTEM_FAILURE and COMMUNICATION_FAILURE.
|
|
79
|
+
CALL FUNCTION ... STARTING NEW TASK, IN UPDATE TASK and IN BACKGROUND are not checked.
|
|
80
|
+
|
|
81
|
+
missingExceptions: reports calls without EXCEPTIONS of a method or function module that declares classic exceptions,
|
|
82
|
+
this includes functional calls, which cannot have EXCEPTIONS.
|
|
83
|
+
With allowLiteralArguments, a method call whose arguments are all literals or me is not reported.
|
|
84
|
+
|
|
85
|
+
missingErrorMessage, off by default: reports every CALL FUNCTION that does not list the predefined exception error_message,
|
|
86
|
+
the policy "always list error_message". Any function module can send a MESSAGE without RAISING, directly or from a
|
|
87
|
+
function module it calls, and OTHERS does not catch it. Outside dialog, in HTTP handlers, RFC and background jobs,
|
|
88
|
+
a message of type E or A ends the processing. Use it together with check_subrc, otherwise error_message turns a
|
|
89
|
+
visible abort into a silent failure. Not reported: DESTINATION, STARTING NEW TASK, IN UPDATE TASK, IN BACKGROUND,
|
|
90
|
+
EXCEPTION-TABLE, and function modules in the registry with class-based exceptions.
|
|
91
|
+
|
|
92
|
+
Signatures are taken from the registry, including dependencies. Methods and function modules that are not
|
|
93
|
+
found (void) are only checked by missingOthers.
|
|
94
|
+
|
|
95
|
+
Does not report any issues if the code contains syntax errors`,
|
|
96
|
+
tags: [_irule_1.RuleTag.Syntax],
|
|
97
|
+
badExample: `CALL FUNCTION 'Z_READ'
|
|
98
|
+
EXCEPTIONS
|
|
99
|
+
not_found = 1.
|
|
100
|
+
|
|
101
|
+
lo_type = cl_abap_typedescr=>describe_by_name( lv_name ).`,
|
|
102
|
+
goodExample: `CALL FUNCTION 'Z_READ'
|
|
103
|
+
EXCEPTIONS
|
|
104
|
+
not_found = 1
|
|
105
|
+
OTHERS = 2.
|
|
106
|
+
|
|
107
|
+
cl_abap_typedescr=>describe_by_name(
|
|
108
|
+
EXPORTING
|
|
109
|
+
p_name = lv_name
|
|
110
|
+
RECEIVING
|
|
111
|
+
p_descr_ref = lo_type
|
|
112
|
+
EXCEPTIONS
|
|
113
|
+
type_not_found = 1
|
|
114
|
+
OTHERS = 2 ).`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
initialize(reg) {
|
|
118
|
+
super.initialize(reg);
|
|
119
|
+
this.functionModules = undefined;
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
getConfig() {
|
|
123
|
+
return this.conf;
|
|
124
|
+
}
|
|
125
|
+
setConfig(conf) {
|
|
126
|
+
this.conf = conf;
|
|
127
|
+
}
|
|
128
|
+
runParsed(file, obj) {
|
|
129
|
+
var _a;
|
|
130
|
+
if (obj.getType() === "INTF" || file.getStructure() === undefined) {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
const syntax = new syntax_1.SyntaxLogic(this.reg, obj).run();
|
|
134
|
+
if (syntax.issues.length > 0) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
const methods = new Map();
|
|
138
|
+
this.findMethodReferences(syntax.spaghetti.getTop(), file.getFilename(), methods);
|
|
139
|
+
const issues = [];
|
|
140
|
+
for (const statement of file.getStatements()) {
|
|
141
|
+
if (statement.get() instanceof Statements.CallFunction) {
|
|
142
|
+
issues.push(...this.checkCallFunction(statement, file));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (statement.get() instanceof Statements.Call) {
|
|
146
|
+
const source = statement.findDirectExpression(Expressions.MethodSource);
|
|
147
|
+
const body = statement.findDirectExpression(Expressions.MethodCallBody);
|
|
148
|
+
const nameNode = source === null || source === void 0 ? void 0 : source.getLastChild();
|
|
149
|
+
if (nameNode) {
|
|
150
|
+
const token = nameNode.getFirstToken();
|
|
151
|
+
const callee = nameNode.get() instanceof Expressions.Dynamic ? undefined : this.findMethod(methods, token);
|
|
152
|
+
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")) !== undefined, false, this.onlyLiterals(body));
|
|
153
|
+
if (issue) {
|
|
154
|
+
issues.push(issue);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
for (const call of statement.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
159
|
+
const token = (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
160
|
+
if (token === undefined) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const param = call.findDirectExpression(Expressions.MethodCallParam);
|
|
164
|
+
const parameters = param === null || param === void 0 ? void 0 : param.findDirectExpression(Expressions.MethodParameters);
|
|
165
|
+
const issue = this.checkCall(file, token, this.findMethod(methods, token), parameters, false, false, this.onlyLiterals(param));
|
|
166
|
+
if (issue) {
|
|
167
|
+
issues.push(issue);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return issues;
|
|
172
|
+
}
|
|
173
|
+
checkCallFunction(statement, file) {
|
|
174
|
+
var _a;
|
|
175
|
+
if (statement.findDirectTokenByText("STARTING")
|
|
176
|
+
|| statement.findDirectTokenByText("UPDATE")
|
|
177
|
+
|| statement.findDirectTokenByText("BACKGROUND")) {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
const nameNode = statement.findDirectExpression(Expressions.FunctionName);
|
|
181
|
+
if (nameNode === undefined) {
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
let callee = undefined;
|
|
185
|
+
let classBased = false;
|
|
186
|
+
if (nameNode.findFirstExpression(Expressions.FieldChain) === undefined) {
|
|
187
|
+
const name = nameNode.concatTokens().replace(/'/g, "").replace(/`/g, "");
|
|
188
|
+
const module = this.findFunctionModule(name);
|
|
189
|
+
if (module) {
|
|
190
|
+
classBased = module.isClassBasedExceptions();
|
|
191
|
+
callee = {
|
|
192
|
+
name: module.getName(),
|
|
193
|
+
exceptions: classBased ? [] : module.getExceptions().map(e => e.toUpperCase()),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const issues = [];
|
|
198
|
+
const parameters = statement.findDirectExpression(Expressions.FunctionParameters);
|
|
199
|
+
const exceptionTable = statement.findDirectTokenByText("EXCEPTION") !== undefined;
|
|
200
|
+
const destination = statement.findDirectExpression(Expressions.Destination) !== undefined;
|
|
201
|
+
const issue = this.checkCall(file, nameNode.getFirstToken(), callee, parameters, exceptionTable, destination, false);
|
|
202
|
+
if (issue) {
|
|
203
|
+
issues.push(issue);
|
|
204
|
+
}
|
|
205
|
+
if (this.conf.missingErrorMessage === true && exceptionTable === false && destination === false && classBased === false) {
|
|
206
|
+
const listed = (_a = parameters === null || parameters === void 0 ? void 0 : parameters.findDirectExpression(Expressions.ParameterListExceptions)) === null || _a === void 0 ? void 0 : _a.findDirectExpressions(Expressions.ParameterException).some(e => e.getFirstChild().concatTokens().toUpperCase() === "ERROR_MESSAGE");
|
|
207
|
+
if (listed !== true) {
|
|
208
|
+
const position = (parameters === null || parameters === void 0 ? void 0 : parameters.findDirectTokenByText("EXCEPTIONS")) || nameNode.getFirstToken();
|
|
209
|
+
const message = "No error_message, OTHERS does not catch a message that the function module sends without RAISING";
|
|
210
|
+
issues.push(issue_1.Issue.atToken(file, position, message, this.getMetadata().key, this.conf.severity));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return issues;
|
|
214
|
+
}
|
|
215
|
+
checkCall(file, token, callee, parameters, exceptionTable, destination, onlyLiterals) {
|
|
216
|
+
if (exceptionTable === true) {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
const list = parameters === null || parameters === void 0 ? void 0 : parameters.findDirectExpression(Expressions.ParameterListExceptions);
|
|
220
|
+
if (list === undefined) {
|
|
221
|
+
if (this.conf.missingExceptions === false
|
|
222
|
+
|| callee === undefined
|
|
223
|
+
|| callee.exceptions.length === 0
|
|
224
|
+
|| (this.conf.allowLiteralArguments === true && onlyLiterals === true)) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
const message = `Classic exceptions of "${callee.name}" not handled: ${callee.exceptions.join(", ")}, call it with EXCEPTIONS`;
|
|
228
|
+
return issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
|
|
229
|
+
}
|
|
230
|
+
if (this.conf.missingOthers === false) {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
const listed = list.findDirectExpressions(Expressions.ParameterException)
|
|
234
|
+
.map(e => e.getFirstChild().concatTokens().toUpperCase());
|
|
235
|
+
if (listed.includes("OTHERS")) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
const position = parameters.findDirectTokenByText("EXCEPTIONS") || list.getFirstToken();
|
|
239
|
+
if (callee === undefined) {
|
|
240
|
+
const message = "EXCEPTIONS without OTHERS, an exception that is not listed ends in a runtime error";
|
|
241
|
+
return issue_1.Issue.atToken(file, position, message, this.getMetadata().key, this.conf.severity);
|
|
242
|
+
}
|
|
243
|
+
const expected = [...callee.exceptions];
|
|
244
|
+
if (destination === true) {
|
|
245
|
+
expected.push("SYSTEM_FAILURE", "COMMUNICATION_FAILURE");
|
|
246
|
+
}
|
|
247
|
+
const missing = expected.filter(e => listed.includes(e) === false);
|
|
248
|
+
if (missing.length === 0) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
const message = `EXCEPTIONS without OTHERS, not mapped: ${missing.join(", ")}`;
|
|
252
|
+
return issue_1.Issue.atToken(file, position, message, this.getMetadata().key, this.conf.severity);
|
|
253
|
+
}
|
|
254
|
+
/** true if the call has arguments and all of them are literals or me, like describe_by_name( 'T100' ) */
|
|
255
|
+
onlyLiterals(node) {
|
|
256
|
+
if (node === undefined || node.findFirstExpression(Expressions.MethodCall) !== undefined) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
const sources = node.findAllExpressions(Expressions.Source);
|
|
260
|
+
return sources.length > 0
|
|
261
|
+
&& sources.every(s => { var _a; return (s.getChildren().length === 1 && ((_a = s.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.Constant)
|
|
262
|
+
|| s.concatTokens().toUpperCase() === "ME"; });
|
|
263
|
+
}
|
|
264
|
+
findMethod(methods, token) {
|
|
265
|
+
const method = methods.get(UnhandledClassicException.positionKey(token.getStart()));
|
|
266
|
+
if (method === undefined) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
name: method.getName(),
|
|
271
|
+
exceptions: method.getExceptions().map(e => e.toUpperCase()),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
findMethodReferences(node, filename, found) {
|
|
275
|
+
for (const r of node.getData().references) {
|
|
276
|
+
if (r.referenceType === _reference_1.ReferenceType.MethodReference
|
|
277
|
+
&& r.position.getFilename() === filename
|
|
278
|
+
&& r.resolved instanceof types_1.MethodDefinition) {
|
|
279
|
+
found.set(UnhandledClassicException.positionKey(r.position.getStart()), r.resolved);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
for (const child of node.getChildren()) {
|
|
283
|
+
this.findMethodReferences(child, filename, found);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
findFunctionModule(name) {
|
|
287
|
+
if (this.functionModules === undefined) {
|
|
288
|
+
this.functionModules = new Map();
|
|
289
|
+
for (const fugr of this.reg.getObjectsByType("FUGR")) {
|
|
290
|
+
for (const module of fugr.getModules()) {
|
|
291
|
+
this.functionModules.set(module.getName().toUpperCase(), module);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return this.functionModules.get(name.toUpperCase());
|
|
296
|
+
}
|
|
297
|
+
static positionKey(p) {
|
|
298
|
+
if (p instanceof virtual_position_1.VirtualPosition) {
|
|
299
|
+
return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
|
|
300
|
+
}
|
|
301
|
+
return p.getRow() + ":" + p.getCol();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.UnhandledClassicException = UnhandledClassicException;
|
|
305
|
+
//# sourceMappingURL=unhandled_classic_exception.js.map
|