Skip to content

Commit

Permalink
revert traversing data function, it does not use assigning template r…
Browse files Browse the repository at this point in the history
…efs to variables
  • Loading branch information
Thomasan1999 committed Nov 2, 2024
1 parent b598f30 commit b56d81e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 62 deletions.
16 changes: 0 additions & 16 deletions lib/rules/prefer-use-template-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,6 @@ module.exports = {
}
}
),
utils.executeOnVue(context, (obj) => {
const properties = utils.iterateProperties(obj, new Set(['data']))
for (const node of properties) {
// @ts-ignore
if (!expressionIsRef(node.property.value)) {
return
}

scriptRefs.push({
// @ts-ignore
node: node.property.value,
// @ts-ignore
ref: node.property.key.name
})
}
}),
{
'Program:exit'() {
for (const templateRef of templateRefs) {
Expand Down
97 changes: 51 additions & 46 deletions tests/lib/rules/prefer-use-template-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ tester.run('prefer-use-template-ref', rule, {
`
},
{
filename: 'options-api.vue',
filename: 'options-api-no-refs.vue',
code: `
<template>
<label ref="label">
Expand All @@ -126,7 +126,7 @@ tester.run('prefer-use-template-ref', rule, {
<button
</template>
<script>
import { useTemplateRef } from 'vue';
import { ref } from 'vue';
export default {
name: 'NameRow',
methods: {
Expand All @@ -138,8 +138,8 @@ tester.run('prefer-use-template-ref', rule, {
}
data() {
return {
label: useTemplateRef('label'),
name: ref('')
label: 'label',
name: ''
}
},
computed: {
Expand All @@ -150,6 +150,53 @@ tester.run('prefer-use-template-ref', rule, {
}
</script>
`
},
{
filename: 'options-api-mixed.vue',
code: `
<template>
<label ref="labelElem">
Name:
<input v-model="name" />
</label>
{{ loremIpsum }}
</template>
<script>
import { ref } from 'vue';
export default {
name: 'NameRow',
props: {
defaultLabel: {
type: String,
},
},
data() {
return {
label: ref(this.defaultLabel),
labelElem: ref(),
name: ''
}
},
computed: {
loremIpsum() {
return this.name + ' lorem ipsum'
}
}
}
</script>
`
},
{
filename: 'template-ref-function.vue',
code: `
<template>
<button :ref="ref => button = ref">Content</button>
</template>
<script setup>
import { ref } from 'vue';
const button = ref();
</script>
`
}
],
invalid: [
Expand Down Expand Up @@ -271,48 +318,6 @@ tester.run('prefer-use-template-ref', rule, {
column: 28
}
]
},
{
filename: 'options-api-only-refs.vue',
code: `
<template>
<label ref="labelElem">
Name:
<input v-model="name" />
</label>
{{ loremIpsum }}
</template>
<script>
import { ref } from 'vue';
export default {
name: 'NameRow',
props: {
defaultLabel: {
type: String,
},
},
data() {
return {
label: ref(this.defaultLabel),
labelElem: ref(),
name: ref('')
}
},
computed: {
loremIpsum() {
return this.name + ' lorem ipsum'
}
}
}
</script>
`,
errors: [
{
messageId: 'preferUseTemplateRef',
line: 21,
column: 26
}
]
}
]
})

0 comments on commit b56d81e

Please sign in to comment.