guideline 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/guideline/checkers/hard_tab_indent_checker.rb +15 -0
- data/lib/guideline/version.rb +1 -1
- data/lib/guideline.rb +4 -3
- data/spec/guideline/checkers/hard_tab_indent_checker_spec.rb +45 -0
- data/spec/guideline/checkers/long_line_checker_spec.rb +45 -0
- data/spec/guideline/checkers/long_method_checker_spec.rb +46 -0
- metadata +13 -8
- data/spec/guideline/checker/long_line_checker_spec.rb +0 -28
- /data/lib/guideline/{checker.rb → checkers/checker.rb} +0 -0
- /data/lib/guideline/{checker → checkers}/long_line_checker.rb +0 -0
- /data/lib/guideline/{checker → checkers}/long_method_checker.rb +0 -0
- /data/spec/guideline/{checker_spec.rb → checkers/checker_spec.rb} +0 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
module Guideline
|
2
|
+
class HardTabIndentChecker < Checker
|
3
|
+
def check(path)
|
4
|
+
path.each_line.with_index do |line, index|
|
5
|
+
if line =~ /^ *\t/
|
6
|
+
add_error(
|
7
|
+
:message => "Use space indent instead of hard tab indent",
|
8
|
+
:path => path,
|
9
|
+
:line => index + 1
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/guideline/version.rb
CHANGED
data/lib/guideline.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "guideline/version"
|
2
2
|
require "guideline/visitor"
|
3
3
|
require "guideline/error"
|
4
|
-
require "guideline/checker"
|
5
|
-
require "guideline/
|
6
|
-
require "guideline/
|
4
|
+
require "guideline/checkers/checker"
|
5
|
+
require "guideline/checkers/long_line_checker"
|
6
|
+
require "guideline/checkers/long_method_checker"
|
7
|
+
require "guideline/checkers/hard_tab_indent_checker"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Guideline
|
4
|
+
describe HardTabIndentChecker do
|
5
|
+
describe "#check" do
|
6
|
+
let(:checker) do
|
7
|
+
described_class.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:path) do
|
11
|
+
mock(:each_line => content.each_line)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when there is hard tab indent" do
|
15
|
+
let(:content) do
|
16
|
+
<<-EOF
|
17
|
+
def foo
|
18
|
+
\t1
|
19
|
+
end
|
20
|
+
EOF
|
21
|
+
end
|
22
|
+
|
23
|
+
specify "checker detects error" do
|
24
|
+
checker.check(path)
|
25
|
+
checker.should have_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when there is no too long line" do
|
30
|
+
let(:content) do
|
31
|
+
<<-EOF
|
32
|
+
def foo
|
33
|
+
1
|
34
|
+
end
|
35
|
+
EOF
|
36
|
+
end
|
37
|
+
|
38
|
+
specify "checker does not detect error" do
|
39
|
+
checker.check(path)
|
40
|
+
checker.should_not have_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Guideline
|
4
|
+
describe LongLineChecker do
|
5
|
+
describe "#check" do
|
6
|
+
let(:checker) do
|
7
|
+
described_class.new(:max => 50)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:path) do
|
11
|
+
mock(:each_line => content.each_line)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when there is too line" do
|
15
|
+
let(:content) do
|
16
|
+
<<-EOF
|
17
|
+
def foo
|
18
|
+
too looooooooooooooooooooooooooooooooooooooooooooooooooooong line
|
19
|
+
end
|
20
|
+
EOF
|
21
|
+
end
|
22
|
+
|
23
|
+
specify "checker detects error" do
|
24
|
+
checker.check(path)
|
25
|
+
checker.should have_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when there is no too long line" do
|
30
|
+
let(:content) do
|
31
|
+
<<-EOF
|
32
|
+
def foo
|
33
|
+
not long line
|
34
|
+
end
|
35
|
+
EOF
|
36
|
+
end
|
37
|
+
|
38
|
+
specify "checker does not detect error" do
|
39
|
+
checker.check(path)
|
40
|
+
checker.should_not have_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Guideline
|
4
|
+
describe LongMethodChecker do
|
5
|
+
describe "#check" do
|
6
|
+
let(:checker) do
|
7
|
+
described_class.new(:max => 1)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:path) do
|
11
|
+
mock(:read => content)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when there is too long method" do
|
15
|
+
let(:content) do
|
16
|
+
<<-EOF
|
17
|
+
def foo
|
18
|
+
1
|
19
|
+
2
|
20
|
+
end
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
|
24
|
+
specify "checker detects error" do
|
25
|
+
checker.check(path)
|
26
|
+
checker.should have_error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when there is no too long method" do
|
31
|
+
let(:content) do
|
32
|
+
<<-EOF
|
33
|
+
def foo
|
34
|
+
1
|
35
|
+
end
|
36
|
+
EOF
|
37
|
+
end
|
38
|
+
|
39
|
+
specify "checker does not detect error" do
|
40
|
+
checker.check(path)
|
41
|
+
checker.should_not have_error
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -91,14 +91,17 @@ files:
|
|
91
91
|
- examples/long_method_checker.rb
|
92
92
|
- guideline.gemspec
|
93
93
|
- lib/guideline.rb
|
94
|
-
- lib/guideline/checker.rb
|
95
|
-
- lib/guideline/
|
96
|
-
- lib/guideline/
|
94
|
+
- lib/guideline/checkers/checker.rb
|
95
|
+
- lib/guideline/checkers/hard_tab_indent_checker.rb
|
96
|
+
- lib/guideline/checkers/long_line_checker.rb
|
97
|
+
- lib/guideline/checkers/long_method_checker.rb
|
97
98
|
- lib/guideline/error.rb
|
98
99
|
- lib/guideline/version.rb
|
99
100
|
- lib/guideline/visitor.rb
|
100
|
-
- spec/guideline/
|
101
|
-
- spec/guideline/
|
101
|
+
- spec/guideline/checkers/checker_spec.rb
|
102
|
+
- spec/guideline/checkers/hard_tab_indent_checker_spec.rb
|
103
|
+
- spec/guideline/checkers/long_line_checker_spec.rb
|
104
|
+
- spec/guideline/checkers/long_method_checker_spec.rb
|
102
105
|
- spec/guideline/visitor_spec.rb
|
103
106
|
- spec/guideline_spec.rb
|
104
107
|
- spec/spec_helper.rb
|
@@ -127,8 +130,10 @@ signing_key:
|
|
127
130
|
specification_version: 3
|
128
131
|
summary: The guideline of your code
|
129
132
|
test_files:
|
130
|
-
- spec/guideline/
|
131
|
-
- spec/guideline/
|
133
|
+
- spec/guideline/checkers/checker_spec.rb
|
134
|
+
- spec/guideline/checkers/hard_tab_indent_checker_spec.rb
|
135
|
+
- spec/guideline/checkers/long_line_checker_spec.rb
|
136
|
+
- spec/guideline/checkers/long_method_checker_spec.rb
|
132
137
|
- spec/guideline/visitor_spec.rb
|
133
138
|
- spec/guideline_spec.rb
|
134
139
|
- spec/spec_helper.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Guideline
|
4
|
-
describe LongLineChecker do
|
5
|
-
describe "#check" do
|
6
|
-
subject do
|
7
|
-
checker.check(path)
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:checker) do
|
11
|
-
described_class.new(:max => 1)
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:path) do
|
15
|
-
Pathname.new(__FILE__)
|
16
|
-
end
|
17
|
-
|
18
|
-
it do
|
19
|
-
should be_a Array
|
20
|
-
end
|
21
|
-
|
22
|
-
it do
|
23
|
-
subject
|
24
|
-
checker.should have_error
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|