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
Add new rule no-action-on-submit-button
#1931
Add new rule no-action-on-submit-button
#1931
Conversation
13d8239
to
0b8a1c6
Compare
0b8a1c6
to
bd1fecf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also check if the parent form
already has an action defined and if so, assume that the action on the submit button is an arbitrary event? E.g. for tracking purposes. Or would this be to far-fetched?
b425d07
to
0bbe945
Compare
no-action-on-submit-button
@JoaoDsv there are conflicts. Is this close to being ready to merge? |
I fixed the conflicts, tests, and many (but not all) of the comments. There's another comment here that may need to be addressed still: #44 (comment) |
If we need to check if the button has a |
@JoaoDsv if you'd like to finish this PR up, let us know. Otherwise, I think @bertdeblock and I will try to finish it up. @bertdeblock, I'll give you access to push updates to this PR, so we can finish addressing comments including reducing false positives and improving consistency. |
To be clear, I do think we should address this comment to reduce false positives: #44 (comment) I'm not going to work on this now so @bertdeblock you can take over if you're interested. |
Thanks for your feedbacks @bmish @bertdeblock ! Feel free to commit at any time to help me to get this PR merged, it will be very welcome 🙂 |
87a9cba
to
b5c8db8
Compare
I addressed the remaining feedbacks ✅ Except reducing the false positives by checking the presence a parent |
<button type="button" {{on "click" this.handleClick}} /> | ||
<button type="button" {{action "handleClick"}} /> | ||
<button type="submit" /> | ||
<button /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be disallowed by the require-button-type
rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment @MelSumner. Sure, but aren't rules independent from each other?
My point is: should we take an other rule into account in the unit test of this current rule?
If users decide to disable the require-button-type
rule, then this syntax will be allowed by the current rule, because it's not its role to prevent the missing type.
What is your opinion about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I try to write new rules with existing rules in mind; I don't want a rule I create to fail another existing rule.
But @rwjblue might have some more clarity here.
(PS overall I am excited about this rule!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @MelSumner
I'm back at work on this rule, which I'd forgotten for a long time 🙇
This rule is not encouraging <button />
without (explicit) type. It's essentially a syntax that won't make this rule fail, so I listed it in the "valid" scenarios.
Would you prefer me to remove <button />
from these scenarios?
- The downside is that this scenario won't be clearly mentioned while likely to happen.
- The advantage is that it won't encourage people using this syntax (not allowed by
require-button-type
dedicated rule)
37683f8
to
dd3636c
Compare
45ad1b9
to
c0ebc5e
Compare
c0ebc5e
to
b859cd5
Compare
Looks good except we still need the parent |
a9928e7
to
df8cafc
Compare
df8cafc
to
40e3f64
Compare
a834abb
to
e2eade7
Compare
@JoaoDsv thanks for your continued work on this. Let us know when it's ready (with my last comment addressed). |
0aa3b13
to
24567e2
Compare
I have belatedly addressed your request about the parent ℹ️ Nicely spotted, as this also seems to solve @rwjblue's related concern: #44 (comment). Would you mind having a last review and if everything looks ready, approve it? |
'<button type="submit" {{on "click" (fn this.addNumber 123)}} />', | ||
], | ||
|
||
bad: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we add a test for a deeply-nested button like this to make sure we aren't only checking the direct parent?
<form><div><button {{action this.handleClick}} /></div></form>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I added it as last scenario ✅
d7d063b
to
270e109
Compare
@JoaoDsv just to confirm, we should enable this as |
I'd indeed suggest to:
By doing so, we additionally have some time to implement a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, thanks for your work to get this finished!
Fixes #44.
It implements the rule proposal of
no-action-on-submit-button
.no-action-on-submit-button
This rule requires all
<button>
elements with atype="submit"
attribute to not have any action.When the
type
attribute of<button>
elements issubmit
, the action should be on the<form>
element instead of directly on the button.By default, the
type
attribute of<button>
elements issubmit
.Examples
This rule forbids the following:
This rule allows the following: