Skip to content

Magic Number: Leading Zeros #479

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 2 commits into from
Oct 11, 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 @@ -18,6 +18,7 @@ Legend

2021-08-XX v.1.16.0
------------------
* Magic Number: Leading Zeros (#479)
* Prefer New to Create Object: Dynamic Type (#469)
* Magic Number: Table Index (#468)
* Use native *_wa variables (#474)
Expand Down
3 changes: 2 additions & 1 deletion src/checks/y_check_magic_number.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ CLASS y_check_magic_number IMPLEMENTATION.
METHOD is_magic_number.
DATA(string) = token_wa-str.
REPLACE ALL OCCURRENCES OF |'| IN string WITH ||.

result = xsdbool( string IS NOT INITIAL
AND string CO '0123456789'
AND string <> '0'
AND string CN '0'
AND string <> '1' ).
ENDMETHOD.

Expand Down
20 changes: 20 additions & 0 deletions src/checks/y_check_magic_number.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,23 @@ CLASS ltc_empty_string IMPLEMENTATION.
ENDMETHOD.

ENDCLASS.


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

CLASS ltc_leading_zeros IMPLEMENTATION.

METHOD get_code_without_issue.
result = VALUE #(
( ' REPORT ut_test.' )
( ' START-OF-SELECTION.' )
( | DATA char TYPE c LENGTH 6. | )
( | IF char = '000000'. | )
( ' ENDIF. ' )
).
ENDMETHOD.

ENDCLASS.