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): Avoid double-printing the first leading comments in arrow chains #951

Merged
merged 1 commit into from
Nov 28, 2023

Conversation

faultyserver
Copy link
Contributor

Playground Example.

Summary

ArrowChain is a special case of FormatJsArrowFunctionExpression that handles formatting all of the nested arrow functions inside of it as a single node point. The top formatting node handles formatting comments, just like any other formatting node, but because all of the other arrow expressions are handled within that node, the chain must print all of their leading comments manually.

However, the logic just used a loop and checked each arrow for a leading comment to then print it out if it exists. This included the first arrow expression in the chain as well, meaning the comment would be double printed; once by the parent Format node, and again by the inner loop.

This PR updates the logic to skip printing the leading comment for the first arrow in the chain, leaving it to only be printed once by the parent Format node.

// Input
foo( /*hi*/(a) => (b) => {});

// Output, before
foo(/*hi*/ /*hi*/ (a) => (b) => {});

// Output, after
foo(/*hi*/ (a) => (b) => {});

Closes #921.

Test Plan

There aren't any tests that currently cover this case, but since it's just a minor fix to the logic I think it's okay to not have an additional test just for it. It should get handled implicitly by most of the other tests with comments around arrow chains.

@github-actions github-actions bot added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages labels Nov 28, 2023
@faultyserver faultyserver merged commit fbe62ce into main Nov 28, 2023
15 checks passed
@faultyserver faultyserver deleted the faulty/arrow-chain-comments branch November 28, 2023 21:40
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.

📝 Duplicated @returns JSDoc
2 participants