From c3771ff4da487efd42e83923003640ab21fc75bb Mon Sep 17 00:00:00 2001 From: Kai Busse Date: Wed, 18 Dec 2024 14:25:41 +0100 Subject: [PATCH 1/4] move check files into correct path --- .../y_check_prefer_insert_into.clas.abap | 50 +++++ ...k_prefer_insert_into.clas.testclasses.abap | 182 ++++++++++++++++++ .../y_check_prefer_insert_into.clas.xml | 17 ++ 3 files changed, 249 insertions(+) create mode 100644 src/checks/y_check_prefer_insert_into.clas.abap create mode 100644 src/checks/y_check_prefer_insert_into.clas.testclasses.abap create mode 100644 src/checks/y_check_prefer_insert_into.clas.xml diff --git a/src/checks/y_check_prefer_insert_into.clas.abap b/src/checks/y_check_prefer_insert_into.clas.abap new file mode 100644 index 00000000..ad02db0d --- /dev/null +++ b/src/checks/y_check_prefer_insert_into.clas.abap @@ -0,0 +1,50 @@ +CLASS y_check_prefer_insert_into DEFINITION + PUBLIC + INHERITING FROM y_check_base + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + METHODS constructor. + PROTECTED SECTION. + METHODS: inspect_tokens REDEFINITION. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS y_check_prefer_insert_into IMPLEMENTATION. + + METHOD constructor. + super->constructor( ). + + settings-pseudo_comment = '"#EC PREF_INSERT_INT' ##NO_TEXT. + settings-disable_threshold_selection = abap_true. + settings-threshold = 0. + settings-documentation = |{ c_docs_path-checks }prefer-insert-into-to-append.md|. + + set_check_message( 'Prefer INSERT INTO TABLE to APPEND TO.' ). + + ENDMETHOD. + + METHOD inspect_tokens. + + IF get_token_abs( statement-from ) <> 'APPEND'. + RETURN. + ENDIF. + + IF next2( p_word1 = 'SORTED' + p_word2 = 'BY' ) IS NOT INITIAL. + RETURN. + ENDIF. + + DATA(check_configuration) = detect_check_configuration( statement ). + + raise_error( statement_level = statement-level + statement_index = index + statement_from = statement-from + check_configuration = check_configuration ). + + ENDMETHOD. + +ENDCLASS. diff --git a/src/checks/y_check_prefer_insert_into.clas.testclasses.abap b/src/checks/y_check_prefer_insert_into.clas.testclasses.abap new file mode 100644 index 00000000..eef9cbeb --- /dev/null +++ b/src/checks/y_check_prefer_insert_into.clas.testclasses.abap @@ -0,0 +1,182 @@ +CLASS ltc_append_to DEFINITION INHERITING FROM y_unit_test_base FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. + PROTECTED SECTION. + METHODS: get_cut REDEFINITION, + get_code_with_issue REDEFINITION, + get_code_without_issue REDEFINITION, + get_code_with_exemption REDEFINITION. + +ENDCLASS. + + +CLASS ltc_append_to IMPLEMENTATION. + + METHOD get_code_without_issue. + + result = VALUE #( + ( ' REPORT y_example.' ) + + ( ' CLASS y_example DEFINITION.' ) + ( ' PUBLIC SECTION.' ) + ( ' METHODS example.' ) + ( ' ENDCLASS.' ) + + ( ' CLASS y_example IMPLEMENTATION.' ) + ( ' METHOD example.' ) + ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) + ( ' INSERT `example` INTO TABLE prefer_insert_into_table.' ) + ( ' ENDMETHOD.' ) + ( ' ENDCLASS.' ) + ). + + ENDMETHOD. + + METHOD get_code_with_exemption. + + result = VALUE #( + ( ' REPORT y_example.' ) + + ( ' CLASS y_example DEFINITION.' ) + ( ' PUBLIC SECTION.' ) + ( ' METHODS example.' ) + ( ' ENDCLASS.' ) + + ( ' CLASS y_example IMPLEMENTATION.' ) + ( ' METHOD example.' ) + ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) + ( ' APPEND `example` TO prefer_insert_into_table. "#EC PREF_INSERT_INT' ) + ( ' ENDMETHOD.' ) + ( ' ENDCLASS.' ) + ). + + ENDMETHOD. + + METHOD get_code_with_issue. + + result = VALUE #( + ( ' REPORT y_example.' ) + + ( ' CLASS y_example DEFINITION.' ) + ( ' PUBLIC SECTION.' ) + ( ' METHODS example.' ) + ( ' ENDCLASS.' ) + + ( ' CLASS y_example IMPLEMENTATION.' ) + ( ' METHOD example.' ) + ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) + ( ' APPEND `example` TO prefer_insert_into_table.' ) + ( ' ENDMETHOD.' ) + ( ' ENDCLASS.' ) + ). + + ENDMETHOD. + + METHOD get_cut. + result ?= NEW y_check_prefer_insert_into( ). + ENDMETHOD. + +ENDCLASS. + +CLASS ltc_append_initial_line DEFINITION INHERITING FROM ltc_append_to FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. + PROTECTED SECTION. + METHODS get_code_with_issue REDEFINITION. +ENDCLASS. + +CLASS ltc_append_initial_line IMPLEMENTATION. + + METHOD get_code_with_issue. + result = VALUE #( + ( ' REPORT y_example.' ) + + ( ' CLASS y_example DEFINITION.' ) + ( ' PUBLIC SECTION.' ) + ( ' METHODS example.' ) + ( ' ENDCLASS.' ) + + ( ' CLASS y_example IMPLEMENTATION.' ) + ( ' METHOD example.' ) + ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) + ( ' FIELD-SYMBOLS TYPE string.' ) + ( ' APPEND INITIAL LINE TO prefer_insert_into_table ASSIGNING .' ) + ( ' ENDMETHOD.' ) + ( ' ENDCLASS.' ) + ). + ENDMETHOD. + +ENDCLASS. + +CLASS ltc_append_lines_of DEFINITION INHERITING FROM ltc_append_to FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. + PROTECTED SECTION. + METHODS get_code_with_issue REDEFINITION. +ENDCLASS. + +CLASS ltc_append_lines_of IMPLEMENTATION. + + METHOD get_code_with_issue. + result = VALUE #( + ( ' REPORT y_example.' ) + + ( ' CLASS y_example DEFINITION.' ) + ( ' PUBLIC SECTION.' ) + ( ' METHODS example.' ) + ( ' ENDCLASS.' ) + + ( ' CLASS y_example IMPLEMENTATION.' ) + ( ' METHOD example.' ) + ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) + ( ' DATA example_table TYPE TABLE OF string.' ) + ( ' APPEND LINES OF example_table TO prefer_insert_into_table.' ) + ( ' ENDMETHOD.' ) + ( ' ENDCLASS.' ) + ). + ENDMETHOD. + +ENDCLASS. + +CLASS ltc_append_sorted_by DEFINITION INHERITING FROM ltc_append_to FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. + PROTECTED SECTION. + METHODS get_code_without_issue REDEFINITION. +ENDCLASS. + +CLASS ltc_append_sorted_by IMPLEMENTATION. + + METHOD get_code_without_issue. + result = VALUE #( + ( ' REPORT y_example.' ) + + ( ' CLASS y_example DEFINITION.' ) + ( ' PUBLIC SECTION.' ) + ( ' METHODS example.' ) + ( ' ENDCLASS.' ) + + ( ' CLASS y_example IMPLEMENTATION.' ) + ( ' METHOD example.' ) + ( ' DATA prefer_insert_into_table TYPE TABLE OF sflight.' ) + ( ' DATA example_line TYPE sflight.' ) + ( ' APPEND example_line TO prefer_insert_into_table SORTED BY fldate.' ) + ( ' ENDMETHOD.' ) + ( ' ENDCLASS.' ) + ). + ENDMETHOD. + +ENDCLASS. + + +CLASS ltc_select DEFINITION INHERITING FROM ltc_append_to FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. + PROTECTED SECTION. + METHODS get_code_without_issue REDEFINITION. +ENDCLASS. + +CLASS ltc_select IMPLEMENTATION. + + METHOD get_code_without_issue. + result = VALUE #( + ( ' REPORT ut_test.' ) + ( ' START-OF-SELECTION.' ) + ( ' DATA example_table TYPE TABLE OF sflight.' ) + ( ' SELECT * FROM sflight APPENDING TABLE example_table.' ) + ). + ENDMETHOD. + +ENDCLASS. diff --git a/src/checks/y_check_prefer_insert_into.clas.xml b/src/checks/y_check_prefer_insert_into.clas.xml new file mode 100644 index 00000000..9be2c895 --- /dev/null +++ b/src/checks/y_check_prefer_insert_into.clas.xml @@ -0,0 +1,17 @@ + + + + + + Y_CHECK_PREFER_INSERT_INTO + E + Prefer INSERT INTO TABLE to APPEND TO + 1 + X + X + X + X + + + + From b9a06ce4a5ce19ca08ee1bba32df9c9d2c90c386 Mon Sep 17 00:00:00 2001 From: Kai Busse <53078228+00500500@users.noreply.github.com> Date: Mon, 13 Jan 2025 12:06:37 +0100 Subject: [PATCH 2/4] Delete src/y_check_prefer_insert_into.clas.abap --- src/y_check_prefer_insert_into.clas.abap | 50 ------------------------ 1 file changed, 50 deletions(-) delete mode 100644 src/y_check_prefer_insert_into.clas.abap diff --git a/src/y_check_prefer_insert_into.clas.abap b/src/y_check_prefer_insert_into.clas.abap deleted file mode 100644 index ad02db0d..00000000 --- a/src/y_check_prefer_insert_into.clas.abap +++ /dev/null @@ -1,50 +0,0 @@ -CLASS y_check_prefer_insert_into DEFINITION - PUBLIC - INHERITING FROM y_check_base - FINAL - CREATE PUBLIC . - - PUBLIC SECTION. - METHODS constructor. - PROTECTED SECTION. - METHODS: inspect_tokens REDEFINITION. - PRIVATE SECTION. -ENDCLASS. - - - -CLASS y_check_prefer_insert_into IMPLEMENTATION. - - METHOD constructor. - super->constructor( ). - - settings-pseudo_comment = '"#EC PREF_INSERT_INT' ##NO_TEXT. - settings-disable_threshold_selection = abap_true. - settings-threshold = 0. - settings-documentation = |{ c_docs_path-checks }prefer-insert-into-to-append.md|. - - set_check_message( 'Prefer INSERT INTO TABLE to APPEND TO.' ). - - ENDMETHOD. - - METHOD inspect_tokens. - - IF get_token_abs( statement-from ) <> 'APPEND'. - RETURN. - ENDIF. - - IF next2( p_word1 = 'SORTED' - p_word2 = 'BY' ) IS NOT INITIAL. - RETURN. - ENDIF. - - DATA(check_configuration) = detect_check_configuration( statement ). - - raise_error( statement_level = statement-level - statement_index = index - statement_from = statement-from - check_configuration = check_configuration ). - - ENDMETHOD. - -ENDCLASS. From 85f58e8a9e245495f7d2d2335d8db799b31b6823 Mon Sep 17 00:00:00 2001 From: Kai Busse <53078228+00500500@users.noreply.github.com> Date: Mon, 13 Jan 2025 12:06:46 +0100 Subject: [PATCH 3/4] Delete src/y_check_prefer_insert_into.clas.testclasses.abap --- ...k_prefer_insert_into.clas.testclasses.abap | 182 ------------------ 1 file changed, 182 deletions(-) delete mode 100644 src/y_check_prefer_insert_into.clas.testclasses.abap diff --git a/src/y_check_prefer_insert_into.clas.testclasses.abap b/src/y_check_prefer_insert_into.clas.testclasses.abap deleted file mode 100644 index eef9cbeb..00000000 --- a/src/y_check_prefer_insert_into.clas.testclasses.abap +++ /dev/null @@ -1,182 +0,0 @@ -CLASS ltc_append_to DEFINITION INHERITING FROM y_unit_test_base FOR TESTING - DURATION SHORT - RISK LEVEL HARMLESS. - PROTECTED SECTION. - METHODS: get_cut REDEFINITION, - get_code_with_issue REDEFINITION, - get_code_without_issue REDEFINITION, - get_code_with_exemption REDEFINITION. - -ENDCLASS. - - -CLASS ltc_append_to IMPLEMENTATION. - - METHOD get_code_without_issue. - - result = VALUE #( - ( ' REPORT y_example.' ) - - ( ' CLASS y_example DEFINITION.' ) - ( ' PUBLIC SECTION.' ) - ( ' METHODS example.' ) - ( ' ENDCLASS.' ) - - ( ' CLASS y_example IMPLEMENTATION.' ) - ( ' METHOD example.' ) - ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) - ( ' INSERT `example` INTO TABLE prefer_insert_into_table.' ) - ( ' ENDMETHOD.' ) - ( ' ENDCLASS.' ) - ). - - ENDMETHOD. - - METHOD get_code_with_exemption. - - result = VALUE #( - ( ' REPORT y_example.' ) - - ( ' CLASS y_example DEFINITION.' ) - ( ' PUBLIC SECTION.' ) - ( ' METHODS example.' ) - ( ' ENDCLASS.' ) - - ( ' CLASS y_example IMPLEMENTATION.' ) - ( ' METHOD example.' ) - ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) - ( ' APPEND `example` TO prefer_insert_into_table. "#EC PREF_INSERT_INT' ) - ( ' ENDMETHOD.' ) - ( ' ENDCLASS.' ) - ). - - ENDMETHOD. - - METHOD get_code_with_issue. - - result = VALUE #( - ( ' REPORT y_example.' ) - - ( ' CLASS y_example DEFINITION.' ) - ( ' PUBLIC SECTION.' ) - ( ' METHODS example.' ) - ( ' ENDCLASS.' ) - - ( ' CLASS y_example IMPLEMENTATION.' ) - ( ' METHOD example.' ) - ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) - ( ' APPEND `example` TO prefer_insert_into_table.' ) - ( ' ENDMETHOD.' ) - ( ' ENDCLASS.' ) - ). - - ENDMETHOD. - - METHOD get_cut. - result ?= NEW y_check_prefer_insert_into( ). - ENDMETHOD. - -ENDCLASS. - -CLASS ltc_append_initial_line DEFINITION INHERITING FROM ltc_append_to FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. - PROTECTED SECTION. - METHODS get_code_with_issue REDEFINITION. -ENDCLASS. - -CLASS ltc_append_initial_line IMPLEMENTATION. - - METHOD get_code_with_issue. - result = VALUE #( - ( ' REPORT y_example.' ) - - ( ' CLASS y_example DEFINITION.' ) - ( ' PUBLIC SECTION.' ) - ( ' METHODS example.' ) - ( ' ENDCLASS.' ) - - ( ' CLASS y_example IMPLEMENTATION.' ) - ( ' METHOD example.' ) - ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) - ( ' FIELD-SYMBOLS TYPE string.' ) - ( ' APPEND INITIAL LINE TO prefer_insert_into_table ASSIGNING .' ) - ( ' ENDMETHOD.' ) - ( ' ENDCLASS.' ) - ). - ENDMETHOD. - -ENDCLASS. - -CLASS ltc_append_lines_of DEFINITION INHERITING FROM ltc_append_to FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. - PROTECTED SECTION. - METHODS get_code_with_issue REDEFINITION. -ENDCLASS. - -CLASS ltc_append_lines_of IMPLEMENTATION. - - METHOD get_code_with_issue. - result = VALUE #( - ( ' REPORT y_example.' ) - - ( ' CLASS y_example DEFINITION.' ) - ( ' PUBLIC SECTION.' ) - ( ' METHODS example.' ) - ( ' ENDCLASS.' ) - - ( ' CLASS y_example IMPLEMENTATION.' ) - ( ' METHOD example.' ) - ( ' DATA prefer_insert_into_table TYPE TABLE OF string.' ) - ( ' DATA example_table TYPE TABLE OF string.' ) - ( ' APPEND LINES OF example_table TO prefer_insert_into_table.' ) - ( ' ENDMETHOD.' ) - ( ' ENDCLASS.' ) - ). - ENDMETHOD. - -ENDCLASS. - -CLASS ltc_append_sorted_by DEFINITION INHERITING FROM ltc_append_to FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. - PROTECTED SECTION. - METHODS get_code_without_issue REDEFINITION. -ENDCLASS. - -CLASS ltc_append_sorted_by IMPLEMENTATION. - - METHOD get_code_without_issue. - result = VALUE #( - ( ' REPORT y_example.' ) - - ( ' CLASS y_example DEFINITION.' ) - ( ' PUBLIC SECTION.' ) - ( ' METHODS example.' ) - ( ' ENDCLASS.' ) - - ( ' CLASS y_example IMPLEMENTATION.' ) - ( ' METHOD example.' ) - ( ' DATA prefer_insert_into_table TYPE TABLE OF sflight.' ) - ( ' DATA example_line TYPE sflight.' ) - ( ' APPEND example_line TO prefer_insert_into_table SORTED BY fldate.' ) - ( ' ENDMETHOD.' ) - ( ' ENDCLASS.' ) - ). - ENDMETHOD. - -ENDCLASS. - - -CLASS ltc_select DEFINITION INHERITING FROM ltc_append_to FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. - PROTECTED SECTION. - METHODS get_code_without_issue REDEFINITION. -ENDCLASS. - -CLASS ltc_select IMPLEMENTATION. - - METHOD get_code_without_issue. - result = VALUE #( - ( ' REPORT ut_test.' ) - ( ' START-OF-SELECTION.' ) - ( ' DATA example_table TYPE TABLE OF sflight.' ) - ( ' SELECT * FROM sflight APPENDING TABLE example_table.' ) - ). - ENDMETHOD. - -ENDCLASS. From b5fb54c651cb2b22fe4dd7204157bf6602802710 Mon Sep 17 00:00:00 2001 From: Kai Busse <53078228+00500500@users.noreply.github.com> Date: Mon, 13 Jan 2025 12:06:55 +0100 Subject: [PATCH 4/4] Delete src/y_check_prefer_insert_into.clas.xml --- src/y_check_prefer_insert_into.clas.xml | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 src/y_check_prefer_insert_into.clas.xml diff --git a/src/y_check_prefer_insert_into.clas.xml b/src/y_check_prefer_insert_into.clas.xml deleted file mode 100644 index 9be2c895..00000000 --- a/src/y_check_prefer_insert_into.clas.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - Y_CHECK_PREFER_INSERT_INTO - E - Prefer INSERT INTO TABLE to APPEND TO - 1 - X - X - X - X - - - -