-
-
Save oroce/11282380 to your computer and use it in GitHub Desktop.
{ | |
"scripts": { | |
"eslint": "LIST=`git diff-index --name-only HEAD | grep .*\\.js | grep -v json`; if [ \"$LIST\" ]; then eslint $LIST; fi" | |
}, | |
"devDependencies": { | |
"pre-commit": "0.0.7", | |
"eslint": "~0.5.1" | |
}, | |
"pre-commit": [ | |
"eslint" | |
] | |
} |
A tiny thing: you might want to grep -E "(.*)\.(jsx|js)$"
This includes files that where deleted. Eslint obviously cannot check deleted files and therefor crashes. Is there a way to exclude these?
PS: Thx for this very useful snippet!
I found the solution, apparently you can exclude deleted filed using --diff-filter=d.
This gives us:
LIST=`git diff-index --name-only --diff-filter=d HEAD | grep .*\\.js | grep -v json`; if [ \"$LIST\" ]; then eslint --fix $LIST; fi
This works well enough if there are only a handful of files, but in a large project with hundreds if not thousands of files, a large merge commit can include a lot of ofiles. LIST is too big in this case - I'm getting ENAMETOOLONG error.
@grebenyuksv-preply I think it is great idea to run lint on all possible ext but I got this err
/bin/sh: 1: [: src/services/acc.js: unexpected operator
my setup "LIST=`git diff-index --name-only HEAD | grep -E \"(.*)\\.(jsx|js|scss)$\" | grep -v json;`; if [ $LIST ]; then eslint $LIST; fi"
You have any idea, Why I'm having this?
This worked for me on mac:
"eslint": "LIST=`git diff-index --name-only --diff-filter=d HEAD | grep -E \"(.*)\\.(tsx|ts)\" | grep -v json`; if [ \"$LIST\" ]; then eslint $LIST --fix; fi",
Awesome dudes! Wont need lint-staged anymore
Problem here with using eslint --fix, is that the script is passing successfully, but the fixed file is now unstaged, and git is commiting the erronous change still unfixed. Can I reuse the list of staged files and git add them??
Just adding to this thread