RustRover 2024.2 Help

ESLint

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

Besides JavaScript and TypeScript, ESLint can be applied to files of other types in the entire project or in its specific parts, refer to Configure linting scope.

Before you start

  1. Download and install Node.js.

  2. Configure a Node.js interpreter in your project as described in Configuring a local Node.js interpreter, or in Using Node.js on Windows Subsystem for Linux, or in Configuring remote Node.js interpreters.

Install ESLint

  1. In the embedded Terminal (Alt+F12) , type one of the following commands:

    • npm init @eslint/config@latest to install ESLint in the current project and generate a configuration file.

      Answer the questions of the wizard. As a result, RustRover installs the latest version of ESLint and generates a eslint.config.js configuration file.

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

    • npm install --g eslint for global installation.

    • pnpm create @eslint/config@latest to install ESLint in the current project and generate a configuration file.

      Answer the questions of the wizard. As a result, RustRover installs the latest version of ESLint and generates a eslint.config.js configuration file.

    • pnpm add -D eslint to install ESLint as a development dependency.

    • pnpm add -g eslint for global installation.

    • yarn create @eslint/config to install ESLint in the current project and generate a configuration file.

      Answer the questions of the wizard. As a result, RustRover installs the latest version of ESLint and generates a eslint.config.js configuration file.

    • yarn add -D eslint to install ESLint as a development dependency.

    • yarn add eslint for global installation.

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

Learn more from the ESLint official website.

Activate and configure ESLint in RustRover

By default, ESLint is configured automatically. You can choose to specify all the configuration settings manually or disable ESLint.

Supported formats of configuration files

Depending on the ESLint version you are using, RustRover recognizes configurations in the following file types:

ESLint version 8 and earlier

  • .eslintrc.* (.eslintrc,, .eslintrc.json, or .eslintrc.yaml file, or a file in another supported format).

  • .eslintignore

  • package.json with a eslintIgnore or a eslintConfig property. This configuration system is deprecated, learn more from the ESLint official website.

ESLint version 9 and later

eslint.config.js, eslint.config.mjs, or eslint.config.cjs (flat format), learn more from the ESLint official website.

You can also use configuration files written in TypeScript, such as, eslint.config.ts, eslint.config.mts, or eslint.config.cts. To do that, you need to specify the unstable_ts_config flag.

  1. Press Ctrl+Alt+S to open settings and then select Languages & Frameworks | JavaScript | Code Quality Tools | ESLint.

  2. Select Manual ESLint Configuration.

  3. In the Extra eslint options field, type --flag unstable_ts_config.

  4. Click Apply to save the changes and close the dialog.

Configure ESLint automatically

With automatic configuration, RustRover uses the ESLint package from the project node_modules folder and the configuration file from the folder where the current file is stored. If no configuration file is found in the current file folder, RustRover 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, RustRover 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.

  • To configure ESLint automatically in the current project, open the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | JavaScript | Code Quality Tools | ESLint, and select the Automatic ESLint configuration option.

  • To configure ESLint automatically in all new projects, open the Settings for New Projects dialog (File | New Projects Setup | Settings for New Projects) , go to Languages & Frameworks | JavaScript | Code Quality Tools | ESLint, and select the Automatic ESLint configuration option.

Configure ESLint manually

With manual configuration, you can use a custom ESLint package, configuration file, and working directories, as well as apply various additional rules and options.

  1. In the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | JavaScript | Code Quality Tools | ESLint, and select Manual ESLint configuration.

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

  3. In the Working directories field, specify the working directories for the ESLint process.

    By default, the field is empty, and RustRover detects the working directory automatically. First, it looks for a directory closest to the linted file which contains a configuration file.

    If the auto-detected working directory doesn't match your project configuration, you need to specify the working directory (directories) manually. Use semicolons as separators. The acceptable values are:

    • Absolute paths.

    • Paths relative to the project base directory (the parent folder of the .idea folder where RustRover-specific project metadata is stored). For example:

      1. ./: use the project base directory as the ESLint process working directory.

      2. client;server: use <project_base_dir>/client and <project_base_dir>/server as working directories. For files that are neither under the client not under the server folder, the working directory will be auto-detected as described above.

      3. packages/*: each subfolder of the <project_base_dir>/packages directory will be used as the working directory for the corresponding linted files.

    • Paths relative to content roots can be used if some linted files are not under the project base directory in the folder hierarchy.

    • Glob patterns that define relative paths to the working directories. For example, with **/foo -* each directory with the name starting with foo- will be used as the working directory for the corresponding linted files.

  4. Choose the configuration to use.

    • Automatic search: select this option if ESLint rules are configured in a configuration file of a supported format.

      RustRover looks for such file starting from the folder where the file to be checked is stored, then searches in its parent folder, and so on until the project root is reached.

    • Configuration File - select this option to use a custom file and specify the file location in the Path field.

    Learn more about configuring ESLint from the ESLint official website.

  5. Optionally:

    • In the Extra eslint options field, specify additional command-line options to run ESLint with, use spaces as separators. For example, to use configuration files written in TypeScript, type --flag unstable_ts_config.

      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 the default configuration file or from a custom configuration file and accordingly will override them.

      See the ESLint official website for more information about ESLint configuration files and adding rules.

