Sha256: 6625db5776ea70a06f46fd82bf0930d46bfcaabd8351dd8cef3af39301cfcb65
Contents?: true
Size: 779 Bytes
Versions: 2
Compression:
Stored size: 779 Bytes
Contents
# encoding: utf-8 module Rubocop module Cop module Style # This cop checks for comparison of something with nil using ==. # # @example # # # bad # if x == nil # if x != nil # # # good # if x.nil? # if !x.nil? class NilComparison < Cop MSG = 'Prefer the use of the nil? predicate.' OPS = %w(== === !=) NIL_NODE = s(:nil) def on_send(node) # lambda.() does not have a selector return unless node.loc.selector op = node.loc.selector.source if OPS.include?(op) _receiver, _method, args = *node add_offense(node, :selector) if args == NIL_NODE end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.19.1 | lib/rubocop/cop/style/nil_comparison.rb |
rubocop-0.19.0 | lib/rubocop/cop/style/nil_comparison.rb |