@abaplint/core 2.120.111 → 2.120.113

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.
Files changed (46) hide show
  1. package/build/abaplint.d.ts +7 -4
  2. package/build/src/abap/2_statements/expressions/loop_group_by.js +1 -1
  3. package/build/src/abap/2_statements/expressions/method_name.js +1 -1
  4. package/build/src/abap/5_syntax/_builtin_call.js +98 -0
  5. package/build/src/abap/5_syntax/_object_oriented.js +11 -0
  6. package/build/src/abap/5_syntax/_reserved_names.js +12 -0
  7. package/build/src/abap/5_syntax/basic_types.js +109 -5
  8. package/build/src/abap/5_syntax/expressions/_check_header_line.js +59 -0
  9. package/build/src/abap/5_syntax/expressions/_substring.js +5 -4
  10. package/build/src/abap/5_syntax/expressions/compare.js +17 -31
  11. package/build/src/abap/5_syntax/expressions/cond_body.js +7 -0
  12. package/build/src/abap/5_syntax/expressions/inline_data.js +2 -0
  13. package/build/src/abap/5_syntax/expressions/method_call_chain.js +1 -1
  14. package/build/src/abap/5_syntax/expressions/method_call_param.js +4 -0
  15. package/build/src/abap/5_syntax/expressions/method_parameters.js +4 -0
  16. package/build/src/abap/5_syntax/expressions/source.js +46 -0
  17. package/build/src/abap/5_syntax/expressions/switch_body.js +6 -0
  18. package/build/src/abap/5_syntax/expressions/type_table.js +21 -1
  19. package/build/src/abap/5_syntax/statements/class_data.js +2 -0
  20. package/build/src/abap/5_syntax/statements/data.js +2 -0
  21. package/build/src/abap/5_syntax/statements/delete_internal.js +11 -0
  22. package/build/src/abap/5_syntax/statements/insert_database.js +12 -0
  23. package/build/src/abap/5_syntax/statements/insert_internal.js +14 -2
  24. package/build/src/abap/5_syntax/statements/message.js +10 -0
  25. package/build/src/abap/5_syntax/statements/modify_internal.js +7 -0
  26. package/build/src/abap/5_syntax/statements/raise.js +5 -0
  27. package/build/src/abap/5_syntax/statements/write.js +10 -0
  28. package/build/src/abap/5_syntax/syntax.js +9 -0
  29. package/build/src/abap/types/basic/floating_point_type.js +2 -2
  30. package/build/src/abap/types/basic/hex_type.js +2 -2
  31. package/build/src/abap/types/basic/numeric_type.js +2 -2
  32. package/build/src/abap/types/basic/table_type.js +2 -1
  33. package/build/src/abap/types/method_parameters.js +8 -1
  34. package/build/src/ddic.js +9 -9
  35. package/build/src/objects/table_type.js +8 -7
  36. package/build/src/registry.js +1 -1
  37. package/build/src/rules/check_subrc.js +87 -3
  38. package/build/src/rules/commented_code.js +21 -1
  39. package/build/src/rules/forbidden_statement.js +122 -0
  40. package/build/src/rules/index.js +1 -0
  41. package/build/src/rules/loop_target_misuse.js +268 -4
  42. package/build/src/rules/obsolete_statement.js +31 -1
  43. package/build/src/rules/redundant_conversion.js +15 -3
  44. package/build/src/rules/rfc_error_handling.js +63 -13
  45. package/build/src/rules/unhandled_classic_exception.js +31 -4
  46. package/package.json +1 -1
@@ -112,6 +112,8 @@ class ObsoleteStatementConf extends _basic_rule_config_1.BasicRuleConfig {
112
112
  this.replaceInto = true;
113
113
  this.loopExtract = true;
114
114
  this.sortExtract = true;
115
+ /** Checks for TRANSLATE statement */
116
+ this.translate = true;
115
117
  }
116
118
  }
117
119
  exports.ObsoleteStatementConf = ObsoleteStatementConf;
@@ -168,7 +170,9 @@ POSIX REGEX: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABE
168
170
 
169
171
  OCCURENCES: check for OCCURENCES vs OCCURRENCES
170
172
 
171
- CLIENT SPECIFIED, from 754: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapselect_client_obsolete.html`,
173
+ CLIENT SPECIFIED, from 754: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapselect_client_obsolete.html
174
+
175
+ TRANSLATE: https://help.sap.com/docs/abap-cloud/abap-keywords-standard-abap/translate`,
172
176
  badExample: `REFRESH itab.
173
177
 
174
178
  COMPUTE foo = 2 + 2.
@@ -373,6 +377,11 @@ ENDIF.`,
373
377
  const issue = issue_1.Issue.atStatement(file, staNode, "SORT extract", this.getMetadata().key, this.conf.severity);
374
378
  issues.push(issue);
375
379
  }
