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

fix(lint/a11y/use_button_type): skip the rule with spread attribute #2249

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Fix [#2211](https://github.com/biomejs/biome/issues/2211). noChildrenProp should work fine when children pass as a prop in a new line. Contributed by @fireairforce

- Fix [#2248](https://github.com/biomejs/biome/issues/2248). `lint/a11y/useButtonType` should not trigger when button element with spread attribute. Contributed by @fireairforce

#### Enhancements

- Add support for object property members in the rule `useSortedClasses`. Contributed by @ematipico
Expand Down
32 changes: 24 additions & 8 deletions crates/biome_js_analyze/src/lint/a11y/use_button_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,18 @@ impl Rule for UseButtonType {
}
let type_attribute = element.find_attribute_by_name("type").ok()?;
let Some(attribute) = type_attribute else {
return Some(UseButtonTypeState {
range: element.range(),
missing_prop: true,
});
let has_spread_prop = element
.attributes()
.into_iter()
.any(|attr| attr.as_jsx_spread_attribute().is_some());
if has_spread_prop {
return None;
} else {
return Some(UseButtonTypeState {
range: element.range(),
missing_prop: true,
});
}
};
inspect_jsx_type_attribute(&attribute)
}
Expand All @@ -85,10 +93,18 @@ impl Rule for UseButtonType {
}
let type_attribute = element.find_attribute_by_name("type").ok()?;
let Some(attribute) = type_attribute else {
return Some(UseButtonTypeState {
range: element.range(),
missing_prop: true,
});
let has_spread_prop = element
.attributes()
.into_iter()
.any(|attr| attr.as_jsx_spread_attribute().is_some());
if has_spread_prop {
return None;
} else {
return Some(UseButtonTypeState {
range: element.range(),
missing_prop: true,
});
}
};
inspect_jsx_type_attribute(&attribute)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
<button type={dynamic_value}>do something</button>
<button type="button"/>
<button type={dynamic_value}/>
<button {...props}></button>
</>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ expression: inJsx.jsx
<button type={dynamic_value}>do something</button>
<button type="button"/>
<button type={dynamic_value}/>
<button {...props}></button>
</>
```

Expand Down Expand Up @@ -178,5 +179,3 @@ inJsx.jsx:10:5 lint/a11y/useButtonType ━━━━━━━━━━━━━


```


2 changes: 2 additions & 0 deletions website/src/content/docs/internals/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Fix [#2211](https://github.com/biomejs/biome/issues/2211). noChildrenProp should work fine when children pass as a prop in a new line. Contributed by @fireairforce

- Fix [#2248](https://github.com/biomejs/biome/issues/2248). `lint/a11y/useButtonType` should not trigger when button element with spread attribute. Contributed by @fireairforce

#### Enhancements

- Add support for object property members in the rule `useSortedClasses`. Contributed by @ematipico
Expand Down