Skip to content

Instantly share code, notes, and snippets.

@ream88
Last active June 6, 2016 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ream88/e510ca628d35515e5cbbcc18e2ea3238 to your computer and use it in GitHub Desktop.
Save ream88/e510ca628d35515e5cbbcc18e2ea3238 to your computer and use it in GitHub Desktop.
Sort your .rubocop.yml
# 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
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