Skip to content

📎 useNullishCoalescing: ignoreBooleanCoercion should verify Boolean is the global built-in #9842

@pkallos

Description

@pkallos

Description

Description

Follow-up to #9232.

The ignoreBooleanCoercion option currently suppresses diagnostics for any || expression inside a call to a function named Boolean, without verifying that the callee resolves to the global Boolean constructor. If a user shadows Boolean with a local function, the option incorrectly suppresses the diagnostic.

Current behavior (incorrect):

function Boolean(x: unknown): boolean { return !!x; }
declare const a: string | null;
const r = Boolean(a || 'default'); // no diagnostic when ignoreBooleanCoercion is true

The diagnostic should still fire here because Boolean is not the global built-in.

Expected behavior:

Only suppress the diagnostic when Boolean resolves to the global built-in, not a locally defined function.

The ESLint rule handles this by checking the scope chain to confirm the identifier has no local definitions. The current Biome implementation uses call.has_callee("Boolean"), which is a name-only check.

Fixing this likely requires either switching the rule's query type from Typed<T> to Semantic<T> for scope/binding resolution, or finding an alternative way to check whether Boolean is shadowed using the available infrastructure.

References:

  • ESLint implementation: isBuiltInBooleanCall checks scope.set.get("Boolean") for local definitions
  • Biome implementation: is_in_boolean_call_context in crates/biome_js_analyze/src/lint/nursery/use_nullish_coalescing.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions