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: ...@@ -560,15 +560,6 @@ Style/GuardClause:
Style/HashEachMethods: Style/HashEachMethods:
Enabled: false 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 # Offense count: 31
# Configuration parameters: AllowIfModifier. # Configuration parameters: AllowIfModifier.
Style/IfInsideElse: Style/IfInsideElse:
......
...@@ -115,8 +115,8 @@ module Vulnerabilities ...@@ -115,8 +115,8 @@ module Vulnerabilities
end end
def self.counted_by_severity def self.counted_by_severity
group(:severity).count.each_with_object({}) do |(severity, count), accum| group(:severity).count.transform_keys do |severity|
accum[SEVERITY_LEVELS[severity]] = count SEVERITY_LEVELS[severity]
end end
end end
......
...@@ -91,7 +91,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do ...@@ -91,7 +91,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do
context 'with file at depth 1' do context 'with file at depth 1' do
# prepend a directory to files (e.g. convert go.sum to foo/go.sum) # 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 it 'creates a pipeline with the expected jobs' do
expect(build_names).to include(*include_build_names) expect(build_names).to include(*include_build_names)
...@@ -100,7 +100,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do ...@@ -100,7 +100,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do
context 'with file at depth 2' do context 'with file at depth 2' do
# prepend a directory to files (e.g. convert go.sum to foo/bar/go.sum) # 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 it 'creates a pipeline with the expected jobs' do
expect(build_names).to include(*include_build_names) expect(build_names).to include(*include_build_names)
...@@ -108,7 +108,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do ...@@ -108,7 +108,7 @@ RSpec.describe 'Dependency-Scanning.gitlab-ci.yml' do
end end
context 'with file at depth > 2' do 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 it 'includes no job' do
expect { pipeline }.to raise_error(Ci::CreatePipelineService::CreateError) expect { pipeline }.to raise_error(Ci::CreatePipelineService::CreateError)
......
...@@ -144,10 +144,7 @@ module Banzai ...@@ -144,10 +144,7 @@ module Banzai
end end
def data_attributes_from_hash(data = {}) def data_attributes_from_hash(data = {})
data.reject! {|_, value| value.nil?} data.compact.transform_keys { |key| %(data-#{key.to_s.dasherize}) }
data.map do |key, value|
[%(data-#{key.to_s.dasherize}), value]
end.to_h
end end
end end
end end
......
...@@ -60,7 +60,7 @@ module Gitlab ...@@ -60,7 +60,7 @@ module Gitlab
# hash for defining ActiveRecord enum: identifier => number # hash for defining ActiveRecord enum: identifier => number
def self.to_enum def self.to_enum
enum_mapping.each_with_object({}) { |(k, v), hash| hash[k.identifier] = v } enum_mapping.transform_keys { |k| k.identifier }
end end
def self.pairing_rules 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