Skip to content
This repository was archived by the owner on Mar 15, 2023. It is now read-only.

Latest commit

 

History

History
29 lines (19 loc) · 638 Bytes

File metadata and controls

29 lines (19 loc) · 638 Bytes

Prefer isSome(expr) to checking against undefined or null (null-or-undefined-check)

Never check directly against undefined or null. Instead, use isSome.

Rule Details

This rule aims to ensure that we don't treat undefined and null differently in our code, since doing so tends to cause confusion.

Autofixer available.

Examples of incorrect code for this rule:

if (x !== undefined) {
  return x;
}

Examples of correct code for this rule:

if (isSome(x)) {
  return x;
}

When Not To Use It

If you're dealing with third-party code that needs to differentiate between undefined and null.