Skip to content

Commit 5636517

Browse files
fix: single location attribute (#49)
1 parent 0776980 commit 5636517

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/rules/no-deprecated-props.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,37 @@ module.exports = {
623623
messages: {
624624
replacedWith: `'{{ a }}' has been replaced with '{{ b }}'`,
625625
removed: `'{{ name }}' has been removed`,
626+
combined: `multiple {{ a }} attributes have been combined`,
626627
},
627628
},
628629

629630
create (context) {
630631
return context.parserServices.defineTemplateBodyVisitor({
632+
VStartTag (tag) {
633+
const attrGroups = {}
634+
tag.attributes.forEach(attr => {
635+
if (['location'].includes(attr.key.name)) {
636+
(attrGroups[attr.key.name] ??= []).push(attr)
637+
}
638+
})
639+
Object.values(attrGroups).forEach(attrGroup => {
640+
const [head, ...tail] = attrGroup
641+
if (!tail.length) return
642+
context.report({
643+
messageId: 'combined',
644+
data: {
645+
a: head.key.name,
646+
},
647+
node: head,
648+
fix (fixer) {
649+
return [
650+
fixer.replaceText(head.value, `"${attrGroup.map(a => a.value.value).join(" ")}"`),
651+
...tail.map(a => fixer.remove(a))
652+
]
653+
},
654+
})
655+
})
656+
},
631657
VAttribute (attr) {
632658
if (
633659
attr.directive &&

tests/rules/no-deprecated-props.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,10 @@ tester.run('no-deprecated-props', rule, {
111111
output: '<template><v-snackbar :class="`elevation-${variable}`" class="foo" /></template>',
112112
errors: [{ messageId: 'replacedWith' }],
113113
},
114+
{
115+
code: '<template><v-menu location="bottom" location="left" /></template>',
116+
output: '<template><v-menu location="bottom left" /></template>',
117+
errors: [{ messageId: 'combined' }],
118+
},
114119
],
115120
})

0 commit comments

Comments
 (0)