eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

Rule proposal: `logical-assignment-operators` replacement

Open fisker opened this issue 7 months ago • 1 comments

Description

The core rule logical-assignment-operators auto fixes

if (!a) {
  a = 1
}

to

a ||= 1

But sometimes, a ??= 1 should be preferred, and ESLint refuses to use suggestions instead, https://github.com/eslint/eslint/issues/19672

How about we make our own one?

Examples

// ❌
if (!a) {
  a = 1
}

// ✅
a ||= 1

// ✅
a ??= 1

Proposed rule name

logical-assignment-operators

Additional Info

No response

fisker avatar May 06 '25 02:05 fisker

Accepted

sindresorhus avatar May 06 '25 06:05 sindresorhus