Skip to content

Commit b56d81e

Browse files
committed
revert traversing data function, it does not use assigning template refs to variables
1 parent b598f30 commit b56d81e

File tree

2 files changed

+51
-62
lines changed

2 files changed

+51
-62
lines changed

lib/rules/prefer-use-template-ref.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@ module.exports = {
6666
}
6767
}
6868
),
69-
utils.executeOnVue(context, (obj) => {
70-
const properties = utils.iterateProperties(obj, new Set(['data']))
71-
for (const node of properties) {
72-
// @ts-ignore
73-
if (!expressionIsRef(node.property.value)) {
74-
return
75-
}
76-
77-
scriptRefs.push({
78-
// @ts-ignore
79-
node: node.property.value,
80-
// @ts-ignore
81-
ref: node.property.key.name
82-
})
83-
}
84-
}),
8569
{
8670
'Program:exit'() {
8771
for (const templateRef of templateRefs) {

tests/lib/rules/prefer-use-template-ref.js

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ tester.run('prefer-use-template-ref', rule, {
115115
`
116116
},
117117
{
118-
filename: 'options-api.vue',
118+
filename: 'options-api-no-refs.vue',
119119
code: `
120120
<template>
121121
<label ref="label">
@@ -126,7 +126,7 @@ tester.run('prefer-use-template-ref', rule, {
126126
<button
127127
</template>
128128
<script>
129-
import { useTemplateRef } from 'vue';
129+
import { ref } from 'vue';
130130
export default {
131131
name: 'NameRow',
132132
methods: {
@@ -138,8 +138,8 @@ tester.run('prefer-use-template-ref', rule, {
138138
}
139139
data() {
140140
return {
141-
label: useTemplateRef('label'),
142-
name: ref('')
141+
label: 'label',
142+
name: ''
143143
}
144144
},
145145
computed: {
@@ -150,6 +150,53 @@ tester.run('prefer-use-template-ref', rule, {
150150
}
151151
</script>
152152
`
153+
},
154+
{
155+
filename: 'options-api-mixed.vue',
156+
code: `
157+
<template>
158+
<label ref="labelElem">
159+
Name:
160+
<input v-model="name" />
161+
</label>
162+
{{ loremIpsum }}
163+
</template>
164+
<script>
165+
import { ref } from 'vue';
166+
export default {
167+
name: 'NameRow',
168+
props: {
169+
defaultLabel: {
170+
type: String,
171+
},
172+
},
173+
data() {
174+
return {
175+
label: ref(this.defaultLabel),
176+
labelElem: ref(),
177+
name: ''
178+
}
179+
},
180+
computed: {
181+
loremIpsum() {
182+
return this.name + ' lorem ipsum'
183+
}
184+
}
185+
}
186+
</script>
187+
`
188+
},
189+
{
190+
filename: 'template-ref-function.vue',
191+
code: `
192+
<template>
193+
<button :ref="ref => button = ref">Content</button>
194+
</template>
195+
<script setup>
196+
import { ref } from 'vue';
197+
const button = ref();
198+
</script>
199+
`
153200
}
154201
],
155202
invalid: [
@@ -271,48 +318,6 @@ tester.run('prefer-use-template-ref', rule, {
271318
column: 28
272319
}
273320
]
274-
},
275-
{
276-
filename: 'options-api-only-refs.vue',
277-
code: `
278-
<template>
279-
<label ref="labelElem">
280-
Name:
281-
<input v-model="name" />
282-
</label>
283-
{{ loremIpsum }}
284-
</template>
285-
<script>
286-
import { ref } from 'vue';
287-
export default {
288-
name: 'NameRow',
289-
props: {
290-
defaultLabel: {
291-
type: String,
292-
},
293-
},
294-
data() {
295-
return {
296-
label: ref(this.defaultLabel),
297-
labelElem: ref(),
298-
name: ref('')
299-
}
300-
},
301-
computed: {
302-
loremIpsum() {
303-
return this.name + ' lorem ipsum'
304-
}
305-
}
306-
}
307-
</script>
308-
`,
309-
errors: [
310-
{
311-
messageId: 'preferUseTemplateRef',
312-
line: 21,
313-
column: 26
314-
}
315-
]
316321
}
317322
]
318323
})

0 commit comments

Comments
 (0)