Skip to content

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

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rules/syntaxes/slot-attribute.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.']
}
]
})