JSHint Changed Files Only
Do you use a linter like JSHint for your JavaScript projects? Has running jshint
to lint your entire project become slow? Do you use git to version your project? If so, this script will solve your slow linting problems. It uses git to detect which files have been changed and only lints those files rather than your entire project. This results in a much faster linting.
#!/bin/bash
#
# Lints all files that have changed
# check if we are in a git repo
isInGitMsg="$(git rev-parse --is-inside-work-tree)"
retval=$?
if [ "$isInGitMsg" != "true" ]
then
echo -n "$isInGitMsg" >&2
exit $retval
fi;
# get the files that we should lint
files="$(
{
# NOTE: the file paths returned are relative to the git root despite the current working directory
# list all files that have changed (but not staged)
git diff --name-only --diff-filter=ACMRTUXB;
# list all files that have changed (and staged)
git diff --name-only --diff-filter=ACMRTUXB --cached;
# list all untracked (new) files
git ls-files --others --exclude-standard;
} |
# only lint files that end with .js
grep '\.js\