Avoid Yoda Conditions
WarningAnti-Patterns & Bad PracticesQuickFix Ready#EC YODA_CONDRemote Enabled
Overview
Avoid Yoda conditions in comparison expressions.
ATC Finding Message:
Avoid Yoda conditions; place variable before literal in comparison
Rationale
Yoda conditions place the literal or constant on the left side of a comparison and break the natural ABAP reading order of subject, operator, and value. The habit comes from languages where an accidental assignment in a condition is possible, which is not the case for ABAP comparisons. Keep the variable or expression on the left so conditions read like plain language.
Non-Compliant
abap
IF 'ACTIVE' = lv_status.
process( ).
ENDIF.Compliant
abap
IF lv_status = 'ACTIVE'.
process( ).
ENDIF.Automated QuickFix
This rule provides an automated QuickFix directly in Eclipse ABAP Development Tools (ADT):
- Position the cursor on the flagged statement.
- Press Ctrl + 1 (Quick Assist).
- Select the automated refactoring to apply the clean syntax immediately.
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC YODA_COND
" SAP CI_ prefix format:
... "#EC CI_YODA_CONDTechnical Details
- Native ATC Class:
ZCL_SKYLINT_NO_YODA_COND - Implementation File: zcl_skylint_no_yoda_cond.clas.abap