reek 1.2.7 → 1.2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,4 +1,9 @@
1
- == 1.2.7 (in development)
1
+ == 1.2.7.1 (in development)
2
+
3
+ === Minor Changes
4
+ * Fixed crash on a case statement with no condition (#58)
5
+
6
+ == 1.2.7 (2010-02-01)
2
7
 
3
8
  === Major Changes
4
9
  * New option --yaml reports smells in YAML format
data/lib/reek.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Reek's core functionality
3
3
  #
4
4
  module Reek
5
- VERSION = '1.2.7'
5
+ VERSION = '1.2.7.1'
6
6
  end
7
7
 
8
8
  require File.join(File.dirname(File.expand_path(__FILE__)), 'reek', 'examiner')
@@ -63,6 +63,7 @@ module Reek
63
63
  def control_parameters(method_ctx)
64
64
  params = method_ctx.exp.parameter_names
65
65
  result = Hash.new {|hash,key| hash[key] = []}
66
+ return result if params.empty?
66
67
  method_ctx.local_nodes(:if) do |if_node|
67
68
  cond = if_node[1]
68
69
  if cond[0] == :lvar and params.include?(cond[1])
@@ -61,14 +61,14 @@ module Reek
61
61
  # the given syntax tree together with the number of times each
62
62
  # occurs. Ignores nested classes and modules.
63
63
  #
64
- def conditional_counts(klass)
64
+ def conditional_counts(sexp)
65
65
  result = Hash.new {|hash,key| hash[key] = []}
66
66
  collector = proc { |node|
67
67
  condition = node.condition
68
- next if condition == s(:call, nil, :block_given?, s(:arglist))
68
+ next if condition.nil? or condition == s(:call, nil, :block_given?, s(:arglist))
69
69
  result[condition].push(condition.line)
70
70
  }
71
- [:if, :case].each {|stmt| klass.local_nodes(stmt, &collector) }
71
+ [:if, :case].each {|stmt| sexp.local_nodes(stmt, &collector) }
72
72
  result
73
73
  end
74
74
  end
data/reek.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reek}
5
- s.version = "1.2.7"
5
+ s.version = "1.2.7.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Kevin Rutherford"]
9
- s.date = %q{2010-02-01}
9
+ s.date = %q{2010-02-03}
10
10
  s.default_executable = %q{reek}
