Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 539 Bytes

Lint-SafeNavigationWithEmpty.md

File metadata and controls

23 lines (15 loc) · 539 Bytes

Pattern: Safe navigation with empty?

Issue: -

Description

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

Examples

# bad
return if foo&.empty?
return unless foo&.empty?

# good
return if foo && foo.empty?
return unless foo && foo.empty?

Further Reading