Skip to content

Commit 201aecb

Browse files
authored
Merge pull request rails#44555 from koic/enable_style_map_to_hash_cop
Enable `Style/MapToHash` cop
2 parents 269037a + 819871c commit 201aecb

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ Style/FrozenStringLiteralComment:
159159
- 'actionmailbox/db/migrate/**/*.rb'
160160
- 'actiontext/db/migrate/**/*.rb'
161161

162+
Style/MapToHash:
163+
Enabled: true
164+
162165
Style/RedundantFreeze:
163166
Enabled: true
164167

actiontext/lib/action_text/attachment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def inspect
9191

9292
private
9393
def node_attributes
94-
@node_attributes ||= ATTRIBUTES.map { |name| [ name.underscore, node[name] ] }.to_h.compact
94+
@node_attributes ||= ATTRIBUTES.to_h { |name| [ name.underscore, node[name] ] }.compact
9595
end
9696

9797
def attachable_attributes

actiontext/lib/action_text/trix_attachment.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def transform_attribute_keys(attributes)
3939
end
4040

4141
def typecast_attribute_values(attributes)
42-
attributes.map do |key, value|
42+
attributes.to_h do |key, value|
4343
typecast = ATTRIBUTE_TYPES[key] || ATTRIBUTE_TYPES[:default]
4444
[key, typecast.call(value)]
45-
end.to_h
45+
end
4646
end
4747
end
4848

actionview/lib/action_view/ripper_ast_parser.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ def to_hash
8686
end
8787

8888
def hash_from_body(body)
89-
body.map do |hash_node|
89+
body.to_h do |hash_node|
9090
return nil if hash_node.type != :assoc_new
9191

9292
[hash_node[0], hash_node[1]]
93-
end.to_h
93+
end
9494
end
9595

9696
def symbol?
@@ -189,9 +189,9 @@ def parse_render_nodes(code)
189189
parser = RenderCallExtractor.new(code)
190190
parser.parse
191191

192-
parser.render_calls.group_by(&:first).collect do |method, nodes|
192+
parser.render_calls.group_by(&:first).to_h do |method, nodes|
193193
[ method.to_sym, nodes.collect { |v| v[1] } ]
194-
end.to_h
194+
end
195195
end
196196
end
197197
end

activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def indexes(table_name)
5757
orders = options.delete(:orders)
5858
lengths = options.delete(:lengths)
5959

60-
columns = index[-1].map { |name|
60+
columns = index[-1].to_h { |name|
6161
[ name.to_sym, expressions[name] || +quote_column_name(name) ]
62-
}.to_h
62+
}
6363

6464
index[-1] = add_options_for_index_columns(
6565
columns, order: orders, length: lengths

activerecord/lib/active_record/encryption/encryptable_record.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ def build_encrypt_attribute_assignments
188188
end
189189

190190
def build_decrypt_attribute_assignments
191-
Array(self.class.encrypted_attributes).collect do |attribute_name|
191+
Array(self.class.encrypted_attributes).to_h do |attribute_name|
192192
type = type_for_attribute(attribute_name)
193193
encrypted_value = ciphertext_for(attribute_name)
194194
new_value = type.deserialize(encrypted_value)
195195
[attribute_name, new_value]
196-
end.to_h
196+
end
197197
end
198198

199199
def cant_modify_encrypted_attributes_when_frozen

activestorage/test/service/mirror_service_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
require "service/shared_service_tests"
44

55
class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
6-
mirror_config = (1..3).map do |i|
6+
mirror_config = (1..3).to_h do |i|
77
[ "mirror_#{i}",
88
service: "Disk",
99
root: Dir.mktmpdir("active_storage_tests_mirror_#{i}") ]
10-
end.to_h
10+
end
1111

1212
config = mirror_config.merge \
1313
mirror: { service: "Mirror", primary: "primary", mirrors: mirror_config.keys },

0 commit comments

Comments
 (0)