Configure linting scope

  1. Open the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | JavaScript | Code Quality Tools | ESLint, and select Automatic ESLint configuration or Manual ESLint configuration.

  2. In the Run for files field, specify the pattern that defines the set of files to be linted. You can accept the default pattern or type a custom one.

    With the default pattern, **/*.{js,ts,jsx,tsx,cjs,cts,mjs,mts,html,vue}, ESLint will wake up and process any updated JavaScript, TypeScript, JSX, TSX, HTML, or Vue file. To lint files of other types or files stored in specific folders, use glob patterns to update the default pattern.

    • For example, to automatically lint CoffeeScript files as well, add coffee to the default pattern as follows:

      **/*.{js,ts,jsx,tsx,cjs,cts,mjs,mts,html,vue,coffee}
    • To lint files from a specific folder, including subfolders, replace **/* with <path to the folder>/**/*.

      Suppose, you have a project with the following structure:

      ESLint: custom patterns. Example project structure

      To lint only the files in the coffee folder, update the pattern as follows:

      coffee/*.{js,ts,jsx,tsx,cjs,cts,mjs,mts,html,vue,coffee}

      As a result, the file linting.coffee is linted while no_linting .coffee is not.

Fix problems automatically on save

ESLint can fix the detected problems every time your changes are saved either manually, with Ctrl+S, or automatically, when you launch a run/debug configuration, or close RustRover, or perform version control actions For more information, refer to Autosave.

  • Open the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | JavaScript | Code Quality Tools | ESLint, and select the Run eslint --fix on save checkbox.

Lint your code

When installed and enabled, ESLint activates automatically every time you open a JavaScript file.

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

Descriptions of the errors detected in the current file and quick-fixes for them are available from the editor and from the File tab of the Problems tool window.

Errors in all previously opened files and quick-fixes for them are shown in the Project Errors tab of the Problems tool window. To open the tool window, click the Inspection widget in the upper-right corner of the editor:

Inspection widget

For more information, refer to View problems and apply quick-fixes in the editor and Problems tool window.

View problems and apply quick-fixes in the editor

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

    To resolve the detected problem, click ESLint: Fix '<rule name>' or press Alt+Shift+Enter.

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

    ESLint: resolving problems

    For more information, refer to View problems and apply quick-fixes in the editor.

  • Alternatively, open the File tab of the Problems tool window Alt+6, where you can view problem descriptions, apply quick-fixes, navigate to the fragments in the source code where errors occurred, as well as fix them in the Editor Preview pane without leaving the tool window. Learn more from Problems tool window.

  • 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 RustRover.

Lint your code in the Problems tool window

To open the Problems tool window, click the Inspections widget in the upper-right corner of the editor.

Inspection widget

Alternatively select View | Tool windows | Problems from the main menu or press Alt+6.

The Project Errors tab shows the errors in all files that were opened during the current session, with error messages grouped by files in which they were detected.

Problems tool window, ESLint. Project Errors tab shows syntax errors in previously opened files across the project

Here you can view problem descriptions, apply quick-fixes, navigate to the fragments in the source code where errors occurred, as well as fix them in the Editor Preview pane without leaving the tool window. Learn more from Problems tool window.

Configure highlighting for ESLint

By default, RustRover 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.

Change the severity level of a rule in the ESLint configuration

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

Ignore the severity levels from the configuration

  1. In the Settings dialog (Ctrl+Alt+S) , 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

Import code style from ESLint

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

RustRover understands ESLint configurations in all official formats:

  • eslint.config.js, eslint.config.mjs, or eslint.config.cjs (flat format) for ESLint version 9 and later.

  • .eslintrc files for ESLint version 8 and earlier.

  • package.json files with the eslintConfig property.

Learn more from the ESLint official website.

  • When you open your project for the first time, RustRover 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.

    RustRover 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

Use 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 RustRover ESLint integration.

Install JavaScript Standard

Enable linting with Standard via ESLint

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

  1. In the Settings dialog (Ctrl+Alt+S) , go to Languages & 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.

Set the JavaScript Standard Style as default

  1. In the Settings dialog (Ctrl+Alt+S) , go to Editor | Code Style | JavaScript.

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

Last modified: 11 October 2024