From 01309e8c837bf1147ac8a29cb185065bd331f3fc Mon Sep 17 00:00:00 2001 From: Vasu Singh Date: Tue, 28 Nov 2023 16:34:04 +0530 Subject: [PATCH] fix(lint/noSvgWithoutTitle): skip on aria-hidden (#928) --- .../src/analyzers/a11y/no_svg_without_title.rs | 9 +++++++++ .../tests/specs/a11y/noSvgWithoutTitle/valid.jsx | 8 ++++++++ .../tests/specs/a11y/noSvgWithoutTitle/valid.jsx.snap | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/crates/biome_js_analyze/src/analyzers/a11y/no_svg_without_title.rs b/crates/biome_js_analyze/src/analyzers/a11y/no_svg_without_title.rs index 0ecdf0cefff4..b263986a981d 100644 --- a/crates/biome_js_analyze/src/analyzers/a11y/no_svg_without_title.rs +++ b/crates/biome_js_analyze/src/analyzers/a11y/no_svg_without_title.rs @@ -99,6 +99,15 @@ impl Rule for NoSvgWithoutTitle { return None; } + if let Some(aria_hidden_attr) = node.find_attribute_by_name("aria-hidden") { + if let Some(attr_static_val) = aria_hidden_attr.as_static_value() { + let attr_text = attr_static_val.text(); + if attr_text == "true" { + return None; + } + } + } + // Checks if a `svg` element has a valid `title` element is in a childlist let jsx_element = node.parent::()?; if let AnyJsxElement::JsxOpeningElement(_) = node { diff --git a/crates/biome_js_analyze/tests/specs/a11y/noSvgWithoutTitle/valid.jsx b/crates/biome_js_analyze/tests/specs/a11y/noSvgWithoutTitle/valid.jsx index f9975cf3b859..cc0f97b5edc9 100644 --- a/crates/biome_js_analyze/tests/specs/a11y/noSvgWithoutTitle/valid.jsx +++ b/crates/biome_js_analyze/tests/specs/a11y/noSvgWithoutTitle/valid.jsx @@ -37,4 +37,12 @@ implicit role Pass + + ; diff --git a/crates/biome_js_analyze/tests/specs/a11y/noSvgWithoutTitle/valid.jsx.snap b/crates/biome_js_analyze/tests/specs/a11y/noSvgWithoutTitle/valid.jsx.snap index 0cdbf0578c18..bcb89892fd00 100644 --- a/crates/biome_js_analyze/tests/specs/a11y/noSvgWithoutTitle/valid.jsx.snap +++ b/crates/biome_js_analyze/tests/specs/a11y/noSvgWithoutTitle/valid.jsx.snap @@ -43,6 +43,14 @@ expression: valid.jsx implicit role Pass + + ; ```