Skip to content

Commit

Permalink
feat(no-unused-refs): support template ref api (#2541)
Browse files Browse the repository at this point in the history
Co-authored-by: Flo Edelmann <[email protected]>
  • Loading branch information
KazariEX and FloEdelmann authored Sep 12, 2024
1 parent dfdbe1a commit c27837d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/rules/no-unused-refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ module.exports = {
refsNode = id.parent
}
extractUsedForPattern(refsNode)
},
CallExpression(callExpression) {
const firstArgument = callExpression.arguments[0]
if (
callExpression.callee.name !== 'useTemplateRef' ||
!firstArgument
) {
return
}
const name = utils.getStringLiteralValue(firstArgument)
if (name !== null) {
usedRefs.add(name)
}
}
}
)
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/no-unused-refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ tester.run('no-unused-refs', rule, {
const x = ref(null)
</script>
`
},
{
filename: 'test.vue',
code: `
<template>
<input ref="x" />
<input ref="y" />
</template>
<script setup>
import {useTemplateRef} from 'vue'
const inputX = useTemplateRef('x')
const inputY = useTemplateRef(\`y\`)
</script>
`
}
],

Expand Down

0 comments on commit c27837d

Please sign in to comment.