Sha256: 81b23dbfa84b2745e09ef79a796c2c817575fb24f078187f007ffddb383b7d74

Contents?: true

Size: 1.02 KB

Versions: 27

Compression:

Stored size: 1.02 KB

Contents

# Nil Check

## Introduction

A _Nil Check_ is a type check. Failures of _Nil Check_ violate the
["tell, don't ask"](http://robots.thoughtbot.com/tell-dont-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.

The _Nil Check_ code smell is a case of [Simulated Polymorphism](Simulated-Polymorphism.md).

## Example

Given

```Ruby
class Klass
  def nil_checker(argument)
    if argument.nil?
      puts "argument is 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

_Nil Check_ reports use of 

* <code>.nil?</code> method
* <code>==</code> and <code>===</code> operators when checking vs. <code>nil</code>
* case statements that use syntax like <code>when nil</code>
* use of the safe navigation operator like `foo&.bar`

## Configuration

_Nil Check_ offers the [Basic Smell Options](Basic-Smell-Options.md).

Version data entries

27 entries across 25 versions & 2 rubygems

Version Path
reek-5.6.0 docs/Nil-Check.md
reek-5.5.0 docs/Nil-Check.md
reek-5.4.1 docs/Nil-Check.md
reek-5.4.0 docs/Nil-Check.md
reek-5.3.2 docs/Nil-Check.md
reek-5.3.1 docs/Nil-Check.md
reek-5.3.0 docs/Nil-Check.md
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Nil-Check.md
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Nil-Check.md
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Nil-Check.md
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/reek-5.2.0/docs/Nil-Check.md
reek-5.2.0 docs/Nil-Check.md
reek-5.1.0 docs/Nil-Check.md
reek-5.0.2 docs/Nil-Check.md
reek-5.0.1 docs/Nil-Check.md
reek-5.0.0 docs/Nil-Check.md
reek-4.8.2 docs/Nil-Check.md
reek-4.8.1 docs/Nil-Check.md
reek-4.8.0 docs/Nil-Check.md
reek-4.7.3 docs/Nil-Check.md