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 #136

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
Expand Up @@ -3,5 +3,6 @@
Synvert::Rewriter.new 'default', 'check_syntax' do
description 'Just used to check if there is a syntax error.'

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 @@ -79,4 +79,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 @@ -68,11 +68,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
10 changes: 8 additions & 2 deletions lib/factory_bot/use_short_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ class MiniTest::Rails::ActiveSupport::TestCase

# insert include FactoryBot::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: ['FactoryBot::Syntax::Methods'] do
insert 'include FactoryBot::Syntax::Methods'
Expand All @@ -104,7 +110,7 @@ class MiniTest::Rails::ActiveSupport::TestCase
# FactoryBot.create_pair(...) => create_pair(...)
# FactoryBot.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: 'FactoryBot', message: message do
replace_with "#{message}({{arguments}})"
end
Expand Down
44 changes: 38 additions & 6 deletions lib/factory_girl/fix_2_0_deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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 @@ -98,7 +106,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 @@ -116,7 +124,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 @@ -130,7 +146,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 @@ -147,7 +171,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 @@ -173,7 +205,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 @@ -81,7 +81,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 @@ -106,7 +112,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 @@ -28,4 +28,4 @@ class CreateUsers < ActiveRecord::Migration[4.2]
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/rails/add_application_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class ApplicationJob < ActiveJob::Base
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/rails/add_application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class ApplicationRecord < ActiveRecord::Base
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/rails/convert_after_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
end
end
end
end
end
13 changes: 7 additions & 6 deletions lib/rails/convert_controller_filter_to_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ class PostsController < ApplicationController
# before_filter :load_post => before_action :load_post
# after_filter :increment_view_count => after_filter :increment_view_count
with_node type: 'send', receiver: nil, message: /_filter$/ do
new_message = if node.message == :skip_filter
'skip_action_callback'
else
node.message.to_s.sub('filter', 'action')
end
new_message =
if node.message == :skip_filter
'skip_action_callback'
else
node.message.to_s.sub('filter', 'action')
end
replace_with "#{new_message} {{arguments}}"
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 @@ -39,9 +39,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
2 changes: 1 addition & 1 deletion lib/rails/convert_head_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
end
end
end
end
end
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 @@ -81,7 +81,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 @@ -97,7 +97,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
3 changes: 1 addition & 2 deletions lib/rails/convert_model_lambda_scope.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# frozen_string_literal: true

Synvert::Rewriter.new 'rails', 'convert_model_lambda_scope' do
Expand Down Expand Up @@ -66,4 +65,4 @@ class Post < ActiveRecord::Base
replace_with 'default_scope -> { {{body}} }'
end
end
end
end
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 @@ -164,10 +164,7 @@
EOS

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 @@ -198,7 +195,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 @@ -254,7 +251,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 @@ -266,7 +263,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 @@ -281,7 +278,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 @@ -331,15 +330,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 @@ -353,14 +356,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 @@ -377,15 +380,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
Loading