close

no-null

Added in v0.9.1

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-null': 'error',
    },
  },
]);

Rule Details

Disallow the null literal and encourage using undefined as the single value for missing data.

Examples of incorrect code for this rule:

let value = null;

if (value == null) {}

Examples of correct code for this rule:

let value;

if (value == undefined) {}

const dictionary = Object.create(null);

Strict equality comparisons are ignored by default:

if (value === null) {}

Options

This rule accepts an object with two boolean options:

  • checkArguments (default: true) checks null when it is a direct function call or constructor argument. Set it to false when APIs require null arguments.
  • checkStrictEquality (default: false) checks strict equality and inequality comparisons against null.

The rule follows Unicorn's built-in exceptions for Object.create(null), useRef(null), React.useRef(null), and null as the second argument of a two-argument insertBefore call.

Original Documentation