roodi 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +5 -0
- data/lib/roodi/checks/empty_rescue_body_check.rb +3 -14
- data/lib/roodi/checks/line_count_check.rb +0 -8
- data/lib/roodi/core/runner.rb +6 -1
- data/lib/roodi/version.rb +1 -1
- data/roodi.gemspec +6 -6
- data/spec/roodi/checks/class_line_count_check_spec.rb +2 -2
- data/spec/roodi/checks/empty_rescue_body_check_spec.rb +59 -1
- data/spec/roodi/checks/method_name_check_spec.rb +3 -3
- data/spec/roodi/core/runner_spec.rb +20 -8
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fe93f143f769ff54f5113a656f2069c9e608070
|
4
|
+
data.tar.gz: e816fefa85c0c9294d8e2370eb7cd5f9715f8c02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7142c98fcb6fffb1c48038118c46da45168d12f95eb9517b4b77e69b38e29c5aadeffdb01fb3679a837704323a312507542e2ec7806e2105f9927b987a5862
|
7
|
+
data.tar.gz: 9e8e8147ccc6d25e5a3866a2eb536122c6bfdec6c8b1a166047937e99618416c327f523c887e93a56390ce30ed7fb672e02f9bb75924a21df13119fd0ebba3dc
|
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= 3.1.0
|
2
|
+
* Loosen ruby_parser version dependency (PR from Benjamin Fleischer)
|
3
|
+
* Files that can't be parsed are no longer silently skipped
|
4
|
+
* Empty rescue body check not failing when block contains empty arrays etc
|
5
|
+
|
1
6
|
= 3.0.1
|
2
7
|
|
3
8
|
* Added brief class level documentation on all checks
|
@@ -3,30 +3,19 @@ require 'roodi/checks/check'
|
|
3
3
|
module Roodi
|
4
4
|
module Checks
|
5
5
|
# Checks the body of a rescue block to make sure it's not empty..
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# When the body of a rescue block is empty, exceptions can get caught and swallowed without
|
8
8
|
# any feedback to the user.
|
9
9
|
class EmptyRescueBodyCheck < Check
|
10
|
-
|
11
|
-
|
10
|
+
|
12
11
|
def interesting_nodes
|
13
12
|
[:resbody]
|
14
13
|
end
|
15
14
|
|
16
15
|
def evaluate_start(node)
|
17
|
-
add_error("Rescue block should not be empty.")
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def has_statement?(node)
|
23
|
-
false unless node
|
24
|
-
has_local_statement?(node) or node.children.any? { |child| has_statement?(child) } if node
|
16
|
+
add_error("Rescue block should not be empty.") if node.children[1].nil?
|
25
17
|
end
|
26
18
|
|
27
|
-
def has_local_statement?(node)
|
28
|
-
STATEMENT_NODES.include?(node.node_type)
|
29
|
-
end
|
30
19
|
end
|
31
20
|
end
|
32
21
|
end
|
@@ -16,14 +16,6 @@ module Roodi
|
|
16
16
|
|
17
17
|
def count_lines(node)
|
18
18
|
node.last.respond_to?(:line) ? node.last.line - node.line : 0
|
19
|
-
|
20
|
-
rescue NoMethodError => e
|
21
|
-
#TODO: Add spec for this, nothing breaks when removing it.
|
22
|
-
if ENV['DEBUG'] =~ /true/i
|
23
|
-
STDERR.puts "!! line counting error #{e.message}\t #{node.inspect}"
|
24
|
-
STDERR.puts "!! Does the node have any lines?"
|
25
|
-
end
|
26
|
-
0
|
27
19
|
end
|
28
20
|
|
29
21
|
end
|
data/lib/roodi/core/runner.rb
CHANGED
@@ -52,6 +52,7 @@ module Roodi
|
|
52
52
|
@checks ||= []
|
53
53
|
all_errors = @checks.collect {|check| check.errors}
|
54
54
|
all_errors.flatten
|
55
|
+
all_errors.flatten + parsing_errors
|
55
56
|
end
|
56
57
|
|
57
58
|
private
|
@@ -60,11 +61,15 @@ module Roodi
|
|
60
61
|
begin
|
61
62
|
Parser.new.parse(content, filename)
|
62
63
|
rescue Exception => e
|
63
|
-
|
64
|
+
parsing_errors << "#{filename} looks like it's not a valid Ruby file."
|
64
65
|
nil
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
69
|
+
def parsing_errors
|
70
|
+
@parsing_errors ||= []
|
71
|
+
end
|
72
|
+
|
68
73
|
def load_checks
|
69
74
|
check_objects = []
|
70
75
|
checks = YAML.load_file @config
|
data/lib/roodi/version.rb
CHANGED
data/roodi.gemspec
CHANGED
@@ -8,16 +8,16 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.description = "Roodi parses your Ruby code and warns you about design issues you have based on the checks that is has configured"
|
9
9
|
gem.homepage = "http://github.com/roodi/roodi"
|
10
10
|
gem.authors = ["Marty Andrews", "Peter Evjan"]
|
11
|
-
gem.email = "
|
11
|
+
gem.email = "hello@peterevjan.com"
|
12
12
|
gem.files = Dir['lib/**/*.rb'] + Dir['bin/*'] + Dir['[A-Za-z]*'] + Dir['spec/**/*']
|
13
13
|
gem.version = Roodi::VERSION.dup
|
14
14
|
gem.platform = Gem::Platform::RUBY
|
15
|
-
gem.add_runtime_dependency("ruby_parser", "
|
15
|
+
gem.add_runtime_dependency("ruby_parser", [">= 3.2.2", "~> 3.2"])
|
16
16
|
gem.executables = ["roodi", "roodi-describe"]
|
17
|
-
gem.files
|
18
|
-
gem.test_files
|
19
|
-
gem.executables
|
17
|
+
gem.files = `git ls-files`.split($\)
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
20
|
gem.require_paths = ["lib"]
|
21
|
-
gem.license
|
21
|
+
gem.license = 'MIT'
|
22
22
|
|
23
23
|
end
|
@@ -4,7 +4,7 @@ describe Roodi::Checks::ClassLineCountCheck do
|
|
4
4
|
before(:each) do
|
5
5
|
@roodi = Roodi::Core::Runner.new(Roodi::Checks::ClassLineCountCheck.make({'line_count' => 1}))
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
it "should accept classes with less lines than the threshold" do
|
9
9
|
content = <<-END
|
10
10
|
class ZeroLineClass
|
@@ -16,7 +16,7 @@ describe Roodi::Checks::ClassLineCountCheck do
|
|
16
16
|
|
17
17
|
it "should accept classes with the same number of lines as the threshold" do
|
18
18
|
content = <<-END
|
19
|
-
|
19
|
+
class OneLineClass
|
20
20
|
@foo = 1
|
21
21
|
end
|
22
22
|
END
|
@@ -4,7 +4,7 @@ describe Roodi::Checks::EmptyRescueBodyCheck do
|
|
4
4
|
before(:each) do
|
5
5
|
@roodi = Roodi::Core::Runner.new(Roodi::Checks::EmptyRescueBodyCheck.make)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
it "should accept a rescue body with content and no parameter" do
|
9
9
|
content = <<-END
|
10
10
|
begin
|
@@ -151,4 +151,62 @@ describe Roodi::Checks::EmptyRescueBodyCheck do
|
|
151
151
|
errors.should be_empty
|
152
152
|
end
|
153
153
|
|
154
|
+
it "should accept a rescue block that has only an empty array" do
|
155
|
+
content = <<-END
|
156
|
+
begin
|
157
|
+
@path.dirname.children
|
158
|
+
rescue Errno::ENOENT
|
159
|
+
[]
|
160
|
+
end
|
161
|
+
END
|
162
|
+
@roodi.check_content(content)
|
163
|
+
errors = @roodi.errors
|
164
|
+
errors.should be_empty
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should accept a rescue block that has only the argument passed to the method" do
|
168
|
+
content = <<-END
|
169
|
+
def method_name(text)
|
170
|
+
begin
|
171
|
+
processed_text = text.some.processing.on.it
|
172
|
+
rescue
|
173
|
+
text
|
174
|
+
end
|
175
|
+
end
|
176
|
+
END
|
177
|
+
|
178
|
+
@roodi.check_content(content)
|
179
|
+
errors = @roodi.errors
|
180
|
+
errors.should be_empty
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should accept a rescue block without a starting begin block" do
|
184
|
+
content = <<-RUBY
|
185
|
+
def process_text(text)
|
186
|
+
processed_text = text.some.processing.on.it
|
187
|
+
rescue
|
188
|
+
text
|
189
|
+
end
|
190
|
+
RUBY
|
191
|
+
|
192
|
+
@roodi.check_content(content)
|
193
|
+
errors = @roodi.errors
|
194
|
+
errors.should be_empty
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should reject a rescue block that only contains a comment" do
|
198
|
+
content = <<-END
|
199
|
+
begin
|
200
|
+
@path.dirname.children
|
201
|
+
rescue Errno::ENOENT
|
202
|
+
# Comment
|
203
|
+
end
|
204
|
+
END
|
205
|
+
|
206
|
+
@roodi.check_content(content)
|
207
|
+
errors = @roodi.errors
|
208
|
+
errors.should_not be_empty
|
209
|
+
errors[0].to_s.should match(/dummy-file.rb:[5] - Rescue block should not be empty./)
|
210
|
+
end
|
211
|
+
|
154
212
|
end
|
@@ -4,7 +4,7 @@ describe Roodi::Checks::MethodNameCheck do
|
|
4
4
|
before(:each) do
|
5
5
|
@roodi = Roodi::Core::Runner.new(Roodi::Checks::MethodNameCheck.make)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
it "should accept method names with underscores" do
|
9
9
|
content = <<-END
|
10
10
|
def good_method_name
|
@@ -40,7 +40,7 @@ describe Roodi::Checks::MethodNameCheck do
|
|
40
40
|
@roodi.check_content(content)
|
41
41
|
@roodi.errors.should be_empty
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "should accept method names ending an equals sign" do
|
45
45
|
content = <<-END
|
46
46
|
def good_method_name=
|
@@ -51,7 +51,7 @@ describe Roodi::Checks::MethodNameCheck do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "when processing non-text based method names" do
|
54
|
-
['<<', '>>', '==', '
|
54
|
+
['<<', '>>', '==', '<', '<=', '>', '>=', '[]', '[]='].each do |each|
|
55
55
|
it "should accept #{each} as a method name" do
|
56
56
|
content = <<-END
|
57
57
|
def #{each}
|
@@ -1,15 +1,14 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
3
|
describe Roodi::Core::Runner do
|
4
|
-
|
4
|
+
subject { Roodi::Core::Runner.new }
|
5
|
+
|
5
6
|
describe "given a custom config file" do
|
6
7
|
before do
|
7
|
-
|
8
|
-
@runner.config= File.expand_path(File.dirname(__FILE__) + '/../roodi.yml')
|
8
|
+
subject.config= File.expand_path(File.dirname(__FILE__) + '/../roodi.yml')
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "uses check from it" do
|
12
|
-
# @runner.check_file(File.expand_path(File.dirname(__FILE__) + '/../fixtures/test_class.rb'))
|
13
12
|
content = <<-RUBY
|
14
13
|
class TestClass
|
15
14
|
|
@@ -18,8 +17,21 @@ describe Roodi::Core::Runner do
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
RUBY
|
21
|
-
|
22
|
-
|
20
|
+
subject.check_content(content)
|
21
|
+
subject.errors.should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "running against a file" do
|
26
|
+
it "adds an error if file is not valid ruby" do
|
27
|
+
content = <<-END
|
28
|
+
<html>
|
29
|
+
</html>
|
30
|
+
END
|
31
|
+
subject.check_content(content)
|
32
|
+
expect(subject.errors).to_not be_empty
|
33
|
+
expect(subject.errors[0]).to eq "dummy-file.rb looks like it's not a valid Ruby file."
|
23
34
|
end
|
24
35
|
end
|
25
|
-
|
36
|
+
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roodi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marty Andrews
|
@@ -9,25 +9,31 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby_parser
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 3.2.2
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '3.2'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: 3.2.2
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
28
34
|
description: Roodi parses your Ruby code and warns you about design issues you have
|
29
35
|
based on the checks that is has configured
|
30
|
-
email:
|
36
|
+
email: hello@peterevjan.com
|
31
37
|
executables:
|
32
38
|
- roodi
|
33
39
|
- roodi-describe
|