Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: noInvalidUseBeforeDeclaration false-positive for param destructuring with default values #1672

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cb1438e
refactor(linter): UseAnchorContent code action
vasucp1207 Oct 7, 2023
364f018
refactor(linter): UseAnchorContent code action
vasucp1207 Oct 7, 2023
d94d9e1
refactor(linter): UseAnchorContent code action
vasucp1207 Oct 7, 2023
5517a6b
Merge branch 'biomejs:main' into main
vasucp1207 Oct 8, 2023
0d46365
Merge branch 'biomejs:main' into main
vasucp1207 Oct 12, 2023
4d11c7c
Merge branch 'biomejs:main' into main
vasucp1207 Oct 15, 2023
aa3d3a5
Merge branch 'biomejs:main' into main
vasucp1207 Oct 19, 2023
a39dad7
Merge branch 'biomejs:main' into main
vasucp1207 Oct 22, 2023
281c6a2
Merge branch 'biomejs:main' into main
vasucp1207 Oct 25, 2023
f3fb5d1
Merge branch 'biomejs:main' into main
vasucp1207 Oct 29, 2023
76b3f81
Merge branch 'biomejs:main' into main
vasucp1207 Oct 29, 2023
103bc72
Merge branch 'biomejs:main' into main
vasucp1207 Oct 31, 2023
63186c9
Merge branch 'biomejs:main' into main
vasucp1207 Nov 3, 2023
8138132
Merge branch 'biomejs:main' into main
vasucp1207 Nov 4, 2023
f276c68
Merge branch 'biomejs:main' into main
vasucp1207 Nov 16, 2023
5e968fc
Merge branch 'biomejs:main' into main
vasucp1207 Nov 17, 2023
736d2f1
Merge branch 'biomejs:main' into main
vasucp1207 Nov 21, 2023
4d6153a
Merge branch 'biomejs:main' into main
vasucp1207 Nov 21, 2023
517cac3
Merge branch 'biomejs:main' into main
vasucp1207 Nov 21, 2023
e833968
Merge branch 'biomejs:main' into main
vasucp1207 Nov 23, 2023
86ed25f
Merge branch 'biomejs:main' into main
vasucp1207 Nov 25, 2023
9c1cf36
Merge branch 'biomejs:main' into main
vasucp1207 Nov 28, 2023
31aa757
Merge branch 'biomejs:main' into main
vasucp1207 Nov 29, 2023
302a0b4
Merge branch 'biomejs:main' into main
vasucp1207 Dec 2, 2023
9d7af14
Merge branch 'biomejs:main' into main
vasucp1207 Dec 7, 2023
2787dd4
Merge branch 'biomejs:main' into main
vasucp1207 Dec 11, 2023
68d833d
Merge branch 'biomejs:main' into main
vasucp1207 Dec 20, 2023
8ea685f
Merge branch 'biomejs:main' into main
vasucp1207 Jan 9, 2024
dff5253
Merge branch 'biomejs:main' into main
vasucp1207 Jan 11, 2024
15d00db
Merge branch 'biomejs:main' into main
vasucp1207 Jan 11, 2024
aeb89a7
Merge branch 'biomejs:main' into main
vasucp1207 Jan 16, 2024
bc40a71
Merge branch 'biomejs:main' into main
vasucp1207 Jan 21, 2024
c03e955
Merge branch 'biomejs:main' into main
vasucp1207 Jan 22, 2024
4cc25c8
Merge branch 'biomejs:main' into main
vasucp1207 Jan 22, 2024
15362b8
Merge branch 'biomejs:main' into main
vasucp1207 Jan 23, 2024
e016949
Merge branch 'biomejs:main' into main
vasucp1207 Jan 24, 2024
a7cad4c
Merge branch 'biomejs:main' into main
vasucp1207 Jan 25, 2024
ed89460
ignores param destructuring
vasucp1207 Jan 25, 2024
4138f14
ignores param destructuring
vasucp1207 Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion crates/biome_js_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use biome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic, Ru
use biome_console::markup;
use biome_js_syntax::{
binding_ext::{AnyJsBindingDeclaration, AnyJsIdentifierBinding},
AnyJsExportNamedSpecifier, AnyJsIdentifierUsage,
AnyJsExportNamedSpecifier, AnyJsIdentifierUsage, JsObjectBindingPatternShorthandProperty,
};
use biome_rowan::{AstNode, SyntaxNodeOptionExt, TextRange};

Expand Down Expand Up @@ -136,6 +136,20 @@ impl Rule for NoInvalidUseBeforeDeclaration {
// type Y = typeof X;
// const X = 0;
// ```
&& reference
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with this fix is: it doesn't report used before declaraion such as { a = b, b = "111" }.

I wonder if we should rather change the implementation of biome_js_syntax::binding_ext::AnyJsIdentifierBinding::declaration and consider JsObjectBindingPatternShorthandProperty, JsObjectBindingPattern* and JsArrayBindingPattern* as declarations. I am not sure of the implication in other part of the codebase. This could solve both #1652 and #1648.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will look into this after some days, quite busy now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you still interested in investigating this? Otherwise, I can take a look :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Conaclos, I get the idea that we have to include JsObjectBindingPatternShorthandProperty as declarations but as you mention I found it hard to handle its implication in other parts of codebase, so you take a look on this. I will follow your work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I proposed a fix in #1800

.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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

```


2 changes: 2 additions & 0 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading