Which eslint rules in my config are slow?

JavascriptProfilingConfiguration FilesEslint

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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.

Solution 2 - Javascript

I found that removing slow rules didn't really help that much, as loading eslint and parsing files takes a while.

It is possible to use the --cache option of eslint (docs) to speed things up substantially.

When using eslint to "lint-as-you-type" in various editors, installing eslint_d allows running eslint as a daemon, and saves the node loading time.

On the project I'm currently working on, combining both eslint_d and --cache brought the linting time from 4+ seconds to 0.17!

Solution 3 - Javascript

In my case I'm using @typescript-eslint/eslint-plugin (linting with type information) and I'd misconfigured the tsconfig include field. Based on this doc you have to include all your files. So I updated my eslint configuration:

module.exports = {
overrides: [
{
files: ['*.ts'],
parserOptions: {

  •   <s>project: ['tsconfig.json'],</s>
    
  •   <s>createDefaultProgram: true,</s>
    
  •   project: ['tsconfig.json', './projects/*/tsconfig.json'],
    
  •   createDefaultProgram: false,
    },
    
    } ] }

This can also happen if you're using @angular-eslint/eslint-plugin. Read the performance section of their docs

Solution 4 - Javascript

I encountered this issue as well, this was because I enabled createDefaultProgram: true, removing it increased my performances significantly !!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmik01ajView Question on Stackoverflow
Solution 1 - JavascriptmysticateaView Answer on Stackoverflow
Solution 2 - JavascriptLaurent SView Answer on Stackoverflow
Solution 3 - JavascriptVahidView Answer on Stackoverflow
Solution 4 - JavascriptYohan DahmaniView Answer on Stackoverflow