Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto corrected by following Format Ruby Code #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion lib/check_syntax.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Synvert::Rewriter.new 'default', 'check_syntax' do
description 'just used to check if there are syntax errors.'

within_files '**/*.rb' do; end
within_files '**/*.rb' do
end
end
2 changes: 1 addition & 1 deletion lib/factory_bot/convert_factory_girl_to_factory_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
replace_with "require 'factory_bot_rails'"
end
end
end
end
4 changes: 2 additions & 2 deletions lib/factory_bot/deprecate_static_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
new_arguments = add_curly_brackets_if_necessary(node.arguments.first.to_source)
replace_with "{{message}} { #{new_arguments} }"
else
replace_with "{{message}} { {{arguments}} }"
replace_with '{{message}} { {{arguments}} }'
end
end
end
end
end
end
end
end
44 changes: 38 additions & 6 deletions lib/factory_girl/fix_deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@
# sequence(:email) { |n| "user#{n}@gmail.com" }
# after_create { |instance| create_list(:post, 5, user: instance) }
# end
within_node type: 'block', caller: { type: 'send', receiver: 'Factory', message: 'define' }, arguments: { size: 1 } do
within_node type: 'block',
caller: {
type: 'send',
receiver: 'Factory',
message: 'define'
},
arguments: {
size: 1
} do
argument = node.arguments.first.to_source
with_node type: 'block', caller: { type: 'send', receiver: argument } do
goto_node :caller do
Expand All @@ -81,7 +89,7 @@
# Factory.define :user do |user|
# after(:create) { |instance| create_list(:post, 5, user: instance) }
# end
%w(after_build after_create).each do |message|
%w[after_build after_create].each do |message|
within_node type: 'block', caller: { type: 'send', message: message } do
goto_node :caller do
new_message = message.sub('after_', '')
Expand All @@ -99,7 +107,15 @@
# Factory.define :user do |user|
# admin true
# end
within_node type: 'block', caller: { type: 'send', receiver: 'Factory', message: 'define' }, arguments: { size: 1 } do
within_node type: 'block',
caller: {
type: 'send',
receiver: 'Factory',
message: 'define'
},
arguments: {
size: 1
} do
argument = node.arguments.first.to_source
with_node type: 'send', receiver: argument do
replace_with '{{message}} {{arguments}}'
Expand All @@ -113,7 +129,15 @@
# =>
# factory :user do
# end
within_node type: 'block', caller: { type: 'send', receiver: 'Factory', message: 'define' }, arguments: { size: 1 } do
within_node type: 'block',
caller: {
type: 'send',
receiver: 'Factory',
message: 'define'
},
arguments: {
size: 1
} do
goto_node :caller do
replace_with 'factory {{arguments}}'
end
Expand All @@ -130,7 +154,15 @@
# sequence :user do |n|
# "new_user_#{n}"
# end
within_node type: 'block', caller: { type: 'send', receiver: 'Factory', message: 'sequence' }, arguments: { size: 1 } do
within_node type: 'block',
caller: {
type: 'send',
receiver: 'Factory',
message: 'sequence'
},
arguments: {
size: 1
} do
goto_node :caller do
replace_with 'sequence {{arguments}}'
end
Expand All @@ -156,7 +188,7 @@
# Factory.create(:user) => create(:user)
# Factory.build(:use) => build(:user)
# Factory.attributes_for(:user) => attributes_for(:user)
%w(create build attributes_for).each do |message|
%w[create build attributes_for].each do |message|
with_node type: 'send', receiver: 'Factory', message: message do
replace_with "#{message}({{arguments}})"
end
Expand Down
10 changes: 8 additions & 2 deletions lib/factory_girl/use_short_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ class MiniTest::Rails::ActiveSupport::TestCase

# insert include FactoryGirl::Syntax::Methods
within_file 'test/test_helper.rb' do
%w(Test::Unit::TestCase ActiveSupport::TestCase MiniTest::Unit::TestCase MiniTest::Spec MiniTest::Rails::ActiveSupport::TestCase).each do |class_name|
%w[
Test::Unit::TestCase
ActiveSupport::TestCase
MiniTest::Unit::TestCase
MiniTest::Spec
MiniTest::Rails::ActiveSupport::TestCase
].each do |class_name|
within_node type: 'class', name: class_name do
unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
insert 'include FactoryGirl::Syntax::Methods'
Expand All @@ -87,7 +93,7 @@ class MiniTest::Rails::ActiveSupport::TestCase
# FactoryGirl.create_pair(...) => create_pair(...)
# FactoryGirl.build_pair(...) => build_pair(...)
within_files '{test,spec,features}/**/*.rb' do
%w(create build attributes_for build_stubbed create_list build_list create_pair build_pair).each do |message|
%w[create build attributes_for build_stubbed create_list build_list create_pair build_pair].each do |message|
with_node type: 'send', receiver: 'FactoryGirl', message: message do
replace_with "#{message}({{arguments}})"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/add_active_record_migration_rails_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class CreateUsers < ActiveRecord::Migration[4.2]
end
end
end
end
end
4 changes: 1 addition & 3 deletions lib/rails/convert_dynamic_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
return nil if (fields - attributes).present?

