Skip to content

Commit

Permalink
Fix false negative for ref in vue/script-setup-uses-vars rule. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jul 3, 2021
1 parent 8dc37de commit 86aff15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rules/script-setup-uses-vars.js
Expand Up @@ -104,6 +104,12 @@ module.exports = {
return
}
markElementVariableAsUsed(`v-${node.key.name.rawName}`)
},
/** @param {VAttribute} node */
'VAttribute[directive=false]'(node) {
if (node.key.name === 'ref' && node.value) {
context.markVariableAsUsed(node.value.value)
}
}
},
undefined,
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/script-setup-uses-vars.js
Expand Up @@ -163,6 +163,22 @@ describe('script-setup-uses-vars', () => {
ecmaVersion: 2022,
sourceType: 'module'
}
},

// ref
{
filename: 'test.vue',
code: `
<script setup>
/* eslint script-setup-uses-vars: 1 */
import {ref} from 'vue'
const v = ref(null)
</script>
<template>
<div ref="v"/>
</template>
`
}
],

Expand Down

0 comments on commit 86aff15

Please sign in to comment.