Commit f815f072 authored by Karthik Sivadas's avatar Karthik Sivadas

Fix cop offenses for Style/HashTransformation in ee directory

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/322739
parent ee8e68ca
---
title: Fix cop offenses for Style/HashTransformation in ee directory
merge_request: 56581
author: Karthik Sivadas @karthik.sivadas
type: other
......@@ -164,9 +164,9 @@ module EE
private
def variables_hash
@variables_hash ||= variables.map do |variable|
@variables_hash ||= variables.to_h do |variable|
[variable[:key], variable[:value]]
end.to_h
end
end
def parse_security_artifact_blob(security_report, blob)
......
......@@ -28,17 +28,17 @@ class ProductivityAnalytics
def histogram_data(type:)
return unless column = METRIC_COLUMNS[type]
histogram_query(column).map do |data|
histogram_query(column).to_h do |data|
[data[:metric]&.to_i, data[:mr_count]]
end.to_h
end
end
def scatterplot_data(type:)
return unless column = METRIC_COLUMNS[type]
scatterplot_query(column).map do |data|
scatterplot_query(column).to_h do |data|
[data.id, { metric: data[:metric], merged_at: data[:merged_at] }]
end.to_h
end
end
def merge_requests_extended
......
......@@ -68,9 +68,9 @@ module SCA
return {} if project.blank?
strong_memoize(:known_policies) do
project.software_license_policies.including_license.unreachable_limit.map do |policy|
project.software_license_policies.including_license.unreachable_limit.to_h do |policy|
[policy.software_license.canonical_id, report_for(policy)]
end.to_h
end
end
end
......
......@@ -232,9 +232,9 @@ module Security
def scanners_objects
strong_memoize(:scanners_objects) do
@report.scanners.map do |key, scanner|
@report.scanners.to_h do |key, scanner|
[key, existing_scanner_objects[key] || project.vulnerability_scanners.build(scanner&.to_hash)]
end.to_h
end
end
end
......@@ -244,17 +244,17 @@ module Security
def existing_scanner_objects
strong_memoize(:existing_scanner_objects) do
project.vulnerability_scanners.with_external_id(all_scanners_external_ids).map do |scanner|
project.vulnerability_scanners.with_external_id(all_scanners_external_ids).to_h do |scanner|
[scanner.external_id, scanner]
end.to_h
end
end
end
def identifiers_objects
strong_memoize(:identifiers_objects) do
@report.identifiers.map do |key, identifier|
@report.identifiers.to_h do |key, identifier|
[key, existing_identifiers_objects[key] || project.vulnerability_identifiers.build(identifier.to_hash)]
end.to_h
end
end
end
......@@ -264,9 +264,9 @@ module Security
def existing_identifiers_objects
strong_memoize(:existing_identifiers_objects) do
project.vulnerability_identifiers.with_fingerprint(all_identifiers_fingerprints).map do |identifier|
project.vulnerability_identifiers.with_fingerprint(all_identifiers_fingerprints).to_h do |identifier|
[identifier.fingerprint, identifier]
end.to_h
end
end
end
......
......@@ -293,8 +293,7 @@ module EE
# returns a hash user_id -> LDAP identity in current LDAP provider
def resolve_ldap_identities(for_users:)
::Identity.for_user(for_users).with_provider(provider)
.map {|identity| [identity.user_id, identity] }
.to_h
.to_h { |identity| [identity.user_id, identity] }
end
# returns a hash of normalized DN -> user for the current LDAP provider
......@@ -302,8 +301,7 @@ module EE
def resolve_users_from_normalized_dn(for_normalized_dns:)
::Identity.with_provider(provider).iwhere(extern_uid: for_normalized_dns)
.preload(:user)
.map {|identity| [identity.extern_uid, identity.user] }
.to_h
.to_h { |identity| [identity.extern_uid, identity.user] }
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -305,7 +305,7 @@ module EE
# }
# ]
geo_node_usage: GeoNodeStatus.for_active_secondaries.map do |node|
GeoNodeStatus::RESOURCE_STATUS_FIELDS.map { |field| [field, node[field]] }.to_h
GeoNodeStatus::RESOURCE_STATUS_FIELDS.to_h { |field| [field, node[field]] }
end
# rubocop: enable UsageData/LargeTable
})
......
......@@ -92,8 +92,7 @@ module Gitlab
.ancestors_upto(nil)
.with_custom_file_templates
.select { |namespace| namespace.checked_file_template_project }
.map { |namespace| [namespace, namespace.checked_file_template_project] }
.to_h
.to_h { |namespace| [namespace, namespace.checked_file_template_project] }
end
end
......
......@@ -173,7 +173,7 @@ RSpec.describe 'GlobalSearch', :elastic do
# access_level can be :disabled, :enabled or :private
def feature_settings(access_level)
Hash[features.collect { |k| ["#{k}_access_level", Featurable.const_get(access_level.to_s.upcase, false)] }]
features.to_h { |k| ["#{k}_access_level", Featurable.const_get(access_level.to_s.upcase, false)] }
end
def expect_no_items_to_be_found(user)
......
......@@ -56,7 +56,7 @@ RSpec.describe Gitlab::ApplicationContext do
with_them do
specify do
# Build a hash that has all `provided_options` as keys, and `nil` as value
provided_values = provided_options.map { |key| [key, nil] }.to_h
provided_values = provided_options.to_h { |key| [key, nil] }
context = described_class.new(**provided_values)
expect(context.to_lazy_hash.keys).to contain_exactly(*expected_context_keys)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment