vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.41k stars 659 forks source link

vue/valid-v-on errors on working code #2251

Open KaelWD opened 11 months ago

KaelWD commented 11 months ago

Checklist

Tell us about your environment

Please show your full configuration:

extends: ["plugin:vue/vue3-essential"],
rules: {
    "vue/multi-word-component-names": "off",
    "vue/no-dupe-keys": "off",
    "vue/no-unused-components": "off",
    "vue/no-v-model-argument": "off",
    "vue/valid-v-model": "off",
    "vue/valid-v-slot": ["error", {
        "allowModifiers": true
    }],
}

What did you do?

<v-text-field
    ref="textFieldRef"
    :model-value="masked"
    @update:model-value=""
/>

What did you expect to happen? Nothing

What actually happened?

5:9  error  'v-on' directives require a value or verb modifier (like 'stop' or 'prevent')  vue/valid-v-on

Repository to reproduce this issue

This is simple enough I don't think it needs one. @update:model-value should be an error because vue doesn't like it either, but @update:model-value="" actually works fine and just throws an eslint warning for no reason.

FloEdelmann commented 11 months ago

Why do you want to use @update:model-value=""? It doesn't do anything, does it?

KaelWD commented 11 months ago

It does whatever the component wants it to do, in this case it stops the input from keeping its own internal state. This is pretty common with other components too, like <v-list-item @click="" /> adds a hover effect.

When you do this props.onClick is just an empty function () => {}

FloEdelmann commented 11 months ago

I'm not sure whether it should be allowed as a default. But I can see your use case. What do you think about an allowEmpty: true parameter (false by default)?

KaelWD commented 11 months ago

I don't really like how many configuration flags this plugin has added over time, most of which have somewhat puzzling defaults. If the intention of this rule is to prevent errors then empty events should be allowed, because they either do nothing or are intentional. If the intention is to prevent mistakes then it should still be allowed by default because sometimes it isn't a mistake.