From d99bf3cb2ec89232c63abb34c541c52695eec4cf Mon Sep 17 00:00:00 2001 From: unvalley Date: Sat, 17 Dec 2022 23:55:06 +0900 Subject: [PATCH 1/7] parent 5f1144170e12e78a3e7b32201dc917bff808f47b author unvalley 1671288906 +0900 committer unvalley 1671554652 +0900 feat(rome_js_analyze): useIframeTitle docs: website chore: delete waste file refactor: remove waste node declaration chore: add configurations refactor: remove missing_prop and edit message --- .../src/categories.rs | 7 + .../rome_js_analyze/src/analyzers/nursery.rs | 10 + .../src/semantic_analyzers/nursery.rs | 3 +- .../nursery/use_iframe_title.rs | 150 +++++++++++++++ .../specs/nursery/useIframeTitle/invalid.jsx | 13 ++ .../nursery/useIframeTitle/invalid.jsx.snap | 174 ++++++++++++++++++ .../specs/nursery/useIframeTitle/valid.jsx | 5 + .../nursery/useIframeTitle/valid.jsx.snap | 15 ++ .../src/configuration/linter/rules.rs | 22 +++ editors/vscode/configuration_schema.json | 5 + npm/backend-jsonrpc/src/workspace.ts | 13 ++ npm/rome/configuration_schema.json | 5 + website/src/pages/lint/rules/index.mdx | 7 + .../src/pages/lint/rules/useIframeTitle.md | 153 +++++++++++++++ 14 files changed, 581 insertions(+), 1 deletion(-) create mode 100644 crates/rome_js_analyze/src/semantic_analyzers/nursery/use_iframe_title.rs create mode 100644 crates/rome_js_analyze/tests/specs/nursery/useIframeTitle/invalid.jsx create mode 100644 crates/rome_js_analyze/tests/specs/nursery/useIframeTitle/invalid.jsx.snap create mode 100644 crates/rome_js_analyze/tests/specs/nursery/useIframeTitle/valid.jsx create mode 100644 crates/rome_js_analyze/tests/specs/nursery/useIframeTitle/valid.jsx.snap create mode 100644 website/src/pages/lint/rules/useIframeTitle.md diff --git a/crates/rome_diagnostics_categories/src/categories.rs b/crates/rome_diagnostics_categories/src/categories.rs index 6f39aedbe44..d86ffb4ed82 100644 --- a/crates/rome_diagnostics_categories/src/categories.rs +++ b/crates/rome_diagnostics_categories/src/categories.rs @@ -80,8 +80,15 @@ define_dategories! { "lint/nursery/useEnumInitializers":"https://docs.rome.tools/lint/rules/useEnumInitializers", "lint/nursery/useExhaustiveDependencies": "https://docs.rome.tools/lint/rules/useExhaustiveDependencies", "lint/nursery/useExponentiationOperator": "https://docs.rome.tools/lint/rules/useExponentiationOperator", +<<<<<<< HEAD "lint/nursery/useIsNan": "https://docs.rome.tools/lint/rules/useIsNan", +<<<<<<< HEAD "lint/nursery/useMediaCaption": "https://docs.rome.tools/lint/rules/useMediaCaption", +======= +======= + "lint/nursery/useIframeTitle": "https://docs.rome.tools/lint/rules/useIframeTitle", +>>>>>>> 3b85ef65dd (feat(rome_js_analyze): useIframeTitle) +>>>>>>> 37232c45fa (parent 5f1144170e12e78a3e7b32201dc917bff808f47b) "lint/nursery/useNumericLiterals": "https://docs.rome.tools/lint/rules/useNumericLiterals", "lint/nursery/useValidForDirection": "https://docs.rome.tools/lint/rules/useValidForDirection", "lint/nursery/useHookAtTopLevel": "https://docs.rome.tools/lint/rules/useHookAtTopLevel", diff --git a/crates/rome_js_analyze/src/analyzers/nursery.rs b/crates/rome_js_analyze/src/analyzers/nursery.rs index 68ec39eac96..bf42600ef83 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery.rs @@ -30,7 +30,17 @@ mod use_default_parameter_last; mod use_default_switch_clause_last; mod use_enum_initializers; mod use_exponentiation_operator; +<<<<<<< HEAD mod use_is_nan; mod use_media_caption; mod use_numeric_literals; +<<<<<<< HEAD declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_access_key :: NoAccessKey , self :: no_assign_in_expressions :: NoAssignInExpressions , self :: no_banned_types :: NoBannedTypes , self :: no_comma_operator :: NoCommaOperator , self :: no_const_enum :: NoConstEnum , self :: no_constructor_return :: NoConstructorReturn , self :: no_distracting_elements :: NoDistractingElements , self :: no_duplicate_case :: NoDuplicateCase , self :: no_duplicate_object_keys :: NoDuplicateObjectKeys , self :: no_empty_interface :: NoEmptyInterface , self :: no_extra_non_null_assertion :: NoExtraNonNullAssertion , self :: no_extra_semicolons :: NoExtraSemicolons , self :: no_header_scope :: NoHeaderScope , self :: no_invalid_constructor_super :: NoInvalidConstructorSuper , self :: no_non_null_assertion :: NoNonNullAssertion , self :: no_precision_loss :: NoPrecisionLoss , self :: no_redundant_alt :: NoRedundantAlt , self :: no_redundant_use_strict :: NoRedundantUseStrict , self :: no_self_compare :: NoSelfCompare , self :: no_setter_return :: NoSetterReturn , self :: no_string_case_mismatch :: NoStringCaseMismatch , self :: no_unsafe_finally :: NoUnsafeFinally , self :: no_useless_switch_case :: NoUselessSwitchCase , self :: no_void_type_return :: NoVoidTypeReturn , self :: no_with :: NoWith , self :: use_default_parameter_last :: UseDefaultParameterLast , self :: use_default_switch_clause_last :: UseDefaultSwitchClauseLast , self :: use_enum_initializers :: UseEnumInitializers , self :: use_exponentiation_operator :: UseExponentiationOperator , self :: use_is_nan :: UseIsNan , self :: use_media_caption :: UseMediaCaption , self :: use_numeric_literals :: UseNumericLiterals ,] } } +======= +declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_access_key :: NoAccessKey , self :: no_assign_in_expressions :: NoAssignInExpressions , self :: no_banned_types :: NoBannedTypes , self :: no_comma_operator :: NoCommaOperator , self :: no_const_enum :: NoConstEnum , self :: no_constructor_return :: NoConstructorReturn , self :: no_distracting_elements :: NoDistractingElements , self :: no_duplicate_case :: NoDuplicateCase , self :: no_duplicate_object_keys :: NoDuplicateObjectKeys , self :: no_empty_interface :: NoEmptyInterface , self :: no_extra_non_null_assertion :: NoExtraNonNullAssertion , self :: no_extra_semicolons :: NoExtraSemicolons , self :: no_header_scope :: NoHeaderScope , self :: no_invalid_constructor_super :: NoInvalidConstructorSuper , self :: no_non_null_assertion :: NoNonNullAssertion , self :: no_precision_loss :: NoPrecisionLoss , self :: no_redundant_alt :: NoRedundantAlt , self :: no_redundant_use_strict :: NoRedundantUseStrict , self :: no_self_compare :: NoSelfCompare , self :: no_setter_return :: NoSetterReturn , self :: no_string_case_mismatch :: NoStringCaseMismatch , self :: no_unsafe_finally :: NoUnsafeFinally , self :: no_useless_switch_case :: NoUselessSwitchCase , self :: no_void_type_return :: NoVoidTypeReturn , self :: no_with :: NoWith , self :: use_default_parameter_last :: UseDefaultParameterLast , self :: use_default_switch_clause_last :: UseDefaultSwitchClauseLast , self :: use_enum_initializers :: UseEnumInitializers , self :: use_exponentiation_operator :: UseExponentiationOperator , self :: use_is_nan :: UseIsNan , self :: use_numeric_literals :: UseNumericLiterals ,] } } +======= +mod use_iframe_title; +mod use_numeric_literals; +declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_access_key :: NoAccessKey , self :: no_assign_in_expressions :: NoAssignInExpressions , self :: no_banned_types :: NoBannedTypes , self :: no_comma_operator :: NoCommaOperator , self :: no_const_enum :: NoConstEnum , self :: no_constructor_return :: NoConstructorReturn , self :: no_distracting_elements :: NoDistractingElements , self :: no_duplicate_case :: NoDuplicateCase , self :: no_duplicate_object_keys :: NoDuplicateObjectKeys , self :: no_empty_interface :: NoEmptyInterface , self :: no_extra_non_null_assertion :: NoExtraNonNullAssertion , self :: no_extra_semicolons :: NoExtraSemicolons , self :: no_header_scope :: NoHeaderScope , self :: no_invalid_constructor_super :: NoInvalidConstructorSuper , self :: no_non_null_assertion :: NoNonNullAssertion , self :: no_precision_loss :: NoPrecisionLoss , self :: no_redundant_alt :: NoRedundantAlt , self :: no_redundant_use_strict :: NoRedundantUseStrict , self :: no_self_compare :: NoSelfCompare , self :: no_setter_return :: NoSetterReturn , self :: no_string_case_mismatch :: NoStringCaseMismatch , self :: no_unsafe_finally :: NoUnsafeFinally , self :: no_useless_switch_case :: NoUselessSwitchCase , self :: no_void_type_return :: NoVoidTypeReturn , self :: no_with :: NoWith , self :: use_default_parameter_last :: UseDefaultParameterLast , self :: use_default_switch_clause_last :: UseDefaultSwitchClauseLast , self :: use_enum_initializers :: UseEnumInitializers , self :: use_exponentiation_operator :: UseExponentiationOperator , self :: use_iframe_title :: UseIframeTitle , self :: use_numeric_literals :: UseNumericLiterals ,] } } +>>>>>>> 3b85ef65dd (feat(rome_js_analyze): useIframeTitle) +>>>>>>> 37232c45fa (parent 5f1144170e12e78a3e7b32201dc917bff808f47b) diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery.rs index 853f29d4933..c9a8446e775 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery.rs @@ -8,4 +8,5 @@ mod use_camel_case; mod use_const; mod use_exhaustive_dependencies; mod use_hook_at_top_level; -declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_class_assign :: NoClassAssign , self :: no_restricted_globals :: NoRestrictedGlobals , self :: no_var :: NoVar , self :: use_camel_case :: UseCamelCase , self :: use_const :: UseConst , self :: use_exhaustive_dependencies :: UseExhaustiveDependencies , self :: use_hook_at_top_level :: UseHookAtTopLevel ,] } } +mod use_iframe_title; +declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_class_assign :: NoClassAssign , self :: no_restricted_globals :: NoRestrictedGlobals , self :: no_var :: NoVar , self :: use_camel_case :: UseCamelCase , self :: use_const :: UseConst , self :: use_exhaustive_dependencies :: UseExhaustiveDependencies , self :: use_hook_at_top_level :: UseHookAtTopLevel , self :: use_iframe_title :: UseIframeTitle ,] } } diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_iframe_title.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_iframe_title.rs new file mode 100644 index 00000000000..93bddbdeb48 --- /dev/null +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_iframe_title.rs @@ -0,0 +1,150 @@ +use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; +use rome_console::markup; +use rome_js_syntax::{jsx_ext::AnyJsxElement, AnyJsExpression}; +use rome_rowan::{AstNode, AstNodeList}; + +declare_rule! { + /// Enforces the usage of the attribute `title` for the element `iframe` + /// + /// ## Examples + /// + /// ### Invalid + /// + /// ```jsx,expect_diagnostic + /// + /// ``` + /// + /// ```jsx,expect_diagnostic + /// + /// ``` + /// + /// ```jsx,expect_diagnostic + /// + + + 5 │ + │ ^^^^^^^^ + 5 │ + > 5 │ + 5 │ +``` + +
nursery/useIframeTitle.js:1:5 lint/nursery/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Provide an explicit title prop for the iframe element.
+  
+  > 1 │     <iframe></iframe>
+       ^^^^^^^^
+    2 │ 
+  
+
+ +```jsx + 5 │ @@ -63,13 +68,15 @@ invalid.jsx:5:2 lint/nursery/useIframeTitle ━━━━━━━━━━━━ 6 │ 5 │ + + i Screen readers rely on the title set on an iframe to describe the content being displayed. ``` @@ -99,14 +110,16 @@ invalid.jsx:7:2 lint/nursery/useIframeTitle ━━━━━━━━━━━━ ``` invalid.jsx:8:2 lint/nursery/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - ! Provide a valid title prop for the iframe element. + ! Provide a title attribute when using iframe elements. 6 │ + 10 │ + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 10 │ + > 10 │ + 10 │ +``` + +
nursery/useIframeTitle.js:1:5 lint/nursery/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   Provide a title attribute when using iframe elements.
+  
+  > 1 │     <iframe title={<span className={"token string"}></span>}></iframe>
+       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    2 │ 
+  
+   Screen readers rely on the title set on an iframe to describe the content being displayed.
+  
 
```jsx @@ -87,12 +113,14 @@ Enforces the usage of the attribute `title` for the element `iframe`
nursery/useIframeTitle.js:1:5 lint/nursery/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Provide a valid title prop for the iframe element.
+   Provide a title attribute when using iframe elements.
   
   > 1 │     <iframe title={undefined} />
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
+   Screen readers rely on the title set on an iframe to describe the content being displayed.
+  
 
```jsx @@ -101,12 +129,14 @@ Enforces the usage of the attribute `title` for the element `iframe`
nursery/useIframeTitle.js:1:5 lint/nursery/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Provide a valid title prop for the iframe element.
+   Provide a title attribute when using iframe elements.
   
   > 1 │     <iframe title={false} />
        ^^^^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
+   Screen readers rely on the title set on an iframe to describe the content being displayed.
+  
 
```jsx @@ -115,12 +145,14 @@ Enforces the usage of the attribute `title` for the element `iframe`
nursery/useIframeTitle.js:1:5 lint/nursery/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Provide a valid title prop for the iframe element.
+   Provide a title attribute when using iframe elements.
   
   > 1 │     <iframe title={true} />
        ^^^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
+   Screen readers rely on the title set on an iframe to describe the content being displayed.
+  
 
```jsx @@ -129,12 +161,14 @@ Enforces the usage of the attribute `title` for the element `iframe`
nursery/useIframeTitle.js:1:5 lint/nursery/useIframeTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
-   Provide a valid title prop for the iframe element.
+   Provide a title attribute when using iframe elements.
   
   > 1 │     <iframe title={42} />
        ^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
+   Screen readers rely on the title set on an iframe to describe the content being displayed.
+  
 
### Valid From fb63872bfe93beaa4ebe5314f0414a234fc1c148 Mon Sep 17 00:00:00 2001 From: unvalley Date: Sun, 18 Dec 2022 02:01:09 +0900 Subject: [PATCH 3/7] refactor: comment --- .../src/semantic_analyzers/nursery/use_iframe_title.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_iframe_title.rs b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_iframe_title.rs index 93bddbdeb48..76eab6dc843 100644 --- a/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_iframe_title.rs +++ b/crates/rome_js_analyze/src/semantic_analyzers/nursery/use_iframe_title.rs @@ -108,7 +108,7 @@ impl Rule for UseIframeTitle { None } None => { - // the title attribute is not a string (boolean, number, function, identifier...) + // the title attribute is not a string let expression = attribute_value .as_jsx_expression_attribute_value()? .expression() @@ -119,7 +119,7 @@ impl Rule for UseIframeTitle { if text.text_trimmed() == "undefined" || text.text_trimmed() == "null" { return Some(UseIframeTitleState { node: node.clone() }); } else { - // assuems identifier is a string type + // we assueme the identifier is a string type return None; } } @@ -128,7 +128,7 @@ impl Rule for UseIframeTitle { } } } else { - // the iframe has some attributes but no `title` attribute. e.g. - - - 5 │ │ ^^^^^^^^ - 5 │ - > 5 │ - 5 │ i Screen readers rely on the title set on an iframe to describe the content being displayed. @@ -95,12 +94,12 @@ invalid.jsx:7:2 lint/nursery/useIframeTitle ━━━━━━━━━━━━ ! Provide a title attribute when using iframe elements. - 5 │ + 8 │ + 9 │ - 10 │ + 6 │ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 10 │ - > 10 │ + > 9 │ - 10 │ + 9 │