How to setup a project with eslint and prettier
Install prettier
npm install --save-dev --save-exact prettier
Create config and ignore files
node --eval "fs.writeFileSync('.prettierrc','{}\n')"
node --eval "fs.writeFileSync('.prettierignore','# Ignore artifacts:\nbuild\ncoverage\n')"
You can now format all files with prettier
npx prettier . --write
Install eslint
npm init @eslint/config@latest
install the eslint prettier plugin
npm install --save-dev eslint-config-prettier
Install git hooks with Husky
npm install --save-dev husky lint-staged
npx husky init
node --eval "fs.writeFileSync('.husky/pre-commit','npx lint-staged\n')"
Add to package.json
{
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
}
}
References:
- https://prettier.io/docs/en/install
- https://eslint.org/