Skip to content

Commit 87806be

Browse files
1.09.0 (SAP#250)
* regression feature (SAP#245) * Update changelog.txt * fixing typo (SAP#247) * Update changelog.txt * Update changelog.txt * Split 'Check LOOP' check (SAP#246) * solves SAP#223 * Update check_documentation.md * Create check-in-loop.md * Update check-in-loop.md * Update check-in-loop.md * Update check-statement-position.md * Update check-in-loop.md Co-authored-by: estevao-schultz-neto-SAP <[email protected]> * Update changelog.txt * Coverage Thresholds (SAP#249) * solves SAP#243 * versioning check * fixing version * Update changelog.txt * Update check_documentation.md * Create deprecated-classes.md * Update check_documentation.md * Delete deprecated-classes.md * Deprecated Classes (SAP#248) * new check SAP#236 * Update check_documentation.md * Create deprecated-classes.md * Update check_documentation.md * Update y_demo_failures.clas.abap * Update changelog.txt * fixing dump (c_info > c_note) * new version * solves SAP#252 * solves SAP#198 Co-authored-by: estevao-schultz-neto-SAP <[email protected]>
1 parent 1f246aa commit 87806be

27 files changed

+1474
-149
lines changed

changelog.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ Legend
88
+ : added
99
- : removed
1010

11+
2020-11-23 v1.09.0
12+
------------------
13+
+ deprecated classes/interfaces check
14+
! coverage checks threshold
15+
! 'check statement position' won't validate check in loop anymore
16+
+ new check: 'check in loop'
17+
* object creation date for classes
18+
+ service to execute regression test
19+
1120
2020-11-16 v1.08.0
1221
------------------
1322
! deprecated classes/interfaces (aunit)

docs/check_documentation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [CALL Method Usage](checks/call-method-usage.md)
99
- [Chain Declaration Usage](checks/chain-declaration-usage.md)
1010
- [CHECK Statement Position](checks/check-statement-position.md)
11+
- [CHECK in LOOP](checks/check-in-loop.md)
1112
- [Combination of Output Parameters](checks/method-output-parameter.md)
1213
- [Comment Position](checks/comment-position.md)
1314
- [Comment Type](checks/comment-type.md)
@@ -17,6 +18,7 @@
1718
- [CX_ROOT Usage](checks/cx-root-usage.md)
1819
- [Database Access in Unit-Test](checks/db-access-in-ut.md)
1920
- [Declaration in IF](checks/declaration-in-if.md)
21+
- [Deprecated Classes](checks/deprecated-classes.md)
2022
- [Deprecated Key Word](checks/deprecated-key-word.md)
2123
- [Empty Catch](checks/empty_catch.md)
2224
- [Empty IF Branches](checks/empty-if-branches.md)

docs/checks/check-in-loop.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# code pal for ABAP
2+
3+
[code pal for ABAP](../../README.md) > [Documentation](../check_documentation.md) > [CHECK in LOOP](check-in-loop.md)
4+
5+
## CHECK in LOOP
6+
7+
### What is the Intent of the Check?
8+
It verifies whether the `CHECK` statement is found inside of a `LOOP` statement. A CHECK within a LOOP, ends the current iteration and proceeds to the next one. This behaviour might lead to confusion: Does it end the method processing or does it exit the loop?
9+
10+
### How to solve the issue?
11+
Prefer using `CONTINUE` within an IF-Statement instead (since the keyword `CONTINUE` can only be used in loops, the intention is clear to everyone reading the code).
12+
Keep also in mind, the other Keywords like `EXIT` and `RETURN` are also more explicit.
13+
14+
### What to do in case of exception?
15+
In special cases you can suppress this finding by using the pseudo comment `"#EC CHECK_IN_LOOP`.
16+
17+
```abap
18+
LOOP AT tadir ASSIGNING FIELD-SYMBOL(<tadir>).
19+
CHECK <tadir>-delflag = abap_true. "#EC CHECK_IN_LOOP
20+
ENDLOOP.
21+
```
22+
23+
### Example
24+
Before the check:
25+
```abap
26+
LOOP AT tadir ASSIGNING FIELD-SYMBOL(<tadir>).
27+
CHECK <tadir>-delflag = abap_true.
28+
ENDLOOP.
29+
```
30+
31+
After the check:
32+
```abap
33+
LOOP AT tadir ASSIGNING FIELD-SYMBOL(<tadir>).
34+
IF <tadir>-delflag = abap_false.
35+
CONTINUE.
36+
ENDIF.
37+
ENDLOOP.
38+
```
39+
40+
### Further Readings & Knowledge
41+
- [Avoid CHECK in other positions (Clean ABAP)](https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md#avoid-check-in-other-positions)
42+
- [Exiting Loops -> Check](https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapcheck_loop.htm)

docs/checks/check-statement-position.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,45 @@
55
## CHECK Statement Position Check
66

77
### What is the Intent of the Check?
8-
9-
The “Check Statement Position” verifies whether the CHECK statement is in the first position (first statement) within a method, function-module or form-routine.
10-
Do not use CHECK outside of the initialization section of a method. The statement behaves differently in different positions and may lead to unclear, unexpected effects.
8+
The "Check Statement Position" verifies whether the `CHECK` statement is in the first position (first statement) within a method, function-module or form-routine.
9+
Do not use `CHECK` outside of the initialization section of a method. The statement behaves differently in different positions and may lead to unclear, unexpected effects.
1110

1211
### Which attributes can be maintained?
13-
1412
![Attributes](./imgs/check_statement_position.png)
1513

1614
### How to solve the issue?
17-
18-
The CHECK statement shall be the first statement of a method (suggested even before any DATA declaration); if not, try to substitute this keyword by an IF-statement instead.
15+
The `CHECK` statement shall be the first statement of a method (suggested even before any DATA declaration);
16+
If not, try to substitute this keyword by an IF-statement instead.
1917

2018
### What to do in case of exception?
21-
2219
In special cases you can suppress this finding by using the pseudo comment `"#EC CHECK_POSITION`.
2320

2421
### Example
25-
22+
Before the check:
2623
```abap
27-
METHOD method_name.
28-
29-
1 some ABAP source code.
30-
31-
2 CHECK condition. "#EC CHECK_POSITION
32-
33-
3 some more ABAP source code.
24+
METHOD example.
25+
...
26+
CHECK sy-mandt = 000.
27+
...
28+
ENDMETHOD.
29+
```
3430

31+
After the check:
32+
```abap
33+
METHOD example.
34+
...
35+
IF sy-mandt <> 000.
36+
RETURN.
37+
ENDIF.
38+
...
3539
ENDMETHOD.
3640
```
41+
```abap
42+
METHOD example.
43+
CHECK sy-mandt = 000.
44+
...
45+
ENDMETHOD.
46+
```
47+
48+
### Further Readings & Knowledge
49+
- [Avoid CHECK in other positions (Clean ABAP)](https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md#avoid-check-in-other-positions)

docs/checks/deprecated-classes.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# code pal for ABAP
2+
3+
[code pal for ABAP](../../README.md) > [Documentation](../check_documentation.md) > [Deprecated Classes](deprecated-classes.md)
4+
5+
## Deprecated Classes
6+
7+
### What is the Intent of the Check?
8+
9+
It points out deprecated classes which should be replaced by newer objects.
10+
11+
You can check the list of supported objects in the `constructor` of the `y_check_deprecated_classes` class.
12+
13+
### How does the check work?
14+
15+
This check searches for the usage of deprecated classes.
16+
17+
### How to solve the issue?
18+
19+
Use the newer objects instead.
20+
21+
### What to do in case of exception?
22+
23+
You can suppress Code Inspector findings generated by this check using the pseudo comment `"#EC DEPRECATED_CLAS`.
24+
The pseudo comment must be placed right after the statement.
25+
26+
Before the check:
27+
```abap
28+
DATA aunit TYPE REF TO cl_aunit_assert.
29+
```
30+
31+
After the check:
32+
```abap
33+
DATA aunit TYPE REF TO cl_abap_unit_assert.
34+
```

src/checks/y_check_branch_coverage.clas.abap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ CLASS y_check_branch_coverage IMPLEMENTATION.
1414
METHOD constructor.
1515
super->constructor( ).
1616

17-
settings-prio = c_warning.
18-
settings-threshold = 100.
17+
version = '0001'.
18+
19+
settings-prio = c_note.
20+
settings-threshold = 70.
1921
settings-is_threshold_reversed = abap_true.
2022
settings-disable_on_prodcode_selection = abap_true.
2123
settings-disable_on_testcode_selection = abap_true.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
CLASS y_check_check_in_loop DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC .
2+
PUBLIC SECTION.
3+
METHODS constructor .
4+
5+
PROTECTED SECTION.
6+
METHODS execute_check REDEFINITION.
7+
METHODS inspect_tokens REDEFINITION.
8+
9+
PRIVATE SECTION.
10+
METHODS get_back_statement IMPORTING structure TYPE sstruc
11+
RETURNING VALUE(result) TYPE sstmnt.
12+
13+
ENDCLASS.
14+
15+
16+
17+
CLASS y_check_check_in_loop IMPLEMENTATION.
18+
19+
20+
METHOD constructor.
21+
super->constructor( ).
22+
23+
settings-pseudo_comment = '"#EC CHECK_IN_LOOP' ##NO_TEXT.
24+
settings-disable_threshold_selection = abap_true.
25+
settings-threshold = 0.
26+
settings-documentation = |{ c_docs_path-checks }check-in-loop.md|.
27+
28+
set_check_message( 'Use an IF statement in combination with CONTINUE instead CHECK!' ).
29+
ENDMETHOD.
30+
31+
32+
METHOD execute_check.
33+
LOOP AT ref_scan_manager->get_structures( ) ASSIGNING FIELD-SYMBOL(<structure>)
34+
WHERE stmnt_type EQ scan_struc_stmnt_type-check.
35+
36+
is_testcode = test_code_detector->is_testcode( <structure> ).
37+
38+
TRY.
39+
DATA(check_configuration) = check_configurations[ apply_on_testcode = abap_true ].
40+
CATCH cx_sy_itab_line_not_found.
41+
IF is_testcode EQ abap_true.
42+
CONTINUE.
43+
ENDIF.
44+
ENDTRY.
45+
46+
DATA(index) = <structure>-stmnt_from.
47+
48+
LOOP AT ref_scan_manager->get_statements( ) ASSIGNING FIELD-SYMBOL(<statement>)
49+
FROM <structure>-stmnt_from TO <structure>-stmnt_to.
50+
51+
inspect_tokens( index = index
52+
structure = <structure>
53+
statement = <statement> ).
54+
index = index + 1.
55+
ENDLOOP.
56+
ENDLOOP.
57+
ENDMETHOD.
58+
59+
60+
METHOD inspect_tokens.
61+
CHECK get_token_abs( statement-from ) = 'CHECK'.
62+
CHECK get_token_abs( get_back_statement( structure )-from ) = 'LOOP'.
63+
64+
DATA(check_configuration) = detect_check_configuration( statement ).
65+
66+
IF check_configuration IS INITIAL.
67+
RETURN.
68+
ENDIF.
69+
70+
raise_error( statement_level = statement-level
71+
statement_index = index
72+
statement_from = statement-from
73+
error_priority = check_configuration-prio ).
74+
ENDMETHOD.
75+
76+
77+
METHOD get_back_statement.
78+
DATA(structures) = ref_scan_manager->get_structures( ).
79+
DATA(statements) = ref_scan_manager->get_statements( ).
80+
81+
TRY.
82+
DATA(back_structure) = structures[ structure-back ].
83+
result = statements[ back_structure-stmnt_from ].
84+
CATCH cx_sy_itab_line_not_found.
85+
CLEAR result.
86+
ENDTRY.
87+
ENDMETHOD.
88+
89+
90+
ENDCLASS.

0 commit comments

Comments
 (0)