Skip to content

Commit

Permalink
Call super in relevant_file?
Browse files Browse the repository at this point in the history
This was preventing Exclude from working
  • Loading branch information
KNejad committed Sep 9, 2024
1 parent a50857f commit ff4c3f5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/internal_affairs/cop_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def comment_index(node, comment_line)
end

def relevant_file?(file)
file.match?(%r{/cop/.*\.rb\z})
file.match?(%r{/cop/.*\.rb\z}) && super
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def assertions_using_described_class_msg

# Only process spec files
def relevant_file?(file)
file.end_with?('_spec.rb')
file.end_with?('_spec.rb') && super
end
end
end
Expand Down
29 changes: 29 additions & 0 deletions spec/rubocop/cop/internal_affairs/cop_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,33 @@ class Foo < Base
RUBY
end
end

context 'when the file is excluded' do
before do
allow_any_instance_of(described_class).to receive(:relevant_file?).and_call_original # rubocop:disable RSpec/AnyInstance
end

let(:config) do
RuboCop::Config.new(
'InternalAffairs/CopDescription' => { 'Exclude' => ['**/example_cop.rb'] }
)
end

it 'does not register an offense' do
expect_no_offenses(<<~RUBY, 'lib/rubocop/cop/example_cop.rb')
module RuboCop
module Cop
module Lint
#
# Checks some problem
#
# ...
class Foo < Base
end
end
end
end
RUBY
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@
it 'does not register an offense and no error when empty file' do
expect_no_offenses('', 'example_spec.rb')
end

context 'when the file is excluded' do
let(:config) do
RuboCop::Config.new(
'InternalAffairs/UselessMessageAssertion' => { 'Exclude' => ['**/example_spec.rb'] }
)
end

it 'does not register an offense' do
expect_no_offenses(<<~RUBY, 'example_spec.rb')
let(:msg) { described_class::MSG }
RUBY
end
end
end

0 comments on commit ff4c3f5

Please sign in to comment.