Skip to content

Commit d176d6b

Browse files
committed
Fix false positives for assignments in no-ref-as-operand rule (#1409)
1 parent c387fc3 commit d176d6b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rules/no-ref-as-operand.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ module.exports = {
131131
reportIfRefWrapped(node)
132132
},
133133
// refValue+=1, refValue-=1, foo+=refValue, foo-=refValue
134-
/** @param {Identifier} node */
134+
/** @param {Identifier & {parent: AssignmentExpression}} node */
135135
'AssignmentExpression>Identifier'(node) {
136+
if (node.parent.operator === '=' && node.parent.left !== node) {
137+
return
138+
}
136139
reportIfRefWrapped(node)
137140
},
138141
// refValue || other, refValue && other. ignore: other || refValue

tests/lib/rules/no-ref-as-operand.js

+10
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ tester.run('no-ref-as-operand', rule, {
121121
const count = ref
122122
count++
123123
`,
124+
`
125+
import { ref } from 'vue'
126+
const count = ref(0)
127+
foo = count
128+
`,
129+
`
130+
import { ref } from 'vue'
131+
const count = ref(0)
132+
const foo = count
133+
`,
124134
{
125135
code: `
126136
<script>

0 commit comments

Comments
 (0)