Skip to content

Instantly share code, notes, and snippets.

@rmrfslashbin
Last active December 29, 2020 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmrfslashbin/cb423020aed3672cc9a2fc2266251ebf to your computer and use it in GitHub Desktop.
Save rmrfslashbin/cb423020aed3672cc9a2fc2266251ebf to your computer and use it in GitHub Desktop.
ESLint fix-on-save for VSCode

ESLint fix-on-save for VSCode

This brief guide will enable fix-on-save in VScode for js and vue files.

Install ESLint

ESLint needs to be installed twice: once inside your project and once globally.

# Install globally
$ npm install -g eslint

# Install in project
$ cd ~/src/my-project
$ npm install eslint

Config ESLint

Next, in your project directory, run npx eslint --init. Follow the prompts to set up ESlint per your project needs. For my needs, I selected:

✔ How would you like to use ESLint? · style
✔ What type of modules does your project use? · esm
✔ Which framework does your project use? · vue
✔ Does your project use TypeScript? · No / Yes
✔ Where does your code run? · browser
✔ How would you like to define a style for your project? · guide
✔ Which style guide do you want to follow? · standard
✔ What format do you want your config file to be in? · JavaScript

After installing additional packages, a config file (.eslintrc.js) should generated.

VSCode Setup

module.exports = {
env: {
browser: true,
es2021: true
},
extends: [
'plugin:vue/essential',
'standard'
],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
plugins: [
'vue'
],
rules: {
}
}
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "vue"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment