Created
March 28, 2023 14:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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