Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #
  3. # WARNING: Rubocop 0.36.0 can turn not(foo) into notfoo :-( Need to check that
  4. # or wait for 0.37.x to be safe.
  5. #
  6. # Perform automated cleanp of ruby files leaving only uncorrected problems'
  7. # rubocop:disable lines in the files.
  8. #
  9. # e.g.
  10. #
  11. # for f in `grep -rl 'rubocop:disable all' app/controllers`; do
  12. # echo $f
  13. # rubocleanup "$f"
  14. # git add "$f"
  15. # git commit -m "Rubocop automated cleanup: $f"
  16. # done
  17.  
  18. set -e
  19.  
  20. function cleanup {
  21. local file=${1?"$0: missing file name"}
  22.  
  23. sed -e"/^ *# rubocop:/d" < "$file" > "$file~"
  24.  
  25. bundle exec rubocop --auto-correct "$file~" >/dev/null || true
  26.  
  27. disables=$(bundle exec rubocop -f j "$file~" \
  28. | jq ".files[].offenses[].cop_name" \
  29. | sort \
  30. | uniq \
  31. | tr -d '"' \
  32. | sed -e 's/^/# rubocop:disable /')
  33.  
  34. (echo "$disables"; cat "$file~") > "$file"
  35.  
  36. rm "$file~"
  37. }
  38.  
  39. for file in "$@"; do
  40. cleanup "$file"
  41. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement