Skip to content

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

Closed
@jacekkarczmarczyk

Description

@jacekkarczmarczyk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions