IntelliJ IDEA 2019.2 Help

ESLint

IntelliJ IDEA integrates with ESLint which brings a wide range of linting rules that can also be extended with plugins. IntelliJ IDEA shows warnings and errors reported by ESLint right in the editor, as you type. With ESLint, you can also use JavaScript Standard Style.

To view the description of a problem, hover over the highlighted code.

ESLint: errors and warnings are highlighted, the description of a problem is shown in a tooltip.

By default, IntelliJ IDEA marks detected problems based on the severity levels from the ESLint configuration. See Configuring ESLint highlighting to learn how to override these settings.

Installing ESLint

  1. In the embedded Terminal N/A, type one of the following commands:

    • npm install eslint -g for global installation.

    • npm install eslint --save-dev to install ESLint as a development dependency.

  2. Optionally, install additional plugins, for example, eslint-plugin-react to lint React applications.

Activating and configuring ESLint in IntelliJ IDEA

By default, IntelliJ IDEA uses the ESLint package from the project node_modules folder and the .eslint.* configuration file from the folder where the current file is stored. If no .eslint.* is found in the current file folder, IntelliJ IDEA will look for one in its parent folders up to the project root.

If you have several package.json files with ESLint listed as a dependency, IntelliJ IDEA starts a separate process for each package.json and processes everything below it. This lets you apply a specific ESLint version or a specific set of plugins to each path in a monorepo or a project with multiple ESLint configurations.

This behavior is default in all new IntelliJ IDEA projects. To enable it in a previously created project, go to Languages and Frameworks | JavaScript | ESLint in the Settings/Preferences dialog N/A and select the Automatic ESLint configuration option.

You can also configure ESLint manually to use a custom ESLint package and configuration.

  1. In the Settings/Preferences dialog N/A, go to Languages and Frameworks | JavaScript | ESLint.

  2. Select the Manual Configuration option to use a custom ESLint package and configuration.

  3. In the Node Interpreter field, specify the path to Node.js. If you followed the standard installation procedure, IntelliJ IDEA detects the path and fills in the field itself.

  4. In the ESLint Package field, specify the location of the eslint or standard package.

  5. Choose the configuration to use.

    • With Automatic search, IntelliJ IDEA looks for a .eslintrc file or tries to detect a configuration defined under eslintConfig in a package.json. IntelliJ IDEA first looks for a .eslintrc or package.json in the folder with the file to be linted, then in its parent folder, and so on up to the project root.

    • Choose Configuration File to use a custom file and specify the file location in the Path field.

    Learn more about configuring ESLint from the ESLint official website.

  6. Optionally:

    • In the Extra ESLint Options field, specify additional command line options to run ESLint with, use spaces as separators.

      Learn more about ESLint CLI options from the ESLint official website.

    • In the Additional Rules Directory field, specify the location of the files with additional code verification rules. These rules will be applied after the rules from .eslintrc or the above specified custom configuration file and accordingly will override them.

Configuring highlighting for ESLint

By default, IntelliJ IDEA marks the detected errors and warnings based on the severity levels from the ESLint configuration. For example, errors are highlighted with a red squiggly line, while warnings are marked with a yellow background. See Code inspections and Change inspection severity for details.

To change the severity level of a rule in the ESLint configuration

In .eslintrc or under eslintConfig in package.json, locate the rule you want to edit and set its ID to 1 warn or to 2 error.

Learn more from the ESLint official website.

You can override the severities from the ESLint configuration so that IntelliJ IDEA ignores them and shows everything reported by the linter as errors, warnings, or in a custom color.

To ignore the severity levels from the configuration

  1. In the Settings/Preferences dialog N/A, select Editor | Inspections. The Inspections page opens.

  2. In the central pane, go to JavaScript | Code quality tools | ESLint.

  3. In the right-hand pane, clear the Use rule severity from the configuration file checkbox and select the severity level to use instead of the default one.

    Specifying a custom severity level for ESLint

Importing code style from ESLint

You can import some of the ESLint code style rules to the IntelliJ IDEA JavaScript code style settings. That enables IntelliJ IDEA to use more accurate code style options for your project when auto-completing, generating, or refactoring the code or adding import statements. When you use the Reformat action, IntelliJ IDEA will then no longer break properly formatted code from the ESLint perspective.

IntelliJ IDEA understands ESLint configurations in all official formats: .eslintrc JSON files, package.json files with the eslintConfig field, as well as JavaScript and YAML configuration files.

  • When you open your project for the first time, IntelliJ IDEA imports the code style from the project ESLint configuration automatically.

  • If your ESLint configuration is updated (manually or from your version control), open it in the editor and choose Apply ESLint Code Style Rules from the context menu.

    Importing ESLint code style rules from JavaScript or YAML configuration files

    Alternatively, just answer Yes to the "Apply code style from ESLint?" question on top of the file.

    IntelliJ IDEA suggests importing the code style from ESLint

    The list of applied rules is shown in the Event log tool window:

    Event log tool window shows the list of applied ESLint rules

Using JavaScript Standard Style

You can set JavaScript Standard Style as default JavaScript code style for your application so its main rules are applied when you type the code or reformat it. Since Standard is based on ESLint, you can also use Standard via the IntelliJ IDEA ESLint integration.

To install JavaScript Standard

In the embedded Terminal N/A, type:

npm install standard --save-dev

Learn more from the JavaScript Standard Style official website.

To enable linting with Standard via ESLint

If you open a project where standard is listed in the project's package.json file, IntelliJ IDEA enables linting with Standard automatically.

  1. In the Settings/Preferences dialog N/A, go to Languages and Frameworks | JavaScript | Code Quality Tools | ESLint.

  2. On the ESLint page that opens, select Manual ESLint configuration and specify the location of the standard package in the ESLint Package field.

To set the JavaScript Standard Style as default

  1. In the Settings/Preferences dialog N/A, go to Editor | Code Style | JavaScript).

  2. On the Code Style. JavaScript page that opens, click Set from, and then select Predefined Style | JavaScript Standard Style. The style will replace your current scheme.

Linting TypeScript code with ESLint

IntelliJ IDEA highlights errors reported by ESLint in .ts and .tsx files when @typescript-eslint/parser is set as a parser in your project ESLint configuration. Learn more from the readme file in the typescript-eslint repo.

To use ESLint for TypeScript in a new project

  1. In the embedded Terminal N/A, type:

    npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin --save-dev

  2. In the .eslintrc configuration file or under eslintConfig in package.json, add:

    { "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint"], "extends": ["plugin:@typescript-eslint/recommended"] }

To suppress linting TypeScript code with ESLint

If you are already using @typescript-eslint/parser but you do not want to check TypeScript code with ESLint, add .ts or .tsx to the .eslintignore file.

ESLint 4.0

If you are using previous versions of ESLint, you have to install babel-eslint, typescript-eslint-parser, or eslint-plugin-typescript because ESLint 4.0 and earlier do not support scoped packages.

To use babel-eslint

  1. In the embedded Terminal N/A, type:

    npm install eslint babel-eslint --save-dev

    Learn more about installation and versions compatibility from the babel-eslint official documentation.

  2. In the .eslintrc configuration file or under eslintConfig in package.json, add:

    { "parser":"babel-eslint" }

To use typescript-eslint-parser

  1. In the embedded Terminal N/A, type:

    npm install typescript-eslint-parser --save-dev

    Learn more from the typescript-eslint-parser official documentation.

  2. In the .eslintrc configuration file or under eslintConfig in package.json, add:

    { "parser":"typescript-eslint-parser" }

To use eslint-plugin-typescript

  1. In the embedded Terminal N/A, type:

    npm install typescript-eslint-parser eslint-plugin-typescript --save-dev

  2. In the .eslintrc configuration file or under eslintConfig in package.json, add:

    { "parser": "typescript-eslint-parser", "plugins": ["eslint-plugin-typescript"] }
Last modified: 19 August 2019

See Also