Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion tasks/reformat_yaml.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

require 'yaml'

desc 'Reformat all locales'
task :reformat_locales do
path = File.absolute_path(File.join(__dir__, '..', 'lib', 'locales', '**', '*.yml'))
locales = Dir[path]
failures = []

locales.each do |locale_path|
reformat_file(locale_path)
rescue StandardError => e
failures << "Error reformatting #{locale_path}: #{e.message}"
end

puts failures
end

desc 'Reformat a yaml file into a common format'
task :reformat_yaml, [:filename] do |_, args|
args.with_defaults(filename: nil)
Expand All @@ -16,7 +31,7 @@ end
def reformat_file(filename)
puts "Reformatting #{filename}"

input = YAML.load_file(filename)
input = YAML.safe_load_file(filename, aliases: true)
# Psych outputs non-indented hypendated array list items.
output = input.to_yaml(line_width: -1)
.gsub(/(^ *- .+$)/, ' \1') # Indent hyphenated list items
Expand Down