ESLint and Prettier are 2 importants tools in the JS tools belt. How to make them aware of each other? Here is how.
From:
- https://gist.github.com/bradtraversy/aab26d1e8983d9f8d79be1a9ca894ab4
- https://dev.to/chgldev/getting-prettier-eslint-and-vscode-to-work-together-3678
yarn add -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-node eslint-config-node
Usage of AirBnB's ESLint rules, for example.
npx install-peerdeps --dev eslint-config-airbnb
NB:
- npx may propose to use yarn. Say yes
- VSCode at the end, may display a popup noticing that "The ESLint extension will use 'node_modules/eslint' for validation'. Say Allow to activate ESLint in VSCode.
{
"extends": [
"plugin:prettier/recommended"
],
"printWidth": 120,
"parser": "typescript",
"semi": false,
"tabWidth": 2,
"trailingComma": "all"
}
I like this sober configuration with no semicolon.
{
"extends": ["airbnb", "prettier", "plugin:node/recommended"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"no-unused-vars": "warn",
"no-console": "off",
"func-names": "off",
"no-process-exit": "off",
"object-shorthand": "off",
"class-methods-use-this": "off"
}
}
Add this minimal configuration file in .vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.formatOnSave": true,
"workbench.colorCustomizations": {
"statusBar.background": "#63ace5" // Change this color!
}
}
PS: colorCustomizations
is not necessary but it is handful to add a specific color in the "status bar", to distinguish between multiple instances of VS Code.
- ESLint Rules - https://eslint.org/docs/rules/
- Prettier Options - https://prettier.io/docs/en/options.html
- Airbnb Style Guide - https://github.com/airbnb/javascript