How to Setup ESLint and Prettier in VSCode For React Project
How to setup ESLint with Prettier in VSCode for React Project
-
Create a React App:
npx create-react-app my-app -
Install
ESLintandPrettierin VSCode. -
In the project directory, run
npm i prettier eslint-config-prettier eslint-plugin-prettier -D -
In User Settings (
ctrl + ,), put in the following:
{
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": false
},
"eslint.autoFixOnSave": true,
"eslint.alwaysShowStatus": true,
"prettier.disableLanguages": [
"js"
],
"files.autoSave": "onFocusChange"
}- Create an
.eslintrcfile:
{
"extends": ["react-app", "plugin:prettier/recommended"]
}-
If your project is not under git, run
git init. -
Run
npm i husky lint-staged -Dandnpm i pretty-quick -D. -
In
package.json, add"precommit": "pretty-quick --staged"toscripts.
Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Email