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

Add Tempfile.create to ignored iterators list #1747

Merged
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
1 change: 1 addition & 0 deletions docs/defaults.reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ detectors:
max_allowed_nesting: 1
ignore_iterators:
- tap
- Tempfile.create
NilCheck:
enabled: true
exclude: []
Expand Down
7 changes: 4 additions & 3 deletions lib/reek/smell_detectors/nested_iterators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def line
# The name of the config field that sets the names of any
# methods for which nesting should not be considered
IGNORE_ITERATORS_KEY = 'ignore_iterators'
DEFAULT_IGNORE_ITERATORS = ['tap'].freeze
DEFAULT_IGNORE_ITERATORS = ['tap', 'Tempfile.create'].freeze

def self.default_config
super.merge(
Expand Down Expand Up @@ -128,8 +128,9 @@ def max_allowed_nesting

# @quality :reek:FeatureEnvy
def ignored_iterator?(exp)
ignore_iterators.any? { |pattern| /#{pattern}/ =~ exp.call.name } ||
exp.without_block_arguments?
ignore_iterators.any? do |pattern|
/#{pattern}/ =~ exp.call.format_to_ruby
end || exp.without_block_arguments?
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/reek/smell_detectors/nested_iterators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ def alfa(bravo)
expect(src).not_to reek_of(:NestedIterators)
end

it 'does not report nested iterators for Tempfile#create' do
src = <<-RUBY
def alfa(bravo)
Tempfile.create('bravo', '.') do |charlie|
charlie.each { |delta| delta }
end
end
RUBY

expect(src).not_to reek_of(:NestedIterators)
end

it 'does not report method with successive iterators' do
src = <<-RUBY
def alfa
Expand Down
Loading