threedaymonk-roodi 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/README.txt +96 -0
  2. data/bin/roodi +21 -0
  3. data/bin/roodi-describe +7 -0
  4. data/lib/roodi.rb +6 -0
  5. data/lib/roodi/checks.rb +16 -0
  6. data/lib/roodi/checks/abc_metric_method_check.rb +77 -0
  7. data/lib/roodi/checks/assignment_in_conditional_check.rb +32 -0
  8. data/lib/roodi/checks/case_missing_else_check.rb +20 -0
  9. data/lib/roodi/checks/check.rb +30 -0
  10. data/lib/roodi/checks/class_line_count_check.rb +18 -0
  11. data/lib/roodi/checks/class_name_check.rb +21 -0
  12. data/lib/roodi/checks/class_variable_check.rb +24 -0
  13. data/lib/roodi/checks/control_coupling_check.rb +20 -0
  14. data/lib/roodi/checks/cyclomatic_complexity_block_check.rb +32 -0
  15. data/lib/roodi/checks/cyclomatic_complexity_check.rb +29 -0
  16. data/lib/roodi/checks/cyclomatic_complexity_method_check.rb +32 -0
  17. data/lib/roodi/checks/empty_rescue_body_check.rb +33 -0
  18. data/lib/roodi/checks/for_loop_check.rb +20 -0
  19. data/lib/roodi/checks/line_count_check.rb +29 -0
  20. data/lib/roodi/checks/method_line_count_check.rb +19 -0
  21. data/lib/roodi/checks/method_name_check.rb +21 -0
  22. data/lib/roodi/checks/module_line_count_check.rb +18 -0
  23. data/lib/roodi/checks/module_name_check.rb +21 -0
  24. data/lib/roodi/checks/name_check.rb +23 -0
  25. data/lib/roodi/checks/parameter_number_check.rb +30 -0
  26. data/lib/roodi/core.rb +1 -0
  27. data/lib/roodi/core/checking_visitor.rb +23 -0
  28. data/lib/roodi/core/error.rb +17 -0
  29. data/lib/roodi/core/iterator_visitor.rb +19 -0
  30. data/lib/roodi/core/parser.rb +35 -0
  31. data/lib/roodi/core/runner.rb +78 -0
  32. data/lib/roodi/core/visitable_sexp.rb +20 -0
  33. data/lib/roodi_task.rb +35 -0
  34. data/roodi.yml +15 -0
  35. data/spec/roodi/checks/abc_metric_method_check_spec.rb +89 -0
  36. data/spec/roodi/checks/assignment_in_conditional_check_spec.rb +64 -0
  37. data/spec/roodi/checks/case_missing_else_check_spec.rb +32 -0
  38. data/spec/roodi/checks/class_line_count_check_spec.rb +39 -0
  39. data/spec/roodi/checks/class_name_check_spec.rb +39 -0
  40. data/spec/roodi/checks/class_variable_check_spec.rb +17 -0
  41. data/spec/roodi/checks/control_coupling_check_spec.rb +23 -0
  42. data/spec/roodi/checks/cyclomatic_complexity_block_check_spec.rb +36 -0
  43. data/spec/roodi/checks/cyclomatic_complexity_method_check_spec.rb +183 -0
  44. data/spec/roodi/checks/empty_rescue_body_check_spec.rb +114 -0
  45. data/spec/roodi/checks/for_loop_check_spec.rb +18 -0
  46. data/spec/roodi/checks/method_line_count_check_spec.rb +39 -0
  47. data/spec/roodi/checks/method_name_check_spec.rb +76 -0
  48. data/spec/roodi/checks/module_line_count_check_spec.rb +39 -0
  49. data/spec/roodi/checks/module_name_check_spec.rb +27 -0
  50. data/spec/roodi/checks/parameter_number_check_spec.rb +47 -0
  51. data/spec/spec_helper.rb +3 -0
  52. metadata +129 -0
@@ -0,0 +1,114 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Roodi::Checks::EmptyRescueBodyCheck do
4
+ before(:each) do
5
+ @roodi = Roodi::Core::Runner.new(Roodi::Checks::EmptyRescueBodyCheck.new)
6
+ end
7
+
8
+ it "should accept a rescue body with content and no parameter" do
9
+ content = <<-END
10
+ begin
11
+ call_method
12
+ rescue
13
+ puts "Recover from the call"
14
+ end
15
+ END
16
+ @roodi.check_content(content)
17
+ @roodi.errors.should be_empty
18
+ end
19
+
20
+ it "should accept a rescue body with a return" do
21
+ content = <<-END
22
+ begin
23
+ call_method
24
+ rescue
25
+ return true
26
+ end
27
+ END
28
+ @roodi.check_content(content)
29
+ @roodi.errors.should be_empty
30
+ end
31
+
32
+ it "should accept a method call that Ruby won't tell apart from a variable (a vcall)" do
33
+ content = <<-END
34
+ begin
35
+ call_method
36
+ rescue
37
+ show_error
38
+ end
39
+ END
40
+ @roodi.check_content(content)
41
+ @roodi.errors.should be_empty
42
+ end
43
+
44
+ it "should accept a rescue body with content and a parameter" do
45
+ content = <<-END
46
+ begin
47
+ call_method
48
+ rescue Exception => e
49
+ puts "Recover from the call"
50
+ end
51
+ END
52
+ @roodi.check_content(content)
53
+ @roodi.errors.should be_empty
54
+ end
55
+
56
+ it "should accept a rescue body with an assignment" do
57
+ content = <<-END
58
+ begin
59
+ call_method
60
+ rescue Exception => e
61
+ my_var = 1
62
+ end
63
+ END
64
+ @roodi.check_content(content)
65
+ @roodi.errors.should be_empty
66
+ end
67
+
68
+ it "should accept a rescue body with an attribute assignment" do
69
+ content = <<-END
70
+ begin
71
+ call_method
72
+ rescue Exception => e
73
+ self.var = 1
74
+ end
75
+ END
76
+ @roodi.check_content(content)
77
+ @roodi.errors.should be_empty
78
+ end
79
+
80
+ it "should reject an empty rescue block with no parameter" do
81
+ content = <<-END
82
+ begin
83
+ call_method
84
+ rescue
85
+ end
86
+ END
87
+ @roodi.check_content(content)
88
+ errors = @roodi.errors
89
+ errors.should_not be_empty
90
+ errors[0].to_s.should match(/dummy-file.rb:[3-4] - Rescue block should not be empty./)
91
+ end
92
+
93
+ it "should accept a rescue block with an explicit nil" do
94
+ content = <<-END
95
+ call_method rescue nil
96
+ END
97
+ @roodi.check_content(content)
98
+ errors = @roodi.errors
99
+ errors.should be_empty
100
+ end
101
+
102
+ it "should reject an empty rescue block with a parameter" do
103
+ content = <<-END
104
+ begin
105
+ call_method
106
+ rescue Exception => e
107
+ end
108
+ END
109
+ @roodi.check_content(content)
110
+ errors = @roodi.errors
111
+ errors.should_not be_empty
112
+ errors[0].to_s.should match(/dummy-file.rb:[3-4] - Rescue block should not be empty./)
113
+ end
114
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Roodi::Checks::ForLoopCheck do
4
+ before(:each) do
5
+ @roodi = Roodi::Core::Runner.new(Roodi::Checks::ForLoopCheck.new)
6
+ end
7
+
8
+ it "should reject for loops" do
9
+ content = <<-END
10
+ for i in 1..2
11
+ end
12
+ END
13
+ @roodi.check_content(content)
14
+ errors = @roodi.errors
15
+ errors.should_not be_empty
16
+ errors[0].to_s.should eql("dummy-file.rb:1 - Don't use 'for' loops. Use Enumerable.each instead.")
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Roodi::Checks::MethodLineCountCheck do
4
+ before(:each) do
5
+ @roodi = Roodi::Core::Runner.new(Roodi::Checks::MethodLineCountCheck.new({'line_count' => 1}))
6
+ end
7
+
8
+ it "should accept methods with less lines than the threshold" do
9
+ content = <<-END
10
+ def zero_line_method
11
+ end
12
+ END
13
+ @roodi.check_content(content)
14
+ @roodi.errors.should be_empty
15
+ end
16
+
17
+ it "should accept methods with the same number of lines as the threshold" do
18
+ content = <<-END
19
+ def one_line_method
20
+ 1
21
+ end
22
+ END
23
+ @roodi.check_content(content)
24
+ @roodi.errors.should be_empty
25
+ end
26
+
27
+ it "should reject methods with more lines than the threshold" do
28
+ content = <<-END
29
+ def two_line_method
30
+ puts 1
31
+ puts 2
32
+ end
33
+ END
34
+ @roodi.check_content(content)
35
+ errors = @roodi.errors
36
+ errors.should_not be_empty
37
+ errors[0].to_s.should eql("dummy-file.rb:1 - Method \"two_line_method\" has 2 lines. It should have 1 or less.")
38
+ end
39
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Roodi::Checks::MethodNameCheck do
4
+ before(:each) do
5
+ @roodi = Roodi::Core::Runner.new(Roodi::Checks::MethodNameCheck.new)
6
+ end
7
+
8
+ it "should accept method names with underscores" do
9
+ content = <<-END
10
+ def good_method_name
11
+ end
12
+ END
13
+ @roodi.check_content(content)
14
+ @roodi.errors.should be_empty
15
+ end
16
+
17
+ it "should accept method names with numbers" do
18
+ content = <<-END
19
+ def good_method_1_name
20
+ end
21
+ END
22
+ @roodi.check_content(content)
23
+ @roodi.errors.should be_empty
24
+ end
25
+
26
+ it "should accept method names ending a question mark" do
27
+ content = <<-END
28
+ def good_method_name?
29
+ end
30
+ END
31
+ @roodi.check_content(content)
32
+ @roodi.errors.should be_empty
33
+ end
34
+
35
+ it "should accept method names ending an exclamation mark" do
36
+ content = <<-END
37
+ def good_method_name!
38
+ end
39
+ END
40
+ @roodi.check_content(content)
41
+ @roodi.errors.should be_empty
42
+ end
43
+
44
+ it "should accept method names ending an equals sign" do
45
+ content = <<-END
46
+ def good_method_name=
47
+ end
48
+ END
49
+ @roodi.check_content(content)
50
+ @roodi.errors.should be_empty
51
+ end
52
+
53
+ describe "when processing non-text based method names" do
54
+ ['<<', '>>', '==', '=', '<', '<=', '>', '>=', '[]', '[]='].each do |each|
55
+ it "should accept #{each} as a method name" do
56
+ content = <<-END
57
+ def #{each}
58
+ end
59
+ END
60
+ @roodi.check_content(content)
61
+ @roodi.errors.should be_empty
62
+ end
63
+ end
64
+ end
65
+
66
+ it "should reject camel case method names" do
67
+ content = <<-END
68
+ def badMethodName
69
+ end
70
+ END
71
+ @roodi.check_content(content)
72
+ errors = @roodi.errors
73
+ errors.should_not be_empty
74
+ errors[0].to_s.should eql("dummy-file.rb:1 - Method name \"badMethodName\" should match pattern /^[_a-z<>=\\[|+-\\/\\*`]+[_a-z0-9_<>=~@\\[\\]]*[=!\\?]?$/")
75
+ end
76
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Roodi::Checks::ModuleLineCountCheck do
4
+ before(:each) do
5
+ @roodi = Roodi::Core::Runner.new(Roodi::Checks::ModuleLineCountCheck.new({'line_count' => 1}))
6
+ end
7
+
8
+ it "should accept modules with less lines than the threshold" do
9
+ content = <<-END
10
+ module ZeroLineModule
11
+ end
12
+ END
13
+ @roodi.check_content(content)
14
+ @roodi.errors.should be_empty
15
+ end
16
+
17
+ it "should accept modules with the same number of lines as the threshold" do
18
+ content = <<-END
19
+ module OneLineModule
20
+ @foo = 1
21
+ end
22
+ END
23
+ @roodi.check_content(content)
24
+ @roodi.errors.should be_empty
25
+ end
26
+
27
+ it "should reject modules with more lines than the threshold" do
28
+ content = <<-END
29
+ module TwoLineModule
30
+ @foo = 1
31
+ @bar = 2
32
+ end
33
+ END
34
+ @roodi.check_content(content)
35
+ errors = @roodi.errors
36
+ errors.should_not be_empty
37
+ errors[0].to_s.should eql("dummy-file.rb:1 - Module \"TwoLineModule\" has 2 lines. It should have 1 or less.")
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Roodi::Checks::ModuleNameCheck do
4
+ before(:each) do
5
+ @roodi = Roodi::Core::Runner.new(Roodi::Checks::ModuleNameCheck.new)
6
+ end
7
+
8
+ it "should accept camel case module names starting in capitals" do
9
+ content = <<-END
10
+ module GoodModuleName
11
+ end
12
+ END
13
+ @roodi.check_content(content)
14
+ @roodi.errors.should be_empty
15
+ end
16
+
17
+ it "should reject module names with underscores" do
18
+ content = <<-END
19
+ module Bad_ModuleName
20
+ end
21
+ END
22
+ @roodi.check_content(content)
23
+ errors = @roodi.errors
24
+ errors.should_not be_empty
25
+ errors[0].to_s.should eql("dummy-file.rb:1 - Module name \"Bad_ModuleName\" should match pattern /^[A-Z][a-zA-Z0-9]*$/")
26
+ end
27
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Roodi::Checks::ParameterNumberCheck do
4
+ before(:each) do
5
+ @roodi = Roodi::Core::Runner.new(Roodi::Checks::ParameterNumberCheck.new({'parameter_count' => 1}))
6
+ end
7
+
8
+ it "should accept methods with less lines than the threshold" do
9
+ content = <<-END
10
+ def zero_parameter_method
11
+ end
12
+ END
13
+ @roodi.check_content(content)
14
+ @roodi.errors.should be_empty
15
+ end
16
+
17
+ it "should accept methods with the same number of parameters as the threshold" do
18
+ content = <<-END
19
+ def one_parameter_method(first_parameter)
20
+ end
21
+ END
22
+ @roodi.check_content(content)
23
+ @roodi.errors.should be_empty
24
+ end
25
+
26
+ it "should reject methods with more parameters than the threshold" do
27
+ content = <<-END
28
+ def two_parameter_method(first_parameter, second_parameter)
29
+ end
30
+ END
31
+ @roodi.check_content(content)
32
+ errors = @roodi.errors
33
+ errors.should_not be_empty
34
+ errors[0].to_s.should eql("dummy-file.rb:1 - Method name \"two_parameter_method\" has 2 parameters. It should have 1 or less.")
35
+ end
36
+
37
+ it "should cope with default values on parameters" do
38
+ content = <<-END
39
+ def two_parameter_method(first_parameter = 1, second_parameter = 2)
40
+ end
41
+ END
42
+ @roodi.check_content(content)
43
+ errors = @roodi.errors
44
+ errors.should_not be_empty
45
+ errors[0].to_s.should eql("dummy-file.rb:1 - Method name \"two_parameter_method\" has 2 parameters. It should have 1 or less.")
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'roodi'
3
+ require 'spec'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: threedaymonk-roodi
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.8
5
+ platform: ruby
6
+ authors:
7
+ - Marty Andrews
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby_parser
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description:
36
+ email: marty@cogentconsulting.com.au
37
+ executables:
38
+ - roodi
39
+ - roodi-describe
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.txt
44
+ files:
45
+ - README.txt
46
+ - roodi.yml
47
+ - bin/roodi
48
+ - bin/roodi-describe
49
+ - spec/roodi
50
+ - spec/roodi/checks
51
+ - spec/roodi/checks/abc_metric_method_check_spec.rb
52
+ - spec/roodi/checks/assignment_in_conditional_check_spec.rb
53
+ - spec/roodi/checks/case_missing_else_check_spec.rb
54
+ - spec/roodi/checks/class_line_count_check_spec.rb
55
+ - spec/roodi/checks/class_name_check_spec.rb
56
+ - spec/roodi/checks/class_variable_check_spec.rb
57
+ - spec/roodi/checks/control_coupling_check_spec.rb
58
+ - spec/roodi/checks/cyclomatic_complexity_block_check_spec.rb
59
+ - spec/roodi/checks/cyclomatic_complexity_method_check_spec.rb
60
+ - spec/roodi/checks/empty_rescue_body_check_spec.rb
61
+ - spec/roodi/checks/for_loop_check_spec.rb
62
+ - spec/roodi/checks/method_line_count_check_spec.rb
63
+ - spec/roodi/checks/method_name_check_spec.rb
64
+ - spec/roodi/checks/module_line_count_check_spec.rb
65
+ - spec/roodi/checks/module_name_check_spec.rb
66
+ - spec/roodi/checks/parameter_number_check_spec.rb
67
+ - spec/spec_helper.rb
68
+ - lib/roodi
69
+ - lib/roodi/checks
70
+ - lib/roodi/checks/abc_metric_method_check.rb
71
+ - lib/roodi/checks/assignment_in_conditional_check.rb
72
+ - lib/roodi/checks/case_missing_else_check.rb
73
+ - lib/roodi/checks/check.rb
74
+ - lib/roodi/checks/class_line_count_check.rb
75
+ - lib/roodi/checks/class_name_check.rb
76
+ - lib/roodi/checks/class_variable_check.rb
77
+ - lib/roodi/checks/control_coupling_check.rb
78
+ - lib/roodi/checks/cyclomatic_complexity_block_check.rb
79
+ - lib/roodi/checks/cyclomatic_complexity_check.rb
80
+ - lib/roodi/checks/cyclomatic_complexity_method_check.rb
81
+ - lib/roodi/checks/empty_rescue_body_check.rb
82
+ - lib/roodi/checks/for_loop_check.rb
83
+ - lib/roodi/checks/line_count_check.rb
84
+ - lib/roodi/checks/method_line_count_check.rb
85
+ - lib/roodi/checks/method_name_check.rb
86
+ - lib/roodi/checks/module_line_count_check.rb
87
+ - lib/roodi/checks/module_name_check.rb
88
+ - lib/roodi/checks/name_check.rb
89
+ - lib/roodi/checks/parameter_number_check.rb
90
+ - lib/roodi/checks.rb
91
+ - lib/roodi/core
92
+ - lib/roodi/core/checking_visitor.rb
93
+ - lib/roodi/core/error.rb
94
+ - lib/roodi/core/iterator_visitor.rb
95
+ - lib/roodi/core/parser.rb
96
+ - lib/roodi/core/runner.rb
97
+ - lib/roodi/core/visitable_sexp.rb
98
+ - lib/roodi/core.rb
99
+ - lib/roodi.rb
100
+ - lib/roodi_task.rb
101
+ has_rdoc: true
102
+ homepage: http://github.com/threedaymonk/roodi
103
+ post_install_message:
104
+ rdoc_options:
105
+ - --main
106
+ - README.txt
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ version:
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: "0"
120
+ version:
121
+ requirements: []
122
+
123
+ rubyforge_project: roodi
124
+ rubygems_version: 1.2.0
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Roodi parses your Ruby code and warns you about design issues you have based on the checks that is has configured.
128
+ test_files: []
129
+