Skip to content
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

Enforce style of passing an event or part of an event to a method #1611

Closed
leonheess opened this issue Aug 16, 2021 · 9 comments
Closed

Enforce style of passing an event or part of an event to a method #1611

leonheess opened this issue Aug 16, 2021 · 9 comments

Comments

@leonheess
Copy link

Please describe what the rule should do:
In Vue you can use test($event.detail) as well as event => test(event.detail) to achieve the same thing. 1. should be preferred.

  1. test($event.detail)
<Component
  @click="test($event.detail)"
/>
  1. event => test(event.detail)
<Component
  @click="event => test(event.detail)"
/>

What category should the rule belong to?
[X] Enforces code style (layout)
[ ] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

<Component
  @click="event => test(event.detail)"
/>
<Component
  @click="({ detail }) => test(detail)"
/>
@ota-meshi
Copy link
Member

Thank you for the rule proposal!
I think it would be even better if the options allowed the user to choose the style they prefer.

@FloEdelmann
Copy link
Member

Instead of a separate rule, it could maybe be a new option for vue/v-on-function-call.

@FloEdelmann
Copy link
Member

This was implemented as the new vue/v-on-handler-style rule in #2009.

@leonheess
Copy link
Author

leonheess commented May 17, 2023

Doesn't seem to work:

'vue/v-on-handler-style': ['error', ['method', 'inline']]

image

image

@ota-meshi
Copy link
Member

I think you should use the following option:

'vue/v-on-handler-style': ['error', 'inline']

https://eslint.vuejs.org/rules/v-on-handler-style.html#inline

@leonheess
Copy link
Author

leonheess commented May 17, 2023

@ota-meshi But then it will complain about @click="function" which is preferred if no arguments are needed 😞

@ota-meshi
Copy link
Member

I'm not sure. I thought you prefer the inline format. Isn't it?

@leonheess
Copy link
Author

@ota-meshi I want it to be as short as possible so if no parentheses are needed, none should be used.

@ota-meshi
Copy link
Member

I'm not sure which style you prefer. Could you please open a new issue as a feature request for the v-on-handler-style rule and detail your preferred style?

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

No branches or pull requests

3 participants