Skip to content

Instantly share code, notes, and snippets.

@kadamwhite
Created August 31, 2015 19:35
Show Gist options
  • Save kadamwhite/1bfb6c4ea502400f1557 to your computer and use it in GitHub Desktop.
Save kadamwhite/1bfb6c4ea502400f1557 to your computer and use it in GitHub Desktop.
Use `git diff` and `grep` to selectively lint changed files
{
"scripts": {
"jscs:branch": "jscs $(git diff --name-only --diff-filter=ACMRTUXB $(git merge-base head master) | grep '.js$') || true",
"jshint:branch": "jshint $(git diff --name-only --diff-filter=ACMRTUXB $(git merge-base head master) | grep '.js$') || true",
"jscs:diff": "jscs $(git diff --name-only --diff-filter=ACMRTUXB | grep '.js$') || true",
"jshint:diff": "jshint $(git diff --name-only --diff-filter=ACMRTUXB | grep '.js$') || true",
"jscs:prev": "jscs $(git diff head~1 --name-only --diff-filter=ACMRTUXB | grep '.js$') || true",
"jshint:prev": "jshint $(git diff head~1 --name-only --diff-filter=ACMRTUXB | grep '.js$') || true"
}
}
@codeocelot
Copy link

Amazing, this was super helpful when trying to lint my contributions to a huge project that sorely needs a lint standard. One thing I might add is the git HEAD ref is usually (always?) case sensitive: if you're getting fatal: Not a valid object name head that's probably the reason.

After that, this approach works great with python's pep8/pycodestyle and autopep8.

Thanks for sharing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment