WebStorm 2020.1 Help

Keymap:

ESLint

WebStorm integrates with ESLint which brings a wide range of linting rules that can also be extended with plugins. WebStorm 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.

To resolve all the detected problems in the current file, click More actions (Alt+Enter) and select ESLint: Fix current file from the list.

You can also configure ESLint to fix all the problems in a file when this file is saved. To configure such behavior, select the Run eslint --fix on save checkbox on the ESLint page of the Settings dialog as described in Activating and configuring ESLint in WebStorm below.

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

Activating and configuring ESLint in WebStorm

By default, WebStorm 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, WebStorm 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, WebStorm 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 WebStorm projects. To enable it in a previously created project, go to Languages and Frameworks | JavaScript | Code Quality Tools | ESLint in the Settings/Preferences dialog Ctrl+Alt+S and select the Automatic ESLint configuration option.

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

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

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

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

Choose the configuration to use.

With Automatic search, WebStorm looks for a .eslintrc file or tries to detect a configuration defined under eslintConfig in a package.json. WebStorm 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.

To fix all detected problems automatically when your project files are saved, select the Run eslint --fix on save checkbox.

With this option on, ESLint will fix the problems every time your changes are saved either manually, with Ctrl+S, or automatically, when you launch a run/debug configuration, or close WebStorm, or perform version control actions, see Autosave for details.

Optionally:

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

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, WebStorm 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.

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 1warn or to 2error.

Ignore the severity levels from the configuration

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.

Importing code style from ESLint

You can import some of the ESLint code style rules to the WebStorm JavaScript code style settings. That enables WebStorm 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, WebStorm will then no longer break properly formatted code from the ESLint perspective.

WebStorm 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, WebStorm 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.

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

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

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 WebStorm ESLint integration.

Set the JavaScript Standard Style as default

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

Linting TypeScript code with ESLint

WebStorm 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.

Use ESLint for TypeScript in a new project

If you installed ESLint globally, install @typescript-eslint/eslint-plugin globally as well. Learn more about installation and versions compatibility from the @typescript-eslint/eslint-plugin official documentation.

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