Created
April 17, 2023 14:49
-
-
Save joeldrapper/19901398056341661058708b65f42336 to your computer and use it in GitHub Desktop.
Enforce frozen string literals when possible and output a list of problematic files
This file contains hidden or 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
#!/usr/bin/env ruby | |
class Run | |
def initialize(files) | |
@files = files | |
end | |
def call | |
@files.each(&:process) | |
if system("bundle exec rspec --fail-fast") | |
system("git commit -a -m 'WIP'") | |
else | |
@files.each(&:restore) | |
if @files.count > 1 | |
Run.new(left).call | |
Run.new(right).call | |
elsif @files.count == 1 | |
IGNORE << @files.first.path | |
puts IGNORE | |
else | |
raise "This shouldn't have happened." | |
end | |
end | |
end | |
def left = @files.slice(...middle) | |
def right = @files.slice(middle..) | |
def middle = @files.count / 2 | |
end | |
class File | |
def initialize(path) | |
@path = path | |
end | |
attr_reader :path | |
def process | |
@original = File.read(@path) | |
File.write(@path, "# frozen_string_literal: true\n\n" + @original) | |
end | |
def restore | |
File.write(@path, @original) | |
end | |
end | |
IGNORE = [] | |
Run.new( | |
Dir.glob("**/*.rb").map { |f| File.new(f) } | |
).call | |
puts IGNORE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment