PullJosh / leopard-website

This repo contains the source code for the Leopard website
https://leopardjs.com
14 stars 3 forks source link

Format code with prettier on save #59

Open PullJosh opened 1 month ago

PullJosh commented 1 month ago

I think this should be a very strong default (possibly even the only option for now). Particularly for beginners, opinionated code formatting helps a lot.

towerofnix commented 1 month ago

Might be a little tricky to make sure the cursor sticks effectively where it was - so it doesn't shift somewhere a bit offset when you save - but this is presumably something other IDEs have already figured out, and maybe something prettier itself supports?

PullJosh commented 1 month ago

Yes indeed! https://prettier.io/docs/en/api.html#prettierformatwithcursorsource--options

formatWithCursor both formats the code, and translates a cursor position from unformatted code to formatted code. This is useful for editor integrations, to prevent the cursor from moving when code is formatted.