Config Eslint and Prettier in VS Code for React js
When I first began utilizing React for my projects, I neglected to incorporate eslint or prettier into my development workflow. Looking back, I deeply regret that decision, as proper linting plays a crucial role in minimizing errors and enhancing the overall code quality, while prettier aids in code formatting. Therefore, let's explore how to configure these tools for your upcoming React.js project.
npm install eslint --save-dev
npx eslint --init
Recommended by LinkedIn
npm install eslint-config-prettier eslint-plugin-prettier prettier --save-dev
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },
"editor.formatOnSave": true,
"eslint.alwaysShowStatus": true,
"files.autoSave": "onFocusChange"
"env": {
"browser": true,
"es2021": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"react/react-in-jsx-scope": "off",
"prettier/prettier": [
"error",
{
"trailingComma": "all",
"tabWidth": 12,
"semi": false,
"singleQuote": true,
"bracketSpacing": true,
"eslintIntegration": true,
"printWidth": 120
}
]
}
}