Skip to content

Instantly share code, notes, and snippets.

@searls
Created March 28, 2023 14:34
Show Gist options
  • Select an option

  • Save searls/65aee8abcfb55294363614d3781d15d7 to your computer and use it in GitHub Desktop.

Select an option

Save searls/65aee8abcfb55294363614d3781d15d7 to your computer and use it in GitHub Desktop.
Ruby file to convert a Rubocop YAML file (rubocop-rails in this case) to a CSV for the purpose of evaluating the rules
# Purpose: Generate a CSV file from the rubocop-rails config file
#
# Usage: ruby driver.rb [csv_file_name] # defaults to rubocop-rails.csv
require "yaml"
require "csv"
def doc_url(cop_name)
squished = cop_name.downcase.delete("/")
"https://docs.rubocop.org/rubocop-rails/cops_rails.html##{squished}"
end
def yaml_to_csv(yaml_file, csv_file)
config = YAML.load_file(yaml_file)
CSV.open(csv_file, "wb") do |csv|
csv << ["Name", "πŸ”—", "🌢️-level", "Justin πŸ‘¨β€βš–οΈ", "Justin πŸ“", "Meagan πŸ‘©β€βš–οΈ", "Meagan πŸ“", "Description", "SupportedStyles", "EnforcedStyle", "Reference"]
config.each do |name, options|
next unless name.include?("/") && options["Enabled"] == true
csv << [name, doc_url(name), "", "", "", "", "", options["Description"], options["SupportedStyles"]&.join("|"), options["EnforcedStyle"], Array(options["Reference"]).join(", ")]
end
end
end
require "rubocop-rails"
require "pathname"
yaml_file = Pathname.new(Gem::Specification.find_by_name("rubocop-rails").gem_dir) + "config/default.yml"
CSV_FILE = ARGV[0] || "rubocop-rails.csv"
yaml_to_csv(yaml_file, CSV_FILE)
`open #{CSV_FILE}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment