From d088b7c5e1efb5eb2c0ded31a073465a2b2c3bf5 Mon Sep 17 00:00:00 2001 From: zoomdong <1344492820@qq.com> Date: Sun, 31 Mar 2024 22:01:23 +0800 Subject: [PATCH] fix(lint/a11y/use_button_type): skip the rule with spread attribute --- CHANGELOG.md | 2 ++ .../src/lint/a11y/use_button_type.rs | 32 ++++++++++++++----- .../tests/specs/a11y/useButtonType/inJsx.jsx | 1 + .../specs/a11y/useButtonType/inJsx.jsx.snap | 3 +- .../src/content/docs/internals/changelog.md | 2 ++ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2048a813fe6..a60e0815cddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/crates/biome_js_analyze/src/lint/a11y/use_button_type.rs b/crates/biome_js_analyze/src/lint/a11y/use_button_type.rs index d3cbefe6ed5c..dcb5b1886073 100644 --- a/crates/biome_js_analyze/src/lint/a11y/use_button_type.rs +++ b/crates/biome_js_analyze/src/lint/a11y/use_button_type.rs @@ -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) } @@ -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) } diff --git a/crates/biome_js_analyze/tests/specs/a11y/useButtonType/inJsx.jsx b/crates/biome_js_analyze/tests/specs/a11y/useButtonType/inJsx.jsx index ab50d9cb3561..0424287baaab 100644 --- a/crates/biome_js_analyze/tests/specs/a11y/useButtonType/inJsx.jsx +++ b/crates/biome_js_analyze/tests/specs/a11y/useButtonType/inJsx.jsx @@ -17,4 +17,5 @@ \ No newline at end of file diff --git a/crates/biome_js_analyze/tests/specs/a11y/useButtonType/inJsx.jsx.snap b/crates/biome_js_analyze/tests/specs/a11y/useButtonType/inJsx.jsx.snap index 3661ce65a52e..48f456b3ae2a 100644 --- a/crates/biome_js_analyze/tests/specs/a11y/useButtonType/inJsx.jsx.snap +++ b/crates/biome_js_analyze/tests/specs/a11y/useButtonType/inJsx.jsx.snap @@ -23,6 +23,7 @@ expression: inJsx.jsx ``` @@ -178,5 +179,3 @@ inJsx.jsx:10:5 lint/a11y/useButtonType ━━━━━━━━━━━━━ ``` - - diff --git a/website/src/content/docs/internals/changelog.md b/website/src/content/docs/internals/changelog.md index c471b624f4fb..ffdb344125e6 100644 --- a/website/src/content/docs/internals/changelog.md +++ b/website/src/content/docs/internals/changelog.md @@ -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