Skip to content

Files

Latest commit

 

History

History
37 lines (25 loc) · 647 Bytes

Style-MinMaxComparison.md

File metadata and controls

37 lines (25 loc) · 647 Bytes

Pattern: Missing use of max/min

Issue: -

Description

Enforces the use of max or min instead of comparison for greater or less.

NOTE: It can be used if you want to present limit or threshold in Ruby 2.7+. That it is slow though. So auto-correction will apply generic max or min:

a.clamp(b..) # Same as `[a, b].max`
a.clamp(..b) # Same as `[a, b].min`

Examples

# bad
a > b ? a : b
a >= b ? a : b

# good
[a, b].max

# bad
a < b ? a : b
a <= b ? a : b

# good
[a, b].min

Further Reading