Skip to content
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: add noLabelWithoutControl rule #2987

Merged
merged 19 commits into from
May 30, 2024

Conversation

michellocana
Copy link
Contributor

Summary

Implementation of the label-has-associated-control rule from eslint-plugin-jsx-a11y in Biome.
Closes #2610

Valid

// Associated control + text content
<label for="js_id" aria-label="A label" />;
<label for="js_id" aria-labelledby="A label" />;
<label htmlFor="js_id" aria-label="A label" />;
<label htmlFor="js_id" aria-labelledby="A label" />;

// Nested control + text content
<label>A label<input /></label>;
<label>A label<textarea /></label>;
<label><img alt="A label" /><input /></label>;

Invalid

// Missing text content
<label for="js_id" />;
<label for="js_id"><input /></label>;
<label htmlFor="js_id" />;
<label htmlFor="js_id"><input /></label>;

// Missing associated control
<label>A label</label>;

// Missing text content + associated control
<div><label /><input /></div>;

Test Plan

Added snapshots, for valid and invalid cases according to the original rule tests.

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels May 26, 2024
@michellocana michellocana force-pushed the feat/no-label-without-control branch 2 times, most recently from 387b9c9 to db234a3 Compare May 26, 2024 01:24
Copy link

codspeed-hq bot commented May 26, 2024

CodSpeed Performance Report

Merging #2987 will not alter performance

Comparing michellocana:feat/no-label-without-control (4101fea) with main (4ed208a)

Summary

✅ 92 untouched benchmarks

@michellocana michellocana force-pushed the feat/no-label-without-control branch 2 times, most recently from 287c204 to 63fc953 Compare May 28, 2024 14:25
@michellocana michellocana requested a review from ematipico May 28, 2024 19:44
@michellocana michellocana force-pushed the feat/no-label-without-control branch from 0a94209 to 5ee008b Compare May 28, 2024 20:25
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Almost there! We just need to create the arrays statically, all of them, and then we can merge the PR

Comment on lines 123 to 126
let default_label_attributes = &["aria-label", "alt"];
let default_label_components = &["label"];
let default_input_components =
&["input", "meter", "output", "progress", "select", "textarea"];
Copy link
Member

@ematipico ematipico May 29, 2024

Choose a reason for hiding this comment

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

You're creating the same array every time you run the rule. This isn't very efficient. Create a static array instead, for example:

const  DEFAULT_LABEL_ATTIRBUTES: &[&str; 2] = &["aria-label", "alt"];

You'll have to place at the top level of the file, for example

pub const BUILTIN: &[&str; 67] = &[

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 catch, done!

@michellocana michellocana force-pushed the feat/no-label-without-control branch from 5ee008b to f0664d6 Compare May 29, 2024 15:38
@ematipico ematipico merged commit 9a7d790 into biomejs:main May 30, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 Implement noLabelWithoutControl - jsx-a11y/label-has-associated-control
2 participants