jsx-eslint / eslint-plugin-jsx-a11y

Static AST checker for a11y rules on JSX elements.
MIT License
3.42k stars 637 forks source link

[Fix]: `label-has-associated-control`: ignore undetermined label text #1004

Closed BillyLevin closed 3 months ago

BillyLevin commented 3 months ago

Attempt to fix #966

The rule no longer errors if the existence of label text cannot be determined. The criteria for not being able to determine whether the text exists are, for each child of the label:

  1. It is a React component
  2. It has no children
  3. It is not registered as a control component. Unfortunately this means it would still error if the control component itself displays text, but I didn't see a way around that

I don't think this accounts for every case, but hopefully a good starting point

I followed the convention already used by making the new parameters for mayHaveAccessibleLabel optional, even though they're not. I assume that was to make it easier to write the unit tests. Happy to change that though if you'd like

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.03%. Comparing base (a08fbcc) to head (a08fbcc).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1004 +/- ## ======================================= Coverage 99.03% 99.03% ======================================= Files 107 107 Lines 1660 1660 Branches 588 588 ======================================= Hits 1644 1644 Misses 16 16 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.