-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Allow CHECK keyword in begin of routines #1097
base: main
Are you sure you want to change the base?
Changes from all commits
96dd95c
9954a80
1f9fb50
95d397f
b352814
aeae0d0
36ce9d1
58d51c9
2f9aa15
bb60f2b
448004c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,13 @@ | |||||||||
PROTECTED SECTION. | ||||||||||
DATA mv_check TYPE flag. | ||||||||||
DATA mv_exit TYPE flag. | ||||||||||
|
||||||||||
METHODS _is_check_allow | ||||||||||
IMPORTING | ||||||||||
!io_scan TYPE REF TO zcl_aoc_scan | ||||||||||
!iv_statement_index TYPE i | ||||||||||
RETURNING | ||||||||||
VALUE(rv_result) TYPE abap_bool . | ||||||||||
PRIVATE SECTION. | ||||||||||
ENDCLASS. | ||||||||||
|
||||||||||
|
@@ -65,6 +72,12 @@ | |||||||||
EXIT. " current loop | ||||||||||
ENDLOOP. | ||||||||||
IF sy-subrc <> 0. | ||||||||||
IF lv_error = '002' AND _is_check_allow( | ||||||||||
io_scan = io_scan | ||||||||||
iv_statement_index = lv_index | ||||||||||
) IS NOT INITIAL. | ||||||||||
CONTINUE. | ||||||||||
ENDIF. | ||||||||||
lv_line = io_scan->statement_row( lv_index ). | ||||||||||
|
||||||||||
lv_include = io_scan->get_include( <ls_statement>-level ). | ||||||||||
|
@@ -142,4 +155,103 @@ | |||||||||
ASSERT sy-subrc = 0. | ||||||||||
|
||||||||||
ENDMETHOD. | ||||||||||
ENDCLASS. | ||||||||||
|
||||||||||
|
||||||||||
METHOD _is_check_allow. | ||||||||||
************************************************************************ | ||||||||||
* Copyright (c) 2023 by Alexandr Zhuravlev | ||||||||||
* MIT License | ||||||||||
* https://github.com/alezhu/abapOpenChecks/ | ||||||||||
|
||||||||||
*Rule | ||||||||||
* | ||||||||||
*Only use RETURN to exit procedures | ||||||||||
|
||||||||||
*Exception !!!!!! | ||||||||||
* | ||||||||||
*An exception to the rule to only use RETURN to exit procedures are | ||||||||||
*CHECK statements that are located at the beginning of a procedure and | ||||||||||
*that check the prerequisites for the execution of the procedure there. | ||||||||||
* | ||||||||||
*Using the CHECK statement in such a way does not impair the legibility | ||||||||||
*and is thus allowed. | ||||||||||
************************************************************************ | ||||||||||
|
||||||||||
DATA(lp_s_check) = REF #( io_scan->statements[ iv_statement_index ] ). | ||||||||||
DATA(lv_struct_index) = lp_s_check->struc. | ||||||||||
"Search Routine parent | ||||||||||
WHILE lv_struct_index > 0. | ||||||||||
DATA(lp_s_struct) = REF #( io_scan->structures[ lv_struct_index ] ). | ||||||||||
IF lp_s_struct->type = scan_struc_type-routine. | ||||||||||
EXIT. | ||||||||||
ENDIF. | ||||||||||
lv_struct_index = lp_s_struct->back. | ||||||||||
ENDWHILE. | ||||||||||
IF lp_s_struct IS NOT BOUND. | ||||||||||
RETURN. | ||||||||||
ENDIF. | ||||||||||
|
||||||||||
"Check all statements from routine start to current CHECK | ||||||||||
"and skip available statements | ||||||||||
DATA(lv_from) = SWITCH i( lp_s_struct->type | ||||||||||
WHEN scan_struc_type-routine THEN lp_s_struct->stmnt_from + 1 " +1 skips METHOD/FORM/FUNCTION etc | ||||||||||
ELSE lp_s_struct->stmnt_from ). | ||||||||||
LOOP AT io_scan->statements REFERENCE INTO DATA(lp_s_statement) | ||||||||||
FROM lv_from | ||||||||||
TO iv_statement_index - 1. " -1 skips current CHECK | ||||||||||
|
||||||||||
CASE lp_s_statement->type. | ||||||||||
WHEN scan_stmnt_type-include | ||||||||||
OR scan_stmnt_type-include_miss | ||||||||||
OR scan_stmnt_type-type_pools | ||||||||||
OR scan_stmnt_type-type_pools_miss | ||||||||||
OR scan_stmnt_type-comment | ||||||||||
OR scan_stmnt_type-comment_in_stmnt | ||||||||||
OR scan_stmnt_type-pragma | ||||||||||
OR scan_stmnt_type-abap_doc | ||||||||||
OR scan_stmnt_type-macro_definition | ||||||||||
OR scan_stmnt_type-empty. | ||||||||||
"Skip allow | ||||||||||
CONTINUE. | ||||||||||
WHEN scan_stmnt_type-standard | ||||||||||
OR scan_stmnt_type-unknown. | ||||||||||
DATA(lv_keyword) = io_scan->statement_keyword( sy-tabix ). | ||||||||||
CASE lv_keyword. | ||||||||||
WHEN 'TYPES' | ||||||||||
OR 'DATA' | ||||||||||
OR 'STATICS' | ||||||||||
OR 'TABLES' | ||||||||||
OR 'CONSTANTS' | ||||||||||
OR 'FIELD-SYMBOLS'. | ||||||||||
WHEN 'CLEAR' | ||||||||||
OR 'FREE' | ||||||||||
OR 'REFRESH'. | ||||||||||
Comment on lines
+226
to
+228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually clear the exporting parameters anyway and then check the importing parameters . |
||||||||||
WHEN 'ASSERT' | ||||||||||
OR 'CHECK' | ||||||||||
OR 'LEAVE' | ||||||||||
OR 'RAISE' | ||||||||||
OR 'RETURN' | ||||||||||
OR 'EXIT'. | ||||||||||
WHEN 'BREAK-POINT' | ||||||||||
OR 'LOG-POINT'. | ||||||||||
WHEN 'DESCRIBE' | ||||||||||
OR 'GET' | ||||||||||
OR 'INCLUDE' | ||||||||||
OR 'ASSIGN'. | ||||||||||
Comment on lines
+237
to
+240
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'DESCRIBE' - for describe lines or get field type and then check it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with pcf0: In my opinion this goes against the spirit of only allowing CHECK at the start of routines. If you need to do things before you CHECK, then it's not the start of the routine anymore. |
||||||||||
WHEN 'IF' | ||||||||||
OR 'ENDIF'. | ||||||||||
WHEN 'DEFINE' | ||||||||||
OR 'END-OF-DEFINITION'. | ||||||||||
WHEN OTHERS. | ||||||||||
"CHECK not allow after others | ||||||||||
RETURN. | ||||||||||
ENDCASE. | ||||||||||
WHEN OTHERS. | ||||||||||
"CHECK not allow after such statement type | ||||||||||
RETURN. | ||||||||||
ENDCASE. | ||||||||||
ENDLOOP. | ||||||||||
|
||||||||||
rv_result = abap_true. | ||||||||||
ENDMETHOD. | ||||||||||
ENDCLASS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git keeps the history
you can choose to contribute under the license terms, I dont want to add multiple license parts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse me, but I do not understand. Do you mean that I should remove those 3 lines?