@abaplint/core 2.79.32 → 2.80.0

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 (88) hide show
  1. package/README.md +6 -6
  2. package/build/abaplint.d.ts +22 -5
  3. package/build/src/abap/2_statements/expressions/find_type.js +12 -0
  4. package/build/src/abap/2_statements/expressions/function_exporting.js +2 -6
  5. package/build/src/abap/2_statements/expressions/function_exporting_parameter.js +17 -0
  6. package/build/src/abap/2_statements/expressions/index.js +2 -0
  7. package/build/src/abap/2_statements/statements/find.js +1 -2
  8. package/build/src/abap/2_statements/statements/replace.js +1 -2
  9. package/build/src/abap/3_structures/structures/cleanup.js +14 -0
  10. package/build/src/abap/3_structures/structures/index.js +3 -2
  11. package/build/src/abap/3_structures/structures/try.js +2 -2
  12. package/build/src/abap/5_syntax/basic_types.js +14 -7
  13. package/build/src/abap/flow/statement_flow.js +126 -11
  14. package/build/src/abap/nodes/structure_node.js +12 -0
  15. package/build/src/lsp/help.js +7 -7
  16. package/build/src/lsp/language_server.js +12 -0
  17. package/build/src/registry.js +1 -1
  18. package/build/src/rules/abapdoc.js +1 -1
  19. package/build/src/rules/align_parameters.js +131 -0
  20. package/build/src/rules/allowed_object_naming.js +1 -1
  21. package/build/src/rules/ambiguous_statement.js +5 -5
  22. package/build/src/rules/avoid_use.js +6 -6
  23. package/build/src/rules/begin_end_names.js +4 -4
  24. package/build/src/rules/begin_single_include.js +12 -12
  25. package/build/src/rules/call_transaction_authority_check.js +3 -3
  26. package/build/src/rules/chain_mainly_declarations.js +4 -4
  27. package/build/src/rules/check_abstract.js +2 -2
  28. package/build/src/rules/check_comments.js +3 -3
  29. package/build/src/rules/check_include.js +3 -3
  30. package/build/src/rules/check_no_handler_pragma.js +8 -8
  31. package/build/src/rules/check_subrc.js +8 -8
  32. package/build/src/rules/commented_code.js +1 -1
  33. package/build/src/rules/constructor_visibility_public.js +4 -4
  34. package/build/src/rules/contains_tab.js +2 -2
  35. package/build/src/rules/dangerous_statement.js +25 -0
  36. package/build/src/rules/downport.js +35 -35
  37. package/build/src/rules/exit_or_check.js +3 -3
  38. package/build/src/rules/exporting.js +1 -1
  39. package/build/src/rules/forbidden_identifier.js +1 -1
  40. package/build/src/rules/forbidden_void_type.js +2 -2
  41. package/build/src/rules/functional_writing.js +17 -17
  42. package/build/src/rules/global_class.js +10 -10
  43. package/build/src/rules/identical_conditions.js +2 -2
  44. package/build/src/rules/identical_contents.js +15 -15
  45. package/build/src/rules/identical_descriptions.js +4 -4
  46. package/build/src/rules/if_in_if.js +7 -7
  47. package/build/src/rules/implement_methods.js +3 -3
  48. package/build/src/rules/in_statement_indentation.js +11 -11
  49. package/build/src/rules/index.js +2 -1
  50. package/build/src/rules/intf_referencing_clas.js +3 -3
  51. package/build/src/rules/line_break_style.js +2 -2
  52. package/build/src/rules/line_length.js +1 -1
  53. package/build/src/rules/line_only_punc.js +1 -1
  54. package/build/src/rules/local_variable_names.js +2 -2
  55. package/build/src/rules/many_parentheses.js +10 -10
  56. package/build/src/rules/max_one_method_parameter_per_line.js +7 -7
  57. package/build/src/rules/max_one_statement.js +3 -3
  58. package/build/src/rules/nesting.js +1 -1
  59. package/build/src/rules/no_public_attributes.js +1 -1
  60. package/build/src/rules/no_yoda_conditions.js +4 -4
  61. package/build/src/rules/obsolete_statement.js +38 -39
  62. package/build/src/rules/omit_parameter_name.js +3 -3
  63. package/build/src/rules/omit_receiving.js +13 -13
  64. package/build/src/rules/parser_702_chaining.js +2 -2
  65. package/build/src/rules/parser_error.js +2 -2
  66. package/build/src/rules/parser_missing_space.js +1 -1
  67. package/build/src/rules/prefer_inline.js +16 -16
  68. package/build/src/rules/prefer_is_not.js +7 -7
  69. package/build/src/rules/prefer_raise_exception_new.js +3 -3
  70. package/build/src/rules/prefer_returning_to_exporting.js +1 -1
  71. package/build/src/rules/prefer_xsdbool.js +2 -2
  72. package/build/src/rules/remove_descriptions.js +4 -4
  73. package/build/src/rules/rfc_error_handling.js +9 -9
  74. package/build/src/rules/select_add_order_by.js +5 -5
  75. package/build/src/rules/select_performance.js +2 -2
  76. package/build/src/rules/sicf_consistency.js +4 -4
  77. package/build/src/rules/space_before_dot.js +2 -2
  78. package/build/src/rules/start_at_tab.js +1 -1
  79. package/build/src/rules/sy_modification.js +2 -2
  80. package/build/src/rules/tabl_enhancement_category.js +2 -2
  81. package/build/src/rules/try_without_catch.js +1 -2
  82. package/build/src/rules/unused_methods.js +9 -9
  83. package/build/src/rules/unused_variables.js +6 -6
  84. package/build/src/rules/use_bool_expression.js +8 -8
  85. package/build/src/rules/use_line_exists.js +6 -6
  86. package/build/src/rules/use_new.js +2 -2
  87. package/build/src/rules/when_others_last.js +6 -6
  88. package/package.json +76 -76
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlignParameters = exports.AlignParametersConf = void 0;
4
+ const issue_1 = require("../issue");
5
+ const Expressions = require("../abap/2_statements/expressions");
6
+ const _abap_rule_1 = require("./_abap_rule");
7
+ const _basic_rule_config_1 = require("./_basic_rule_config");
8
+ const _irule_1 = require("./_irule");
9
+ class AlignParametersConf extends _basic_rule_config_1.BasicRuleConfig {
10
+ }
11
+ exports.AlignParametersConf = AlignParametersConf;
12
+ class AlignParameters extends _abap_rule_1.ABAPRule {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.conf = new AlignParametersConf();
16
+ }
17
+ getMetadata() {
18
+ return {
19
+ key: "align_parameters",
20
+ title: "Align Parameters",
21
+ shortDescription: `Checks for aligned parameters in function module calls.`,
22
+ extendedInformation: `https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md#align-parameters`,
23
+ tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Styleguide],
24
+ badExample: `CALL FUNCTION 'FOOBAR'
25
+ EXPORTING
26
+ foo = 2
27
+ parameter = 3.`,
28
+ goodExample: `CALL FUNCTION 'FOOBAR'
29
+ EXPORTING
30
+ foo = 2
31
+ parameter = 3.`,
32
+ };
33
+ }
34
+ getConfig() {
35
+ return this.conf;
36
+ }
37
+ setConfig(conf) {
38
+ this.conf = conf;
39
+ }
40
+ runParsed(file) {
41
+ const issues = [];
42
+ const stru = file.getStructure();
43
+ if (stru === undefined) {
44
+ return issues; // parser error
45
+ }
46
+ const candidates = [];
47
+ candidates.push(...this.functionParameterCandidates(stru));
48
+ /* TODO,
49
+ stru.findAllExpressionsRecursive(Expressions.MethodCallParam);
50
+ stru.findAllExpressionsRecursive(Expressions.MethodParameters);
51
+ stru.findAllExpressionsRecursive(Expressions.ValueBody);
52
+ */
53
+ for (const c of candidates) {
54
+ const i = this.checkCandidate(c, file);
55
+ if (i) {
56
+ issues.push(i);
57
+ }
58
+ }
59
+ return issues;
60
+ }
61
+ checkCandidate(candidate, file) {
62
+ if (candidate.parameters.length === 0) {
63
+ return undefined;
64
+ }
65
+ let expectedEqualsColumn = 0;
66
+ for (const p of candidate.parameters) {
67
+ const currentCol = p.left.getLastToken().getCol() + p.left.getLastToken().getStr().length + 1;
68
+ if (currentCol > expectedEqualsColumn) {
69
+ expectedEqualsColumn = currentCol;
70
+ }
71
+ }
72
+ for (const p of candidate.parameters) {
73
+ if (p.eq.getCol() !== expectedEqualsColumn) {
74
+ const pos = candidate.parameters[0].eq;
75
+ const message = "Align parameters to column " + expectedEqualsColumn;
76
+ return issue_1.Issue.atPosition(file, pos, message, this.getMetadata().key);
77
+ }
78
+ }
79
+ return undefined;
80
+ }
81
+ functionParameterCandidates(stru) {
82
+ const candidates = [];
83
+ for (const fp of stru.findAllExpressionsRecursive(Expressions.FunctionParameters)) {
84
+ const parameters = [];
85
+ for (const p of fp.findAllExpressions(Expressions.FunctionExportingParameter)) {
86
+ const children = p.getChildren();
87
+ if (children.length < 3) {
88
+ continue; // unexpected
89
+ }
90
+ parameters.push({
91
+ left: children[0],
92
+ eq: children[1].getFirstToken().getStart(),
93
+ right: children[2],
94
+ });
95
+ }
96
+ for (const list of fp.findDirectExpressions(Expressions.ParameterListT)) {
97
+ for (const pt of list.findDirectExpressions(Expressions.ParameterT)) {
98
+ const children = pt.getChildren();
99
+ if (children.length < 3) {
100
+ continue; // unexpected
101
+ }
102
+ parameters.push({
103
+ left: children[0],
104
+ eq: children[1].getFirstToken().getStart(),
105
+ right: children[2],
106
+ });
107
+ }
108
+ }
109
+ const list = fp.findDirectExpression(Expressions.ParameterListExceptions);
110
+ if (list) {
111
+ for (const pt of list.findDirectExpressions(Expressions.ParameterException)) {
112
+ const children = pt.getChildren();
113
+ if (children.length < 3) {
114
+ continue; // unexpected
115
+ }
116
+ parameters.push({
117
+ left: children[0],
118
+ eq: children[1].getFirstToken().getStart(),
119
+ right: children[2],
120
+ });
121
+ }
122
+ }
123
+ if (parameters.length > 0) {
124
+ candidates.push({ parameters });
125
+ }
126
+ }
127
+ return candidates;
128
+ }
129
+ }
130
+ exports.AlignParameters = AlignParameters;
131
+ //# sourceMappingURL=align_parameters.js.map
@@ -42,7 +42,7 @@ class AllowedObjectNaming {
42
42
  message = "Name not allowed";
43
43
  }
