class Rufo::Command

def format_file(filename)

def format_file(filename)
  code = File.read(filename)
  begin
    result = format(code, @filename_for_dot_rufo || File.dirname(filename))
  rescue Rufo::SyntaxError
    # We ignore syntax errors as these might be template files
    # with .rb extension
    STDERR.puts "Error: #{filename} has syntax errors"
    return CODE_ERROR
  end
  if code.force_encoding(result.encoding) != result
    if @want_check
      STDERR.puts "Formatting #{filename} produced changes"
    else
      unless @squiggly_warning
        File.write(filename, result)
        puts "Format: #{filename}"
      else
        @squiggly_warning_files << filename
      end
    end
    return CODE_CHANGE
  end
rescue Rufo::SyntaxError
  STDERR.puts "Error: the given text in #{filename} is not a valid ruby program (it has syntax errors)"
  CODE_ERROR
rescue => ex
  STDERR.puts "You've found a bug!"
  STDERR.puts "It happened while trying to format the file #{filename}"
  STDERR.puts "Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it"
  STDERR.puts
  raise ex
end