Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

exclude specific input types from react-a11y-input-elements rule #754

Merged

Conversation

lizzzp1
Copy link
Contributor

@lizzzp1 lizzzp1 commented Jan 1, 2019

PR checklist

Overview of change:

Excludes the 3 input types listed in issue from requiring a placeholder.

Is there anything you'd like reviewers to focus on?

Copy link

@JoshuaKGoldberg JoshuaKGoldberg left a 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.

src/reactA11yInputElementsRule.ts Outdated Show resolved Hide resolved
src/reactA11yInputElementsRule.ts Outdated Show resolved Hide resolved
src/reactA11yInputElementsRule.ts Outdated Show resolved Hide resolved
src/tests/ReactA11yInputElementsRuleTests.ts Show resolved Hide resolved
Copy link

@JoshuaKGoldberg JoshuaKGoldberg left a 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!

src/reactA11yInputElementsRule.ts Outdated Show resolved Hide resolved
src/tests/ReactA11yInputElementsRuleTests.ts Show resolved Hide resolved
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬 might this be simplified?

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 into isExcludedInputType.type so you don't have to call getJsxAttributesFromJsxElement 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! 😊

Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

Copy link

@JoshuaKGoldberg JoshuaKGoldberg left a 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 🙌

@JoshuaKGoldberg JoshuaKGoldberg merged commit 0519742 into microsoft:master Jan 2, 2019
@IllusionMH IllusionMH added this to the 6.1.0-beta milestone Feb 19, 2019
apawast pushed a commit to lupine86/tslint-microsoft-contrib that referenced this pull request Feb 26, 2019
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule react-a11y-input-elements incorrectly requiring placeholder for radio, checkbox, and file inputs
3 participants