Skip to content

Commit

Permalink
fix: no-unused-vars false positive with logical assignment operators (#…
Browse files Browse the repository at this point in the history
…17320)

* fix: no-unused-vars should be corrected in logical assignment operator

Fixes #17299

* refactor: use astUtils.isLogicalAssignmentOperator check exception
  • Loading branch information
gweesin committed Jun 30, 2023
1 parent c8b1f4d commit a36bcb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/no-unused-vars.js
Expand Up @@ -466,7 +466,8 @@ module.exports = {
(
parent.type === "AssignmentExpression" &&
parent.left === id &&
isUnusedExpression(parent)
isUnusedExpression(parent) &&
!astUtils.isLogicalAssignmentOperator(parent.operator)
) ||
(
parent.type === "UpdateExpression" &&
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/no-unused-vars.js
Expand Up @@ -417,6 +417,20 @@ ruleTester.run("no-unused-vars", rule, {
{
code: "import.meta",
parserOptions: { ecmaVersion: 2020, sourceType: "module" }
},

// https://github.com/eslint/eslint/issues/17299
{
code: "var a; a ||= 1;",
parserOptions: { ecmaVersion: 2021 }
},
{
code: "var a; a &&= 1;",
parserOptions: { ecmaVersion: 2021 }
},
{
code: "var a; a ??= 1;",
parserOptions: { ecmaVersion: 2021 }
}
],
invalid: [
Expand Down

0 comments on commit a36bcb6

Please sign in to comment.