Skip to content

Instantly share code, notes, and snippets.

@igorparrabastias
Last active September 21, 2022 21:34
Show Gist options
  • Save igorparrabastias/c7cc59ff5c61fd8c89bb7ada7680e8d1 to your computer and use it in GitHub Desktop.
Save igorparrabastias/c7cc59ff5c61fd8c89bb7ada7680e8d1 to your computer and use it in GitHub Desktop.

Init project

npm init

Add basics packages

yarn add eslint jest nodemon -D

Install eslint globally

npm install eslint -g

Init eslint creating .eslintrc.js for node.js, commonjs (useful for generic modules) ans standard code style

$ eslint --init
You can also run this command directly using 'npm init @eslint/config'.
npx: installed 40 in 1.055s
✔ How would you like to use ESLint? · style
✔ What type of modules does your project use? · commonjs
✔ Which framework does your project use? · none
✔ Does your project use TypeScript? · No / Yes
✔ Where does your code run? · node
✔ 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

Checking peerDependencies of eslint-config-standard@latest
The config that you've selected requires the following dependencies:

eslint-config-standard@latest eslint@^8.0.1 eslint-plugin-import@^2.25.2 eslint-plugin-n@^15.0.0 eslint-plugin-promise@^6.0.0
✔ Would you like to install them now? · No / Yes
✔ Which package manager do you want to use? · yarn
Installing eslint-config-standard@latest, eslint@^8.0.1, eslint-plugin-import@^2.25.2, eslint-plugin-n@^15.0.0, eslint-plugin-promise@^6.0.0
...
Successfully created .eslintrc.js file in /media/nomikos/home/nomikos2/dev/pruebas-trabajo/amazon-sde/plusMinus

ref: https://dev.to/devdammak/setting-up-eslint-in-your-javascript-project-with-vs-code-2amf

Adding Code Actions on Save (vscode)

In settings.json paste the following code:

.vscode/settings.json
{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.validate": ["javascript"]
 }

ref: https://www.digitalocean.com/community/tutorials/workflow-auto-eslinting


Using eslint standard style in vscode without package.json

In many occasions you just want edit some single js files without all the paraphernalia

  1. Install standard globally
npm install standard --global
  1. Install vscode standardjs extension https://marketplace.visualstudio.com/items?itemName=standard.vscode-standard

  2. Customize vscode-standard in your VSCode settings.json.

standard.enable: true
standard.enableGlobally: true
standard.autoFixOnSave: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment