Website: Update documentation of `resolveConfigFile` (#6568)

master
Sosuke Suzuki 2019-10-03 00:34:58 +09:00 committed by Simon Lydell
parent fced57c1d6
commit 1aef2b13f4
2 changed files with 26 additions and 6 deletions

View File

@ -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()`

View File

@ -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()`