-
-
Notifications
You must be signed in to change notification settings - Fork 682
edit v-on-function-call
to enforce @click="() => fn()"
over @click="fn()"
and @click="fn"
#2001
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
Comments
@click="() => fn()"
over @click="fn()"
and @click="fn"
v-on-function-call
to enforce @click="() => fn()"
over @click="fn()"
and @click="fn"
Thank you for requesting to add the rule. <button @click="fn" />
<button @click="fn()" /> It seems that rules already exist to check for these. <button @click="fn" />
<button @click="() => fn()" /> I don't think a rule exists yet to check for these. <MyComponent :callback="fn" />
<MyComponent :callback="() => fn()" /> |
@ota-meshi thank you for your comment. I feel like it's best that we only keep this rule focused on Eg. <button
:type="calculateType()"
@click="() => onClick()"
/> in this case I'd want ESLint to make sure that my So I feel it's better to pass a third option to
OR via a new option
Finally, (but this can be a separate issue) Can anyone can think of any other PROs to the first two versions over the third version as described in my original post? |
I agree with @mesqueeb, I don't think checking props is a good idea. Another CON for the $emit('my-event', 'foo', 'bar');
<my-button @my-event="fn" />; // `fn` will be called with both parameters
<my-button @my-event="fn($event)" />; // `fn` will be called with the `foo` parameter only
<my-button @my-event="(foo, bar) => fn(foo, bar)" />; // `fn` will be called with both parameters Although that may also be seen as an advantage, because one has to comply to that style, i.e. only pass one event parameter everywhere. A clear PRO for the |
Thank you for your opinion. I think you are right. It seems I didn't give it enough thought. I think adding options to existing rule is a good idea. However, I'm not sure if <button @click="fn" />
<button @click="fn()" />
<button @click="() => fn()" /> I think we need to use options with arrays to allow multiples. "vue/v-on-function-call": [
"error",
["never", "arrow-function"] // : ("always"|"never"|"arrow-function")[]
] What do you think? |
Yes i think this rule syntax looks good! 🙌🏼 |
Makes sense. To be backwards-compatible, a single option should still be accepted. |
I've started implementing this option, but am worried about enforcing the following style. <button @click="count++" /> <!-- "always" style -->
<button @click="() => count++" /> <!-- "arrow-function" style --> I think the new option should report on these stylistic differences as well, but I feel like it's doing more than the rule name. What do you think? |
Yes, the rule should also check stylistic differences, the old rule name doesn't really convey that. Also, I like that the suggested options |
https://eslint.vuejs.org/rules/v-on-function-call.html#vue-v-on-function-call
I want to have a new option for
v-on-function-call
to enforce a 3rd way of writing that is not yet enforcable. My reasoning is very sound I believe bet let me elaborate:Please describe what the rule should do:
There are 3 ways in Vue to pass an event listener in HTML:
To me there are clear PROs for using the last way and only CONs for using the first two. This is why I want to enforce this style with a new rule.
Here is my reasoning:
fn
if any.fn
doesn't accept a payload, but will still receive one because of this way of writingfn
is used somewhere else with a payload, but passed here as well, but it will end up receivingPointerEvent | MouseEvent
implicitly which can cause bugs that are hard to find because it's implicitfn
, if anyWhat 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:
I believe the explanation above is clear enough but let me know if it doesn't
The text was updated successfully, but these errors were encountered: