helixbass / prettier-plugin-coffeescript

Prettier Coffeescript Plugin
MIT License
37 stars 1 forks source link

force assignment with await on the same line #179

Closed ksaitor closed 3 years ago

ksaitor commented 3 years ago

Thanks for the awesome lib!

Would be great to preserve assignment with result = await functionCall({ … }) on the same line.

Current behavior:

My code before formatting:

history = await SearchHistory.find({
  where: q
  limit: 10000
  skip: 0
  sort: 'createdAt ASC'
})

After formatting await SearchHistory.find({ shifts on a new line:

histories =
  await SearchHistory.find({
    where: q
    limit: 10000
    skip: 0
    sort: 'createdAt ASC'
  })

Desired behavior:

Don't break the line:

history = await SearchHistory.find({
  where: q
  limit: 10000
  skip: 0
  sort: 'createdAt ASC'
})

How can i config prettier to achieve that (prevent line break)? Thank you.

helixbass commented 3 years ago

Ok this isn't something that was exposed as configurable but makes sense to format that way consistently, so should now format that way as of #180

To test it out could you install a dev version of the plugin via (if you use yarn):

yarn add --dev github:helixbass/prettier-plugin-coffeescript#prettier-plugin-coffeescript-v0.1.6-dev.1-gitpkg

and let me know if that behaves as expected?

ksaitor commented 3 years ago

thanks for the fast response, @helixbass !

Didn't seem to help :/ I'm on yarn. Formatting through vscode. Installed dev version as your instructed. Also tried reinstalling it. Same results.

One thing to note. Previous and latest version did keep oneliners on the same line. E.g.

# stays as one line after formatting:
history = await SearchHistory.find({ where: q }) 

# still breaks 
histories =
  await SearchHistory.find({
    where: q
    limit: 10000
    skip: 0
    sort: 'createdAt ASC'
  })
helixbass commented 3 years ago

Hmm ok can you provide a complete example file where you are seeing it still linebreak (specifically I think await needs to live inside a function) along with your Prettier config (eg .prettierrc) so I can try and reproduce? And could you try running Prettier via the command line (instead of vscode) and see if you still see the same results, eg yarn prettier path/to/file.coffee?

One thing to note. Previous and latest version did keep oneliners on the same line

Ya if you're curious at all about the guts of Prettier you basically describe ways of formatting things if they fit on a single line vs if they don't, and it generally tries to fit things onto a single line and then falls back to the multi-line version if it doesn't fit. So in this case this is about telling it that the multi-line version of this type of assignment should be formatted differently than it currently is

ksaitor commented 3 years ago

worked via cli yarn prettier path/to/file.coffee ! thank you.

…now i just got to figure out how to make it work in VSCode again. I've got this in my config (as you've recommended in the docs)

  "[coffeescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
helixbass commented 3 years ago

Ok I don't have the strongest understanding of VSCode but I'd think it should just be invoking the versions of Prettier + Prettier plugins from your local environment/node_modules/, so if you're seeing different formatting when running via the cli vs inside VSCode that sounds like maybe a caching issue? Have you tried restarting VSCode to see if it picks up the newer version?