Skip to content

Rule proposal: Incorrect binding to a directive that already binds to expression #328

Closed
@Phlow2001

Description

@Phlow2001

Please describe what the rule should do:

I have come across this error in code several times now. We use ':' on attributes so often that sometimes we don't realize that we've done it on well-known directives.

<input :v-model="field">

Instead of binding field to the model, it renders a v-model attribute on the html element.

I think it makes sense to error about this for the following well-known directives accepting expressions: v-text, v-html, v-show, v-if, v-else, v-else-if, v-for, v-on, v-bind, v-model

What category of rule is this? (place an "X" next to just one item)

[ ] Enforces code style
[X] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

<!-- ✘ BAD -->
<input :v-model="foo">
<input :v-if="foo">

<!-- ✓ GOOD -->
<input v-model="foo">
<input v-if="foo">

Why should this rule be included in ESLint (instead of a plugin)?
Because it's a very easy mistake to make, has very few use-cases to allow it, and can eliminate a class of bugs in templates.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions