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
Handlebars: improve conditional formatting #8691
Comments
related issue: lifeart/vsc-ember-syntax#2 |
Other weird cases that fall into a similar pattern {{
yield
(hash
header=(component "fluid-table/thead")
body=(component "fluid-table/tbody")
th=(component "fluid-table/th")
td=(component "fluid-table/td")
)
}} ( <LinkTo
@query={{
hash
filter=(compute this.computeFilterWithEmail this.filter campaignPic.userEmail)
}}
class="text-xs hover:underline"
data-test-user-email
>
{{campaignPic.userEmail}}
</LinkTo>
|
@alexlafroscia The main issue I've seen about this is that other syntaxes that use mustaches I think it might be why Prettier is biased to render
I'm not totally against this add spaces inside the mustaches rule, but IMO at the very least
|
I agree that if It's interesting that the Vue community would do something like Does Vue have any kind of precedent for what it does to format "helpers" like Ember has, where it's essentially a function invocation within the template? It seems to my like maybe a filter is the closest analogue, which you pipe after a value and follows the same formatting pattern expressed earlier (with whitespace separating values from the curly braces) |
@alexlafroscia yep, I can reproduce <div
foo={{
yield
(hash foo bar="string that's long enough to definitely create a new line")
}}
></div> |
I would argue in favor of the following:
as well as
I think putting yield on a line by itself looks pretty awful and wastes a lot of vertical space. I would liken it to JS, where we do the following:
rather than
|
I encountered another edge case if a helper exceeds the print width only a little bit. Input: {{if abcdefghijklmnopqrstuvwxyz (t 'abcdefghijklmnopq') (t 'abcdefghijklmnopq')}}
{{#if (eq abcdefghijklmnopqrstuvwxyzabcdefgh abcdefghijklmnopqrstuvwxyzabcdefgh)}}
foo{{/if}}
{{some-helper abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijkl}} Output: {{if abcdefghijklmnopqrstuvwxyz (t "abcdefghijklmnopq") (t "abcdefghijklmnopq")
}}
{{#if (eq abcdefghijklmnopqrstuvwxyzabcdefgh abcdefghijklmnopqrstuvwxyzabcdefgh)
}}
foo
{{/if}}
{{some-helper abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijkl
}} Expected: {{if
abcdefghijklmnopqrstuvwxyz
(t "abcdefghijklmnopq")
(t "abcdefghijklmnopq")
}}
{{#if
(eq abcdefghijklmnopqrstuvwxyzabcdefgh abcdefghijklmnopqrstuvwxyzabcdefgh)
}}
foo
{{/if}}
{{some-helper
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijkl
}} Please note that it works for all as expected if adding a few more chars. This issue only occurs if the helper invocation without closing brackets does not exceed print width. |
@jelhan yep, I came across that one before; see #6 in jgwhite#1 (comment) |
Also running into this :) |
Should this be closed? Looks like all the cases described here are fixed via #10586! |
Running |
Prettier 2.0.5
Playground link
Input:
Output:
I think we can (should?) improve the last case where the condition moves to the new line. This, arguably, looks better:
I'm not sure how to go about differentiating between which helpers should keep 1st param on the same line (unless it overflows) and which shouldn't. One option is to make a whitelist of helpers like
if
but that's brittle. Another option is to always leave 1st param on the first line for helpers with 3+ params. That might not be the best formatting for non-conditional helpers with 3+ params. Thoughts?Another (related) issue I'm seeing on master is with this chunk from our codebase:
Input:
Output:
I would expect
if
to stay adjacent to{{
(looks like #8593 didn't fix all the cases?) Or rather, we seem to be treating helpers different within attributes since this issues doesn't happen in a regular block-level mustache.The text was updated successfully, but these errors were encountered: