Skip to content

Commit

Permalink
Improved autofix of vue/no-deprecated-slot-attribute rule when slot n…
Browse files Browse the repository at this point in the history
…ame contains `_`. (#1436)
  • Loading branch information
ota-meshi committed Feb 14, 2021
1 parent b978258 commit 4b41399
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/syntaxes/slot-attribute.js
Expand Up @@ -23,8 +23,8 @@ module.exports = {
return true
}
const slotName = slotAttr.value.value
// If non-Latin characters are included it can not be converted.
return !/[^a-z]/i.test(slotName)
// If other than alphanumeric, underscore and hyphen characters are included it can not be converted.
return !/[^\w\-]/u.test(slotName)
}

/**
Expand Down
57 changes: 57 additions & 0 deletions tests/lib/rules/no-deprecated-slot-attribute.js
Expand Up @@ -348,6 +348,63 @@ tester.run('no-deprecated-slot-attribute', rule, {
line: 4
}
]
},
{
code: `
<template>
<MyComponent>
<template slot="foo-bar">
<a/>
</template>
</MyComponent>
</template>`,
output: `
<template>
<MyComponent>
<template v-slot:foo-bar>
<a/>
</template>
</MyComponent>
</template>`,
errors: ['`slot` attributes are deprecated.']
},
{
code: `
<template>
<MyComponent>
<template slot="foo_bar">
<a/>
</template>
</MyComponent>
</template>`,
output: `
<template>
<MyComponent>
<template v-slot:foo_bar>
<a/>
</template>
</MyComponent>
</template>`,
errors: ['`slot` attributes are deprecated.']
},
{
code: `
<template>
<MyComponent>
<template slot="123">
<a/>
</template>
</MyComponent>
</template>`,
output: `
<template>
<MyComponent>
<template v-slot:123>
<a/>
</template>
</MyComponent>
</template>`,
errors: ['`slot` attributes are deprecated.']
}
]
})

0 comments on commit 4b41399

Please sign in to comment.