Skip to content

Instantly share code, notes, and snippets.

@kitsunde
Created August 25, 2014 11:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitsunde/dc2c10f11c2b54bf093f to your computer and use it in GitHub Desktop.
Save kitsunde/dc2c10f11c2b54bf093f to your computer and use it in GitHub Desktop.
ESLint lint pre_commit hook
#!/usr/bin/env node
var exec = require('child_process').exec;
var fs = require('fs');
var eslint = require('../node_modules/eslint/lib/cli');
var files;
var child = exec("git diff-index --cached --name-only HEAD", function(error, stdout, stderr){
files = stdout.split('\n').filter(function(i){
return /\.js$/.test(i) && fs.existsSync(i);
});
if(files.length === 0){
return;
}
var exitCode = eslint.execute.apply(this, files);
process.exit(exitCode);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment