kevinrutherford-reek 0.3.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/History.txt +92 -0
  2. data/README.txt +6 -0
  3. data/Rakefile +7 -0
  4. data/bin/reek +19 -0
  5. data/lib/reek/block_context.rb +37 -0
  6. data/lib/reek/class_context.rb +73 -0
  7. data/lib/reek/code_context.rb +47 -0
  8. data/lib/reek/code_parser.rb +204 -0
  9. data/lib/reek/exceptions.reek +13 -0
  10. data/lib/reek/if_context.rb +25 -0
  11. data/lib/reek/method_context.rb +85 -0
  12. data/lib/reek/module_context.rb +34 -0
  13. data/lib/reek/name.rb +42 -0
  14. data/lib/reek/object_refs.rb +53 -0
  15. data/lib/reek/options.rb +92 -0
  16. data/lib/reek/rake_task.rb +121 -0
  17. data/lib/reek/report.rb +42 -0
  18. data/lib/reek/sexp_formatter.rb +52 -0
  19. data/lib/reek/singleton_method_context.rb +27 -0
  20. data/lib/reek/smell_warning.rb +49 -0
  21. data/lib/reek/smells/control_couple.rb +61 -0
  22. data/lib/reek/smells/duplication.rb +50 -0
  23. data/lib/reek/smells/feature_envy.rb +58 -0
  24. data/lib/reek/smells/large_class.rb +50 -0
  25. data/lib/reek/smells/long_method.rb +43 -0
  26. data/lib/reek/smells/long_parameter_list.rb +43 -0
  27. data/lib/reek/smells/long_yield_list.rb +18 -0
  28. data/lib/reek/smells/nested_iterators.rb +28 -0
  29. data/lib/reek/smells/smell_detector.rb +66 -0
  30. data/lib/reek/smells/smells.rb +85 -0
  31. data/lib/reek/smells/uncommunicative_name.rb +80 -0
  32. data/lib/reek/smells/utility_function.rb +34 -0
  33. data/lib/reek/source.rb +116 -0
  34. data/lib/reek/spec.rb +130 -0
  35. data/lib/reek/stop_context.rb +62 -0
  36. data/lib/reek/yield_call_context.rb +14 -0
  37. data/lib/reek.rb +8 -0
  38. data/spec/integration/reek_source_spec.rb +20 -0
  39. data/spec/integration/script_spec.rb +55 -0
  40. data/spec/reek/class_context_spec.rb +198 -0
  41. data/spec/reek/code_context_spec.rb +92 -0
  42. data/spec/reek/code_parser_spec.rb +44 -0
  43. data/spec/reek/config_spec.rb +42 -0
  44. data/spec/reek/module_context_spec.rb +38 -0
  45. data/spec/reek/object_refs_spec.rb +129 -0
  46. data/spec/reek/options_spec.rb +13 -0
  47. data/spec/reek/report_spec.rb +48 -0
  48. data/spec/reek/sexp_formatter_spec.rb +31 -0
  49. data/spec/reek/singleton_method_context_spec.rb +17 -0
  50. data/spec/reek/smells/control_couple_spec.rb +23 -0
  51. data/spec/reek/smells/duplication_spec.rb +81 -0
  52. data/spec/reek/smells/feature_envy_spec.rb +129 -0
  53. data/spec/reek/smells/large_class_spec.rb +86 -0
  54. data/spec/reek/smells/long_method_spec.rb +59 -0
  55. data/spec/reek/smells/long_parameter_list_spec.rb +92 -0
  56. data/spec/reek/smells/nested_iterators_spec.rb +33 -0
  57. data/spec/reek/smells/smell_spec.rb +24 -0
  58. data/spec/reek/smells/uncommunicative_name_spec.rb +118 -0
  59. data/spec/reek/smells/utility_function_spec.rb +96 -0
  60. data/spec/samples/inline.rb +704 -0
  61. data/spec/samples/inline_spec.rb +40 -0
  62. data/spec/samples/optparse.rb +1788 -0
  63. data/spec/samples/optparse_spec.rb +100 -0
  64. data/spec/samples/redcloth.rb +1130 -0
  65. data/spec/samples/redcloth_spec.rb +93 -0
  66. data/spec/spec.opts +1 -0
  67. data/spec/spec_helper.rb +15 -0
  68. data/tasks/reek.rake +20 -0
  69. data/tasks/rspec.rake +22 -0
  70. metadata +167 -0
@@ -0,0 +1,118 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+ require 'ostruct'
3
+ require 'reek/method_context'
4
+ require 'reek/smells/uncommunicative_name'
5
+
6
+ include Reek
7
+ include Reek::Smells
8
+
9
+ describe UncommunicativeName, "method name" do
10
+ it 'should not report one-word method name' do
11
+ 'def help(fred) basics(17) end'.should_not reek
12
+ end
13
+ it 'should report one-letter method name' do
14
+ 'def x(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/)
15
+ end
16
+ it 'should report name of the form "x2"' do
17
+ 'def x2(fred) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/)
18
+ end
19
+ end
20
+
21
+ describe UncommunicativeName, "field name" do
22
+ it 'should not report one-word field name' do
23
+ 'class Thing; def help(fred) @simple end end'.should_not reek
24
+ end
25
+ it 'should report one-letter fieldname' do
26
+ 'class Thing; def simple(fred) @x end end'.should reek_only_of(:UncommunicativeName, /@x/, /Thing/, /variable name/)
27
+ end
28
+ it 'should report name of the form "x2"' do
29
+ 'class Thing; def simple(fred) @x2 end end'.should reek_only_of(:UncommunicativeName, /@x2/, /Thing/, /variable name/)
30
+ end
31
+ it 'should report one-letter fieldname in assignment' do
32
+ 'class Thing; def simple(fred) @x = fred end end'.should reek_only_of(:UncommunicativeName, /@x/, /Thing/, /variable name/)
33
+ end
34
+ end
35
+
36
+ describe UncommunicativeName, "local variable name" do
37
+ it 'should not report one-word variable name' do
38
+ 'def help(fred) simple = jim(45) end'.should_not reek
39
+ end
40
+ it 'should report one-letter variable name' do
41
+ 'def simple(fred) x = jim(45) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/)
42
+ end
43
+ it 'should report name of the form "x2"' do
44
+ 'def simple(fred) x2 = jim(45) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/)
45
+ end
46
+ it 'should report variable name only once' do
47
+ 'def simple(fred) x = jim(45); x = y end'.should reek_only_of(:UncommunicativeName, /x/)
48
+ end
49
+ end
50
+
51
+ describe UncommunicativeName, "parameter name" do
52
+ it 'should not recognise *' do
53
+ 'def help(xray, *) basics(17) end'.should_not reek
54
+ end
55
+ it "should report parameter's name" do
56
+ 'def help(x) basics(17) end'.should reek_only_of(:UncommunicativeName, /x/, /variable name/)
57
+ end
58
+ it 'should report name of the form "x2"' do
59
+ 'def help(x2) basics(17) end'.should reek_only_of(:UncommunicativeName, /x2/, /variable name/)
60
+ end
61
+ end
62
+
63
+ describe UncommunicativeName, "block parameter name" do
64
+ it "should report parameter's name" do
65
+ 'def help() @stuff.each {|x|} end'.should reek_only_of(:UncommunicativeName, /x/, /block/, /variable name/)
66
+ end
67
+
68
+ it "should report method name via if context" do
69
+ src = <<EOS
70
+ def bad
71
+ unless @mod then
72
+ @sig.each { |x| x.to_s }
73
+ end
74
+ end
75
+ EOS
76
+ src.should reek_only_of(:UncommunicativeName, /'x'/)
77
+ end
78
+ end
79
+
80
+ describe UncommunicativeName, "several names" do
81
+
82
+ it 'should report all bad names' do
83
+ ruby = Source.from_s('class Oof; def y(x) @z = x end end')
84
+ ruby.should reek_of(:UncommunicativeName, /'x'/)
85
+ ruby.should reek_of(:UncommunicativeName, /'y'/)
86
+ ruby.should reek_of(:UncommunicativeName, /'@z'/)
87
+ end
88
+
89
+ it 'should report all bad block parameters' do
90
+ source =<<EOS
91
+ class Thing
92
+ def bad(fred)
93
+ @fred.each {|x| 4 - x }
94
+ @jim.each {|y| y - 4 }
95
+ end
96
+ end
97
+ EOS
98
+ source.should reek_of(:UncommunicativeName, /'x'/)
99
+ source.should reek_of(:UncommunicativeName, /'y'/)
100
+ end
101
+ end
102
+
103
+ describe UncommunicativeName, '#examine' do
104
+ before :each do
105
+ @report = Report.new
106
+ @uc = UncommunicativeName.new
107
+ end
108
+
109
+ it 'should return true when reporting a smell' do
110
+ mc = MethodContext.new(StopContext.new, [:defn, :x, nil])
111
+ @uc.examine(mc, @report).should == true
112
+ end
113
+
114
+ it 'should return false when not reporting a smell' do
115
+ mc = MethodContext.new(StopContext.new, [:defn, :not_bad, nil])
116
+ @uc.examine(mc, @report).should == false
117
+ end
118
+ end
@@ -0,0 +1,96 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ require 'reek/smells/utility_function'
4
+
5
+ include Reek
6
+ include Reek::Smells
7
+
8
+ describe UtilityFunction do
9
+
10
+ before(:each) do
11
+ @rpt = Report.new
12
+ @cchk = CodeParser.new(@rpt, SmellConfig.new.smell_listeners)
13
+ end
14
+
15
+ it 'should not report attrset' do
16
+ class Fred
17
+ attr_writer :xyz
18
+ end
19
+ @cchk.check_object(Fred)
20
+ @rpt.should be_empty
21
+ end
22
+
23
+ it 'should count usages of self'do
24
+ 'def <=>(other) Options[:sort_order].compare(self, other) end'.should_not reek
25
+ end
26
+ it 'should count self reference within a dstr' do
27
+ 'def as(alias_name); "#{self} as #{alias_name}".to_sym; end'.should_not reek
28
+ end
29
+ it 'should count calls to self within a dstr' do
30
+ 'def to_sql; "\'#{self.gsub(/\'/, "\'\'")}\'"; end'.should_not reek
31
+ end
32
+ it 'should report simple parameter call' do
33
+ 'def simple(arga) arga.to_s end'.should reek_of(:UtilityFunction, /simple/)
34
+ end
35
+ it 'should report message chain' do
36
+ 'def simple(arga) arga.b.c end'.should reek_of(:UtilityFunction, /simple/)
37
+ end
38
+
39
+ it 'should not report overriding methods' do
40
+ class Father
41
+ def thing(ff); @kids = 0; end
42
+ end
43
+ class Son < Father
44
+ def thing(ff); ff; end
45
+ end
46
+ @cchk.check_object(Son)
47
+ @rpt.should be_empty
48
+ end
49
+
50
+ it 'should not report class method' do
51
+ pending('bug')
52
+ source = <<EOS
53
+ class Cache
54
+ class << self
55
+ def create_unless_known(attributes)
56
+ Cache.create(attributes) unless Cache.known?
57
+ end
58
+ end
59
+ end
60
+ EOS
61
+ source.should_not reek
62
+ end
63
+
64
+ it 'should recognise a deep call' do
65
+ src = <<EOS
66
+ class Red
67
+ def deep(text)
68
+ text.each { |mod| atts = shelve(mod) }
69
+ end
70
+
71
+ def shelve(val)
72
+ @shelf << val
73
+ end
74
+ end
75
+ EOS
76
+ src.should_not reek
77
+ end
78
+ end
79
+
80
+ describe UtilityFunction, 'should only report a method containing a call' do
81
+ it 'should not report empty method' do
82
+ 'def simple(arga) end'.should_not reek
83
+ end
84
+ it 'should not report literal' do
85
+ 'def simple(arga) 3; end'.should_not reek
86
+ end
87
+ it 'should not report instance variable reference' do
88
+ 'def simple(arga) @yellow end'.should_not reek
89
+ end
90
+ it 'should not report vcall' do
91
+ 'def simple(arga) y end'.should_not reek
92
+ end
93
+ it 'should not report references to self' do
94
+ 'def into; self; end'.should_not reek
95
+ end
96
+ end