Skip to content

Instantly share code, notes, and snippets.

@ixti
Created August 8, 2019 16:35
Show Gist options
  • Select an option

  • Save ixti/0ed2d1cef41d61a6b7c22fbeb8c0f832 to your computer and use it in GitHub Desktop.

Select an option

Save ixti/0ed2d1cef41d61a6b7c22fbeb8c0f832 to your computer and use it in GitHub Desktop.
Rubocop configs linter.
namespace :lint do
task :rubocop_config do
errors = []
Dir[File.expand_path("../../../config/rubocop/*.yml", __dir__)].each do |f|
config = Psych.parse_file(f)&.children&.first
unless config.is_a? Psych::Nodes::Mapping
errors << "Invalid config: #{f}"
next
end
keys = config.children.grep(Psych::Nodes::Scalar).map(&:value)
next if keys.sort == keys
errors << "Invalid sort of keys: #{f}"
end
unless errors.empty?
errors = errors.map { |e| " - #{e}" }.join("\n")
abort "Found invalid configs:\n\n#{errors}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment