To make the whole developer experience more pleasant and convenient, it is important to configure your code editor of choice integrate with ESLint. The following can be achieved with most editors:
- Show errors/warnings inline with your code, as you type/on save
- Fix some issues immediately after saving the file so you do not have to do it manually
Letting your editor fix some issues will increase your productivity and code quality dramatically.
Install the following packages:
For the linter package, these settings are recommended:
- Lint as you type
- Do not lint files ignored by VCS
For the linter-eslint package, these settings are recommended:
- Disable when no eslintrc file in PATH
- Fix errors on save
- Ignore fixable rules while typing
Install the following packages:
Put the following configuration options into your settings.json file:
"eslint.autoFixOnSave": true
For best results, make sure you have Package Control installed in your Sublime Text. Issue reports and autofix on save are handled by two different packages, so you will need to configure both for best developer experience.
Install the following packages:
Make sure ESLint does not lint files in node_modules folder: (Preferences
-> Package Settings
-> SublimeLinter
-> Settings - User
):
"linters": {
"eslint": {
"@disable": false,
"exludes": [
"node_modules"
]
}
}
Enable autofix on save (Preferences
-> Package Settings
-> ESLint Formatter
-> Settings - User
):
{
"format_on_save": true
}
WebStorm has built-in support for ESLint issue reporting. Auto fixing is only supported in versions 2016.3 and newer.
To enable ESLint reporter, follow the guide on WebStorm's support page. To use the new autofix feature, read their blog post on the topic.
To use autofix on save feature:
- Go to
Preferences
->Tools
->File watchers
- Click the
Add
(+) button and choose custom template - Name it for example
eslint
- Set file type to
javascript
- Program will be your path to eslint binary for example
/Users/[yourusername]/git/[yourproject]/node_modules/.bin/eslint
- Arguments
--fix $FilePath$
- Working directory
$ProjectFileDir$
- Show console
never
(if you don't want to see the console when--fix
command finds errors) - Check
Trigger watcher regardless of syntax errors
and uncheckImmediate file synchronization