Skip to content

Instantly share code, notes, and snippets.

@andrewhamon
Last active August 29, 2015 14:22
Show Gist options
  • Save andrewhamon/23724158d436400c60c2 to your computer and use it in GitHub Desktop.
Save andrewhamon/23724158d436400c60c2 to your computer and use it in GitHub Desktop.
Rubodiff! Diffs the rubocop results of your current branch with the results of develop
#!/bin/bash
GREEN='\033[0;32m'
# The ampersand at the end of this line makes this command run in the background...
rubocop --format simple --out ~/rubocop_results_current_branch.txt &
# ...while all this runs in the foreground...
mkdir -p ~/rubodiff_temp
rm -rf ~/rubodiff_temp/*
git archive develop | tar -x -C ~/rubodiff_temp
rubocop --format simple --out ~/rubocop_results_develop.txt ~/rubodiff_temp
# Normalize the filenames that rubocop prints
sed -E -i '' 's/\/Users\/[^\/]+\/rubodiff_temp\///g' ~/rubocop_results_develop.txt
# ...and this waits until everything is done...
wait
# ...and finally a diff is printed.
{
# Hack to prevent annoying copyright info from being printed
colordiff -U0 -F "==" ~/rubocop_results_develop.txt ~/rubocop_results_current_branch.txt | tee ~/rubodiff_results.txt
} &> /dev/null
cat ~/rubodiff_results.txt
if [[ ! -s ~/rubodiff_results.txt ]] ; then
echo -e "${GREEN}There were no changes in rubocop."
fi ;
# Cleanup
rm ~/rubocop_results_current_branch.txt
rm ~/rubocop_results_develop.txt
rm ~/rubodiff_results.txt
rm -rf ~/rubodiff_temp
@andrewhamon
Copy link
Author

Install

  • First, install colordiff so we can have colors (fancy!) brew install colordiff
  • Download this gist
  • Make it executable chmod +x /path/to/rubodiff
  • Run it /path/to/rubodiff
  • Optionally, put it somewhere in your search path so you can run it without its full path

Sample output

--- /Users/ahamon/rubocop_results_develop.txt   2015-06-04 18:02:37.000000000 -0400
+++ /Users/ahamon/rubocop_results_current_branch.txt    2015-06-04 18:02:36.000000000 -0400
@@ -1,2 +1,12 @@
+== app/poros/account_downloader.rb ==
+C: 17: 25: Prefer single-quoted strings when you don't need string interpolation or special symbols.
+C: 19:  1: Extra blank line detected.
+C: 20:  1: Extra blank line detected.
+C: 21:  1: Extra blank line detected.
+== app/poros/ad_updater.rb ==
+C: 27:  1: Extra blank line detected.
+C: 28:  1: Extra blank line detected.
+C: 29:  1: Extra blank line detected.
+C: 30:  1: Extra blank line detected.

-330 files inspected, no offenses detected
+332 files inspected, 8 offenses detected

Its just a diff between the two outputs of rubocop for the different branches.

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