guideline 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/guideline CHANGED
@@ -9,11 +9,12 @@ options = Runner.parse(ARGV)
9
9
  checkers = CheckerFactory.new(
10
10
  options[:config],
11
11
  AbcComplexityChecker,
12
- UnusedMethodChecker,
12
+ HardTabIndentChecker,
13
13
  HashCommaChecker,
14
14
  LongLineChecker,
15
15
  LongMethodChecker,
16
- HardTabIndentChecker
16
+ TrailingWhitespaceChecker,
17
+ UnusedMethodChecker,
17
18
  ).create
18
19
 
19
20
  visitor = Visitor.new(:only => ARGV[0], :checker => checkers)
data/lib/guideline.rb CHANGED
@@ -2,11 +2,13 @@ require "guideline/version"
2
2
  require "guideline/visitor"
3
3
  require "guideline/error"
4
4
  require "guideline/runner"
5
+ require "guideline/parser/moduleable"
5
6
  require "guideline/checker_factory"
6
7
  require "guideline/checkers/checker"
7
- require "guideline/checkers/long_line_checker"
8
- require "guideline/checkers/long_method_checker"
8
+ require "guideline/checkers/abc_complexity_checker"
9
9
  require "guideline/checkers/hard_tab_indent_checker"
10
10
  require "guideline/checkers/hash_comma_checker"
11
+ require "guideline/checkers/long_line_checker"
12
+ require "guideline/checkers/long_method_checker"
13
+ require "guideline/checkers/trailing_whitespace_checker"
11
14
  require "guideline/checkers/unused_method_checker"
12
- require "guideline/checkers/abc_complexity_checker"
@@ -1,4 +1,4 @@
1
- require "ripper"
1
+ require "code_analyzer"
2
2
 
3
3
  module Guideline
4
4
  class AbcComplexityChecker < Checker
@@ -36,38 +36,6 @@ module Guideline
36
36
  @options[:max]
37
37
  end
38
38
 
39
- module Moduleable
40
- def self.included(base)
41
- base.class_eval do
42
- interesting_nodes :class, :module
43
-
44
- add_callback :start_class do |node|
45
- modules << node.class_name.to_s
46
- end
47
-
48
- add_callback :start_module do |node|
49
- modules << node.module_name.to_s
50
- end
51
-
52
- add_callback :end_class do |node|
53
- modules.pop
54
- end
55
-
56
- add_callback :end_module do |node|
57
- modules.pop
58
- end
59
- end
60
- end
61
-
62
- def current_module_name
63
- modules.join("::")
64
- end
65
-
66
- def modules
67
- @moduels ||= []
68
- end
69
- end
70
-
71
39
  class AbcParser < CodeAnalyzer::Checker
72
40
  ASSIGNMENT_NODES = [:assign, :opassign]
73
41
  BRANCH_NODES = [:call, :fcall, :vcall, :zsuper, :yield0, :brace_block, :do_block]
@@ -75,7 +43,7 @@ module Guideline
75
43
  CONDITION_TOKENS = [:==, :===, :"<>", :<=, :>=, :=~, :>, :<, :<=>]
76
44
  ALL_NODES = ASSIGNMENT_NODES + BRANCH_NODES + CONDITION_NODES
77
45
 
78
- include Moduleable
46
+ include Parser::Moduleable
79
47
 
80
48
  attr_reader :assignment, :branch, :condition
81
49
 
