roodi 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc65ef0c9ffac9f896579cda0a56572065ea813f
4
- data.tar.gz: 8c0c7e0b9ca16a6f2e2597fc38677c6ac12ea663
3
+ metadata.gz: 3e40866579e8df51093c4bce137a04710c118548
4
+ data.tar.gz: e2141d7d84ca7cc12bc4d2fa483335eaa7c0f5e6
5
5
  SHA512:
6
- metadata.gz: e5ff37f5f09ebfab6113e5fcf9e0705998ff1067174df0be337f4ee3b42fcfadc1273639e7447e56b26bb89089879f16e2fbd5d8a68598473211f345b2e38eb9
7
- data.tar.gz: 6f07ed9c3bb7f711daf43f5ce2108b98654f06a315aed57c83e3d0d236d790a517d8811868d98e3ac18db5fa588504718e2541839107b3a7fe85e9e39a95edd4
6
+ metadata.gz: 600ff6529f75c763aed4de9b8c63b9b0f01eea3018c5290899b7ce9cf4a07a5c4e926baedeabf9ef8f4bad8b99669c36975f05058ebf720e878d229aa5b6ab90
7
+ data.tar.gz: 76e602ff62a8a0e2427ab2e6090e73fb6b5e565dcd1dc37b31dd3ec82beaea0f282cea4dab52f9c1487ead8584227efcdc558bbdd54311646f0a9ebe4e735d51
@@ -1,3 +1,7 @@
1
+ = 3.3.0
2
+ * Using the roodi.yml in the current folder by default if it exists
3
+ * Added coloured output
4
+
1
5
  = 3.2.0
2
6
  * Checks all files under current directory by default
3
7
  * Made it easier to run for the whole project as a rake task
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
@@ -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 = DEFAULT_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 = YAML.load_file @config
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
@@ -1,3 +1,3 @@
1
1
  module Roodi
2
- VERSION = '3.2.0'
2
+ VERSION = '3.3.0'
3
3
  end
@@ -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
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.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marty Andrews