Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 261
calebo Avatar asked Mar 01 '17 03:03

calebo


People also ask

How many ESLint rules are there?

Keep in mind that we have over 200 rules, and that is daunting both for end users and the ESLint team (who has to maintain them).

How do you set rules in ESLint?

ESLint comes with a large number of built-in rules and you can add more rules through plugins. You can modify which rules your project uses either using configuration comments or configuration files. To change a rule setting, you must set the rule ID equal to one of these values: "off" or 0 - turn the rule off.

How do you customize ESLint?

There are two primary ways to configure ESLint: Configuration Comments - use JavaScript comments to embed configuration information directly into a file. Configuration Files - use a JavaScript, JSON, or YAML file to specify configuration information for an entire directory and all of its subdirectories.


2 Answers

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.

like image 125
gman Avatar answered Sep 18 '22 12:09

gman


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.

like image 24
Ilya Volodin Avatar answered Sep 17 '22 12:09

Ilya Volodin