-
Notifications
You must be signed in to change notification settings - Fork 2
How to setup your IDE for correct linting
This project has linting setup for Vue/GQL/JS/SCSS/CSS and HTML using Prettier and ESLint. The ruleset is the Vue style guide "Recommended" spec.
Behind the scenes, the workflow is this: Ugly code > Prettier > ESLint > Nice code!
The idea is that Prettier formats things like CSS and GQL nicely, and ESLint goes last and does everything else. This allows us to config ESLint to the Vue specs (Prettier has little config options by design). So that is what the .eslintrc.js
file is for.
In your code editor, you'll want to install a Prettier Eslint plugin and "Format on Save" to true
. The settings for "prettier-eslint” should have a toggle for "Run Prettier Last", you want that set to false
. Although often times this is the default setup for plugins. We need ESLint to run last, this ensures the Vue Recommended specs get priority, not Prettier's specs.
The 4 devDependencies
installed in the package are "eslint", "eslint-plugin-vue", "prettier" and "prettier-eslint". The "prettier" plugin is not required as most editor plugins will use a default version they ship with, although we have more control over the version of Prettier if we include it in the package file, so we include it to be safe. It also means it would run the same server side or client side if you do that as part of CI. "prettier-eslint" is used to integrate "prettier" and "eslint" together, and get them running one after the other.
- Delete the
.vscode
file from your repo - Install the Prettier-ESlint extension
- Install the Vetur extension
- Install Vue Dev tools for your browser.
- Open a component such as
ExampleComponent.vue
and CMD + Shift + P to open the command palette - Search
Format Document With
and select it - Choose the bottom item
Configure Default Formatter
- Choose
Prettier ESLint
- Open Code > Preferences > Settings
- Type
Format on
and select it - Check
Format on Save
- Go to Code > Preferences > Settings
- Under Extensions, select Vetur
- Set Formatter > Default Formatter: JS as
Prettier ESLint