Nil Check
Introduction
A NilCheck
is a type check. Failures of NilCheck
violate the "tell, don't ask" principle.
Additionally to that, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.
Example
Given
class Klass
def nil_checker(argument)
if argument.nil?
puts "argument isn't nil!"
end
end
end
reek
would emit the following warning:
test.rb -- 1 warning:
[3]:Klass#nil_checker performs a nil-check. (NilCheck)
Current Support in Reek
NilCheck
reports use of
.nil?
method==
and===
operators when checking vs.nil
- case statements that use syntax like
when nil
Configuration
Nil Check
offers the Basic Smell Options.