Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
893 views
in Technique[技术] by (71.8m points)

git - setup pre-commit hook jshint

I recently started a project on github. I've managed to setup automatic testing after each commit using Travis. But now I would like to setup a pre-commit hook with jshint too. So if jshint reports errors, the commit should fail. But is this possible, and if so, how to do this ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's an easier way of doing pre-commit checks (e.g. JSHint) in your Node.js workflow:

Install jshint from NPM:

npm install jshint

Next create a .jshintrc file in your project if you don't already have one. e.g: https://github.com/nelsonic/learn-jshint/blob/master/.jshintrc

Now install pre-commit module (and save it as a dev dependency):

npm install pre-commit --save-dev

Next you will need to define the task (script) that will be run for JSHint in your package.json

e.g:

{ "scripts": { "jshint": "jshint -c .jshintrc --exclude-path .gitignore ." } }

then you register the scripts you want to be run pre-commit (also in package.json) e.g:

"pre-commit": [ "jshint", "coverage", "etc" ]

This allows you to have more than just one check in your pre-commit workflow. (We have checks to ensure team members code complies with JSHint, Code Style and Test Coverage is 100%)

For a more detailed tutorial you can share with your team see: https://github.com/nelsonic/learn-pre-commit


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...