Skip to content

Commit

Permalink
New: Add overrides and files configuration options (refs #3611)
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma authored and Sylvan Mably committed Feb 15, 2017
1 parent c7e64f3 commit 6460a0d
Show file tree
Hide file tree
Showing 15 changed files with 830 additions and 208 deletions.
55 changes: 55 additions & 0 deletions docs/user-guide/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,61 @@ module.exports = {
}
```

## Configuration Based on Glob Patterns

Sometimes a more fine-controlled configuration is necessary, for example if the configuration for files within the same directory has to be different. Therefore you can provide configurations under the `overrides` key that will only apply to files that match specific glob patterns, using the same format you would pass on the command line (e.g., `app/**/*.test.js`).

### How it works

* Glob pattern overrides can only be configured within `.eslintrc` files.
* The patterns are applied against the file path relative to the directory of the `.eslintrc` file. For example, if your `.eslintrc` file has the path `/Users/john/workspace/any-project/.eslintrc` and the file you want to lint has the path `/Users/john/workspace/any-project/lib/util.js`, then the pattern provided in `.eslintrc` will be executed against the relative path `lib/util.js`.
* Glob pattern overrides have higher precedence than the regular configuration in the same `.eslintrc` file.
* A glob specific configuration works almost the same as the regular configuration in your `.eslintrc`, except that you can't define nested glob based configurations or use `extends`.
* Multiple glob patterns can be provided within a single override block. The associated configuration will be applied to the intersection of the sets of files matched by each of the patterns. In other words, a file must match all the supplied patterns for the configuration to apply.

### Relative glob patterns

```
project-root
├── app
│ ├── lib
│ │ ├── foo.js
│ │ ├── fooSpec.js
│ ├── components
│ │ ├── bar.js
│ │ ├── barSpec.js
│ ├── .eslintrc
├── server
│ ├── server.js
│ ├── serverSpec.js
├── .eslintrc
```

The config in `app/.eslintrc` defines the glob pattern `**/*Spec.js`. This pattern is relative to the base directory of `app/.eslintrc`. So, this pattern would match `app/lib/fooSpec.js` and `app/components/barSpec.js` but **NOT** `server/serverSpec.js`. If you defined the same pattern in the `.eslintrc` file within in the `project-root` folder, it would match all three of the `*Spec` files.

### Example configuration

In your `.eslintrc`:

```json
{
"rules": {
"quotes": [ 2, "double" ]
},

"overrides": [
{
"files": [ "lib/*.jsx" ],
"config": {
"rules": {
"quotes": [ 2, "single" ]
}
}
}
]
}
```

## Comments in Configuration Files

Both the JSON and YAML configuration file formats support comments (`package.json` files should not include them). You can use JavaScript-style comments or YAML-style comments in either type of file and ESLint will safely ignore them. This allows your configuration files to be more human-friendly. For example:
Expand Down

0 comments on commit 6460a0d

Please sign in to comment.