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): fix indention when huggable expressions break in arrow chains #1036

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

faultyserver
Copy link
Contributor

Summary

I'm not sure if this came from some of the other fixes I'd made to arrow chains or was pre-existing and only came up because of those other fixes, but currently when a call argument layout with an arrow chain ends up using the middle variant (i.e., the signature chain is printed on a single line, but the body of the chain breaks), and the body is a huggable expression (i.e., an array, block body, jsx, etc.)), it gets printed with an extra level of indention:

somePromise.then(({reallyLongArguments}) => (makeTheChainFullyBreak) => [dontIndentTwice]);

// Biome Output
somePromise.then(({ reallyLongArguments }) => (makeTheChainFullyBreak) => [
    dontIndentTwice,
  ]);

// Prettier Output
somePromise.then(({ reallyLongArguments }) => (makeTheChainFullyBreak) => [
  dontIndentTwice,
]);

This PR ensures that there is only a single level of indention for the tail body, matching Prettier's output.

Test Plan

There weren't any existing tests that hit this case, so I added them to the arrow/currying.js spec test.

Copy link

netlify bot commented Dec 4, 2023

Deploy Preview for biomejs ready!

Name Link
🔨 Latest commit 9315c4f
🔍 Latest deploy log https://app.netlify.com/sites/biomejs/deploys/656f69b82c286000085c7d13
😎 Deploy Preview https://deploy-preview-1036--biomejs.netlify.app/playground
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages labels Dec 4, 2023
@faultyserver
Copy link
Contributor Author

Actually this is seemingly incorrect and causes block function bodies to dedent too much? Not sure how that isn't being caught by prettier tests, but I'll need to fix that before this moves forward.

@faultyserver
Copy link
Contributor Author

Okay the newer commits have updated this to properly match Prettier's logic.

The difference is that we were pre-emptively applying indent_if_group_breaks to all bodies, but we only want to do that if the chain is a grouped call argument, since that's the only time it'll need the extra level. When it's fully broken out or fully collapsed, it'll have the appropriate indention naturally.

@faultyserver faultyserver changed the title fix(js_formatter): Fix indention when huggable expressions break in arrow chains fix(js_formatter): fix indention when huggable expressions break in arrow chains Dec 4, 2023
@Conaclos
Copy link
Member

Conaclos commented Dec 5, 2023

Feel free to merge once the conflicts resolved :)

@faultyserver faultyserver merged commit 5ff507e into main Dec 5, 2023
18 checks passed
@faultyserver faultyserver deleted the faulty/curry-hug-indent branch December 5, 2023 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants