class RuboCop::Cop::Style::NilComparison
This cop checks for comparison of something with nil using ==.
@example
# bad if x == nil # good if x.nil?
Constants
- MSG
- NIL_NODE
- OPS
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/style/nil_comparison.rb, line 22 def on_send(node) _receiver, method, args = *node return unless OPS.include?(method) add_offense(node, :selector) if args == NIL_NODE end
Private Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/style/nil_comparison.rb, line 31 def autocorrect(node) new_code = node.source.sub(/\s*={2,3}\s*nil/, '.nil?') ->(corrector) { corrector.replace(node.source_range, new_code) } end