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

Smart linebreak printer for pipe chains #6411

Merged
merged 4 commits into from
Sep 27, 2023

Conversation

fhammerschmidt
Copy link
Member

This PR is an alternative to #6387
Fixes #6380

@fhammerschmidt
Copy link
Member Author

Found out that it did not break correctly if the newline was before the last pipe (no matter how many pipes there were in total). Fixed now.
Also moved all smart pipe tests to a separate file.
Also added a formatting test with a React Hook which is now more densely formatted (the same as when there was a {} block in it).

@fhammerschmidt
Copy link
Member Author

fhammerschmidt commented Sep 25, 2023

I formatted a big codebase with this change and the only thing that changed were some Hooks like this one:

-  React.useCallback(
-    () =>
-      flatListRef.current
-      ->Nullable.toOption
-      ->Option.forEach(flatList => flatList->FlatList.scrollToOffset({offset: 0.})),
-    [],
-  )
+  React.useCallback(() =>
+    flatListRef.current
+    ->Nullable.toOption
+    ->Option.forEach(flatList => flatList->FlatList.scrollToOffset({offset: 0.}))
+  , [])

However, if you wrapped the former callback body in curly braces it was already formatted like that:

  React.useCallback(() => {
    flatListRef.current
    ->Nullable.toOption
    ->Option.forEach(flatList => flatList->FlatList.scrollToOffset({offset: 0.}))
  }, [])

If this change is ok, the PR is ready to review
@zth @cristianoc @cknitt

@cknitt cknitt requested a review from cristianoc September 25, 2023 14:41
@zth
Copy link
Collaborator

zth commented Sep 26, 2023

Looks great to me! @cristianoc ?

@cristianoc
Copy link
Collaborator

Looks great to me! @cristianoc ?

Looks great

@zth
Copy link
Collaborator

zth commented Sep 27, 2023

@fhammerschmidt fix that merge conflict and then let's merge? This is really worthy of a forum post as well given this is something many have complained about over the years. Great work! ⭐

@zth zth merged commit 843e2fc into rescript-lang:master Sep 27, 2023
@fhammerschmidt fhammerschmidt deleted the smart-pipe-printer branch September 27, 2023 07:13
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.

Smart linebreak printer for pipe chains
6 participants