oxc-project/oxc · error · OxcDiagnostic

Do not use `null` literals

Error message

Do not use `null` literals

What it means

Raised by unicorn/no-null when a `null` literal is used in code the rule flags (variable declarators, binary expressions, etc.) and no allowed exception applies. The rule promotes `undefined` over `null`; the faulting input is the null literal at the labeled span.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_null.rs:25

};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::operator::BinaryOperator;
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::Value;

use crate::{
    AstNode,
    ast_util::{is_method_call, iter_outer_expressions},
    context::LintContext,
    fixer::{RuleFix, RuleFixer},
    rule::{DefaultRuleConfig, Rule},
};

fn no_null_diagnostic(null: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Do not use `null` literals").with_label(null)
}

#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NoNull {
    /// When set to `true`, the rule will also check strict equality/inequality comparisons (`===` and `!==`) against `null`.
    check_strict_equality: bool,
    /// When set to `true`, disallow the use of `null` as a direct function call or constructor argument.
    check_arguments: bool,
}

impl Default for NoNull {
    fn default() -> Self {
        Self { check_strict_equality: false, check_arguments: true }
    }
}

declare_oxc_lint!(

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Use `undefined` instead of `null` as the absent value
  2. Allow specific comparisons or declarations via the rule's configuration if a genuine null case exists
  3. Refactor APIs to return `undefined` or option objects rather than null sentinels
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_null.rs:25 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/55c56fe875a13e25. Report an issue: GitHub.