Skip to content

feat: add vue/prefer-emits-arrow-function rule - #3288

Open
Pra-j wants to merge 1 commit into
vuejs:masterfrom
Pra-j:feat/1787-prefer-emits-arrow-function
Open

Pra-j wants to merge 1 commit into
vuejs:masterfrom
Pra-j:feat/1787-prefer-emits-arrow-function

Conversation

@Pra-j

@Pra-j Pra-j commented Nov 28, 2026

Copy link
Copy Markdown

Closes #1787

Adds the vue/prefer-emits-arrow-function rule as discussed in the issue.

Emits validators written as regular functions or methods break the type inference of the emits option in TypeScript (vuejs/core#5343), so the rule reports them. Arrow functions and functions with an explicit this: undefined parameter are allowed.

Fixing works the way it was described in the issue:

  • If there's no type information (not a TS file / lang="ts" block and no type annotations on the function), it autofixes the validator to an arrow function.
  • Otherwise it doesn't autofix and offers two suggestions instead: convert to an arrow function, or add this: undefined (or change the existing this type to undefined).

Validators that use this, arguments, super or new.target, generators and named function expressions are still reported but not converted, since that could change their behavior.

A couple of things I wasn't sure about:

  • I only check the emits component option, not defineEmits() in <script setup>, since the issue is about defineComponent inference. Happy to add it if you think it makes sense.
  • this parameters with a type other than undefined (e.g. this: void) are reported, following the spec in the thread.

Tests cover plain objects, defineComponent, Vue.component, .vue files with and without lang="ts", and .ts files. Docs and a changeset are included.

@changeset-bot

changeset-bot Bot commented Nov 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ca782ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-vue Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Rule Proposal: Validate "emits" section

1 participant