Fix RuboCop offense Style/HashEachMethods (#39887).

git-svn-id: https://svn.redmine.org/redmine/trunk@22532 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2023-12-20 08:13:48 +00:00
parent d9ef2d191c
commit c8640d7ffc
13 changed files with 19 additions and 29 deletions

View 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'

View 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:

View 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

View 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)

View 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

View 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|

View 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] ||= []

View 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

View 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

View 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

View 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

View 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

View 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