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(js_formatter): format hook with 3 arguments #4462

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1205,14 +1205,21 @@ fn is_multiline_template_only_args(arguments: &JsCallArguments) -> bool {
/// useMemo(() => {}, [])
/// ```
fn is_react_hook_with_deps_array(arguments: &JsCallArguments, comments: &JsComments) -> bool {
if arguments.args().len() > 3 || arguments.args().len() < 2 {
return false;
};

use AnyJsExpression::*;
let mut args = arguments.args().iter();
if arguments.args().len() == 3 {
args.next();
}

match (args.next(), args.next()) {
(
Some(Ok(AnyJsCallArgument::AnyJsExpression(JsArrowFunctionExpression(callback)))),
Some(Ok(AnyJsCallArgument::AnyJsExpression(JsArrayExpression(deps)))),
) if arguments.args().len() == 2 => {
) => {
if comments.has_comments(callback.syntax()) || comments.has_comments(deps.syntax()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ expect(
bar;
}
).toThrow(ReferenceError);

useImperativeHandle(ref, () => {
return;
}, []);
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ expect(
bar;
},
).toThrow(ReferenceError);

useImperativeHandle(ref, () => {
Copy link
Member

Choose a reason for hiding this comment

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

These tests are coming from prettier repository, so they should not be modified

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad 😅 I thought that since we are dealing with a difference in formatting with prettier, I should place the test there

return;
}, []);
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ expect(
}
).toThrow(ReferenceError);

useImperativeHandle(ref, () => {
return;
}, []);

```


Expand Down Expand Up @@ -104,7 +108,7 @@ expect(
var bar = "foo";
bar;
};
@@ -28,6 +40,6 @@
@@ -28,9 +40,9 @@
() => {
var bar = "foo";
};
Expand All @@ -114,6 +118,9 @@ expect(
+bar;
+}
+).toThrow(ReferenceError)

useImperativeHandle(ref, () => {
return;
```

# Output
Expand Down Expand Up @@ -164,6 +171,10 @@ expect(
bar;
}
).toThrow(ReferenceError)

useImperativeHandle(ref, () => {
return;
}, []);
```

# Errors
Expand Down Expand Up @@ -394,6 +405,7 @@ call-arguments.js:40:3 parse ━━━━━━━━━━━━━━━━━
> 41 │ ).toThrow(ReferenceError);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
42 │
43 │ useImperativeHandle(ref, () => {

i Expected a statement here.

Expand All @@ -404,6 +416,7 @@ call-arguments.js:40:3 parse ━━━━━━━━━━━━━━━━━
> 41 │ ).toThrow(ReferenceError);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
42 │
43 │ useImperativeHandle(ref, () => {


```