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

[feat] Break down big prop objects into separate lines #170

Closed
dkzlv opened this issue Dec 29, 2020 · 3 comments · Fixed by #175
Closed

[feat] Break down big prop objects into separate lines #170

dkzlv opened this issue Dec 29, 2020 · 3 comments · Fixed by #175

Comments

@dkzlv
Copy link

dkzlv commented Dec 29, 2020

Is your feature request related to a problem? Please describe.
Currently prettier plugin does not break down big props/objects into multiple lines if it is placed in template. More than that, it puts everything into one huge line, ignoring the printWidth setting.

Describe the solution you'd like
It should work exactly like it does in other places.

Take this code as an example:

<input
  class="input"
  type="password"
  bind:value={$passwordStore.rawValue}
  use:trackChanges={{ store: passwordStore, clean: [ensureString], validate: [minLength(6), maxLength(25)] }} />
  // Cannot be broken down into multiple lines no matter what

It should be formatted into something like this:

<input
  class="input"
  type="password"
  bind:value={$passwordStore.rawValue}
  use:trackChanges={{
    store: passwordStore,
    clean: [ensureString],
    validate: [minLength(6), maxLength(25)]
  }} />
@dummdidumm
Copy link
Member

Fixing this is easy. The only question is, do we want to change this behavior for everything? I think the only question is whether we want to have that for svelte control blocks, too. It may then look like this:

<p>
  asdddddddddddddddddddddddddddddddddddddddd{#await Promise.resolve(
         "asd"
     ) then b}s{/await}
</p>

@Conduitry @ehrencrona what do you think?

dummdidumm pushed a commit to dummdidumm/prettier-plugin-svelte that referenced this issue Jan 3, 2021
Fixes sveltejs#170

### BREAKING CHANGE
When a line exceeds the maximum characters, it is now possible to break the js expressions, too
@ehrencrona
Copy link
Contributor

I’d say it’s reasonable to do it in control blocks, too, but I’m not sure I can overview all the consequences.
But it feels like in most situations, if you don’t like how it breaks, you can just put the tag (await in your example) on a new line, so it’s no so close to the max width.

@dummdidumm
Copy link
Member

After some more thought I think it's better to not break up control blocks. In the case of if/else they might contain destructurings/arrays which would look really clunky broken up. So I'd say break everything except control blocks.

dummdidumm added a commit that referenced this issue Jan 4, 2021
Fixes #170

### BREAKING CHANGE
If the js content inside a mustache tag is too long, break it up if possible. Only exception are Svelte Blocks (#if/#await/etc) because that looks stupid.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants