Created
April 22, 2021 16:01
-
-
Save DRBragg/aa892d4609600ad7b1400399a4e0da7b to your computer and use it in GitHub Desktop.
Add style guide links to rubocop config
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
require "net/http" | |
require "yaml" | |
rubocop_config = YAML.load_file(".rubocop.yml") | |
rubocop_config.keys.each do |key| | |
if key.include? "/" | |
cop, rule = key.split("/") | |
docs = "rubocop" | |
if ["Performance", "Rails"].include? cop | |
docs += "-#{cop.downcase}" | |
end | |
docs_link = "https://docs.rubocop.org/#{docs}/cops_#{cop}.html##{cop}#{rule}".downcase | |
uri = URI(docs_link) | |
response = Net::HTTP.get_response(uri) | |
unless response.code.to_i >= 400 | |
rubocop_config[key]["StyleGuide"] = docs_link | |
end | |
end | |
end | |
File.open(".rubocop.yml", "w") { |file| file.write(rubocop_config.to_yaml) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment