-
-
Notifications
You must be signed in to change notification settings - Fork 640
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
feat(label-has-associated-control): add option for enforcing label's htmlFor matches control's id #1042
base: main
Are you sure you want to change the base?
Conversation
c5c7649
to
789d368
Compare
…htmlFor matches control's id This change adds an option to the `label-has-associated-control` rule, enforcing that the label's htmlFor attribute matches the associated control's id attribute. Previously, the only validation done on htmlFor was that it was on the label component and had text. There was no attempt to cross-check that value against any attribute on the associated control. Not, when the option is enabled, cases where they don't match will report. I also took the opportunity to update the error messages so that each assert type gets an error message with verbiage specific to the assertion. (not sure if this should be called out as a separate feature in the changelog?). Note: the current implementation only checks the first instance it finds of child component that matches each control component type. It assumes that there won't be any acceptable cases where a label would have multiple inputs nested beneath it. Let me know if that assumption doesn't hold. Closes:
789d368
to
0f1845a
Compare
type: 'JSXClosingFragment', | ||
}; | ||
|
||
export type JSXFragment = JSXElement & { |
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.
It would have been better to use Omit
here to remove openingElement
and closingElement
from JSXElement
, but this version of flow doesn't have Omit
(that was introduced in 0.211.0). I'd be up for upgrading the version of flow in a separate change if you'd like?
type: 'JSXClosingFragment', | ||
}; | ||
|
||
export type JSXFragment = JSXElement & { |
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.
The ast-types-flow
package doesn't include a type for JSXFragment
label-has-associated-control
): add option for enforcing label's htmlFor matches control's id
label-has-associated-control
): add option for enforcing label's htmlFor matches control's id
This change adds an option to the
label-has-associated-control
rule, enforcing that the label's htmlFor attribute matches the associated control's id attribute. Previously, the only validation done on htmlFor was that it was on the label component and had text. There was no attempt to cross-check that value against any attribute on the associated control. Not, when the option is enabled, cases where they don't match will report.I also took the opportunity to update the error messages so that each assert type gets an error message with verbiage specific to the assertion. (not sure if this should be called out as a separate feature in the changelog?).
Note: the current implementation only checks the first instance it finds of a child component that matches each control component type. It assumes that there won't be any acceptable cases where a label would have multiple inputs nested beneath it. Let me know if that assumption doesn't hold and i can refine that logic more.
Closes: #956