Skip to content

vue/custom-event-name-casing doesn't flag incorrectly cased emits in the template #2577

Closed
@henribru

Description

@henribru

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: 9.12.0
  • eslint-plugin-vue version: 9.29.0
  • Vue version: 3.5.9
  • Node version: 18.20.4
  • Operating System: Arch Linux

Please show your full configuration:

import pluginVue from 'eslint-plugin-vue'
import vueTsEslintConfig from '@vue/eslint-config-typescript'
import pluginVitest from '@vitest/eslint-plugin'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'

export default [
  {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}'],
  },

  {
    name: 'app/files-to-ignore',
    ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
  },

  ...pluginVue.configs['flat/essential'],
  ...vueTsEslintConfig(),
  
  {
    ...pluginVitest.configs.recommended,
    files: ['src/**/__tests__/*'],
  },
  skipFormatting,
  {
    rules: {
      "vue/custom-event-name-casing": "error"
    }
  }
]

What did you do?

<script setup lang="ts">
const emit = defineEmits({ 'foo-bar': () => true })

emit('foo-bar')
</script>

<template>
  <button @click="emit('foo-bar')">Foo</button>
  <button @click="$emit('foo-bar')">Foo</button>
</template>

What did you expect to happen?
ESLint should flag all three emits because they all use kebab case instead of camelcase.

What actually happened?

It flags the one in script setup and the one using $emit in the template, but not the one using emit.

➜  vue-project npm run lint

> [email protected] lint
> eslint . --fix


/home/.../dev/vue-project/src/components/HelloWorld.vue
  4:6   error  Custom event name 'foo-bar' must be camelCase  vue/custom-event-name-casing
  9:25  error  Custom event name 'foo-bar' must be camelCase  vue/custom-event-name-casing

✖ 2 problems (2 errors, 0 warnings)

Repository to reproduce this issue

https://github.com/henribru/eslint-plugin-vue-custom-event-name-casing-bug

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