'Different eslint rules based on file extension
Is it possible to have different rules applied to files based on their files extension? For example I have [test].spec.js test spec files residing along my source code, but I like to add rules that only apply to them only.
Solution 1:[1]
Currently it's not possible, unless you create multiple configuration files and run eslint with correct globs for each file type separately. However, there's an open PR here: https://github.com/eslint/eslint/pull/8081 to add this functionality.
Solution 2:[2]
This was added. Docs here
example from the docs
{
"rules": {
"quotes": [ 2, "double" ]
},
"overrides": [
{
"files": [ "bin/*.js", "lib/*.js" ],
"excludedFiles": "*.test.js",
"rules": {
"quotes": [ 2, "single" ]
}
}
]
}
Effecitively you can supply globs and a set of rules that override the default rules for files that match each glob.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ilya Volodin |
Solution 2 |