2017-11-07 14:39:07 +11:00
---
id : configuration
title : Configuration File
---
2017-11-22 19:27:40 +08:00
Prettier uses [cosmiconfig ](https://github.com/davidtheclark/cosmiconfig ) for configuration file support. This means you can configure prettier via:
2017-11-07 14:39:07 +11:00
2018-05-27 15:37:44 -03:00
- A `.prettierrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js` .
- A `prettier.config.js` file that exports an object.
- A `"prettier"` key in your `package.json` file.
2017-11-07 14:39:07 +11:00
2017-11-22 19:27:40 +08:00
The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found.
2017-11-07 14:39:07 +11:00
2017-11-20 12:26:33 -08:00
The options to the configuration file are the same as the [API options ](options.md ).
2017-11-07 14:39:07 +11:00
## Basic Configuration
JSON:
```json
{
"printWidth" : 100 ,
"parser" : "flow"
}
```
2017-12-26 00:26:09 -07:00
JS:
```js
// .prettierrc.js
module . exports = {
printWidth : 100 ,
parser : "flow"
};
```
2017-11-07 14:39:07 +11:00
YAML:
```yaml
# .prettierrc
printWidth : 100
parser : flow
```
## Configuration Overrides
2017-11-22 19:27:40 +08:00
Prettier borrows eslint's [override format ](http://eslint.org/docs/user-guide/configuring#example-configuration ). This allows you to apply configuration to specific files.
2017-11-07 14:39:07 +11:00
JSON:
```json
{
"semi" : false ,
2017-11-22 19:27:40 +08:00
"overrides" : [
{
"files" : "*.test.js" ,
"options" : {
"semi" : true
}
2017-11-07 14:39:07 +11:00
}
2017-11-22 19:27:40 +08:00
]
2017-11-07 14:39:07 +11:00
}
```
YAML:
```yaml
semi : false
overrides :
- files : "*.test.js"
options :
semi : true
```
2017-11-22 19:27:40 +08:00
`files` is required for each override, and may be a string or array of strings. `excludeFiles` may be optionally provided to exclude files for a given rule, and may also be a string or array of strings.
2017-11-07 14:39:07 +11:00
To get prettier to format its own `.prettierrc` file, you can do:
```json
{
2017-11-22 19:27:40 +08:00
"overrides" : [
{
"files" : ".prettierrc" ,
"options" : { "parser" : "json" }
}
]
2017-11-07 14:39:07 +11:00
}
```
For more information on how to use the CLI to locate a file, see the [CLI ](cli.md ) section.
## Configuration Schema
If you'd like a JSON schema to validate your configuration, one is available here: http://json.schemastore.org/prettierrc.