From c8b14c15cd415686967086a768496663b68044d1 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Mon, 10 Feb 2025 15:57:14 +0100 Subject: [PATCH] Remove unnecessary RuboCop disables This includes fixing a `Naming/PredicateName` offense, and one `Style/GuardClause` offense. Not sure why Lint/RedundantCopDisableDirective didn't find these. --- .rubocop.yml | 1 - lib/rubocop/cop/rspec/implicit_expect.rb | 4 ++-- lib/rubocop/cop/rspec/return_from_stub.rb | 8 ++++---- spec/rubocop/cop/rspec/align_left_let_brace_spec.rb | 2 -- spec/rubocop/cop/rspec/align_right_let_brace_spec.rb | 2 -- spec/rubocop/cop/rspec/focus_spec.rb | 4 +--- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 581d7978b..e8de9e412 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,7 +16,6 @@ AllCops: - 'tmp/**/*' - 'spec/smoke_tests/**/*.rb' - # Enable when we require rubocop >= 1.71.1 or rubocop-ast >= 1.38.0 InternalAffairs/NodePatternGroups: Enabled: false diff --git a/lib/rubocop/cop/rspec/implicit_expect.rb b/lib/rubocop/cop/rspec/implicit_expect.rb index 42517a103..2224c2c38 100644 --- a/lib/rubocop/cop/rspec/implicit_expect.rb +++ b/lib/rubocop/cop/rspec/implicit_expect.rb @@ -69,13 +69,13 @@ def on_send(node) # rubocop:disable Metrics/MethodLength def offending_expect(node) case implicit_expect(node) when :is_expected - is_expected_range(node.loc) + range_for_is_expected(node.loc) when :should, :should_not node.loc.selector end end - def is_expected_range(source_map) # rubocop:disable Naming/PredicateName + def range_for_is_expected(source_map) Parser::Source::Range.new( source_map.expression.source_buffer, source_map.expression.begin_pos, diff --git a/lib/rubocop/cop/rspec/return_from_stub.rb b/lib/rubocop/cop/rspec/return_from_stub.rb index 30c980a2e..8c7feab0b 100644 --- a/lib/rubocop/cop/rspec/return_from_stub.rb +++ b/lib/rubocop/cop/rspec/return_from_stub.rb @@ -80,10 +80,10 @@ def check_and_return_call(node) def check_block_body(block) body = block.body - unless dynamic?(body) # rubocop:disable Style/GuardClause - add_offense(block.loc.begin, message: MSG_AND_RETURN) do |corrector| - BlockBodyCorrector.new(block).call(corrector) - end + return if dynamic?(body) + + add_offense(block.loc.begin, message: MSG_AND_RETURN) do |corrector| + BlockBodyCorrector.new(block).call(corrector) end end diff --git a/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb b/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb index 66bfae9e4..c350a04ff 100644 --- a/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +++ b/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::AlignLeftLetBrace do - # rubocop:disable RSpec/ExampleLength it 'registers offense for unaligned braces' do expect_offense(<<~RUBY) let(:foo) { bar } @@ -41,7 +40,6 @@ end RUBY end - # rubocop:enable RSpec/ExampleLength it 'does not register an offense for let with proc argument' do expect_no_offenses(<<~RUBY) diff --git a/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb b/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb index 991737d66..c1ee4f0e6 100644 --- a/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +++ b/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::AlignRightLetBrace do - # rubocop:disable RSpec/ExampleLength it 'registers offense for unaligned braces' do expect_offense(<<~RUBY) let(:foo) { a } @@ -41,7 +40,6 @@ end RUBY end - # rubocop:enable RSpec/ExampleLength it 'does not register an offense for let with proc argument' do expect_no_offenses(<<~RUBY) diff --git a/spec/rubocop/cop/rspec/focus_spec.rb b/spec/rubocop/cop/rspec/focus_spec.rb index feb0b5476..83ceaf15e 100644 --- a/spec/rubocop/cop/rspec/focus_spec.rb +++ b/spec/rubocop/cop/rspec/focus_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.describe RuboCop::Cop::RSpec::Focus do - # rubocop:disable RSpec/ExampleLength it 'flags all rspec example blocks with that include `focus: true`' do expect_offense(<<~RUBY) example 'test', meta: true, focus: true do; end @@ -131,7 +130,6 @@ shared_context 'test' do; end RUBY end - # rubocop:enable RSpec/ExampleLength it 'does not flag unfocused specs' do expect_no_offenses(<<~RUBY) @@ -175,7 +173,7 @@ RUBY end - it 'flags focused block types' do # rubocop:disable RSpec/ExampleLength + it 'flags focused block types' do expect_offense(<<~RUBY) fdescribe 'test' do; end ^^^^^^^^^^^^^^^^ Focused spec found.