Sha256: 0b77d4e1f7eee05cc2dae0687f4e54e42317e594c38400bb738045089bad2ad9

Contents?: true

Size: 1.03 KB

Versions: 11

Compression:

Stored size: 1.03 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 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

_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

11 entries across 11 versions & 1 rubygems

Version Path
reek-4.5.5 docs/Nil-Check.md
reek-4.5.4 docs/Nil-Check.md
reek-4.5.3 docs/Nil-Check.md
reek-4.5.2 docs/Nil-Check.md
reek-4.5.1 docs/Nil-Check.md
reek-4.5.0 docs/Nil-Check.md
reek-4.4.2 docs/Nil-Check.md
reek-4.4.1 docs/Nil-Check.md
reek-4.4.0 docs/Nil-Check.md
reek-4.3.0 docs/Nil-Check.md
reek-4.2.5 docs/Nil-Check.md