Skip to content

v-on-function-call autofix can break the code if method has optional arguments #1345

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

Closed
2 tasks done
jacekkarczmarczyk opened this issue Oct 26, 2020 · 0 comments · Fixed by #1369
Closed
2 tasks done
Labels

Comments

@jacekkarczmarczyk
Copy link

jacekkarczmarczyk commented Oct 26, 2020

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: eslint@^7.8.0
  • eslint-plugin-vue version: eslint-plugin-vue@^7.0.0
  • Node version: v12.10.0
  • Operating System: win10

Please show your full configuration:

more or less

module.exports = {
  root: true,
  env: {
    browser: true,
    es6: true,
    node: true,
    jest: true,
  },
  parserOptions: {
    sourceType: 'module',
    parser: '@typescript-eslint/parser',
  },
  extends: [
    'standard',
    'plugin:@typescript-eslint/recommended',
    'plugin:sonarjs/recommended',
    'plugin:vue/recommended',
    '@vue/typescript/recommended',
  ],
  plugins: [
    'html',
    'node',
    'sort-destructure-keys',
    '@typescript-eslint',
    'vue',
  ],
};

What did you do?

<template>
  <div @onclick="foo()" />
</template>
<script>
export default {
  methods: {
    foo(optional = undefined) {
    }
  }
}
</script>

What did you expect to happen?
Code should not be changed to

<div @onclick="foo" />

What actually happened?
Applied autofix changed the semantics and broke the code (originally foo is called with undefined, after autofix it's called with event)

EDIT: similar situation would be if you don't declare method arguments but use arguments variable, with foo() arguments[0] would be undefined, with foo arguments[0] would be an event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants