simplabs-excellent 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ = 1.3.0
2
+
3
+ * added formatters (currently text and HTML formatting is supported, see README)
4
+
1
5
  = 1.2.2
2
6
 
3
7
  * fixed specs
data/README.rdoc CHANGED
@@ -17,7 +17,10 @@ To analyse all the models in your Rails application, just do
17
17
 
18
18
  excellent app/models
19
19
 
20
- in your <tt>RAILS_ROOT</tt>. You can also invoke analysation through the Simplabs::Excellent::Runner class.
20
+ in your <tt>RAILS_ROOT</tt>. You can also invoke analysation through the Simplabs::Excellent::Runner class. Excellent can also produce HTML output. To
21
+ get a formatted HTML report, just specify html:<filename>:
22
+
23
+ excellent html:out.html app/models
21
24
 
22
25
  == Static analysis
23
26
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 2
4
- :patch: 2
3
+ :minor: 3
4
+ :patch: 0
data/bin/excellent CHANGED
@@ -7,29 +7,29 @@ require 'pathname'
7
7
 
8
8
  excellent = Simplabs::Excellent::Runner.new
9
9
 
10
+ if ARGV.first =~ /html:[^\s]+/
11
+ begin
12
+ output = File.open(ARGV.first.sub(/html:/, ''), 'w+')
13
+ formatter = Simplabs::Excellent::Formatters::Html.new(output)
14
+ ARGV.shift
15
+ rescue
16
+ end
17
+ else
18
+ formatter = Simplabs::Excellent::Formatters::Text.new
19
+ end
20
+
10
21
  if ARGV.empty?
11
22
  puts "\n You must specify one or more directories to analyse, e.g.:\n"
12
23
  puts "\n excellent app/\n\n"
13
24
  exit 1
14
25
  end
15
26
 
16
- ARGV.each do |arg|
17
- if File.file?(arg)
18
- excellent.check_file(arg)
19
- elsif File.directory?(arg)
20
- Dir.glob("#{arg}/**/*.rb").each { |file| excellent.check_file(file) }
21
- else
22
- puts "\n** Excellent cannot find '#{arg}'\n\n"
23
- exit 1
24
- end
25
- end
26
-
27
- unless excellent.warnings.empty?
28
- puts "\n Warnings:\n\n"
29
- excellent.warnings.each do |warning|
30
- puts " * File #{warning.filename}, line #{warning.line_number}: #{warning.message}"
31
- end
27
+ begin
28
+ excellent.check_paths(ARGV, formatter)
29
+ rescue ArgumentError => ex
30
+ puts "EXCEPTION: #{ex.message}"
31
+ puts "\n** Excellent cannot find the paths specified!\n\n"
32
+ exit 1
32
33
  end
33
- puts "\n Found #{excellent.warnings.size} warnings.\n\n"
34
34
 
35
35
  exit 0
@@ -1,5 +1,7 @@
1
1
  require 'simplabs/excellent/checks'
2
2
  require 'simplabs/excellent/parsing'
3
+ require 'simplabs/excellent/formatters'
4
+ require 'simplabs/excellent/runner'
3
5
  require 'rubygems'
4
6
  require 'sexp'
5
7
 
@@ -7,7 +9,7 @@ module Simplabs #:nodoc:
7
9
 
8
10
  module Excellent #:nodoc:
9
11
 
10
- VERSION = '1.2.2'
12
+ VERSION = '1.3.0'
11
13
 
12
14
  end
13
15
 
@@ -42,6 +42,10 @@ module Simplabs
42
42
  @warnings << Simplabs::Excellent::Warning.new(klass, message, context.file, context.line + offset, info)
43
43
  end
44
44
 
45
+ def warnings_for(filename) #:nodoc:
46
+ warnings.select { |warning| warning.filename == filename }
47
+ end
48
+
45
49
  end
46
50
 
47
51
  end
@@ -14,6 +14,11 @@ module Simplabs
14
14
  downcase
15
15
  end
16
16
 
17
+ def lpad(to, with = ' ')
18
+ return self if self.length >= to
19
+ "#{with * (to - self.length)}#{self}"
20
+ end
21
+
17
22
  end
18
23
 
19
24
  end
@@ -8,5 +8,3 @@ module Simplabs
8
8
  end
9
9
 
10
10
  end
11
-
12
- require 'simplabs/excellent/runner'
@@ -39,7 +39,7 @@ module Simplabs
39
39
  #
40
40
  # ==== Parameters
41
41
  #
42
- # * <tt>checks</tt> - The checks to apply - passed instances of the various check classes. If no checks are specified, all checks will be applied.
42
+ # * <tt>checks</tt> - The checks to apply - pass instances of the various check classes. If no checks are specified, all checks will be applied.
43
43
  def initialize(*checks)
44
44
  @config = DEFAULT_CONFIG
45
45
  @checks = checks unless checks.empty?
@@ -77,6 +77,21 @@ module Simplabs
77
77
  check(filename, File.read(filename))
78
78
  end
79
79
 
80
+ # Processes the passed +paths+
81
+ #
82
+ # ==== Parameters
83
+ #
84
+ # * <tt>paths</tt> - The paths to process (specify file names or directories; will recursively process all ruby files if a directory are given).
85
+ # * <tt>formatter</tt> - The formatter to use. If a formatter is specified, its +start+, +file+, +warning+ and +end+ methods will be called
86
+ def check_paths(paths, formatter = nil)
87
+ formatter.start if formatter
88
+ collect_files(paths).each do |path|
89
+ check_file(path)
90
+ format_file_and_warnings(formatter, path) if formatter
91
+ end
92
+ formatter.end if formatter
93
+ end
94
+
80
95
  # Gets the warnings that were produced by the checks.
81
96
  def warnings
82
97
  @checks ||= []
@@ -98,6 +113,29 @@ module Simplabs
98
113
  check_objects
99
114
  end
100
115
 
116
+ def collect_files(paths)
117
+ files = []
118
+ paths.each do |path|
119
+ if File.file?(path)
120
+ files << path
121
+ elsif File.directory?(path)
122
+ files += Dir.glob(File.join(path, '**/*.rb'))
123
+ else
124
+ raise ArgumentError.new("#{path} is neither a File nor a directory!")
125
+ end
126
+ end
127
+ files
128
+ end
129
+
130
+ def format_file_and_warnings(formatter, filename)
131
+ warnings = @checks.map { |check| check.warnings_for(filename) }.flatten
132
+ if warnings.length > 0
133
+ formatter.file(filename) do |formatter|
134
+ warnings.sort { |x, y| x.line_number <=> y.line_number }.each { |warning| formatter.warning(warning) }
135
+ end
136
+ end
137
+ end
138
+
101
139
  end
102
140
 
103
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplabs-excellent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Otte-Witte