excellent 1.7.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,77 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::Rails::AttrProtectedCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::Rails::AttrProtectedCheck.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 specify attr_protected' do
|
23
|
-
code = <<-END
|
24
|
-
class User < ActiveRecord::Base
|
25
|
-
attr_protected :first_name
|
26
|
-
end
|
27
|
-
END
|
28
|
-
@excellent.check_code(code)
|
29
|
-
warnings = @excellent.warnings
|
30
|
-
|
31
|
-
warnings.should_not be_empty
|
32
|
-
warnings[0].info.should == { :class => 'User' }
|
33
|
-
warnings[0].line_number.should == 1
|
34
|
-
warnings[0].message.should == 'User specifies attr_protected.'
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should accept an active record model that does specify attr_accessible' do
|
38
|
-
code = <<-END
|
39
|
-
class User < ActiveRecord::Base
|
40
|
-
attr_accessible :first_name
|
41
|
-
end
|
42
|
-
END
|
43
|
-
@excellent.check_code(code)
|
44
|
-
warnings = @excellent.warnings
|
45
|
-
|
46
|
-
warnings.should be_empty
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should accept an active record model that specifies neither attr_accessible not attr_protected' do
|
50
|
-
code = <<-END
|
51
|
-
class User < ActiveRecord::Base
|
52
|
-
end
|
53
|
-
END
|
54
|
-
@excellent.check_code(code)
|
55
|
-
warnings = @excellent.warnings
|
56
|
-
|
57
|
-
warnings.should be_empty
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should also work with namespaced models' do
|
61
|
-
code = <<-END
|
62
|
-
class Backend::User < ActiveRecord::Base
|
63
|
-
attr_protected :first_name
|
64
|
-
end
|
65
|
-
END
|
66
|
-
@excellent.check_code(code)
|
67
|
-
warnings = @excellent.warnings
|
68
|
-
|
69
|
-
warnings.should_not be_empty
|
70
|
-
warnings[0].info.should == { :class => 'Backend::User' }
|
71
|
-
warnings[0].line_number.should == 1
|
72
|
-
warnings[0].message.should == 'Backend::User specifies attr_protected.'
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::Rails::CustomInitializeMethodCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::Rails::CustomInitializeMethodCheck.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
|
-
def initialize
|
15
|
-
end
|
16
|
-
end
|
17
|
-
END
|
18
|
-
@excellent.check_code(code)
|
19
|
-
warnings = @excellent.warnings
|
20
|
-
|
21
|
-
warnings.should be_empty
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should reject an active record model that defines initialize' do
|
25
|
-
code = <<-END
|
26
|
-
class User < ActiveRecord::Base
|
27
|
-
def initialize
|
28
|
-
end
|
29
|
-
end
|
30
|
-
END
|
31
|
-
@excellent.check_code(code)
|
32
|
-
warnings = @excellent.warnings
|
33
|
-
|
34
|
-
warnings.should_not be_empty
|
35
|
-
warnings[0].info.should == { :class => 'User' }
|
36
|
-
warnings[0].line_number.should == 1
|
37
|
-
warnings[0].message.should == 'User defines initialize method.'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should also work with namespaced models' do
|
41
|
-
code = <<-END
|
42
|
-
class Backend::User < ActiveRecord::Base
|
43
|
-
def initialize
|
44
|
-
end
|
45
|
-
end
|
46
|
-
END
|
47
|
-
@excellent.check_code(code)
|
48
|
-
warnings = @excellent.warnings
|
49
|
-
|
50
|
-
warnings.should_not be_empty
|
51
|
-
warnings[0].info.should == { :class => 'Backend::User' }
|
52
|
-
warnings[0].line_number.should == 1
|
53
|
-
warnings[0].message.should == 'Backend::User defines initialize method.'
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::Rails::InstanceVarInPartialCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::Rails::InstanceVarInPartialCheck.new)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should accept partials that do not use instance variables' do
|
12
|
-
code = <<-END
|
13
|
-
<div>
|
14
|
-
<%= 'some text' %>
|
15
|
-
</div>
|
16
|
-
END
|
17
|
-
@excellent.check('_dummy-file.html.erb', code)
|
18
|
-
warnings = @excellent.warnings
|
19
|
-
|
20
|
-
warnings.should be_empty
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should reject partials that use instance variables' do
|
24
|
-
code = <<-END
|
25
|
-
<div>
|
26
|
-
<%= @ivar %>
|
27
|
-
</div>
|
28
|
-
END
|
29
|
-
@excellent.check('_dummy-file.html.erb', code)
|
30
|
-
warnings = @excellent.warnings
|
31
|
-
|
32
|
-
warnings.should_not be_empty
|
33
|
-
warnings[0].info.should == { :variable => 'ivar' }
|
34
|
-
warnings[0].line_number.should == 2
|
35
|
-
warnings[0].message.should == 'Instance variable ivar used in partial.'
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::Rails::ParamsHashInViewCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::Rails::ParamsHashInViewCheck.new)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should accept views that do not use the params hash' do
|
12
|
-
code = <<-END
|
13
|
-
<div>
|
14
|
-
<%= 'some text' %>
|
15
|
-
</div>
|
16
|
-
END
|
17
|
-
@excellent.check('dummy-file.html.erb', code)
|
18
|
-
warnings = @excellent.warnings
|
19
|
-
|
20
|
-
warnings.should be_empty
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should reject views that use the params hash' do
|
24
|
-
code = <<-END
|
25
|
-
<div>
|
26
|
-
<%= params[:q] %>
|
27
|
-
</div>
|
28
|
-
END
|
29
|
-
@excellent.check('dummy-file.html.erb', code)
|
30
|
-
warnings = @excellent.warnings
|
31
|
-
|
32
|
-
warnings.should_not be_empty
|
33
|
-
warnings[0].info.should == {}
|
34
|
-
warnings[0].line_number.should == 2
|
35
|
-
warnings[0].message.should == 'Params hash used in view.'
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::Rails::SessionHashInViewCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::Rails::SessionHashInViewCheck.new)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should accept views that do not use the session hash' do
|
12
|
-
code = <<-END
|
13
|
-
<div>
|
14
|
-
<%= 'some text' %>
|
15
|
-
</div>
|
16
|
-
END
|
17
|
-
@excellent.check('dummy-file.html.erb', code)
|
18
|
-
warnings = @excellent.warnings
|
19
|
-
|
20
|
-
warnings.should be_empty
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should reject views that use the session hash' do
|
24
|
-
code = <<-END
|
25
|
-
<div>
|
26
|
-
<%= session[:someCount] %>
|
27
|
-
</div>
|
28
|
-
END
|
29
|
-
@excellent.check('dummy-file.html.erb', code)
|
30
|
-
warnings = @excellent.warnings
|
31
|
-
|
32
|
-
warnings.should_not be_empty
|
33
|
-
warnings[0].info.should == {}
|
34
|
-
warnings[0].line_number.should == 2
|
35
|
-
warnings[0].message.should == 'Session hash used in view.'
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::Rails::ValidationsCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::Rails::ValidationsCheck.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 validate anything' 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 validate any attributes.'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should accept an active record model that validates attributes using a macro method' do
|
37
|
-
code = <<-END
|
38
|
-
class User < ActiveRecord::Base
|
39
|
-
validates_presence_of :login
|
40
|
-
end
|
41
|
-
END
|
42
|
-
@excellent.check_code(code)
|
43
|
-
warnings = @excellent.warnings
|
44
|
-
|
45
|
-
warnings.should be_empty
|
46
|
-
end
|
47
|
-
|
48
|
-
%w(validate validate_on_create validate_on_update).each do |method|
|
49
|
-
|
50
|
-
it "should accept an active record model that validates attribute by overriding #{method}" do
|
51
|
-
code = <<-END
|
52
|
-
class User < ActiveRecord::Base
|
53
|
-
def #{method}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
END
|
57
|
-
@excellent.check_code(code)
|
58
|
-
warnings = @excellent.warnings
|
59
|
-
|
60
|
-
warnings.should be_empty
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should also work with namespaced models' do
|
66
|
-
code = <<-END
|
67
|
-
class Backend::User < ActiveRecord::Base
|
68
|
-
end
|
69
|
-
END
|
70
|
-
@excellent.check_code(code)
|
71
|
-
warnings = @excellent.warnings
|
72
|
-
|
73
|
-
warnings.should_not be_empty
|
74
|
-
warnings[0].info.should == { :class => 'Backend::User' }
|
75
|
-
warnings[0].line_number.should == 1
|
76
|
-
warnings[0].message.should == 'Backend::User does not validate any attributes.'
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::SingletonVariableCheck do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::SingletonVariableCheck.new)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should reject singleton variables' do
|
12
|
-
code = <<-END
|
13
|
-
@@foo
|
14
|
-
END
|
15
|
-
@excellent.check_code(code)
|
16
|
-
warnings = @excellent.warnings
|
17
|
-
|
18
|
-
warnings.should_not be_empty
|
19
|
-
warnings[0].info.should == { :variable => 'foo' }
|
20
|
-
warnings[0].line_number.should == 1
|
21
|
-
warnings[0].message.should == 'Singleton variable foo used.'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should also work for namespaced classes' do
|
25
|
-
code = <<-END
|
26
|
-
module Outer
|
27
|
-
module Inner
|
28
|
-
class Class
|
29
|
-
@@foo
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
END
|
34
|
-
@excellent.check_code(code)
|
35
|
-
warnings = @excellent.warnings
|
36
|
-
|
37
|
-
warnings.should_not be_empty
|
38
|
-
warnings[0].info.should == { :variable => 'Outer::Inner::Class.foo' }
|
39
|
-
warnings[0].line_number.should == 4
|
40
|
-
warnings[0].message.should == 'Singleton variable Outer::Inner::Class.foo used.'
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should also work for singleton variables that occur within methods' do
|
44
|
-
code = <<-END
|
45
|
-
module Outer
|
46
|
-
module Inner
|
47
|
-
class Class
|
48
|
-
def method
|
49
|
-
@@foo
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
END
|
55
|
-
@excellent.check_code(code)
|
56
|
-
warnings = @excellent.warnings
|
57
|
-
|
58
|
-
warnings.should_not be_empty
|
59
|
-
warnings[0].info.should == { :variable => 'Outer::Inner::Class.foo' }
|
60
|
-
warnings[0].line_number.should == 5
|
61
|
-
warnings[0].message.should == 'Singleton variable Outer::Inner::Class.foo used.'
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
@@ -1,13 +0,0 @@
|
|
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
|
data/spec/spec_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'spec'
|
5
|
-
require 'simplabs/excellent'
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'ruby-debug'
|
9
|
-
Debugger.start
|
10
|
-
Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
|
11
|
-
rescue LoadError
|
12
|
-
# ruby-debug wasn't available so neither can the debugging be
|
13
|
-
end
|