Skip to content

Commit

Permalink
Merge pull request #292 from SAP/1.11.0
Browse files Browse the repository at this point in the history
1.11.0
  • Loading branch information
lucasborin authored Jan 18, 2021
2 parents 7903ab6 + 3bcf450 commit 7e49c5f
Show file tree
Hide file tree
Showing 80 changed files with 1,727 additions and 1,839 deletions.
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ Upgrade Note
------------------
Whenever you upgrade code pal for ABAP, it is highly recommended to execute the Y_CI_CHECK_REGISTRATION report to activate/reactivate the Checks (SE38 transaction) and regenerate the respective code inspector variant (SCI transaction)

2021-01-18 v1.11.0
------------------
* CHECK position after comments (#301)
* Modify an Internal Table is no DB Access (#300)
+ Enhancing coverage to run for multiple objects (#294)
! Disabling profiles when the API executes the regression (#293)
* DELETE from internal table gives a "Database access" prio 1 error (#290)
! The pseudo comment position of the Form Routine Check was moved from the 'ENDFORM' to 'FORM' statement
! The pseudo comment position of the Number of Public Attributes was moved from the 'CLASS DEFINITION.' to 'PUBLIC SECTION' statement

2020-12-14 v1.10.0
------------------
+ New Check: Scope of the Variable (#276)
Expand Down
6 changes: 3 additions & 3 deletions docs/checks/form-routine.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ Use classes and methods instead. Methods are similar to subroutines and can be u
### What to do in case of exception?

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

```abap
FORM my_form.
FORM my_form. "#EC CI_FORM
" Form content
ENDFORM. "#EC CI_FORM
ENDFORM.
```

### Further Readings & Knowledge
Expand Down
6 changes: 3 additions & 3 deletions docs/checks/number-public-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Make those attributes `PRIVATE` or `PROTECTED`. You can grant the read access wi
### What to do in case of exception?

You can suppress Code Inspector findings generated by this check using the pseudo comment `"#EC NUM_PUBLIC_ATTR`.
The pseudo comment must be placed right after the class definition header.
The pseudo comment must be placed right after the `PUBLIC SECTION` statement.

```abap
CLASS class_name DEFINITION. "#EC NUM_PUBLIC_ATTR
PUBLIC SECTION.
CLASS class_name DEFINITION.
PUBLIC SECTION. "#EC NUM_PUBLIC_ATTR
DATA attribute1 TYPE i.
DATA attribute2 TYPE i.
ENDCLASS.
Expand Down
39 changes: 11 additions & 28 deletions src/checks/y_check_boolean_input_param.clas.abap
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
CLASS y_check_boolean_input_param 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 is_setter_method IMPORTING statement TYPE sstmnt
RETURNING VALUE(result) TYPE abap_bool.

METHODS has_boolean_input_param IMPORTING statement TYPE sstmnt
RETURNING VALUE(result) TYPE abap_bool.
ENDCLASS.


CLASS y_check_boolean_input_param IMPLEMENTATION.


METHOD constructor.
super->constructor( ).

Expand All @@ -22,35 +25,12 @@ CLASS y_check_boolean_input_param IMPLEMENTATION.
settings-threshold = 0.
settings-documentation = |{ c_docs_path-checks }boolean-input-parameter.md|.

relevant_statement_types = VALUE #( ( scan_struc_stmnt_type-class_definition ) ).
relevant_structure_types = VALUE #( ).

set_check_message( 'Split method instead of Boolean input parameter!' ).
ENDMETHOD.

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

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.

Expand All @@ -71,14 +51,16 @@ CLASS y_check_boolean_input_param IMPLEMENTATION.

ENDMETHOD.


METHOD is_setter_method.
DATA(method_name) = get_token_abs( statement-from + 1 ).
result = COND #( WHEN method_name CS 'SET_' THEN abap_true ).
ENDMETHOD.


METHOD has_boolean_input_param.
DATA(skip) = abap_true.
LOOP AT ref_scan_manager->get_tokens( ) ASSIGNING FIELD-SYMBOL(<token>)
LOOP AT ref_scan_manager->tokens ASSIGNING FIELD-SYMBOL(<token>)
FROM statement-from TO statement-to.

IF <token>-str = 'IMPORTING'.
Expand All @@ -101,4 +83,5 @@ CLASS y_check_boolean_input_param IMPLEMENTATION.
ENDLOOP.
ENDMETHOD.


ENDCLASS.
13 changes: 10 additions & 3 deletions src/checks/y_check_branch_coverage.clas.abap
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
CLASS y_check_branch_coverage DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC .
PUBLIC SECTION.
METHODS constructor.

PROTECTED SECTION.
METHODS execute_check REDEFINITION.
METHODS inspect_tokens REDEFINITION.

ENDCLASS.


Expand Down Expand Up @@ -34,11 +36,14 @@ CLASS y_check_branch_coverage IMPLEMENTATION.
DATA(coverage) = y_unit_test_coverage=>get( program_name = program_name
object = VALUE #( object = object_type obj_name = object_name )
coverage_type = ce_scv_coverage_type=>branch ).

DATA(branch) = round( val = coverage->get_percentage( )
dec = 2 ).
CATCH cx_scv_execution_error.
RETURN.
ENDTRY.

DATA(check_configuration) = detect_check_configuration( error_count = CONV #( coverage )
DATA(check_configuration) = detect_check_configuration( error_count = CONV #( branch )
statement = VALUE #( level = 1 ) ).

IF check_configuration IS INITIAL.
Expand All @@ -49,8 +54,10 @@ CLASS y_check_branch_coverage IMPLEMENTATION.
statement_index = 1
statement_from = 1
error_priority = check_configuration-prio
parameter_01 = |{ coverage }|
parameter_02 = |{ check_configuration-threshold }| ).
parameter_01 = |{ branch }|
parameter_02 = |{ check_configuration-threshold }|
parameter_03 = |{ coverage->get_total( ) }|
parameter_04 = |{ coverage->get_executed( ) }| ).

ENDMETHOD.

Expand Down
11 changes: 5 additions & 6 deletions src/checks/y_check_call_method_usage.clas.abap
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
CLASS y_check_call_method_usage DEFINITION
PUBLIC
INHERITING FROM y_check_base
CREATE PUBLIC .

CLASS y_check_call_method_usage DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC .
PUBLIC SECTION.
METHODS constructor .

PROTECTED SECTION.
METHODS inspect_tokens REDEFINITION.
PRIVATE SECTION.

ENDCLASS.


Expand Down Expand Up @@ -49,4 +46,6 @@ CLASS y_check_call_method_usage IMPLEMENTATION.
error_priority = check_configuration-prio ).
ENDIF.
ENDMETHOD.


ENDCLASS.
6 changes: 5 additions & 1 deletion src/checks/y_check_chain_decl_usage.clas.abap
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
CLASS y_check_chain_decl_usage DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC .
CLASS y_check_chain_decl_usage DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor.

PROTECTED SECTION.
METHODS inspect_tokens REDEFINITION.

PRIVATE SECTION.
DATA rows_with_colon TYPE STANDARD TABLE OF stmnt_crow.

METHODS has_error_not_raised_yet IMPORTING statement TYPE sstmnt RETURNING VALUE(result) TYPE abap_bool.

ENDCLASS.


Expand Down
39 changes: 5 additions & 34 deletions src/checks/y_check_check_in_loop.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ CLASS y_check_check_in_loop DEFINITION PUBLIC INHERITING FROM y_check_base CREAT
METHODS constructor .

PROTECTED SECTION.
METHODS execute_check REDEFINITION.
METHODS inspect_tokens REDEFINITION.

PRIVATE SECTION.
Expand All @@ -25,35 +24,10 @@ CLASS y_check_check_in_loop IMPLEMENTATION.
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> ).
relevant_statement_types = VALUE #( ( scan_struc_stmnt_type-check ) ).
relevant_structure_types = VALUE #( ).

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.
set_check_message( 'Use an IF statement in combination with CONTINUE instead CHECK!' ).
ENDMETHOD.


Expand All @@ -75,12 +49,9 @@ CLASS y_check_check_in_loop IMPLEMENTATION.


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 ].
DATA(back_structure) = ref_scan_manager->structures[ structure-back ].
result = ref_scan_manager->statements[ back_structure-stmnt_from ].
CATCH cx_sy_itab_line_not_found.
CLEAR result.
ENDTRY.
Expand Down
16 changes: 11 additions & 5 deletions src/checks/y_check_check_stmnt_position.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,24 @@ CLASS y_check_check_stmnt_position IMPLEMENTATION.
OR token EQ 'DATA'
OR token EQ 'TYPES'
OR token EQ 'CHECK'
OR token EQ 'FIELD-SYMBOLS' ).
OR token EQ 'FIELD-SYMBOLS'
OR token EQ 'CONSTANTS' ).
ENDMETHOD.


METHOD has_wrong_position.
DATA(statements) = ref_scan_manager->get_statements( ).

LOOP AT ref_scan_manager->get_statements( ) ASSIGNING FIELD-SYMBOL(<statement>)
LOOP AT ref_scan_manager->statements ASSIGNING FIELD-SYMBOL(<statement>)
FROM structure-stmnt_from TO structure-stmnt_to.
IF <statement>-type = scan_stmnt_type-empty
OR <statement>-type = scan_stmnt_type-comment
OR <statement>-type = scan_stmnt_type-comment_in_stmnt.
CONTINUE.
ENDIF.

IF <statement>-number = check-number.
RETURN.
ENDIF.

IF is_not_relevant_token( get_token_abs( <statement>-from ) ) = abap_false.
result = abap_true.
RETURN.
Expand All @@ -87,7 +93,7 @@ CLASS y_check_check_stmnt_position IMPLEMENTATION.


METHOD is_check_in_loop.
LOOP AT ref_scan_manager->get_tokens( ) ASSIGNING FIELD-SYMBOL(<token>)
LOOP AT ref_scan_manager->tokens ASSIGNING FIELD-SYMBOL(<token>)
FROM structure-stmnt_from TO check-from
WHERE str = 'LOOP'
OR str = 'ENDLOOP'.
Expand Down
Loading

0 comments on commit 7e49c5f

Please sign in to comment.