un-ts / prettier

:package: Opinionated but Incredible Prettier plugins.
https://prettier.vercel.app
MIT License
260 stars 23 forks source link

prettier-plugin-sh: support .nvmrc files? #340

Closed JoshuaKGoldberg closed 5 months ago

JoshuaKGoldberg commented 5 months ago

Coming over here from https://github.com/prettier/prettier/issues/15898#issuecomment-1883395232: I'd like to use prettier-plugin-sh to format .nvmrc files. Given that the plugin supports similar files (gitignore, dotenv, ...), is this a reasonable use case for the plugin?

JounQin commented 5 months ago

Is there a .nvmrc spec?

Or at least some example so that we can add some test cases?

JoshuaKGoldberg commented 5 months ago

I don't think there's a formal spec, no. Parsing of .nvmrc comes from commands in https://github.com/nvm-sh/nvm/blob/6c9cd2f2d1779b91c0ab7ab0b243c0c55f25a8a5/nvm.sh. Filed https://github.com/nvm-sh/nvm/issues/3265.

For now, node -v is the rough format it uses: an optional v, a number, then 0-1 of . and more numbers.

Trailing ~whitespace and/or~ newlines seem to be fine as well.

https://github.com/JoshuaKGoldberg/create-typescript-app/blob/c91ce25e556f67ea321cd0df260a08569e71d8f8/.nvmrc is an example of a working file.

20.11.0
JounQin commented 5 months ago

I'm not for sure to understand the user case here, this file is already lean enough to me? Is there any chance that can be not pretty?

JoshuaKGoldberg commented 5 months ago

Extra newlines after the version are allowed:

20.11.0

Playing around with it a bit more, it looks like whitespace on the same line are being parsed as the version number. So those can't be removed. But the following are ignored:

So this is actually a totally valid .nvmrc:

20.11.0

...gotcha!

...now that I've played with this a bit more, maybe it deserves its own plugin?

JounQin commented 5 months ago

...now that I've played with this a bit more, maybe it deserves its own plugin?

🤣 Still don't quite understand what's the text after first line does.

20.11.0

...gotcha!

It's just valid, but not useful at all? Is there anyone really doing this?

JoshuaKGoldberg commented 5 months ago

Haha yeah it's just ignored. I've never seen it in the wild and didn't even think to try it out until after we started talking!

JounQin commented 5 months ago

If you only want to trim, I think maybe it could be added, with a reference doc. Would you like to raise a PR?