Use the follwing steps to setup and use eslint and prettier in a create react app. I've seperated out the eslint and prettier setup so you can see whats needed for both.
npx create-react-app purdier
npm i -D eslint eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks
Find each in the respective marketplace in the editor.
- Atom: https://github.com/AtomLinter/linter-eslint
- VSCode: https://github.com/Microsoft/vscode-eslint
{
"extends": ["airbnb"],
"rules": {
"react/jsx-filename-extension": [
1,
{
"extensions": [".js", ".jsx"]
}
]
},
"parser": "babel-eslint"
}
npm i -D prettier eslint-config-prettier eslint-plugin-prettier
"extends": ["airbnb", "prettier", "prettier/react"],
"plugins": ["prettier"],
{}
Find these on the respective marketplace tabs in your editor
- Atom: https://github.com/prettier/prettier-atom
- VSCode: https://github.com/prettier/prettier-vscode
- Atom: Verify auto save checkbox is checked in prettier setttings.
- VSCode: Under settings search for 'formatOnSave', and ensure the option is checked.
Instead of re-formating each file you touch in your project bring it all up to prettier style. This makes it easy to see new changes you make.
- Install prettier cli
npm i -g prettier --dev
prettier --write "src/**/*.js"
Ensure nothing is unstyled no matter whos commiting code. This will be ran after every commit.
npm i -D precise-commits husky
Add to your package.json
"husky": {
"hooks": {
"pre-commit": "precise-commits"
}
}