ember-tooling / prettier-plugin-ember-template-tag

A prettier plugin for formatting Ember template tags
MIT License
22 stars 12 forks source link

RFC: Short templates in the top-level-of-a-class position #193

Closed gitKrystan closed 9 months ago

gitKrystan commented 10 months ago

Vote by reacting to this issue. Comment with more details below. Do you prefer:

Option A (🚀)

This is what v2.0.0-0 is currently returning.

export default class MyComponent extends Component {
  <template>Hey shorty</template>
}

Option B (👎)

This is what v1 currently returns.

export default class MyComponent extends Component {
  <template>
    Hey shorty
  </template>
}

Caveats

Neither of these solutions address the issue that whitespace matters in html. 🙈 I haven't had any issues reported here about whitespace causing issues so I am choosing to ignore that for now.

NullVoxPopuli commented 10 months ago

Option A, less text nodes. Also, very few templates will be one line.

If there is an element in there tho, option b

IgnaceMaes commented 10 months ago

Relevant RFC looking to address the whitespace difference: https://github.com/emberjs/rfcs/issues/982

As mentioned by @NullVoxPopuli, would this imply a template with a single element would also be on one line as follows?

export default class MyComponent extends Component {
  <template><h1>Hey shorty</h1></template>
}

Or would it then switch to a new line?

export default class MyComponent extends Component {
  <template>
    <h1>Hey shorty</h1>
  </template>
}

Because for that case I also would prefer option b.

gitKrystan commented 10 months ago

As mentioned by @NullVoxPopuli, would this imply a template with a single element would also be on one line as follows?

In the current implementation, yes.

NullVoxPopuli commented 10 months ago

oh, I'd prefer the link breaks then

gossi commented 10 months ago

trying v2 right now, which is producing one-liners with html tags is not giving the visual cue for the template I'm trying to find.

the short version is nice for tests though 😇

gitKrystan commented 9 months ago

Update:

I got this working, which is how the JSX formatter works:

One line if there is no tag:

<template>Hey shorty</template>

Multi lines if there is a tag:

<template>
  <h1>Hey shorty</h1>
</template>

Multi lines if there is a block and you wrote the block as multiline:

<template>
  {{#if true}}
    Hey shorty
  {{/if}}
</template>

One line in this case too:

<template>{{if true 'Hey shorty'}}</template>