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

Prettier formats handlebars components incorrectly inside html tag #8584

Closed
Drakeoon opened this issue Jun 17, 2020 · 5 comments · Fixed by #8593
Closed

Prettier formats handlebars components incorrectly inside html tag #8584

Drakeoon opened this issue Jun 17, 2020 · 5 comments · Fixed by #8593
Labels
lang:handlebars Issues affecting Handlebars (Glimmer) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@Drakeoon
Copy link

Prettier 2.0.5
Playground link

--arrow-parens avoid
--parser glimmer
--trailing-comma none

Input:

<div>
  {{shared/input-component label="The Component" value="description" issue=issue}}
  
  {{shared/input-component more=props even=more label="The Component" value="description" issue=issue}}
</div>

Output:

<div>
  {{
    shared/input-component label="The Component" value="description" issue=issue
  }}

  {{
    shared/input-component
    more=props
    even=more
    label="The Component"
    value="description"
    issue=issue
  }}
</div>

Expected behavior:

<div>
  {{shared/input-component label="The Component" value="description" issue=issue}}

  {{shared/input-component
    more=props
    even=more
    label="The Component"
    value="description"
    issue=issue
  }}
</div>

The issue only appears to happen when having an html tag wrapping Ember components, here's the example of prettier working correctly after stripping <div> tag

@Drakeoon Drakeoon changed the title Prettier formats incorrectly inside html tag Prettier formats handlebars components incorrectly inside html tag Jun 17, 2020
@alexander-akait
Copy link
Member

For me current output is readable. Why do you think result in expected is better?

@alexander-akait alexander-akait added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Jun 17, 2020
@3runo
Copy link

3runo commented Jun 18, 2020

For me current output is readable. Why do you think result in expected is better?

This should not be based on personal information. The parser is breaking the init and ending of the components for no reason.

It would be the same of

<ReactComponent prop1=1 prop2=2 prop3=3 />

being formatted like

<
ReactComponent prop1=1 prop2=2 prop3=3
/>

@PoslinskiNet
Copy link

PoslinskiNet commented Jun 18, 2020

It's funny because if we don't wrap it as a first ancestor with HTML element, then it works as expected. With HTML element it behaves oddly. Funny thing - vue formatter works well in this case (for Handlebars).

Input:

{{shared/input-component label="The Component" value="description" issue=issue}}

<div>
  {{shared/input-component label="The Component" value="description" issue=issue}}
</div>

Output:

{{shared/input-component label="The Component" value="description" issue=issue}}

<div>
  {{
    shared/input-component label="The Component" value="description" issue=issue
  }}
</div>

@Drakeoon
Copy link
Author

@evilebottnawi Well, to me the main reasons to follow the expected output would be:

  1. VSCode does not recognize the current output as any form of component when using Handlebars language
    image

  2. Ember guides use the same formatting style, which leads to the majority of Ember projects following the expected output style

  3. It looks more like a bug than an intention, because if the element is not wrapped in an html tag it behaves just fine

Although I understand you guys provide a limited support to the handlebars and it might be outside of the scope

@no-response no-response bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Jun 18, 2020
@mikoscz
Copy link
Contributor

mikoscz commented Jun 18, 2020

jgwhite#1 (comment)

mikoscz added a commit to mikoscz/prettier that referenced this issue Jun 18, 2020
mikoscz added a commit to mikoscz/prettier that referenced this issue Jun 18, 2020
mikoscz added a commit to mikoscz/prettier that referenced this issue Jun 18, 2020
mikoscz added a commit to mikoscz/prettier that referenced this issue Jun 18, 2020
@thorn0 thorn0 linked a pull request Jun 18, 2020 that will close this issue
3 tasks
@thorn0 thorn0 added lang:handlebars Issues affecting Handlebars (Glimmer) type:bug Issues identifying ugly output, or a defect in the program labels Jun 18, 2020
thorn0 pushed a commit that referenced this issue Jun 24, 2020
* Test: Add test addressing #8584

* Fix: Resolves problem with incorrect component formatting (#8584)

* Docs: Add changelog note

* Test: Add test for yield formatting case

* Fix: Fix handlebars yield opening tag break

* Test: Add case for any helper with params

* Fix: Fix opening tag for every helper with params

* Chore: Revert whitespaces

* Chore: Revert whitespaces in tests
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Sep 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:handlebars Issues affecting Handlebars (Glimmer) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants