Created
August 8, 2019 16:35
-
-
Save ixti/0ed2d1cef41d61a6b7c22fbeb8c0f832 to your computer and use it in GitHub Desktop.
Rubocop configs linter.
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
| 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