From cb1438e1da99682244d580e61993794c45b73855 Mon Sep 17 00:00:00 2001 From: vasu Date: Sun, 8 Oct 2023 02:39:49 +0530 Subject: [PATCH 1/5] refactor(linter): UseAnchorContent code action --- .../src/analyzers/a11y/use_anchor_content.rs | 33 ++++++++- .../a11y/useAnchorContent/invalid.jsx.snap | 72 ++++++++++++++++++- .../docs/linter/rules/use-anchor-content.md | 36 +++++++++- 3 files changed, 137 insertions(+), 4 deletions(-) diff --git a/crates/biome_js_analyze/src/analyzers/a11y/use_anchor_content.rs b/crates/biome_js_analyze/src/analyzers/a11y/use_anchor_content.rs index ca443277793f..9cd9a4380ba6 100644 --- a/crates/biome_js_analyze/src/analyzers/a11y/use_anchor_content.rs +++ b/crates/biome_js_analyze/src/analyzers/a11y/use_anchor_content.rs @@ -1,9 +1,12 @@ use biome_analyze::context::RuleContext; -use biome_analyze::{declare_rule, Ast, Rule, RuleDiagnostic}; +use biome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic}; use biome_console::markup; +use biome_diagnostics::Applicability; use biome_js_syntax::jsx_ext::AnyJsxElement; use biome_js_syntax::JsxElement; -use biome_rowan::AstNode; +use biome_rowan::{AstNode, BatchMutationExt}; + +use crate::JsRuleAction; declare_rule! { /// Enforce that anchors have content and that the content is accessible to screen readers. @@ -117,8 +120,34 @@ impl Rule for UseAnchorContent { markup! { "All links on a page should have content that is accessible to screen readers." } + ).note( + markup! { + "Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies." + } + ).note( + markup! { + "Follow the links for more information,\n ""WCAG 2.4.4""\n ""WCAG 4.1.2""" + } )) } + + fn action(ctx: &RuleContext, _: &Self::State) -> Option { + let node = ctx.query(); + let mut mutation = ctx.root().begin(); + + if node.has_truthy_attribute("aria-hidden") { + let aria_hidden = node.find_attribute_by_name("aria-hidden")?; + mutation.remove_node(aria_hidden); + + return Some(JsRuleAction { + category: ActionCategory::QuickFix, + applicability: Applicability::MaybeIncorrect, + message: markup! { "Remove the ""aria-hidden"" attribute to allow the anchor element and its content visible to assistive technologies." }.to_owned(), + mutation, + }); + } + None + } } /// check if the node has a valid anchor attribute diff --git a/crates/biome_js_analyze/tests/specs/a11y/useAnchorContent/invalid.jsx.snap b/crates/biome_js_analyze/tests/specs/a11y/useAnchorContent/invalid.jsx.snap index d4b2db3ce728..cd21e6e5636c 100644 --- a/crates/biome_js_analyze/tests/specs/a11y/useAnchorContent/invalid.jsx.snap +++ b/crates/biome_js_analyze/tests/specs/a11y/useAnchorContent/invalid.jsx.snap @@ -34,6 +34,12 @@ invalid.jsx:2:5 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` @@ -51,6 +57,12 @@ invalid.jsx:3:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` @@ -68,6 +80,12 @@ invalid.jsx:4:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` @@ -85,6 +103,12 @@ invalid.jsx:5:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` @@ -102,11 +126,17 @@ invalid.jsx:6:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` ``` -invalid.jsx:7:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.jsx:7:3 lint/a11y/useAnchorContent FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Provide screen reader accessible content when using `a` elements. @@ -119,6 +149,16 @@ invalid.jsx:7:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + + i Unsafe fix: Remove the aria-hidden attribute to allow the anchor element and its content visible to assistive technologies. + + 7 │ → → content + │ ----------- ``` @@ -136,6 +176,12 @@ invalid.jsx:8:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` @@ -153,6 +199,12 @@ invalid.jsx:9:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` @@ -170,6 +222,12 @@ invalid.jsx:10:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` @@ -187,6 +245,12 @@ invalid.jsx:11:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` @@ -204,6 +268,12 @@ invalid.jsx:12:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i All links on a page should have content that is accessible to screen readers. + i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + i Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ``` diff --git a/website/src/content/docs/linter/rules/use-anchor-content.md b/website/src/content/docs/linter/rules/use-anchor-content.md index fca96f88ecc8..fd0158bb07d8 100644 --- a/website/src/content/docs/linter/rules/use-anchor-content.md +++ b/website/src/content/docs/linter/rules/use-anchor-content.md @@ -31,6 +31,12 @@ Refer to the references to learn about why this is important. All links on a page should have content that is accessible to screen readers. + Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ```jsx @@ -47,6 +53,12 @@ Refer to the references to learn about why this is important. All links on a page should have content that is accessible to screen readers. + Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ```jsx @@ -63,13 +75,19 @@ Refer to the references to learn about why this is important. All links on a page should have content that is accessible to screen readers. + Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 + ```jsx content ``` -
a11y/useAnchorContent.js:1:1 lint/a11y/useAnchorContent ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
a11y/useAnchorContent.js:1:1 lint/a11y/useAnchorContent  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
    Provide screen reader accessible content when using `a` elements.
   
@@ -79,6 +97,16 @@ Refer to the references to learn about why this is important.
   
    All links on a page should have content that is accessible to screen readers.
   
+   Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies.
+  
+   Follow the links for more information,
+     WCAG 2.4.4
+     WCAG 4.1.2
+  
+   Unsafe fix: Remove the aria-hidden attribute to allow the anchor element and its content visible to assistive technologies.
+  
+    1 │ <a·aria-hidden>content</a>
+     -----------            
 
```jsx @@ -95,6 +123,12 @@ Refer to the references to learn about why this is important. All links on a page should have content that is accessible to screen readers. + Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. + + Follow the links for more information, + WCAG 2.4.4 + WCAG 4.1.2 +
## Valid From 364f018719141104109671c9865cdbd98d57ae50 Mon Sep 17 00:00:00 2001 From: vasu Date: Sun, 8 Oct 2023 02:44:20 +0530 Subject: [PATCH 2/5] refactor(linter): UseAnchorContent code action --- .../src/analyzers/a11y/use_anchor_content.rs | 2 +- .../a11y/useAnchorContent/invalid.jsx.snap | 22 +++++++++---------- .../docs/linter/rules/use-anchor-content.md | 10 ++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/crates/biome_js_analyze/src/analyzers/a11y/use_anchor_content.rs b/crates/biome_js_analyze/src/analyzers/a11y/use_anchor_content.rs index 9cd9a4380ba6..aa15a86d6ce8 100644 --- a/crates/biome_js_analyze/src/analyzers/a11y/use_anchor_content.rs +++ b/crates/biome_js_analyze/src/analyzers/a11y/use_anchor_content.rs @@ -126,7 +126,7 @@ impl Rule for UseAnchorContent { } ).note( markup! { - "Follow the links for more information,\n ""WCAG 2.4.4""\n ""WCAG 4.1.2""" + "Follow these links for more information,\n ""WCAG 2.4.4""\n ""WCAG 4.1.2""" } )) } diff --git a/crates/biome_js_analyze/tests/specs/a11y/useAnchorContent/invalid.jsx.snap b/crates/biome_js_analyze/tests/specs/a11y/useAnchorContent/invalid.jsx.snap index cd21e6e5636c..00af38ce718b 100644 --- a/crates/biome_js_analyze/tests/specs/a11y/useAnchorContent/invalid.jsx.snap +++ b/crates/biome_js_analyze/tests/specs/a11y/useAnchorContent/invalid.jsx.snap @@ -36,7 +36,7 @@ invalid.jsx:2:5 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -59,7 +59,7 @@ invalid.jsx:3:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -82,7 +82,7 @@ invalid.jsx:4:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -105,7 +105,7 @@ invalid.jsx:5:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -128,7 +128,7 @@ invalid.jsx:6:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -151,7 +151,7 @@ invalid.jsx:7:3 lint/a11y/useAnchorContent FIXABLE ━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -178,7 +178,7 @@ invalid.jsx:8:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -201,7 +201,7 @@ invalid.jsx:9:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -224,7 +224,7 @@ invalid.jsx:10:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -247,7 +247,7 @@ invalid.jsx:11:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -270,7 +270,7 @@ invalid.jsx:12:3 lint/a11y/useAnchorContent ━━━━━━━━━━━━ i Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - i Follow the links for more information, + i Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 diff --git a/website/src/content/docs/linter/rules/use-anchor-content.md b/website/src/content/docs/linter/rules/use-anchor-content.md index fd0158bb07d8..ff08f05eb96c 100644 --- a/website/src/content/docs/linter/rules/use-anchor-content.md +++ b/website/src/content/docs/linter/rules/use-anchor-content.md @@ -33,7 +33,7 @@ Refer to the references to learn about why this is important. Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - Follow the links for more information, + Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -55,7 +55,7 @@ Refer to the references to learn about why this is important. Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - Follow the links for more information, + Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -77,7 +77,7 @@ Refer to the references to learn about why this is important. Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - Follow the links for more information, + Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -99,7 +99,7 @@ Refer to the references to learn about why this is important. Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - Follow the links for more information, + Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 @@ -125,7 +125,7 @@ Refer to the references to learn about why this is important. Accessible content refers to digital content that is designed and structured in a way that makes it easy for people with disabilities to access, understand, and interact with using assistive technologies. - Follow the links for more information, + Follow these links for more information, WCAG 2.4.4 WCAG 4.1.2 From d94d9e1041de5d0336513b52924504867bceedda Mon Sep 17 00:00:00 2001 From: vasu Date: Sun, 8 Oct 2023 03:10:15 +0530 Subject: [PATCH 3/5] refactor(linter): UseAnchorContent code action --- crates/biome_js_unicode_table/src/tables.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/biome_js_unicode_table/src/tables.rs b/crates/biome_js_unicode_table/src/tables.rs index 3ed00b032140..7700038e9f9c 100644 --- a/crates/biome_js_unicode_table/src/tables.rs +++ b/crates/biome_js_unicode_table/src/tables.rs @@ -318,6 +318,7 @@ pub mod derived_property { ('ῠ', 'Ῥ'), ('ῲ', 'ῴ'), ('ῶ', 'ῼ'), + ('\u{200c}', '\u{200d}'), ('‿', '⁀'), ('⁔', '⁔'), ('ⁱ', 'ⁱ'), @@ -362,8 +363,7 @@ pub mod derived_property { ('〸', '〼'), ('ぁ', 'ゖ'), ('\u{3099}', 'ゟ'), - ('ァ', 'ヺ'), - ('ー', 'ヿ'), + ('ァ', 'ヿ'), ('ㄅ', 'ㄯ'), ('ㄱ', 'ㆎ'), ('ㆠ', 'ㆿ'), @@ -441,7 +441,7 @@ pub mod derived_property { ('A', 'Z'), ('_', '_'), ('a', 'z'), - ('ヲ', 'ᄒ'), + ('・', 'ᄒ'), ('ᅡ', 'ᅦ'), ('ᅧ', 'ᅬ'), ('ᅭ', 'ᅲ'), @@ -782,6 +782,7 @@ pub mod derived_property { ('𫝀', '𫠝'), ('𫠠', '𬺡'), ('𬺰', '𮯠'), + ('\u{2ebf0}', '\u{2ee5d}'), ('丽', '𪘀'), ('𰀀', '𱍊'), ('𱍐', '𲎯'), @@ -1447,6 +1448,7 @@ pub mod derived_property { ('𫝀', '𫠝'), ('𫠠', '𬺡'), ('𬺰', '𮯠'), + ('\u{2ebf0}', '\u{2ee5d}'), ('丽', '𪘀'), ('𰀀', '𱍊'), ('𱍐', '𲎯'), From ed8946073e51d2921692bacc148c0e0994648e60 Mon Sep 17 00:00:00 2001 From: vasu Date: Thu, 25 Jan 2024 23:08:29 +0530 Subject: [PATCH 4/5] ignores param destructuring --- CHANGELOG.md | 2 ++ crates/biome_js_analyze/src/lib.rs | 1 - .../no_invalid_use_before_declaration.rs | 17 +++++++++++++++-- .../noInvalidUseBeforeDeclaration/valid.js | 16 ++++++++++++++++ .../noInvalidUseBeforeDeclaration/valid.js.snap | 16 ++++++++++++++++ .../src/content/docs/internals/changelog.mdx | 2 ++ 6 files changed, 51 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b21a710a685..40b70bf92662 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom #### Bug fixes +- Fix [#1648](https://github.com/biomejs/biome/issues/1648). [noInvalidUseBeforeDeclaration](https://biomejs.dev/linter/rules/no-invalid-use-before-declaration/) now ignores when identifier destructured in function params. Contributed by @vasucp1207 + - Fix [#1640](https://github.com/biomejs/biome/issues/1640). [useEnumInitializers](https://biomejs.dev/linter/rules/use-enum-initializers) code action now generates valid code when last member has a comment but no comma. Contributed by @kalleep ### Parser diff --git a/crates/biome_js_analyze/src/lib.rs b/crates/biome_js_analyze/src/lib.rs index fa4530f848d0..fd782e60b0aa 100644 --- a/crates/biome_js_analyze/src/lib.rs +++ b/crates/biome_js_analyze/src/lib.rs @@ -259,7 +259,6 @@ mod tests { dependencies_index: Some(1), }; let rule_filter = RuleFilter::Rule("nursery", "noDisabledTests"); - options.configuration.rules.push_rule( RuleKey::new("nursery", "useHookAtTopLevel"), RuleOptions::new(HooksOptions { hooks: vec![hook] }), diff --git a/crates/biome_js_analyze/src/semantic_analyzers/nursery/no_invalid_use_before_declaration.rs b/crates/biome_js_analyze/src/semantic_analyzers/nursery/no_invalid_use_before_declaration.rs index f7bd8a751dfa..7d7cf4cda80c 100644 --- a/crates/biome_js_analyze/src/semantic_analyzers/nursery/no_invalid_use_before_declaration.rs +++ b/crates/biome_js_analyze/src/semantic_analyzers/nursery/no_invalid_use_before_declaration.rs @@ -2,8 +2,7 @@ use crate::{control_flow::AnyJsControlFlowRoot, semantic_services::SemanticServi use biome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic, RuleSource}; use biome_console::markup; use biome_js_syntax::{ - binding_ext::{AnyJsBindingDeclaration, AnyJsIdentifierBinding}, - AnyJsExportNamedSpecifier, AnyJsIdentifierUsage, + binding_ext::{AnyJsBindingDeclaration, AnyJsIdentifierBinding}, AnyJsExportNamedSpecifier, AnyJsIdentifierUsage, JsObjectBindingPatternShorthandProperty }; use biome_rowan::{AstNode, SyntaxNodeOptionExt, TextRange}; @@ -136,6 +135,20 @@ impl Rule for NoInvalidUseBeforeDeclaration { // type Y = typeof X; // const X = 0; // ``` + && reference + .syntax() + .ancestors() + .nth(3) + .filter(|ancestor| JsObjectBindingPatternShorthandProperty::can_cast(ancestor.kind())) + .is_none() + // ignore when identifier destructured in function params + // For example: + // + // ```js + // const aFunction = ({a = '111', b = a}) => { + // console.info(a,b); + // } + // ``` && !AnyJsIdentifierUsage::cast_ref(reference.syntax()) .is_some_and(|usage| usage.is_only_type()) { diff --git a/crates/biome_js_analyze/tests/specs/nursery/noInvalidUseBeforeDeclaration/valid.js b/crates/biome_js_analyze/tests/specs/nursery/noInvalidUseBeforeDeclaration/valid.js index 42c908298f2d..3379f9913369 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/noInvalidUseBeforeDeclaration/valid.js +++ b/crates/biome_js_analyze/tests/specs/nursery/noInvalidUseBeforeDeclaration/valid.js @@ -10,3 +10,19 @@ export { X }; const X = 1; let a; console.log(a); function h() { Y; }; const Y = 0; + +const aFunction = (a = '111', b = a) => { + console.info(a,b); +} + +const aFunction = (b = a) => { + console.info(a,b); +} + +const aFunction = ({a = '111', b = a}) => { + console.info(a,b); +} + +const aFunction = ({b = a}) => { + console.info(a,b); +} diff --git a/crates/biome_js_analyze/tests/specs/nursery/noInvalidUseBeforeDeclaration/valid.js.snap b/crates/biome_js_analyze/tests/specs/nursery/noInvalidUseBeforeDeclaration/valid.js.snap index 6a234c833047..7e909fcc9bfc 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/noInvalidUseBeforeDeclaration/valid.js.snap +++ b/crates/biome_js_analyze/tests/specs/nursery/noInvalidUseBeforeDeclaration/valid.js.snap @@ -17,6 +17,22 @@ let a; console.log(a); function h() { Y; }; const Y = 0; +const aFunction = (a = '111', b = a) => { + console.info(a,b); +} + +const aFunction = (b = a) => { + console.info(a,b); +} + +const aFunction = ({a = '111', b = a}) => { + console.info(a,b); +} + +const aFunction = ({b = a}) => { + console.info(a,b); +} + ``` diff --git a/website/src/content/docs/internals/changelog.mdx b/website/src/content/docs/internals/changelog.mdx index 9bb2ef04b9bf..df0f50d7e9e5 100644 --- a/website/src/content/docs/internals/changelog.mdx +++ b/website/src/content/docs/internals/changelog.mdx @@ -76,6 +76,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom #### Bug fixes +- Fix [#1648](https://github.com/biomejs/biome/issues/1648). [noInvalidUseBeforeDeclaration](https://biomejs.dev/linter/rules/no-invalid-use-before-declaration/) now ignores when identifier destructured in function params. Contributed by @vasucp1207 + - Fix [#1640](https://github.com/biomejs/biome/issues/1640). [useEnumInitializers](https://biomejs.dev/linter/rules/use-enum-initializers) code action now generates valid code when last member has a comment but no comma. Contributed by @kalleep ### Parser From 4138f146a5fbb7a680a18081df468f1a3ac8f913 Mon Sep 17 00:00:00 2001 From: vasu Date: Thu, 25 Jan 2024 23:10:55 +0530 Subject: [PATCH 5/5] ignores param destructuring --- .../nursery/no_invalid_use_before_declaration.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/biome_js_analyze/src/semantic_analyzers/nursery/no_invalid_use_before_declaration.rs b/crates/biome_js_analyze/src/semantic_analyzers/nursery/no_invalid_use_before_declaration.rs index 7d7cf4cda80c..229b33ba41b4 100644 --- a/crates/biome_js_analyze/src/semantic_analyzers/nursery/no_invalid_use_before_declaration.rs +++ b/crates/biome_js_analyze/src/semantic_analyzers/nursery/no_invalid_use_before_declaration.rs @@ -2,7 +2,8 @@ use crate::{control_flow::AnyJsControlFlowRoot, semantic_services::SemanticServi use biome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic, RuleSource}; use biome_console::markup; use biome_js_syntax::{ - binding_ext::{AnyJsBindingDeclaration, AnyJsIdentifierBinding}, AnyJsExportNamedSpecifier, AnyJsIdentifierUsage, JsObjectBindingPatternShorthandProperty + binding_ext::{AnyJsBindingDeclaration, AnyJsIdentifierBinding}, + AnyJsExportNamedSpecifier, AnyJsIdentifierUsage, JsObjectBindingPatternShorthandProperty, }; use biome_rowan::{AstNode, SyntaxNodeOptionExt, TextRange};