Commit 322a4e95 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'pl-rubocop-style-hashtransformation-lib-directory' into 'master'

Fix cop offenses for Style/HashTransformation in lib directory

See merge request gitlab-org/gitlab!56583
parents 125d7ef6 a240e9da
...@@ -3306,26 +3306,6 @@ Style/HashTransformation: ...@@ -3306,26 +3306,6 @@ Style/HashTransformation:
- 'ee/lib/gitlab/custom_file_templates.rb' - 'ee/lib/gitlab/custom_file_templates.rb'
- 'ee/spec/elastic_integration/global_search_spec.rb' - 'ee/spec/elastic_integration/global_search_spec.rb'
- 'ee/spec/lib/ee/gitlab/application_context_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/atlassian/jira_connect/serializers/pull_request_entity_spec.rb'
- 'spec/lib/gitlab/ci/status/composite_spec.rb' - 'spec/lib/gitlab/ci/status/composite_spec.rb'
- 'spec/lib/gitlab/conflict/file_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 ...@@ -32,19 +32,15 @@ module API
end end
def recipe_upload_urls def recipe_upload_urls
{ upload_urls: Hash[ { upload_urls: file_names.select(&method(:recipe_file?)).to_h do |file_name|
file_names.select(&method(:recipe_file?)).map do |file_name| [file_name, build_recipe_file_upload_url(file_name)]
[file_name, build_recipe_file_upload_url(file_name)] end }
end
] }
end end
def package_upload_urls def package_upload_urls
{ upload_urls: Hash[ { upload_urls: file_names.select(&method(:package_file?)).to_h do |file_name|
file_names.select(&method(:package_file?)).map do |file_name| [file_name, build_package_file_upload_url(file_name)]
[file_name, build_package_file_upload_url(file_name)] end }
end
] }
end end
def recipe_file?(file_name) def recipe_file?(file_name)
......
...@@ -485,7 +485,7 @@ module API ...@@ -485,7 +485,7 @@ module API
get ':id/languages', feature_category: :source_code_management do get ':id/languages', feature_category: :source_code_management do
::Projects::RepositoryLanguagesService ::Projects::RepositoryLanguagesService
.new(user_project, current_user) .new(user_project, current_user)
.execute.map { |lang| [lang.name, lang.share] }.to_h .execute.to_h { |lang| [lang.name, lang.share] }
end end
desc 'Delete a project' desc 'Delete a project'
......
...@@ -141,9 +141,9 @@ module Atlassian ...@@ -141,9 +141,9 @@ module Atlassian
def user_notes_count(merge_requests) def user_notes_count(merge_requests)
return unless 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] [count_group.noteable_id, count_group.count]
end.to_h end
end end
def jwt_token(http_method, uri) def jwt_token(http_method, uri)
......
...@@ -60,7 +60,7 @@ module Banzai ...@@ -60,7 +60,7 @@ module Banzai
def get_uri_types(paths) def get_uri_types(paths)
return {} if paths.empty? 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| get_blob_types(paths).each do |name, type|
if type == :blob if type == :blob
......
...@@ -25,8 +25,7 @@ module Gitlab ...@@ -25,8 +25,7 @@ module Gitlab
def value def value
@config @config
.map { |key, value| [key.to_s, Array(value).map(&:to_s)] } .to_h { |key, value| [key.to_s, Array(value).map(&:to_s)] }
.to_h
end end
end end
end end
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
end end
def value 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 end
def self.default(**) def self.default(**)
...@@ -26,7 +26,7 @@ module Gitlab ...@@ -26,7 +26,7 @@ module Gitlab
end end
def value_with_data 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 end
def use_value_data? def use_value_data?
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
def transform_from_yaml_variables(vars) def transform_from_yaml_variables(vars)
return vars.stringify_keys if vars.is_a?(Hash) 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 end
def inherit_yaml_variables(from:, to:, inheritance:) def inherit_yaml_variables(from:, to:, inheritance:)
......
...@@ -390,7 +390,7 @@ module Gitlab ...@@ -390,7 +390,7 @@ module Gitlab
@committer_name = commit.committer.name.dup @committer_name = commit.committer.name.dup
@committer_email = commit.committer.email.dup @committer_email = commit.committer.email.dup
@parent_ids = Array(commit.parent_ids) @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 end
# Gitaly provides a UNIX timestamp in author.date.seconds, and a timezone # Gitaly provides a UNIX timestamp in author.date.seconds, and a timezone
......
...@@ -28,7 +28,7 @@ module Gitlab ...@@ -28,7 +28,7 @@ module Gitlab
prepend_if_ee('EE::Gitlab::ImportSources') # rubocop: disable Cop/InjectEnterpriseEditionModule prepend_if_ee('EE::Gitlab::ImportSources') # rubocop: disable Cop/InjectEnterpriseEditionModule
def options def options
Hash[import_table.map { |importer| [importer.title, importer.name] }] import_table.to_h { |importer| [importer.title, importer.name] }
end end
def values def values
......
...@@ -20,7 +20,7 @@ module Gitlab ...@@ -20,7 +20,7 @@ module Gitlab
# Newly detected languages, returned in a structure accepted by # Newly detected languages, returned in a structure accepted by
# Gitlab::Database.bulk_insert # Gitlab::Database.bulk_insert
def insertions(programming_languages) 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| (languages - previous_language_names).map do |new_lang|
{ {
...@@ -63,8 +63,7 @@ module Gitlab ...@@ -63,8 +63,7 @@ module Gitlab
@repository @repository
.languages .languages
.first(MAX_LANGUAGES) .first(MAX_LANGUAGES)
.map { |l| [l[:label], l] } .to_h { |l| [l[:label], l] }
.to_h
end end
end end
end end
...@@ -32,9 +32,9 @@ module Gitlab ...@@ -32,9 +32,9 @@ module Gitlab
private private
def init_metrics def init_metrics
METRIC_DESCRIPTIONS.map do |name, description| METRIC_DESCRIPTIONS.to_h do |name, description|
[name, ::Gitlab::Metrics.gauge(:"#{METRIC_PREFIX}#{name}", description)] [name, ::Gitlab::Metrics.gauge(:"#{METRIC_PREFIX}#{name}", description)]
end.to_h end
end end
def host_stats def host_stats
......
...@@ -55,12 +55,13 @@ module Gitlab ...@@ -55,12 +55,13 @@ module Gitlab
end end
def project_feature_attributes def project_feature_attributes
@project_features_attributes ||= begin @project_features_attributes ||=
# everything disabled except for issues begin
ProjectFeature::FEATURES.map do |feature| # everything disabled except for issues
[ProjectFeature.access_level_attribute(feature), ProjectFeature::DISABLED] ProjectFeature::FEATURES.to_h do |feature|
end.to_h.merge(ProjectFeature.access_level_attribute(:issues) => ProjectFeature::ENABLED) [ProjectFeature.access_level_attribute(feature), ProjectFeature::DISABLED]
end end.merge(ProjectFeature.access_level_attribute(:issues) => ProjectFeature::ENABLED)
end
end end
def import_data def import_data
......
...@@ -140,7 +140,7 @@ module Gitlab ...@@ -140,7 +140,7 @@ module Gitlab
end end
def mapped_options 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 end
def http_options def http_options
......
...@@ -148,7 +148,7 @@ module Gitlab ...@@ -148,7 +148,7 @@ module Gitlab
# @param hash [Hash] # @param hash [Hash]
# @return [Hash] the stringified hash # @return [Hash] the stringified hash
def standardize_hash(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 end
# Record metrics in Prometheus. # Record metrics in Prometheus.
......
...@@ -28,7 +28,7 @@ module Gitlab ...@@ -28,7 +28,7 @@ module Gitlab
def to_hash_with_defaults def to_hash_with_defaults
# NOTE: The current approach of simply mapping all the descendents' keys and values ('config') # 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. # 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 end
private private
......
...@@ -130,10 +130,10 @@ module Gitlab ...@@ -130,10 +130,10 @@ module Gitlab
return [] if project && !project.repository.exists? return [] if project && !project.repository.exists?
if categories.any? if categories.any?
categories.keys.map do |category| categories.keys.to_h do |category|
files = self.by_category(category, project) files = self.by_category(category, project)
[category, files.map { |t| { key: t.key, name: t.name, content: t.content } }] [category, files.map { |t| { key: t.key, name: t.name, content: t.content } }]
end.to_h end
else else
files = self.all(project) files = self.all(project)
files.map { |t| { key: t.key, name: t.name, content: t.content } } files.map { |t| { key: t.key, name: t.name, content: t.content } }
......
...@@ -22,11 +22,11 @@ module Gitlab::UsageDataCounters ...@@ -22,11 +22,11 @@ module Gitlab::UsageDataCounters
end end
def totals def totals
known_events.map { |event| [counter_key(event), read(event)] }.to_h known_events.to_h { |event| [counter_key(event), read(event)] }
end end
def fallback_totals def fallback_totals
known_events.map { |event| [counter_key(event), -1] }.to_h known_events.to_h { |event| [counter_key(event), -1] }
end end
def fetch_supported_event(event_name) def fetch_supported_event(event_name)
......
...@@ -24,13 +24,13 @@ module Gitlab::UsageDataCounters ...@@ -24,13 +24,13 @@ module Gitlab::UsageDataCounters
end end
def totals def totals
COUNTABLE_TYPES.map do |countable_type| COUNTABLE_TYPES.to_h do |countable_type|
[counter_key(countable_type), read(:create, countable_type)] [counter_key(countable_type), read(:create, countable_type)]
end.to_h end
end end
def fallback_totals 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 end
private 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