Created
March 27, 2017 18:14
-
-
Save rfarine/4fb71f250d8a9be23051c29be3a5898f to your computer and use it in GitHub Desktop.
Only lint files added to repo after a certain date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adapted from: https://gist.github.com/jhartikainen/36a955f3bfe06557e16e | |
#!/bin/bash | |
# Find all js/jsx files staged to commit | |
staged_files=$(git diff --staged --diff-filter=ACMTUXB --name-only | grep '\.jsx\?$') | |
files_to_lint=() | |
# Find all staged js/jsx files created since 2017-01-13 | |
for file in ${staged_files}; do | |
# if the file has previously been committed, get author date of file: | |
author_date="$(git log --format=%at --date=short "$file" | tail -1)" | |
# format date: | |
if [[ $author_date ]] ; then | |
created_at=$(date -r $author_date '+%Y%m%d%H%M%S') | |
else | |
created_at=0 | |
fi | |
# if the file was created after 2017-01-13 OR has been newly created in this branch: | |
if [[ $created_at -gt "20170113000000" || $created_at = 0 ]] ; then | |
files_to_lint+=("$file") | |
fi | |
done; | |
# Prevent ESLint help message if no files matched | |
if [[ $files_to_lint = "" ]] ; then | |
exit 0 | |
fi | |
failed=0 | |
for file in ${files_to_lint}; do | |
echo "*** Linting: ${file} ***" | |
git show :$file | eslint --stdin --stdin-filename $file | |
if [[ $? != 0 ]] ; then | |
failed=1 | |
fi | |
done; | |
if [[ $failed != 0 ]] ; then | |
echo "ESLint check failed, commit denied. Fix those errors!" | |
exit $failed | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment