Skip to content

Commit 3952e01

Browse files
committed
fix(linter): false negative in jsx-a11y/aria-role (oxc-project#11547)
1 parent b0e3e08 commit 3952e01

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

crates/oxc_linter/src/rules/jsx_a11y/aria_role.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ impl Rule for AriaRole {
164164
Some(JSXAttributeValue::StringLiteral(str)) => {
165165
let words_str = String::from(str.value.as_str());
166166
let words = words_str.split_whitespace();
167-
if let Some(error_prop) = words.into_iter().find(|word| {
167+
if words_str.trim().is_empty() {
168+
ctx.diagnostic(aria_role_diagnostic(str.span, ""));
169+
} else if let Some(error_prop) = words.into_iter().find(|word| {
168170
!VALID_ARIA_ROLES.contains(word)
169171
&& !self.allowed_invalid_roles.contains(&(*word).to_string())
170172
}) {
@@ -237,7 +239,7 @@ fn test() {
237239
("<div role='datepicker'></div>", None, None),
238240
("<div role='range'></div>", None, None),
239241
("<div role='Button'></div>", None, None),
240-
("<div role='></div>", None, None),
242+
("<div role=''></div>", None, None),
241243
("<div role='tabpanel row foobar'></div>", None, None),
242244
("<div role='tabpanel row range'></div>", None, None),
243245
("<div role='doc-endnotes range'></div>", None, None),

crates/oxc_linter/src/snapshots/jsx_a11y_aria_role.snap

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ source: crates/oxc_linter/src/tester.rs
2929
╰────
3030
help: Set a valid, non-abstract ARIA role for element with ARIA, `Button` is an invalid aria role
3131

32-
× Unterminated string
32+
eslint-plugin-jsx-a11y(aria-role): Elements with ARIA roles must use a valid, non-abstract ARIA role.
3333
╭─[aria_role.tsx:1:11]
34-
1<div role='></div>
35-
· ────────
34+
1<div role=''></div>
35+
· ──
3636
╰────
37+
help: Set a valid, non-abstract ARIA role for element with ARIA
3738

3839
eslint-plugin-jsx-a11y(aria-role): Elements with ARIA roles must use a valid, non-abstract ARIA role.
3940
╭─[aria_role.tsx:1:11]

0 commit comments

Comments
 (0)