Skip to content

Commit 84a9a6a

Browse files
author
Awesome Code
committed
Auto corrected by following Format Ruby Code
1 parent ffe7d35 commit 84a9a6a

37 files changed

+525
-188
lines changed

lib/helpers/parse_rails.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
with_configurations(number_of_workers: 1) do
1010
tables = {}
1111
within_file 'db/schema.rb' do
12-
within_node node_type: 'call_node', name: 'create_table' do
12+
within_node node_type: 'call_node', name: 'create_table' do
1313
table_name = node.arguments.arguments.first.to_value
1414
tables[table_name] = { columns: [], indices: [] }
1515
with_node node_type: 'call_node', receiver: 't', message: { not: 'index' } do
@@ -66,7 +66,12 @@
6666
options[option_key] = option_element.value.to_value if option_element
6767
end
6868
end
69-
associations << { class_name: context_stack.join('::'), name: association_name.to_s, type: node.name.to_s, **options }
69+
associations << {
70+
class_name: context_stack.join('::'),
71+
name: association_name.to_s,
72+
type: node.name.to_s,
73+
**options
74+
}
7075
end
7176
end
7277
end

lib/helpers/parse_ruby.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ def initialize
149149
end
150150

151151
def to_h
152-
{ modules: @modules.map(&:to_h), classes: @classes.map(&:to_h), constants: @constants, methods: @methods.map(&:to_h) }
152+
{
153+
modules: @modules.map(&:to_h),
154+
classes: @classes.map(&:to_h),
155+
constants: @constants,
156+
methods: @methods.map(&:to_h)
157+
}
153158
end
154159
end
155160

@@ -176,7 +181,7 @@ def to_h
176181
methods: @methods.map(&:to_h),
177182
static_methods: @static_methods.map(&:to_h),
178183
constants: @constants,
179-
singleton: @singleton &.to_h,
184+
singleton: @singleton&.to_h,
180185
ancestors: @ancestors
181186
}
182187
end
@@ -288,7 +293,10 @@ def to_h
288293
end
289294

290295
add_callback :call_node, at: 'start' do |node|
291-
if node.receiver.nil? && node.name == :include && definitions.current_node_type == "class" && !node.arguments.nil? && %i[constant_read_node constant_path_node].include?(node.arguments.arguments.first.type)
296+
if node.receiver.nil? && node.name == :include && definitions.current_node_type == "class" && !node.arguments.nil? && %i[
297+
constant_read_node constant_path_node
298+
].include?(node.arguments.arguments.first.type)
299+
292300
definitions.add_included_module(node.arguments.arguments.first.to_source)
293301
end
294302
end

lib/helpers/set_rails_load_defaults.rb

Lines changed: 4 additions & 1 deletion
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/convert_after_commit.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@
4141
with_node node_type: 'call_node',
4242
receiver: nil,
4343
name: 'after_commit',
44-
arguments: { node_type: 'arguments_node', arguments: { size: 2, '1': { node_type: 'keyword_hash_node', on_value: { in: %i[create update destroy] } } } } do
44+
arguments: {
45+
node_type: 'arguments_node',
46+
arguments: {
47+
size: 2,
48+
'1': { node_type: 'keyword_hash_node', on_value: { in: %i[create update destroy] } }
49+
}
50+
} do
4551
group do
4652
replace :name, with: 'after_{{arguments.arguments.-1.on_value.to_value}}_commit'
4753
delete 'arguments.arguments.-1.on_element', and_comma: true
@@ -60,7 +66,13 @@
6066
with_node node_type: 'call_node',
6167
receiver: nil,
6268
message: 'after_commit',
63-
arguments: { node_type: 'arguments_node', arguments: { size: 2, '1': { node_type: 'keyword_hash_node', on_value: { node_type: 'array_node' } } } } do
69+
arguments: {
70+
node_type: 'arguments_node',
71+
arguments: {
72+
size: 2,
73+
'1': { node_type: 'keyword_hash_node', on_value: { node_type: 'array_node' } }
74+
}
75+
} do
6476
group do
6577
if node.arguments.arguments[1].on_value.elements.size == 1
6678
replace :message, with: 'after_{{arguments.arguments.-1.on_value.elements.0.to_value}}_commit'

lib/rails/convert_configs_3_0_to_3_1.rb

