Created
June 2, 2017 10:51
-
-
Save wteuber/54c822698bb5a0f428bc0282181e4b99 to your computer and use it in GitHub Desktop.
Script to check & commit all stable auto-corrections of Rubocop
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
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