npm install -D eslint-config-prettier husky lint-staged
npm install -D -E prettier
npm init @eslint/config
Recommended options:
- How would you like to use ESLint?: To check syntax, find problems, and enforce code style
- What type of modules does your project use?: JavaScript modules (import/export)
- How would you like to define a style for your project?: Use a popular style guide
- Would you like to install them (dependencies) now?: Yes
Make sure to put it last, so it overrides other configs.
"extends": [
/* other configs */,
"prettier"
]
npx husky init
{
// ...
"scripts": {
// ...
"test": "npx lint-staged"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "eslint --fix",
"**/*": "prettier --write --ignore-unknown"
},
// ...
}
- To set up a Prettier configuration, create a
.prettierrc
file. - To exclude files from being formatted by Prettier, create a
.prettierignore
file. - The
lint-staged
object inpackage.json
can be moved into a.lintstagedrc.json
file.
// .lintstagedrc.json
{
"*.{js,jsx,ts,tsx}": "eslint --fix",
"**/*": "prettier --write --ignore-unknown"
}