Last active
June 6, 2016 09:59
-
-
Save ream88/e510ca628d35515e5cbbcc18e2ea3238 to your computer and use it in GitHub Desktop.
Sort your .rubocop.yml
This file contains 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
# http://dan.doezema.com/2012/04/recursively-sort-ruby-hash-by-key/ | |
class Hash | |
def sort_by_key(recursive = false, &block) | |
self.keys.sort(&block).reduce({}) do |seed, key| | |
seed[key] = self[key] | |
if recursive && seed[key].is_a?(Hash) | |
seed[key] = seed[key].sort_by_key(true, &block) | |
end | |
seed | |
end | |
end | |
end |
This file contains 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_relative './hash-sort-by-key' | |
File.write( | |
'.rubocop.yml', | |
YAML.load_file('.rubocop.yml').sort_by_key(true).to_yaml | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment