Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending multiple recommended configurations in ESLint

The Story:

Currently, we are extending the recommended ESLint configuration:

{
  "extends": "eslint:recommended",
  ...
  "plugins": [
    "angular",
    "jasmine",
    "protractor"
  ],
  "rules": {
    "no-multiple-empty-lines": 2,
    "no-trailing-spaces": 2,
    "jasmine/valid-expect": 2
  }
}

And also using angular, jasmine and protractor ESLint plugins which also ship with their own recommended configurations (default rule strictness levels and default rule parameters).

The Question:

How can we use all the recommended configurations at the same time - the one that ESLint and all the used plugins ship with?


Tried the following:

{
  "extends": [
    "eslint:recommended",
    "plugin:protractor/recommended",
    "plugin:jasmine/recommended",
    "plugin:angular/recommended"
  ],
  ...
}

but got the following error:

Cannot read property 'recommended' of undefined

like image 474
alecxe Avatar asked Mar 26 '16 17:03

alecxe


People also ask

How does ESLint extend work?

extends uses a config file which applies set of rules when you add that to the extends options. A plugin on the other hand provides you with a set of rules that you can individually apply depending on your need. Just having a plugin does not enforce any rule. You have to choose which rules you need.

How do I make ESLint run faster?

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.

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.

What format do you want your config file to be in ESLint?

ESLint configuration rules can be modified in the . eslintrc. json file.


1 Answers

How can we use all the recommended configurations at the same time - the one that ESLint and all the used plugins ship with?

Your syntax is correct, and multiple extensions are loaded like this:

{
  "extends": [
    "eslint:recommended",
    "plugin:protractor/recommended",
    "plugin:jasmine/recommended",
    "plugin:angular/recommended"
  ]
}

However, this requires that the plugins in question actually come bundled with recommended settings. eslint-plugin-angular does not, and you have to install it yourself:

npm install --save-dev eslint-config-angular

Change your eslint settings to

{
  "extends": [
    "eslint:recommended",
    "plugin:protractor/recommended",
    "plugin:jasmine/recommended",
    "angular"
  ]
}

and it should work.

like image 133
dannyjolie Avatar answered Sep 28 '22 10:09

dannyjolie