if fields.length == node.arguments.length && :hash != node.arguments.first.type
fields.length.times.map { |i|
fields[i] + ': ' + node.arguments[i].to_source
}.join(', ')
fields.length.times.map { |i| fields[i] + ': ' + node.arguments[i].to_source }.join(', ')
else
'{{arguments}}'
end
Expand Down
6 changes: 4 additions & 2 deletions lib/rails/convert_mailers_2_3_to_3_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def signup_notification(recipient)
args[:to] = node.arguments.first.to_source
remove
end
%w(subject from cc bcc).each do |message|
%w[subject from cc bcc].each do |message|
with_node type: 'send', receiver: nil, message: message do
args[message.to_sym] = node.arguments.first.to_source
remove
Expand All @@ -77,7 +77,9 @@ def signup_notification(recipient)
with_node type: 'send', receiver: nil, message: 'body', arguments: { size: 1 } do
body_argument = node.arguments.first
if :hash == body_argument.type
replace_with body_argument.children.map { |pair_node| "@#{pair_node.key.to_value} = #{pair_node.value.to_source}" }.join("\n")
replace_with body_argument.children.map { |pair_node|
"@#{pair_node.key.to_value} = #{pair_node.value.to_source}"
}.join("\n")
end
end
if args.size > 0
Expand Down
33 changes: 19 additions & 14 deletions lib/rails/convert_models_2_3_to_3_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@
EOF

keys = [:conditions, :order, :joins, :select, :from, :having, :group, :include, :limit, :offset, :lock, :readonly]
keys_converters = {
:conditions => :where,
:include => :includes
}
keys_converters = { conditions: :where, include: :includes }

helper_method :generate_new_queries do |hash_node|
new_queries = []
Expand Down Expand Up @@ -125,7 +122,7 @@
# default_scope :conditions => {:active => true}
# =>
# default_scope where(:active => true)
%w(named_scope default_scope).each do |message|
%w[named_scope default_scope].each do |message|
within_node type: 'send', message: message, arguments: { last: { type: 'hash' } } do
with_node type: 'hash' do
if keys.any? { |key| node.has_key? key }
Expand Down Expand Up @@ -181,7 +178,7 @@
end
end

%w(first last).each do |message|
%w[first last].each do |message|
# Post.first(:conditions => {:title => "test"})
# =>
# Post.where(:title => "test").first
Expand All @@ -193,7 +190,7 @@
end
end

%w(count average min max sum).each do |message|
%w[count average min max sum].each do |message|
# Client.count("age", :conditions => {:active => true})
# Client.average("orders_count", :conditions => {:active => true})
# Client.min("age", :conditions => {:active => true})
Expand All @@ -208,7 +205,9 @@
within_node type: 'send', message: message, arguments: { size: 2 } do
argument_node = node.arguments.last
if :hash == argument_node.type && keys.any? { |key| argument_node.has_key? key }
replace_with add_receiver_if_necessary("#{generate_new_queries(argument_node)}.#{message}({{arguments.first}})")
replace_with add_receiver_if_necessary(
"#{generate_new_queries(argument_node)}.#{message}({{arguments.first}})"
)
end
end
end
Expand Down Expand Up @@ -258,15 +257,19 @@
# Post.where("title = ?", title).update_all("title = \'title\'")
within_node type: 'send', message: :update_all, arguments: { size: 2 } do
updates_node, conditions_node = node.arguments
replace_with add_receiver_if_necessary("where(#{(strip_brackets(conditions_node.to_source))}).update_all(#{strip_brackets(updates_node.to_source)})")
replace_with add_receiver_if_necessary(
"where(#{(strip_brackets(conditions_node.to_source))}).update_all(#{strip_brackets(updates_node.to_source)})"
)
end

