Skip to content

Commit

Permalink
Merge pull request #1151 from jhubert/1150-super-feature-envy
Browse files Browse the repository at this point in the history
Stop reporting FeatureEnvy with super and arguments
  • Loading branch information
troessner committed Dec 3, 2016
2 parents a250726 + bf1770b commit 3e19596
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/reek/context_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Reek
# counting. Ideally `ContextBuilder` would only build up the context tree and leave the
# statement and reference counting to the contexts.
#
# :reek:TooManyMethods: { max_methods: 30 }
# :reek:TooManyMethods: { max_methods: 31 }
# :reek:UnusedPrivateMethod: { exclude: [ !ruby/regexp /process_/ ] }
class ContextBuilder
attr_reader :context_tree
Expand Down Expand Up @@ -228,6 +228,30 @@ def process_zsuper(_)
current_context.record_use_of_self
end

# Handles `super` nodes a.k.a. calls to `super` with arguments
#
# An input example that would trigger this method would be:
#
# def call_me; super(); end
#
# or
#
# def call_me; super(bar); end
#
# but not
#
# def call_me; super; end
#
# and not
#
# def call_me; super do end; end
#
# We record one reference to `self`.
#
def process_super(_)
current_context.record_use_of_self
end

# Handles `block` nodes.
#
# An input example that would trigger this method would be:
Expand Down
5 changes: 5 additions & 0 deletions spec/reek/smell_detectors/feature_envy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def golf(hotel)
expect(src).not_to reek_of(:FeatureEnvy)
end

it 'does not report parameter method called with super ' do
src = 'def alfa(bravo) super(bravo.to_s); end'
expect(src).not_to reek_of(:FeatureEnvy)
end

it 'ignores multiple ivars' do
src = <<-EOS
def func
Expand Down

0 comments on commit 3e19596

Please sign in to comment.