<commit_before>#!/usr/bin/env ruby
require 'gemfile_arranger'
require 'parser/current'
require 'byebug'
require 'pp'
require 'unparser'
require 'safe_yaml/load'

base_config = SafeYAML.load_file('config/.gemfile_arranger.base.yml')
CONFIG = base_config

code = <<-EOF
# comment 1
gem 'action_args'
source 'https://rubygems.org'
gem 'bar'
gemspec

group :development do
  gem 'bullet'
end

gem 'foo'
gem 'abba'

group :test do
  gem 'database_rewinder'
  gem 'capybara-webkit'
  gem 'redis'
end

ruby '2.1.2' # comment 2
EOF

expect = <<-EOF
source 'https://rubygems.org'
ruby '2.1.2'
gemspec
gem 'action_args'
gem 'abba'
gem 'bar'
gem 'foo'
group :development do
  gem 'bullet'
end

group :test do
  gem 'redis'
  gem 'capybara-webkit'
  gem 'database_rewinder'
end
EOF

buffer        = Parser::Source::Buffer.new('(example)')
buffer.source = code
parser        = Parser::CurrentRuby.new
ast           = parser.parse(buffer)

class SortBlockTraverser < Parser::AST::Processor
  def initialize(keys)
    @keys = Array(keys.dup).map(&:to_sym)
  end

  def on_begin(node)
    sorted_block = sort_block_with_keys(node, @keys)
    node.updated(:begin, sorted_block) if node != sorted_block
  end
<commit_msg>Fix example<commit_after>#!/usr/bin/env ruby
require 'gemfile_arranger'
require 'parser/current'
require 'byebug'
require 'pp'
require 'unparser'
require 'safe_yaml/load'

base_config = SafeYAML.load_file('config/.gemfile_arranger.base.yml')
CONFIG = base_config

code = <<-EOF
# comment 1
gem 'action_args'
source 'https://rubygems.org'
gem 'bar'
gemspec

group :development do
  gem 'bullet'
end

gem 'foo'
gem 'abba'

group :test do
  gem 'database_rewinder'
  gem 'capybara-webkit'
  gem 'redis'
end

ruby '2.1.2' # comment 2
EOF

expect = <<-EOF
source 'https://rubygems.org'
ruby '2.1.2'
gemspec
gem 'abba'
gem 'action_args'
gem 'bar'
gem 'foo'
group :development do
  gem 'bullet'
end

group :test do
  gem 'redis'
  gem 'capybara-webkit'
  gem 'database_rewinder'
end
EOF

buffer        = Parser::Source::Buffer.new('(example)')
buffer.source = code
parser        = Parser::CurrentRuby.new
ast           = parser.parse(buffer)

class SortBlockTraverser < Parser::AST::Processor
  def initialize(keys)
    @keys = Array(keys.dup).map(&:to_sym)
  end

  def on_begin(node)
    sorted_block = sort_block_with_keys(node, @keys)
    node.updated(:begin, sorted_block) if node != sorted_block
  end

{'fraction_non_alphanumeric': 0.1281198003327787, 'fraction_numerical': 0.0066555740432612314, 'mean_word_length': 4.228260869565218, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '201650', 'n_tokens_mistral': 916, 'n_tokens_neox': 889, 'n_words': 227}