Skip to content

Conversation

@adrian-gierakowski
Copy link

@adrian-gierakowski adrian-gierakowski commented Nov 20, 2025

Modified src/generation/generate.rs to return false for Node::ArrowExpr in allows_inline_multi_line unless the arrow function body is a block statement. This prevents arrow functions with expression bodies from being formatted inline when they overflow, ensuring consistent multi-line formatting for function arguments. Verified with regression tests.

NOTE: this PR was created with the assistance from an AI agent, see original PR on my for which was created by the agent: adrian-gierakowski#2

Fixes #753
Fixes #686

adrian-gierakowski and others added 3 commits November 20, 2025 12:40
This change modifies `allows_inline_multi_line` to restrict arrow functions with expression bodies from being inline multi-line. This ensures that if such an arrow function overflows the line width, it forces the parent call expression to break its arguments onto multiple lines, rather than allowing a partial split that results in inconsistent formatting.

Fixes dprint#753
Fixes dprint#686
Copy link

@naimonon77 naimonon77 left a comment

Choose a reason for hiding this comment

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

@adrian-gierakowski Let me just comment on one thing.

@@ -0,0 +1,46 @@
~~ lineWidth: 80, indentWidth: 2, memberExpression.linePerExpression: true ~~
Copy link

@naimonon77 naimonon77 Dec 27, 2025

Choose a reason for hiding this comment

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

@adrian-gierakowski
Let me just comment on one thing.
I think it should have a name starting with 0, like other files, like "issue0753.txt".

Copy link
Author

Choose a reason for hiding this comment

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

Thanks.

Btw. I'm not sure of this is the correct fix. Please see my comments in related issue.

Copy link

@naimonon77 naimonon77 Dec 27, 2025

Choose a reason for hiding this comment

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

In my environment, the behavior of the following test case changed when memberExpression.linePerExpression:
false was set. You may want to check this.

When you do, it's a good idea to incorporate the latest changes from the main branch and check them just to be sure.

https://github.com/naimonon77/dprint-plugin-typescript/blob/issue0753_2/tests/specs/issues/issue0753_02.txt

Copy link
Author

Choose a reason for hiding this comment

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

In my environment, the behavior of the following test case changed when memberExpression.linePerExpression:
false was set. You may want to check this.

Yes, the issue only manifests when memberExpression.linePerExpression: true. I think that's the reason @dsherret keeps ignoring it since this option is disabled in deno. I'm not interested in disabling this option as without it dprint allows formatting which is quite inconsistent, like:

a.b.c
  .b.e
  .f

Copy link
Author

Choose a reason for hiding this comment

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

The main problem at this point is: what's the intended behaviour in #753 as that would determine if solution in this PR is valid or not

Choose a reason for hiding this comment

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

As far as I can confirm, the intended behavior in #753 is fine.

Copy link
Author

Choose a reason for hiding this comment

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

@dsherret would be great if you could confirm and merge if you agree with the above. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inconsistent formatting of multi-argument function calls when memberExpression.linePerExpression: true Formatting is unstable (not idempotent)

2 participants