From d176d6bce9953c1b20eff851208235ea7e7a5efa Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Tue, 5 Jan 2021 10:29:24 +0900 Subject: [PATCH] Fix false positives for assignments in `no-ref-as-operand` rule (#1409) --- lib/rules/no-ref-as-operand.js | 5 ++++- tests/lib/rules/no-ref-as-operand.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-ref-as-operand.js b/lib/rules/no-ref-as-operand.js index fb5dc0881..00cdbed09 100644 --- a/lib/rules/no-ref-as-operand.js +++ b/lib/rules/no-ref-as-operand.js @@ -131,8 +131,11 @@ module.exports = { reportIfRefWrapped(node) }, // refValue+=1, refValue-=1, foo+=refValue, foo-=refValue - /** @param {Identifier} node */ + /** @param {Identifier & {parent: AssignmentExpression}} node */ 'AssignmentExpression>Identifier'(node) { + if (node.parent.operator === '=' && node.parent.left !== node) { + return + } reportIfRefWrapped(node) }, // refValue || other, refValue && other. ignore: other || refValue diff --git a/tests/lib/rules/no-ref-as-operand.js b/tests/lib/rules/no-ref-as-operand.js index 50cfd3249..2a6293485 100644 --- a/tests/lib/rules/no-ref-as-operand.js +++ b/tests/lib/rules/no-ref-as-operand.js @@ -121,6 +121,16 @@ tester.run('no-ref-as-operand', rule, { const count = ref count++ `, + ` + import { ref } from 'vue' + const count = ref(0) + foo = count + `, + ` + import { ref } from 'vue' + const count = ref(0) + const foo = count + `, { code: `