Skip to content

Commit dc81e40

Browse files
authored
Fix false positives for assignments in no-ref-as-operand rule (#1409)
1 parent 3fb52a9 commit dc81e40

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ module.exports = {
134134
reportIfRefWrapped(node)
135135
},
136136
// refValue+=1, refValue-=1, foo+=refValue, foo-=refValue
137-
/** @param {Identifier} node */
137+
/** @param {Identifier & {parent: AssignmentExpression}} node */
138138
'AssignmentExpression>Identifier'(node) {
139+
if (node.parent.operator === '=' && node.parent.left !== node) {
140+
return
141+
}
139142
reportIfRefWrapped(node)
140143
},
141144
// refValue || other, refValue && other. ignore: other || refValue

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

Lines changed: 10 additions & 0 deletions
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)