-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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(config): support TOML configuration files #4877
Conversation
Also, I recognize adding another dependency is not ideal for what is essentially a minor feature, but |
@jorgegonzalez how about |
It’s also (packagephobia tells you how big a package is when installed on your computer, while bundlephobia tells you how big it is when bundled+minified(+gzipped).) |
@foray1010 I'll use |
Thanks @ikatyang for upgrading |
Should be fine 👍 |
Not sure why it's failing on |
Ah I see. |
I think you could use a snapshot in that test, which would save having to create an object to match against. |
`; | ||
|
||
exports[`TOML throws error on incorrect toml 1`] = ` | ||
"TOML Error in load-toml.js: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The currentFile
looks weird to me, it confused me why there's a TOML parsing error for a js file. We should rename it to something ends with .toml
.
src/utils/load-toml.js
Outdated
@@ -0,0 +1,12 @@ | |||
"use strict"; | |||
|
|||
const toml = require("@iarna/toml"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use @iarna/toml/parse-string
to further reduce the bundle size.
I'll let other maintainers to decide if we should merge it as I hesitate about adding another config format. If someone wants to add support for other format later, what should we do? I'm thinking of if we should make loaders be part of plugins so that people can use whatever format they want. |
I understand the hesitance to add another format, and this is indeed an opinionated PR. Personally, I would love to see the JavaScript community embrace TOML configuration files more, as it is subjectively superior to both YAML and JSON configurations, and Prettier has the opportunity to lead the community in this. I suspect more users would also lean toward this format if they were given the chance to try it. As linked in #4845: Some reasons why TOML is better than YAML for configuration files: https://arp242.net/weblog/yaml_probably_not_so_great_after_all.html Some arguments against JSON as a configuration language: https://www.lucidchart.com/techblog/2018/07/16/why-json-isnt-a-good-configuration-language/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great idea! It seems fairly lightweight and it shouldn’t take too much maintenance, especially if it’s integrated into cosmiconfig directly. All that’s missing now is support for printing it 😉
There's not a huge value-add imo since prettier config files are very small and you're unlikely to need comments in them, but since the work is already done let's merge it 👍 |
Thank you for contributing to Prettier! |
Closes #4845
In order to support
.toml
configuration files,cosmiconfig
must first be updated tov5.0
. This update seems to break a bunch of tests. The following errors are thrown all over the place:Update 29/7/2018: This PR adds support for
.prettierrc.toml
config files.