Skip to content
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

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

Open
2 tasks done
petrkotek opened this issue Apr 24, 2024 · 2 comments
Open
2 tasks done

Comments

@petrkotek
Copy link

petrkotek commented Apr 24, 2024

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 8.57.0
  • eslint-plugin-vue version: 9.25.0
  • Vue version: 3.4.23
  • Node version: v20.11.1
  • Operating System: macOS 12.7.4 (21H1123)

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
Copy link
Author

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
Copy link
Author

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)

@petrkotek petrkotek reopened this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant