Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved autofix of vue/no-deprecated-slot-attribute rule when slot name contains _. #1436

Merged
merged 1 commit into from Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.']
}
]
})