mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
add hintStagedFiles, use in pre-commit hook
This commit is contained in:
parent
c281af4568
commit
1b8a0dd3d6
2 changed files with 29 additions and 1 deletions
|
@ -49,7 +49,7 @@
|
|||
"scripts": {
|
||||
"test": "grunt test --use-jruby",
|
||||
"server": "grunt server",
|
||||
"precommit": "grunt jshint",
|
||||
"precommit": "grunt hintStagedFiles",
|
||||
"prepush": "echo"
|
||||
},
|
||||
"repository": {
|
||||
|
|
28
tasks/jshint.js
Normal file
28
tasks/jshint.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
var path = require('path');
|
||||
var workingPath = path.resolve(__dirname, '..');
|
||||
var simplegit = require('simple-git')(workingPath);
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask('hintStagedFiles', 'JSHint staged filed', function () {
|
||||
grunt.log.debug('git working path', workingPath);
|
||||
|
||||
var done = this.async();
|
||||
var files = simplegit.diff('--name-only --cached', function (err, files) {
|
||||
// match these patterns
|
||||
var patterns = grunt.config.get('jshint.source.files.src');
|
||||
files = files.split('\n').filter(Boolean).map(function (file) {
|
||||
if (file.length) {
|
||||
return path.join(workingPath, file);
|
||||
}
|
||||
});
|
||||
|
||||
files = grunt.file.match(patterns, files);
|
||||
grunt.log.debug(files);
|
||||
|
||||
grunt.config.set('jshint.staged.files.src', files);
|
||||
|
||||
grunt.task.run(['jshint:staged']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue