class Rufo::Command

def format_file(filename)

def format_file(filename)
  logger.debug("Formatting: #{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
    logger.warn("Error: #{filename} has syntax errors")
    return CODE_ERROR
  end
  if code.force_encoding(result.encoding) != result
    if @want_check
      logger.warn("Formatting #{filename} produced changes")
    else
      File.write(filename, result)
      logger.log("Format: #{filename}")
    end
    return CODE_CHANGE
  end
rescue Rufo::SyntaxError
  logger.error("Error: the given text in #{filename} is not a valid ruby program (it has syntax errors)")
  CODE_ERROR
rescue => ex
  logger.error("You've found a bug!")
  logger.error("It happened while trying to format the file #{filename}")
  logger.error("Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it\n")
  raise ex
end