JavaScript: Fix indentation for binary expressions with trailing comments#8476
Conversation
|
Seems dirty, can it done in |
|
okay, I'll try it later. |
|
done |
|
I mean can we print the first part differently in that function? |
|
Performance-wise, it was better before the change. |
|
Prettier pr-8476 --parser babelInput: bifornCringerMoshedPerplexSawder(
askTrovenaBeenaDependsRowans,
glimseGlyphsHazardNoopsTieTie,
averredBathersBoxroomBuggyNurl
)
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;
bifornCringerMoshedPerplexSawder(
askTrovenaBeenaDependsRowans,
glimseGlyphsHazardNoopsTieTie,
averredBathersBoxroomBuggyNurl
) // comment
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;Output: bifornCringerMoshedPerplexSawder(
askTrovenaBeenaDependsRowans,
glimseGlyphsHazardNoopsTieTie,
averredBathersBoxroomBuggyNurl
)
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;
bifornCringerMoshedPerplexSawder(
askTrovenaBeenaDependsRowans,
glimseGlyphsHazardNoopsTieTie,
averredBathersBoxroomBuggyNurl
) // comment
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie; |
I tried but I was not sure how to print it differently...
the flattening is actually done only when the parent node type is |
|
@sosukesuzuki I'd try to do flattening where |
| if (isBinaryish(node) && !node.comments) { | ||
| return hasTrailingCommentInBinaryish(node.left); | ||
| } | ||
| return isBinaryish(node) && hasTrailingComment(node); |
There was a problem hiding this comment.
Prettier pr-8476
Playground link
--parser babelInput:
bifornCringerMoshedPerplexSawder(
askTrovenaBeenaDependsRowans,
glimseGlyphsHazardNoopsTieTie
)
|> foo
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;
bifornCringerMoshedPerplexSawder(
askTrovenaBeenaDependsRowans,
glimseGlyphsHazardNoopsTieTie
)
|> foo // comment
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;Output:
bifornCringerMoshedPerplexSawder(
askTrovenaBeenaDependsRowans,
glimseGlyphsHazardNoopsTieTie
)
|> foo
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;
bifornCringerMoshedPerplexSawder(
askTrovenaBeenaDependsRowans,
glimseGlyphsHazardNoopsTieTie
)
|> foo // comment
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;|
Looks complicated and I'm not sure it's okay to circumvent the I have another idea. There is a function called |
This comment has been minimized.
This comment has been minimized.
| // We group here when the callee is itself a call expression. | ||
| // See `isLongCurriedCallExpression` for more info. | ||
| isCallOrOptionalCallExpression(n.callee) || | ||
| isBinaryish(path.getParentNode()) |
There was a problem hiding this comment.
No, we can't tackle it this way:
Prettier pr-8476
Playground link
--parser babelInput:
bifornCringerMoshedPerplexSawder[
askTrovenaBeenaDependsRowans +
glimseGlyphsHazardNoopsTieTie
]
|> foo // comment
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;Output:
bifornCringerMoshedPerplexSawder[
askTrovenaBeenaDependsRowans + glimseGlyphsHazardNoopsTieTie
]
|> foo // comment
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;There was a problem hiding this comment.
I know, I'm fixing it.:+1:
There was a problem hiding this comment.
Looks good. Fixes this place in needs-parens.js:
prettier/src/language-js/needs-parens.js
Lines 138 to 151 in 7659a86
| } | ||
|
|
||
| return newParts; | ||
| } |
There was a problem hiding this comment.
We export this file to plugins, so I think we should documented it
There was a problem hiding this comment.
There was a problem hiding this comment.
I was wrong, we don't have documentation about utils
There was a problem hiding this comment.
This is definitely out of scope for this PR. The entire prettier.doc namespace isn't documented.
|
@sosukesuzuki I think we came close to fixing #1210. |
This comment has been minimized.
This comment has been minimized.
|
With block comment seems ugly Prettier pr-8476 --parser babelInput: bifornCringerMoshedPerplexSawder
|> foo
|> foo /* comment */
|> foo /* comment */
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;Output: bifornCringerMoshedPerplexSawder
|> foo
|> foo |>
/* comment */
foo |>
/* comment */
kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;Prettier 2.0.5 --parser babelInput: bifornCringerMoshedPerplexSawder
|> foo
|> foo /* comment */
|> foo /* comment */
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;Output: bifornCringerMoshedPerplexSawder
|> foo
|> foo /* comment */
|> foo /* comment */
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie; |
Fixes #8451
This PR seems to work fine but the doc is transformed so it maybe a dirty way...
changelog_unreleased/*/pr-XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