- React Design Patterns and Best Practices(Second Edition)
- Carlos Santana Roldán
- 194字
- 2021-06-24 15:43:41
Git hooks
To avoid having unlinted code in our repository, what we can do is add ESLint at one point of our process using Git hooks. For example, we can use Husky to run our linter in a Git hook called pre-commit, and it is also useful to run our unit tests on the hook pre-push.
To install husky, you need to run:
npm install --save-dev husky
Then in our package.json file, we can add this node to configure the tasks we want to run in the Git hooks:
{
"scripts": {
"lint": "eslint --ext .jsx,.js src",
"lint:fix": "eslint --ext .jsx,.js --fix src",
"test": "jest src"
},
"husky": {
"hooks": {
"pre-commit": "npm lint",
"pre-push": "npm test"
}
}
}
There is a special option (flag) for the ESlint command called --fix – with this option, ESLint will try to fix all our linter errors automatically (not all of them), be careful with this option because sometimes can affect a little bit of our code style. Another useful flag is --ext to specify the extensions of the files we want to validate, in this case just the .jsx and .js files.
- EJB 3.1從入門到精通
- 6G潛在關鍵技術(下冊)
- 高校網絡道德教育研究
- Hands-On Chatbot Development with Alexa Skills and Amazon Lex
- Proxmox High Availability
- 物聯網與無線傳感器網絡
- Metasploit Penetration Testing Cookbook
- Hands-On Bitcoin Programming with Python
- Selenium WebDriver 3 Practical Guide
- 精通SEO:100%網站流量提升密碼
- 智能物聯網:區塊鏈與霧計算融合應用詳解
- 新IP:面向泛在全場景的未來數據網絡
- ReasonML Quick Start Guide
- CDN技術詳解
- Scala Programming Projects