380
+ if (this.conf.translate && sta instanceof Statements.Translate) {
381
+ const fix = this.getTranslateFix(file, staNode);
382
+ const issue = issue_1.Issue.atStatement(file, staNode, "TRANSLATE is obsolete", this.getMetadata().key, this.conf.severity, fix);
383
+ issues.push(issue);
384
+ }
376
385
  if ((0, version_1.releaseAtLeast)(configRelease, version_1.Release.v754) && this.conf.clientSpecified
377
386
  && (sta instanceof Statements.Select
378
387
  || sta instanceof Statements.SelectLoop
@@ -495,6 +504,27 @@ ENDIF.`,
495
504
  }
496
505
  return undefined;
497
506
  }
507
+ getTranslateFix(file, statementNode) {
508
+ const tokens = statementNode.getTokens();
509
+ // tokens: TRANSLATE <target> TO UPPER|LOWER CASE .
510
+ // or: TRANSLATE <target> USING <source> .
511
+ if (tokens.length < 4) {
512
+ return undefined;
513
+ }
514
+ const thirdToken = tokens[2].getStr().toUpperCase();
515
+ if (thirdToken !== "TO") {
516
+ return undefined;
517
+ }
518
+ const targetStr = tokens[1].getStr();
519
+ const directionToken = tokens[3].getStr().toUpperCase();
520
+ if (directionToken === "UPPER") {
521
+ return edit_helper_1.EditHelper.replaceRange(file, statementNode.getStart(), statementNode.getEnd(), targetStr + " = to_upper( " + targetStr + " ).");
522
+ }
523
+ else if (directionToken === "LOWER") {
524
+ return edit_helper_1.EditHelper.replaceRange(file, statementNode.getStart(), statementNode.getEnd(), targetStr + " = to_lower( " + targetStr + " ).");
525
+ }
526
+ return undefined;
527
+ }
498
528
  }
499
529
  exports.ObsoleteStatement = ObsoleteStatement;
500
530
  //# sourceMappingURL=obsolete_statement.js.map
@@ -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 structure.findAllExpressionsRecursive(Expressions.Source)) {
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
- const preserveParentheses = bodySource.findDirectExpression(Expressions.ArithOperator) !== undefined
147
- || bodySource.findDirectTokenByText("&&") !== undefined;
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
- https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenrfc_exception.html`,
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
- if (destination === undefined) {
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 = stat.findDirectTokenByText("STARTING") !== undefined
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 parameters = list.findAllExpressions(Expressions.ParameterName);
100
- const names = [];
101
- for (const par of parameters) {
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 (names.indexOf("SYSTEM_FAILURE") < 0
105
- || names.indexOf("COMMUNICATION_FAILURE") < 0
106
- || (requireResourceFailure && names.indexOf("RESOURCE_FAILURE") < 0)) {
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
- continue;
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;
@@ -55,6 +55,8 @@ class UnhandledClassicExceptionConf extends _basic_rule_config_1.BasicRuleConfig
55
55
  this.missingExceptions = true;
56
56
  /** missingExceptions: do not report a method call whose arguments are all literals or me, like describe_by_name( 'T100' ) */
57
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;
58
60
  }
59
61
  }
60
62
  exports.UnhandledClassicExceptionConf = UnhandledClassicExceptionConf;
@@ -80,6 +82,13 @@ missingExceptions: reports calls without EXCEPTIONS of a method or function modu
80
82
  this includes functional calls, which cannot have EXCEPTIONS.
81
83
  With allowLiteralArguments, a method call whose arguments are all literals or me is not reported.
82
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
+
83
92
  Signatures are taken from the registry, including dependencies. Methods and function modules that are not
84
93
  found (void) are only checked by missingOthers.
85
94
 
@@ -140,7 +149,7 @@ cl_abap_typedescr=>describe_by_name(
140
149
  if (nameNode) {
141
150
  const token = nameNode.getFirstToken();
142
151
  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));
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));
144
153
  if (issue) {
145
154
  issues.push(issue);
146
155
  }
@@ -162,6 +171,7 @@ cl_abap_typedescr=>describe_by_name(
162
171
  return issues;
163
172
  }
164
173
  checkCallFunction(statement, file) {
174
+ var _a;
165
175
  if (statement.findDirectTokenByText("STARTING")
166
176
  || statement.findDirectTokenByText("UPDATE")
167
177
  || statement.findDirectTokenByText("BACKGROUND")) {
@@ -172,18 +182,35 @@ cl_abap_typedescr=>describe_by_name(
172
182
  return [];
173
183
  }
174
184
  let callee = undefined;
185
+ let classBased = false;
175
186
  if (nameNode.findFirstExpression(Expressions.FieldChain) === undefined) {
176
187
  const name = nameNode.concatTokens().replace(/'/g, "").replace(/`/g, "");
177
188
  const module = this.findFunctionModule(name);
178
189
  if (module) {
190
+ classBased = module.isClassBasedExceptions();
179
191
  callee = {
180
192
  name: module.getName(),
181
- exceptions: module.isClassBasedExceptions() ? [] : module.getExceptions().map(e => e.toUpperCase()),
193
+ exceptions: classBased ? [] : module.getExceptions().map(e => e.toUpperCase()),
182
194
  };
183
195
  }
184
196
  }
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] : [];
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;
187
214
  }
188
215
  checkCall(file, token, callee, parameters, exceptionTable, destination, onlyLiterals) {
189
216
  if (exceptionTable === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.111",
3
+ "version": "2.120.113",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",