guideline 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/{guideline.yml → .guideline.yml} +0 -0
- data/README.md +33 -5
- data/guideline.gemspec +2 -2
- data/lib/guideline/runner.rb +42 -17
- data/lib/guideline/version.rb +1 -1
- data/lib/guideline/visitor.rb +0 -1
- data/spec/guideline/runner_spec.rb +61 -27
- metadata +16 -56
File without changes
|
data/README.md
CHANGED
@@ -1,16 +1,34 @@
|
|
1
1
|
# Guideline
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
Guideline checks that your code is protecting the rule of coding guideline.
|
3
|
+
This library requires Ruby 1.9 or later.
|
4
|
+
|
5
|
+
## Feature
|
6
|
+
* For each method
|
7
|
+
* Check ABC-complexity
|
8
|
+
* Check the number of lines
|
9
|
+
* Check unused method
|
10
|
+
* For each file
|
11
|
+
* Check the precense of hard tab indent
|
12
|
+
* Check the presense of comma at the end of multiline Hash literal
|
13
|
+
* Check the horizontal length of each line
|
14
|
+
|
15
|
+
## Install
|
6
16
|
```
|
7
17
|
$ gem install guideline
|
8
18
|
```
|
9
19
|
|
10
20
|
## Usage
|
21
|
+
```
|
22
|
+
$ guideline --help
|
23
|
+
Usage: guideline [directory] [options]
|
24
|
+
-c, --config Path to config YAML file.
|
25
|
+
-i, --init Generate config YAML template into current directory.
|
26
|
+
-h, --help Display this help message.
|
27
|
+
```
|
11
28
|
|
12
29
|
```
|
13
|
-
$ guideline
|
30
|
+
$ guideline ./chatroid
|
31
|
+
|
14
32
|
lib/chatroid/adapter/campfire.rb
|
15
33
|
26: Line length 85 should be less than 80 characters
|
16
34
|
|
@@ -26,3 +44,13 @@ spec/chatroid/adapter/twitter_spec.rb
|
|
26
44
|
lib/chatroid/adapter/twitter.rb
|
27
45
|
19: Too long 12 lines method <#stream>
|
28
46
|
```
|
47
|
+
|
48
|
+
```
|
49
|
+
$ guideline ./guideline
|
50
|
+
|
51
|
+
lib/guideline/checkers/abc_complexity_checker.rb
|
52
|
+
40: ABC Complexity of method<Guideline::AbcComplexityChecker::Moduleable.included> 16 should be less than 10
|
53
|
+
|
54
|
+
lib/guideline/error.rb
|
55
|
+
5: Remove unused method <render>
|
56
|
+
```
|
data/guideline.gemspec
CHANGED
@@ -8,7 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Guideline::VERSION
|
9
9
|
gem.authors = ["Ryo NAKAMURA"]
|
10
10
|
gem.email = ["r7kamura@gmail.com"]
|
11
|
-
gem.description = "Guideline.gem checks
|
11
|
+
gem.description = "Guideline.gem checks that your code is protecting" +
|
12
|
+
"the rule of coding guideline"
|
12
13
|
gem.summary = "The guideline of your code"
|
13
14
|
gem.homepage = "https://github.com/r7kamura/guideline"
|
14
15
|
|
@@ -20,7 +21,6 @@ Gem::Specification.new do |gem|
|
|
20
21
|
gem.add_dependency "slop"
|
21
22
|
gem.add_dependency "code_analyzer"
|
22
23
|
gem.add_dependency "active_support"
|
23
|
-
gem.add_dependency "i18n"
|
24
24
|
gem.add_development_dependency "rspec", ">=2.12.0"
|
25
25
|
gem.add_development_dependency "pry"
|
26
26
|
end
|
data/lib/guideline/runner.rb
CHANGED
@@ -1,32 +1,56 @@
|
|
1
1
|
require "yaml"
|
2
|
+
require "fileutils"
|
2
3
|
require "slop"
|
4
|
+
require "active_support/core_ext/hash/indifferent_access"
|
3
5
|
|
4
6
|
module Guideline
|
5
|
-
|
6
|
-
|
7
|
+
class Runner
|
8
|
+
CONFIG_FILE_NAME = ".guideline.yml"
|
7
9
|
|
8
|
-
def parse(argv)
|
9
|
-
|
10
|
-
hash[:config] = load_config(hash[:config])
|
11
|
-
hash.delete(:help)
|
12
|
-
hash
|
10
|
+
def self.parse(*argv)
|
11
|
+
new(*argv).parse
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
def initialize(argv)
|
15
|
+
@hash = Parser.parse(argv).with_indifferent_access
|
16
|
+
end
|
16
17
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
18
|
+
def parse
|
19
|
+
generate_default_config_file if @hash[:init]
|
20
|
+
@hash[:config] = load_config
|
21
|
+
@hash.delete(:help)
|
22
|
+
@hash
|
20
23
|
end
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
private
|
26
|
+
|
27
|
+
def load_config
|
28
|
+
YAML.load_file(config_path)
|
24
29
|
rescue Errno::ENOENT
|
25
|
-
|
30
|
+
puts "No such config file - #{config_path}"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
def config_path
|
35
|
+
@hash[:config] || default_config_path
|
26
36
|
end
|
27
37
|
|
28
38
|
def default_config_path
|
29
|
-
File.expand_path("
|
39
|
+
File.expand_path("../../../#{CONFIG_FILE_NAME}", __FILE__)
|
40
|
+
end
|
41
|
+
|
42
|
+
def generate_default_config_file
|
43
|
+
if config_file_exist?
|
44
|
+
puts "./#{CONFIG_FILE_NAME} already exists"
|
45
|
+
else
|
46
|
+
FileUtils.copy(default_config_path, "./")
|
47
|
+
puts "./#{CONFIG_FILE_NAME} was generated"
|
48
|
+
end
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
def config_file_exist?
|
53
|
+
File.exist?(CONFIG_FILE_NAME)
|
30
54
|
end
|
31
55
|
|
32
56
|
class Parser
|
@@ -47,8 +71,9 @@ module Guideline
|
|
47
71
|
|
48
72
|
def slop
|
49
73
|
@slop ||= Slop.new(:help => true) do
|
50
|
-
banner "Usage:
|
51
|
-
on :c=, :config=, "
|
74
|
+
banner "Usage: guideline [directory] [options]"
|
75
|
+
on :c=, :config=, "Path to config YAML file."
|
76
|
+
on :i, :init, "Generate config YAML template into current directory."
|
52
77
|
end
|
53
78
|
end
|
54
79
|
end
|
data/lib/guideline/version.rb
CHANGED
data/lib/guideline/visitor.rb
CHANGED
@@ -8,54 +8,88 @@ module Guideline
|
|
8
8
|
end
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
11
|
+
described_class.any_instance.stub(:puts)
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:
|
15
|
-
|
14
|
+
let(:argv) do
|
15
|
+
[]
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
File.expand_path("../../../guideline.yml", __FILE__)
|
20
|
-
end
|
18
|
+
it { should be_a HashWithIndifferentAccess }
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
context "when given --init option" do
|
21
|
+
let(:argv) do
|
22
|
+
["--init"]
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
context "when config file already exists" do
|
26
|
+
before do
|
27
|
+
described_class.any_instance.stub(:config_file_exist? => true)
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
|
30
|
+
it "does not generate config file" do
|
31
|
+
FileUtils.should_not_receive(:copy)
|
32
|
+
expect { subject }.to raise_error(SystemExit)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when config file does not exist" do
|
37
|
+
before do
|
38
|
+
described_class.any_instance.stub(:config_file_exist? => false)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "generates config file" do
|
42
|
+
FileUtils.should_receive(:copy)
|
43
|
+
expect { subject }.to raise_error(SystemExit)
|
44
|
+
end
|
45
|
+
end
|
33
46
|
end
|
34
47
|
|
35
|
-
context "when config option
|
36
|
-
it "returns parsed
|
37
|
-
should == {
|
48
|
+
context "when not given --config option" do
|
49
|
+
it "returns default config parsed from guideline.yml" do
|
50
|
+
should == {
|
51
|
+
"config" => {
|
52
|
+
"Guideline::LongLineChecker" => {
|
53
|
+
"max" => 80,
|
54
|
+
},
|
55
|
+
"Guideline::LongMethodChecker" => {
|
56
|
+
"max" => 10,
|
57
|
+
},
|
58
|
+
"Guideline::AbcComplexityChecker" => {
|
59
|
+
"max" => 10,
|
60
|
+
},
|
61
|
+
},
|
62
|
+
"init" => nil,
|
63
|
+
}
|
38
64
|
end
|
39
65
|
end
|
40
66
|
|
41
|
-
context "when
|
67
|
+
context "when existent file is specified by --config option" do
|
42
68
|
let(:argv) do
|
43
|
-
["
|
69
|
+
["--config", "existent.yml"]
|
70
|
+
end
|
71
|
+
|
72
|
+
before do
|
73
|
+
YAML.stub(:load_file).and_return("a" => "b")
|
44
74
|
end
|
45
75
|
|
46
|
-
it "returns parsed
|
47
|
-
should == {
|
76
|
+
it "returns config parsed from specified file" do
|
77
|
+
should == {
|
78
|
+
"config" => {
|
79
|
+
"a" => "b",
|
80
|
+
},
|
81
|
+
"init" => nil,
|
82
|
+
}
|
48
83
|
end
|
49
84
|
end
|
50
85
|
|
51
|
-
context "when
|
86
|
+
context "when non-existent file is specified by --config option" do
|
52
87
|
let(:argv) do
|
53
|
-
[]
|
88
|
+
["--config", "non-existent.yml"]
|
54
89
|
end
|
55
90
|
|
56
|
-
it
|
57
|
-
|
58
|
-
should have_key(:config)
|
91
|
+
it do
|
92
|
+
expect { subject }.to raise_error
|
59
93
|
end
|
60
94
|
end
|
61
95
|
end
|
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.0.
|
4
|
+
version: 0.0.9
|
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
|
+
date: 2012-12-01 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: &70154114004860 !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: *70154114004860
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: code_analyzer
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70154114004440 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,31 +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: *70154114004440
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: active_support
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: i18n
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70154114004020 !ruby/object:Gem::Requirement
|
65
39
|
none: false
|
66
40
|
requirements:
|
67
41
|
- - ! '>='
|
@@ -69,15 +43,10 @@ dependencies:
|
|
69
43
|
version: '0'
|
70
44
|
type: :runtime
|
71
45
|
prerelease: false
|
72
|
-
version_requirements:
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
46
|
+
version_requirements: *70154114004020
|
78
47
|
- !ruby/object:Gem::Dependency
|
79
48
|
name: rspec
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &70154114003520 !ruby/object:Gem::Requirement
|
81
50
|
none: false
|
82
51
|
requirements:
|
83
52
|
- - ! '>='
|
@@ -85,15 +54,10 @@ dependencies:
|
|
85
54
|
version: 2.12.0
|
86
55
|
type: :development
|
87
56
|
prerelease: false
|
88
|
-
version_requirements:
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 2.12.0
|
57
|
+
version_requirements: *70154114003520
|
94
58
|
- !ruby/object:Gem::Dependency
|
95
59
|
name: pry
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirement: &70154114003100 !ruby/object:Gem::Requirement
|
97
61
|
none: false
|
98
62
|
requirements:
|
99
63
|
- - ! '>='
|
@@ -101,13 +65,8 @@ dependencies:
|
|
101
65
|
version: '0'
|
102
66
|
type: :development
|
103
67
|
prerelease: false
|
104
|
-
version_requirements:
|
105
|
-
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
description: Guideline.gem checks if your code observes your coding guidelines
|
68
|
+
version_requirements: *70154114003100
|
69
|
+
description: Guideline.gem checks that your code is protectingthe rule of coding guideline
|
111
70
|
email:
|
112
71
|
- r7kamura@gmail.com
|
113
72
|
executables:
|
@@ -116,13 +75,13 @@ extensions: []
|
|
116
75
|
extra_rdoc_files: []
|
117
76
|
files:
|
118
77
|
- .gitignore
|
78
|
+
- .guideline.yml
|
119
79
|
- Gemfile
|
120
80
|
- LICENSE.txt
|
121
81
|
- README.md
|
122
82
|
- Rakefile
|
123
83
|
- bin/guideline
|
124
84
|
- guideline.gemspec
|
125
|
-
- guideline.yml
|
126
85
|
- lib/guideline.rb
|
127
86
|
- lib/guideline/checker_factory.rb
|
128
87
|
- lib/guideline/checkers/abc_complexity_checker.rb
|
@@ -168,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
127
|
version: '0'
|
169
128
|
requirements: []
|
170
129
|
rubyforge_project:
|
171
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.15
|
172
131
|
signing_key:
|
173
132
|
specification_version: 3
|
174
133
|
summary: The guideline of your code
|
@@ -185,3 +144,4 @@ test_files:
|
|
185
144
|
- spec/guideline/visitor_spec.rb
|
186
145
|
- spec/guideline_spec.rb
|
187
146
|
- spec/spec_helper.rb
|
147
|
+
has_rdoc:
|