From 1f56d105c8517cfce4b50d68449fd60ee2e9d5b8 Mon Sep 17 00:00:00 2001 From: Vitali Tatarintev Date: Fri, 4 Mar 2022 12:16:08 +0100 Subject: [PATCH] Fix Style/RedundantFetchBlock rubocop offence Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/239356 --- .rubocop_todo.yml | 12 ------------ app/finders/admin/projects_finder.rb | 2 +- lib/gitlab/diff/file.rb | 2 +- spec/lib/gitlab/json_cache_spec.rb | 2 ++ spec/lib/gitlab/metrics/dashboard/cache_spec.rb | 2 ++ spec/lib/gitlab/null_request_store_spec.rb | 2 +- spec/lib/gitlab/safe_request_store_spec.rb | 4 ++-- 7 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d7632c361033e5..5eadab8e590a96 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -706,18 +706,6 @@ Style/NumericLiteralPrefix: Style/PercentLiteralDelimiters: Enabled: false -# Offense count: 26 -# Cop supports --auto-correct. -# Configuration parameters: SafeForConstants. -Style/RedundantFetchBlock: - Exclude: - - 'app/finders/admin/projects_finder.rb' - - 'lib/gitlab/diff/file.rb' - - 'spec/lib/gitlab/json_cache_spec.rb' - - 'spec/lib/gitlab/metrics/dashboard/cache_spec.rb' - - 'spec/lib/gitlab/null_request_store_spec.rb' - - 'spec/lib/gitlab/safe_request_store_spec.rb' - # Offense count: 206 # Cop supports --auto-correct. Style/RedundantInterpolation: diff --git a/app/finders/admin/projects_finder.rb b/app/finders/admin/projects_finder.rb index 53dbf65c43abdf..fc18bb1984afee 100644 --- a/app/finders/admin/projects_finder.rb +++ b/app/finders/admin/projects_finder.rb @@ -69,7 +69,7 @@ def by_name(items) end def sort(items) - sort = params.fetch(:sort) { 'latest_activity_desc' } + sort = params.fetch(:sort, 'latest_activity_desc') items.sort_by_attribute(sort) end end diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 392505422604b1..89822af2455ba9 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -383,7 +383,7 @@ def rendered private def diffable_by_attribute? - repository.attributes(file_path).fetch('diff') { true } + repository.attributes(file_path).fetch('diff', true) end # NOTE: Files with unsupported encodings (e.g. UTF-16) are treated as binary by git, but they are recognized as text files during encoding detection. These files have `Binary files a/filename and b/filename differ' as their raw diff content which cannot be used. We need to handle this special case and avoid displaying incorrect diff. diff --git a/spec/lib/gitlab/json_cache_spec.rb b/spec/lib/gitlab/json_cache_spec.rb index 01c2120d9a638f..d7d28a94cfe5ba 100644 --- a/spec/lib/gitlab/json_cache_spec.rb +++ b/spec/lib/gitlab/json_cache_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +# rubocop:disable Style/RedundantFetchBlock require 'spec_helper' @@ -547,3 +548,4 @@ end end end +# rubocop:enable Style/RedundantFetchBlock diff --git a/spec/lib/gitlab/metrics/dashboard/cache_spec.rb b/spec/lib/gitlab/metrics/dashboard/cache_spec.rb index 9467d441ae1f57..8c2edc85c35908 100644 --- a/spec/lib/gitlab/metrics/dashboard/cache_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/cache_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +# rubocop:disable Style/RedundantFetchBlock require 'spec_helper' @@ -84,3 +85,4 @@ end end end +# rubocop:enable Style/RedundantFetchBlock diff --git a/spec/lib/gitlab/null_request_store_spec.rb b/spec/lib/gitlab/null_request_store_spec.rb index f600af2e31f4d5..66700313c9ae28 100644 --- a/spec/lib/gitlab/null_request_store_spec.rb +++ b/spec/lib/gitlab/null_request_store_spec.rb @@ -49,7 +49,7 @@ describe '#fetch' do it 'returns the block result' do - expect(null_store.fetch('key') { 'block result' }).to eq('block result') + expect(null_store.fetch('key') { 'block result' }).to eq('block result') # rubocop:disable Style/RedundantFetchBlock end end diff --git a/spec/lib/gitlab/safe_request_store_spec.rb b/spec/lib/gitlab/safe_request_store_spec.rb index 704102ccaeebcf..accc491fbb7c67 100644 --- a/spec/lib/gitlab/safe_request_store_spec.rb +++ b/spec/lib/gitlab/safe_request_store_spec.rb @@ -183,7 +183,7 @@ context 'when RequestStore is active', :request_store do it 'uses RequestStore' do expect do - described_class.fetch('foo') { 'block result' } + described_class.fetch('foo') { 'block result' } # rubocop:disable Style/RedundantFetchBlock end.to change { described_class.read('foo') }.from(nil).to('block result') end end @@ -193,7 +193,7 @@ RequestStore.clear! # Ensure clean expect do - described_class.fetch('foo') { 'block result' } + described_class.fetch('foo') { 'block result' } # rubocop:disable Style/RedundantFetchBlock end.not_to change { described_class.read('foo') }.from(nil) RequestStore.clear! # Clean up -- GitLab