From 0c52fd763539a6d06993ffa451b0d21d9ad3032a Mon Sep 17 00:00:00 2001 From: LinBin Date: Fri, 11 Aug 2023 15:35:52 +0800 Subject: [PATCH] Fix no-ref-as-operand and allow lint when ref as right operator fix #2271 --- lib/rules/no-ref-as-operand.js | 3 --- tests/lib/rules/no-ref-as-operand.js | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/rules/no-ref-as-operand.js b/lib/rules/no-ref-as-operand.js index 9661b2b60..7b56557dc 100644 --- a/lib/rules/no-ref-as-operand.js +++ b/lib/rules/no-ref-as-operand.js @@ -104,9 +104,6 @@ module.exports = { // refValue || other, refValue && other. ignore: other || refValue /** @param {Identifier & {parent: LogicalExpression}} node */ 'LogicalExpression>Identifier'(node) { - if (node.parent.left !== node) { - return - } // Report only constants. const data = refReferences.get(node) if ( diff --git a/tests/lib/rules/no-ref-as-operand.js b/tests/lib/rules/no-ref-as-operand.js index a932ff1c2..232f7b66e 100644 --- a/tests/lib/rules/no-ref-as-operand.js +++ b/tests/lib/rules/no-ref-as-operand.js @@ -68,6 +68,8 @@ tester.run('no-ref-as-operand', rule, { 1 - count.value count.value || other count.value && other + other && count.value + other || count.value var foo = count.value ? x : y `, ` @@ -78,8 +80,6 @@ tester.run('no-ref-as-operand', rule, { ` import { ref } from 'vue' const foo = ref(true) - var a = other || foo // ignore - var b = other && foo // ignore let bar = ref(true) var a = bar || other @@ -451,12 +451,16 @@ tester.run('no-ref-as-operand', rule, { const foo = ref(true) var a = foo || other var b = foo && other + var c = other || foo + var d = other && foo `, output: ` import { ref } from 'vue' const foo = ref(true) var a = foo.value || other var b = foo.value && other + var c = other || foo.value + var d = other && foo.value `, errors: [ { @@ -466,6 +470,14 @@ tester.run('no-ref-as-operand', rule, { { messageId: 'requireDotValue', line: 5 + }, + { + messageId: 'requireDotValue', + line: 6 + }, + { + messageId: 'requireDotValue', + line: 7 } ] },