summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-12-20 08:13:48 +0000
committerGo MAEDA <maeda@farend.jp>2023-12-20 08:13:48 +0000
commitc8640d7ffc28b1632106e2d2bc33f5d792d644fc (patch)
tree221c5cd85f75561695faf6c4d795d0263f2a5cc3
parentd9ef2d191cdb3d04508530275bc99c3710820fcb (diff)
downloadredmine-c8640d7ffc28b1632106e2d2bc33f5d792d644fc.tar.gz
redmine-c8640d7ffc28b1632106e2d2bc33f5d792d644fc.zip
Fix RuboCop offense Style/HashEachMethods (#39887).
git-svn-id: https://svn.redmine.org/redmine/trunk@22532 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--.rubocop.yml5
-rw-r--r--.rubocop_todo.yml11
-rw-r--r--app/controllers/groups_controller.rb6
-rw-r--r--app/controllers/workflows_controller.rb6
-rw-r--r--app/helpers/attachments_helper.rb2
-rw-r--r--app/models/journal.rb2
-rw-r--r--app/models/mailer.rb2
-rw-r--r--app/models/project.rb2
-rw-r--r--app/models/role.rb2
-rw-r--r--app/models/token.rb2
-rw-r--r--lib/redmine/acts/mentionable.rb2
-rw-r--r--test/functional/issues_custom_fields_visibility_test.rb4
-rw-r--r--test/unit/auth_source_ldap_test.rb2
13 files changed, 19 insertions, 29 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index b30000672..4fae950f0 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -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'
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 1c7208e3f..5c37fd235 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -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:
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 85192a9d7..41e7b1000 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -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
diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb
index b1dea0c4c..3bb46ad14 100644
--- a/app/controllers/workflows_controller.rb
+++ b/app/controllers/workflows_controller.rb
@@ -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)
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index a9e147a3f..fc2cca351 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -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
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 4b4139a14..cc5611754 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -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|
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index c4c7ab07f..2fe9673c9 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -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] ||= []
diff --git a/app/models/project.rb b/app/models/project.rb
index 11f4a953d..1bf5f913c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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
diff --git a/app/models/role.rb b/app/models/role.rb
index 1665d7982..13ebb3324 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -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
diff --git a/app/models/token.rb b/app/models/token.rb
index 1fd9c228b..29340edba 100644
--- a/app/models/token.rb
+++ b/app/models/token.rb
@@ -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
diff --git a/lib/redmine/acts/mentionable.rb b/lib/redmine/acts/mentionable.rb
index 24adf04b3..f8332637e 100644
--- a/lib/redmine/acts/mentionable.rb
+++ b/lib/redmine/acts/mentionable.rb
@@ -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
diff --git a/test/functional/issues_custom_fields_visibility_test.rb b/test/functional/issues_custom_fields_visibility_test.rb
index 46ca01100..6a06abe12 100644
--- a/test/functional/issues_custom_fields_visibility_test.rb
+++ b/test/functional/issues_custom_fields_visibility_test.rb
@@ -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
diff --git a/test/unit/auth_source_ldap_test.rb b/test/unit/auth_source_ldap_test.rb
index 9c37746bf..1dbdb3b73 100644
--- a/test/unit/auth_source_ldap_test.rb
+++ b/test/unit/auth_source_ldap_test.rb
@@ -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