π Require or disallow logical assignment operator shorthand.
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
π§π‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
This rule is the same as the built-in ESLint logical-assignment-operators rule, but when enforceForIfStatements is enabled, falsy if assignments are reported with suggestions for both ||= and ??= instead of being autofixed.
Consistently choosing logical-assignment shorthand or an explicit assignment or conditional makes updates easier to scan and avoids mixing the same pattern in different forms.
This rule replaces ESLint's built-in logical-assignment-operators rule, which Unicorn presets disable when this rule is enabled.
/* eslint unicorn/logical-assignment-operators: ["error", "always", {"enforceForIfStatements": true}] */
// β
if (!foo) {
foo = bar;
}
// β
foo ||= bar;
// β
foo ??= bar;This rule supports the same options as ESLint logical-assignment-operators.