guideline 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -7
- data/bin/guideline +1 -18
- data/guideline.gemspec +0 -2
- data/lib/guideline.rb +2 -0
- data/lib/guideline/checkers/abc_complexity_checker.rb +15 -17
- data/lib/guideline/checkers/long_line_checker.rb +3 -1
- data/lib/guideline/checkers/long_method_checker.rb +3 -1
- data/lib/guideline/option_parser.rb +89 -0
- data/lib/guideline/path_finder.rb +54 -0
- data/lib/guideline/runner.rb +36 -69
- data/lib/guideline/version.rb +1 -1
- data/lib/guideline/visitor.rb +9 -49
- data/spec/guideline/option_parser_spec.rb +34 -0
- data/spec/guideline/runner_spec.rb +34 -83
- data/spec/guideline/visitor_spec.rb +13 -22
- metadata +29 -29
- data/.guideline.yml +0 -6
data/README.md
CHANGED
@@ -20,15 +20,22 @@ $ gem install guideline
|
|
20
20
|
## Usage
|
21
21
|
```
|
22
22
|
$ guideline --help
|
23
|
-
Usage: guideline [
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
Usage: guideline [options]
|
24
|
+
--no-abc-complexity (default: true) check method ABC complexity
|
25
|
+
--no-hard-tab-indent (default: true) check hard tab indent
|
26
|
+
--no-hash-comma (default: true) check last comma in Hash literal
|
27
|
+
--no-long-line (default: true) check line length
|
28
|
+
--no-long-method (default: true) check method height
|
29
|
+
--no-trailing-whitespace (default: true) check trailing whitespace
|
30
|
+
--no-unused-method (default: true) check unused method
|
31
|
+
--abc-complexity= (default: 15) threshold of ABC complexity
|
32
|
+
--long-line= (default: 80) threshold of long line
|
33
|
+
--long-method= (default: 10) threshold of long method
|
34
|
+
--path= (default: ./) checked file or dir or glob pattern
|
28
35
|
```
|
29
36
|
|
30
37
|
```
|
31
|
-
$ guideline
|
38
|
+
$ guideline --path /path/to/chatroid
|
32
39
|
|
33
40
|
lib/chatroid/adapter/campfire.rb
|
34
41
|
26: Line length 85 should be less than 80 characters
|
@@ -47,7 +54,7 @@ lib/chatroid/adapter/twitter.rb
|
|
47
54
|
```
|
48
55
|
|
49
56
|
```
|
50
|
-
$ guideline
|
57
|
+
$ guideline --path /path/to/guideline
|
51
58
|
|
52
59
|
lib/guideline/checkers/abc_complexity_checker.rb
|
53
60
|
40: ABC Complexity of method<Guideline::AbcComplexityChecker::Moduleable.included> 16 should be less than 10
|
data/bin/guideline
CHANGED
@@ -2,22 +2,5 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift File.expand_path("../../lib/", __FILE__)
|
4
4
|
require "guideline"
|
5
|
-
include Guideline
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
checkers = CheckerFactory.new(
|
10
|
-
options[:config],
|
11
|
-
AbcComplexityChecker,
|
12
|
-
HardTabIndentChecker,
|
13
|
-
HashCommaChecker,
|
14
|
-
LongLineChecker,
|
15
|
-
LongMethodChecker,
|
16
|
-
TrailingWhitespaceChecker,
|
17
|
-
UnusedMethodChecker,
|
18
|
-
).create
|
19
|
-
|
20
|
-
visitor = Visitor.new(:only => ARGV[0], :checker => checkers)
|
21
|
-
visitor.prepare
|
22
|
-
visitor.visit
|
23
|
-
visitor.render
|
6
|
+
Guideline::Runner.run
|
data/guideline.gemspec
CHANGED
@@ -18,9 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_dependency "slop"
|
22
21
|
gem.add_dependency "code_analyzer"
|
23
|
-
gem.add_dependency "activesupport"
|
24
22
|
gem.add_development_dependency "rspec", ">=2.12.0"
|
25
23
|
gem.add_development_dependency "pry"
|
26
24
|
gem.add_development_dependency "simplecov"
|
data/lib/guideline.rb
CHANGED
@@ -2,6 +2,8 @@ require "code_analyzer"
|
|
2
2
|
|
3
3
|
module Guideline
|
4
4
|
class AbcComplexityChecker < Checker
|
5
|
+
DEFAULT_MAX = 15
|
6
|
+
|
5
7
|
def check(path)
|
6
8
|
@current_path = path
|
7
9
|
visitor.check(path.to_s, path.read)
|
@@ -12,22 +14,18 @@ module Guideline
|
|
12
14
|
|
13
15
|
def checker
|
14
16
|
AbcParser.new do |complexity, method, module_name, class_method_flag|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
)
|
28
|
-
end
|
29
|
-
rescue Exception
|
30
|
-
require "pry"; binding.pry
|
17
|
+
if complexity > max
|
18
|
+
report(
|
19
|
+
:path => @current_path,
|
20
|
+
:line => method.line,
|
21
|
+
:message => "ABC Complexity of method<%s%s%s>%3d should be less than %d" % [
|
22
|
+
module_name,
|
23
|
+
class_method_flag ? "." : "#",
|
24
|
+
method.method_name,
|
25
|
+
complexity,
|
26
|
+
max,
|
27
|
+
]
|
28
|
+
)
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
@@ -37,7 +35,7 @@ module Guideline
|
|
37
35
|
end
|
38
36
|
|
39
37
|
def max
|
40
|
-
@options[:max]
|
38
|
+
(@options[:max] || DEFAULT_MAX).to_i
|
41
39
|
end
|
42
40
|
|
43
41
|
class AbcParser < CodeAnalyzer::Checker
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Guideline
|
2
2
|
class LongLineChecker < Checker
|
3
|
+
DEFAULT_MAX = 80
|
4
|
+
|
3
5
|
def check(path)
|
4
6
|
lines(path).select(&:has_error?).each do |line|
|
5
7
|
report(
|
@@ -19,7 +21,7 @@ module Guideline
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def max
|
22
|
-
@options[:max]
|
24
|
+
(@options[:max] || DEFAULT_MAX).to_i
|
23
25
|
end
|
24
26
|
|
25
27
|
class LineChecker
|
@@ -3,6 +3,8 @@ require "ostruct"
|
|
3
3
|
|
4
4
|
module Guideline
|
5
5
|
class LongMethodChecker < Checker
|
6
|
+
DEFAULT_MAX = 10
|
7
|
+
|
6
8
|
def check(path)
|
7
9
|
MethodParser.parse(path.read) do |method|
|
8
10
|
if method.height > max
|
@@ -18,7 +20,7 @@ module Guideline
|
|
18
20
|
private
|
19
21
|
|
20
22
|
def max
|
21
|
-
@options[:max] ||
|
23
|
+
(@options[:max] || DEFAULT_MAX).to_i
|
22
24
|
end
|
23
25
|
|
24
26
|
class Method < OpenStruct
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module Guideline
|
4
|
+
class OptionParser < ::OptionParser
|
5
|
+
OPTIONS = [
|
6
|
+
"--no-abc-complexity", "(default: true) check method ABC complexity",
|
7
|
+
"--no-hard-tab-indent", "(default: true) check hard tab indent",
|
8
|
+
"--no-hash-comma", "(default: true) check last comma in Hash literal",
|
9
|
+
"--no-long-line", "(default: true) check line length",
|
10
|
+
"--no-long-method", "(default: true) check method height",
|
11
|
+
"--no-trailing-whitespace", "(default: true) check trailing whitespace",
|
12
|
+
"--no-unused-method", "(default: true) check unused method",
|
13
|
+
"--abc-complexity=", "(default: 15) threshold of ABC complexity",
|
14
|
+
"--long-line=", "(default: 80) threshold of long line",
|
15
|
+
"--long-method=", "(default: 10) threshold of long method",
|
16
|
+
"--path=", "(default: ./) checked file or dir or glob pattern",
|
17
|
+
]
|
18
|
+
|
19
|
+
def self.parse(argv = ARGV)
|
20
|
+
new.parse(argv)
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(*)
|
24
|
+
super
|
25
|
+
configure_checker_options
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse(*)
|
29
|
+
super
|
30
|
+
options
|
31
|
+
end
|
32
|
+
|
33
|
+
def options
|
34
|
+
@options ||= {}
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def configure_checker_options
|
40
|
+
arguments.each do |argument|
|
41
|
+
on(argument.key, argument.description) do |value|
|
42
|
+
options[argument.to_sym] = value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def arguments
|
48
|
+
OPTIONS.each_slice(2).map do |key, description|
|
49
|
+
Argument.new(key, description)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Argument
|
54
|
+
attr_reader :key, :description
|
55
|
+
|
56
|
+
def initialize(key, description)
|
57
|
+
@key = key
|
58
|
+
@description = description
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_sym
|
62
|
+
str = @key
|
63
|
+
str = without_head_hyphen(str)
|
64
|
+
str = without_head_no(str)
|
65
|
+
str = without_last_equal(str)
|
66
|
+
str = underscored(str)
|
67
|
+
str.to_sym
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def underscored(str)
|
73
|
+
str.gsub("-", "_")
|
74
|
+
end
|
75
|
+
|
76
|
+
def without_head_hyphen(str)
|
77
|
+
str.gsub(/^--/, "")
|
78
|
+
end
|
79
|
+
|
80
|
+
def without_head_no(str)
|
81
|
+
str.gsub(/^no-/, "")
|
82
|
+
end
|
83
|
+
|
84
|
+
def without_last_equal(str)
|
85
|
+
str.gsub(/=$/, "")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module Guideline
|
4
|
+
class PathFinder
|
5
|
+
def self.find(pattern)
|
6
|
+
new(pattern).paths
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(pattern)
|
10
|
+
@pattern = pattern
|
11
|
+
end
|
12
|
+
|
13
|
+
def paths
|
14
|
+
Pathname.glob(recognized_pattern)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def pattern
|
20
|
+
@pattern
|
21
|
+
end
|
22
|
+
|
23
|
+
def path
|
24
|
+
@path ||= Pathname.new(pattern)
|
25
|
+
end
|
26
|
+
|
27
|
+
def recognized_pattern
|
28
|
+
case
|
29
|
+
when pattern_not_given?
|
30
|
+
default_glob
|
31
|
+
when directory?
|
32
|
+
default_glob_with_directory
|
33
|
+
else
|
34
|
+
pattern
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def pattern_not_given?
|
39
|
+
pattern.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
def directory?
|
43
|
+
path.directory?
|
44
|
+
end
|
45
|
+
|
46
|
+
def default_glob
|
47
|
+
"**/*.rb"
|
48
|
+
end
|
49
|
+
|
50
|
+
def default_glob_with_directory
|
51
|
+
File.join(path, default_glob)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/guideline/runner.rb
CHANGED
@@ -1,96 +1,63 @@
|
|
1
|
-
require "yaml"
|
2
|
-
require "fileutils"
|
3
|
-
require "slop"
|
4
|
-
require "active_support/core_ext/hash/indifferent_access"
|
5
|
-
|
6
1
|
module Guideline
|
7
2
|
class Runner
|
8
|
-
|
9
|
-
|
10
|
-
def self.parse(*argv)
|
11
|
-
new(*argv).parse
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(argv)
|
15
|
-
@hash = Parser.parse(argv).with_indifferent_access
|
3
|
+
def self.run
|
4
|
+
new.run
|
16
5
|
end
|
17
6
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@hash
|
7
|
+
def run
|
8
|
+
visitor.prepare
|
9
|
+
visitor.visit
|
10
|
+
visitor.render
|
23
11
|
end
|
24
12
|
|
25
13
|
private
|
26
14
|
|
27
|
-
def
|
28
|
-
|
29
|
-
when @hash[:init]
|
30
|
-
generate_default_config_file
|
31
|
-
when @hash[:version]
|
32
|
-
show_version
|
33
|
-
end
|
15
|
+
def visitor
|
16
|
+
@visitor ||= Visitor.new(options[:path], enable_checkers)
|
34
17
|
end
|
35
18
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
19
|
+
def enable_checkers
|
20
|
+
array = []
|
21
|
+
array << abc_complexity_checker if options[:abc_complexity] != false
|
22
|
+
array << hard_tab_indent_checker if options[:hard_tab_indent] != false
|
23
|
+
array << hash_comma_checker if options[:hash_comma] != false
|
24
|
+
array << long_line_checker if options[:long_line] != false
|
25
|
+
array << long_method_checker if options[:long_method] != false
|
26
|
+
array << trailing_whitespace_checker if options[:trailing_whitespace] != false
|
27
|
+
array << unused_method_checker if options[:unused_method] != false
|
28
|
+
array
|
39
29
|
end
|
40
30
|
|
41
|
-
def
|
42
|
-
|
43
|
-
rescue Errno::ENOENT
|
44
|
-
puts "No such config file - #{config_path}"
|
45
|
-
exit
|
31
|
+
def options
|
32
|
+
@options ||= OptionParser.parse
|
46
33
|
end
|
47
34
|
|
48
|
-
def
|
49
|
-
|
35
|
+
def abc_complexity_checker
|
36
|
+
AbcComplexityChecker.new(:max => options[:abc_complexity])
|
50
37
|
end
|
51
38
|
|
52
|
-
def
|
53
|
-
|
39
|
+
def hard_tab_indent_checker
|
40
|
+
HardTabIndentChecker.new
|
54
41
|
end
|
55
42
|
|
56
|
-
def
|
57
|
-
|
58
|
-
puts "./#{CONFIG_FILE_NAME} already exists"
|
59
|
-
else
|
60
|
-
FileUtils.copy(default_config_path, "./")
|
61
|
-
puts "./#{CONFIG_FILE_NAME} was generated"
|
62
|
-
end
|
63
|
-
exit
|
43
|
+
def hash_comma_checker
|
44
|
+
HashCommaChecker.new
|
64
45
|
end
|
65
46
|
|
66
|
-
def
|
67
|
-
|
47
|
+
def long_line_checker
|
48
|
+
LongLineChecker.new(:max => options[:long_line])
|
68
49
|
end
|
69
50
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
def initialize(argv)
|
76
|
-
@argv = argv
|
77
|
-
end
|
78
|
-
|
79
|
-
def parse
|
80
|
-
slop.parse(@argv)
|
81
|
-
slop.to_hash
|
82
|
-
end
|
51
|
+
def long_method_checker
|
52
|
+
LongMethodChecker.new(:max => options[:long_method])
|
53
|
+
end
|
83
54
|
|
84
|
-
|
55
|
+
def trailing_whitespace_checker
|
56
|
+
TrailingWhitespaceChecker.new
|
57
|
+
end
|
85
58
|
|
86
|
-
|
87
|
-
|
88
|
-
banner "Usage: guideline [directory] [options]"
|
89
|
-
on :c=, :config=, "Path to config YAML file."
|
90
|
-
on :i, :init, "Generate config YAML template into current directory."
|
91
|
-
on :v, :version, "Show version number."
|
92
|
-
end
|
93
|
-
end
|
59
|
+
def unused_method_checker
|
60
|
+
UnusedMethodChecker.new
|
94
61
|
end
|
95
62
|
end
|
96
63
|
end
|
data/lib/guideline/version.rb
CHANGED
data/lib/guideline/visitor.rb
CHANGED
@@ -4,9 +4,9 @@ module Guideline
|
|
4
4
|
class Visitor
|
5
5
|
attr_reader :options
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
@
|
7
|
+
def initialize(pattern, checkers)
|
8
|
+
@pattern = pattern
|
9
|
+
@checkers = checkers
|
10
10
|
end
|
11
11
|
|
12
12
|
def visit
|
@@ -36,59 +36,19 @@ module Guideline
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def paths
|
39
|
-
PathFinder.find(
|
39
|
+
PathFinder.find(pattern)
|
40
40
|
end
|
41
41
|
|
42
42
|
def checkers
|
43
|
-
@checkers
|
43
|
+
@checkers
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
47
|
-
@
|
46
|
+
def pattern
|
47
|
+
@pattern
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
def self.find(options = {})
|
54
|
-
new(options).paths
|
55
|
-
end
|
56
|
-
|
57
|
-
def initialize(options = {})
|
58
|
-
@options = options
|
59
|
-
end
|
60
|
-
|
61
|
-
def paths
|
62
|
-
(found_paths - excepted_paths).select(&:exist?)
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def found_paths
|
68
|
-
Pathname.glob(only_pattern)
|
69
|
-
end
|
70
|
-
|
71
|
-
def excepted_paths
|
72
|
-
if except_pattern
|
73
|
-
Pathname.glob(except_pattern)
|
74
|
-
else
|
75
|
-
[]
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def only_pattern
|
80
|
-
if options[:only]
|
81
|
-
File.expand_path(options[:only])
|
82
|
-
else
|
83
|
-
File.expand_path("**/*.rb")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def except_pattern
|
88
|
-
if options[:except]
|
89
|
-
File.expand_path(options[:except])
|
90
|
-
end
|
91
|
-
end
|
50
|
+
def errors
|
51
|
+
@errors ||= checkers.select(&:has_error?).map(&:errors).inject([], &:+)
|
92
52
|
end
|
93
53
|
end
|
94
54
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Guideline
|
4
|
+
describe OptionParser do
|
5
|
+
describe ".parse" do
|
6
|
+
subject do
|
7
|
+
described_class.parse(argv)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when ARGV is --no-abc-complexity" do
|
11
|
+
let(:argv) do
|
12
|
+
["--no-abc-complexity"]
|
13
|
+
end
|
14
|
+
it { should == { :abc_complexity => false } }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when ARGV is --abc-complexity 5" do
|
18
|
+
let(:argv) do
|
19
|
+
["--abc-complexity", "5"]
|
20
|
+
end
|
21
|
+
it { should == { :abc_complexity => "5" } }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when ARGV is --non-existent-key" do
|
25
|
+
let(:argv) do
|
26
|
+
["--non-existent-key"]
|
27
|
+
end
|
28
|
+
it do
|
29
|
+
expect { subject }.to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -2,111 +2,62 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
module Guideline
|
4
4
|
describe Runner do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
let(:runner) do
|
6
|
+
described_class.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".run" do
|
10
|
+
it "creates its instance and call #run" do
|
11
|
+
described_class.any_instance.should_receive(:run)
|
12
|
+
described_class.run
|
8
13
|
end
|
14
|
+
end
|
9
15
|
|
16
|
+
describe "#run" do
|
10
17
|
before do
|
11
|
-
runner.stub(:
|
18
|
+
runner.stub(:enable_checkers => enable_checkers)
|
12
19
|
end
|
13
20
|
|
14
|
-
let(:
|
15
|
-
[]
|
21
|
+
let(:enable_checkers) do
|
22
|
+
[checker]
|
16
23
|
end
|
17
24
|
|
18
|
-
let(:
|
19
|
-
|
25
|
+
let(:checker) do
|
26
|
+
mock(:has_error? => false)
|
20
27
|
end
|
21
28
|
|
22
|
-
it
|
23
|
-
|
24
|
-
|
25
|
-
let(:argv) do
|
26
|
-
["--init"]
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when config file already exists" do
|
30
|
-
before do
|
31
|
-
File.stub(:exist? => true)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "does not generate config file" do
|
35
|
-
FileUtils.should_not_receive(:copy)
|
36
|
-
expect { subject }.to raise_error(SystemExit)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when config file does not exist" do
|
41
|
-
before do
|
42
|
-
File.stub(:exist? => false)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "generates config file" do
|
46
|
-
FileUtils.should_receive(:copy)
|
47
|
-
expect { subject }.to raise_error(SystemExit)
|
48
|
-
end
|
49
|
-
end
|
29
|
+
it "runs enable checkers" do
|
30
|
+
checker.should_receive(:check).at_least(1)
|
31
|
+
runner.run
|
50
32
|
end
|
33
|
+
end
|
51
34
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
it "shows current version number and exit" do
|
58
|
-
runner.should_receive(:puts).with(VERSION)
|
59
|
-
expect { subject }.to raise_error(SystemExit)
|
60
|
-
end
|
35
|
+
describe "#enable_checkers" do
|
36
|
+
subject do
|
37
|
+
runner.send(:enable_checkers)
|
61
38
|
end
|
62
39
|
|
63
|
-
|
64
|
-
|
65
|
-
should == {
|
66
|
-
"config" => {
|
67
|
-
"Guideline::LongLineChecker" => {
|
68
|
-
"max" => 80,
|
69
|
-
},
|
70
|
-
"Guideline::LongMethodChecker" => {
|
71
|
-
"max" => 10,
|
72
|
-
},
|
73
|
-
"Guideline::AbcComplexityChecker" => {
|
74
|
-
"max" => 10,
|
75
|
-
},
|
76
|
-
},
|
77
|
-
"init" => nil,
|
78
|
-
"version" => nil,
|
79
|
-
}
|
80
|
-
end
|
40
|
+
before do
|
41
|
+
runner.stub(:options => options)
|
81
42
|
end
|
82
43
|
|
83
|
-
context "when
|
84
|
-
let(:
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
before do
|
89
|
-
YAML.stub(:load_file).and_return("a" => "b")
|
44
|
+
context "when options[:abc_complexity] is false" do
|
45
|
+
let(:options) do
|
46
|
+
{ :abc_complexity => false }
|
90
47
|
end
|
91
48
|
|
92
|
-
it "
|
93
|
-
|
94
|
-
"config" => {
|
95
|
-
"a" => "b",
|
96
|
-
},
|
97
|
-
"init" => nil,
|
98
|
-
"version" => nil,
|
99
|
-
}
|
49
|
+
it "does not include AbcComplexityChecker" do
|
50
|
+
should_not be_any {|checker| checker.is_a?(AbcComplexityChecker) }
|
100
51
|
end
|
101
52
|
end
|
102
53
|
|
103
|
-
context "when
|
104
|
-
let(:
|
105
|
-
|
54
|
+
context "when options[:abc_complexity] is nil" do
|
55
|
+
let(:options) do
|
56
|
+
{}
|
106
57
|
end
|
107
58
|
|
108
|
-
it do
|
109
|
-
|
59
|
+
it "includes AbcComplexityChecker" do
|
60
|
+
should be_any {|checker| checker.is_a?(AbcComplexityChecker) }
|
110
61
|
end
|
111
62
|
end
|
112
63
|
end
|
@@ -3,11 +3,15 @@ require "spec_helper"
|
|
3
3
|
module Guideline
|
4
4
|
describe Visitor do
|
5
5
|
let(:visitor) do
|
6
|
-
described_class.new(
|
6
|
+
described_class.new(pattern, checkers)
|
7
7
|
end
|
8
8
|
|
9
|
-
let(:
|
10
|
-
|
9
|
+
let(:pattern) do
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:checkers) do
|
14
|
+
[checker]
|
11
15
|
end
|
12
16
|
|
13
17
|
let(:checker) do
|
@@ -16,29 +20,16 @@ module Guideline
|
|
16
20
|
|
17
21
|
describe "#visit" do
|
18
22
|
let(:path) do
|
19
|
-
Pathname.new(
|
23
|
+
Pathname.new(__FILE__)
|
20
24
|
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
options[:only] = "lib/**/*.rb"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "does not visit paths which are not specified" do
|
28
|
-
checker.should_not_receive(:check).with(path)
|
29
|
-
visitor.visit
|
30
|
-
end
|
26
|
+
let(:pattern) do
|
27
|
+
path.to_s
|
31
28
|
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
it "does not visit paths which are specified" do
|
39
|
-
checker.should_not_receive(:check).with(path)
|
40
|
-
visitor.visit
|
41
|
-
end
|
30
|
+
it "calls checker.check with found paths" do
|
31
|
+
checker.should_receive(:check).with(path).at_least(1)
|
32
|
+
visitor.visit
|
42
33
|
end
|
43
34
|
end
|
44
35
|
|
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.
|
4
|
+
version: 0.2.0
|
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-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
15
|
+
name: code_analyzer
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,43 +21,31 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: code_analyzer
|
27
|
-
requirement: &70221529082560 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ! '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '0'
|
33
|
-
type: :runtime
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *70221529082560
|
36
30
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
39
33
|
none: false
|
40
34
|
requirements:
|
41
35
|
- - ! '>='
|
42
36
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
type: :
|
37
|
+
version: 2.12.0
|
38
|
+
type: :development
|
45
39
|
prerelease: false
|
46
|
-
version_requirements:
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rspec
|
49
|
-
requirement: &70221529081640 !ruby/object:Gem::Requirement
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
41
|
none: false
|
51
42
|
requirements:
|
52
43
|
- - ! '>='
|
53
44
|
- !ruby/object:Gem::Version
|
54
45
|
version: 2.12.0
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *70221529081640
|
58
46
|
- !ruby/object:Gem::Dependency
|
59
47
|
name: pry
|
60
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
61
49
|
none: false
|
62
50
|
requirements:
|
63
51
|
- - ! '>='
|
@@ -65,10 +53,15 @@ dependencies:
|
|
65
53
|
version: '0'
|
66
54
|
type: :development
|
67
55
|
prerelease: false
|
68
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
69
62
|
- !ruby/object:Gem::Dependency
|
70
63
|
name: simplecov
|
71
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
72
65
|
none: false
|
73
66
|
requirements:
|
74
67
|
- - ! '>='
|
@@ -76,7 +69,12 @@ dependencies:
|
|
76
69
|
version: '0'
|
77
70
|
type: :development
|
78
71
|
prerelease: false
|
79
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
80
78
|
description: Guideline.gem checks that your code is protectingthe rule of coding guideline
|
81
79
|
email:
|
82
80
|
- r7kamura@gmail.com
|
@@ -86,7 +84,6 @@ extensions: []
|
|
86
84
|
extra_rdoc_files: []
|
87
85
|
files:
|
88
86
|
- .gitignore
|
89
|
-
- .guideline.yml
|
90
87
|
- Gemfile
|
91
88
|
- LICENSE.txt
|
92
89
|
- README.md
|
@@ -104,7 +101,9 @@ files:
|
|
104
101
|
- lib/guideline/checkers/trailing_whitespace_checker.rb
|
105
102
|
- lib/guideline/checkers/unused_method_checker.rb
|
106
103
|
- lib/guideline/error.rb
|
104
|
+
- lib/guideline/option_parser.rb
|
107
105
|
- lib/guideline/parser/moduleable.rb
|
106
|
+
- lib/guideline/path_finder.rb
|
108
107
|
- lib/guideline/runner.rb
|
109
108
|
- lib/guideline/version.rb
|
110
109
|
- lib/guideline/visitor.rb
|
@@ -118,6 +117,7 @@ files:
|
|
118
117
|
- spec/guideline/checkers/trailing_whitespace_checker_spec.rb
|
119
118
|
- spec/guideline/checkers/unused_method_checker_spec.rb
|
120
119
|
- spec/guideline/error_spec.rb
|
120
|
+
- spec/guideline/option_parser_spec.rb
|
121
121
|
- spec/guideline/runner_spec.rb
|
122
122
|
- spec/guideline/visitor_spec.rb
|
123
123
|
- spec/spec_helper.rb
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 1.8.
|
144
|
+
rubygems_version: 1.8.24
|
145
145
|
signing_key:
|
146
146
|
specification_version: 3
|
147
147
|
summary: The guideline of your code
|
@@ -156,7 +156,7 @@ test_files:
|
|
156
156
|
- spec/guideline/checkers/trailing_whitespace_checker_spec.rb
|
157
157
|
- spec/guideline/checkers/unused_method_checker_spec.rb
|
158
158
|
- spec/guideline/error_spec.rb
|
159
|
+
- spec/guideline/option_parser_spec.rb
|
159
160
|
- spec/guideline/runner_spec.rb
|
160
161
|
- spec/guideline/visitor_spec.rb
|
161
162
|
- spec/spec_helper.rb
|
162
|
-
has_rdoc:
|