Skip to content

Commit

Permalink
Updated jshint-pre-commit-hook. Improved formatting and created grunt…
Browse files Browse the repository at this point in the history
… task to copy hook file to the ".git/hooks" folder.
  • Loading branch information
sbedulin committed Jan 17, 2015
1 parent 7fc5814 commit 57eecfa
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
36 changes: 36 additions & 0 deletions .jshint-pre-commit-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
#
# Put this file into ".git\hooks" folder
# It would jshint-validate scripts only from the current commit
#

files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
if [ "$files" = "" ]; then
exit 0
fi

valid=true

printf '\n%s\n' "---- Validating JavaScript with JSHint: -----"

for file in ${files}; do

result=$(jshint ${file} --config .jshintrc)

if [ "$result" == "" ]; then
printf '\n%s' "-- JSHint Passed: ${file}"
else
printf '\n\n%s' "-- JSHint Failed: ${file}"
printf '\n%s\n' "$result"
valid=false
fi
done

printf '\n\n%s\n' "---- JavaScript validation complete. -----"

if ${valid}; then
printf '\n%s\n' echo "Commit Succeeded"
else
printf '\n%s\n' "Commit Failed: Please fix all above JSHint errors and try again"
exit 1
fi
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ module.exports = function(grunt) {
options: {
jshintrc: true
}
},
copy: {
"jshint-pre-commit-hook": {
src: '.jshint-pre-commit-hook',
dest: '.git/hooks/pre-commit'
}
}
});

grunt.loadNpmTasks('grunt-git');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-copy');

grunt.registerTask('default', function() {
grunt.task.run('replace', 'shell:gitAdd', 'shell:gitCommit');
});

grunt.registerTask('validatejs', ['jshint']);
grunt.registerTask('jshint-hook', ['copy:jshint-pre-commit-hook']);
};
2 changes: 1 addition & 1 deletion app/chapter-23/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ angular.module('exampleApp', ['increment', 'ngResource', 'ngRoute', 'ngAnimate']
}

$scope.cancelEdit = function () {
$location.path("/list");
$location.path('/list');
};

$scope.updateProduct = function (product) {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-jshint": "^0.10.0",
"grunt-git": "~0.2.14",
"grunt-shell": "~1.1.1",
"grunt-text-replace": "~0.3.12",
"jshint": "^2.5.10"
"jshint": "^2.5.10",
"pre-commit": "0.0.11",
"which": "^1.0.8"
}
}
39 changes: 0 additions & 39 deletions pre-commit

This file was deleted.

0 comments on commit 57eecfa

Please sign in to comment.