Lines changed: 2 additions & 6 deletions
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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@
102102
end
103103

104104
# remove config.middleware.xxx(..., ActionDispatch::BestStandardsSupport)
105-
with_node node_type: 'call_node', arguments: { node_type: 'arguments_node', arguments: { includes: 'ActionDispatch::BestStandardsSupport' } } do
105+
with_node node_type: 'call_node',
106+
arguments: {
107+
node_type: 'arguments_node',
108+
arguments: { includes: 'ActionDispatch::BestStandardsSupport' }
109+
} do
106110
remove
107111
end
108112

@@ -153,9 +157,23 @@
153157
receiver: 'ActiveSupport',
154158
name: 'on_load',
155159
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: :active_record } },
156-
block: { node_type: 'block_node', body: { node_type: 'statements_node', body: { size: 1, first: {
157-
node_type: 'call_node', receiver: 'self', name: 'include_root_in_json=', arguments: { node_type: 'arguments_node', arguments: { size: 1, first: false } }
158-
} } } } do
160+
block: {
161+
node_type: 'block_node',
162+
body: {
163+
node_type: 'statements_node',
164+
body: {
165+
size: 1,
166+
first: {
167+
node_type: 'call_node',
168+
receiver: 'self',
169+
name: 'include_root_in_json=',
170+
arguments: {
171+
node_type: 'arguments_node', arguments: { size: 1, first: false }
172+
}
173+
}
174+
}
175+
}
176+
} do
159177
remove
160178
end
161179
end

lib/rails/convert_configs_4_2_to_5_0.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555
name: 'middleware'
5656
},
5757
name: 'use',
58-
arguments: { node_type: 'arguments_node', arguments: { size: { gt: 0 }, first: { node_type: 'string_node' } } } do
58+
arguments: {
59+
node_type: 'arguments_node',
60+
arguments: { size: { gt: 0 }, first: { node_type: 'string_node' } }
61+
} do
5962
replace 'arguments.arguments.first', with: "{{arguments.arguments.first.to_value}}"
6063
end
6164
end

lib/rails/convert_dynamic_finders_for_rails_3.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@
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.name.to_s[prefix.length..-1].split('_and_')
3640
return nil if (fields - table_columns).present?
3741

3842
if fields.length == node.arguments.arguments.length && :hash_node != node.arguments.arguments.first.type
39-
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }.join(', ')
43+
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }
44+
.join(', ')
4045
else
4146
'{{arguments}}'
4247
end

lib/rails/convert_dynamic_finders_for_rails_4.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@
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.name.to_s[prefix.length..-1].split('_and_')
2832
return nil if (fields - table_columns).present?
2933

3034
if fields.length == node.arguments.arguments.length && :hash_node != node.arguments.arguments.first.type
31-
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }.join(', ')
35+
fields.length.times.map { |i| fields[i] + ': ' + node.arguments.arguments[i].to_source }
36+
.join(', ')
3237
else
3338
'{{arguments}}'
3439
end

lib/rails/convert_head_response.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
with_node node_type: 'call_node',
3737
receiver: nil,
3838
name: 'render',
39-
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', nothing_value: true } } } do
39+
arguments: {
40+
node_type: 'arguments_node',
41+
arguments: { size: 1, first: { node_type: 'keyword_hash_node', nothing_value: true } }
42+
} do
4043
group do
4144
replace :message, with: 'head'
4245
if node.arguments.arguments.first.status_value.nil?
@@ -53,7 +56,13 @@
5356
with_node node_type: 'call_node',
5457
receiver: nil,
5558
name: 'head',
56-
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', location_value: { not: nil } } } } do
59+
arguments: {
60+
node_type: 'arguments_node',
61+
arguments: {
62+
size: 1,
63+
first: { node_type: 'keyword_hash_node', location_value: { not: nil } }
64+
}
65+
} do
5766
replace 'arguments.arguments.0', with: ':ok, {{arguments.arguments.0.to_source}}'
5867
end
5968

@@ -63,7 +72,13 @@
6372
with_node node_type: 'call_node',
6473
receiver: nil,
6574
name: 'head',
66-
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node', status_value: { not: nil } } } } do
75+
arguments: {
76+
node_type: 'arguments_node',
77+
arguments: {
78+
size: 1,
79+
first: { node_type: 'keyword_hash_node', status_value: { not: nil } }
80+
}
81+
} do
6782
replace 'arguments.arguments.0', with: '{{arguments.arguments.0.status_source}}'
6883
end
6984
end

