Skip to content

Commit

Permalink
Fix false positives for assignments in no-ref-as-operand rule (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jan 5, 2021
1 parent c387fc3 commit d176d6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rules/no-ref-as-operand.js
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/no-ref-as-operand.js
Expand Up @@ -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: `
<script>
Expand Down

0 comments on commit d176d6b

Please sign in to comment.