Skip to content

vue/valid-define-emits treats validator payload as local variable and fails #1651

Closed
@larvanitis

Description

@larvanitis

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: 7.32.0
  • eslint-plugin-vue version: 7.19.0
  • Node version: 14.17.4
  • *Operating System: Arch Linux

Please show your full configuration:

module.exports = {
  root: true,

  parserOptions: {
    parser: '@babel/eslint-parser',
    ecmaVersion: 2018,
    sourceType: 'module',
  },

  env: {
    browser: true,
  },

  extends: ['plugin:vue/vue3-recommended', 'prettier'],

  plugins: ['vue'],

  globals: {
    ga: 'readonly',
    cordova: 'readonly',
    __statics: 'readonly',
    __QUASAR_SSR__: 'readonly',
    __QUASAR_SSR_SERVER__: 'readonly',
    __QUASAR_SSR_CLIENT__: 'readonly',
    __QUASAR_SSR_PWA__: 'readonly',
    process: 'readonly',
    Capacitor: 'readonly',
    chrome: 'readonly',
  },

  rules: {
    'prefer-promise-reject-errors': 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'vue/component-name-in-template-casing': [
      'warn',
      'PascalCase',
      { registeredComponentsOnly: false },
    ],
    'vue/html-button-has-type': 'error',
    'vue/match-component-file-name': 'error',
    'vue/no-boolean-default': ['error', 'default-false'],
    'vue/no-reserved-component-names': [
      'error',
      {
        disallowVueBuiltInComponents: true,
        disallowVue3BuiltInComponents: true,
      },
    ],
    'vue/valid-define-emits': 'error',
    'vue/valid-define-props': 'error',
    'vue/valid-next-tick': 'error',
    'vue/valid-v-memo': 'error',
  },
};

What did you do?
Example from https://v3.vuejs.org/guide/component-custom-events.html#validate-emitted-events

<script setup>
const emits = defineEmits({
  submit: ({ email, password }) => {
    if (email && password) {
      return true;
    } else {
      return false;
    }
  },
});
</script>

What did you expect to happen?
This should work since the docs say:

[...] defineEmits accepts the same value as the emits option.

What actually happened?
I get the following error (cli, IntelliJ, VSCode).

/path/to/TestComponent.vue
  15:14  error  `defineEmits` are referencing locally declared variables  vue/valid-define-emits

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