44
44
  }
45
- else if (obj.getName().match(/^(\/[A-Z_\d]{3,8}\/)?[A-Z_\d<> ]+$/i) === null) {
45
+ else if (obj.getName().match(/^(\/[A-Z_\d]{3,8}\/)?[A-Z_-\d<> ]+$/i) === null) {
46
46
  message = "Name not allowed";
47
47
  }
48
48
  if (message.length > 0) {
@@ -20,14 +20,14 @@ class AmbiguousStatement extends _abap_rule_1.ABAPRule {
20
20
  return {
21
21
  key: "ambiguous_statement",
22
22
  title: "Check for ambigious statements",
23
- shortDescription: `Checks for ambiguity between deleting or modifying from internal and database table
24
- Add "TABLE" keyword or "@" for escaping SQL variables
25
-
23
+ shortDescription: `Checks for ambiguity between deleting or modifying from internal and database table
24
+ Add "TABLE" keyword or "@" for escaping SQL variables
25
+
26
26
  Only works if the target version is 740sp05 or above`,
27
27
  tags: [_irule_1.RuleTag.SingleFile],
28
- badExample: `DELETE foo FROM bar.
28
+ badExample: `DELETE foo FROM bar.
29
29
  MODIFY foo FROM bar.`,
30
- goodExample: `DELETE foo FROM @bar.
30
+ goodExample: `DELETE foo FROM @bar.
31
31
  MODIFY TABLE foo FROM bar.`,
32
32
  };
33
33
  }
@@ -35,12 +35,12 @@ class AvoidUse extends _abap_rule_1.ABAPRule {
35
35
  key: "avoid_use",
36
36
  title: "Avoid use of certain statements",
37
37
  shortDescription: `Detects usage of certain statements.`,
38
- extendedInformation: `DEFAULT KEY: https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#avoid-default-key
39
-
40
- Macros: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenmacros_guidl.htm
41
-
42
- STATICS: use CLASS-DATA instead
43
-
38
+ extendedInformation: `DEFAULT KEY: https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#avoid-default-key
39
+
40
+ Macros: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenmacros_guidl.htm
41
+
42
+ STATICS: use CLASS-DATA instead
43
+
44
44
  DESCRIBE TABLE LINES: use lines() instead (quickfix exists)`,
45
45
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
46
46
  };
@@ -23,11 +23,11 @@ class BeginEndNames extends _abap_rule_1.ABAPRule {
23
23
  title: "Check BEGIN END names",
24
24
  shortDescription: `Check BEGIN OF and END OF names match, plus there must be statements between BEGIN and END`,
25
25
  tags: [_irule_1.RuleTag.Syntax, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
26
- badExample: `DATA: BEGIN OF stru,
27
- field TYPE i,
26
+ badExample: `DATA: BEGIN OF stru,
27
+ field TYPE i,
28
28
  END OF structure_not_the_same.`,
29
- goodExample: `DATA: BEGIN OF stru,
30
- field TYPE i,
29
+ goodExample: `DATA: BEGIN OF stru,
30
+ field TYPE i,
31
31
  END OF stru.`,
32
32
  };
33
33
  }
@@ -21,19 +21,19 @@ class BeginSingleInclude extends _abap_rule_1.ABAPRule {
21
21
  title: "BEGIN contains single INCLUDE",
22
22
  shortDescription: `Finds TYPE BEGIN with just one INCLUDE TYPE, and DATA with single INCLUDE STRUCTURE`,
23
23
  tags: [_irule_1.RuleTag.SingleFile],
24
- badExample: `TYPES: BEGIN OF dummy1.
25
- INCLUDE TYPE dselc.
26
- TYPES: END OF dummy1.
27
-
28
- DATA BEGIN OF foo.
29
- INCLUDE STRUCTURE syst.
30
- DATA END OF foo.
31
-
32
- STATICS BEGIN OF bar.
33
- INCLUDE STRUCTURE syst.
24
+ badExample: `TYPES: BEGIN OF dummy1.
25
+ INCLUDE TYPE dselc.
26
+ TYPES: END OF dummy1.
27
+
28
+ DATA BEGIN OF foo.
29
+ INCLUDE STRUCTURE syst.
30
+ DATA END OF foo.
31
+
32
+ STATICS BEGIN OF bar.
33
+ INCLUDE STRUCTURE syst.
34
34
  STATICS END OF bar.`,
35
- goodExample: `DATA BEGIN OF foo.
36
- INCLUDE STRUCTURE dselc.
35
+ goodExample: `DATA BEGIN OF foo.
36
+ INCLUDE STRUCTURE dselc.
37
37
  DATA END OF foo.`,
38
38
  };
39
39
  }
@@ -24,9 +24,9 @@ class CallTransactionAuthorityCheck extends _abap_rule_1.ABAPRule {
24
24
  extendedInformation: `https://docs.abapopenchecks.org/checks/54/`,
25
25
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Security],
26
26
  badExample: `CALL TRANSACTION 'FOO'.`,
27
- goodExample: `TRY.
28
- CALL TRANSACTION 'FOO' WITH AUTHORITY-CHECK.
29
- CATCH cx_sy_authorization_error.
27
+ goodExample: `TRY.
28
+ CALL TRANSACTION 'FOO' WITH AUTHORITY-CHECK.
29
+ CATCH cx_sy_authorization_error.
30
30
  ENDTRY.`,
31
31
  };
32
32
  }
@@ -45,10 +45,10 @@ class ChainMainlyDeclarations extends _abap_rule_1.ABAPRule {
45
45
  key: "chain_mainly_declarations",
46
46
  title: "Chain mainly declarations",
47
47
  shortDescription: `Chain mainly declarations, allows chaining for the configured statements, reports errors for other statements.`,
48
- extendedInformation: `
49
- https://docs.abapopenchecks.org/checks/23/
50
-
51
- https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenchained_statements_guidl.htm
48
+ extendedInformation: `
49
+ https://docs.abapopenchecks.org/checks/23/
50
+
51
+ https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenchained_statements_guidl.htm
52
52
  `,
53
53
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
54
54
  badExample: `CALL METHOD: bar.`,
@@ -23,8 +23,8 @@ class CheckAbstract extends _abap_rule_1.ABAPRule {
23
23
  return {
24
24
  key: "check_abstract",
25
25
  title: "Check abstract methods and classes",
26
- shortDescription: `Checks abstract methods and classes:
27
- - class defined as abstract and final,
26
+ shortDescription: `Checks abstract methods and classes:
27
+ - class defined as abstract and final,
28
28
  - non-abstract class contains abstract methods`,
29
29
  extendedInformation: `If a class defines only constants, use an interface instead`,
30
30
  tags: [_irule_1.RuleTag.SingleFile],
@@ -27,9 +27,9 @@ class CheckComments extends _abap_rule_1.ABAPRule {
27
27
  return {
28
28
  key: "check_comments",
29
29
  title: "Check Comments",
30
- shortDescription: `
31
- Various checks for comment usage.
32
-
30
+ shortDescription: `
31
+ Various checks for comment usage.
32
+
33
33
  * End of line comments. Comments starting with "#EC" or "##" are ignored`,
34
34
  extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#put-comments-before-the-statement-they-relate-to`,
35
35
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
@@ -17,9 +17,9 @@ class CheckInclude {
17
17
  key: "check_include",
18
18
  title: "Check INCLUDEs",
19
19
  shortDescription: `Checks INCLUDE statements`,
20
- extendedInformation: `
21
- * Reports unused includes
22
- * Errors if the includes are not found
20
+ extendedInformation: `
21
+ * Reports unused includes
22
+ * Errors if the includes are not found
23
23
  * Error if including a main program`,
24
24
  tags: [_irule_1.RuleTag.Syntax],
25
25
  };
@@ -21,15 +21,15 @@ class CheckNoHandlerPragma extends _abap_rule_1.ABAPRule {
21
21
  title: "Check if NO_HANDLER can be removed",
22
22
  shortDescription: `Checks NO_HANDLER pragmas that can be removed`,
23
23
  tags: [_irule_1.RuleTag.SingleFile],
24
- badExample: `TRY.
25
- ...
26
- CATCH zcx_abapgit_exception ##NO_HANDLER.
27
- RETURN. " it has a handler
24
+ badExample: `TRY.
25
+ ...
26
+ CATCH zcx_abapgit_exception ##NO_HANDLER.
27
+ RETURN. " it has a handler
28
28
  ENDTRY.`,
29
- goodExample: `TRY.
30
- ...
31
- CATCH zcx_abapgit_exception.
32
- RETURN.
29
+ goodExample: `TRY.
30
+ ...
31
+ CATCH zcx_abapgit_exception.
32
+ RETURN.
33
33
  ENDTRY.`,
34
34
  };
35
35
  }
@@ -34,14 +34,14 @@ class CheckSubrc extends _abap_rule_1.ABAPRule {
34
34
  key: "check_subrc",
35
35
  title: "Check sy-subrc",
36
36
  shortDescription: `Check sy-subrc`,
37
- extendedInformation: `Pseudo comment "#EC CI_SUBRC can be added to suppress findings
38
-
39
- If sy-dbcnt is checked after database statements, it is considered okay.
40
-
41
- "SELECT SINGLE @abap_true FROM " is considered as an existence check
42
-
43
- If IS ASSIGNED is checked after assigning, it is considered okay.
44
-
37
+ extendedInformation: `Pseudo comment "#EC CI_SUBRC can be added to suppress findings
38
+
39
+ If sy-dbcnt is checked after database statements, it is considered okay.
40
+
41
+ "SELECT SINGLE @abap_true FROM " is considered as an existence check
42
+
43
+ If IS ASSIGNED is checked after assigning, it is considered okay.
44
+
45
45
  FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
46
46
  tags: [_irule_1.RuleTag.SingleFile],
47
47
  pseudoComment: "EC CI_SUBRC",
@@ -30,7 +30,7 @@ class CommentedCode extends _abap_rule_1.ABAPRule {
30
30
  key: "commented_code",
31
31
  title: "Find commented code",
32
32
  shortDescription: `Detects usage of commented out code.`,
33
- extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#delete-code-instead-of-commenting-it
33
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#delete-code-instead-of-commenting-it
34
34
  https://docs.abapopenchecks.org/checks/14/`,
35
35
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
36
36
  };
@@ -18,10 +18,10 @@ class ConstructorVisibilityPublic {
18
18
  key: "constructor_visibility_public",
19
19
  title: "Check constructor visibility is public",
20
20
  shortDescription: `Constructor must be placed in the public section, even if the class is not CREATE PUBLIC.`,
21
- extendedInformation: `
22
- This only applies to global classes.
23
-
24
- https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#if-your-global-class-is-create-private-leave-the-constructor-public
21
+ extendedInformation: `
22
+ This only applies to global classes.
23
+
24
+ https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#if-your-global-class-is-create-private-leave-the-constructor-public
25
25
  https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abeninstance_constructor_guidl.htm`,
26
26
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
27
27
  };
@@ -25,8 +25,8 @@ class ContainsTab extends _abap_rule_1.ABAPRule {
25
25
  key: "contains_tab",
26
26
  title: "Code contains tab",
27
27
  shortDescription: `Checks for usage of tabs (enable to enforce spaces)`,
28
- extendedInformation: `
29
- https://docs.abapopenchecks.org/checks/09/
28
+ extendedInformation: `
29
+ https://docs.abapopenchecks.org/checks/09/
30
30
  https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#indent-and-snap-to-tab`,
31
31
  tags: [_irule_1.RuleTag.Whitespace, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile],
32
32
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DangerousStatement = exports.DangerousStatementConf = void 0;
4
4
  const Statements = require("../abap/2_statements/statements");
5
+ const Expressions = require("../abap/2_statements/expressions");
5
6
  const issue_1 = require("../issue");
6
7
  const _abap_rule_1 = require("./_abap_rule");
7
8
  const _basic_rule_config_1 = require("./_basic_rule_config");
@@ -24,6 +25,8 @@ class DangerousStatementConf extends _basic_rule_config_1.BasicRuleConfig {
24
25
  this.deleteTextpool = true;
25
26
  this.deleteDynpro = true;
26
27
  this.importDynpro = true;
28
+ /** Finds instances of dynamic SQL: SELECT, UPDATE, DELETE, INSERT, MODIFY */
29
+ this.dynamicSQL = true;
27
30
  }
28
31
  }
29
32
  exports.DangerousStatementConf = DangerousStatementConf;
@@ -37,6 +40,8 @@ class DangerousStatement extends _abap_rule_1.ABAPRule {
37
40
  key: "dangerous_statement",
38
41
  title: "Dangerous statement",
39
42
  shortDescription: `Detects potentially dangerous statements`,
43
+ extendedInformation: `Dynamic SQL: Typically ABAP logic does not need dynamic SQL,
44
+ dynamic SQL can potentially create SQL injection problems`,
40
45
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Security],
41
46
  };
42
47
  }
@@ -90,9 +95,29 @@ class DangerousStatement extends _abap_rule_1.ABAPRule {
90
95
  if (message) {
91
96
  issues.push(issue_1.Issue.atStatement(file, statementNode, this.getDescription(message), this.getMetadata().key, this.conf.severity));
92
97
  }
98
+ if (this.conf.dynamicSQL) {
99
+ message = this.findDynamicSQL(statementNode);
100
+ if (message) {
101
+ issues.push(issue_1.Issue.atStatement(file, statementNode, this.getDescription(message), this.getMetadata().key, this.conf.severity));
102
+ }
103
+ }
93
104
  }
94
105
  return issues;
95
106
  }
107
+ findDynamicSQL(statementNode) {
108
+ const statement = statementNode.get();
109
+ if (statement instanceof Statements.UpdateDatabase
110
+ || statement instanceof Statements.Select
111
+ || statement instanceof Statements.SelectLoop
112
+ || statement instanceof Statements.InsertDatabase
113
+ || statement instanceof Statements.ModifyDatabase
114
+ || statement instanceof Statements.DeleteDatabase) {
115
+ if (statementNode.findFirstExpression(Expressions.Dynamic)) {
116
+ return "Dynamic SQL";
117
+ }
118
+ }
119
+ return undefined;
120
+ }
96
121
  }
97
122
  exports.DangerousStatement = DangerousStatement;
98
123
  //# sourceMappingURL=dangerous_statement.js.map
@@ -32,27 +32,27 @@ class Downport {
32
32
  key: "downport",
33
33
  title: "Downport statement",
34
34
  shortDescription: `Experimental downport functionality`,
35
- extendedInformation: `Much like the 'commented_code' rule this rule loops through unknown statements and tries parsing with
36
- a higher level language version. If successful, various rules are applied to downport the statement.
37
- Target downport version is always v702, thus rule is only enabled if target version is v702.
38
-
39
- Current rules:
40
- * NEW transformed to CREATE OBJECT, opposite of https://rules.abaplint.org/use_new/
41
- * DATA() definitions are outlined, opposite of https://rules.abaplint.org/prefer_inline/
42
- * FIELD-SYMBOL() definitions are outlined
43
- * CONV is outlined
44
- * COND is outlined
45
- * REDUCE is outlined
46
- * EMPTY KEY is changed to DEFAULT KEY, opposite of DEFAULT KEY in https://rules.abaplint.org/avoid_use/
47
- * CAST changed to ?=
48
- * LOOP AT method_call( ) is outlined
49
- * VALUE # with structure fields
50
- * VALUE # with internal table lines
51
- * Table Expressions[ index ] are outlined
52
- * SELECT INTO @DATA definitions are outlined
53
- * Some occurrences of string template formatting option ALPHA changed to function module call
54
- * SELECT/INSERT/MODIFY/DELETE/UPDATE "," in field list removed, "@" in source/targets removed
55
-
35
+ extendedInformation: `Much like the 'commented_code' rule this rule loops through unknown statements and tries parsing with
36
+ a higher level language version. If successful, various rules are applied to downport the statement.
37
+ Target downport version is always v702, thus rule is only enabled if target version is v702.
38
+
39
+ Current rules:
40
+ * NEW transformed to CREATE OBJECT, opposite of https://rules.abaplint.org/use_new/
41
+ * DATA() definitions are outlined, opposite of https://rules.abaplint.org/prefer_inline/
42
+ * FIELD-SYMBOL() definitions are outlined
43
+ * CONV is outlined
44
+ * COND is outlined
45
+ * REDUCE is outlined
46
+ * EMPTY KEY is changed to DEFAULT KEY, opposite of DEFAULT KEY in https://rules.abaplint.org/avoid_use/
47
+ * CAST changed to ?=
48
+ * LOOP AT method_call( ) is outlined
49
+ * VALUE # with structure fields
50
+ * VALUE # with internal table lines
51
+ * Table Expressions[ index ] are outlined
52
+ * SELECT INTO @DATA definitions are outlined
53
+ * Some occurrences of string template formatting option ALPHA changed to function module call
54
+ * SELECT/INSERT/MODIFY/DELETE/UPDATE "," in field list removed, "@" in source/targets removed
55
+
56
56
  Only one transformation is applied to a statement at a time, so multiple steps might be required to do the full downport.`,
57
57
  tags: [_irule_1.RuleTag.Experimental, _irule_1.RuleTag.Downport, _irule_1.RuleTag.Quickfix],
58
58
  };
@@ -306,10 +306,10 @@ Only one transformation is applied to a statement at a time, so multiple steps m
306
306
  const fieldName = f.concatTokens();
307
307
  fieldDefinition += indentation + " " + fieldName + " TYPE " + tableName + "-" + fieldName + ",\n";
308
308
  }
309
- fieldDefinition = `DATA: BEGIN OF ${name},
309
+ fieldDefinition = `DATA: BEGIN OF ${name},
310
310
  ${fieldDefinition}${indentation} END OF ${name}.`;
311
311
  }
312
- const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getStart(), `${fieldDefinition}
312
+ const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getStart(), `${fieldDefinition}
313
313
  ${indentation}`);
314
314
  const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, inlineData.getFirstToken().getStart(), inlineData.getLastToken().getEnd(), name);
315
315
  const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
@@ -345,9 +345,9 @@ ${indentation}`);
345
345
  }
346
346
  const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
347
347
  const name = ((_c = inlineData.findFirstExpression(Expressions.TargetField)) === null || _c === void 0 ? void 0 : _c.concatTokens()) || "error";
348
- const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getStart(), `TYPES: BEGIN OF ${uniqueName},
349
- ${fieldDefinitions}${indentation} END OF ${uniqueName}.
350
- ${indentation}DATA ${name} TYPE STANDARD TABLE OF ${uniqueName} WITH DEFAULT KEY.
348
+ const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getStart(), `TYPES: BEGIN OF ${uniqueName},
349
+ ${fieldDefinitions}${indentation} END OF ${uniqueName}.
350
+ ${indentation}DATA ${name} TYPE STANDARD TABLE OF ${uniqueName} WITH DEFAULT KEY.
351
351
  ${indentation}`);
352
352
  const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, inlineData.getFirstToken().getStart(), inlineData.getLastToken().getEnd(), name);
353
353
  const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
@@ -381,11 +381,11 @@ ${indentation}`);
381
381
  const uniqueName = this.uniqueName(node.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
382
382
  const indentation = " ".repeat(node.getFirstToken().getStart().getCol() - 1);
383
383
  const firstToken = node.getFirstToken();
384
- const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, firstToken.getStart(), `DATA ${uniqueName} LIKE LINE OF ${pre}.
385
- ${indentation}READ TABLE ${pre} INDEX ${(_a = tableExpression.findFirstExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens()} INTO ${uniqueName}.
386
- ${indentation}IF sy-subrc <> 0.
387
- ${indentation} RAISE EXCEPTION TYPE cx_sy_itab_line_not_found.
388
- ${indentation}ENDIF.
384
+ const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, firstToken.getStart(), `DATA ${uniqueName} LIKE LINE OF ${pre}.
385
+ ${indentation}READ TABLE ${pre} INDEX ${(_a = tableExpression.findFirstExpression(Expressions.Source)) === null || _a === void 0 ? void 0 : _a.concatTokens()} INTO ${uniqueName}.
386
+ ${indentation}IF sy-subrc <> 0.
387
+ ${indentation} RAISE EXCEPTION TYPE cx_sy_itab_line_not_found.
388
+ ${indentation}ENDIF.
389
389
  ${indentation}`);
390
390
  const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, startToken.getStart(), tableExpression.getLastToken().getEnd(), uniqueName);
391
391
  const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
@@ -484,10 +484,10 @@ ${indentation}`);
484
484
  const indentation = " ".repeat(node.getFirstToken().getStart().getCol() - 1);
