DEV Community

loading...
Cover image for Enabling ESLint on Intellij & VSCode

Enabling ESLint on Intellij & VSCode

blaytenshi profile image Jimmy Tang ・3 min read

ESLint is a pretty cool tool that cleans up your Javascript code for you! But when you're deving on an IDE such as IntelliJ/WebStorm/VSCode, who wants to be running npm run lint all the time am I right?

"Would be pretty awesome to have my IDE run my linting automatically... But how?" - You.

You've come to the right place my friend! 🎉

IntellJ/WebStorm

Let's start with IntelliJ first because it's the easiest! It's usually already set up on IntelliJ (and subsequently WebStorm). In case it isn't, here are the steps to enable it.

I'm assuming you already have a .eslintrc.* file in your project root directory. This is usually standard practice. If not, make one and put all your settings in there!

For context, the project I'll be using in this example is a Vue project.

  1. Find your Settings (where this is differs for Windows/OSX)

    IntelliJ Settings on Windows
    Forgive me for I am but a Windows pleb
  2. Go to Language & Frameworks > Javascript > Code Quality Tools > ESLint

    ESLint Settings in IntelliJ
    Ensure this option is checked
  3. Make sure that the "Automatic ESLint configuration" is checked! Like the screenshot says, it will use the ESLint package as well as the .eslintrc.* to run the linter.

    ESlint showing errors
    Fix your mistakes, noobs
  4. Now, in the files that you work on, the IDE will pick up any mistakes you made and highlight them for you to fix up! Easy!

VSCode

VSCode is a little trickier to set up as it doesn't come with a tool to run ESLint out of a box. You have to install it as an extension.

The most popular ESLint extention by far is ESLint by Dirk Baeumer.

ESLint VSCode Extension by Dirk Baeumer


Can't go wrong when it's been installed over 13 million times

Once it is installed, make sure it is enabled (by clicking on the Enable button if it isn't already), and just like the setup for IntelliJ, check that your .eslintrc.* file is in your project root!

  1. Open the Command Palette

    VSCode Command Palette
    ...Or you can hit Ctrl + Shift + P
  2. Search for this Command: "ESLint: Manage Library Execution"

    Managing ESLint Library Execution
    Allowing ESLint Extension to run in your project
  3. A popup like below should show up asking if you want to allow the ESLint extension to run the ESLint you've installed in your project using the .eslintrc.* config file. This is different to clicking the 'Enable' button after you install the ESLint Extension so make sure you don't skip this step! As for which option you should pick. Allow Everywhere enables ESLint for all workspaces (or projects) which is useful if all your project happen to be Javascript based. Otherwise Allow will just enable it for this project and you have to repeat these steps for all subsequent projects.

    Allowing extension execution in Project
    Allow... Everywhere? 🤔
  4. Now just open up your Javascript files and start fixing up any mistakes the linter picks up!

    Allowing extension execution in Project
    ESLint: "REEEEEEEEEEEEEeeeee..."

Linting .vue files!

If you're linting .vue files like I am, the ESLint extension doesn't pick up Vue SFC files. If your project is pure Javascript or React, you don't need to worry about this extra step!

According to the official eslint-plugin-vue guide here, we need to create a .vscode folder in the root directory of the project and within it, create a settings.json file.

Inside that file, you'll need to add a bit of extra config for the ESLint plugin to pick up .vue files.

{
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "vue"
  ],
  "vetur.validation.template": false
}
Enter fullscreen mode Exit fullscreen mode

The vetur setting is if you have the vetur plugin installed.

And that's it! Happy Linting!

Discussion (0)

pic
Editor guide