]> source.dussan.org Git - redmine.git/commitdiff
Fix RuboCop offense Style/HashEachMethods (#39887).
authorGo MAEDA <maeda@farend.jp>
Wed, 20 Dec 2023 08:13:48 +0000 (08:13 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 20 Dec 2023 08:13:48 +0000 (08:13 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@22532 e93f8b46-1217-0410-a6f0-8f06a7374b81

13 files changed:
.rubocop.yml
.rubocop_todo.yml
app/controllers/groups_controller.rb
app/controllers/workflows_controller.rb
app/helpers/attachments_helper.rb
app/models/journal.rb
app/models/mailer.rb
app/models/project.rb
app/models/role.rb
app/models/token.rb
lib/redmine/acts/mentionable.rb
test/functional/issues_custom_fields_visibility_test.rb
test/unit/auth_source_ldap_test.rb

index b30000672c9826dab1d98acee496bf41d7f61b33..4fae950f00a87115a16fae7431c195164c8bb464 100644 (file)
@@ -221,6 +221,11 @@ Style/GlobalStdStream:
 Style/HashSyntax:
   EnforcedStyle: no_mixed_keys
 
+Style/HashEachMethods:
+  Exclude:
+    - 'db/migrate/072_add_enumerations_position.rb'
+    - 'db/migrate/078_add_custom_fields_position.rb'
+
 Style/IdenticalConditionalBranches:
   Exclude:
     - 'config/initializers/10-patches.rb'
index 1c7208e3fb15240e2ac2ece8bdb99d8ec5970a4c..5c37fd235b5c79dde11b0ef22468e70b52667e9d 100644 (file)
@@ -1106,17 +1106,6 @@ Style/HashAsLastArrayItem:
     - 'app/controllers/enumerations_controller.rb'
     - 'app/models/board.rb'
 
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: AllowedReceivers.
-# AllowedReceivers: Thread.current
-Style/HashEachMethods:
-  Exclude:
-    - 'app/controllers/groups_controller.rb'
-    - 'app/models/mailer.rb'
-    - 'app/models/role.rb'
-    - 'test/functional/issues_custom_fields_visibility_test.rb'
-    - 'test/unit/auth_source_ldap_test.rb'
-
 # This cop supports safe autocorrection (--autocorrect).
 # Configuration parameters: AllowIfModifier.
 Style/IfInsideElse:
index 85192a9d70ae49992fdd6587064357011ea7a879..41e7b100049b6ebf42342d672465592beaa811e7 100644 (file)
@@ -153,10 +153,6 @@ class GroupsController < ApplicationController
   end
 
   def user_count_by_group_id
-    h = User.joins(:groups).group('group_id').count
-    h.keys.each do |key|
-      h[key.to_i] = h.delete(key)
-    end
-    h
+    User.joins(:groups).group(:group_id).count.transform_keys(&:to_i)
   end
 end
index b1dea0c4c619d057b3a7a847f3bdac4176b032e5..3bb46ad143fd33c78016ead7e293476bb3d1788c 100644 (file)
@@ -45,8 +45,8 @@ class WorkflowsController < ApplicationController
   def update
     if @roles && @trackers && params[:transitions]
       transitions = params[:transitions].deep_dup
-      transitions.each do |old_status_id, transitions_by_new_status|
-        transitions_by_new_status.each do |new_status_id, transition_by_rule|
+      transitions.each_value do |transitions_by_new_status|
+        transitions_by_new_status.each_value do |transition_by_rule|
           transition_by_rule.reject! {|rule, transition| transition == 'no_change'}
         end
       end
@@ -68,7 +68,7 @@ class WorkflowsController < ApplicationController
   def update_permissions
     if @roles && @trackers && params[:permissions]
       permissions = params[:permissions].deep_dup
-      permissions.each do |field, rule_by_status_id|
+      permissions.each_value do |rule_by_status_id|
         rule_by_status_id.reject! {|status_id, rule| rule == 'no_change'}
       end
       WorkflowPermission.replace_permissions(@trackers, @roles, permissions)
index a9e147a3f1da64982228a8856715ad470516f1b4..fc2cca351fbeee2434fa216e82314bb4b3400068 100644 (file)
@@ -70,7 +70,7 @@ module AttachmentsHelper
   def render_api_attachment(attachment, api, options={})
     api.attachment do
       render_api_attachment_attributes(attachment, api)
-      options.each {|key, value| eval("api.#{key} value")}
+      options.each_key {|key| eval("api.#{key} value")}
     end
   end
 
index 4b4139a149c7ea870aa46bc015acfe8d3db7d85f..cc5611754902279d03ccef0c609c46a04afd724f 100644 (file)
@@ -264,7 +264,7 @@ class Journal < ActiveRecord::Base
     # custom fields changes
     if @custom_values_before_change
       values_by_custom_field_id = {}
-      @custom_values_before_change.each do |custom_field_id, value|
+      @custom_values_before_change.each_key do |custom_field_id|
         values_by_custom_field_id[custom_field_id] = nil
       end
       journalized.custom_field_values.each do |c|
index c4c7ab07fe261f1776073a6c51e401645882b6e1..2fe9673c9dc8f7b4ed3d5811217e3d288df7e5be 100644 (file)
@@ -620,7 +620,7 @@ class Mailer < ActionMailer::Base
     scope = scope.where(:tracker_id => tracker.id) if tracker
     issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).
                               group_by(&:assigned_to)
-    issues_by_assignee.keys.each do |assignee|
+    issues_by_assignee.keys.each do |assignee|  # rubocop:disable Style/HashEachMethods
       if assignee.is_a?(Group)
         assignee.users.each do |user|
           issues_by_assignee[user] ||= []
index 11f4a953da2475b9cef0ba26e74e1501bdc93f45..1bf5f913c38744454c62f64ed9dd55c230392701 100644 (file)
@@ -1128,7 +1128,7 @@ class Project < ActiveRecord::Base
 
     # Store status and reopen locked/closed versions
     version_statuses = versions.reject(&:open?).map {|version| [version, version.status]}
-    version_statuses.each do |version, status|
+    version_statuses.each do |version, _| # rubocop:disable Style/HashEachMethods
       version.update_attribute :status, 'open'
     end
 
index 1665d798255d638c41ba1e0dbab577f4a3f7e3f5..13ebb33248a2df5c417ee8d756a54d63ddc713fd 100644 (file)
@@ -224,7 +224,7 @@ class Role < ActiveRecord::Base
 
   def permissions_tracker_ids=(arg)
     h = arg.to_hash
-    h.values.each {|v| v.reject!(&:blank?)}
+    h.each_value {|v| v.reject!(&:blank?)}
     super(h)
   end
 
index 1fd9c228b1897828c99f06aad292353b81c4c420..29340edbad6d862c38357244326699695a4bc0e1 100644 (file)
@@ -78,7 +78,7 @@ class Token < ActiveRecord::Base
     # Unknown actions have default validity_time
     condition = t[:action].not_in(self.actions.keys).and(t[:created_on].lt(invalid_when_created_before))
 
-    self.actions.each do |action, options|
+    self.actions.each_key do |action|
       validity_time = invalid_when_created_before(action)
 
       # Do not delete tokens, which don't become invalid
index 24adf04b3f5a0c296f53c8e24e0ce5b859ed8af8..f8332637e7419244298cec77f13e7746918dc969 100644 (file)
@@ -57,7 +57,7 @@ module Redmine
           mentionable_attrs = self.mentionable_attributes
           saved_mentionable_attrs = self.saved_changes.select{|a| mentionable_attrs.include?(a)}
 
-          saved_mentionable_attrs.each do |key, attr|
+          saved_mentionable_attrs.each_value do |attr|
             old_value, new_value =  attr
             get_mentioned_users(old_value, new_value)
           end
index 46ca01100309f0f420d2a638dcb6d68cf3eed79b..6a06abe12432584dfaf72971321759de144a4023 100644 (file)
@@ -323,7 +323,7 @@ class IssuesCustomFieldsVisibilityTest < Redmine::ControllerTest
     # anonymous user is never notified
     users_to_test = @users_to_test.reject {|k, v| k.anonymous?}
 
-    users_to_test.keys.each do |user|
+    users_to_test.each_key do |user|
       Watcher.create!(:user => user, :watchable => @issue)
     end
     ActionMailer::Base.deliveries.clear
@@ -362,7 +362,7 @@ class IssuesCustomFieldsVisibilityTest < Redmine::ControllerTest
     # anonymous user is never notified
     users_to_test = @users_to_test.reject {|k, v| k.anonymous?}
 
-    users_to_test.keys.each do |user|
+    users_to_test.each_key do |user|
       Watcher.create!(:user => user, :watchable => @issue)
     end
     ActionMailer::Base.deliveries.clear
index 9c37746bf27dbca69a50cdca805676892ddc84ad..1dbdb3b73280689e45997f6bfa5c69d8aae9bc65 100644 (file)
@@ -129,7 +129,7 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
       assert_equal 'One', attributes[:lastname]
       assert_equal 'example1@redmine.org', attributes[:mail]
       assert_equal auth.id, attributes[:auth_source_id]
-      attributes.keys.each do |attribute|
+      attributes.each_key do |attribute|
         assert User.new.respond_to?("#{attribute}="), "Unexpected :#{attribute} attribute returned"
       end
     end