Commit b3d09ee0 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'pl-rubocop-style-hash-transform-keys' into 'master'

Fix todo offenses for Style/HashTransformKeys

See merge request gitlab-org/gitlab!34971
parents 0e816c66 f15faf3d
......@@ -560,15 +560,6 @@ Style/GuardClause:
Style/HashEachMethods:
Enabled: false
# Offense count: 6
# Cop supports --auto-correct.
Style/HashTransformKeys:
Exclude:
- 'ee/app/models/vulnerabilities/occurrence.rb'
- 'ee/spec/lib/gitlab/ci/templates/dependency_scanning_gitlab_ci_yaml_spec.rb'
- 'lib/banzai/filter/commit_trailers_filter.rb'
- 'lib/gitlab/analytics/cycle_analytics/stage_events.rb'
# Offense count: 31
# Configuration parameters: AllowIfModifier.
Style/IfInsideElse:
......
......@@ -115,8 +115,8 @@ module Vulnerabilities
end
def self.counted_by_severity
group(:severity).count.each_with_object({}) do |(severity, count), accum|
accum[SEVERITY_LEVELS[severity]] = count
group(:severity).count.transform_keys do |severity|
SEVERITY_LEVELS[severity]
end
end
......
......@@ -91,7 +91,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do
context 'with file at depth 1' do
# prepend a directory to files (e.g. convert go.sum to foo/go.sum)
let(:files_at_depth_x) { Hash[files.map { |k, v| ["foo/#{k}", v]}] }
let(:files_at_depth_x) { files.transform_keys { |k| "foo/#{k}"} }
it 'creates a pipeline with the expected jobs' do
expect(build_names).to include(*include_build_names)
......@@ -100,7 +100,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do
context 'with file at depth 2' do
# prepend a directory to files (e.g. convert go.sum to foo/bar/go.sum)
let(:files_at_depth_x) { Hash[files.map { |k, v| ["foo/bar/#{k}", v]}] }
let(:files_at_depth_x) { files.transform_keys { |k| "foo/bar/#{k}"} }
it 'creates a pipeline with the expected jobs' do
expect(build_names).to include(*include_build_names)
......@@ -108,7 +108,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do
end
context 'with file at depth > 2' do
let(:files_at_depth_x) { Hash[files.map { |k, v| ["foo/bar/baz/#{k}", v]}] }
let(:files_at_depth_x) { files.transform_keys { |k| "foo/bar/baz/#{k}"} }
it 'includes no job' do
expect { pipeline }.to raise_error(Ci::CreatePipelineService::CreateError)
......
......@@ -144,10 +144,7 @@ module Banzai
end
def data_attributes_from_hash(data = {})
data.reject! {|_, value| value.nil?}
data.map do |key, value|
[%(data-#{key.to_s.dasherize}), value]
end.to_h
data.compact.transform_keys { |key| %(data-#{key.to_s.dasherize}) }
end
end
end
......
......@@ -60,7 +60,7 @@ module Gitlab
# hash for defining ActiveRecord enum: identifier => number
def self.to_enum
enum_mapping.each_with_object({}) { |(k, v), hash| hash[k.identifier] = v }
enum_mapping.transform_keys { |k| k.identifier }
end
def self.pairing_rules
......
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