Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fewer inline disabled cops #2039

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,6 +69,9 @@ Metrics/BlockLength:
- Rakefile
- '**/*.rake'

Metrics/MethodLength:
Max: 15

Naming/FileName:
Exclude:
- lib/rubocop-rspec.rb
Expand Down
2 changes: 0 additions & 2 deletions lib/rubocop/cop/rspec/change_by_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def on_send(node)

private

# rubocop:disable Metrics/MethodLength
def register_offense(node, change_node)
if compound_expectations?(node)
add_offense(node,
Expand All @@ -115,7 +114,6 @@ def register_offense(node, change_node)
end
end
end
# rubocop:enable Metrics/MethodLength

def compound_expectations?(node)
node.parent.send_type? &&
Expand Down
2 changes: 0 additions & 2 deletions lib/rubocop/cop/rspec/example_wording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class ExampleWording < Base
} ...) ...)
PATTERN

# rubocop:disable Metrics/MethodLength
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
it_description(node) do |description_node, message|
if message.match?(SHOULD_PREFIX)
Expand All @@ -82,7 +81,6 @@ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
end
end
end
# rubocop:enable Metrics/MethodLength

private

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/expect_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ExpectActual < Base
)
PATTERN

def on_send(node) # rubocop:disable Metrics/MethodLength
def on_send(node)
expect_literal(node) do |actual, send_node, matcher, expected|
next if SKIPPED_MATCHERS.include?(matcher)

Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rspec/implicit_expect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ImplicitExpect < Base

ENFORCED_REPLACEMENTS = alternatives.merge(alternatives.invert).freeze

def on_send(node) # rubocop:disable Metrics/MethodLength
def on_send(node)
return unless (source_range = offending_expect(node))

expectation_source = source_range.source
Expand All @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions lib/rubocop/cop/rspec/implicit_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def on_send(node)

private

# rubocop:disable Metrics/MethodLength
def autocorrect(corrector, node)
case node.method_name
when :expect
Expand All @@ -114,7 +113,6 @@ def autocorrect(corrector, node)
# :nocov:
end
end
# rubocop:enable Metrics/MethodLength

def message(_node)
case style
Expand All @@ -125,7 +123,6 @@ def message(_node)
end
end

# rubocop:disable Metrics/MethodLength
def invalid?(node)
case style
when :require_implicit
Expand All @@ -142,7 +139,6 @@ def invalid?(node)
# :nocov:
end
end
# rubocop:enable Metrics/MethodLength

def implicit_subject_in_non_its?(node)
implicit_subject?(node) && !its?(node)
Expand Down
6 changes: 0 additions & 6 deletions lib/rubocop/cop/rspec/predicate_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def message_inflected(predicate)
matcher_name: to_predicate_matcher(predicate.method_name))
end

# rubocop:disable Metrics/MethodLength
def to_predicate_matcher(name)
case name = name.to_s
when 'is_a?'
Expand All @@ -86,7 +85,6 @@ def to_predicate_matcher(name)
"be_#{name[0..-2]}"
end
end
# rubocop:enable Metrics/MethodLength

def remove_predicate(corrector, predicate)
range = predicate.loc.dot.with(
Expand All @@ -110,7 +108,6 @@ def rewrite_matcher(corrector, predicate, matcher)
)
end

# rubocop:disable Metrics/MethodLength
def true?(to_symbol, matcher)
result = case matcher.method_name
when :be, :eq, :eql, :equal
Expand All @@ -126,7 +123,6 @@ def true?(to_symbol, matcher)
end
to_symbol == :to ? result : !result
end
# rubocop:enable Metrics/MethodLength
end

# A helper for `explicit` style
Expand Down Expand Up @@ -245,7 +241,6 @@ def move_predicate(corrector, actual, matcher, block_child)
corrector.insert_after(actual, ".#{predicate}" + args + block)
end

# rubocop:disable Metrics/MethodLength
def to_predicate_method(matcher)
case matcher = matcher.to_s
when 'be_a', 'be_an', 'be_a_kind_of', 'a_kind_of', 'be_kind_of'
Expand All @@ -262,7 +257,6 @@ def to_predicate_method(matcher)
"#{matcher[/\Abe_(.+)/, 1]}?"
end
end
# rubocop:enable Metrics/MethodLength

def replacement_matcher(node)
case [cop_config['Strict'], node.method?(:to)]
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/rspec/return_from_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions lib/rubocop/rspec/wording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def initialize(text, ignore:, replace:)
@replacements = replace
end

# rubocop:disable Metrics/MethodLength
def rewrite
case text
when SHOULDNT_BE_PREFIX
Expand All @@ -32,7 +31,6 @@ def rewrite
remove_should_and_pluralize
end
end
# rubocop:enable Metrics/MethodLength

private

Expand Down
2 changes: 0 additions & 2 deletions spec/rubocop/cop/rspec/align_left_let_brace_spec.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions spec/rubocop/cop/rspec/align_right_let_brace_spec.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions spec/rubocop/cop/rspec/focus_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down