Created
February 9, 2016 10:09
-
-
Save mikestok/a13eb086aa09a7d042c6 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# | |
# WARNING: Rubocop 0.36.0 can turn not(foo) into notfoo :-( Need to check that | |
# or wait for 0.37.x to be safe. | |
# | |
# Perform automated cleanp of ruby files leaving only uncorrected problems' | |
# rubocop:disable lines in the files. | |
# | |
# e.g. | |
# | |
# for f in `grep -rl 'rubocop:disable all' app/controllers`; do | |
# echo $f | |
# rubocleanup "$f" | |
# git add "$f" | |
# git commit -m "Rubocop automated cleanup: $f" | |
# done | |
set -e | |
function cleanup { | |
local file=${1?"$0: missing file name"} | |
sed -e"/^ *# rubocop:/d" < "$file" > "$file~" | |
bundle exec rubocop --auto-correct "$file~" >/dev/null || true | |
disables=$(bundle exec rubocop -f j "$file~" \ | |
| jq ".files[].offenses[].cop_name" \ | |
| sort \ | |
| uniq \ | |
| tr -d '"' \ | |
| sed -e 's/^/# rubocop:disable /') | |
if [ -z "$disables" ]; then | |
mv "$file~" "$file" | |
else | |
(echo "$disables"; cat "$file~") > "$file" | |
rm "$file~" | |
fi | |
} | |
for file in "$@"; do | |
cleanup "$file" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment