eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

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

Open leonheess opened this issue 4 years ago • 2 comments

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)"
/>

leonheess avatar Aug 16 '21 12:08 leonheess

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.

ota-meshi avatar Sep 17 '21 07:09 ota-meshi

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

FloEdelmann avatar Nov 04 '21 18:11 FloEdelmann

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

FloEdelmann avatar May 16 '23 15:05 FloEdelmann

Doesn't seem to work:

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

image

image

leonheess avatar May 17 '23 00:05 leonheess

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

ota-meshi avatar May 17 '23 00:05 ota-meshi

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

leonheess avatar May 17 '23 01:05 leonheess

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

ota-meshi avatar May 17 '23 03:05 ota-meshi

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

leonheess avatar May 22 '23 13:05 leonheess

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?

ota-meshi avatar May 22 '23 13:05 ota-meshi