lib/rails/convert_mailers_2_3_to_3_0.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ def signup_notification(recipient)
7979
class_name = node.name
8080
within_node node_type: 'def_node' do
8181
args = {}
82-
with_node node_type: 'call_node', receiver: nil, name: 'recipients', arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
82+
with_node node_type: 'call_node',
83+
receiver: nil,
84+
name: 'recipients',
85+
arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
8386
args[:to] = node.arguments.arguments.first.to_source
8487
remove
8588
end
@@ -97,13 +100,20 @@ def signup_notification(recipient)
97100
with_node node_type: 'call_node',
98101
receiver: nil,
99102
name: 'body',
100-
arguments: { node_type: 'arguments_node', arguments: { size: 1, first: { node_type: 'keyword_hash_node' } } } do
101-
replace_with node.arguments.arguments.first.elements.map { |element| "@#{element.key.to_value} = #{element.value.to_source}" }.join("\n")
103+
arguments: {
104+
node_type: 'arguments_node',
105+
arguments: { size: 1, first: { node_type: 'keyword_hash_node' } }
106+
} do
107+
replace_with node.arguments.arguments.first.elements.map { |element|
108+
"@#{element.key.to_value} = #{element.value.to_source}"
109+
}
110+
.join("\n")
102111
end
103112
if args.size > 0
104113
mailer_methods[class_name] ||= []
105114
mailer_methods[class_name] << node.name
106-
args_str = args.map { |key, value| ":#{key} => #{value}" }.join(', ')
115+
args_str = args.map { |key, value| ":#{key} => #{value}" }
116+
.join(', ')
107117
append "mail(#{args_str})"
108118
end
109119
end
@@ -134,7 +144,10 @@ def signup_notification(recipient)
134144
# Notifier.deliver(message)
135145
# =>
136146
# message.deliver
137-
with_node node_type: 'call_node', receiver: { not: nil }, name: 'deliver', arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
147+
with_node node_type: 'call_node',
148+
receiver: { not: nil },
149+
name: 'deliver',
150+
arguments: { node_type: 'arguments_node', arguments: { size: 1 } } do
138151
if mailer_methods[node.receiver.name]
139152
replace_with '{{arguments}}.{{message}}'
140153
end

lib/rails/convert_model_lambda_scope.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class Post < ActiveRecord::Base
6666
}
6767
} do
6868
if node.arguments.arguments.last.block.parameters
69-
replace 'arguments.arguments.last', with: '->({{arguments.arguments.last.block.parameters.parameters}}) { {{arguments.arguments.last.block.body}} }'
69+
replace 'arguments.arguments.last',
70+
with: '->({{arguments.arguments.last.block.parameters.parameters}}) { {{arguments.arguments.last.block.body}} }'
7071
else
7172
replace 'arguments.arguments.last', with: '-> { {{arguments.arguments.last.block.body}} }'
7273
end
@@ -87,7 +88,8 @@ class Post < ActiveRecord::Base
8788
}
8889
} do
8990
if node.arguments.arguments.last.block.parameters
90-
replace 'arguments.arguments.last', with: '->({{arguments.arguments.last.block.parameters.parameters}}) { {{arguments.arguments.last.block.body}} }'
91+
replace 'arguments.arguments.last',
92+
with: '->({{arguments.arguments.last.block.parameters.parameters}}) { {{arguments.arguments.last.block.body}} }'
9193
else
9294
replace 'arguments.arguments.last', with: '-> { {{arguments.arguments.last.block.body}} }'
9395
end
@@ -102,10 +104,7 @@ class Post < ActiveRecord::Base
102104
end
103105

104106
# default_scope { order("updated_at DESC") } => default_scope -> { order("updated_at DESC") }
105-
with_node node_type: 'call_node',
106-
receiver: nil,
107-
name: 'default_scope',
108-
block: { node_type: 'block_node' } do
107+
with_node node_type: 'call_node', receiver: nil, name: 'default_scope', block: { node_type: 'block_node' } do
109108
replace_with 'default_scope -> { {{block.body.body}} }'
110109
end
111110
end

0 commit comments

Comments
 (0)