simplabs-excellent 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/History.txt +3 -0
  2. data/README.markdown +30 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/excellent +21 -0
  5. data/lib/simplabs/excellent.rb +12 -0
  6. data/lib/simplabs/excellent/checks.rb +16 -0
  7. data/lib/simplabs/excellent/checks/abc_metric_method_check.rb +80 -0
  8. data/lib/simplabs/excellent/checks/assignment_in_conditional_check.rb +38 -0
  9. data/lib/simplabs/excellent/checks/base.rb +42 -0
  10. data/lib/simplabs/excellent/checks/case_missing_else_check.rb +25 -0
  11. data/lib/simplabs/excellent/checks/class_line_count_check.rb +34 -0
  12. data/lib/simplabs/excellent/checks/class_name_check.rb +37 -0
  13. data/lib/simplabs/excellent/checks/class_variable_check.rb +25 -0
  14. data/lib/simplabs/excellent/checks/control_coupling_check.rb +32 -0
  15. data/lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb +32 -0
  16. data/lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb +39 -0
  17. data/lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb +33 -0
  18. data/lib/simplabs/excellent/checks/empty_rescue_body_check.rb +39 -0
  19. data/lib/simplabs/excellent/checks/for_loop_check.rb +25 -0
  20. data/lib/simplabs/excellent/checks/line_count_check.rb +45 -0
  21. data/lib/simplabs/excellent/checks/method_line_count_check.rb +34 -0
  22. data/lib/simplabs/excellent/checks/method_name_check.rb +34 -0
  23. data/lib/simplabs/excellent/checks/module_line_count_check.rb +34 -0
  24. data/lib/simplabs/excellent/checks/module_name_check.rb +34 -0
  25. data/lib/simplabs/excellent/checks/name_check.rb +32 -0
  26. data/lib/simplabs/excellent/checks/parameter_number_check.rb +37 -0
  27. data/lib/simplabs/excellent/core.rb +2 -0
  28. data/lib/simplabs/excellent/core/checking_visitor.rb +34 -0
  29. data/lib/simplabs/excellent/core/error.rb +31 -0
  30. data/lib/simplabs/excellent/core/extensions/underscore.rb +27 -0
  31. data/lib/simplabs/excellent/core/iterator_visitor.rb +29 -0
  32. data/lib/simplabs/excellent/core/parse_tree_runner.rb +88 -0
  33. data/lib/simplabs/excellent/core/parser.rb +33 -0
  34. data/lib/simplabs/excellent/core/visitable_sexp.rb +31 -0
  35. data/spec/checks/abc_metric_method_check_spec.rb +94 -0
  36. data/spec/checks/assignment_in_conditional_check_spec.rb +73 -0
  37. data/spec/checks/case_missing_else_check_spec.rb +42 -0
  38. data/spec/checks/class_line_count_check_spec.rb +49 -0
  39. data/spec/checks/class_name_check_spec.rb +48 -0
  40. data/spec/checks/class_variable_check_spec.rb +26 -0
  41. data/spec/checks/control_coupling_check_spec.rb +32 -0
  42. data/spec/checks/cyclomatic_complexity_block_check_spec.rb +51 -0
  43. data/spec/checks/cyclomatic_complexity_method_check_spec.rb +184 -0
  44. data/spec/checks/empty_rescue_body_check_spec.rb +132 -0
  45. data/spec/checks/for_loop_check_spec.rb +52 -0
  46. data/spec/checks/method_line_count_check_spec.rb +50 -0
  47. data/spec/checks/method_name_check_spec.rb +91 -0
  48. data/spec/checks/module_line_count_check_spec.rb +49 -0
  49. data/spec/checks/module_name_check_spec.rb +37 -0
  50. data/spec/checks/parameter_number_check_spec.rb +61 -0
  51. data/spec/core/extensions/underscore_spec.rb +13 -0
  52. data/spec/spec_helper.rb +11 -0
  53. metadata +115 -0
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Simplabs::Excellent::Checks::ForLoopCheck do
4
+
5
+ before do
6
+ @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::ForLoopCheck.new)
7
+ end
8
+
9
+ describe '#evaluate' do
10
+
11
+ it 'should accept iterators' do
12
+ content = <<-END
13
+ [:sym1, :sym2].each do |sym|
14
+ end
15
+ END
16
+ @excellent.check_content(content)
17
+ errors = @excellent.errors
18
+
19
+ errors.should be_empty
20
+ end
21
+
22
+ it 'should reject for loops on ranges' do
23
+ content = <<-END
24
+ for i in 1..2
25
+ end
26
+ END
27
+
28
+ verify_error_found(content)
29
+ end
30
+
31
+ it 'should reject for loops on enumerations' do
32
+ content = <<-END
33
+ for symbol in [:sym1, :sym2]
34
+ end
35
+ END
36
+
37
+ verify_error_found(content)
38
+ end
39
+
40
+ end
41
+
42
+ def verify_error_found(content)
43
+ @excellent.check_content(content)
44
+ errors = @excellent.errors
45
+
46
+ errors.should_not be_empty
47
+ errors[0].info.should == {}
48
+ errors[0].line_number.should == 1
49
+ errors[0].message.should == 'For loop used.'
50
+ end
51
+
52
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Simplabs::Excellent::Checks::MethodLineCountCheck do
4
+
5
+ before do
6
+ @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::MethodLineCountCheck.new({ :threshold => 1 }))
7
+ end
8
+
9
+ describe '#evaluate' do
10
+
11
+ it 'should accept methods with less lines than the threshold' do
12
+ content = <<-END
13
+ def zero_line_method
14
+ end
15
+ END
16
+ @excellent.check_content(content)
17
+
18
+ @excellent.errors.should be_empty
19
+ end
20
+
21
+ it 'should accept methods with the same number of lines as the threshold' do
22
+ content = <<-END
23
+ def one_line_method
24
+ 1
25
+ end
26
+ END
27
+ @excellent.check_content(content)
28
+
29
+ @excellent.errors.should be_empty
30
+ end
31
+
32
+ it 'should reject methods with more lines than the threshold' do
33
+ content = <<-END
34
+ def two_line_method
35
+ puts 1
36
+ puts 2
37
+ end
38
+ END
39
+ @excellent.check_content(content)
40
+ errors = @excellent.errors
41
+
42
+ errors.should_not be_empty
43
+ errors[0].info.should == { :method => :two_line_method, :count => 2 }
44
+ errors[0].line_number.should == 1
45
+ errors[0].message.should == 'Method two_line_method has 2 lines.'
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,91 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Simplabs::Excellent::Checks::MethodNameCheck do
4
+
5
+ before do
6
+ @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::MethodNameCheck.new)
7
+ end
8
+
9
+ describe '#evaluate' do
10
+
11
+ it 'should accept method names with underscores' do
12
+ content = <<-END
13
+ def good_method_name
14
+ end
15
+ END
16
+ @excellent.check_content(content)
17
+
18
+ @excellent.errors.should be_empty
19
+ end
20
+
21
+ it 'should accept method names with numbers' do
22
+ content = <<-END
23
+ def good_method_name_1
24
+ end
25
+ END
26
+ @excellent.check_content(content)
27
+
28
+ @excellent.errors.should be_empty
29
+ end
30
+
31
+ it 'should accept method names ending with a question mark' do
32
+ content = <<-END
33
+ def good_method_name?
34
+ end
35
+ END
36
+ @excellent.check_content(content)
37
+
38
+ @excellent.errors.should be_empty
39
+ end
40
+
41
+ it 'should accept method names ending with an exclamation mark' do
42
+ content = <<-END
43
+ def good_method_name!
44
+ end
45
+ END
46
+ @excellent.check_content(content)
47
+
48
+ @excellent.errors.should be_empty
49
+ end
50
+
51
+ it 'should accept method names ending an equals sign' do
52
+ content = <<-END
53
+ def good_method_name=
54
+ end
55
+ END
56
+ @excellent.check_content(content)
57
+
58
+ @excellent.errors.should be_empty
59
+ end
60
+
61
+ ['<<', '>>', '==', '=', '<', '<=', '>', '>=', '[]', '[]=', '+', '-', '*', '~', '/', '%', '&', '^' '|'].each do |operator|
62
+
63
+ it "should accept #{operator} as a method name" do
64
+ content = <<-END
65
+ def #{operator}
66
+ end
67
+ END
68
+ @excellent.check_content(content)
69
+
70
+ @excellent.errors.should be_empty
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ it 'should reject camel cased method names' do
78
+ content = <<-END
79
+ def badMethodName
80
+ end
81
+ END
82
+ @excellent.check_content(content)
83
+ errors = @excellent.errors
84
+
85
+ errors.should_not be_empty
86
+ errors[0].info.should == { :method => :badMethodName }
87
+ errors[0].line_number.should == 1
88
+ errors[0].message.should == 'Bad method name badMethodName.'
89
+ end
90
+
91
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Simplabs::Excellent::Checks::ModuleLineCountCheck do
4
+
5
+ before do
6
+ @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::ModuleLineCountCheck.new({ :threshold => 1 }))
7
+ end
8
+
9
+ describe '#evaluate' do
10
+
11
+ it 'should accept modules with less lines than the threshold' do
12
+ content = <<-END
13
+ module ZeroLineModule; end
14
+ END
15
+ @excellent.check_content(content)
16
+
17
+ @excellent.errors.should be_empty
18
+ end
19
+
20
+ it 'should accept modules with the same number of lines as the threshold' do
21
+ content = <<-END
22
+ module OneLineModule
23
+ @foo = 1
24
+ end
25
+ END
26
+ @excellent.check_content(content)
27
+
28
+ @excellent.errors.should be_empty
29
+ end
30
+
31
+ it 'should reject modules with more lines than the threshold' do
32
+ content = <<-END
33
+ module TwoLineModule
34
+ @foo = 1
35
+ @bar = 2
36
+ end
37
+ END
38
+ @excellent.check_content(content)
39
+ errors = @excellent.errors
40
+
41
+ errors.should_not be_empty
42
+ errors[0].info.should == { :module => :TwoLineModule, :count => 2 }
43
+ errors[0].line_number.should == 1
44
+ errors[0].message.should == 'Module TwoLineModule has 2 lines.'
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Simplabs::Excellent::Checks::ModuleNameCheck do
4
+
5
+ before do
6
+ @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::ModuleNameCheck.new)
7
+ end
8
+
9
+ describe '#evaluate' do
10
+
11
+ it 'should accept camel case module names starting in capitals' do
12
+ content = <<-END
13
+ module GoodModuleName
14
+ end
15
+ END
16
+ @excellent.check_content(content)
17
+
18
+ @excellent.errors.should be_empty
19
+ end
20
+
21
+ it 'should reject module names with underscores' do
22
+ content = <<-END
23
+ module Bad_ModuleName
24
+ end
25
+ END
26
+ @excellent.check_content(content)
27
+ errors = @excellent.errors
28
+
29
+ errors.should_not be_empty
30
+ errors[0].info.should == { :module => :Bad_ModuleName }
31
+ errors[0].line_number.should == 1
32
+ errors[0].message.should == 'Bad module name Bad_ModuleName.'
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Simplabs::Excellent::Checks::ParameterNumberCheck do
4
+
5
+ before(:each) do
6
+ @excellent = Simplabs::Excellent::Core::ParseTreeRunner.new(Simplabs::Excellent::Checks::ParameterNumberCheck.new({ :threshold => 1 }))
7
+ end
8
+
9
+ describe '#evaluate' do
10
+
11
+ it 'should accept methods with less parameters than the threshold' do
12
+ content = <<-END
13
+ def zero_parameter_method
14
+ end
15
+ END
16
+ @excellent.check_content(content)
17
+
18
+ @excellent.errors.should be_empty
19
+ end
20
+
21
+ it 'should accept methods with the same number of parameters as the threshold' do
22
+ content = <<-END
23
+ def one_parameter_method(first_parameter)
24
+ end
25
+ END
26
+ @excellent.check_content(content)
27
+
28
+ @excellent.errors.should be_empty
29
+ end
30
+
31
+ it 'should reject methods with more parameters than the threshold' do
32
+ content = <<-END
33
+ def two_parameter_method(first_parameter, second_parameter)
34
+ end
35
+ END
36
+
37
+ verify_error_found(content)
38
+ end
39
+
40
+ it 'should cope with default values on parameters' do
41
+ content = <<-END
42
+ def two_parameter_method(first_parameter = 1, second_parameter = 2)
43
+ end
44
+ END
45
+
46
+ verify_error_found(content)
47
+ end
48
+
49
+ end
50
+
51
+ def verify_error_found(content)
52
+ @excellent.check_content(content)
53
+ errors = @excellent.errors
54
+
55
+ errors.should_not be_empty
56
+ errors[0].info.should == { :method => :two_parameter_method, :parameter_count => 2 }
57
+ errors[0].line_number.should == 1
58
+ errors[0].message.should == 'Method two_parameter_method has 2 parameters.'
59
+ end
60
+
61
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe String do
4
+
5
+ describe '#underscore' do
6
+
7
+ it 'should correctly add underscores to "AbcMetricMethodCheck"' do
8
+ 'AbcMetricMethodCheck'.underscore.should == 'abc_metric_method_check'
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'simplabs/excellent'
3
+ require 'spec'
4
+
5
+ begin
6
+ require 'ruby-debug'
7
+ Debugger.start
8
+ Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
9
+ rescue LoadError
10
+ # ruby-debug wasn't available so neither can the debugging be
11
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplabs-excellent
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Marty Andrews
8
+ - Marco Otte-Witte
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-05-06 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ruby_parser
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "2.0"
25
+ version:
26
+ description:
27
+ email: marco.otte-witte@simplabs.com
28
+ executables:
29
+ - excellent
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - History.txt
36
+ - README.markdown
37
+ - VERSION.yml
38
+ - bin/excellent
39
+ - lib/simplabs/excellent/checks/abc_metric_method_check.rb
40
+ - lib/simplabs/excellent/checks/assignment_in_conditional_check.rb
41
+ - lib/simplabs/excellent/checks/base.rb
42
+ - lib/simplabs/excellent/checks/case_missing_else_check.rb
43
+ - lib/simplabs/excellent/checks/class_line_count_check.rb
44
+ - lib/simplabs/excellent/checks/class_name_check.rb
45
+ - lib/simplabs/excellent/checks/class_variable_check.rb
46
+ - lib/simplabs/excellent/checks/control_coupling_check.rb
47
+ - lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb
48
+ - lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb
49
+ - lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
50
+ - lib/simplabs/excellent/checks/empty_rescue_body_check.rb
51
+ - lib/simplabs/excellent/checks/for_loop_check.rb
52
+ - lib/simplabs/excellent/checks/line_count_check.rb
53
+ - lib/simplabs/excellent/checks/method_line_count_check.rb
54
+ - lib/simplabs/excellent/checks/method_name_check.rb
55
+ - lib/simplabs/excellent/checks/module_line_count_check.rb
56
+ - lib/simplabs/excellent/checks/module_name_check.rb
57
+ - lib/simplabs/excellent/checks/name_check.rb
58
+ - lib/simplabs/excellent/checks/parameter_number_check.rb
59
+ - lib/simplabs/excellent/checks.rb
60
+ - lib/simplabs/excellent/core/checking_visitor.rb
61
+ - lib/simplabs/excellent/core/error.rb
62
+ - lib/simplabs/excellent/core/extensions/underscore.rb
63
+ - lib/simplabs/excellent/core/iterator_visitor.rb
64
+ - lib/simplabs/excellent/core/parse_tree_runner.rb
65
+ - lib/simplabs/excellent/core/parser.rb
66
+ - lib/simplabs/excellent/core/visitable_sexp.rb
67
+ - lib/simplabs/excellent/core.rb
68
+ - lib/simplabs/excellent.rb
69
+ - spec/checks/abc_metric_method_check_spec.rb
70
+ - spec/checks/assignment_in_conditional_check_spec.rb
71
+ - spec/checks/case_missing_else_check_spec.rb
72
+ - spec/checks/class_line_count_check_spec.rb
73
+ - spec/checks/class_name_check_spec.rb
74
+ - spec/checks/class_variable_check_spec.rb
75
+ - spec/checks/control_coupling_check_spec.rb
76
+ - spec/checks/cyclomatic_complexity_block_check_spec.rb
77
+ - spec/checks/cyclomatic_complexity_method_check_spec.rb
78
+ - spec/checks/empty_rescue_body_check_spec.rb
79
+ - spec/checks/for_loop_check_spec.rb
80
+ - spec/checks/method_line_count_check_spec.rb
81
+ - spec/checks/method_name_check_spec.rb
82
+ - spec/checks/module_line_count_check_spec.rb
83
+ - spec/checks/module_name_check_spec.rb
84
+ - spec/checks/parameter_number_check_spec.rb
85
+ - spec/core/extensions/underscore_spec.rb
86
+ - spec/spec_helper.rb
87
+ has_rdoc: true
88
+ homepage: http://github.com/simplabs/excellent
89
+ post_install_message:
90
+ rdoc_options:
91
+ - --inline-source
92
+ - --charset=UTF-8
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ version:
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.2.0
111
+ signing_key:
112
+ specification_version: 2
113
+ summary: Source code analysis gem
114
+ test_files: []
115
+