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

Resolves config by default in getFileInfo() #14108

Merged
merged 4 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog_unreleased/api/14108.md
@@ -0,0 +1,3 @@
#### [BREAKING] `getFileInfo()` resolves config by default (#14108 by @fisker)

`options.resolveConfig` default to `true` now, see the [documentation](https://prettier.io/docs/en/api.html#prettiergetfileinfofilepath--options).
2 changes: 1 addition & 1 deletion docs/api.md
Expand Up @@ -96,7 +96,7 @@ If the given `filePath` is ignored, the `inferredParser` is always `null`.

Providing [plugin](plugins.md) paths in `options.plugins` (`string[]`) helps extract `inferredParser` for files that are not supported by Prettier core.

When setting `options.resolveConfig` (`boolean`, default `false`), Prettier will resolve the configuration for the given `filePath`. This is useful, for example, when the `inferredParser` might be overridden for a subset of files.
When setting `options.resolveConfig` (`boolean`, default `true`) to `false`, Prettier will not search for configuration file. This is can be useful if this function is only used to check if file is ignored.

## `prettier.getSupportInfo()`

Expand Down
2 changes: 1 addition & 1 deletion src/common/get-file-info.js
Expand Up @@ -39,7 +39,7 @@ async function getFileInfo(filePath, options) {

async function getParser(filePath, options) {
let config;
if (options.resolveConfig) {
if (options.resolveConfig !== false) {
config = await resolveConfig(filePath);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/__tests__/file-info.js
Expand Up @@ -159,11 +159,11 @@ describe("API getFileInfo resolveConfig", () => {
test("{resolveConfig: undefined}", async () => {
await expect(prettier.getFileInfo(files.foo)).resolves.toMatchObject({
ignored: false,
inferredParser: null,
inferredParser: "foo-parser",
});
await expect(prettier.getFileInfo(files.js)).resolves.toMatchObject({
ignored: false,
inferredParser: "babel",
inferredParser: "override-js-parser",
});
await expect(prettier.getFileInfo(files.bar)).resolves.toMatchObject({
ignored: false,
Expand Down