Skip to content

Commit

Permalink
Resolves config by default in getFileInfo() (#14108)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jan 30, 2023
1 parent d65a88a commit a26e8ac
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog_unreleased/api/14108.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit a26e8ac

Please sign in to comment.