Skip to content

[Fixes #238] Don't report dynamic types on inputs with v-model directive #242

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
Nov 24, 2017
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
1 change: 0 additions & 1 deletion docs/rules/valid-v-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ This rule reports `v-model` directives in the following cases:
- The directive does not have that attribute value. E.g. `<input v-model>`
- The directive does not have the attribute value which is valid as LHS. E.g. `<input v-model="foo() + bar()">`
- The directive is on unsupported elements. E.g. `<div v-model="foo"></div>`
- The directive is on `<input>` elements which their types are dynamic. E.g. `<input :type="type" v-model="foo">`
- The directive is on `<input>` elements which their types are `file`. E.g. `<input type="file" v-model="foo">`
- The directive's reference is iteration variables. E.g. `<div v-for="x in list"><input type="file" v-model="x"></div>`

Expand Down
25 changes: 8 additions & 17 deletions lib/rules/valid-v-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,14 @@ function create (context) {
data: { name }
})
}
if (name === 'input') {
if (utils.hasDirective(element, 'bind', 'type')) {
context.report({
node,
loc: node.loc,
message: "'v-model' directives don't support dynamic input types.",
data: { name }
})
}
if (utils.hasAttribute(element, 'type', 'file')) {
context.report({
node,
loc: node.loc,
message: "'v-model' directives don't support 'file' input type.",
data: { name }
})
}

if (name === 'input' && utils.hasAttribute(element, 'type', 'file')) {
context.report({
node,
loc: node.loc,
message: "'v-model' directives don't support 'file' input type.",
data: { name }
})
}

if (node.key.argument) {
Expand Down
18 changes: 8 additions & 10 deletions tests/lib/rules/valid-v-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ tester.run('valid-v-model', rule, {
{
filename: 'test.vue',
code: '<template><div><div v-for="x in list"><input v-model="x.foo"></div></div></template>'
},
{
filename: 'test.vue',
code: '<template><input :type="a" v-model="b"></template>'
},
{
filename: 'test.vue',
code: '<template><input v-bind:type="a" v-model="b"></template>'
}
],
invalid: [
Expand Down Expand Up @@ -94,16 +102,6 @@ tester.run('valid-v-model', rule, {
code: '<template><input v-model="a + b"></template>',
errors: ["'v-model' directives require the attribute value which is valid as LHS."]
},
{
filename: 'test.vue',
code: '<template><input :type="a" v-model="b"></template>',
errors: ["'v-model' directives don't support dynamic input types."]
},
{
filename: 'test.vue',
code: '<template><input v-bind:type="a" v-model="b"></template>',
errors: ["'v-model' directives don't support dynamic input types."]
},
{
filename: 'test.vue',
code: '<template><input type="file" v-model="b"></template>',
Expand Down