Prefer Early Return to Reduce Nesting (Guard Clauses)
WarningClean ABAP & Modern Syntax#EC PREF_GUARD_METHODRemote Enabled
Overview
Prefer early return or continue over nested IF blocks.
ATC Finding Messages:
Invert IF condition and use RETURN to reduce nesting in methodInvert IF condition and use CONTINUE to reduce nesting in loop
Rationale
Wrapping the whole method body in IF is_valid( ) creates unnecessary nesting and pushes the happy path to the right. Guard clauses reject invalid input at the top and leave the main logic flat and easy to read. Return early for preconditions and error cases instead of indenting the successful path.
Non-Compliant
abap
METHOD process_order.
IF is_valid( ).
execute_order( ).
log_order( ).
ENDIF.
ENDMETHOD.Compliant
abap
METHOD process_order.
IF NOT is_valid( ).
RETURN.
ENDIF.
execute_order( ).
log_order( ).
ENDMETHOD.Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
CHECK_METHOD_RETURN | Boolean | true | Suggest early RETURN guard clause for top-level method validation IFs |
CHECK_LOOP_CONTINUE | Boolean | true | Suggest early CONTINUE guard clause for loop item validation IFs |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_GUARD_METHOD
" SAP CI_ prefix format:
... "#EC CI_PREF_GUARD_METHODRelated Rules
- Prefer RETURN over EXIT in Methods —
#EC PREF_RETURN - Do Not Ignore Return Value of Functional Methods —
#EC NO_IGNORED_RETURN - Omit Unnecessary RETURN Statement —
#EC NO_UNNEC_RETURN
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_EARLY_RET - Implementation File: zcl_skylint_pref_early_ret.clas.abap