11
11
  s.description = %q{Reek is a tool that examines Ruby classes, modules and methods
12
12
  and reports any code smells it finds.
@@ -10,6 +10,7 @@ include Reek::Smells
10
10
  describe ClassVariable do
11
11
  before :each do
12
12
  @detector = ClassVariable.new('raffles')
13
+ @class_variable = '@@things'
13
14
  end
14
15
 
15
16
  context 'with no class variables' do
@@ -25,99 +26,62 @@ describe ClassVariable do
25
26
 
26
27
  context 'with one class variable' do
27
28
  shared_examples_for 'one variable found' do
28
- it 'records the class variable' do
29
- @detector.class_variables_in(@ctx).should include(:@@tools)
29
+ before :each do
30
+ @detector.examine_context(@ctx)
31
+ @smells = @detector.smells_found
30
32
  end
31
33
  it 'records only that class variable' do
32
- @detector.class_variables_in(@ctx).length.should == 1
34
+ @smells.length.should == 1
33
35
  end
34
- it 'records the variable in the YAML report' do
35
- @detector.examine_context(@ctx)
36
- @detector.smells_found.each do |warning|
37
- warning.to_yaml.should match(/variable:[\s]*"@@tools"/)
36
+ it 'records the variable name' do
37
+ @smells.each do |warning|
38
+ warning.smell['variable'].should == @class_variable
38
39
  end
39
40
  end
40
41
  end
41
42
 
42
- context 'declared in a class' do
43
- before :each do
44
- @ctx = ClassContext.from_s('class Fred; @@tools = {}; end')
45
- end
46
-
47
- it_should_behave_like 'one variable found'
48
- end
49
-
50
- context 'used in a class' do
51
- before :each do
52
- @ctx = ClassContext.from_s('class Fred; def jim() @@tools = {}; end; end')
53
- end
54
-
55
- it_should_behave_like 'one variable found'
56
- end
57
-
58
- context 'indexed in a class' do
59
- before :each do
60
- @ctx = ClassContext.from_s('class Fred; def jim() @@tools[mash] = {}; end; end')
61
- end
62
-
63
- it_should_behave_like 'one variable found'
64
- end
65
-
66
- context 'declared and used in a class' do
67
- before :each do
68
- @ctx = ClassContext.from_s('class Fred; @@tools = {}; def jim() @@tools = {}; end; end')
69
- end
70
-
71
- it_should_behave_like 'one variable found'
72
- end
43
+ ['class', 'module'].each do |scope|
44
+ context "declared in a #{scope}" do
45
+ before :each do
46
+ @ctx = ClassContext.from_s("#{scope} Fred; #{@class_variable} = {}; end")
47
+ end
73
48
 
74
- context 'used twice in a class' do
75
- before :each do
76
- @ctx = ClassContext.from_s('class Fred; def jeff() @@tools = {}; end; def jim() @@tools = {}; end; end')
49
+ it_should_behave_like 'one variable found'
77
50
  end
78
51
 
79
- it_should_behave_like 'one variable found'
80
- end
52
+ context "used in a #{scope}" do
53
+ before :each do
54
+ @ctx = ClassContext.from_s("#{scope} Fred; def jim() #{@class_variable} = {}; end; end")
55
+ end
81
56
 
82
- context 'declared in a module' do
83
- before :each do
84
- @ctx = ClassContext.from_s('module Fred; @@tools = {}; end')
57
+ it_should_behave_like 'one variable found'
85
58
  end
86
59
 
87
- it_should_behave_like 'one variable found'
88
- end
60
+ context "indexed in a #{scope}" do
61
+ before :each do
62
+ @ctx = ClassContext.from_s("#{scope} Fred; def jim() #{@class_variable}[mash] = {}; end; end")
63
+ end
89
64
 
90
- context 'used in a module' do
91
- before :each do
92
- @ctx = ClassContext.from_s('module Fred; def jim() @@tools = {}; end; end')
65
+ it_should_behave_like 'one variable found'
93
66
  end
94
67
 
95
- it_should_behave_like 'one variable found'
96
- end
68
+ context "declared and used in a #{scope}" do
69
+ before :each do
70
+ @ctx = ClassContext.from_s("#{scope} Fred; #{@class_variable} = {}; def jim() #{@class_variable} = {}; end; end")
71
+ end
97
72
 
98
- context 'indexed in a module' do
99
- before :each do
100
- @ctx = ClassContext.from_s('module Fred; def jim() @@tools[mash] = {}; end; end')
73
+ it_should_behave_like 'one variable found'
101
74
  end
102
75
 
103
- it_should_behave_like 'one variable found'
104
- end
76
+ context "used twice in a #{scope}" do
77
+ before :each do
78
+ @ctx = ClassContext.from_s("#{scope} Fred; def jeff() #{@class_variable} = {}; end; def jim() #{@class_variable} = {}; end; end")
79
+ end
105
80
 
106
- context 'declared and used in a module' do
107
- before :each do
108
- @ctx = ClassContext.from_s('module Fred; @@tools = {}; def jim() @@tools = {}; end; end')
81
+ it_should_behave_like 'one variable found'
109
82
  end
110
-
111
- it_should_behave_like 'one variable found'
112
83
  end
113
84
 
114
- context 'used twice in a module' do
115
- before :each do
116
- @ctx = ClassContext.from_s('module Fred; def jeff() @@tools = {}; end; def jim() @@tools = {}; end; end')
117
- end
118
-
119
- it_should_behave_like 'one variable found'
120
- end
121
85
  end
122
86
 
123
87
  it_should_behave_like 'SmellDetector'
@@ -30,6 +30,14 @@ describe SimulatedPolymorphism do
30
30
  end
31
31
  end
32
32
 
33
+ context 'with an empty condition' do
34
+ it 'does not record the condition' do
35
+ ast = 'def fred() case; when 3; end; end'.to_reek_source.syntax_tree
36
+ ctx = CodeContext.new(nil, ast)
37
+ @detector.conditional_counts(ctx).length.should == 0
38
+ end
39
+ end
40
+
33
41
  context 'with three identical conditionals' do
34
42
  before :each do
35
43
  @cond = '@field == :sym'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reek
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-01 00:00:00 +00:00
12
+ date: 2010-02-03 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency