Skip to content

Commit 9f3fb53

Browse files
author
Awesome Code
committed
Auto corrected by following Format Ruby Code
1 parent a3a42fc commit 9f3fb53

16 files changed

+145
-40
lines changed

lib/helpers/parse_rails.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
with_configurations(number_of_workers: 1) do
88
tables = {}
99
within_file 'db/schema.rb' do
10-
within_node node_type: 'call_node', name: 'create_table' do
10+
within_node node_type: 'call_node', name: 'create_table' do
1111
table_name = node.arguments.arguments.first.to_value
1212
tables[table_name] = { columns: [], indices: [] }
1313
with_node node_type: 'call_node', receiver: 't', message: { not: 'index' } do

lib/helpers/set_rails_load_defaults.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
within_file 'config/application.rb' do
99
with_node node_type: 'class_node', constant_path: 'Application' do
1010
exists = false
11-
with_node node_type: 'call_node', receiver: 'config', name: 'load_defaults', arguments: { arguments: { length: 1 } } do
11+
with_node node_type: 'call_node',
12+
receiver: 'config',
13+
name: 'load_defaults',
14+
arguments: { arguments: { length: 1 } } do
1215
exists = true
1316
replace_with "config.load_defaults #{rails_version}"
1417
end

lib/rails/application_secrets_use_symbol_keys.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
# Rails.appplication.config.secrets[:smtp_settings]["address"]
2626
# =>
2727
# Rails.appplication.config.secrets[:smtp_settings][:address]
28-
with_node node_type: 'send', receiver: /^Rails.application.config.secrets/, message: '[]', arguments: { first: { node_type: 'str' } } do
28+
with_node node_type: 'send',
29+
receiver: /^Rails.application.config.secrets/,
30+
message: '[]',
31+
arguments: { first: { node_type: 'str' } } do
2932
replace 'arguments.first', with: '{{arguments.first.to_symbol}}'
3033
end
3134
end

lib/rails/convert_configs_3_0_to_3_1.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,12 @@ def down
173173

174174
within_file 'config/environments/test.rb' do
175175
# prepend config.static_cache_control = "public, max-age=3600"
176-
unless_exist_node node_type: 'call_node',
177-
receiver: 'config',
178-
name: 'static_cache_control=' do
176+
unless_exist_node node_type: 'call_node', receiver: 'config', name: 'static_cache_control=' do
179177
prepend 'config.static_cache_control = "public, max-age=3600"'
180178
end
181179

182180
# prepend config.serve_static_assets = true
183-
unless_exist_node node_type: 'call_node',
184-
receiver: 'config',
185-
name: 'serve_static_assets=' do
181+
unless_exist_node node_type: 'call_node', receiver: 'config', name: 'serve_static_assets=' do
186182
prepend 'config.serve_static_assets = true'
187183
end
188184
end

lib/rails/convert_configs_3_2_to_4_0.rb

+22-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@
100100
end
101101

102102
# remove config.middleware.xxx(..., ActionDispatch::BestStandardsSupport)
103-
with_node node_type: 'call_node', arguments: { node_type: 'arguments_node', arguments: { includes: 'ActionDispatch::BestStandardsSupport' } } do
103+
with_node node_type: 'call_node',
104+
arguments: {
105+
node_type: 'arguments_node',
106+
arguments: { includes: 'ActionDispatch::BestStandardsSupport' }
107+
} do
104108
remove
105109
end
106110

@@ -151,9 +155,23 @@
151155
receiver: 'ActiveSupport',
152156
name: 'on_load',
153157
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: :active_record } },
154-
block: { node_type: 'block_node', body: { node_type: 'statements_node', body: { size: 1, first: {
155-
node_type: 'call_node', receiver: 'self', name: 'include_root_in_json=', arguments: { node_type: 'arguments_node', arguments: { size: 1, first: false } }
156-
} } } } do
158+
block: {
159+
node_type: 'block_node',
160+
body: {
161+
node_type: 'statements_node',
162+
body: {
163+
size: 1,
164+
first: {
165+
node_type: 'call_node',
166+
receiver: 'self',
167+
name: 'include_root_in_json=',
168+
arguments: {
169+
node_type: 'arguments_node', arguments: { size: 1, first: false }
170+
}
171+
}
172+
}
173+
}
174+
} do
157175
remove
158176
end
159177
end

lib/rails/convert_dynamic_finders_for_rails_3.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929

3030
call_helper 'rails/parse'
3131
rails_tables = load_data :rails_tables
32-
table_columns = rails_tables.present? ? rails_tables.values.flat_map { |value| value[:columns] }.map { |column| column[:name] } + ['id'] : []
32+
table_columns =
33+
rails_tables.present? ? rails_tables.values.flat_map { |value|
34+
value[:columns]
35+
}
36+
.map { |column| column[:name] } + ['id'] : []
3337

3438
helper_method :dynamic_finder_to_hash do |prefix|
3539
fields = node.message.to_s[prefix.length..-1].split('_and_')

lib/rails/convert_dynamic_finders_for_rails_4.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
call_helper 'rails/parse'
2323
rails_tables = load_data :rails_tables
24-
table_columns = rails_tables.present? ? rails_tables.values.flat_map { |value| value[:columns] }.map { |column| column[:name] } + ['id'] : []
24+
table_columns =
25+
rails_tables.present? ? rails_tables.values.flat_map { |value|
26+
value[:columns]
27+
}
28+
.map { |column| column[:name] } + ['id'] : []
2529

2630
helper_method :dynamic_finder_to_hash do |prefix|
2731
fields = node.message.to_s[prefix.length..-1].split('_and_')

lib/rails/convert_views_3_2_to_4_0.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,30 @@
2323
# link_to 'delete', post_path(post), confirm: 'Are you sure to delete post?'
2424
# =>
2525
# link_to 'delete', post_path(post), data: { confirm: 'Are you sure to delete post?' }
26-
within_node node_type: 'send', message: 'link_to', arguments: { last: { node_type: 'hash', confirm_value: { not: nil }, data_value: nil } } do
26+
within_node node_type: 'send',
27+
message: 'link_to',
28+
arguments: {
29+
last: {
30+
node_type: 'hash',
31+
confirm_value: { not: nil },
32+
data_value: nil
33+
}
34+
} do
2735
group do
2836
delete 'arguments.last.confirm_pair', and_comma: true
2937
insert 'data: { confirm: {{arguments.last.confirm_value}} }', to: 'arguments.last', and_comma: true
3038
end
3139
end
3240

33-
within_node node_type: 'send', message: 'link_to', arguments: { last: { node_type: 'hash', confirm_value: { not: nil }, data_value: { not: nil } } } do
41+
within_node node_type: 'send',
42+
message: 'link_to',
43+
arguments: {
44+
last: {
45+
node_type: 'hash',
46+
confirm_value: { not: nil },
47+
data_value: { not: nil }
48+
}
49+
} do
3450
group do
3551
delete 'arguments.last.confirm_pair', and_comma: true
3652
insert 'confirm: {{arguments.last.confirm_value}}', to: 'arguments.last.data_pair.value.pairs', and_comma: true

lib/rails/strong_parameters.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ def xxx_params
7171
within_files Synvert::RAILS_MODEL_FILES do
7272
within_node node_type: 'class' do
7373
object_name = node.name.to_source.underscore
74-
table_columns = rails_tables.present? ? rails_tables[object_name.tableize][:columns].map { |column| column[:name] } - default_columns : []
74+
table_columns =
75+
rails_tables.present? ? rails_tables[object_name.tableize][:columns].map { |column|
76+
column[:name]
77+
} - default_columns : []
7578

7679
# assign and remove attr_accessible ...
7780
with_node node_type: 'send', message: 'attr_accessible' do
@@ -87,7 +90,6 @@ def xxx_params
8790
end
8891
end
8992

90-
9193
within_file Synvert::RAILS_CONTROLLER_FILES do
9294
within_node node_type: 'class' do
9395
object_name = node.name.to_source.sub('Controller', '').singularize.underscore

