roodi 0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -15
- data/Manifest.txt +1 -0
- data/README.txt +36 -27
- data/Rakefile +16 -13
- data/lib/roodi.rb +1 -1
- data/lib/roodi/checks/check.rb +4 -9
- data/lib/roodi/checks/class_name_check.rb +1 -1
- data/lib/roodi/checks/cyclomatic_complexity_block_check.rb +2 -2
- data/lib/roodi/checks/cyclomatic_complexity_method_check.rb +1 -1
- data/lib/roodi/checks/empty_rescue_body_check.rb +1 -1
- data/lib/roodi/checks/for_loop_check.rb +1 -1
- data/lib/roodi/checks/method_line_count_check.rb +2 -2
- data/lib/roodi/checks/method_name_check.rb +2 -2
- data/lib/roodi/core/checking_visitor.rb +1 -2
- data/lib/roodi/core/iterator_visitor.rb +1 -0
- data/lib/roodi/core/parse_tree_runner.rb +2 -8
- data/lib/roodi/core/parser.rb +1 -11
- data/lib/roodi/core/visitable_sexp.rb +8 -0
- data/roodi.gemspec +15 -0
- data/roodi.yml +0 -1
- data/spec/checks/class_name_check_spec.rb +1 -1
- data/spec/checks/cyclomatic_complexity_block_check_spec.rb +2 -2
- data/spec/checks/cyclomatic_complexity_method_check_spec.rb +1 -1
- data/spec/checks/empty_rescue_body_check_spec.rb +4 -2
- data/spec/checks/for_loop_check_spec.rb +1 -1
- data/spec/checks/method_line_count_check_spec.rb +6 -3
- data/spec/checks/method_name_check_spec.rb +1 -100
- metadata +4 -23
data/History.txt
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
-
= 0.
|
1
|
+
= 1.0.0
|
2
2
|
|
3
|
-
*
|
4
|
-
* suppressed noisy output from ParseTree using facets API.
|
5
|
-
* updated dependencies and version as a result of facets change.
|
6
|
-
* made Roodi tolerant of being asked to parse files which aren't really Ruby files.
|
7
|
-
* updated the documentation with usage examples.
|
8
|
-
|
9
|
-
= 0.4
|
10
|
-
|
11
|
-
* Added support back in for line numbers in error messages.
|
12
|
-
* Re-enabled MethodLineCountCheck as part of the default check set.
|
13
|
-
|
14
|
-
= 0.3
|
15
|
-
|
16
|
-
* First version of Roodi to be published to Rubyforge.
|
3
|
+
* First release of Roodi.
|
17
4
|
|
18
5
|
= 0.2
|
19
6
|
|
data/Manifest.txt
CHANGED
@@ -21,6 +21,7 @@ lib/roodi/core/iterator_visitor.rb
|
|
21
21
|
lib/roodi/core/parse_tree_runner.rb
|
22
22
|
lib/roodi/core/parser.rb
|
23
23
|
lib/roodi/core/visitable_sexp.rb
|
24
|
+
roodi.gemspec
|
24
25
|
roodi.yml
|
25
26
|
spec/checks/class_name_check_spec.rb
|
26
27
|
spec/checks/cyclomatic_complexity_block_check_spec.rb
|
data/README.txt
CHANGED
@@ -1,36 +1,12 @@
|
|
1
1
|
= roodi
|
2
2
|
|
3
|
-
* http://
|
3
|
+
* http://www.rubyforge.org/
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
7
|
Roodi stands for Ruby Object Oriented Design Inferometer. It parses your Ruby code and warns you about design issues you have based on the checks that is has configured.
|
8
8
|
|
9
|
-
==
|
10
|
-
|
11
|
-
* sudo gem install roodi
|
12
|
-
|
13
|
-
== SYNOPSIS:
|
14
|
-
|
15
|
-
To check one or more files using the default configuration that comes with Roodi, use:
|
16
|
-
roodi [patterns]
|
17
|
-
|
18
|
-
=== EXAMPLE USAGE
|
19
|
-
|
20
|
-
Check all ruby files in a rails app:
|
21
|
-
roodi "rails_app/**/*.rb"
|
22
|
-
|
23
|
-
Check one controller and one model file in a rails app:
|
24
|
-
roodi app/controller/sample_controller.rb app/models/sample.rb
|
25
|
-
|
26
|
-
Check one controller and all model files in a rails app:
|
27
|
-
roodi app/controller/sample_controller.rb "app/models/*.rb"
|
28
|
-
|
29
|
-
|
30
|
-
If you're writing a check, it is useful to see the structure of a file the way that Roodi tokenizes it (via ParesTree). Use:
|
31
|
-
roodi-describe [filename]
|
32
|
-
|
33
|
-
== SUPPORTED CHECKS:
|
9
|
+
== SUPPORTED CHECKS
|
34
10
|
|
35
11
|
* ClassNameCheck - Check that class names match convention.
|
36
12
|
* CyclomaticComplexityBlockCheck - Check that the cyclomatic complexity of all blocks is below the threshold.
|
@@ -38,7 +14,14 @@ If you're writing a check, it is useful to see the structure of a file the way t
|
|
38
14
|
* EmptyRescueBodyCheck - Check that there are no empty rescue blocks.
|
39
15
|
* ForLoopCheck - Check that for loops aren't used (Use Enumerable.each instead)
|
40
16
|
* MethodNameCheck - Check that method names match convention.
|
41
|
-
|
17
|
+
|
18
|
+
== SYNOPSIS:
|
19
|
+
|
20
|
+
* TBD. See the Rakefile in this project for an example of how to get started if you're on the bleeding edge.
|
21
|
+
|
22
|
+
== INSTALL:
|
23
|
+
|
24
|
+
* sudo gem install roodi
|
42
25
|
|
43
26
|
== LICENSE:
|
44
27
|
|
@@ -64,3 +47,29 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
64
47
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
65
48
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
66
49
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
== Introduction
|
54
|
+
|
55
|
+
Roodi is an acronym that stands for Ruby Object Oriented Design Inferometer. It parses your Ruby code and warns you about design issues you have based on the checks that is has configured.
|
56
|
+
|
57
|
+
== Usage
|
58
|
+
|
59
|
+
TBD. See the Rakefile in this project for an example of how to get started if you're on the bleeding edge.
|
60
|
+
|
61
|
+
== Background
|
62
|
+
|
63
|
+
Roodi is almost identical in design to the Java tool called Checkstyle (http://checkstyle.sf.net/), however it is named after the Java tool that I worked on called Joodi (http://joodi.checkstyle.net). I think it's more appropriate to name it similarly to Joodi than Checkstyle, because the checks exist to warn you about design issues, not style issues. Joodi has a different design, but a better name. I used a combination of each.
|
64
|
+
|
65
|
+
== Design
|
66
|
+
|
67
|
+
Roodi builds an Abstract Syntax Tree (AST) of the Ruby source code, then uses the visitor patten to walk every node in the tree and see if the checks can infer any design issues with them. Usually, the existence of an AST would mean running a grammar file through a parser to build it. No such grammar file exists to build a complete representation of the source (including whitespace characters and comments) for the Ruby language, so I originally used the object model built by the JRuby team instead. That design soon switched to use ParseTree instead, which makes Roodi more portable (it doesn't depend on JRuby anymore), but slightly less functional (mainly because ParseTree doesn't support line numbers).
|
68
|
+
|
69
|
+
== Checks currently supported
|
70
|
+
ClassNameCheck Check that class names match convention.
|
71
|
+
CyclomaticComplexityBlockCheck Check that the cyclomatic complexity of all blocks is below the threshold.
|
72
|
+
CyclomaticComplexityMethodCheck Check that the cyclomatic complexity of all methods is below the threshold.
|
73
|
+
EmptyRescueBodyCheck Check that there are no empty rescue blocks.
|
74
|
+
ForLoopCheck Check that for loops aren't used (Use Enumerable.each instead)
|
75
|
+
MethodNameCheck Check that method names match convention.
|
data/Rakefile
CHANGED
@@ -6,19 +6,6 @@ require 'rake'
|
|
6
6
|
require 'spec/rake/spectask'
|
7
7
|
require 'roodi'
|
8
8
|
|
9
|
-
Hoe.new('roodi', Roodi::VERSION) do |p|
|
10
|
-
p.developer('Marty Andrews', 'marty@cogentconsulting.com.au')
|
11
|
-
p.extra_deps = ['ParseTree', 'facets']
|
12
|
-
p.remote_rdoc_dir = ''
|
13
|
-
end
|
14
|
-
|
15
|
-
def roodi(ruby_files)
|
16
|
-
roodi = Roodi::Core::ParseTreeRunner.new
|
17
|
-
ruby_files.each { |file| roodi.check_file(file) }
|
18
|
-
roodi.errors.each {|error| puts error}
|
19
|
-
puts "\nFound #{roodi.errors.size} errors."
|
20
|
-
end
|
21
|
-
|
22
9
|
desc "Run all specs"
|
23
10
|
Spec::Rake::SpecTask.new('spec') do |t|
|
24
11
|
t.spec_files = FileList['spec/**/*spec.rb']
|
@@ -30,3 +17,19 @@ task :roodi do
|
|
30
17
|
roodi(Dir.glob(pattern))
|
31
18
|
end
|
32
19
|
|
20
|
+
task :roodi_runway do
|
21
|
+
pattern = File.join("/Users/marty/Data/runway", "**", "*.rb")
|
22
|
+
roodi(Dir.glob(pattern))
|
23
|
+
end
|
24
|
+
|
25
|
+
def roodi(ruby_files)
|
26
|
+
roodi = Roodi::Core::ParseTreeRunner.new
|
27
|
+
ruby_files.each { |file| roodi.check_file(file) }
|
28
|
+
roodi.errors.each {|error| puts error}
|
29
|
+
puts "\nFound #{roodi.errors.size} errors."
|
30
|
+
end
|
31
|
+
|
32
|
+
Hoe.new('roodi', Roodi::VERSION) do |p|
|
33
|
+
p.developer('Marty Andrews', 'marty@cogentconsulting.com.au')
|
34
|
+
p.remote_rdoc_dir = '' # Release to root
|
35
|
+
end
|
data/lib/roodi.rb
CHANGED
data/lib/roodi/checks/check.rb
CHANGED
@@ -5,17 +5,12 @@ module Roodi
|
|
5
5
|
@errors = []
|
6
6
|
end
|
7
7
|
|
8
|
-
def position(
|
9
|
-
|
8
|
+
def position(node)
|
9
|
+
node.filename
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
@
|
14
|
-
evaluate(node)
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_error(error, offset = 0)
|
18
|
-
@errors << "#{position(offset)} - #{error}"
|
12
|
+
def add_error(error)
|
13
|
+
@errors << error
|
19
14
|
end
|
20
15
|
|
21
16
|
def errors
|
@@ -9,7 +9,7 @@ module Roodi
|
|
9
9
|
|
10
10
|
def evaluate(node)
|
11
11
|
pattern = /^[A-Z][a-zA-Z0-9]*$/
|
12
|
-
add_error "Class name \"#{node[1]}\" should match pattern #{pattern.
|
12
|
+
add_error "#{position(node)} - Class name \"#{node[1]}\" should match pattern #{pattern}." unless node[1].to_s =~ pattern
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -8,12 +8,12 @@ module Roodi
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def interesting_nodes
|
11
|
-
[:
|
11
|
+
[:block]
|
12
12
|
end
|
13
13
|
|
14
14
|
def evaluate(node)
|
15
15
|
complexity = count_complexity(node)
|
16
|
-
add_error "Block cyclomatic complexity is #{complexity}. It should be #{@complexity} or less." unless complexity <= @complexity
|
16
|
+
add_error "#{position(node)} - Block cyclomatic complexity is #{complexity}. It should be #{@complexity} or less." unless complexity <= @complexity
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -13,7 +13,7 @@ module Roodi
|
|
13
13
|
|
14
14
|
def evaluate(node)
|
15
15
|
complexity = count_complexity(node)
|
16
|
-
add_error "Method name \"#{node[1]}\" has a cyclomatic complexity is #{complexity}. It should be #{@complexity} or less." unless complexity <= @complexity
|
16
|
+
add_error "#{position(node)} - Method name \"#{node[1]}\" has a cyclomatic complexity is #{complexity}. It should be #{@complexity} or less." unless complexity <= @complexity
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -14,7 +14,7 @@ module Roodi
|
|
14
14
|
|
15
15
|
def evaluate(node)
|
16
16
|
line_count = count_lines(node)
|
17
|
-
add_error "Method name \"#{node
|
17
|
+
add_error "#{position(node)} - Method name \"#{node.getName}\" has #{line_count} lines. It should have #{@line_count} or less." unless line_count <= @line_count
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
@@ -22,7 +22,7 @@ module Roodi
|
|
22
22
|
def count_lines(node)
|
23
23
|
count = 0
|
24
24
|
count = count + 1 if node.node_type == :newline
|
25
|
-
node.
|
25
|
+
node.childNodes.each {|node| count += count_lines(node)}
|
26
26
|
count
|
27
27
|
end
|
28
28
|
end
|
@@ -8,8 +8,8 @@ module Roodi
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def evaluate(node)
|
11
|
-
pattern = /^[
|
12
|
-
add_error "Method name \"#{node[1]}\" should match pattern #{pattern.
|
11
|
+
pattern = /^[a-z]+[a-z0-9_]*[!\?]?$/
|
12
|
+
add_error "#{position(node)} - Method name \"#{node[1]}\" should match pattern #{pattern}." unless node[1].to_s =~ pattern
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -14,9 +14,8 @@ module Roodi
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def visit(node)
|
17
|
-
@last_newline = node if node.node_type == :newline
|
18
17
|
checks = @checks[node.node_type]
|
19
|
-
checks.each {|check| check.
|
18
|
+
checks.each {|check| check.evaluate(node)} unless checks.nil?
|
20
19
|
nil
|
21
20
|
end
|
22
21
|
end
|
@@ -19,13 +19,8 @@ module Roodi
|
|
19
19
|
|
20
20
|
def check(filename, content)
|
21
21
|
@checks ||= load_checks
|
22
|
-
|
23
|
-
|
24
|
-
node.accept(IteratorVisitor.new(CheckingVisitor.new(@checks)))
|
25
|
-
rescue Exception => e
|
26
|
-
# puts e
|
27
|
-
puts "#{filename} looks like it's not a valid Ruby file. Skipping..."
|
28
|
-
end
|
22
|
+
node = @parser.parse(content, filename)
|
23
|
+
node.accept(IteratorVisitor.new(CheckingVisitor.new(@checks)))
|
29
24
|
end
|
30
25
|
|
31
26
|
def check_content(content)
|
@@ -50,7 +45,6 @@ module Roodi
|
|
50
45
|
end
|
51
46
|
|
52
47
|
def errors
|
53
|
-
@checks ||= []
|
54
48
|
all_errors = @checks.collect {|check| check.errors}
|
55
49
|
all_errors.flatten
|
56
50
|
end
|
data/lib/roodi/core/parser.rb
CHANGED
@@ -1,21 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'parse_tree'
|
3
|
-
require 'facets'
|
4
|
-
|
5
3
|
|
6
4
|
module Roodi
|
7
5
|
module Core
|
8
6
|
class Parser
|
9
7
|
def parse(content, filename)
|
10
|
-
|
11
|
-
return silent_parse(content, filename)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def silent_parse(content, filename)
|
18
|
-
@parser ||= ParseTree.new(true)
|
8
|
+
@parser ||= ParseTree.new
|
19
9
|
node = @parser.parse_tree_for_string(content, filename)
|
20
10
|
sexp = VisitableSexp.from_array node
|
21
11
|
sexp.filename = filename
|
data/roodi.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "roodi"
|
3
|
+
s.version = "0.1.1"
|
4
|
+
s.platform = "jruby"
|
5
|
+
s.summary = "Ruby Object Oriented Design Inferometer"
|
6
|
+
s.email = "marty@martyandrews.net"
|
7
|
+
s.homepage = "https://github.com/martinjandrews/roodi"
|
8
|
+
s.description = "Roodi parses your Ruby code and warns you about design issues you have based on the checks that is has configured."
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.author = "Marty Andrews"
|
11
|
+
s.files = ["CHANGELOG", "LICENSE", "README", "Rakefile", "bin/roodi", "bin/roodi-describe", "lib/roodi", "lib/roodi/checks", "lib/roodi/checks/check.rb", "lib/roodi/checks/class_name_check.rb", "lib/roodi/checks/cyclomatic_complexity_block_check.rb", "lib/roodi/checks/cyclomatic_complexity_check.rb", "lib/roodi/checks/cyclomatic_complexity_method_check.rb", "lib/roodi/checks/empty_rescue_body_check.rb", "lib/roodi/checks/for_loop_check.rb", "lib/roodi/checks/method_line_count_check.rb", "lib/roodi/checks/method_name_check.rb", "lib/roodi/checks.rb", "lib/roodi/core", "lib/roodi/core/checking_visitor.rb", "lib/roodi/core/iterator_visitor.rb", "lib/roodi/core/printing_visitor.rb", "lib/roodi/core/runner.rb", "lib/roodi/core/tree_walker.rb", "lib/roodi/core.rb", "lib/roodi/jruby", "lib/roodi/jruby/ast", "lib/roodi/jruby/ast/node.rb", "lib/roodi/jruby/ast/when_node.rb", "lib/roodi/jruby/ast.rb", "lib/roodi/jruby.rb", "lib/roodi.rb", "lib/tasks", "spec/checks", "spec/checks/class_name_check_spec.rb", "spec/checks/cyclomatic_complexity_block_check_spec.rb", "spec/checks/cyclomatic_complexity_method_check_spec.rb", "spec/checks/empty_rescue_body_check_spec.rb", "spec/checks/for_loop_check_spec.rb", "spec/checks/method_line_count_check_spec.rb", "spec/checks/method_name_check_spec.rb", "spec/spec_helper.rb"]
|
12
|
+
# s.test_files = ["spec/checks", "spec/checks/class_name_check_spec.rb", "spec/checks/cyclomatic_complexity_block_check_spec.rb", "spec/checks/cyclomatic_complexity_method_check_spec.rb", "spec/checks/empty_rescue_body_check_spec.rb", "spec/checks/for_loop_check_spec.rb", "spec/checks/method_line_count_check_spec.rb", "spec/checks/method_name_check_spec.rb", "spec/spec_helper.rb"]
|
13
|
+
s.rdoc_options = ['--quiet', '--title', 'The Roodi Reference', '--main', 'README', '--inline-source']
|
14
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
|
15
|
+
end
|
data/roodi.yml
CHANGED
@@ -22,6 +22,6 @@ describe Roodi::Checks::ClassNameCheck do
|
|
22
22
|
@roodi.check_content(content)
|
23
23
|
errors = @roodi.errors
|
24
24
|
errors.should_not be_empty
|
25
|
-
errors[0].should eql("dummy-file.rb
|
25
|
+
errors[0].should eql("dummy-file.rb - Class name \"Bad_ClassName\" should match pattern (?-mix:^[A-Z][a-zA-Z0-9]*$).")
|
26
26
|
end
|
27
27
|
end
|
@@ -9,13 +9,13 @@ describe Roodi::Checks::CyclomaticComplexityBlockCheck do
|
|
9
9
|
@roodi.check_content(content)
|
10
10
|
errors = @roodi.errors
|
11
11
|
errors.should_not be_empty
|
12
|
-
errors[0].should eql("dummy-file.rb
|
12
|
+
errors[0].should eql("dummy-file.rb - Block cyclomatic complexity is #{complexity}. It should be 0 or less.")
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should find a simple block" do
|
16
16
|
content = <<-END
|
17
17
|
def method_name
|
18
|
-
it "should be a
|
18
|
+
it "should be a complex block" do
|
19
19
|
call_foo
|
20
20
|
end
|
21
21
|
end
|
@@ -9,7 +9,7 @@ describe Roodi::Checks::CyclomaticComplexityMethodCheck do
|
|
9
9
|
@roodi.check_content(content)
|
10
10
|
errors = @roodi.errors
|
11
11
|
errors.should_not be_empty
|
12
|
-
errors[0].should eql("dummy-file.rb
|
12
|
+
errors[0].should eql("dummy-file.rb - Method name \"method_name\" has a cyclomatic complexity is #{complexity}. It should be 0 or less.")
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should find an if block" do
|
@@ -13,6 +13,7 @@ describe Roodi::Checks::EmptyRescueBodyCheck do
|
|
13
13
|
puts "Recover from the call"
|
14
14
|
end
|
15
15
|
END
|
16
|
+
# @roodi.print_content(content)
|
16
17
|
@roodi.check_content(content)
|
17
18
|
@roodi.errors.should be_empty
|
18
19
|
end
|
@@ -36,10 +37,11 @@ describe Roodi::Checks::EmptyRescueBodyCheck do
|
|
36
37
|
rescue
|
37
38
|
end
|
38
39
|
END
|
40
|
+
# @roodi.print_content(content)
|
39
41
|
@roodi.check_content(content)
|
40
42
|
errors = @roodi.errors
|
41
43
|
errors.should_not be_empty
|
42
|
-
errors[0].should eql("dummy-file.rb
|
44
|
+
errors[0].should eql("dummy-file.rb - Rescue block should not be empty.")
|
43
45
|
end
|
44
46
|
|
45
47
|
it "should reject an empty rescue block with a parameter" do
|
@@ -52,6 +54,6 @@ describe Roodi::Checks::EmptyRescueBodyCheck do
|
|
52
54
|
@roodi.check_content(content)
|
53
55
|
errors = @roodi.errors
|
54
56
|
errors.should_not be_empty
|
55
|
-
errors[0].should eql("dummy-file.rb
|
57
|
+
errors[0].should eql("dummy-file.rb - Rescue block should not be empty.")
|
56
58
|
end
|
57
59
|
end
|
@@ -13,6 +13,6 @@ describe Roodi::Checks::ForLoopCheck do
|
|
13
13
|
@roodi.check_content(content)
|
14
14
|
errors = @roodi.errors
|
15
15
|
errors.should_not be_empty
|
16
|
-
errors[0].should eql("dummy-file.rb
|
16
|
+
errors[0].should eql("dummy-file.rb - Don't use 'for' loops. Use Enumerable.each instead.")
|
17
17
|
end
|
18
18
|
end
|
@@ -6,6 +6,7 @@ describe Roodi::Checks::MethodLineCountCheck do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should accept methods with less lines than the threshold" do
|
9
|
+
pending "Support from ParseTree for newlines in methods"
|
9
10
|
content = <<-END
|
10
11
|
def zero_line_method
|
11
12
|
end
|
@@ -15,6 +16,7 @@ describe Roodi::Checks::MethodLineCountCheck do
|
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should accept methods with the same number of lines as the threshold" do
|
19
|
+
pending "Support from ParseTree for newlines in methods"
|
18
20
|
content = <<-END
|
19
21
|
def one_line_method
|
20
22
|
1
|
@@ -25,15 +27,16 @@ describe Roodi::Checks::MethodLineCountCheck do
|
|
25
27
|
end
|
26
28
|
|
27
29
|
it "should reject methods with more lines than the threshold" do
|
30
|
+
pending "Support from ParseTree for newlines in methods"
|
28
31
|
content = <<-END
|
29
32
|
def two_line_method
|
30
|
-
|
31
|
-
|
33
|
+
1
|
34
|
+
2
|
32
35
|
end
|
33
36
|
END
|
34
37
|
@roodi.check_content(content)
|
35
38
|
errors = @roodi.errors
|
36
39
|
errors.should_not be_empty
|
37
|
-
errors[0].should eql("dummy-file.rb
|
40
|
+
errors[0].should eql("dummy-file.rb - Method name \"two_line_method\" has 2 lines. It should have 1 or less.")
|
38
41
|
end
|
39
42
|
end
|
@@ -41,105 +41,6 @@ describe Roodi::Checks::MethodNameCheck do
|
|
41
41
|
@roodi.errors.should be_empty
|
42
42
|
end
|
43
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
|
-
it "should accept << as a method name" do
|
54
|
-
content = <<-END
|
55
|
-
def <<
|
56
|
-
end
|
57
|
-
END
|
58
|
-
@roodi.check_content(content)
|
59
|
-
@roodi.errors.should be_empty
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should accept >> as a method name" do
|
63
|
-
content = <<-END
|
64
|
-
def >>
|
65
|
-
end
|
66
|
-
END
|
67
|
-
@roodi.check_content(content)
|
68
|
-
@roodi.errors.should be_empty
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should accept == as a method name" do
|
72
|
-
content = <<-END
|
73
|
-
def ==
|
74
|
-
end
|
75
|
-
END
|
76
|
-
@roodi.check_content(content)
|
77
|
-
@roodi.errors.should be_empty
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should accept === as a method name" do
|
81
|
-
content = <<-END
|
82
|
-
def ===
|
83
|
-
end
|
84
|
-
END
|
85
|
-
@roodi.check_content(content)
|
86
|
-
@roodi.errors.should be_empty
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should accept < as a method name" do
|
90
|
-
content = <<-END
|
91
|
-
def <
|
92
|
-
end
|
93
|
-
END
|
94
|
-
@roodi.check_content(content)
|
95
|
-
@roodi.errors.should be_empty
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should accept <= as a method name" do
|
99
|
-
content = <<-END
|
100
|
-
def <=
|
101
|
-
end
|
102
|
-
END
|
103
|
-
@roodi.check_content(content)
|
104
|
-
@roodi.errors.should be_empty
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should accept > as a method name" do
|
108
|
-
content = <<-END
|
109
|
-
def >
|
110
|
-
end
|
111
|
-
END
|
112
|
-
@roodi.check_content(content)
|
113
|
-
@roodi.errors.should be_empty
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should accept >= as a method name" do
|
117
|
-
content = <<-END
|
118
|
-
def >=
|
119
|
-
end
|
120
|
-
END
|
121
|
-
@roodi.check_content(content)
|
122
|
-
@roodi.errors.should be_empty
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should accept [] as a method name" do
|
126
|
-
content = <<-END
|
127
|
-
def []
|
128
|
-
end
|
129
|
-
END
|
130
|
-
@roodi.check_content(content)
|
131
|
-
@roodi.errors.should be_empty
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should accept []= as a method name" do
|
135
|
-
content = <<-END
|
136
|
-
def []=
|
137
|
-
end
|
138
|
-
END
|
139
|
-
@roodi.check_content(content)
|
140
|
-
@roodi.errors.should be_empty
|
141
|
-
end
|
142
|
-
|
143
44
|
it "should reject camel case method names" do
|
144
45
|
content = <<-END
|
145
46
|
def badMethodName
|
@@ -148,6 +49,6 @@ describe Roodi::Checks::MethodNameCheck do
|
|
148
49
|
@roodi.check_content(content)
|
149
50
|
errors = @roodi.errors
|
150
51
|
errors.should_not be_empty
|
151
|
-
errors[0].should eql("dummy-file.rb
|
52
|
+
errors[0].should eql("dummy-file.rb - Method name \"badMethodName\" should match pattern (?-mix:^[a-z]+[a-z0-9_]*[!\\?]?$).")
|
152
53
|
end
|
153
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roodi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marty Andrews
|
@@ -9,29 +9,9 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-08 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: ParseTree
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: facets
|
27
|
-
type: :runtime
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "0"
|
34
|
-
version:
|
35
15
|
- !ruby/object:Gem::Dependency
|
36
16
|
name: hoe
|
37
17
|
type: :development
|
@@ -78,6 +58,7 @@ files:
|
|
78
58
|
- lib/roodi/core/parse_tree_runner.rb
|
79
59
|
- lib/roodi/core/parser.rb
|
80
60
|
- lib/roodi/core/visitable_sexp.rb
|
61
|
+
- roodi.gemspec
|
81
62
|
- roodi.yml
|
82
63
|
- spec/checks/class_name_check_spec.rb
|
83
64
|
- spec/checks/cyclomatic_complexity_block_check_spec.rb
|
@@ -88,7 +69,7 @@ files:
|
|
88
69
|
- spec/checks/method_name_check_spec.rb
|
89
70
|
- spec/spec_helper.rb
|
90
71
|
has_rdoc: true
|
91
|
-
homepage: http://
|
72
|
+
homepage: http://www.rubyforge.org/
|
92
73
|
post_install_message:
|
93
74
|
rdoc_options:
|
94
75
|
- --main
|