Skip to content

Commit

Permalink
1.09.0 (#250)
Browse files Browse the repository at this point in the history
* regression feature (#245)

* Update changelog.txt

* fixing typo (#247)

* Update changelog.txt

* Update changelog.txt

* Split 'Check LOOP' check (#246)

* solves #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 <63100656+estevao-schultz-neto-SAP@users.noreply.github.com>

* Update changelog.txt

* Coverage Thresholds  (#249)

* solves #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 (#248)

* new check #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 #252

* solves #198

Co-authored-by: estevao-schultz-neto-SAP <63100656+estevao-schultz-neto-SAP@users.noreply.github.com>
  • Loading branch information
lucasborin and estevao-schultz-neto-SAP authored Nov 23, 2020
1 parent 1f246aa commit 87806be
Show file tree
Hide file tree
Showing 27 changed files with 1,474 additions and 149 deletions.
9 changes: 9 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ Legend
+ : added
- : removed

2020-11-23 v1.09.0
------------------
+ deprecated classes/interfaces check
! coverage checks threshold
! 'check statement position' won't validate check in loop anymore
+ new check: 'check in loop'
* object creation date for classes
+ service to execute regression test

2020-11-16 v1.08.0
------------------
! deprecated classes/interfaces (aunit)
Expand Down
2 changes: 2 additions & 0 deletions docs/check_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [CALL Method Usage](checks/call-method-usage.md)
- [Chain Declaration Usage](checks/chain-declaration-usage.md)
- [CHECK Statement Position](checks/check-statement-position.md)
- [CHECK in LOOP](checks/check-in-loop.md)
- [Combination of Output Parameters](checks/method-output-parameter.md)
- [Comment Position](checks/comment-position.md)
- [Comment Type](checks/comment-type.md)
Expand All @@ -17,6 +18,7 @@
- [CX_ROOT Usage](checks/cx-root-usage.md)
- [Database Access in Unit-Test](checks/db-access-in-ut.md)
- [Declaration in IF](checks/declaration-in-if.md)
- [Deprecated Classes](checks/deprecated-classes.md)
- [Deprecated Key Word](checks/deprecated-key-word.md)
- [Empty Catch](checks/empty_catch.md)
- [Empty IF Branches](checks/empty-if-branches.md)
Expand Down
42 changes: 42 additions & 0 deletions docs/checks/check-in-loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# code pal for ABAP

[code pal for ABAP](../../README.md) > [Documentation](../check_documentation.md) > [CHECK in LOOP](check-in-loop.md)

## CHECK in LOOP

### What is the Intent of the Check?
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?

### How to solve the issue?
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).
Keep also in mind, the other Keywords like `EXIT` and `RETURN` are also more explicit.

### What to do in case of exception?
In special cases you can suppress this finding by using the pseudo comment `"#EC CHECK_IN_LOOP`.

```abap
LOOP AT tadir ASSIGNING FIELD-SYMBOL(<tadir>).
CHECK <tadir>-delflag = abap_true. "#EC CHECK_IN_LOOP
ENDLOOP.
```

### Example
Before the check:
```abap
LOOP AT tadir ASSIGNING FIELD-SYMBOL(<tadir>).
CHECK <tadir>-delflag = abap_true.
ENDLOOP.
```

After the check:
```abap
LOOP AT tadir ASSIGNING FIELD-SYMBOL(<tadir>).
IF <tadir>-delflag = abap_false.
CONTINUE.
ENDIF.
ENDLOOP.
```

### Further Readings & Knowledge
- [Avoid CHECK in other positions (Clean ABAP)](https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md#avoid-check-in-other-positions)
- [Exiting Loops -> Check](https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapcheck_loop.htm)
43 changes: 28 additions & 15 deletions docs/checks/check-statement-position.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,45 @@
## CHECK Statement Position Check

### What is the Intent of the Check?

The “Check Statement Position” verifies whether the CHECK statement is in the first position (first statement) within a method, function-module or form-routine.
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.
The "Check Statement Position" verifies whether the `CHECK` statement is in the first position (first statement) within a method, function-module or form-routine.
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.

### Which attributes can be maintained?

![Attributes](./imgs/check_statement_position.png)

### How to solve the issue?

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.
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.

### What to do in case of exception?

In special cases you can suppress this finding by using the pseudo comment `"#EC CHECK_POSITION`.

### Example

Before the check:
```abap
METHOD method_name.
1 some ABAP source code.
2 CHECK condition. "#EC CHECK_POSITION
3 some more ABAP source code.
METHOD example.
...
CHECK sy-mandt = 000.
...
ENDMETHOD.
```

After the check:
```abap
METHOD example.
...
IF sy-mandt <> 000.
RETURN.
ENDIF.
...
ENDMETHOD.
```
```abap
METHOD example.
CHECK sy-mandt = 000.
...
ENDMETHOD.
```

### Further Readings & Knowledge
- [Avoid CHECK in other positions (Clean ABAP)](https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md#avoid-check-in-other-positions)
34 changes: 34 additions & 0 deletions docs/checks/deprecated-classes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# code pal for ABAP

[code pal for ABAP](../../README.md) > [Documentation](../check_documentation.md) > [Deprecated Classes](deprecated-classes.md)

## Deprecated Classes

### What is the Intent of the Check?

It points out deprecated classes which should be replaced by newer objects.

You can check the list of supported objects in the `constructor` of the `y_check_deprecated_classes` class.

### How does the check work?

This check searches for the usage of deprecated classes.

### How to solve the issue?

Use the newer objects instead.

### What to do in case of exception?

You can suppress Code Inspector findings generated by this check using the pseudo comment `"#EC DEPRECATED_CLAS`.
The pseudo comment must be placed right after the statement.

Before the check:
```abap
DATA aunit TYPE REF TO cl_aunit_assert.
```

After the check:
```abap
DATA aunit TYPE REF TO cl_abap_unit_assert.
```
6 changes: 4 additions & 2 deletions src/checks/y_check_branch_coverage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ CLASS y_check_branch_coverage IMPLEMENTATION.
METHOD constructor.
super->constructor( ).

settings-prio = c_warning.
settings-threshold = 100.
version = '0001'.

settings-prio = c_note.
settings-threshold = 70.
settings-is_threshold_reversed = abap_true.
settings-disable_on_prodcode_selection = abap_true.
settings-disable_on_testcode_selection = abap_true.
Expand Down
90 changes: 90 additions & 0 deletions src/checks/y_check_check_in_loop.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
CLASS y_check_check_in_loop DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC .
PUBLIC SECTION.
METHODS constructor .

PROTECTED SECTION.
METHODS execute_check REDEFINITION.
METHODS inspect_tokens REDEFINITION.

PRIVATE SECTION.
METHODS get_back_statement IMPORTING structure TYPE sstruc
RETURNING VALUE(result) TYPE sstmnt.

ENDCLASS.



CLASS y_check_check_in_loop IMPLEMENTATION.


METHOD constructor.
super->constructor( ).

settings-pseudo_comment = '"#EC CHECK_IN_LOOP' ##NO_TEXT.
settings-disable_threshold_selection = abap_true.
settings-threshold = 0.
settings-documentation = |{ c_docs_path-checks }check-in-loop.md|.

set_check_message( 'Use an IF statement in combination with CONTINUE instead CHECK!' ).
ENDMETHOD.


METHOD execute_check.
LOOP AT ref_scan_manager->get_structures( ) ASSIGNING FIELD-SYMBOL(<structure>)
WHERE stmnt_type EQ scan_struc_stmnt_type-check.

is_testcode = test_code_detector->is_testcode( <structure> ).

TRY.
DATA(check_configuration) = check_configurations[ apply_on_testcode = abap_true ].
CATCH cx_sy_itab_line_not_found.
IF is_testcode EQ abap_true.
CONTINUE.
ENDIF.
ENDTRY.

DATA(index) = <structure>-stmnt_from.

LOOP AT ref_scan_manager->get_statements( ) ASSIGNING FIELD-SYMBOL(<statement>)
FROM <structure>-stmnt_from TO <structure>-stmnt_to.

inspect_tokens( index = index
structure = <structure>
statement = <statement> ).
index = index + 1.
ENDLOOP.
ENDLOOP.
ENDMETHOD.


METHOD inspect_tokens.
CHECK get_token_abs( statement-from ) = 'CHECK'.
CHECK get_token_abs( get_back_statement( structure )-from ) = 'LOOP'.

DATA(check_configuration) = detect_check_configuration( statement ).

IF check_configuration IS INITIAL.
RETURN.
ENDIF.

raise_error( statement_level = statement-level
statement_index = index
statement_from = statement-from
error_priority = check_configuration-prio ).
ENDMETHOD.


METHOD get_back_statement.
DATA(structures) = ref_scan_manager->get_structures( ).
DATA(statements) = ref_scan_manager->get_statements( ).

TRY.
DATA(back_structure) = structures[ structure-back ].
result = statements[ back_structure-stmnt_from ].
CATCH cx_sy_itab_line_not_found.
CLEAR result.
ENDTRY.
ENDMETHOD.


ENDCLASS.
Loading

0 comments on commit 87806be

Please sign in to comment.