Skip to content

πŸ“Ž useNullishCoalescing: add ignoreMixedLogicalExpressions, ignorePrimitives, and ignoreBooleanCoercion optionsΒ #9232

@pkallos

Description

@pkallos

Description

Follow-up to #8043 / PR #8952.

Add three configuration options to bring the existing || -> ?? check to feature parity with the ESLint rule. These all enhance the base behavior that already exists without introducing new AST visitors.

ignoreMixedLogicalExpressions (default: false)

When true, suppress diagnostics when the || expression is part of a mixed logical expression involving &&. The current implementation already blocks fixes in this scenario for safety, but doesn't expose this as a user-facing option to also suppress the diagnostic. This option makes that behavior configurable.

Example suppressed when enabled: a || b && c

ignorePrimitives (default: all false)

Allow users to suppress diagnostics for specific primitive types in the left operand's type union. Accepts either true (ignore all primitives) or an object with string, number, boolean, bigint fields.

Example suppressed when number: true: declare const x: number | null; x || 0

ignoreBooleanCoercion (default: false)

When true, suppress diagnostics when the || expression appears inside a Boolean() call, where the falsy-coalescing behavior is intentional.

Example suppressed when enabled: Boolean(a || b)

References:

Once this and the preceding issues are all integrated and validated in nursery, the rule source can be rebranded from inspired() to same().

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions