Skip to content

Standard Functions in Prefer IS NOT to NOT IS #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Whenever you upgrade code pal for ABAP, it is highly recommended to execute the

2021-04-** v.1.14.0
------------------
* Standard functions in Prefer IS NOT to NOT IS (#338)
* In the profile feature, you can add all the missing checks (#346)

2021-04-05 v.1.13.1
Expand Down
16 changes: 14 additions & 2 deletions src/checks/y_check_prefer_is_not.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ CLASS y_check_prefer_is_not DEFINITION PUBLIC INHERITING FROM y_check_base CREAT
PROTECTED SECTION.
METHODS inspect_tokens REDEFINITION.

METHODS is_standard_function IMPORTING token TYPE stokesx
RETURNING VALUE(result) TYPE abap_bool.

ENDCLASS.


Expand Down Expand Up @@ -33,7 +36,8 @@ CLASS y_check_prefer_is_not IMPLEMENTATION.
WHERE str = 'IF'
OR str = 'ELSEIF'
OR str = 'AND'
OR str = 'OR'.
OR str = 'OR'
OR str = 'ASSERT'.

DATA(position) = sy-tabix.

Expand All @@ -46,7 +50,7 @@ CLASS y_check_prefer_is_not IMPLEMENTATION.
ENDTRY.

TRY.
IF ref_scan_manager->tokens[ position + 2 ]-str = 'LINE_EXISTS('.
IF is_standard_function( ref_scan_manager->tokens[ position + 2 ] ) = abap_true.
CONTINUE.
ENDIF.
CATCH cx_sy_itab_line_not_found.
Expand All @@ -67,4 +71,12 @@ CLASS y_check_prefer_is_not IMPLEMENTATION.
ENDLOOP.
ENDMETHOD.


METHOD is_standard_function.
result = xsdbool( token-str CP 'CONTAINS*'
OR token-str CP 'LINE_EXISTS*'
OR token-str CP 'MATCHES*' ).
ENDMETHOD.


ENDCLASS.
80 changes: 78 additions & 2 deletions src/checks/y_check_prefer_is_not.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,84 @@ CLASS ltc_line_exists IMPLEMENTATION.

( ' START-OF-SELECTION. ' )
( ' DATA itab TYPE TABLE OF tadir. ' )
( ' IF NOT line_exists( itab[ 0 ] ). ' )
( ' ENDIF. ' )
( ' ASSERT NOT line_exists( itab[ 0 ] ). ' )
).
ENDMETHOD.

ENDCLASS.



CLASS ltc_contains DEFINITION INHERITING FROM ltc_not_value FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_without_issue REDEFINITION.
ENDCLASS.

CLASS ltc_contains IMPLEMENTATION.

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

( ' START-OF-SELECTION. ' )
( | ASSERT NOT contains( val = 'code pal for ABAP' sub = 'ABAP' ). | )
).
ENDMETHOD.

ENDCLASS.


CLASS ltc_matches DEFINITION INHERITING FROM ltc_not_value FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_without_issue REDEFINITION.
ENDCLASS.

CLASS ltc_matches IMPLEMENTATION.

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

( ' START-OF-SELECTION. ' )
( | ASSERT NOT matches( val = 'a123e' regex = '[[:alpha:]]*' ). | )
).
ENDMETHOD.

ENDCLASS.


CLASS ltc_contains_any_not_of DEFINITION INHERITING FROM ltc_not_value FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_without_issue REDEFINITION.
ENDCLASS.

CLASS ltc_contains_any_not_of IMPLEMENTATION.

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

( ' START-OF-SELECTION. ' )
( | ASSERT NOT contains_any_not_of( val = 'a123e' sub = '123' ). | )
).
ENDMETHOD.

ENDCLASS.


CLASS ltc_contains_any_of DEFINITION INHERITING FROM ltc_not_value FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_without_issue REDEFINITION.
ENDCLASS.

CLASS ltc_contains_any_of IMPLEMENTATION.

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

( ' START-OF-SELECTION. ' )
( | ASSERT NOT contains_any_of( val = 'a123e' sub = '123' ). | )
).
ENDMETHOD.

Expand Down