Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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 /')
- (echo "$disables"; cat "$file~") > "$file"
- rm "$file~"
- }
- for file in "$@"; do
- cleanup "$file"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement