From 1162355add7a02c9ce33faaf54f6cec4a628ff22 Mon Sep 17 00:00:00 2001 From: Eugen Guenther Date: Wed, 7 Apr 2021 09:30:29 +0200 Subject: [PATCH 1/2] feature - allow pseudo comment exception --- src/foundation/y_check_base.clas.abap | 39 ++++--- src/foundation/y_clean_code_manager.clas.abap | 16 ++- .../y_if_clean_code_manager.intf.abap | 37 ++++--- src/foundation/ycicp_pseudo_comments.dtel.xml | 23 ++++ .../y_profile_admin_classes.prog.abap | 104 ++++++++---------- src/profiles/y_profile_admin_data.prog.abap | 2 + .../y_profile_administrator.prog.abap | 2 +- src/profiles/y_profile_administrator.prog.xml | 47 +++++++- src/profiles/ytab_checks.tabl.xml | 20 +++- 9 files changed, 189 insertions(+), 101 deletions(-) create mode 100644 src/foundation/ycicp_pseudo_comments.dtel.xml diff --git a/src/foundation/y_check_base.clas.abap b/src/foundation/y_check_base.clas.abap index 3b0f3e3b..7fc096af 100644 --- a/src/foundation/y_check_base.clas.abap +++ b/src/foundation/y_check_base.clas.abap @@ -30,6 +30,7 @@ CLASS y_check_base DEFINITION PUBLIC ABSTRACT apply_on_test_code TYPE ycicc_testcode, documentation TYPE c LENGTH 1000, is_threshold_reversed TYPE abap_bool, + allow_pseudo_comments TYPE abap_bool, END OF settings. METHODS constructor. @@ -104,8 +105,7 @@ CLASS y_check_base DEFINITION PUBLIC ABSTRACT parameter_04 TYPE csequence OPTIONAL is_include_specific TYPE sci_inclspec DEFAULT ' ' additional_information TYPE xstring OPTIONAL - checksum TYPE int4 OPTIONAL - pseudo_comments TYPE t_comments OPTIONAL. "#EC OPTL_PARAM + checksum TYPE int4 OPTIONAL. "#EC OPTL_PARAM METHODS get_column_abs REDEFINITION. METHODS get_column_rel REDEFINITION. @@ -149,14 +149,14 @@ CLASS y_check_base DEFINITION PUBLIC ABSTRACT METHODS is_structure_type_relevant IMPORTING structure TYPE sstruc RETURNING VALUE(result) TYPE abap_bool. - METHODS is_app_comp_in_scope IMPORTING level TYPE stmnt_levl - RETURNING value(result) TYPE abap_bool. + METHODS is_app_comp_in_scope IMPORTING level TYPE stmnt_levl + RETURNING VALUE(result) TYPE abap_bool. ENDCLASS. -CLASS y_check_base IMPLEMENTATION. +CLASS Y_CHECK_BASE IMPLEMENTATION. METHOD check_start_conditions. @@ -181,6 +181,7 @@ CLASS y_check_base IMPLEMENTATION. settings-apply_on_productive_code = abap_true. settings-apply_on_test_code = abap_true. settings-documentation = |{ c_docs_path-main }check_documentation.md|. + settings-allow_pseudo_comments = abap_true. has_attributes = do_attributes_exist( ). @@ -298,7 +299,7 @@ CLASS y_check_base IMPLEMENTATION. check_configuration-object_creation_date = settings-object_created_on. check_configuration-prio = settings-prio. check_configuration-threshold = settings-threshold. - + check_configuration-allow_pseudo_comments = settings-allow_pseudo_comments. APPEND check_configuration TO check_configurations. ENDIF. EXPORT @@ -307,6 +308,7 @@ CLASS y_check_base IMPLEMENTATION. threshold = check_configuration-threshold apply_on_productive_code = check_configuration-apply_on_productive_code apply_on_testcode = check_configuration-apply_on_testcode + allow_pseudo_comments = check_configuration-allow_pseudo_comments TO DATA BUFFER p_attributes. ENDMETHOD. @@ -512,6 +514,7 @@ CLASS y_check_base IMPLEMENTATION. check_configuration-apply_on_productive_code = settings-apply_on_productive_code. check_configuration-apply_on_testcode = settings-apply_on_test_code. check_configuration-threshold = settings-threshold. + check_configuration-allow_pseudo_comments = settings-allow_pseudo_comments. ENDIF. INSERT VALUE #( @@ -550,6 +553,14 @@ CLASS y_check_base IMPLEMENTATION. ) INTO TABLE sci_attributes. ENDIF. + IF settings-pseudo_comment IS NOT INITIAL. + INSERT VALUE #( + kind = '' + ref = REF #( check_configuration-allow_pseudo_comments ) + text = |Allow { settings-pseudo_comment }| + ) INTO TABLE sci_attributes. + ENDIF. + title = description. attributes_ok = abap_false. @@ -597,7 +608,7 @@ CLASS y_check_base IMPLEMENTATION. ENDIF. IF clean_code_exemption_handler IS NOT BOUND. - clean_code_exemption_handler = new y_exemption_handler( ). + clean_code_exemption_handler = NEW y_exemption_handler( ). ENDIF. IF test_code_detector IS NOT BOUND. @@ -638,6 +649,7 @@ CLASS y_check_base IMPLEMENTATION. threshold = check_configuration-threshold apply_on_productive_code = check_configuration-apply_on_productive_code apply_on_testcode = check_configuration-apply_on_testcode + allow_pseudo_comments = check_configuration-allow_pseudo_comments FROM DATA BUFFER p_attributes. APPEND check_configuration TO check_configurations. CATCH cx_root. "#EC NEED_CX_ROOT @@ -647,12 +659,15 @@ CLASS y_check_base IMPLEMENTATION. METHOD raise_error. + DATA(pseudo_comment) = COND sci_pcom( WHEN settings-allow_pseudo_comments = abap_false THEN settings-pseudo_comment + ELSE space ). + statistics->collect( kind = error_priority pc = NEW y_pseudo_comment_detector( )->is_pseudo_comment( ref_scan_manager = ref_scan_manager scimessages = scimessages test = myname code = get_code( error_priority ) - suppress = settings-pseudo_comment + suppress = pseudo_comment position = statement_index ) ). IF cl_abap_typedescr=>describe_by_object_ref( ref_scan_manager )->get_relative_name( ) EQ 'Y_REF_SCAN_MANAGER'. @@ -665,17 +680,15 @@ CLASS y_check_base IMPLEMENTATION. p_kind = error_priority p_test = myname p_code = get_code( error_priority ) - p_suppress = settings-pseudo_comment + p_suppress = pseudo_comment p_param_1 = parameter_01 p_param_2 = parameter_02 p_param_3 = parameter_03 p_param_4 = parameter_04 p_inclspec = is_include_specific p_detail = additional_information - p_checksum_1 = checksum - p_comments = pseudo_comments ). + p_checksum_1 = checksum ). ENDIF. - ENDMETHOD. @@ -797,6 +810,4 @@ CLASS y_check_base IMPLEMENTATION. result = abap_true. ENDTRY. ENDMETHOD. - - ENDCLASS. diff --git a/src/foundation/y_clean_code_manager.clas.abap b/src/foundation/y_clean_code_manager.clas.abap index 2cda64ef..05a4ca36 100644 --- a/src/foundation/y_clean_code_manager.clas.abap +++ b/src/foundation/y_clean_code_manager.clas.abap @@ -4,18 +4,20 @@ CLASS y_clean_code_manager DEFINITION PUBLIC CREATE PUBLIC. ALIASES calculate_obj_creation_date FOR y_if_clean_code_manager~calculate_obj_creation_date. ALIASES read_check_customizing FOR y_if_clean_code_manager~read_check_customizing. + PROTECTED SECTION. PRIVATE SECTION. METHODS determine_profiles RETURNING VALUE(result) TYPE string_table - RAISING ycx_no_check_customizing. + RAISING ycx_no_check_customizing. - METHODS determine_checks IMPORTING profile TYPE ycicc_profile - checkid TYPE seoclsname + METHODS determine_checks IMPORTING profile TYPE ycicc_profile + checkid TYPE seoclsname RETURNING VALUE(result) TYPE y_if_clean_code_manager=>check_configurations - RAISING ycx_no_check_customizing . + RAISING ycx_no_check_customizing . ENDCLASS. -CLASS y_clean_code_manager IMPLEMENTATION. + +CLASS Y_CLEAN_CODE_MANAGER IMPLEMENTATION. METHOD determine_checks. @@ -33,7 +35,9 @@ CLASS y_clean_code_manager IMPLEMENTATION. threshold = -threshold prio = -prio apply_on_productive_code = -apply_on_productive_code - apply_on_testcode = -apply_on_testcode ). + apply_on_testcode = -apply_on_testcode + allow_pseudo_comments = -ignore_pseudo_comments + ). result = VALUE #( BASE result ( CORRESPONDING #( check_configuration ) ) ). ENDLOOP. ENDMETHOD. diff --git a/src/foundation/y_if_clean_code_manager.intf.abap b/src/foundation/y_if_clean_code_manager.intf.abap index 845bba56..c3729617 100644 --- a/src/foundation/y_if_clean_code_manager.intf.abap +++ b/src/foundation/y_if_clean_code_manager.intf.abap @@ -1,29 +1,30 @@ -interface Y_IF_CLEAN_CODE_MANAGER - public . +INTERFACE y_if_clean_code_manager + PUBLIC . - types: + TYPES: BEGIN OF check_configuration, object_creation_date TYPE datum, threshold TYPE ycicc_threshold, prio TYPE ycicc_message_kind, apply_on_productive_code TYPE ycicc_productive_code, apply_on_testcode TYPE ycicc_testcode, + allow_pseudo_comments TYPE ycicp_pseudo_comments, END OF check_configuration . - types: + TYPES: check_configurations TYPE STANDARD TABLE OF check_configuration WITH DEFAULT KEY . - methods READ_CHECK_CUSTOMIZING - importing - CHECKID type SEOCLSNAME - returning - value(RESULT) type CHECK_CONFIGURATIONS - raising - YCX_NO_CHECK_CUSTOMIZING . - methods CALCULATE_OBJ_CREATION_DATE - importing - OBJECT_NAME type SOBJ_NAME - OBJECT_TYPE type TROBJTYPE - returning - value(RESULT) type CREATIONDT . -endinterface. + METHODS read_check_customizing + IMPORTING + checkid TYPE seoclsname + RETURNING + VALUE(result) TYPE check_configurations + RAISING + ycx_no_check_customizing . + METHODS calculate_obj_creation_date + IMPORTING + object_name TYPE sobj_name + object_type TYPE trobjtype + RETURNING + VALUE(result) TYPE creationdt . +ENDINTERFACE. diff --git a/src/foundation/ycicp_pseudo_comments.dtel.xml b/src/foundation/ycicp_pseudo_comments.dtel.xml new file mode 100644 index 00000000..271ab2c1 --- /dev/null +++ b/src/foundation/ycicp_pseudo_comments.dtel.xml @@ -0,0 +1,23 @@ + + + + + + YCICP_PSEUDO_COMMENTS + E + BOOLE + 55 + 10 + 20 + 40 + Code Pal - Allow Pseudo Comments + PseudCom + PseudCom + PseudCom + PseudCom + E + D + + + + diff --git a/src/profiles/y_profile_admin_classes.prog.abap b/src/profiles/y_profile_admin_classes.prog.abap index 56274f64..080fa4aa 100644 --- a/src/profiles/y_profile_admin_classes.prog.abap +++ b/src/profiles/y_profile_admin_classes.prog.abap @@ -200,23 +200,19 @@ CLASS lcl_util DEFINITION. "#EC NUMBER_METHODS check_f4help. CLASS-METHODS: - init_check_fields_active - IMPORTING checkid TYPE vseoclass-clsname, - get_disable_threshold_select + init_check_fields_active, + get_check IMPORTING checkid TYPE vseoclass-clsname - RETURNING VALUE(result) TYPE abap_bool, - get_disable_on_prodcode_select - IMPORTING checkid TYPE vseoclass-clsname - RETURNING VALUE(result) TYPE abap_bool, - get_disable_on_testcode_select - IMPORTING checkid TYPE vseoclass-clsname - RETURNING VALUE(result) TYPE abap_bool, + RETURNING VALUE(result) TYPE REF TO y_check_base + RAISING cx_sy_create_object_error, set_threshold_active IMPORTING is_active TYPE abap_bool DEFAULT abap_true, set_on_prodcode_active IMPORTING is_active TYPE abap_bool DEFAULT abap_true, set_on_testcode_active IMPORTING is_active TYPE abap_bool DEFAULT abap_true, + set_allow_pcom_active + IMPORTING is_active TYPE abap_bool DEFAULT abap_true, set_dynpro_field_active IMPORTING fieldname TYPE string is_active TYPE abap_bool. @@ -541,6 +537,8 @@ CLASS lcl_util IMPLEMENTATION. is_visible = abap_true ). checks_tree->set_field_visibility( fieldname = 'APPLY_ON_TESTCODE' is_visible = abap_true ). + checks_tree->set_field_visibility( fieldname = 'IGNORE_PSEUDO_COMMENTS' + is_visible = abap_true ). checks_tree->set_field_header_text( fieldname = 'PROFILE' header_text = 'Profile'(001) ). @@ -558,6 +556,8 @@ CLASS lcl_util IMPLEMENTATION. header_text = 'Apply on Productive Code'(050) ). checks_tree->set_field_header_text( fieldname = 'APPLY_ON_TESTCODE' header_text = 'Apply on Testcode'(034) ). + checks_tree->set_field_header_text( fieldname = 'IGNORE_PSEUDO_COMMENTS' + header_text = 'Allow Pseudo Comments' ). checks_tree->init_display( ). @@ -818,34 +818,43 @@ CLASS lcl_util IMPLEMENTATION. ENDMETHOD. METHOD init_check_fields_active. - DATA obj TYPE REF TO y_check_base. - TRY. - IF get_disable_threshold_select( checkid ) EQ abap_true. + DATA(obj) = get_check( io_check_id ). + + IF obj->settings-disable_threshold_selection EQ abap_true. set_threshold_active( abap_false ). ELSE. set_threshold_active( abap_true ). ENDIF. - IF get_disable_on_prodcode_select( checkid ) EQ abap_true. + IF obj->settings-disable_on_prodcode_selection EQ abap_true. set_on_prodcode_active( abap_false ). ELSE. set_on_prodcode_active( abap_true ). ENDIF. - IF get_disable_on_testcode_select( checkid ) EQ abap_true. + IF obj->settings-disable_on_testcode_selection EQ abap_true. set_on_testcode_active( abap_false ). ELSE. set_on_testcode_active( abap_true ). ENDIF. - CREATE OBJECT obj TYPE (io_check_id). + IF obj->settings-pseudo_comment IS INITIAL. + set_allow_pcom_active( abap_false ). + ELSE. + set_allow_pcom_active( abap_true ). + ENDIF. + + lbl_pcom_name = obj->settings-pseudo_comment. + IF has_edit_mode_started EQ abap_true. io_threshold = obj->settings-threshold. io_prio = obj->settings-prio. io_creation_date = obj->settings-object_created_on. chbx_on_prodcode = obj->settings-apply_on_productive_code. chbx_on_testcode = obj->settings-apply_on_test_code. + chbx_allow_pcom = obj->settings-allow_pseudo_comments. + lbl_pcom_name = obj->settings-pseudo_comment. has_edit_mode_started = abap_false. ENDIF. @@ -854,40 +863,8 @@ CLASS lcl_util IMPLEMENTATION. ENDTRY. ENDMETHOD. - METHOD get_disable_on_prodcode_select. - DATA obj TYPE REF TO y_check_base. - TRY. - CREATE OBJECT obj TYPE (checkid). - result = obj->settings-disable_on_prodcode_selection. - - CATCH cx_sy_create_object_error. - result = abap_false. - - ENDTRY. - ENDMETHOD. - - METHOD get_disable_on_testcode_select. - DATA obj TYPE REF TO y_check_base. - TRY. - CREATE OBJECT obj TYPE (checkid). - result = obj->settings-disable_on_testcode_selection. - - CATCH cx_sy_create_object_error. - result = abap_false. - - ENDTRY. - ENDMETHOD. - - METHOD get_disable_threshold_select. - DATA obj TYPE REF TO y_check_base. - TRY. - CREATE OBJECT obj TYPE (checkid). - result = obj->settings-disable_threshold_selection. - - CATCH cx_sy_create_object_error. - result = abap_false. - - ENDTRY. + METHOD get_check. + CREATE OBJECT result TYPE (checkid). ENDMETHOD. METHOD set_on_prodcode_active. @@ -911,6 +888,13 @@ CLASS lcl_util IMPLEMENTATION. is_active = is_active ). ENDMETHOD. + METHOD set_allow_pcom_active. + set_dynpro_field_active( fieldname = 'LBL_ALLOW_PCOM' + is_active = is_active ). + set_dynpro_field_active( fieldname = 'CHBX_ALLOW_PCOM' + is_active = is_active ). + ENDMETHOD. + METHOD set_dynpro_field_active. LOOP AT SCREEN INTO DATA(line). @@ -981,11 +965,11 @@ CLASS lcl_util IMPLEMENTATION. DATA(checklist) = profile_manager->select_checks( io_profilename ). profile_manager->insert_profile( VALUE #( username = sy-uname - profile = io_to_profile - is_standard = abap_false - last_changed_by = sy-uname - last_changed_on = sy-datum - last_changed_at = sy-timlo ) ). + profile = io_to_profile + is_standard = abap_false + last_changed_by = sy-uname + last_changed_on = sy-datum + last_changed_at = sy-timlo ) ). profile_manager->check_delegation_rights( io_to_profile ). @@ -1115,6 +1099,7 @@ CLASS lcl_util IMPLEMENTATION. result-last_changed_by = sy-uname. result-last_changed_on = sy-datum. result-last_changed_at = sy-timlo. + result-ignore_pseudo_comments = abap_true. ENDMETHOD. METHOD auto_re_start_delegate. @@ -1183,8 +1168,8 @@ CLASS lcl_util IMPLEMENTATION. CATCH ycx_entry_not_found. MESSAGE 'Please select a profile!'(005) TYPE 'I'. - CATCH ycx_no_delegation_rights. + CATCH ycx_no_delegation_rights. MESSAGE 'You are not a delegate of the profile!'(006) TYPE 'I'. CATCH cx_failed. @@ -1216,6 +1201,8 @@ CLASS lcl_util IMPLEMENTATION. io_threshold = 0. chbx_on_prodcode = abap_true. chbx_on_testcode = abap_true. + chbx_allow_pcom = abap_true. + lbl_pcom_name = space. TRY. CREATE OBJECT obj TYPE (io_check_id). @@ -1224,7 +1211,8 @@ CLASS lcl_util IMPLEMENTATION. io_prio = obj->settings-prio. chbx_on_prodcode = obj->settings-apply_on_productive_code. chbx_on_testcode = obj->settings-apply_on_test_code. - + chbx_allow_pcom = obj->settings-allow_pseudo_comments. + lbl_pcom_name = obj->settings-pseudo_comment. CATCH cx_sy_create_object_error. RETURN. ENDTRY. @@ -1241,6 +1229,7 @@ CLASS lcl_util IMPLEMENTATION. io_prio = check_line-prio. chbx_on_prodcode = check_line-apply_on_productive_code. chbx_on_testcode = check_line-apply_on_testcode. + chbx_allow_pcom = check_line-ignore_pseudo_comments. TRY. io_check_description = profile_manager->get_check_description( check_line-checkid ). @@ -1276,6 +1265,7 @@ CLASS lcl_util IMPLEMENTATION. prio = io_prio apply_on_productive_code = chbx_on_prodcode apply_on_testcode = chbx_on_testcode + ignore_pseudo_comments = chbx_allow_pcom last_changed_by = sy-uname last_changed_on = sy-datum last_changed_at = sy-timlo ). diff --git a/src/profiles/y_profile_admin_data.prog.abap b/src/profiles/y_profile_admin_data.prog.abap index af28ca03..960a50ff 100644 --- a/src/profiles/y_profile_admin_data.prog.abap +++ b/src/profiles/y_profile_admin_data.prog.abap @@ -18,3 +18,5 @@ DATA io_threshold TYPE ytab_checks-threshold. DATA io_prio TYPE ytab_checks-prio. DATA chbx_on_testcode TYPE abap_bool. DATA chbx_on_prodcode TYPE abap_bool. +DATA chbx_allow_pcom TYPE abap_bool. +DATA lbl_pcom_name TYPE sci_pcom. diff --git a/src/profiles/y_profile_administrator.prog.abap b/src/profiles/y_profile_administrator.prog.abap index 1928d3ea..b2282d5f 100644 --- a/src/profiles/y_profile_administrator.prog.abap +++ b/src/profiles/y_profile_administrator.prog.abap @@ -38,7 +38,7 @@ ENDMODULE. MODULE status_0400 OUTPUT. SET PF-STATUS check_customizing_screen. SET TITLEBAR check_customizing_screen. - lcl_util=>init_check_fields_active( io_check_id ). + lcl_util=>init_check_fields_active( ). ENDMODULE. MODULE status_0500 OUTPUT. diff --git a/src/profiles/y_profile_administrator.prog.xml b/src/profiles/y_profile_administrator.prog.xml index c00f32c7..381309e9 100644 --- a/src/profiles/y_profile_administrator.prog.xml +++ b/src/profiles/y_profile_administrator.prog.xml @@ -230,7 +230,7 @@ N 0400 027 - 121 + 122 @@ -537,6 +537,51 @@ X X + + SCREEN + SCREEN + TEXT + LBL_ALLOW_PCOM + Allow_Pseudo-Comment_Exemption:__ + 009 + 001 + 033 + 033 + 001 + CHAR + N + X + + + SCREEN + SCREEN + CHECK + CHBX_ALLOW_PCOM + 009 + 035 + 001 + 001 + 001 + CHAR + X + X + + + SCREEN + SCREEN + TEMPLATE + LBL_PCOM_NAME + ____________________ + 009 + 037 + 020 + 020 + 001 + CHAR + X + X + N + SCREEN SCREEN diff --git a/src/profiles/ytab_checks.tabl.xml b/src/profiles/ytab_checks.tabl.xml index d52c3b56..91da8f1c 100644 --- a/src/profiles/ytab_checks.tabl.xml +++ b/src/profiles/ytab_checks.tabl.xml @@ -111,8 +111,20 @@ YTAB_CHECKS - THRESHOLD + IGNORE_PSEUDO_COMMENTS 0009 + X + YCICP_PSEUDO_COMMENTS + 0 + X + X + F + E + + + YTAB_CHECKS + THRESHOLD + 0010 YCICC_THRESHOLD 0 E @@ -120,7 +132,7 @@ YTAB_CHECKS LAST_CHANGED_BY - 0010 + 0011 AS4USER 0 E @@ -128,7 +140,7 @@ YTAB_CHECKS LAST_CHANGED_ON - 0011 + 0012 AS4DATE 0 T @@ -137,7 +149,7 @@ YTAB_CHECKS LAST_CHANGED_AT - 0012 + 0013 AS4TIME 0 T From d85625e391f3f8df8b55a392c7665dc6f4afce72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugen=20G=C3=BCnther?= <64586309+eugen-guenther-sap@users.noreply.github.com> Date: Wed, 7 Apr 2021 10:02:06 +0200 Subject: [PATCH 2/2] Update y_check_unit_test_assert.clas.abap --- src/checks/y_check_unit_test_assert.clas.abap | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/checks/y_check_unit_test_assert.clas.abap b/src/checks/y_check_unit_test_assert.clas.abap index 8c48c9bd..b4202159 100644 --- a/src/checks/y_check_unit_test_assert.clas.abap +++ b/src/checks/y_check_unit_test_assert.clas.abap @@ -49,11 +49,10 @@ CLASS y_check_unit_test_assert IMPLEMENTATION. RETURN. ENDIF. - IF act-str <> exp-str. - IF is_variable( act ) = abap_true - OR is_variable( exp ) = abap_true. + IF act-str <> exp-str + AND ( is_variable( act ) = abap_true + OR is_variable( exp ) = abap_true ). RETURN. - ENDIF. ENDIF. DATA(check_configuration) = detect_check_configuration( statement ).