-
Notifications
You must be signed in to change notification settings - Fork 199
exclude specific input types from react-a11y-input-elements rule #754
exclude specific input types from react-a11y-input-elements rule #754
Conversation
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.
A few structural things to change, but generally a step in the right direction.
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.
Waiting on the variable nit and attribute name check & tests. Otherwise looking good!
if (isEmpty(attributes.value) && isEmpty(attributes.placeholder)) { | ||
const isExcludedInputTypeValueEmpty = isEmpty(attributes.value) && isExcludedInputType(node); | ||
const isPlaceholderEmpty = isEmpty(attributes.placeholder) && !isExcludedInputType(node); | ||
if ((isEmpty(attributes.value) && isPlaceholderEmpty) || isExcludedInputTypeValueEmpty) { | ||
ctx.addFailureAt(node.getStart(), node.getWidth(), MISSING_PLACEHOLDER_INPUT_FAILURE_STRING); |
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.
😬 might this be simplified?
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.
A couple things to try:
- Pass
attributes
intoisExcludedInputType.type
so you don't have to callgetJsxAttributesFromJsxElement
each time - Only make one call to
isExcludedInputType(node)
and store that in a variable, so you don't need to call it twice.
...but the test cases look good, build passes, and this is still a pretty simple rule; I'm fine with merging this in as is & filing a followup issue to look into cleaning it up.
I'll wait for direction from you if you want to tackle it now - totally up to you! 😊
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 call! Dried it up ⬇️
@@ -46,10 +46,10 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
} | |||
} | |||
|
|||
function isExcludedInputType(node: ts.JsxSelfClosingElement): boolean { | |||
function isExcludedInputType(node: ts.JsxSelfClosingElement, attributes: { [propName: string]: ts.JsxAttribute }): boolean { | |||
for (const attribute of node.attributes.properties) { |
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.
got this type from below. Let me know if this looks right to you.
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.
LGTM, thanks @lizzzp1! Exciting how quick this bug was fixed 🙌
…rosoft#754) * exclude specific input types from react-a11y-input-elements rule * feedback - use for of, tsutils for type checks * feedback - add tests for non type attributes with excluded values, clean up boolean * dry things up
PR checklist
react-a11y-input-elements
incorrectly requiring placeholder for radio, checkbox, and file inputs #749Overview of change:
Excludes the 3 input types listed in issue from requiring a placeholder.
Is there anything you'd like reviewers to focus on?