guideline 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/guideline/checkers/abc_complexity_checker.rb +21 -18
- data/lib/guideline/checkers/hash_comma_checker.rb +5 -0
- data/lib/guideline/version.rb +1 -1
- data/lib/guideline/visitor.rb +8 -2
- data/spec/guideline/checkers/abc_complexity_checker_spec.rb +13 -0
- data/spec/guideline/visitor_spec.rb +0 -11
- metadata +16 -45
@@ -12,18 +12,22 @@ module Guideline
|
|
12
12
|
|
13
13
|
def checker
|
14
14
|
AbcParser.new do |complexity, method, module_name, class_method_flag|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
begin
|
16
|
+
if complexity > max
|
17
|
+
report(
|
18
|
+
:path => @current_path,
|
19
|
+
:line => method.line,
|
20
|
+
:message => "ABC Complexity of method<%s%s%s>%3d should be less than %d" % [
|
21
|
+
module_name,
|
22
|
+
class_method_flag ? "." : "#",
|
23
|
+
method.method_name,
|
24
|
+
complexity,
|
25
|
+
max,
|
26
|
+
]
|
27
|
+
)
|
28
|
+
end
|
29
|
+
rescue Exception
|
30
|
+
require "pry"; binding.pry
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -69,23 +73,21 @@ module Guideline
|
|
69
73
|
end
|
70
74
|
|
71
75
|
add_callback :start_def do |node|
|
72
|
-
@current_method
|
76
|
+
@current_method << node
|
73
77
|
clear
|
74
78
|
end
|
75
79
|
|
76
80
|
add_callback :start_defs do |node|
|
77
|
-
@current_method
|
81
|
+
@current_method << node
|
78
82
|
clear
|
79
83
|
end
|
80
84
|
|
81
85
|
add_callback :end_def do |node|
|
82
|
-
@callback.call(complexity, @current_method, current_module_name, false)
|
83
|
-
@current_method = nil
|
86
|
+
@callback.call(complexity, @current_method.pop, current_module_name, false)
|
84
87
|
end
|
85
88
|
|
86
89
|
add_callback :end_defs do |node|
|
87
|
-
@callback.call(complexity, @current_method, current_module_name, true)
|
88
|
-
@current_method = nil
|
90
|
+
@callback.call(complexity, @current_method.pop, current_module_name, true)
|
89
91
|
end
|
90
92
|
|
91
93
|
add_callback :start_binary do |node|
|
@@ -95,6 +97,7 @@ module Guideline
|
|
95
97
|
def initialize(*, &callback)
|
96
98
|
clear
|
97
99
|
@callback = callback
|
100
|
+
@current_method = []
|
98
101
|
super
|
99
102
|
end
|
100
103
|
|
data/lib/guideline/version.rb
CHANGED
data/lib/guideline/visitor.rb
CHANGED
@@ -77,11 +77,17 @@ module Guideline
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def only_pattern
|
80
|
-
options[:only]
|
80
|
+
if options[:only]
|
81
|
+
File.expand_path(options[:only])
|
82
|
+
else
|
83
|
+
File.expand_path("**/*.rb")
|
84
|
+
end
|
81
85
|
end
|
82
86
|
|
83
87
|
def except_pattern
|
84
|
-
options[:except]
|
88
|
+
if options[:except]
|
89
|
+
File.expand_path(options[:except])
|
90
|
+
end
|
85
91
|
end
|
86
92
|
end
|
87
93
|
end
|
@@ -220,6 +220,19 @@ module Guideline
|
|
220
220
|
subject
|
221
221
|
end
|
222
222
|
end
|
223
|
+
|
224
|
+
context "when there is nested method" do
|
225
|
+
let(:script) do
|
226
|
+
<<-'EOF'
|
227
|
+
def a
|
228
|
+
def b
|
229
|
+
c
|
230
|
+
end
|
231
|
+
end
|
232
|
+
EOF
|
233
|
+
end
|
234
|
+
it { should_not have_error }
|
235
|
+
end
|
223
236
|
end
|
224
237
|
end
|
225
238
|
end
|
@@ -19,17 +19,6 @@ module Guideline
|
|
19
19
|
Pathname.new("spec/guideline/visitor_spec.rb")
|
20
20
|
end
|
21
21
|
|
22
|
-
context "when :only option is not specified" do
|
23
|
-
it "visits all paths" do
|
24
|
-
called = false
|
25
|
-
checker.should_receive(:check).at_least(1) do |args|
|
26
|
-
called = true if args == path
|
27
|
-
end
|
28
|
-
visitor.visit
|
29
|
-
called.should be_true
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
22
|
context "when :only option is specified" do
|
34
23
|
before do
|
35
24
|
options[:only] = "lib/**/*.rb"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guideline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: slop
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70221529066600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
24
|
+
version_requirements: *70221529066600
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: code_analyzer
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70221529082560 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,15 +32,10 @@ dependencies:
|
|
37
32
|
version: '0'
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
35
|
+
version_requirements: *70221529082560
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: activesupport
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70221529082140 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ! '>='
|
@@ -53,15 +43,10 @@ dependencies:
|
|
53
43
|
version: '0'
|
54
44
|
type: :runtime
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
46
|
+
version_requirements: *70221529082140
|
62
47
|
- !ruby/object:Gem::Dependency
|
63
48
|
name: rspec
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &70221529081640 !ruby/object:Gem::Requirement
|
65
50
|
none: false
|
66
51
|
requirements:
|
67
52
|
- - ! '>='
|
@@ -69,15 +54,10 @@ dependencies:
|
|
69
54
|
version: 2.12.0
|
70
55
|
type: :development
|
71
56
|
prerelease: false
|
72
|
-
version_requirements:
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 2.12.0
|
57
|
+
version_requirements: *70221529081640
|
78
58
|
- !ruby/object:Gem::Dependency
|
79
59
|
name: pry
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirement: &70221529081220 !ruby/object:Gem::Requirement
|
81
61
|
none: false
|
82
62
|
requirements:
|
83
63
|
- - ! '>='
|
@@ -85,15 +65,10 @@ dependencies:
|
|
85
65
|
version: '0'
|
86
66
|
type: :development
|
87
67
|
prerelease: false
|
88
|
-
version_requirements:
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
68
|
+
version_requirements: *70221529081220
|
94
69
|
- !ruby/object:Gem::Dependency
|
95
70
|
name: simplecov
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirement: &70221529080760 !ruby/object:Gem::Requirement
|
97
72
|
none: false
|
98
73
|
requirements:
|
99
74
|
- - ! '>='
|
@@ -101,12 +76,7 @@ dependencies:
|
|
101
76
|
version: '0'
|
102
77
|
type: :development
|
103
78
|
prerelease: false
|
104
|
-
version_requirements:
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
79
|
+
version_requirements: *70221529080760
|
110
80
|
description: Guideline.gem checks that your code is protectingthe rule of coding guideline
|
111
81
|
email:
|
112
82
|
- r7kamura@gmail.com
|
@@ -171,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
141
|
version: '0'
|
172
142
|
requirements: []
|
173
143
|
rubyforge_project:
|
174
|
-
rubygems_version: 1.8.
|
144
|
+
rubygems_version: 1.8.15
|
175
145
|
signing_key:
|
176
146
|
specification_version: 3
|
177
147
|
summary: The guideline of your code
|
@@ -189,3 +159,4 @@ test_files:
|
|
189
159
|
- spec/guideline/runner_spec.rb
|
190
160
|
- spec/guideline/visitor_spec.rb
|
191
161
|
- spec/spec_helper.rb
|
162
|
+
has_rdoc:
|