lib/rails/test_request_methods_use_keyword_arguments.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,21 @@
4242
within_files Synvert::RAILS_CONTROLLER_TEST_FILES + Synvert::RAILS_INTEGRATION_TEST_FILES do
4343
with_node node_type: 'call_node',
4444
name: { in: request_methods },
45-
arguments: { node_type: 'arguments_node', arguments: { size: 2, '-1': { node_type: { in: %w[local_variable_read_node instance_variable_read_node call_node] } } } } do
45+
arguments: {
46+
node_type: 'arguments_node',
47+
arguments: {
48+
size: 2,
49+
'-1': {
50+
node_type: {
51+
in: %w[
52+
local_variable_read_node
53+
instance_variable_read_node
54+
call_node
55+
]
56+
}
57+
}
58+
}
59+
} do
4660
insert '**', to: 'arguments.arguments.-1', at: 'beginning'
4761
end
4862
end

lib/rails/update_active_storage_variant_argument.rb

+21-4
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,38 @@
2626
if_gem 'activestorage', '>= 7.0'
2727

2828
within_files Synvert::ALL_RUBY_FILES + Synvert::ALL_RAKE_FILES do
29-
with_node node_type: 'send', message: 'variant', arguments: { size: 1, first: { node_type: 'hash', resize_value: { node_type: 'str', value: { last: 'x' } } } } do
29+
with_node node_type: 'send',
30+
message: 'variant',
31+
arguments: {
32+
size: 1,
33+
first: { node_type: 'hash', resize_value: { node_type: 'str', value: { last: 'x' } } }
34+
} do
3035
width = node.arguments.first.resize_value.to_value.to_i
3136
replace 'arguments.first.resize_pair', with: "resize_to_limit: [#{width}, nil]"
3237
end
3338

34-
with_node node_type: 'send', message: 'variant', arguments: { size: 1, first: { node_type: 'hash', crop_value: { node_type: 'str' } } } do
39+
with_node node_type: 'send',
40+
message: 'variant',
41+
arguments: { size: 1, first: { node_type: 'hash', crop_value: { node_type: 'str' } } } do
3542
width, height, x, y = node.arguments.first.crop_value.to_value.split(/x|\+/)
3643
replace :arguments, with: "crop: [#{x}, #{y}, #{width}, #{height}]"
3744
end
3845

39-
with_node node_type: 'send', message: 'variant', arguments: { size: 1, first: { node_type: 'hash', resize_and_pad_value: { node_type: 'array', elements: { size: 2 } } } } do
46+
with_node node_type: 'send',
47+
message: 'variant',
48+
arguments: {
49+
size: 1,
50+
first: {
51+
node_type: 'hash',
52+
resize_and_pad_value: { node_type: 'array', elements: { size: 2 } }
53+
}
54+
} do
4055
insert 'background: [255]', to: 'arguments.0.pairs.0.value.elements.-1', at: 'end', and_comma: true
4156
end
4257

43-
with_node node_type: 'send', message: 'variant', arguments: { size: 1, first: { node_type: 'hash', monochrome_value: true } } do
58+
with_node node_type: 'send',
59+
message: 'variant',
60+
arguments: { size: 1, first: { node_type: 'hash', monochrome_value: true } } do
4461
replace 'arguments.first.monochrome_pair', with: 'colourspace: "b-w"'
4562
end
4663
end

lib/rails/use_active_storage_image_processing_macros.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
if_gem 'activestorage', '>= 6.1'
2525

2626
within_files Synvert::ALL_RUBY_FILES + Synvert::ALL_RAKE_FILES do
27-
with_node node_type: 'send', message: 'preview', arguments: { size: 1, first: { node_type: 'hash', resize_value: { not: nil } } } do
27+
with_node node_type: 'send',
28+
message: 'preview',
29+
arguments: { size: 1, first: { node_type: 'hash', resize_value: { not: nil } } } do
2830
resize_value = node.arguments.first.resize_value.to_value
2931
width, height = resize_value.split('x')
3032
if resize_value.ends_with?('>')

lib/rspec/one_liner_expectation.rb

+16-11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
{ should: 'to', should_not: 'not_to' }.each do |old_message, new_message|
3939
# it { should matcher } => it { is_expected.to matcher }
4040
# it { should_not matcher } => it { is_expected.not_to matcher }
41-
with_node node_type: 'block', caller: { message: 'it' }, body: { size: 1, first: { node_type: 'send', receiver: nil, message: old_message } } do
41+
with_node node_type: 'block',
42+
caller: { message: 'it' },
43+
body: { size: 1, first: { node_type: 'send', receiver: nil, message: old_message } } do
4244
receiver = node.body.first.arguments.first.receiver
4345
unless receiver && matcher_converters.include?(receiver.message)
4446
matcher = node.body.first.arguments.first.to_source
@@ -60,20 +62,23 @@
6062
matcher_converters.each do |old_matcher, new_matcher|
6163
with_node node_type: 'block',
6264
caller: { message: 'it' },
63-
body: { size: 1, first: {
64-
node_type: 'send',
65-
receiver: nil,
66-
message: old_message,
67-
arguments: {
68-
first: {
69-
node_type: 'send',
70-
receiver: {
65+
body: {
66+
size: 1,
67+
first: {
68+
node_type: 'send',
69+
receiver: nil,
70+
message: old_message,
71+
arguments: {
72+
first: {
7173
node_type: 'send',
72-
message: old_matcher
74+
receiver: {
75+
node_type: 'send',
76+
message: old_matcher
77+
}
7378
}
7479
}
7580
}
76-
} } do
81+
} do
7782
times = node.body.first.arguments.first.receiver.arguments.first.to_source
7883
items_name = node.body.first.arguments.first.message
7984
if :items == items_name

lib/ruby/nested_class_definition.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@ def test; end
3838
parts = node.name.to_source.split('::')
3939
class_name = parts.pop
4040
new_parts = parts.map.with_index { |mod, index| ' ' * NodeMutation.tab_width * index + "module #{mod}" }
41-
new_parts.concat(source.sub(parts.join('::') + '::', '').split("\n").map { |line| (' ' * NodeMutation.tab_width * parts.size) + line })
42-
new_parts.concat(parts.map.with_index { |mod, index| ' ' * NodeMutation.tab_width * (parts.size - index - 1) + "end" })
41+
new_parts.concat(
42+
source.sub(parts.join('::') + '::', '').split("\n").map { |line|
43+
(' ' * NodeMutation.tab_width * parts.size) + line
44+
}
45+
)
46+
new_parts.concat(
47+
parts.map.with_index { |mod, index|
48+
' ' * NodeMutation.tab_width * (parts.size - index - 1) + "end"
49+
}
50+
)
4351

4452
replace_with new_parts.join("\n")
4553
end

lib/ruby/use_keyword_arguments.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,21 @@
2828
with_node node_type: 'call_node',
2929
receiver: 'CSV',
3030
name: 'generate',
31-
arguments: { node_type: 'arguments_node', arguments: { size: 1, '0': { node_type: { in: %w[local_variable_read_node instance_variable_read_node call_node] } } } } do
31+
arguments: {
32+
node_type: 'arguments_node',
33+
arguments: {
34+
size: 1,
35+
'0': {
36+
node_type: {
37+
in: %w[
38+
local_variable_read_node
39+
instance_variable_read_node
40+
call_node
41+
]
42+
}
43+
}
44+
}
45+
} do
3246
insert '**', to: 'arguments.arguments.0', at: 'beginning'
3347
end
3448
end

spec/rails/convert_configs_3_2_to_4_0_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class Application < Rails::Application
9696
Synvert::Application.config.secret_key_base = "bf4f3f46924ecd9adcb6515681c78144545bba454420973a274d7021ff946b8ef043a95ca1a15a9d1b75f9fbdf85d1a3afaf22f4e3c2f3f78e24a0a188b581df"
9797
EOS
9898

99-
10099
let(:fake_file_paths) {
101100
%w[
102101
config/application.rb

0 commit comments

Comments
 (0)