cane 2.6.0 → 2.6.1
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.
- checksums.yaml +7 -0
- data/HISTORY.md +6 -0
- data/README.md +41 -35
- data/cane.gemspec +1 -0
- data/lib/cane/doc_check.rb +28 -11
- data/lib/cane/json_formatter.rb +1 -1
- data/lib/cane/version.rb +1 -1
- data/spec/doc_check_spec.rb +27 -4
- data/spec/spec_helper.rb +3 -1
- metadata +18 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1eef945328c09e0abccd91652842a632f639eac0
|
4
|
+
data.tar.gz: 5c154f5d285bea2fd7d5d0549436a16ace066ca8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a4d12974def26b1bfb704167090c2c56a50d5fb134b598821a532fadfb4f75cbce155d017734a2720d06ce851be65bf4a413886ca403a5dde3a2365b3f1fe5bc
|
7
|
+
data.tar.gz: e5a7b0b163105d6eab4e2e92522693552d034503f12e10de7e45268ae80a330ba203e8c77bdb305bfc8fc519a4f29ef71f9f5ee870e974f8c08dc3c7559883a9
|
data/HISTORY.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Cane History
|
2
2
|
|
3
|
+
## 2.6.1 - 30 October 2013 (2ea008)
|
4
|
+
|
5
|
+
* Feature: Don't require doc for one-line class w/out method.
|
6
|
+
* Bugfix: JsonFormatter initializer needs to take an options hash.
|
7
|
+
* Doc: Add license definition to gemspec.
|
8
|
+
|
3
9
|
## 2.6.0 - 7 June 2013 (616bb8a5)
|
4
10
|
|
5
11
|
* Feature: classes with no methods do not require documentation.
|
data/README.md
CHANGED
@@ -79,21 +79,23 @@ Command-line arguments will override arguments specified in the `.cane` file.
|
|
79
79
|
|
80
80
|
## Integrating with Rake
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
82
|
+
```ruby
|
83
|
+
begin
|
84
|
+
require 'cane/rake_task'
|
85
|
+
|
86
|
+
desc "Run cane to check quality metrics"
|
87
|
+
Cane::RakeTask.new(:quality) do |cane|
|
88
|
+
cane.abc_max = 10
|
89
|
+
cane.add_threshold 'coverage/covered_percent', :>=, 99
|
90
|
+
cane.no_style = true
|
91
|
+
cane.abc_exclude = %w(Foo::Bar#some_method)
|
92
|
+
end
|
93
|
+
|
94
|
+
task :default => :quality
|
95
|
+
rescue LoadError
|
96
|
+
warn "cane not available, quality task not provided."
|
97
|
+
end
|
98
|
+
```
|
97
99
|
|
98
100
|
Loading options from a `.cane` file is supported by setting `canefile=` to the
|
99
101
|
file name.
|
@@ -137,22 +139,24 @@ Checks must implement:
|
|
137
139
|
|
138
140
|
See existing checks for guidance. Create your check in a new file:
|
139
141
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
142
|
+
```ruby
|
143
|
+
# unhappy.rb
|
144
|
+
class UnhappyCheck < Struct.new(:opts)
|
145
|
+
def self.options
|
146
|
+
{
|
147
|
+
unhappy_file: ["File to check", default: [nil]]
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
151
|
+
def violations
|
152
|
+
[
|
153
|
+
description: "Files are unhappy",
|
154
|
+
file: opts.fetch(:unhappy_file),
|
155
|
+
label: ":("
|
156
|
+
]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
```
|
156
160
|
|
157
161
|
Include your check either using command-line options:
|
158
162
|
|
@@ -160,11 +164,13 @@ Include your check either using command-line options:
|
|
160
164
|
|
161
165
|
Or in your rake task:
|
162
166
|
|
163
|
-
|
167
|
+
```ruby
|
168
|
+
require 'unhappy'
|
164
169
|
|
165
|
-
|
166
|
-
|
167
|
-
|
170
|
+
Cane::RakeTask.new(:quality) do |c|
|
171
|
+
c.use UnhappyCheck, unhappy_file: 'myfile'
|
172
|
+
end
|
173
|
+
```
|
168
174
|
|
169
175
|
## Protips
|
170
176
|
|
data/cane.gemspec
CHANGED
data/lib/cane/doc_check.rb
CHANGED
@@ -43,6 +43,10 @@ module Cane
|
|
43
43
|
|
44
44
|
CLASS_REGEX = /^\s*(?:class|module)\s+([^\s;]+)/
|
45
45
|
|
46
|
+
# http://rubular.com/r/53BapkefdD
|
47
|
+
SINGLE_LINE_CLASS_REGEX =
|
48
|
+
/^\s*(?:class|module).*;\s*end\s*(#.*)?\s*$/
|
49
|
+
|
46
50
|
METHOD_REGEX = /(?:^|\s)def\s+/
|
47
51
|
|
48
52
|
def violations
|
@@ -67,26 +71,35 @@ module Cane
|
|
67
71
|
end
|
68
72
|
|
69
73
|
def class_definitions_in(file_name)
|
70
|
-
|
74
|
+
closed_classes = []
|
75
|
+
open_classes = []
|
71
76
|
last_line = ""
|
72
77
|
|
73
78
|
Cane::File.iterator(file_name).each_with_index do |line, number|
|
74
79
|
if class_definition? line
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
class_definitions.last.requires_doc = true
|
80
|
+
if single_line_class_definition? line
|
81
|
+
closed_classes
|
82
|
+
else
|
83
|
+
open_classes
|
84
|
+
end.push class_definition(number, line, last_line)
|
85
|
+
|
86
|
+
elsif method_definition?(line) && !open_classes.empty?
|
87
|
+
open_classes.last.requires_doc = true
|
84
88
|
end
|
85
89
|
|
86
90
|
last_line = line
|
87
91
|
end
|
88
92
|
|
89
|
-
|
93
|
+
(closed_classes + open_classes).sort_by(&:line)
|
94
|
+
end
|
95
|
+
|
96
|
+
def class_definition(number, line, last_line)
|
97
|
+
ClassDefinition.new({
|
98
|
+
line: (number + 1),
|
99
|
+
label: extract_class_name(line),
|
100
|
+
has_doc: comment?(last_line),
|
101
|
+
requires_doc: method_definition?(line)
|
102
|
+
})
|
90
103
|
end
|
91
104
|
|
92
105
|
def missing_file_violations
|
@@ -112,6 +125,10 @@ module Cane
|
|
112
125
|
line =~ CLASS_REGEX && $1.index('<<') != 0
|
113
126
|
end
|
114
127
|
|
128
|
+
def single_line_class_definition?(line)
|
129
|
+
line =~ SINGLE_LINE_CLASS_REGEX
|
130
|
+
end
|
131
|
+
|
115
132
|
def comment?(line)
|
116
133
|
line =~ /^\s*#/ && !(MAGIC_COMMENT_REGEX =~ line)
|
117
134
|
end
|
data/lib/cane/json_formatter.rb
CHANGED
data/lib/cane/version.rb
CHANGED
data/spec/doc_check_spec.rb
CHANGED
@@ -9,7 +9,6 @@ describe Cane::DocCheck do
|
|
9
9
|
|
10
10
|
it 'creates a DocViolation for each undocumented class with a method' do
|
11
11
|
file_name = make_file <<-RUBY
|
12
|
-
# This class is documented
|
13
12
|
class Doc; end
|
14
13
|
class Empty; end # No doc is fine
|
15
14
|
class NoDoc; def with_method; end; end
|
@@ -43,15 +42,39 @@ end
|
|
43
42
|
violations.length.should == 3
|
44
43
|
|
45
44
|
violations[0].values_at(:file, :line, :label).should == [
|
46
|
-
file_name,
|
45
|
+
file_name, 3, "NoDoc"
|
47
46
|
]
|
48
47
|
|
49
48
|
violations[1].values_at(:file, :line, :label).should == [
|
50
|
-
file_name,
|
49
|
+
file_name, 15, "AlsoNeedsDoc"
|
51
50
|
]
|
52
51
|
|
53
52
|
violations[2].values_at(:file, :line, :label).should == [
|
54
|
-
file_name,
|
53
|
+
file_name, 17, "ButThisNeedsDoc"
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'does not create violations for single line classes without methods' do
|
58
|
+
file_name = make_file <<-RUBY
|
59
|
+
class NeedsDoc
|
60
|
+
class AlsoNeedsDoc < StandardError; def foo; end; end
|
61
|
+
class NoDocIsOk < StandardError; end
|
62
|
+
class NoDocIsAlsoOk < StandardError; end # No doc is fine on this too
|
63
|
+
|
64
|
+
def my_method
|
65
|
+
end
|
66
|
+
end
|
67
|
+
RUBY
|
68
|
+
|
69
|
+
violations = check(file_name).violations
|
70
|
+
violations.length.should == 2
|
71
|
+
|
72
|
+
violations[0].values_at(:file, :line, :label).should == [
|
73
|
+
file_name, 1, "NeedsDoc"
|
74
|
+
]
|
75
|
+
|
76
|
+
violations[1].values_at(:file, :line, :label).should == [
|
77
|
+
file_name, 2, "AlsoNeedsDoc"
|
55
78
|
]
|
56
79
|
end
|
57
80
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
5
|
-
prerelease:
|
4
|
+
version: 2.6.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Xavier Shay
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: parallel
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,49 +41,43 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: simplecov
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rspec-fire
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: Fails your build if code quality thresholds are not met
|
@@ -136,28 +125,28 @@ files:
|
|
136
125
|
- cane.gemspec
|
137
126
|
- bin/cane
|
138
127
|
homepage: http://github.com/square/cane
|
139
|
-
licenses:
|
128
|
+
licenses:
|
129
|
+
- Apache 2.0
|
130
|
+
metadata: {}
|
140
131
|
post_install_message:
|
141
132
|
rdoc_options: []
|
142
133
|
require_paths:
|
143
134
|
- lib
|
144
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
136
|
requirements:
|
147
|
-
- -
|
137
|
+
- - '>='
|
148
138
|
- !ruby/object:Gem::Version
|
149
139
|
version: 1.9.0
|
150
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
141
|
requirements:
|
153
|
-
- -
|
142
|
+
- - '>='
|
154
143
|
- !ruby/object:Gem::Version
|
155
144
|
version: '0'
|
156
145
|
requirements: []
|
157
146
|
rubyforge_project:
|
158
|
-
rubygems_version:
|
147
|
+
rubygems_version: 2.0.3
|
159
148
|
signing_key:
|
160
|
-
specification_version:
|
149
|
+
specification_version: 4
|
161
150
|
summary: Fails your build if code quality thresholds are not met. Provides complexity
|
162
151
|
and style checkers built-in, and allows integration with with custom quality metrics.
|
163
152
|
test_files:
|
@@ -175,3 +164,4 @@ test_files:
|
|
175
164
|
- spec/style_check_spec.rb
|
176
165
|
- spec/threshold_check_spec.rb
|
177
166
|
- spec/violation_formatter_spec.rb
|
167
|
+
has_rdoc: false
|