Skip to content

Commit 1955fb5

Browse files
committed
feat(RFC0011): add support for custom modifiers in valid-v-model used on Vue component
1 parent 8c861d3 commit 1955fb5

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

docs/rules/valid-v-model.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This rule checks whether every `v-model` directive is valid.
1616
This rule reports `v-model` directives in the following cases:
1717

1818
- The directive used on HTMLElement has an argument. E.g. `<input v-model:aaa="foo">`
19-
- The directive has the modifiers which are not supported. E.g. `<input v-model.bbb="foo">`
19+
- The directive used on HTMLElement has modifiers which are not supported. E.g. `<input v-model.bbb="foo">`
2020
- The directive does not have that attribute value. E.g. `<input v-model>`
2121
- The directive does not have the attribute value which is valid as LHS. E.g. `<input v-model="foo() + bar()">`
2222
- The directive is on unsupported elements. E.g. `<div v-model="foo"></div>`
@@ -33,6 +33,8 @@ This rule reports `v-model` directives in the following cases:
3333
<textarea v-model="foo"/>
3434
<MyComponent v-model="foo"/>
3535
<MyComponent v-model:propName="foo"/>
36+
<MyComponent v-model.modifier="foo"/>
37+
<MyComponent v-model:propName.modifier="foo"/>
3638
<div v-for="todo in todos">
3739
<input v-model="todo.name">
3840
</div>

lib/rules/valid-v-model.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,27 @@ module.exports = {
112112
})
113113
}
114114

115-
if (node.key.argument && !utils.isCustomComponent(element)) {
116-
context.report({
117-
node,
118-
loc: node.loc,
119-
message: "'v-model' directives require no argument."
120-
})
121-
}
122-
123-
for (const modifier of node.key.modifiers) {
124-
if (!VALID_MODIFIERS.has(modifier.name)) {
115+
if (!utils.isCustomComponent(element)) {
116+
if (node.key.argument) {
125117
context.report({
126118
node,
127119
loc: node.loc,
128-
message: "'v-model' directives don't support the modifier '{{name}}'.",
129-
data: { name: modifier.name }
120+
message: "'v-model' directives require no argument."
130121
})
131122
}
123+
124+
for (const modifier of node.key.modifiers) {
125+
if (!VALID_MODIFIERS.has(modifier.name)) {
126+
context.report({
127+
node,
128+
loc: node.loc,
129+
message: "'v-model' directives don't support the modifier '{{name}}'.",
130+
data: { name: modifier.name }
131+
})
132+
}
133+
}
132134
}
135+
133136
if (!utils.hasAttributeValue(node)) {
134137
context.report({
135138
node,

tests/lib/rules/valid-v-model.js

+16
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ tester.run('valid-v-model', rule, {
118118
{
119119
filename: 'test.vue',
120120
code: '<template><MyComponent v-model:aaa="a"></MyComponent></template>'
121+
},
122+
{
123+
filename: 'test.vue',
124+
code: '<template><MyComponent v-model:aaa.modifier="a"></MyComponent></template>'
125+
},
126+
{
127+
filename: 'test.vue',
128+
code: '<template><MyComponent v-model.modifier="a"></MyComponent></template>'
129+
},
130+
{
131+
filename: 'test.vue',
132+
code: '<template><MyComponent v-model:aaa.modifier.modifierTwo="a"></MyComponent></template>'
133+
},
134+
{
135+
filename: 'test.vue',
136+
code: '<template><MyComponent v-model.modifier.modifierTwo="a"></MyComponent></template>'
121137
}
122138
],
123139
invalid: [

0 commit comments

Comments
 (0)