Linting
Basic Configurationβ
- Automated and standardized way of Formatting Code.
Prerequisitesβ
Installation
yarn add -D eslint-config-prettier eslint-plugin-prettier prettier
npm install --save-dev eslint-config-prettier eslint-plugin-prettier prettier
Automate Linting see (Husky.md)
yarn add -D husky lint-staged
npm install --save-dev husky lint-staged
Howβ
- Add to your package.json
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest",
"plugin:prettier/recommended"
]
},
"prettier": {
"printWidth": 90,
"bracketSpacing": true,
"trailingComma": "es5",
"semi": false,
"singleQuote": true
},
- Add to your scripts:
"scripts": {
"lint:fix": "eslint 'src/**/*.js' --fix",
"lint": "eslint 'src/**/*.js'",
"prettify": "prettier './src/**/*.{ts,tsx,js,jsx}' --write"
},
- Further configuration to automatically remove unused imports
npm install eslint-plugin-unused-imports --save-dev