How to make WebStorm format code according to eslint?

SiberianGuy picture SiberianGuy · Jan 19, 2017 · Viewed 34.1k times · Source

I've specified eslint configuration for my WebStorm project. But it does not seem to apply to code reformat feature. For example, it continues to format import { something } from 'somewhere' as import {something} from 'somewhere'.

Is there a way to make WebStorm to format code according to eslint configuration?

Answer

phse picture phse · Sep 7, 2017

(Described steps and screenshots are from IntelliJ IDEA 2017.2)

You can add a keyboard shortcut to action 'Fix ESLint Problem'. Ensure plugin 'JavaScript Support' is installed and enabled.

First got to Preferences | Language & Frameworks | JavaScript | Code Quality Tools | ESLint and enable it. You will need to define your 'Node interpreter', 'ESlint package' and optional 'Configuration file'.

enter image description here

Next go to Preferences | Keymap and search there for 'eslint'. Now you can add for example the shortcut 'control + shift + L'.

enter image description here