Commit a240e9da authored by Karthik Sivadas's avatar Karthik Sivadas

Fix cop offenses for Style/HashTransformation in lib directory

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/322739
parent 2a034467
......@@ -3335,26 +3335,6 @@ Style/HashTransformation:
- 'ee/lib/gitlab/custom_file_templates.rb'
- 'ee/spec/elastic_integration/global_search_spec.rb'
- 'ee/spec/lib/ee/gitlab/application_context_spec.rb'
- 'lib/api/helpers/packages/conan/api_helpers.rb'
- 'lib/api/projects.rb'
- 'lib/atlassian/jira_connect/client.rb'
- 'lib/banzai/filter/repository_link_filter.rb'
- 'lib/gitlab/ci/config/entry/product/variables.rb'
- 'lib/gitlab/ci/config/entry/variables.rb'
- 'lib/gitlab/ci/variables/collection.rb'
- 'lib/gitlab/ci/variables/helpers.rb'
- 'lib/gitlab/git/commit.rb'
- 'lib/gitlab/import_sources.rb'
- 'lib/gitlab/language_detection.rb'
- 'lib/gitlab/metrics/samplers/database_sampler.rb'
- 'lib/gitlab/metrics/subscribers/active_record.rb'
- 'lib/gitlab/phabricator_import/project_creator.rb'
- 'lib/gitlab/prometheus_client.rb'
- 'lib/gitlab/repository_hash_cache.rb'
- 'lib/gitlab/static_site_editor/config/file_config.rb'
- 'lib/gitlab/template/base_template.rb'
- 'lib/gitlab/usage_data_counters/base_counter.rb'
- 'lib/gitlab/usage_data_counters/note_counter.rb'
- 'spec/lib/atlassian/jira_connect/serializers/pull_request_entity_spec.rb'
- 'spec/lib/gitlab/ci/status/composite_spec.rb'
- 'spec/lib/gitlab/conflict/file_spec.rb'
......
---
title: Fix cop offenses for Style/HashTransformation in lib directory
merge_request: 56583
author: Karthik Sivadas @karthik.sivadas
type: other
......@@ -32,19 +32,15 @@ module API
end
def recipe_upload_urls
{ upload_urls: Hash[
file_names.select(&method(:recipe_file?)).map do |file_name|
[file_name, build_recipe_file_upload_url(file_name)]
end
] }
{ upload_urls: file_names.select(&method(:recipe_file?)).to_h do |file_name|
[file_name, build_recipe_file_upload_url(file_name)]
end }
end
def package_upload_urls
{ upload_urls: Hash[
file_names.select(&method(:package_file?)).map do |file_name|
[file_name, build_package_file_upload_url(file_name)]
end
] }
{ upload_urls: file_names.select(&method(:package_file?)).to_h do |file_name|
[file_name, build_package_file_upload_url(file_name)]
end }
end
def recipe_file?(file_name)
......
......@@ -485,7 +485,7 @@ module API
get ':id/languages', feature_category: :source_code_management do
::Projects::RepositoryLanguagesService
.new(user_project, current_user)
.execute.map { |lang| [lang.name, lang.share] }.to_h
.execute.to_h { |lang| [lang.name, lang.share] }
end
desc 'Delete a project'
......
......@@ -141,9 +141,9 @@ module Atlassian
def user_notes_count(merge_requests)
return unless merge_requests
Note.count_for_collection(merge_requests.map(&:id), 'MergeRequest').map do |count_group|
Note.count_for_collection(merge_requests.map(&:id), 'MergeRequest').to_h do |count_group|
[count_group.noteable_id, count_group.count]
end.to_h
end
end
def jwt_token(http_method, uri)
......
......@@ -60,7 +60,7 @@ module Banzai
def get_uri_types(paths)
return {} if paths.empty?
uri_types = Hash[paths.collect { |name| [name, nil] }]
uri_types = paths.to_h { |name| [name, nil] }
get_blob_types(paths).each do |name, type|
if type == :blob
......
......@@ -25,8 +25,7 @@ module Gitlab
def value
@config
.map { |key, value| [key.to_s, Array(value).map(&:to_s)] }
.to_h
.to_h { |key, value| [key.to_s, Array(value).map(&:to_s)] }
end
end
end
......
......@@ -18,7 +18,7 @@ module Gitlab
end
def value
Hash[@config.map { |key, value| [key.to_s, expand_value(value)[:value]] }]
@config.to_h { |key, value| [key.to_s, expand_value(value)[:value]] }
end
def self.default(**)
......@@ -26,7 +26,7 @@ module Gitlab
end
def value_with_data
Hash[@config.map { |key, value| [key.to_s, expand_value(value)] }]
@config.to_h { |key, value| [key.to_s, expand_value(value)] }
end
def use_value_data?
......
......@@ -23,7 +23,7 @@ module Gitlab
def transform_from_yaml_variables(vars)
return vars.stringify_keys if vars.is_a?(Hash)
vars.to_a.map { |var| [var[:key].to_s, var[:value]] }.to_h
vars.to_a.to_h { |var| [var[:key].to_s, var[:value]] }
end
def inherit_yaml_variables(from:, to:, inheritance:)
......
......@@ -390,7 +390,7 @@ module Gitlab
@committer_name = commit.committer.name.dup
@committer_email = commit.committer.email.dup
@parent_ids = Array(commit.parent_ids)
@trailers = Hash[commit.trailers.map { |t| [t.key, t.value] }]
@trailers = commit.trailers.to_h { |t| [t.key, t.value] }
end
# Gitaly provides a UNIX timestamp in author.date.seconds, and a timezone
......
......@@ -28,7 +28,7 @@ module Gitlab
prepend_if_ee('EE::Gitlab::ImportSources') # rubocop: disable Cop/InjectEnterpriseEditionModule
def options
Hash[import_table.map { |importer| [importer.title, importer.name] }]
import_table.to_h { |importer| [importer.title, importer.name] }
end
def values
......
......@@ -20,7 +20,7 @@ module Gitlab
# Newly detected languages, returned in a structure accepted by
# Gitlab::Database.bulk_insert
def insertions(programming_languages)
lang_to_id = programming_languages.map { |p| [p.name, p.id] }.to_h
lang_to_id = programming_languages.to_h { |p| [p.name, p.id] }
(languages - previous_language_names).map do |new_lang|
{
......@@ -63,8 +63,7 @@ module Gitlab
@repository
.languages
.first(MAX_LANGUAGES)
.map { |l| [l[:label], l] }
.to_h
.to_h { |l| [l[:label], l] }
end
end
end
......@@ -32,9 +32,9 @@ module Gitlab
private
def init_metrics
METRIC_DESCRIPTIONS.map do |name, description|
METRIC_DESCRIPTIONS.to_h do |name, description|
[name, ::Gitlab::Metrics.gauge(:"#{METRIC_PREFIX}#{name}", description)]
end.to_h
end
end
def host_stats
......
......@@ -55,12 +55,13 @@ module Gitlab
end
def project_feature_attributes
@project_features_attributes ||= begin
# everything disabled except for issues
ProjectFeature::FEATURES.map do |feature|
[ProjectFeature.access_level_attribute(feature), ProjectFeature::DISABLED]
end.to_h.merge(ProjectFeature.access_level_attribute(:issues) => ProjectFeature::ENABLED)
end
@project_features_attributes ||=
begin
# everything disabled except for issues
ProjectFeature::FEATURES.to_h do |feature|
[ProjectFeature.access_level_attribute(feature), ProjectFeature::DISABLED]
end.merge(ProjectFeature.access_level_attribute(:issues) => ProjectFeature::ENABLED)
end
end
def import_data
......
......@@ -140,7 +140,7 @@ module Gitlab
end
def mapped_options
options.keys.map { |k| [gitlab_http_key(k), options[k]] }.to_h
options.keys.to_h { |k| [gitlab_http_key(k), options[k]] }
end
def http_options
......
......@@ -148,7 +148,7 @@ module Gitlab
# @param hash [Hash]
# @return [Hash] the stringified hash
def standardize_hash(hash)
hash.map { |k, v| [k.to_s, v.to_s] }.to_h
hash.to_h { |k, v| [k.to_s, v.to_s] }
end
# Record metrics in Prometheus.
......
......@@ -28,7 +28,7 @@ module Gitlab
def to_hash_with_defaults
# NOTE: The current approach of simply mapping all the descendents' keys and values ('config')
# into a flat hash may need to be enhanced as we add more complex, non-scalar entries.
@global.descendants.map { |descendant| [descendant.key, descendant.config] }.to_h
@global.descendants.to_h { |descendant| [descendant.key, descendant.config] }
end
private
......
......@@ -130,10 +130,10 @@ module Gitlab
return [] if project && !project.repository.exists?
if categories.any?
categories.keys.map do |category|
categories.keys.to_h do |category|
files = self.by_category(category, project)
[category, files.map { |t| { key: t.key, name: t.name, content: t.content } }]
end.to_h
end
else
files = self.all(project)
files.map { |t| { key: t.key, name: t.name, content: t.content } }
......
......@@ -22,11 +22,11 @@ module Gitlab::UsageDataCounters
end
def totals
known_events.map { |event| [counter_key(event), read(event)] }.to_h
known_events.to_h { |event| [counter_key(event), read(event)] }
end
def fallback_totals
known_events.map { |event| [counter_key(event), -1] }.to_h
known_events.to_h { |event| [counter_key(event), -1] }
end
def fetch_supported_event(event_name)
......
......@@ -24,13 +24,13 @@ module Gitlab::UsageDataCounters
end
def totals
COUNTABLE_TYPES.map do |countable_type|
COUNTABLE_TYPES.to_h do |countable_type|
[counter_key(countable_type), read(:create, countable_type)]
end.to_h
end
end
def fallback_totals
COUNTABLE_TYPES.map { |counter_key| [counter_key(counter_key), -1] }.to_h
COUNTABLE_TYPES.to_h { |counter_key| [counter_key(counter_key), -1] }
end
private
......
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