485
485
  const source = (_b = templateSource === null || templateSource === void 0 ? void 0 : templateSource.findDirectExpression(Expressions.Source)) === null || _b === void 0 ? void 0 : _b.concatTokens();
486
486
  const topTarget = (_c = node.findDirectExpression(Expressions.Target)) === null || _c === void 0 ? void 0 : _c.concatTokens();
487
- const code = `CALL FUNCTION '${functionName}'
488
- ${indentation} EXPORTING
489
- ${indentation} input = ${source}
490
- ${indentation} IMPORTING
487
+ const code = `CALL FUNCTION '${functionName}'
488
+ ${indentation} EXPORTING
489
+ ${indentation} input = ${source}
490
+ ${indentation} IMPORTING
491
491
  ${indentation} output = ${topTarget}.`;
492
492
  const fix = edit_helper_1.EditHelper.replaceRange(lowFile, node.getFirstToken().getStart(), node.getLastToken().getEnd(), code);
493
493
  return issue_1.Issue.atToken(lowFile, node.getFirstToken(), "Downport ALPHA", this.getMetadata().key, this.conf.severity, fix);
@@ -24,10 +24,10 @@ class ExitOrCheck extends _abap_rule_1.ABAPRule {
24
24
  return {
25
25
  key: "exit_or_check",
26
26
  title: "Find EXIT or CHECK outside loops",
27
- shortDescription: `Detects usages of EXIT or CHECK statements outside of loops.
27
+ shortDescription: `Detects usages of EXIT or CHECK statements outside of loops.
28
28
  Use RETURN to leave procesing blocks instead.`,
