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

Only report FeatureEnvy for instance methods #1338

Merged
merged 1 commit into from
Jun 13, 2018
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 lib/reek/smell_detectors/feature_envy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FeatureEnvy < BaseDetector
# @return [Array<SmellWarning>]
#
def sniff
return [] if context.singleton_method? || context.module_function?
return [] unless context.references_self?
envious_receivers.map do |name, lines|
smell_warning(
Expand Down
45 changes: 45 additions & 0 deletions spec/reek/smell_detectors/feature_envy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,49 @@ def alfa(bravo)

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

it 'does not report on class methods defined by opening the metaclass' do
src = <<-EOS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use the name of the language as a delimiter (i.e. RUBY), most editors will provide syntax highlighting for the code example. 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice. I'm leaving it as-is for now to match the rest of the specs. Then we can change all of them in one go.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use the name of the language as a delimiter (i.e. RUBY), most editors will provide syntax highlighting for the code example

Super cool indeed, didn't know that!

class Alfa
class << self
def bravo(charlie)
delta = new(charlie)
delta.echo
delta.echo
end
end
end
EOS

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

it 'does not report on class methods defined with an explicit receiver' do
src = <<-EOS
class Alfa
def self.bravo(charlie)
delta = new(charlie)
delta.echo
delta.echo
end
end
EOS

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

it 'does not report module functions' do
src = <<-EOF
module Alfa
module_function
def bravo(charlie)
echo = delta(charlie)
echo.foxtrot
echo.foxtrot
end
end
EOF

expect(src).not_to reek_of(:FeatureEnvy)
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice specs!

end