Skip to content

πŸ“Ž useNullishCoalescing: suggest ??= for logical OR assignment (||=)Β #9230

@pkallos

Description

@pkallos

Description

Follow-up to #8043 / PR #8952.

Extend useNullishCoalescing to detect ||= assignment expressions where the left-hand side is possibly nullish and suggest rewriting them as ??=.

Pattern to detect:

  • a ||= b -> a ??= b

The existing type-eligibility and safety logic from the || -> ?? check applies directly here. The main work is adding a new query target for JsAssignmentExpression with the ||= operator, reusing is_possibly_nullish and is_safe_type_for_replacement to gate the diagnostic and fix.

The fix itself is a straightforward token replacement of ||= with ??=, same approach as the existing || -> ?? fix.

References:

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