29
- extendedInformation: `https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenleave_processing_blocks.htm
30
- https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapcheck_processing_blocks.htm
29
+ extendedInformation: `https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenleave_processing_blocks.htm
30
+ https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapcheck_processing_blocks.htm
31
31
  https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#check-vs-return`,
32
32
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
33
33
  };
@@ -22,7 +22,7 @@ class Exporting extends _abap_rule_1.ABAPRule {
22
22
  shortDescription: `Detects EXPORTING statements which can be omitted.`,
23
23
  badExample: `call_method( EXPORTING foo = bar ).`,
24
24
  goodExample: `call_method( foo = bar ).`,
25
- extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#omit-the-optional-keyword-exporting
25
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#omit-the-optional-keyword-exporting
26
26
  https://docs.abapopenchecks.org/checks/30/`,
27
27
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
28
28
  };
@@ -26,7 +26,7 @@ class ForbiddenIdentifier extends _abap_rule_1.ABAPRule {
26
26
  key: "forbidden_identifier",
27
27
  title: "Forbidden Identifier",
28
28
  shortDescription: `Forbid use of specified identifiers, list of regex.`,
29
- extendedInformation: `Used in the transpiler to find javascript keywords in ABAP identifiers,
29
+ extendedInformation: `Used in the transpiler to find javascript keywords in ABAP identifiers,
30
30
  https://github.com/abaplint/transpiler/blob/bda94b8b56e2b7f2f87be2168f12361aa530220e/packages/transpiler/src/validation.ts#L44`,
31
31
  tags: [_irule_1.RuleTag.SingleFile],
32
32
  };
@@ -28,8 +28,8 @@ class ForbiddenVoidType {
28
28
  key: "forbidden_void_type",
29
29
  title: "Forbidden Void Types",
30
30
  shortDescription: `Avoid usage of specified void types.`,
31
- extendedInformation: `Inspiration:
32
- BOOLEAN, BOOLE_D, CHAR01, CHAR1, CHAR10, CHAR12, CHAR128, CHAR2, CHAR20, CHAR4, CHAR70,
31
+ extendedInformation: `Inspiration:
32
+ BOOLEAN, BOOLE_D, CHAR01, CHAR1, CHAR10, CHAR12, CHAR128, CHAR2, CHAR20, CHAR4, CHAR70,
33
33
  DATS, TIMS, DATUM, FLAG, INT4, NUMC3, NUMC4, SAP_BOOL, TEXT25, TEXT80, X255, XFELD`,
34
34
  };
35
35
  }
@@ -28,26 +28,26 @@ class FunctionalWriting extends _abap_rule_1.ABAPRule {
28
28
  key: "functional_writing",
29
29
  title: "Use functional writing",
30
30
  shortDescription: `Detects usage of call method when functional style calls can be used.`,
31
- extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#prefer-functional-to-procedural-calls
31
+ extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#prefer-functional-to-procedural-calls
32
32
  https://docs.abapopenchecks.org/checks/07/`,
33
33
  tags: [_irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.SingleFile],
34
- badExample: `CALL METHOD zcl_class=>method( ).
35
- CALL METHOD cl_abap_typedescr=>describe_by_name
36
- EXPORTING
37
- p_name = 'NAME'
38
- RECEIVING
39
- p_descr_ref = lr_typedescr
40
- EXCEPTIONS
41
- type_not_found = 1
34
+ badExample: `CALL METHOD zcl_class=>method( ).
35
+ CALL METHOD cl_abap_typedescr=>describe_by_name
36
+ EXPORTING
37
+ p_name = 'NAME'
38
+ RECEIVING
39
+ p_descr_ref = lr_typedescr
40
+ EXCEPTIONS
41
+ type_not_found = 1
42
42
  OTHERS = 2.`,
43
- goodExample: `zcl_class=>method( ).
44
- cl_abap_typedescr=>describe_by_name(
45
- EXPORTING
46
- p_name = 'NAME'
47
- RECEIVING
48
- p_descr_ref = lr_typedescr
49
- EXCEPTIONS
50
- type_not_found = 1
43
+ goodExample: `zcl_class=>method( ).
44
+ cl_abap_typedescr=>describe_by_name(
45
+ EXPORTING
46
+ p_name = 'NAME'
47
+ RECEIVING
48
+ p_descr_ref = lr_typedescr
49
+ EXCEPTIONS
50
+ type_not_found = 1
51
51
  OTHERS = 2 ).`,
52
52
  };
53
53
  }