- Initialize Git repository
git init 
- Create .gitignorefile and add the following:node_modules/ *.env
- Create a package.jsonfile withnpm initnpm init -y 
- Install dev dependencies
npm i -D prettier eslint husky lint-staged 
- Initialize ESLint config
npx eslint --init 
- Create .prettierrcfile and add the following rules:{ "printWidth": 80, "tabWidth": 2, "useTabs": false, "semi": true, "singleQuote": true, "quoteProps": "as-needed", "jsxSingleQuote": false, "trailingComma": "all", "bracketSpacing": true, "jsxBracketSameLine": true, "arrowParens": "avoid", "endOfLine": "auto" }
- Open package.jsonfile and add the following sections:"husky": { "hooks": { "pre-commit": "lint-staged" } }, "lint-staged": { "*.{js,jsx}": [ "prettier --write", "eslint --fix", "git add" ], "*.{html,css,less,ejs}": [ "prettier --write", "git add" ] } 
- At this point, your pre-commit linting setup should be working and ready for use.
- Open .eslintrc.jsfile and addno-consolerule underrulessection.module.exports = { ... rules: { 'no-console': 'off', }, }; 
- Add this sample app.jsfile:console.log('one'); var ww = process.env.NODE_ENV.trim.toLowerCase(); if (ww === 'production') { console.log('Another one'); } else { console.log('test'); } 
- Commit all files
git add . git commit -m "Initial commit" 
- If all goes well, your app.jsshould now be formatted properly :console.log('one'); const ww = process.env.NODE_ENV.trim.toLowerCase(); if (ww === 'production') { console.log('Another one'); } else { console.log('test'); } 
For someone who is still looking to setup husky with new interface, please checkout this article/blog https://duncanlew.medium.com/getting-started-with-husky-and-lint-staged-for-pre-commit-hooks-c2764d8c9ae