-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
add resolveConfigWithFilePath API #3846
add resolveConfigWithFilePath API #3846
Conversation
What if we just had prettier.resolveConfig.sync('some/path.js');
// ->
// {
// useTabs: true,
// configPath: "/abs/path/.prettierrc"
// } |
That's also an option, however I would suggest against it. It makes sense that the API returns the configuration as Prettier can later ingest it. Adding extra properties in this one case doesn't quite make sense to me and feels like a mix of concerns. Even more so when the rest of the time we are working with the configuration payload it is separated between |
src/config/resolve-config.js
Outdated
@@ -52,6 +62,13 @@ function _resolveConfig(filePath, opts, sync) { | |||
return null; | |||
} | |||
|
|||
if (!!includeFilePath) { |
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.
Can this just be if (includeFilePath)
?
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.
fixed!
docs/api.md
Outdated
@@ -57,6 +57,18 @@ If `options.editorconfig` is `true` and an [`.editorconfig` file](http://editorc | |||
|
|||
Use `prettier.resolveConfig.sync(filePath [, options])` if you'd like to use sync version. | |||
|
|||
## `prettier.resolveConfigWithFilePath(filePath [, options])` | |||
|
|||
`resolveConfigWithFilePath` works that same as `resolveConfig` with one difference. The response will include both the configuration that was resolved, along with the file path to the configuration that was used to generate the configuration. However, it will not include the path to the located `.editorconfig` file when used as the core Prettier configuration acts as an override. This is useful for editor integrations, to subscribe to the resolved configuration and reload with any changes. |
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'd suggest the following changes:
The response will include both the configuration that was resolved, along with the
filepath to theconfigurationfile that was used to generate the configuration
However, it will not include the path to
the locatedany.editorconfig
filewhenused, as thecore Prettier configurationconfiguration file acts as an override.
(note the ,
after used
)
...wait a minute. Couldn't we just export After typing this out, I realized that the use case (editor integrations) will likely want both the config and the file path anyway, so it probably makes sense to combine them into a single function, instead of forcing the integration to call two functions (which would also unnecessarily repeat the path resolution). I'm going to leave this comment here anyway, for the record. |
I thought the same thing at first. Though as someone who would be implementing this type of functionality, I'd much rather make a call that returns both the resolved/merged config as well as the file path of the config used. There is room for error when using those API separately. |
I believe a valid workaround until this is resolved would be to use cosmiconfig's |
Is there a way to expose the path to the editorconfig file too? |
I don't think https://github.com/editorconfig/editorconfig-core-js provides a way to see the path of the files being parsed (note that there can be more than one). However, assuming there's just one, we could use some combination of |
"assuming just one" could produce false positives though the simplification would be nice. Seems the devs behind editorconfig-core-js are pretty responsive though, so a PR adding a method such as this one wouldn't be out of the question. |
Sorry for the silence! Having some crunch time at the office :( I totally agree we should find a way to expose the path to |
Bummer about the office time. I'm in between jobs so I finally get to work on stuff I enjoy haha.
Unfortunately. I created a quick repo if you wanted to mess around with it. |
FTR |
I'm going to close this based on #3846 (comment) |
This PR introduces a new API
prettier.resolveConfigWithFilePath
. This method uses the pre-existing internals to find and merge prettier configurations, but exposes the resolved file path for consumers. This will close #3451 and allow us to solve prettier/prettier-atom#270.I also reorganized the API docs a bit so that similar API sit next to each other.