Skip to content

Commit

Permalink
fix: single location attribute (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslihotzki authored Nov 9, 2023
1 parent 0776980 commit 5636517
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/rules/no-deprecated-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,37 @@ module.exports = {
messages: {
replacedWith: `'{{ a }}' has been replaced with '{{ b }}'`,
removed: `'{{ name }}' has been removed`,
combined: `multiple {{ a }} attributes have been combined`,
},
},

create (context) {
return context.parserServices.defineTemplateBodyVisitor({
VStartTag (tag) {
const attrGroups = {}
tag.attributes.forEach(attr => {
if (['location'].includes(attr.key.name)) {
(attrGroups[attr.key.name] ??= []).push(attr)
}
})
Object.values(attrGroups).forEach(attrGroup => {
const [head, ...tail] = attrGroup
if (!tail.length) return
context.report({
messageId: 'combined',
data: {
a: head.key.name,
},
node: head,
fix (fixer) {
return [
fixer.replaceText(head.value, `"${attrGroup.map(a => a.value.value).join(" ")}"`),
...tail.map(a => fixer.remove(a))
]
},
})
})
},
VAttribute (attr) {
if (
attr.directive &&
Expand Down
5 changes: 5 additions & 0 deletions tests/rules/no-deprecated-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,10 @@ tester.run('no-deprecated-props', rule, {
output: '<template><v-snackbar :class="`elevation-${variable}`" class="foo" /></template>',
errors: [{ messageId: 'replacedWith' }],
},
{
code: '<template><v-menu location="bottom" location="left" /></template>',
output: '<template><v-menu location="bottom left" /></template>',
errors: [{ messageId: 'combined' }],
},
],
})

0 comments on commit 5636517

Please sign in to comment.