@@ -0,0 +1,15 @@
1
+ module Guideline
2
+ class TrailingWhitespaceChecker < Checker
3
+ def check(path)
4
+ path.each_line.with_index do |line, index|
5
+ if line =~ / $/
6
+ report(
7
+ :message => "Remove trailing whitespace",
8
+ :path => path,
9
+ :line => index + 1
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -49,9 +49,13 @@ module Guideline
49
49
  def report_unused_methods(path)
50
50
  unused_methods.each do |method|
51
51
  report(
52
- :message => "Remove unused method <#{method.name}>",
53
52
  :path => path,
54
- :line => method.line
53
+ :line => method.line,
54
+ :message => "Remove unused method <%s%s%s>" % [
55
+ method.module_name,
56
+ method.class_method ? "." : "#",
57
+ method.name,
58
+ ],
55
59
  )
56
60
  end
57
61
  end
@@ -78,12 +82,30 @@ module Guideline
78
82
  end
79
83
 
80
84
  class MethodDefinitionChecker < MethodChecker
85
+ include Parser::Moduleable
86
+
81
87
  interesting_files /.*\.rb/
82
- interesting_nodes :def
88
+ interesting_nodes :def, :defs
83
89
 
84
90
  add_callback :start_def do |node|
85
- definition = Definition.new(:line => node.line, :name => node.method_name.to_s)
86
- call(definition)
91
+ call(
92
+ Definition.new(
93
+ :line => node.line,
94
+ :name => node.method_name.to_s,
95
+ :module_name => current_module_name,
96
+ )
97
+ )
98
+ end
99
+
100
+ add_callback :start_defs do |node|
101
+ call(
102
+ Definition.new(
103
+ :line => node.line,
104
+ :name => node.method_name.to_s,
105
+ :module_name => current_module_name,
106
+ :class_method => true,
107
+ )
108
+ )
87
109
  end
88
110
  end
89
111
 
@@ -0,0 +1,35 @@
1
+ module Guideline
2
+ class Parser
3
+ module Moduleable
4
+ def self.included(base)
5
+ base.class_eval do
6
+ interesting_nodes :class, :module
7
+
8
+ add_callback :start_class do |node|
9
+ modules << node.class_name.to_s
10
+ end
11
+
12
+ add_callback :start_module do |node|
13
+ modules << node.module_name.to_s
14
+ end
15
+
16
+ add_callback :end_class do |node|
17
+ modules.pop
18
+ end
19
+
20
+ add_callback :end_module do |node|
21
+ modules.pop
22
+ end
23
+ end
24
+ end
25
+
26
+ def current_module_name
27
+ modules.join("::")
28
+ end
29
+
30
+ def modules
31
+ @moduels ||= []
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Guideline
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ module Guideline
4
+ describe TrailingWhitespaceChecker do
5
+ describe "#check" do
6
+ let(:checker) do
7
+ described_class.new
8
+ end
9
+
10
+ let(:path) do
11
+ mock(:each_line => script.each_line)
12
+ end
13
+
14
+ context "when there is trailing whitespace" do
15
+ let(:script) do
16
+ <<-EOF
17
+ 1
18
+ EOF
19
+ end
20
+
21
+ it "detects error" do
22
+ checker.check(path)
23
+ checker.should have_error
24
+ end
25
+ end
26
+
27
+ context "when there is no trailing whitespace" do
28
+ let(:script) do
29
+ <<-EOF
30
+ 1
31
+ EOF
32
+ end
33
+
34
+ it "does not detect error" do
35
+ checker.check(path)
36
+ checker.should_not have_error
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -68,6 +68,44 @@ module Guideline
68
68
  checker.check(path)
69
69
  checker.send(:definitions).should be_empty
70
70
  end
71
+
72
+ context "when there is unused instance method" do
73
+ let(:script) do
74
+ <<-EOF
75
+ class A
76
+ def c
77
+ 1
78
+ end
79
+ end
80
+ EOF
81
+ end
82
+
83
+ it "reports it as instance method" do
84
+ checker.should_receive(:report) do |args|
85
+ args[:message].should include("A#c")
86
+ end
87
+ checker.check(path)
88
+ end
89
+ end
90
+
91
+ context "when there is unused class method" do
92
+ let(:script) do
93
+ <<-EOF
94
+ class A
95
+ def self.c
96
+ 1
97
+ end
98
+ end
99
+ EOF
100
+ end
101
+
102
+ it "reports it as class method" do
103
+ checker.should_receive(:report) do |args|
104
+ args[:message].should include("A.c")
105
+ end
106
+ checker.check(path)
107
+ end
108
+ end
71
109
  end
72
110
  end
73
111
  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.1.1
4
+ version: 0.1.2
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-02 00:00:00.000000000 Z
12
+ date: 2012-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slop
16
- requirement: &70218636493320 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70218636493320
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: code_analyzer
27
- requirement: &70218636492900 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70218636492900
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: activesupport
38
- requirement: &70218636492480 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70218636492480
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &70218636491980 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 2.12.0
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70218636491980
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: pry
60
- requirement: &70218636522520 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70218636522520
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: simplecov
71
- requirement: &70218636522060 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,7 +101,12 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70218636522060
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  description: Guideline.gem checks that your code is protectingthe rule of coding guideline
81
111
  email:
82
112
  - r7kamura@gmail.com
@@ -101,8 +131,10 @@ files:
101
131
  - lib/guideline/checkers/hash_comma_checker.rb
102
132
  - lib/guideline/checkers/long_line_checker.rb
103
133
  - lib/guideline/checkers/long_method_checker.rb
134
+ - lib/guideline/checkers/trailing_whitespace_checker.rb
104
135
  - lib/guideline/checkers/unused_method_checker.rb
105
136
  - lib/guideline/error.rb
137
+ - lib/guideline/parser/moduleable.rb
106
138
  - lib/guideline/runner.rb
107
139
  - lib/guideline/version.rb
108
140
  - lib/guideline/visitor.rb
@@ -113,11 +145,11 @@ files:
113
145
  - spec/guideline/checkers/hash_comma_checker_spec.rb
114
146
  - spec/guideline/checkers/long_line_checker_spec.rb
115
147
  - spec/guideline/checkers/long_method_checker_spec.rb
148
+ - spec/guideline/checkers/trailing_whitespace_checker_spec.rb
116
149
  - spec/guideline/checkers/unused_method_checker_spec.rb
117
150
  - spec/guideline/error_spec.rb
118
151
  - spec/guideline/runner_spec.rb
119
152
  - spec/guideline/visitor_spec.rb
120
- - spec/guideline_spec.rb
121
153
  - spec/spec_helper.rb
122
154
  homepage: https://github.com/r7kamura/guideline
123
155
  licenses: []
@@ -139,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
171
  version: '0'
140
172
  requirements: []
141
173
  rubyforge_project:
142
- rubygems_version: 1.8.15
174
+ rubygems_version: 1.8.24
143
175
  signing_key:
144
176
  specification_version: 3
145
177
  summary: The guideline of your code
@@ -151,10 +183,9 @@ test_files:
151
183
  - spec/guideline/checkers/hash_comma_checker_spec.rb
152
184
  - spec/guideline/checkers/long_line_checker_spec.rb
153
185
  - spec/guideline/checkers/long_method_checker_spec.rb
186
+ - spec/guideline/checkers/trailing_whitespace_checker_spec.rb
154
187
  - spec/guideline/checkers/unused_method_checker_spec.rb
155
188
  - spec/guideline/error_spec.rb
156
189
  - spec/guideline/runner_spec.rb
157
190
  - spec/guideline/visitor_spec.rb
158
- - spec/guideline_spec.rb
159
191
  - spec/spec_helper.rb
160
- has_rdoc:
@@ -1,4 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Guideline
4
- end