Skip to content

Instantly share code, notes, and snippets.

@wteuber
Created June 2, 2017 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wteuber/54c822698bb5a0f428bc0282181e4b99 to your computer and use it in GitHub Desktop.
Save wteuber/54c822698bb5a0f428bc0282181e4b99 to your computer and use it in GitHub Desktop.
Script to check & commit all stable auto-corrections of Rubocop
require 'fileutils'
# TODO get list of Cops that support auto-correct
# for each cop, run the following
# only commit if change was stable
# (each run takes ~2 minutes)
prefix = ARGV[0]
files = Dir["#{prefix}/**/*.rb"].sort
orig = Hash[files.map do |file|
FileUtils.cp(file, "#{file}.orig")
[file, %x(ruby --dump insns #{file}).gsub(/\s+\(\s*\d+\)$/, '')]
end]
%x(bundle exec rubocop --auto-correct #{prefix})
changed = Hash[files.map { |file| [file, %x(ruby --dump insns #{file}).gsub(/\s+\(\s*\d+\)$/, '')] }]
files.each do |file|
stable = (orig[file] == changed[file])
puts stable, file unless stable
File.open("#{file}-orig.txt", 'w') { |f| f.write(orig[file]) }
File.open("#{file}-changed.txt", 'w') { |f| f.write(changed[file]) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment