@@ -5,8 +5,8 @@ use biome_aria_metadata::AriaRole;
55use biome_console:: markup;
66use biome_deserialize:: TextRange ;
77use biome_diagnostics:: Severity ;
8- use biome_js_syntax:: { JsxAttribute , JsxOpeningElement } ;
9- use biome_rowan:: AstNode ;
8+ use biome_js_syntax:: { JsxAttribute , JsxOpeningElement , JsxSelfClosingElement } ;
9+ use biome_rowan:: { AstNode , declare_node_union } ;
1010use biome_rule_options:: use_semantic_elements:: UseSemanticElementsOptions ;
1111
1212declare_lint_rule ! {
@@ -27,6 +27,14 @@ declare_lint_rule! {
2727 /// <div role="separator"></div>
2828 /// ```
2929 ///
30+ /// ```jsx,expect_diagnostic
31+ /// <div role="checkbox" />
32+ /// ```
33+ ///
34+ /// ```jsx,expect_diagnostic
35+ /// <div role="separator" />
36+ /// ```
37+ ///
3038 /// ### Valid
3139 ///
3240 /// ```jsx
@@ -53,15 +61,24 @@ declare_lint_rule! {
5361 }
5462}
5563
64+ declare_node_union ! {
65+ pub AnyOpeningElement = JsxOpeningElement | JsxSelfClosingElement
66+ }
67+
5668impl Rule for UseSemanticElements {
57- type Query = Ast < JsxOpeningElement > ;
69+ type Query = Ast < AnyOpeningElement > ;
5870 type State = JsxAttribute ;
5971 type Signals = Option < Self :: State > ;
6072 type Options = UseSemanticElementsOptions ;
6173
6274 fn run ( ctx : & RuleContext < Self > ) -> Self :: Signals {
6375 let node = ctx. query ( ) ;
64- let role_attribute = node. find_attribute_by_name ( "role" ) ?;
76+ let role_attribute = match node {
77+ AnyOpeningElement :: JsxOpeningElement ( node) => node. find_attribute_by_name ( "role" ) ?,
78+ AnyOpeningElement :: JsxSelfClosingElement ( node) => {
79+ node. find_attribute_by_name ( "role" ) ?
80+ }
81+ } ;
6582 let role_value = role_attribute. as_static_value ( ) ?;
6683 let role_value = role_value. as_string_constant ( ) ?;
6784
0 commit comments