From ed2473f4fc3353c8f6e17f5a5ffa204aa84e08ae Mon Sep 17 00:00:00 2001 From: Daiki Nishikawa Date: Thu, 4 May 2023 18:19:24 +0900 Subject: [PATCH] refactor(rome_js_analyze): move useIframeTitle from semantic_analyzer to analyzer and refactoring (#4438) * wip * refactor: move useIframeTitle to analyzers * fix: codegen --- crates/rome_js_analyze/src/analyzers/a11y.rs | 3 +- .../src/analyzers/a11y/use_iframe_title.rs | 110 +++++++++++++ .../src/semantic_analyzers/a11y.rs | 3 +- .../a11y/use_iframe_title.rs | 147 ------------------ .../specs/a11y/useIframeTitle/invalid.jsx | 1 - .../a11y/useIframeTitle/invalid.jsx.snap | 65 +++----- .../src/configuration/linter/rules.rs | 2 +- editors/vscode/configuration_schema.json | 2 +- npm/backend-jsonrpc/src/workspace.ts | 2 +- npm/rome/configuration_schema.json | 2 +- website/src/pages/lint/rules/index.mdx | 2 +- .../src/pages/lint/rules/useIframeTitle.md | 96 +++++------- 12 files changed, 181 insertions(+), 254 deletions(-) create mode 100644 crates/rome_js_analyze/src/analyzers/a11y/use_iframe_title.rs delete mode 100644 crates/rome_js_analyze/src/semantic_analyzers/a11y/use_iframe_title.rs 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 new file mode 100644 index 00000000000..00308755fb1 --- /dev/null +++ b/crates/rome_js_analyze/src/analyzers/a11y/use_iframe_title.rs @@ -0,0 +1,110 @@ +use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; +use rome_console::markup; +use rome_js_syntax::jsx_ext::AnyJsxElement; +use rome_rowan::AstNode; + +declare_rule! { + /// Enforces the usage of the attribute `title` for the element `iframe`. + /// + /// ## Examples + /// + /// ### Invalid + /// + /// ```jsx,expect_diagnostic + /// + /// ``` + /// + /// ```jsx,expect_diagnostic + /// - /// ``` - /// - /// ```jsx,expect_diagnostic - /// - /// ``` - /// - /// ```jsx,expect_diagnostic - /// + 8 │ - 9 │ - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 9 │ - > 9 │ - 9 │ + ``` -
a11y/useIframeTitle.js:1:5 lint/a11y/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
a11y/useIframeTitle.js:1:1 lint/a11y/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
    Provide a title attribute when using iframe elements.
   
-  > 1 │     <iframe></iframe>
-       ^^^^^^^^
+  > 1 │ <iframe></iframe>
+   ^^^^^^^^
     2 │ 
   
    Screen readers rely on the title set on an iframe to describe the content being displayed.
@@ -46,15 +46,15 @@ Enforces the usage of the attribute `title` for the element `iframe`
 
```jsx - +