diff --git a/docs/api.md b/docs/api.md index 249d59882..6bd79d4fe 100644 --- a/docs/api.md +++ b/docs/api.md @@ -58,16 +58,26 @@ 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.resolveConfigFile(filePath [, options])` +## `prettier.resolveConfigFile([filePath])` -`resolveConfigFile` can be used to find the path of the Prettier's configuration file will be used when resolving the config (i.e. when calling `resolveConfig`). A promise is returned which will resolve to: +`resolveConfigFile` can be used to find the path of the Prettier configuration file that will be used when resolving the config (i.e. when calling `resolveConfig`). A promise is returned which will resolve to: - The path of the configuration file. - `null`, if no file was found. The promise will be rejected if there was an error parsing the configuration file. -If `options.useCache` is `false`, all caching will be bypassed. +The search starts at `process.cwd()`, or at `filePath` if provided. Please see the [cosmiconfig docs](https://github.com/davidtheclark/cosmiconfig#explorersearch) for details on how the resolving works. + +```js +prettier.resolveConfigFile().then(filePath => { + prettier.resolveConfig(filePath).then(options => { + const formatted = prettier.format(text, options); + }); +}); +``` + +Use `prettier.resolveConfigFile.sync([filePath])` if you'd like to use sync version. ## `prettier.clearConfigCache()` diff --git a/website/versioned_docs/version-stable/api.md b/website/versioned_docs/version-stable/api.md index f5468dd25..47d066ca3 100644 --- a/website/versioned_docs/version-stable/api.md +++ b/website/versioned_docs/version-stable/api.md @@ -59,16 +59,26 @@ 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.resolveConfigFile(filePath [, options])` +## `prettier.resolveConfigFile([filePath])` -`resolveConfigFile` can be used to find the path of the Prettier's configuration file will be used when resolving the config (i.e. when calling `resolveConfig`). A promise is returned which will resolve to: +`resolveConfigFile` can be used to find the path of the Prettier configuration file that will be used when resolving the config (i.e. when calling `resolveConfig`). A promise is returned which will resolve to: - The path of the configuration file. - `null`, if no file was found. The promise will be rejected if there was an error parsing the configuration file. -If `options.useCache` is `false`, all caching will be bypassed. +The search starts at `process.cwd()`, or at `filePath` if provided. Please see the [cosmiconfig docs](https://github.com/davidtheclark/cosmiconfig#explorersearch) for details on how the resolving works. + +```js +prettier.resolveConfigFile().then(filePath => { + prettier.resolveConfig(filePath).then(options => { + const formatted = prettier.format(text, options); + }); +}); +``` + +Use `prettier.resolveConfigFile.sync([filePath])` if you'd like to use sync version. ## `prettier.clearConfigCache()`