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

Fix #1808: Lint slots in attribute-hyphenation #1826

Merged
merged 3 commits into from Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion docs/rules/attribute-hyphenation.md
Expand Up @@ -5,6 +5,7 @@ title: vue/attribute-hyphenation
description: enforce attribute naming style on custom components in template
since: v3.9.0
---

# vue/attribute-hyphenation

> enforce attribute naming style on custom components in template
Expand Down Expand Up @@ -35,7 +36,7 @@ This rule enforces using hyphenated attribute names on custom components in Vue
```json
{
"vue/attribute-hyphenation": ["error", "always" | "never", {
"ignore": []
"ignore": [],
}]
doug-wade marked this conversation as resolved.
Show resolved Hide resolved
}
```
Expand Down
6 changes: 5 additions & 1 deletion lib/rules/attribute-hyphenation.js
Expand Up @@ -106,7 +106,11 @@ module.exports = {

return utils.defineTemplateBodyVisitor(context, {
VAttribute(node) {
if (!utils.isCustomComponent(node.parent.parent)) return
if (
!utils.isCustomComponent(node.parent.parent) &&
node.parent.parent.name !== 'slot'
)
return

const name = !node.directive
? node.key.rawName
Expand Down
36 changes: 36 additions & 0 deletions tests/lib/rules/attribute-hyphenation.js
Expand Up @@ -56,6 +56,16 @@ ruleTester.run('attribute-hyphenation', rule, {
filename: 'test.vue',
code: '<template><my-component :[foo-bar]></my-component></template>',
options: ['never']
},
{
filename: 'test.vue',
code: '<template><div><slot my-prop></slot></div></template>',
options: ['always']
},
{
filename: 'test.vue',
code: '<template><div><slot myProp></slot></div></template>',
options: ['never']
}
],

Expand Down Expand Up @@ -252,6 +262,32 @@ ruleTester.run('attribute-hyphenation', rule, {
line: 3
}
]
},
{
filename: 'test.vue',
code: '<template><div><slot my-prop="foo"></slot></div></template>',
output: '<template><div><slot myProp="foo"></slot></div></template>',
options: ['never'],
errors: [
{
message: "Attribute 'my-prop' can't be hyphenated.",
type: 'VIdentifier',
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><slot MyProp="Bar"></slot></div></template>',
output: '<template><div><slot my-prop="Bar"></slot></div></template>',
options: ['always'],
errors: [
{
message: "Attribute 'MyProp' must be hyphenated.",
type: 'VIdentifier',
line: 1
}
]
}
]
})