Skip to content

Instantly share code, notes, and snippets.

@joeldrapper
Created April 17, 2023 14:49
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 joeldrapper/19901398056341661058708b65f42336 to your computer and use it in GitHub Desktop.
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
#!/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