class Tapioca::Commands::Annotations

def add_header(name, content)

def add_header(name, content)
  # WARNING: Changing this header could impact how GitHub determines if the file should be hidden:
  # https://github.com/github/linguist/pull/6143
  header = <<~COMMENT
    # DO NOT EDIT MANUALLY
    # This file was pulled from a central RBI files repository.
    # Please run `#{default_command(:annotations)}` to update it.
  COMMENT
  # Split contents into newlines and ensure trailing empty lines are included
  contents = content.split("\n", -1)
  if contents[0]&.start_with?("# typed:") && contents[1]&.empty?
    contents.insert(2, header).join("\n")
  else
    say_error("Couldn't insert file header for content: #{content} due to unexpected file format")
    content
  end
end