vuejs / eslint-plugin-vue

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

vue/use-v-on-exact - false positive on multiple @keydown.* attributes #2455

Open petrkotek opened 6 months ago

petrkotek commented 6 months ago

Checklist

Tell us about your environment

Please show your full configuration:

/* eslint-env node */
module.exports = {
  root: true,
  'extends': [
    'plugin:vue/vue3-essential',
    'eslint:recommended'
  ],
  parserOptions: {
    ecmaVersion: 'latest'
  }
}

What did you do?

<script lang="ts">
export default {
  methods: {
    save(): void {}
  }
}
</script>

<template>
  <!-- OK -->
  <input @keydown.ctrl.enter.exact="save()" />
  <!-- OK -->
  <input @keydown.stop />
  <!-- ERROR - Fails with vue/use-v-on-exact -> Consider to use '.exact' modifier on the @keydown.stop line -->
  <input
    @keydown.ctrl.enter.exact="save()"
    @keydown.stop
  />
</template>

What did you expect to happen? I expected that @keydown.stop is OK to use and doesn't need .exact modifier.

What actually happened?

vue/use-v-on-exact returned an error that .exact should be used - on the @keydown.stop line.

$ npm run lint

> vue-project@0.0.0 lint
> eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore

/<redacted>/bugreports/vue-project/src/components/HelloWorld.vue
  17:5  error  Consider to use '.exact' modifier  vue/use-v-on-exact

✖ 1 problem (1 error, 0 warnings)

Repository to reproduce this issue https://github.com/petrkotek/bugreports (See https://github.com/petrkotek/bugreports/blob/main/vue-project/src/components/HelloWorld.vue)

petrkotek commented 6 months ago

Looking at the tests (https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/use-v-on-exact.js), this may be the correct behaviour. I'll look into this a bit more and potentially reopen this.

petrkotek commented 6 months ago

Turns out that:

  <input
    @keydown.ctrl.enter.exact="save()"
    @keydown.stop.exact
  />

passes the lint & works fine, however, feels like @keydown.stop shouldn't need the .exact (since I want to stop propagation of all keys, .exact seems confusing).

If somebody has some thoughts around this / best practices recommendations, I'd appreciate it!

(But certainly don't want to waste anyones time)

FloEdelmann commented 3 months ago

That does sound like a bug. PR welcome to fix this!