Skip to content

Commit

Permalink
fix(attribute-hyphenation): apply to v-model directive (#2511)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynzh authored Sep 2, 2024
1 parent 21d3ed8 commit 354c0de
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/attribute-hyphenation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getAttributeName(node) {
}

if (
node.key.name.name === 'bind' &&
(node.key.name.name === 'bind' || node.key.name.name === 'model') &&
node.key.argument &&
node.key.argument.type === 'VIdentifier'
) {
Expand Down
47 changes: 47 additions & 0 deletions tests/lib/rules/attribute-hyphenation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ ruleTester.run('attribute-hyphenation', rule, {
code: '<template><div><custom data-id="foo" aria-test="bar" slot-scope="{ data }" my-prop="prop"></custom></div></template>',
options: ['always']
},
{
filename: 'test.vue',
code: '<template><div><custom :my-prop="prop" v-model:foo-bar="fooBar"></custom></div></template>',
options: ['always']
},
{
filename: 'test.vue',
code: '<template><div><custom data-id="foo" aria-test="bar" slot-scope="{ data }" myProp="prop"></custom></div></template>',
Expand Down Expand Up @@ -219,6 +224,48 @@ ruleTester.run('attribute-hyphenation', rule, {
}
]
},
{
// https://github.com/vuejs/eslint-plugin-vue/issues/2510
filename: 'test.vue',
code: '<template><div><custom v-model:my-prop="prop"></custom></div></template>',
output:
'<template><div><custom v-model:myProp="prop"></custom></div></template>',
options: ['never'],
errors: [
{
message: "Attribute 'v-model:my-prop' can't be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><custom v-model:myProp="prop"></custom></div></template>',
output:
'<template><div><custom v-model:my-prop="prop"></custom></div></template>',
options: ['always'],
errors: [
{
message: "Attribute 'v-model:myProp' must be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
},
{
filename: 'test.vue',
code: '<template><div><custom v-model:MyProp="prop"></custom></div></template>',
output: null,
options: ['always'],
errors: [
{
message: "Attribute 'v-model:MyProp' must be hyphenated.",
type: 'VDirectiveKey',
line: 1
}
]
},
{
filename: 'test.vue',
code: `
Expand Down

0 comments on commit 354c0de

Please sign in to comment.