Enabling ESLint on Intellij & VSCode
Tags: vue, eslint, vscode, intellij
Published: 2021-02-26 16:03:02

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)
<figure>
  <img alt="IntelliJ Settings on Windows" src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x3nuss9ic7o996sijvt7.png">
  <figcaption>Forgive me for I am but a Windows pleb</figcaption>
</figure>

2. Go to **Language & Frameworks > Javascript > Code Quality Tools > ESLint**
<figure>
  <img alt="ESLint Settings in IntelliJ" src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4b3hnbb24zd8rfwbt2b5.png">
  <figcaption>Ensure this option is checked</figcaption>
</figure>

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.
<figure>
  <img alt="ESlint showing errors" src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lkcxcz33h46ynx9v5zrk.png">
  <figcaption>Fix your mistakes, noobs</figcaption>
</figure>

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**.
<figure>
  <img alt="ESLint VSCode Extension by Dirk Baeumer" src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ocmt3i0txlib1awnnk5.png">
  <figcaption>Can't go wrong when it's been  installed over 13 million times</figcaption>
</figure>

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**
<figure>
  <img alt="VSCode Command Palette" src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bxuaniml1qwwtrt7k4c.png">
  <figcaption>...Or you can hit Ctrl + Shift + P</figcaption>
</figure>

2. Search for this Command: "**ESLint: Manage Library Execution**"
<figure>
  <img alt="Managing ESLint Library Execution" src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sz6z2gqfz8c5nxbkoi22.png">
  <figcaption>Allowing ESLint Extension to run in your project</figcaption>
</figure>

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.
<figure>
  <img alt="Allowing extension execution in Project" src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpz72onubx881bhl3f8h.png">
  <figcaption>Allow... Everywhere? 🤔</figcaption>
</figure>

4. Now just open up your Javascript files and start fixing up any mistakes the linter picks up!
<figure>
  <img alt="Allowing extension execution in Project" src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abishmuoos17ig1da7nc.png">
  <figcaption>ESLint: "REEEEEEEEEEEEEeeeee..."</figcaption>
</figure>


##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](https://eslint.vuejs.org/user-guide/#editor-integrations), 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.
```json
{
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "vue"
  ],
  "vetur.validation.template": false
}
```
The `vetur` setting is if you have the vetur plugin installed.

And that's it! Happy Linting!