diff --git a/crates/rome_js_analyze/src/analyzers/a11y.rs b/crates/rome_js_analyze/src/analyzers/a11y.rs index d6fce6bed1c..d488edb7cf6 100644 --- a/crates/rome_js_analyze/src/analyzers/a11y.rs +++ b/crates/rome_js_analyze/src/analyzers/a11y.rs @@ -11,8 +11,9 @@ mod no_svg_without_title; mod use_alt_text; mod use_anchor_content; mod use_html_lang; +mod use_iframe_title; mod use_key_with_click_events; mod use_key_with_mouse_events; mod use_media_caption; mod use_valid_anchor; -declare_group! { pub (crate) A11y { name : "a11y" , rules : [self :: no_access_key :: NoAccessKey , self :: no_auto_focus :: NoAutoFocus , self :: no_blank_target :: NoBlankTarget , self :: no_distracting_elements :: NoDistractingElements , self :: no_header_scope :: NoHeaderScope , self :: no_redundant_alt :: NoRedundantAlt , self :: no_svg_without_title :: NoSvgWithoutTitle , self :: use_alt_text :: UseAltText , self :: use_anchor_content :: UseAnchorContent , self :: use_html_lang :: UseHtmlLang , self :: use_key_with_click_events :: UseKeyWithClickEvents , self :: use_key_with_mouse_events :: UseKeyWithMouseEvents , self :: use_media_caption :: UseMediaCaption , self :: use_valid_anchor :: UseValidAnchor ,] } } +declare_group! { pub (crate) A11y { name : "a11y" , rules : [self :: no_access_key :: NoAccessKey , self :: no_auto_focus :: NoAutoFocus , self :: no_blank_target :: NoBlankTarget , self :: no_distracting_elements :: NoDistractingElements , self :: no_header_scope :: NoHeaderScope , self :: no_redundant_alt :: NoRedundantAlt , self :: no_svg_without_title :: NoSvgWithoutTitle , self :: use_alt_text :: UseAltText , self :: use_anchor_content :: UseAnchorContent , self :: use_html_lang :: UseHtmlLang , self :: use_iframe_title :: UseIframeTitle , self :: use_key_with_click_events :: UseKeyWithClickEvents , self :: use_key_with_mouse_events :: UseKeyWithMouseEvents , self :: use_media_caption :: UseMediaCaption , self :: use_valid_anchor :: UseValidAnchor ,] } } diff --git a/crates/rome_js_analyze/src/analyzers/a11y/use_iframe_title.rs b/crates/rome_js_analyze/src/analyzers/a11y/use_iframe_title.rs index ca79f20eae8..00308755fb1 100644 --- a/crates/rome_js_analyze/src/analyzers/a11y/use_iframe_title.rs +++ b/crates/rome_js_analyze/src/analyzers/a11y/use_iframe_title.rs @@ -1,7 +1,7 @@ use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; use rome_console::markup; -use rome_js_syntax::{jsx_ext::AnyJsxElement, AnyJsExpression, AnyJsxAttributeValue}; -use rome_rowan::{AstNode, AstNodeList}; +use rome_js_syntax::jsx_ext::AnyJsxElement; +use rome_rowan::AstNode; declare_rule! { /// Enforces the usage of the attribute `title` for the element `iframe`. @@ -72,10 +72,21 @@ impl Rule for UseIframeTitle { type Options = (); fn run(ctx: &RuleContext) -> Self::Signals { - let node = ctx.query(); + let element = ctx.query(); + let name = element.name().ok()?.name_value_token()?; - if node.name_value_token()?.text_trimmed() == "iframe" && has_valid_title(element) { - return Some(()); + if name.text_trimmed() == "iframe" { + if let Some(lang_attribute) = element.find_attribute_by_name("title") { + if !lang_attribute + .as_static_value() + .map_or(true, |attribute| attribute.is_not_string_constant("")) + && !element.has_trailing_spread_prop(lang_attribute) + { + return Some(()); + } + } else if !element.has_spread_prop() { + return Some(()); + } } None @@ -97,17 +108,3 @@ impl Rule for UseIframeTitle { ) } } - -fn has_valid_title(element: &AnyJsxElement) -> bool { - element - .find_attribute_by_name("title") - .map_or(false, |attribute| { - if attribute.initializer().is_none() { - return false; - } - - attribute.as_static_value().map_or(true, |value| { - !value.is_null_or_undefined() && value.is_not_string_constant("") - }) && !element.has_trailing_spread_prop(attribute) - }) -} diff --git a/crates/rome_js_analyze/tests/specs/a11y/useIframeTitle/invalid.jsx b/crates/rome_js_analyze/tests/specs/a11y/useIframeTitle/invalid.jsx index 013a27257af..16691ecc46f 100644 --- a/crates/rome_js_analyze/tests/specs/a11y/useIframeTitle/invalid.jsx +++ b/crates/rome_js_analyze/tests/specs/a11y/useIframeTitle/invalid.jsx @@ -5,7 +5,6 @@ + 8 │ - 9 │ - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 9 │ - > 9 │ - 9 │