excellent 1.7.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/MIT-LICENSE +20 -0
- data/README.md +123 -0
- data/bin/excellent +49 -12
- data/lib/simplabs/excellent.rb +2 -2
- data/lib/simplabs/excellent/checks.rb +1 -1
- data/lib/simplabs/excellent/checks/abc_metric_method_check.rb +1 -1
- data/lib/simplabs/excellent/checks/assignment_in_conditional_check.rb +1 -1
- data/lib/simplabs/excellent/checks/base.rb +12 -9
- data/lib/simplabs/excellent/checks/case_missing_else_check.rb +1 -1
- data/lib/simplabs/excellent/checks/class_line_count_check.rb +3 -3
- data/lib/simplabs/excellent/checks/class_name_check.rb +5 -5
- data/lib/simplabs/excellent/checks/{singleton_variable_check.rb → class_variable_check.rb} +3 -3
- data/lib/simplabs/excellent/checks/control_coupling_check.rb +1 -1
- data/lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb +4 -4
- data/lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb +3 -3
- data/lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb +2 -2
- data/lib/simplabs/excellent/checks/empty_rescue_body_check.rb +1 -1
- data/lib/simplabs/excellent/checks/flog_block_check.rb +2 -2
- data/lib/simplabs/excellent/checks/flog_check.rb +3 -3
- data/lib/simplabs/excellent/checks/flog_class_check.rb +2 -2
- data/lib/simplabs/excellent/checks/flog_method_check.rb +2 -2
- data/lib/simplabs/excellent/checks/for_loop_check.rb +1 -1
- data/lib/simplabs/excellent/checks/global_variable_check.rb +5 -2
- data/lib/simplabs/excellent/checks/line_count_check.rb +3 -3
- data/lib/simplabs/excellent/checks/method_line_count_check.rb +2 -2
- data/lib/simplabs/excellent/checks/method_name_check.rb +5 -4
- data/lib/simplabs/excellent/checks/module_line_count_check.rb +2 -2
- data/lib/simplabs/excellent/checks/module_name_check.rb +3 -3
- data/lib/simplabs/excellent/checks/name_check.rb +4 -4
- data/lib/simplabs/excellent/checks/nested_iterators_check.rb +2 -2
- data/lib/simplabs/excellent/checks/parameter_number_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/attr_accessible_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/attr_protected_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/custom_initialize_method_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/instance_var_in_partial_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/params_hash_in_view_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/session_hash_in_view_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/validations_check.rb +1 -1
- data/lib/simplabs/excellent/formatters/text.rb +7 -1
- data/lib/simplabs/excellent/parsing/gvar_context.rb +0 -8
- data/lib/simplabs/excellent/parsing/loc_parser.rb +94 -0
- data/lib/simplabs/excellent/parsing/resbody_context.rb +0 -6
- data/lib/simplabs/excellent/runner.rb +49 -32
- data/lib/simplabs/excellent/warning.rb +1 -4
- metadata +23 -49
- data/README.rdoc +0 -72
- data/VERSION.yml +0 -4
- data/lib/simplabs/excellent/extensions/string.rb +0 -28
- data/spec/checks/abc_metric_method_check_spec.rb +0 -122
- data/spec/checks/assignment_in_conditional_check_spec.rb +0 -90
- data/spec/checks/case_missing_else_check_spec.rb +0 -46
- data/spec/checks/class_line_count_check_spec.rb +0 -62
- data/spec/checks/class_name_check_spec.rb +0 -48
- data/spec/checks/control_coupling_check_spec.rb +0 -103
- data/spec/checks/cyclomatic_complexity_block_check_spec.rb +0 -47
- data/spec/checks/cyclomatic_complexity_method_check_spec.rb +0 -210
- data/spec/checks/empty_rescue_body_check_spec.rb +0 -170
- data/spec/checks/flog_block_check_spec.rb +0 -28
- data/spec/checks/flog_class_check_spec.rb +0 -28
- data/spec/checks/flog_method_check_spec.rb +0 -46
- data/spec/checks/for_loop_check_spec.rb +0 -52
- data/spec/checks/global_variable_check_spec.rb +0 -66
- data/spec/checks/method_line_count_check_spec.rb +0 -49
- data/spec/checks/method_name_check_spec.rb +0 -112
- data/spec/checks/module_line_count_check_spec.rb +0 -48
- data/spec/checks/module_name_check_spec.rb +0 -61
- data/spec/checks/nested_iterators_check_spec.rb +0 -44
- data/spec/checks/parameter_number_check_spec.rb +0 -97
- data/spec/checks/rails/attr_accessible_check_spec.rb +0 -79
- data/spec/checks/rails/attr_protected_check_spec.rb +0 -77
- data/spec/checks/rails/custom_initialize_method_check_spec.rb +0 -58
- data/spec/checks/rails/instance_var_in_partial_check_spec.rb +0 -40
- data/spec/checks/rails/params_hash_in_view_check_spec.rb +0 -40
- data/spec/checks/rails/session_hash_in_view_check_spec.rb +0 -40
- data/spec/checks/rails/validations_check_spec.rb +0 -81
- data/spec/checks/singleton_variable_check_spec.rb +0 -66
- data/spec/extensions/string_spec.rb +0 -13
- data/spec/spec_helper.rb +0 -13
@@ -1,112 +0,0 @@
|
|
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::Runner.new(Simplabs::Excellent::Checks::MethodNameCheck.new)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should accept method names with underscores' do
|
12
|
-
code = <<-END
|
13
|
-
def good_method_name
|
14
|
-
end
|
15
|
-
END
|
16
|
-
@excellent.check_code(code)
|
17
|
-
|
18
|
-
@excellent.warnings.should be_empty
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should accept method names with numbers' do
|
22
|
-
code = <<-END
|
23
|
-
def good_method_name_1
|
24
|
-
end
|
25
|
-
END
|
26
|
-
@excellent.check_code(code)
|
27
|
-
|
28
|
-
@excellent.warnings.should be_empty
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should accept method names ending with a question mark' do
|
32
|
-
code = <<-END
|
33
|
-
def good_method_name?
|
34
|
-
end
|
35
|
-
END
|
36
|
-
@excellent.check_code(code)
|
37
|
-
|
38
|
-
@excellent.warnings.should be_empty
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should accept method names ending with an exclamation mark' do
|
42
|
-
code = <<-END
|
43
|
-
def good_method_name!
|
44
|
-
end
|
45
|
-
END
|
46
|
-
@excellent.check_code(code)
|
47
|
-
|
48
|
-
@excellent.warnings.should be_empty
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should accept method names ending an equals sign' do
|
52
|
-
code = <<-END
|
53
|
-
def good_method_name=
|
54
|
-
end
|
55
|
-
END
|
56
|
-
@excellent.check_code(code)
|
57
|
-
|
58
|
-
@excellent.warnings.should be_empty
|
59
|
-
end
|
60
|
-
|
61
|
-
['<<', '>>', '==', '<', '<=', '>', '>=', '[]', '[]=', '+', '-', '*', '~', '/', '%', '&', '^', '|'].each do |operator|
|
62
|
-
|
63
|
-
it "should accept #{operator} as a method name" do
|
64
|
-
code = <<-END
|
65
|
-
def #{operator}
|
66
|
-
end
|
67
|
-
END
|
68
|
-
@excellent.check_code(code)
|
69
|
-
|
70
|
-
@excellent.warnings.should be_empty
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should reject camel cased method names' do
|
78
|
-
code = <<-END
|
79
|
-
def badMethodName
|
80
|
-
end
|
81
|
-
END
|
82
|
-
@excellent.check_code(code)
|
83
|
-
warnings = @excellent.warnings
|
84
|
-
|
85
|
-
warnings.should_not be_empty
|
86
|
-
warnings[0].info.should == { :method => 'badMethodName' }
|
87
|
-
warnings[0].line_number.should == 1
|
88
|
-
warnings[0].message.should == 'Bad method name badMethodName.'
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should correctly return the method's full name" do
|
92
|
-
code = <<-END
|
93
|
-
class Class
|
94
|
-
def badMethodName
|
95
|
-
end
|
96
|
-
def self.badMethodName2
|
97
|
-
end
|
98
|
-
end
|
99
|
-
END
|
100
|
-
@excellent.check_code(code)
|
101
|
-
warnings = @excellent.warnings
|
102
|
-
|
103
|
-
warnings.should_not be_empty
|
104
|
-
warnings[0].info.should == { :method => 'Class#badMethodName' }
|
105
|
-
warnings[0].line_number.should == 2
|
106
|
-
warnings[0].message.should == 'Bad method name Class#badMethodName.'
|
107
|
-
warnings[1].info.should == { :method => 'Class.badMethodName2' }
|
108
|
-
warnings[1].line_number.should == 4
|
109
|
-
warnings[1].message.should == 'Bad method name Class.badMethodName2.'
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
@@ -1,48 +0,0 @@
|
|
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::Runner.new(Simplabs::Excellent::Checks::ModuleLineCountCheck.new({ :threshold => 2 }))
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should accept modules with less lines than the threshold' do
|
12
|
-
code = <<-END
|
13
|
-
module OneLineModule; end
|
14
|
-
END
|
15
|
-
@excellent.check_code(code)
|
16
|
-
|
17
|
-
@excellent.warnings.should be_empty
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should accept modules with the same number of lines as the threshold' do
|
21
|
-
code = <<-END
|
22
|
-
module TwoLinesModule
|
23
|
-
end
|
24
|
-
END
|
25
|
-
@excellent.check_code(code)
|
26
|
-
|
27
|
-
@excellent.warnings.should be_empty
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should reject modules with more lines than the threshold' do
|
31
|
-
code = <<-END
|
32
|
-
module FourLinesModule
|
33
|
-
@foo = 1
|
34
|
-
@bar = 2
|
35
|
-
end
|
36
|
-
END
|
37
|
-
@excellent.check_code(code)
|
38
|
-
warnings = @excellent.warnings
|
39
|
-
|
40
|
-
warnings.should_not be_empty
|
41
|
-
warnings[0].info.should == { :module => 'FourLinesModule', :count => 4 }
|
42
|
-
warnings[0].line_number.should == 1
|
43
|
-
warnings[0].message.should == 'FourLinesModule has 4 lines.'
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
@@ -1,61 +0,0 @@
|
|
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::Runner.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
|
-
code = <<-END
|
13
|
-
module GoodModuleName
|
14
|
-
end
|
15
|
-
END
|
16
|
-
@excellent.check_code(code)
|
17
|
-
|
18
|
-
@excellent.warnings.should be_empty
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should accept namespaced modules' do
|
22
|
-
code = <<-END
|
23
|
-
module Outer::Inner::GoodModuleName
|
24
|
-
end
|
25
|
-
END
|
26
|
-
@excellent.check_code(code)
|
27
|
-
|
28
|
-
@excellent.warnings.should be_empty
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should reject module names with underscores' do
|
32
|
-
code = <<-END
|
33
|
-
module Bad_ModuleName
|
34
|
-
end
|
35
|
-
END
|
36
|
-
@excellent.check_code(code)
|
37
|
-
warnings = @excellent.warnings
|
38
|
-
|
39
|
-
warnings.should_not be_empty
|
40
|
-
warnings[0].info.should == { :module => 'Bad_ModuleName' }
|
41
|
-
warnings[0].line_number.should == 1
|
42
|
-
warnings[0].message.should == 'Bad module name Bad_ModuleName.'
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should correctly report bad names of namespaced modules' do
|
46
|
-
code = <<-END
|
47
|
-
module Outer::Inner::Bad_ModuleName
|
48
|
-
end
|
49
|
-
END
|
50
|
-
@excellent.check_code(code)
|
51
|
-
warnings = @excellent.warnings
|
52
|
-
|
53
|
-
warnings.should_not be_empty
|
54
|
-
warnings[0].info.should == { :module => 'Outer::Inner::Bad_ModuleName' }
|
55
|
-
warnings[0].line_number.should == 1
|
56
|
-
warnings[0].message.should == 'Bad module name Outer::Inner::Bad_ModuleName.'
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::NestedIteratorsCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::NestedIteratorsCheck.new)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should reject a block inside a block' do
|
12
|
-
code = <<-END
|
13
|
-
method1 do
|
14
|
-
method2 do
|
15
|
-
end
|
16
|
-
end
|
17
|
-
END
|
18
|
-
@excellent.check_code(code)
|
19
|
-
warnings = @excellent.warnings
|
20
|
-
|
21
|
-
warnings.should_not be_empty
|
22
|
-
warnings[0].info.should == { :block => 'block', :parent => 'block' }
|
23
|
-
warnings[0].line_number.should == 2
|
24
|
-
warnings[0].message.should == 'block inside of block.'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should accept 2 blocks inside a method that are not nested' do
|
28
|
-
code = <<-END
|
29
|
-
def method
|
30
|
-
method1 do
|
31
|
-
end
|
32
|
-
method2 do
|
33
|
-
end
|
34
|
-
end
|
35
|
-
END
|
36
|
-
@excellent.check_code(code)
|
37
|
-
warnings = @excellent.warnings
|
38
|
-
|
39
|
-
warnings.should be_empty
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
@@ -1,97 +0,0 @@
|
|
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::Runner.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
|
-
code = <<-END
|
13
|
-
def zero_parameter_method
|
14
|
-
end
|
15
|
-
END
|
16
|
-
@excellent.check_code(code)
|
17
|
-
|
18
|
-
@excellent.warnings.should be_empty
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should accept methods with the same number of parameters as the threshold' do
|
22
|
-
code = <<-END
|
23
|
-
def one_parameter_method(first_parameter)
|
24
|
-
end
|
25
|
-
END
|
26
|
-
@excellent.check_code(code)
|
27
|
-
|
28
|
-
@excellent.warnings.should be_empty
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should reject methods with more parameters than the threshold' do
|
32
|
-
code = <<-END
|
33
|
-
def two_parameter_method(first_parameter, second_parameter)
|
34
|
-
end
|
35
|
-
END
|
36
|
-
|
37
|
-
verify_warning_found(code, 'two_parameter_method')
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should work with default values on parameters' do
|
41
|
-
code = <<-END
|
42
|
-
def two_parameter_method(first_parameter = 1, second_parameter = 2)
|
43
|
-
end
|
44
|
-
END
|
45
|
-
|
46
|
-
verify_warning_found(code, 'two_parameter_method')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should work with methods defined on objects' do
|
50
|
-
code = <<-END
|
51
|
-
def object.two_parameter_method(first_parameter = 1, second_parameter = 2)
|
52
|
-
end
|
53
|
-
END
|
54
|
-
|
55
|
-
verify_warning_found(code, 'object.two_parameter_method')
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should work with methods defined directly on classes' do
|
59
|
-
code = <<-END
|
60
|
-
def Class.two_parameter_method(first_parameter = 1, second_parameter = 2)
|
61
|
-
end
|
62
|
-
END
|
63
|
-
|
64
|
-
verify_warning_found(code, 'Class.two_parameter_method')
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should reject yield calls with more parameters than the threshold' do
|
68
|
-
code = <<-END
|
69
|
-
two_parameter_method do |first_parameter, second_parameter|
|
70
|
-
end
|
71
|
-
END
|
72
|
-
|
73
|
-
verify_warning_found(code, 'block')
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'should reject yield calls on a receiver with more parameters than the threshold' do
|
77
|
-
code = <<-END
|
78
|
-
receiver.two_parameter_method do |first_parameter, second_parameter|
|
79
|
-
end
|
80
|
-
END
|
81
|
-
|
82
|
-
verify_warning_found(code, 'block')
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
def verify_warning_found(code, name)
|
88
|
-
@excellent.check_code(code)
|
89
|
-
warnings = @excellent.warnings
|
90
|
-
|
91
|
-
warnings.should_not be_empty
|
92
|
-
warnings[0].info.should == { :method => name, :parameters => 2 }
|
93
|
-
warnings[0].line_number.should == 1
|
94
|
-
warnings[0].message.should == "#{name} has 2 parameters."
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::Rails::AttrAccessibleCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::Rails::AttrAccessibleCheck.new)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should ignore classes that are not active record models' do
|
12
|
-
code = <<-END
|
13
|
-
class Test
|
14
|
-
end
|
15
|
-
END
|
16
|
-
@excellent.check_code(code)
|
17
|
-
warnings = @excellent.warnings
|
18
|
-
|
19
|
-
warnings.should be_empty
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should reject an active record model that does not specify attr_accessible' do
|
23
|
-
code = <<-END
|
24
|
-
class User < ActiveRecord::Base
|
25
|
-
end
|
26
|
-
END
|
27
|
-
@excellent.check_code(code)
|
28
|
-
warnings = @excellent.warnings
|
29
|
-
|
30
|
-
warnings.should_not be_empty
|
31
|
-
warnings[0].info.should == { :class => 'User' }
|
32
|
-
warnings[0].line_number.should == 1
|
33
|
-
warnings[0].message.should == 'User does not specify attr_accessible.'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should reject an active record model that does specify attr_protected' do
|
37
|
-
code = <<-END
|
38
|
-
class User < ActiveRecord::Base
|
39
|
-
attr_protected :first_name
|
40
|
-
end
|
41
|
-
END
|
42
|
-
@excellent.check_code(code)
|
43
|
-
warnings = @excellent.warnings
|
44
|
-
|
45
|
-
warnings.should_not be_empty
|
46
|
-
warnings[0].info.should == { :class => 'User' }
|
47
|
-
warnings[0].line_number.should == 1
|
48
|
-
warnings[0].message.should == 'User does not specify attr_accessible.'
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should accept an active record model that does specify attr_accessible' do
|
52
|
-
code = <<-END
|
53
|
-
class User < ActiveRecord::Base
|
54
|
-
attr_accessible :first_name
|
55
|
-
end
|
56
|
-
END
|
57
|
-
@excellent.check_code(code)
|
58
|
-
warnings = @excellent.warnings
|
59
|
-
|
60
|
-
warnings.should be_empty
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should also work with namespaced models' do
|
64
|
-
code = <<-END
|
65
|
-
class Backend::User < ActiveRecord::Base
|
66
|
-
end
|
67
|
-
END
|
68
|
-
@excellent.check_code(code)
|
69
|
-
warnings = @excellent.warnings
|
70
|
-
|
71
|
-
warnings.should_not be_empty
|
72
|
-
warnings[0].info.should == { :class => 'Backend::User' }
|
73
|
-
warnings[0].line_number.should == 1
|
74
|
-
warnings[0].message.should == 'Backend::User does not specify attr_accessible.'
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|