Open klimashkin opened 8 years ago
you could use the --cached
flag of git diff-index
to only match the files that are actually staged.
For instance, I use in my package.json
the following script:
eslint $(git diff-index --name-only HEAD --cached | grep \".js$\シ
to lint all the staged files. You could do:
git.exec({args: `diff-index --name-only --cached HEAD | grep .*\\.js | grep -v json`, //...
Check out https://github.com/okonet/lint-staged. It solves exactly this problem.
Hello, thanks for good module! But one thing is really needed. For example, I have lint script on npm, that run linting gulp lint task. And in this task I can get list of all changed files from last commit through
gulp-git
to lint only them like thisBut if I commit only some files this task anyway will take every changed, i.e. some files that I don't want to commit right now may have broken lint rules (for examples this files in deep development in that moment). It would be great, if
pre-commit
passed list of files to npm script, for example if we haveAnd
pre-commit
can callnpm run lint -- --file path1 [--file path2 [--file path3]]
wherepathN
is path to commiting files. In this case I can read in gulp array of passed files and lint only them.