Skip to content

Files

Latest commit

 

History

History
28 lines (19 loc) · 633 Bytes

Rails-SafeNavigationWithBlank.md

File metadata and controls

28 lines (19 loc) · 633 Bytes

Pattern: Use of blank? with safe navigation operator

Issue: -

Description

This cop checks to make sure safe navigation isn't used with blank? in a conditional.

While the safe navigation operator is generally a good idea, when checking foo&.blank? in a conditional, foo being nil will actually do the opposite of what the author intends.

Examples

# bad
do_something if foo&.blank?
do_something unless foo&.blank?

# good
do_something if foo.blank?
do_something unless foo.blank?

Further Reading