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

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

Closed
JoshuaKGoldberg opened this issue Jan 16, 2024 · 7 comments · Fixed by #341
Closed

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

JoshuaKGoldberg opened this issue Jan 16, 2024 · 7 comments · Fixed by #341

Comments

@JoshuaKGoldberg
Copy link
Contributor

Coming over here from prettier/prettier#15898 (comment): 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
Copy link
Member

JounQin commented Jan 16, 2024

Is there a .nvmrc spec?

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

@JoshuaKGoldberg
Copy link
Contributor Author

JoshuaKGoldberg commented Jan 16, 2024

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 nvm-sh/nvm#3265.

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

  • 20
  • v20
  • v20.1
  • v20.12
  • v20.1.2
  • v20.1.23
  • v20.1.234
  • v20.12.2
  • v20.12.34
  • v20.12.345

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
Copy link
Member

JounQin commented Jan 16, 2024

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
Copy link
Contributor Author

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:

  • Presence or lack of v
  • Any text after a newline following the version number

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
Copy link
Member

JounQin commented Jan 16, 2024

...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
Copy link
Contributor Author

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
Copy link
Member

JounQin commented Jan 16, 2024

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

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.

2 participants