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 +4 -0
- data/README.rdoc +4 -1
- data/VERSION.yml +2 -2
- data/bin/excellent +17 -17
- data/lib/simplabs/excellent.rb +3 -1
- data/lib/simplabs/excellent/checks/base.rb +4 -0
- data/lib/simplabs/excellent/extensions/string.rb +5 -0
- data/lib/simplabs/excellent/parsing.rb +0 -2
- data/lib/simplabs/excellent/runner.rb +39 -1
- metadata +1 -1
data/History.txt
CHANGED
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
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
data/lib/simplabs/excellent.rb
CHANGED
@@ -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.
|
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
|
@@ -39,7 +39,7 @@ module Simplabs
|
|
39
39
|
#
|
40
40
|
# ==== Parameters
|
41
41
|
#
|
42
|
-
# * <tt>checks</tt> - The checks to apply -
|
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
|