roodi 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.txt +4 -0
- data/bin/roodi +0 -6
- data/lib/roodi/core/runner.rb +33 -4
- data/lib/roodi/version.rb +1 -1
- data/lib/roodi_task.rb +0 -8
- data/spec/roodi/core/runner_spec.rb +31 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e40866579e8df51093c4bce137a04710c118548
|
4
|
+
data.tar.gz: e2141d7d84ca7cc12bc4d2fa483335eaa7c0f5e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 600ff6529f75c763aed4de9b8c63b9b0f01eea3018c5290899b7ce9cf4a07a5c4e926baedeabf9ef8f4bad8b99669c36975f05058ebf720e878d229aa5b6ab90
|
7
|
+
data.tar.gz: 76e602ff62a8a0e2427ab2e6090e73fb6b5e565dcd1dc37b31dd3ec82beaea0f282cea4dab52f9c1487ead8584227efcdc558bbdd54311646f0a9ebe4e735d51
|
data/History.txt
CHANGED
data/bin/roodi
CHANGED
@@ -10,12 +10,6 @@ config_param = ARGV.detect {|arg| arg =~ /-config=.*/}
|
|
10
10
|
runner.config = config_param.split("=")[1] if config_param
|
11
11
|
ARGV.delete config_param
|
12
12
|
|
13
|
-
puts "\nRunning Roodi checks"
|
14
|
-
|
15
13
|
runner.start(ARGV)
|
16
|
-
runner.errors.each {|error| puts error}
|
17
|
-
|
18
|
-
puts "\nChecked #{runner.files_checked} files"
|
19
|
-
puts "Found #{runner.errors.size} errors"
|
20
14
|
|
21
15
|
exit runner.errors.size
|
data/lib/roodi/core/runner.rb
CHANGED
@@ -8,23 +8,49 @@ require 'roodi/core/visitable_sexp'
|
|
8
8
|
module Roodi
|
9
9
|
module Core
|
10
10
|
class Runner
|
11
|
-
DEFAULT_CONFIG = File.join(File.dirname(__FILE__), "..", "..", "..", "roodi.yml")
|
12
|
-
|
13
11
|
attr_writer :config
|
14
12
|
attr_reader :files_checked
|
15
13
|
|
16
14
|
def initialize(*checks)
|
17
|
-
@config =
|
15
|
+
@config = default_config
|
18
16
|
@checks = checks unless checks.empty?
|
19
17
|
end
|
20
18
|
|
19
|
+
def default_config
|
20
|
+
project_config ? project_config : roodi_gem_config
|
21
|
+
end
|
22
|
+
|
23
|
+
def roodi_gem_config
|
24
|
+
File.join(File.dirname(__FILE__), "..", "..", "..", "roodi.yml")
|
25
|
+
end
|
26
|
+
|
27
|
+
def project_config
|
28
|
+
File.exists?("roodi.yml") ? "roodi.yml" : nil
|
29
|
+
end
|
30
|
+
|
21
31
|
def start(paths)
|
32
|
+
puts "\nRunning Roodi checks"
|
33
|
+
|
22
34
|
paths = ['.'] if paths == []
|
23
35
|
all_files = collect_files(paths)
|
24
36
|
@files_checked = all_files.count
|
25
37
|
all_files.each do |path|
|
26
38
|
check_file(path)
|
27
39
|
end
|
40
|
+
|
41
|
+
output_result(errors, @files_checked)
|
42
|
+
end
|
43
|
+
|
44
|
+
def output_result(errors, files_checked)
|
45
|
+
errors.each {|error| puts "\e[31m#{error}\e[0m"}
|
46
|
+
|
47
|
+
puts "\nChecked #{files_checked} files"
|
48
|
+
result = "Found #{errors.size} errors."
|
49
|
+
if errors.empty?
|
50
|
+
puts "\e[32m#{result}\e[0m"
|
51
|
+
else
|
52
|
+
raise "\e[31m#{result}\e[0m"
|
53
|
+
end
|
28
54
|
end
|
29
55
|
|
30
56
|
def collect_files(paths)
|
@@ -96,7 +122,7 @@ module Roodi
|
|
96
122
|
|
97
123
|
def load_checks
|
98
124
|
check_objects = []
|
99
|
-
checks =
|
125
|
+
checks = load_config(@config)
|
100
126
|
checks.each do |check_class_name, options|
|
101
127
|
check_class = Roodi::Checks.const_get(check_class_name)
|
102
128
|
check_objects << check_class.make(options || {})
|
@@ -104,6 +130,9 @@ module Roodi
|
|
104
130
|
check_objects
|
105
131
|
end
|
106
132
|
|
133
|
+
def load_config(config_file)
|
134
|
+
YAML.load_file config_file
|
135
|
+
end
|
107
136
|
end
|
108
137
|
end
|
109
138
|
end
|
data/lib/roodi/version.rb
CHANGED
data/lib/roodi_task.rb
CHANGED
@@ -21,19 +21,11 @@ class RoodiTask < Rake::TaskLib
|
|
21
21
|
def define
|
22
22
|
desc "Run Roodi against all source files"
|
23
23
|
task name do
|
24
|
-
puts "\nRunning Roodi checks"
|
25
|
-
|
26
24
|
runner = Roodi::Core::Runner.new
|
27
25
|
|
28
26
|
runner.config = config if config
|
29
27
|
|
30
28
|
runner.start(@patterns)
|
31
|
-
|
32
|
-
runner.errors.each {|error| puts error}
|
33
|
-
|
34
|
-
puts "\nChecked #{runner.files_checked} files"
|
35
|
-
|
36
|
-
raise "Found #{runner.errors.size} errors." unless runner.errors.empty?
|
37
29
|
end
|
38
30
|
self
|
39
31
|
end
|
@@ -3,25 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
3
3
|
describe Roodi::Core::Runner do
|
4
4
|
subject { Roodi::Core::Runner.new }
|
5
5
|
|
6
|
-
describe "given a custom config file" do
|
7
|
-
before do
|
8
|
-
subject.config= File.expand_path(File.dirname(__FILE__) + '/../roodi.yml')
|
9
|
-
end
|
10
|
-
|
11
|
-
it "uses check from it" do
|
12
|
-
content = <<-RUBY
|
13
|
-
class TestClass
|
14
|
-
|
15
|
-
def METHOD
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
RUBY
|
20
|
-
subject.check_content(content)
|
21
|
-
subject.errors.should be_empty
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
6
|
describe "running against a file" do
|
26
7
|
it "adds an error if file is not valid ruby" do
|
27
8
|
content = <<-END
|
@@ -53,4 +34,35 @@ describe Roodi::Core::Runner do
|
|
53
34
|
end
|
54
35
|
end
|
55
36
|
|
37
|
+
describe "configuration" do
|
38
|
+
context "given a custom config file" do
|
39
|
+
before do
|
40
|
+
subject.config= File.expand_path(File.dirname(__FILE__) + '/../roodi.yml')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "uses check from it" do
|
44
|
+
content = <<-RUBY
|
45
|
+
class TestClass
|
46
|
+
|
47
|
+
def METHOD
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
RUBY
|
52
|
+
subject.check_content(content)
|
53
|
+
subject.errors.should be_empty
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "uses the default config if none given" do
|
58
|
+
subject.stub(:project_config) { nil }
|
59
|
+
expect(subject.default_config).to eq subject.default_config
|
60
|
+
end
|
61
|
+
|
62
|
+
it "uses roodi.yml if it exists" do
|
63
|
+
subject.stub(:project_config) { "roodi.yml" }
|
64
|
+
expect(subject.default_config).to eq "roodi.yml"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
56
68
|
end
|