# Post.update_all({:title => "title"}, {:title => "test"}, {:limit => 2})
# =>
# Post.where(:title => "test").limit(2).update_all(:title => "title")
within_node type: 'send', message: :update_all, arguments: { size: 3 } do
updates_node, conditions_node, options_node = node.arguments
replace_with add_receiver_if_necessary("where(#{strip_brackets(conditions_node.to_source)}).#{generate_new_queries(options_node)}.update_all(#{strip_brackets(updates_node.to_source)})")
replace_with add_receiver_if_necessary(
"where(#{strip_brackets(conditions_node.to_source)}).#{generate_new_queries(options_node)}.update_all(#{strip_brackets(updates_node.to_source)})"
)
end

# Post.delete_all("title = \'test\'")
Expand All @@ -280,14 +283,14 @@
# =>
# Post.where("title = \'test\'").destroy_all
# Post.where("title = ?", title).destroy_all
%w(delete_all destroy_all).each do |message|
%w[delete_all destroy_all].each do |message|
within_node type: 'send', message: message, arguments: { size: 1 } do
conditions_node = node.arguments.first
replace_with add_receiver_if_necessary("where(#{strip_brackets(conditions_node.to_source)}).#{message}")
end
end

%w(find_each find_in_batches).each do |message|
%w[find_each find_in_batches].each do |message|
# Post.find_each(:conditions => {:title => "test"}, :batch_size => 100) do |post|
# end
# =>
Expand All @@ -304,15 +307,17 @@
if :hash == argument_node.type && keys.any? { |key| argument_node.has_key? key }
batch_options = generate_batch_options(argument_node)
if batch_options.length > 0
replace_with add_receiver_if_necessary("#{generate_new_queries(argument_node)}.#{message}(#{batch_options})")
replace_with add_receiver_if_necessary(
"#{generate_new_queries(argument_node)}.#{message}(#{batch_options})"
)
else
replace_with add_receiver_if_necessary("#{generate_new_queries(argument_node)}.#{message}")
end
end
end
end

%w(with_scope with_exclusive_scope).each do |message|
%w[with_scope with_exclusive_scope].each do |message|
# with_scope(:find => {:conditions => {:active => true}}) { Post.first }
# =>
# with_scope(where(:active => true)) { Post.first }
Expand Down
12 changes: 11 additions & 1 deletion lib/rails/convert_rails_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@
# File.exists?(Rails.root.join('config/database.yml'))
# =>
# Rails.root.join('config/database.yml').exist?
with_node type: 'send', receiver: 'File', message: 'exists?', arguments: { size: 1, first: { type: 'send', receiver: 'Rails.root', message: 'join' } } do
with_node type: 'send',
receiver: 'File',
message: 'exists?',
arguments: {
size: 1,
first: {
type: 'send',
receiver: 'Rails.root',
message: 'join'
}
} do
replace_with '{{arguments.first}}.exist?'
end
end
Expand Down
11 changes: 7 additions & 4 deletions lib/rails/convert_rails_test_request_methods_4_2_to_5_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# =>
# get :show, params: { id: user.id }, flash: { notice: 'Welcome' }, session: { admin: user.admin? }.
within_files '{test,spec}/{functional,controllers}/**/*.rb' do
%w(get post put patch delete).each do |message|
%w[get post put patch delete].each do |message|
with_node type: 'send', message: message do
next unless node.arguments.size > 1
next unless node.arguments[1].type == :hash
Expand Down Expand Up @@ -47,10 +47,13 @@ def make_up_hash_pair(key, argument_node)
# =>
# get '/posts/1', params: { user_id: user.id }, headers: { 'HTTP_AUTHORIZATION' => 'fake' }
within_files '{test,spec}/{integration}/**/*.rb' do
%w(get post put patch delete).each do |message|
%w[get post put patch delete].each do |message|
with_node type: 'send', message: message do
next unless node.arguments.size > 1
next if node.arguments[1].type == :hash && (node.arguments[1].has_key?(:params) || node.arguments[1].has_key?(:headers))
if node.arguments[1].type == :hash &&
(node.arguments[1].has_key?(:params) || node.arguments[1].has_key?(:headers))
next
end

def make_up_hash_pair(key, argument_node)
if argument_node.to_source != 'nil'
Expand All @@ -68,4 +71,4 @@ def make_up_hash_pair(key, argument_node)
end
end
end
end
end
3 changes: 1 addition & 2 deletions lib/rails/convert_render_nothing_true_to_head_ok.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Synvert::Rewriter.new 'rails', 'convert_render_nothing_true_to_head_ok' do
description <<-EOF
It replaces render nothing: true with head :ok in controller files.
Expand All @@ -22,4 +21,4 @@
end
end
end
end
end
Loading