Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d9ac7d1
fixes #156
lucasborin Sep 29, 2020
edcea84
Update changelog.txt
lucasborin Sep 29, 2020
c6f866f
Update changelog.txt
lucasborin Sep 29, 2020
6917ebc
enabling log in exemption table
lucasborin Sep 29, 2020
28d9685
Update changelog.txt
lucasborin Sep 29, 2020
6d0b75f
Extend magic number check to find numbers in single quotes (#160)
smb Oct 1, 2020
3e42646
Update changelog.txt
lucasborin Oct 1, 2020
686a21d
fixes #154
lucasborin Oct 1, 2020
2a0aac8
Adding unit test to new magic number
lucasborin Oct 1, 2020
8f3026e
adding / removing all checks
lucasborin Oct 2, 2020
9093d9c
Update changelog.txt
lucasborin Oct 2, 2020
78c1cea
1.05.0
lucasborin Oct 2, 2020
149709c
fixes #136
lucasborin Oct 5, 2020
4eaf972
Update changelog.txt
lucasborin Oct 5, 2020
383d93d
How to install via report
lucasborin Oct 5, 2020
99fbf14
typo
lucasborin Oct 5, 2020
2424ea0
allows run only once
lucasborin Oct 7, 2020
60d273c
execute the profile check only once
lucasborin Oct 7, 2020
232b687
Update changelog.txt
lucasborin Oct 7, 2020
9ccb045
Update changelog.txt
lucasborin Oct 7, 2020
a18fae5
category decription update
Oct 8, 2020
5a3bf96
Update changelog.txt
Oct 8, 2020
48949df
Update changelog.txt
lucasborin Oct 8, 2020
fb890fc
reverting run only once
lucasborin Oct 8, 2020
afa5944
disabling coverages in test code (#166)
lucasborin Oct 9, 2020
6f2c34e
&1 attributes reach threshold of &2 (#168)
lucasborin Oct 9, 2020
dd7e165
Disabling "db access in ut" check when the OSQL/CDS UT framework is i…
lucasborin Oct 15, 2020
127518a
Standardizing Messages (#174)
lucasborin Oct 15, 2020
1062fdc
Update changelog.txt
lucasborin Oct 15, 2020
b0f1341
Raising profile message only once (#169)
lucasborin Oct 16, 2020
be98bb1
Merge branch 'master' into 1.05.0
lucasborin Oct 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-10-10 v1.05.0
------------------
* profile message check runs only once
! check messages
- db access in ut when OSQL/CDS framework is being used
! category description
+ report to activate or deactivate the SCI entries
+ add/remove all check in profiles

2020-10-05 v1.04.1
------------------
* magic number to support numeric strings (#142)
Expand Down
22 changes: 5 additions & 17 deletions pages/how-to-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,26 @@ Follow the step-by-step available in the abapGit documentation: [Installing onli

![how to clone repository](imgs/clone-repository.png)

### 2. Activate code pal for ABAP category
### 2. Activate code pal for ABAP

Start the transaction `SCI`, and go to the `Code Inspector > Management of > Checks` menu.
Then, select the `Y_CATEGORY_CODE_PAL` check class and save it.
Execute the report `Y_CI_CHECK_REGISTRATION` using the run mode `Activate`.

![how to activate the category](imgs/sci-management-of-checks.png)

(In some system releases, the path to the `Check Management` might differ from the screenshot.)

### 3. Activate code pal for ABAP checks

Start the transaction `SCI` again, and go to the `Code Inspector > Management of > Checks` menu.
Then, select all the `Y_CHECK_*` check classes and save it.

![how to activate the checks](imgs/sci-checks.png)

### 4. Create code inspector variant
### 3. Create code inspector variant

Start the transaction `SCI` again, and create a new global check variant.
Then, select the `code pal for ABAP` group and save it.

![how to create code inspector variant](imgs/sci-check-variant.png)

### 5. User Parameter
### 4. User Parameter

It requires you to set the ABAP Test Cockpit (ATC) to run in Code Inspector mode.

Start the transaction `SU3`, and add/set the user parameter `SATC_CI_MODE` to `X`:

![user parameter](imgs/user-parameter.png)

### 6. Service
### 5. Service

> :warn: Optional Feature!

Expand Down
Binary file removed pages/imgs/sci-checks.png
Binary file not shown.
Binary file removed pages/imgs/sci-management-of-checks.png
Binary file not shown.
20 changes: 10 additions & 10 deletions src/categories/y_category_code_pal.clas.abap
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
CLASS y_category_code_pal DEFINITION
PUBLIC
INHERITING FROM cl_ci_category_root
CREATE PUBLIC .
class Y_CATEGORY_CODE_PAL definition
public
inheriting from CL_CI_CATEGORY_ROOT
create public .

PUBLIC SECTION.
public section.

METHODS constructor .
methods CONSTRUCTOR .

METHODS if_ci_test~display_documentation
REDEFINITION .
methods IF_CI_TEST~DISPLAY_DOCUMENTATION
redefinition .
PROTECTED SECTION.
METHODS get_class_description
RETURNING VALUE(result) TYPE string.
PRIVATE SECTION.
ENDCLASS.


CLASS y_category_code_pal IMPLEMENTATION.

CLASS Y_CATEGORY_CODE_PAL IMPLEMENTATION.


METHOD constructor.
Expand Down Expand Up @@ -54,5 +55,4 @@ CLASS y_category_code_pal IMPLEMENTATION.
result = 'Description Not Available'.
ENDTRY.
ENDMETHOD.

ENDCLASS.
2 changes: 1 addition & 1 deletion src/categories/y_category_code_pal.clas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<VSEOCLASS>
<CLSNAME>Y_CATEGORY_CODE_PAL</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>code pal for ABAP</DESCRIPT>
<DESCRIPT>code pal for ABAP (open source plugin)</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
Expand Down
3 changes: 2 additions & 1 deletion src/checks/y_check_branch_coverage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ CLASS y_check_branch_coverage IMPLEMENTATION.
settings-is_threshold_reversed = abap_true.
settings-disable_on_prodcode_selection = abap_true.
settings-disable_on_testcode_selection = abap_true.
settings-apply_on_test_code = abap_false.
settings-documentation = |{ c_docs_path-checks }unit-test-coverages.md|.

set_check_message( 'Branch Coverage of &1% is under the threshold of &2%.' ).
set_check_message( 'Branch Coverage of &1% does not reach the threshold of &2%!' ).
ENDMETHOD.


Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_call_method_usage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CLASS y_check_call_method_usage IMPLEMENTATION.
settings-threshold = 0.
settings-documentation = |{ c_docs_path-checks }call-method-usage.md|.

set_check_message( '"CALL METHOD" Statement should not be used!' ).
set_check_message( '"CALL METHOD" statement should not be used!' ).
ENDMETHOD.


Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_check_stmnt_position.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CLASS Y_CHECK_CHECK_STMNT_POSITION IMPLEMENTATION.
settings-threshold = 0.
settings-documentation = |{ c_docs_path-checks }check-statement-position.md|.

set_check_message( '"CHECK" Statement should be the very first statement.' ).
set_check_message( '"CHECK" statement should be the very first statement!' ).
ENDMETHOD.


Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_comment_usage.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ CLASS Y_CHECK_COMMENT_USAGE IMPLEMENTATION.
settings-threshold = 10.
settings-documentation = |{ c_docs_path-checks }comment-usage.md|.

set_check_message( '&1 comments found! This is &2% of the productive code, exceeding threshold of &3%' ).
set_check_message( '&1 comments found! This is &2% of the productive code reaching threshold of &3%!' ).
ENDMETHOD.


Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_cyclomatic_complexity.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ CLASS Y_CHECK_CYCLOMATIC_COMPLEXITY IMPLEMENTATION.
settings-threshold = 10.
settings-documentation = |{ c_docs_path-checks }cyclomatic-complexity.md|.

set_check_message( 'Cyclomatic complexity is &1, exceeding threshold of &2' ).
set_check_message( 'Cyclomatic complexity is &1 reaching threshold of &2!' ).
ENDMETHOD.


Expand Down
39 changes: 20 additions & 19 deletions src/checks/y_check_db_access_in_ut.clas.abap
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
CLASS y_check_db_access_in_ut DEFINITION
PUBLIC
INHERITING FROM y_check_base
CREATE PUBLIC .

CLASS y_check_db_access_in_ut DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor .
METHODS constructor.
PROTECTED SECTION.
METHODS execute_check REDEFINITION.
METHODS inspect_tokens REDEFINITION.

METHODS has_osql_or_cds_framework RETURNING VALUE(result) TYPE abap_bool.
PRIVATE SECTION.

METHODS is_persistent_object
IMPORTING
!obj_name TYPE string
RETURNING
VALUE(result) TYPE abap_bool .

METHODS check_if_error
IMPORTING
!index TYPE i OPTIONAL
!statement TYPE sstmnt OPTIONAL .
METHODS is_persistent_object IMPORTING obj_name TYPE string
RETURNING VALUE(result) TYPE abap_bool .
METHODS check_if_error IMPORTING index TYPE i OPTIONAL
statement TYPE sstmnt OPTIONAL .
ENDCLASS.



CLASS Y_CHECK_DB_ACCESS_IN_UT IMPLEMENTATION.


Expand All @@ -45,6 +33,9 @@ CLASS Y_CHECK_DB_ACCESS_IN_UT IMPLEMENTATION.


METHOD execute_check.

CHECK has_osql_or_cds_framework( ) = abap_false.

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

Expand Down Expand Up @@ -144,4 +135,14 @@ CLASS Y_CHECK_DB_ACCESS_IN_UT IMPLEMENTATION.
parameter_01 = |{ key_word }| ).

ENDMETHOD.

METHOD has_osql_or_cds_framework.
DATA(tokens) = ref_scan_manager->get_tokens( ).

IF line_exists( tokens[ str = 'IF_OSQL_TEST_ENVIRONMENT' ] )
OR line_exists( tokens[ str = 'IF_CDS_TEST_ENVIRONMENT' ] ).
result = abap_true.
ENDIF.
ENDMETHOD.

ENDCLASS.
102 changes: 102 additions & 0 deletions src/checks/y_check_db_access_in_ut.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,105 @@ CLASS ltc_commit IMPLEMENTATION.
ENDMETHOD.

ENDCLASS.

CLASS ltc_osql_framework DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_cut REDEFINITION.
METHODS get_code_with_issue REDEFINITION.
METHODS get_code_without_issue REDEFINITION.
METHODS get_code_with_exemption REDEFINITION.
ENDCLASS.

CLASS ltc_osql_framework IMPLEMENTATION.

METHOD get_cut.
result ?= NEW y_check_db_access_in_ut( ).
ENDMETHOD.

METHOD get_code_with_issue.
result = VALUE #(
( ' REPORT ut_test. ' )

( ' CLASS lcl_classname DEFINITION FOR TESTING. ' )
( ' PUBLIC SECTION. ' )
( ' METHODS example FOR TESTING. ' )
( ' ENDCLASS.' )

( ' CLASS lcl_classname IMPLEMENTATION. ' )
( ' METHOD example. ' )
( ' DATA tadir TYPE tadir. ' )
( ' SELECT SINGLE * FROM tadir INTO tadir. ' )
( ' ENDMETHOD. ' )
( ' ENDCLASS. ' )
).
ENDMETHOD.

METHOD get_code_without_issue.
result = VALUE #(
( ' REPORT ut_test. ' )

( ' CLASS lcl_classname DEFINITION FOR TESTING. ' )
( ' PUBLIC SECTION. ' )
( ' METHODS scenario FOR TESTING. ' )
( ' PROTECTED SECTION. ' )
( ' METHODS given_fake_value. ' )
( ' METHODS when_select. ' )
( ' METHODS then_has_entry. ' )
( ' PRIVATE SECTION. ' )
( ' CLASS-DATA osql_test_environment TYPE REF TO if_osql_test_environment. ' )
( ' DATA cut TYPE tadir. ' )
( ' CLASS-METHODS class_setup. ' )
( ' CLASS-METHODS class_teardown. ' )
( ' ENDCLASS.' )

( ' CLASS lcl_classname IMPLEMENTATION. ' )

( ' METHOD class_setup. ' )
( | osql_test_environment = cl_osql_test_environment=>create( VALUE #( ( 'tadir' ) ) ). | )
( ' ENDMETHOD. ' )

( ' METHOD class_teardown. ' )
( ' osql_test_environment->destroy( ). ' )
( ' ENDMETHOD. ' )

( ' METHOD given_fake_value. ' )
( ' "osql_test_environment->insert_test_data( data ). ' )
( ' ENDMETHOD. ' )

( ' METHOD when_select. ' )
( ' SELECT SINGLE * FROM tadir INTO cut. ' )
( ' ENDMETHOD. ' )

( ' METHOD then_has_entry. ' )
( ' cl_aunit_assert=>assert_not_initial( cut ). ' )
( ' ENDMETHOD. ' )

( ' METHOD scenario. ' )
( ' given_fake_value( ). ' )
( ' when_select( ). ' )
( ' then_has_entry( ). ' )
( ' ENDMETHOD. ' )

( ' ENDCLASS. ' )
).
ENDMETHOD.

METHOD get_code_with_exemption.
result = VALUE #(
( ' REPORT ut_test. ' )

( ' CLASS lcl_classname DEFINITION FOR TESTING. ' )
( ' PUBLIC SECTION. ' )
( ' METHODS example FOR TESTING. ' )
( ' ENDCLASS.' )

( ' CLASS lcl_classname IMPLEMENTATION. ' )
( ' METHOD example. ' )
( ' DATA tadir TYPE tadir. ' )
( ' SELECT SINGLE * FROM tadir INTO tadir. "#EC DB_ACCESS_UT ' )
( ' ENDMETHOD. ' )
( ' ENDCLASS. ' )
).
ENDMETHOD.

ENDCLASS.
2 changes: 1 addition & 1 deletion src/checks/y_check_deprecated_key_words.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CLASS Y_CHECK_DEPRECATED_KEY_WORDS IMPLEMENTATION.
settings-threshold = 0.
settings-documentation = |{ c_docs_path-checks }deprecated-key-word.md|.

set_check_message( '"&1" is deprecated' ).
set_check_message( '"&1" is deprecated!' ).
ENDMETHOD.


Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_is_interface_in_class.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CLASS Y_CHECK_IS_INTERFACE_IN_CLASS IMPLEMENTATION.
settings-prio = c_warning.
settings-documentation = |{ c_docs_path-checks }interface-in-class.md|.

set_check_message( '&1 public methods without interface' ).
set_check_message( '&1 public methods without interface!' ).
ENDMETHOD.


Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_magic_number.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CLASS Y_CHECK_MAGIC_NUMBER IMPLEMENTATION.
settings-apply_on_test_code = abap_false.
settings-documentation = |{ c_docs_path-checks }magic-number.md|.

set_check_message( 'Magic Number Violation - &1 is a Magic Number' ).
set_check_message( 'Magic Number Violation - &1 is a Magic Number!' ).
ENDMETHOD.


Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_max_nesting_depth.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ CLASS Y_CHECK_MAX_NESTING_DEPTH IMPLEMENTATION.
settings-pseudo_comment = '"#EC CI_NESTING' ##NO_TEXT.
settings-documentation = |{ c_docs_path-checks }maximum-nesting-depth.md|.

set_check_message( 'Maximal nesting depth is &1, exceeding threshold of &2' ).
set_check_message( 'Maximal nesting depth is &1 reaching threshold of &2!' ).
ENDMETHOD.


Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_num_exec_statements.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CLASS Y_CHECK_NUM_EXEC_STATEMENTS IMPLEMENTATION.

add_obj_type( c_type_program ).

set_check_message( '&1 executable statements in method, exceeds threshold &2' ).
set_check_message( '&1 executable statements in method reaching threshold of &2!' ).
ENDMETHOD.


Expand Down
6 changes: 4 additions & 2 deletions src/checks/y_check_num_output_parameter.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CLASS Y_CHECK_NUM_OUTPUT_PARAMETER IMPLEMENTATION.
settings-threshold = 2.
settings-documentation = |{ c_docs_path-checks }number-output-parameter.md|.

set_check_message( 'Too many output parameters!' ).
set_check_message( '&1 output parameters reaching threshold of &2!' ).
ENDMETHOD.


Expand Down Expand Up @@ -67,7 +67,9 @@ CLASS Y_CHECK_NUM_OUTPUT_PARAMETER IMPLEMENTATION.
raise_error( statement_level = statement-level
statement_index = index
statement_from = statement-from + 1
error_priority = configuration-prio ).
error_priority = configuration-prio
parameter_01 = |{ outputs_of_statement }|
parameter_02 = |{ configuration-threshold }| ).

ENDMETHOD.

Expand Down
2 changes: 1 addition & 1 deletion src/checks/y_check_num_public_attributes.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CLASS Y_CHECK_NUM_PUBLIC_ATTRIBUTES IMPLEMENTATION.
settings-threshold = 1.
settings-documentation = |{ c_docs_path-checks }number-public-attributes.md|.

set_check_message( '&1 public attributes. All attributes should be private by default.' ).
set_check_message( '&1 public attributes. All attributes should be private/protected by default!' ).
ENDMETHOD.


Expand Down
Loading