Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which eslint rules in my config are slow?

I have a config with around 100 rules, and running eslint on my project with all these rules takes around 10 seconds. I'd like to identify the slowest rules and eliminate some of them. How do I do this? Is there any profiler tool for eslint?

like image 976
mik01aj Avatar asked Jul 19 '16 12:07

mik01aj


People also ask

How can I speed up my ESLint?

Speeding up ESLint Execution One of the most convenient ways to speed up ESLint execution on big projects is to run it on only files that have been changed while you are working. It's possible to achieve this by using lint-staged. The exact technique is covered in the Automation chapter.

Why is ESLint taking so long?

The cause of the slow ESLint runtime with eslint-plugin-prettier is because that plugin also runs Prettier under the hood to detect and raise issues when the code differs from Prettier's expected output.

What does 2 mean in ESLint rules?

I defines the severity of a rule. Severity should be one of the following: 0 = off, 1 = warning, 2 = error (you passed "3"). Documentation: https://eslint.org/docs/user-guide/configuring/rules.

Where are ESLint rules set?

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.


1 Answers

eslint shows the spent times of rules if the environment variable TIMING is set. For example:

$ TIMING=1 eslint lib Rule                         | Time (ms) | Relative :----------------------------|----------:|--------: valid-jsdoc                  |   203.798 |     6.7% camelcase                    |   142.146 |     4.6% no-unmodified-loop-condition |   136.811 |     4.5% indent                       |   127.138 |     4.2% no-undefined                 |   124.525 |     4.1% keyword-spacing              |    85.397 |     2.8% space-in-parens              |    76.179 |     2.5% no-this-before-super         |    72.317 |     2.4% no-implied-eval              |    69.945 |     2.3% space-infix-ops              |    57.128 |     1.9% 

See also the official docs on Per-rule Performance.

like image 117
mysticatea Avatar answered Sep 23 '22 03:09

mysticatea