Skip to content

Commit

Permalink
Applied Preserve Whole Object to smell warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jul 6, 2009
1 parent 84222cc commit 65646be
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 35 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -9,6 +9,7 @@
** Reports for multiple sources are run together; no more blank lines
* The smells masked by *.reek config files can now be seen:
** The header for each source file now counts masked smells
** The --show-all (-a) option shows masked warnings in the report

=== Minor Changes
* Several changes to the LongMethod counting algorithm:
Expand Down
8 changes: 4 additions & 4 deletions config/defaults.reek
Expand Up @@ -7,8 +7,8 @@ LargeClass:
max_instance_variables: 9
LongParameterList:
max_params: 3
exclude:
- initialize
exclude: []

enabled: true
FeatureEnvy:
exclude:
Expand Down Expand Up @@ -46,6 +46,6 @@ ControlCouple:
enabled: true
LongYieldList:
max_params: 3
exclude:
- initialize
exclude: []

enabled: true
3 changes: 2 additions & 1 deletion features/samples.feature
Expand Up @@ -50,7 +50,7 @@ Feature: Basic smell detection
Then it fails with exit status 2
And it reports:
"""
spec/samples/optparse.rb -- 116 warnings:
spec/samples/optparse.rb -- 117 warnings:
OptionParser has at least 59 methods (Large Class)
OptionParser#CompletingHash#match/block/block is nested (Nested Iterators)
OptionParser#Completion::complete calls candidates.size multiple times (Duplication)
Expand Down Expand Up @@ -81,6 +81,7 @@ Feature: Basic smell detection
OptionParser#Switch#RequiredArgument#parse is controlled by argument arg (Control Couple)
OptionParser#Switch#add_banner has the variable name 's' (Uncommunicative Name)
OptionParser#Switch#conv_arg calls conv multiple times (Duplication)
OptionParser#Switch#initialize has 7 parameters (Long Parameter List)
OptionParser#Switch#parse_arg calls pattern multiple times (Duplication)
OptionParser#Switch#parse_arg calls s.length multiple times (Duplication)
OptionParser#Switch#parse_arg has approx 11 statements (Long Method)
Expand Down
10 changes: 5 additions & 5 deletions lib/reek/smell_warning.rb
Expand Up @@ -8,11 +8,11 @@ module Reek
class SmellWarning
include Comparable

def initialize(smell, context, warning, is_masked = false)
@smell = smell
def initialize(smell, context, warning)
@detector = smell
@context = context
@warning = warning
@is_masked = is_masked
@is_masked = smell.masked?
end

def hash # :nodoc:
Expand All @@ -30,13 +30,13 @@ def <=>(other)
# +smell_class+ and its report string matches all of the +patterns+.
#
def matches?(smell_class, patterns)
return false unless smell_class.to_s == @smell.class.class_name
return false unless smell_class.to_s == @detector.class.class_name
rpt = report
return patterns.all? {|exp| exp === rpt}
end

def basic_report
Options[:format].gsub(/\%s/, @smell.smell_name).gsub(/\%c/, @context.to_s).gsub(/\%w/, @warning)
Options[:format].gsub(/\%s/, @detector.smell_name).gsub(/\%c/, @context.to_s).gsub(/\%w/, @warning)
end

#
Expand Down
5 changes: 1 addition & 4 deletions lib/reek/smells/long_parameter_list.rb
Expand Up @@ -19,10 +19,7 @@ class LongParameterList < SmellDetector
MAX_ALLOWED_PARAMS_KEY = 'max_params'

def self.default_config
super.adopt(
MAX_ALLOWED_PARAMS_KEY => 3,
EXCLUDE_KEY => ['initialize']
)
super.adopt(MAX_ALLOWED_PARAMS_KEY => 3)
end

def initialize(config = LongParameterList.default_config)
Expand Down
6 changes: 5 additions & 1 deletion lib/reek/smells/smell_detector.rb
Expand Up @@ -58,6 +58,10 @@ def be_masked
@masked = true
end

def masked?
@masked
end

def enabled?
@config[ENABLED_KEY]
end
Expand Down Expand Up @@ -90,7 +94,7 @@ def exception?(context)
end

def found(scope, warning)
smell = SmellWarning.new(self, scope, warning, @masked)
smell = SmellWarning.new(self, scope, warning)
@smells_found << smell
smell
end
Expand Down
20 changes: 0 additions & 20 deletions spec/reek/smell_warning_spec.rb
Expand Up @@ -8,37 +8,17 @@
before :each do
@first = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self")
@second = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self")
@masked = SmellWarning.new(Smells::FeatureEnvy.new, "self", "self", true)
end

it 'should hash equal when the smell is the same' do
@first.hash.should == @second.hash
@first.hash.should == @masked.hash
end

it 'should compare equal when the smell is the same' do
@first.should == @second
@first.should == @masked
end

it 'should compare equal when using <=>' do
(@first <=> @second).should == 0
end

it 'should compare equal to masked smell' do
(@first <=> @masked).should == 0
end
end

describe SmellWarning, 'ordering' do
before :each do
@first = SmellWarning.new(Smells::FeatureEnvy.new, "aaa", "bbb")
@second = SmellWarning.new(Smells::FeatureEnvy.new, "ccc", "ddd")
@masked = SmellWarning.new(Smells::FeatureEnvy.new, "ccc", "ddd", true)
end

it 'should ignore masking in comparisons' do
(@first <=> @second).should == (@first <=> @masked)
(@second <=> @first).should == (@masked <=> @first)
end
end

0 comments on commit 65646be

Please sign in to comment.