Why this matters
Using meaningful default values prevents errors caused by uninitialized keys, improving code robustness and reducing unexpected `nil` values.
Check for hash key lookups without default values. If a missing key is accessed, suggest using `fetch` with a default value.
Using meaningful default values prevents errors caused by uninitialized keys, improving code robustness and reducing unexpected `nil` values.
Side-by-side examples engineers can pattern-match during review.
options = {}
puts options[:timeout] || 5options = { timeout: 5 }
puts options.fetch(:timeout)options = {}
puts options[:timeout] || 5options = { timeout: 5 }
puts options.fetch(:timeout)From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.