simplabs-excellent 1.3.0 → 1.3.1
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 +1 -1
- data/VERSION.yml +1 -1
- data/lib/simplabs/excellent.rb +1 -1
- data/lib/simplabs/excellent/command_line_runner.rb +37 -0
- data/lib/simplabs/excellent/formatters.rb +13 -0
- data/lib/simplabs/excellent/formatters/base.rb +49 -0
- data/lib/simplabs/excellent/formatters/html.rb +132 -0
- data/lib/simplabs/excellent/formatters/text.rb +40 -0
- metadata +6 -1
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -18,7 +18,7 @@ To analyse all the models in your Rails application, just do
|
|
18
18
|
excellent app/models
|
19
19
|
|
20
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>:
|
21
|
+
get a formatted HTML report, just specify <tt>html:<filename></tt>:
|
22
22
|
|
23
23
|
excellent html:out.html app/models
|
24
24
|
|
data/VERSION.yml
CHANGED
data/lib/simplabs/excellent.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'simplabs/excellent/runner'
|
2
|
+
require 'simplabs/excellent/formatters'
|
3
|
+
|
4
|
+
module Simplabs
|
5
|
+
|
6
|
+
module Excellent
|
7
|
+
|
8
|
+
class CommandLineRunner < Runner #:nodoc:
|
9
|
+
|
10
|
+
def initialize(*checks)
|
11
|
+
super
|
12
|
+
@formatter = Formatters::Text.new
|
13
|
+
@formatter.start
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_paths(paths)
|
17
|
+
paths.each do |path|
|
18
|
+
if File.file?(path)
|
19
|
+
check_file(path)
|
20
|
+
elsif File.directory?(path)
|
21
|
+
Dir.glob(File.join(path, '**/*.rb')).each { |file| check_file(file) }
|
22
|
+
else
|
23
|
+
next
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_file(filename)
|
29
|
+
super
|
30
|
+
@formatter.file(filename, (@checks || []).collect { |check| check.warnings }.flatten)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Simplabs
|
2
|
+
|
3
|
+
module Excellent
|
4
|
+
|
5
|
+
module Formatters
|
6
|
+
|
7
|
+
# The base class for all formatters.
|
8
|
+
class Base
|
9
|
+
|
10
|
+
# Initializes the formatter.
|
11
|
+
#
|
12
|
+
# Always call +super+ in custom formatters!
|
13
|
+
def initialize(stream)
|
14
|
+
@stream = stream
|
15
|
+
end
|
16
|
+
|
17
|
+
# Called when the Simplabs::Excellent::Runner starts processing code.
|
18
|
+
#
|
19
|
+
# The text formatter renders the heading here ('Excellent result')
|
20
|
+
def start
|
21
|
+
end
|
22
|
+
|
23
|
+
# Called whenever the Simplabs::Excellent::Runner processes a file. Yields the formatter
|
24
|
+
#
|
25
|
+
# You have to <tt>yield self</tt> in custom formatters. +file+ is called like that by the runner:
|
26
|
+
#
|
27
|
+
# formatter.file(filename) do |formatter|
|
28
|
+
# warnings.each { |warning| formatter.warning(warning) }
|
29
|
+
# end
|
30
|
+
def file(filename)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Called when the Simplabs::Excellent::Runner found a warning. This warning will always refer to the last filename, +file+ was invoked with.
|
34
|
+
def warning(warning)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Called when the Simplabs::Excellent::Runner ends processing code.
|
38
|
+
#
|
39
|
+
# The text formatter renders the footer here ('Found <x> warnings').
|
40
|
+
def end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'simplabs/excellent/formatters/base'
|
2
|
+
|
3
|
+
module Simplabs
|
4
|
+
|
5
|
+
module Excellent
|
6
|
+
|
7
|
+
module Formatters
|
8
|
+
|
9
|
+
class Html < Base #:nodoc:
|
10
|
+
|
11
|
+
def initialize(stream = $stdout)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def start
|
16
|
+
@stream.write(HEADER_TEMPLATE)
|
17
|
+
end
|
18
|
+
|
19
|
+
def file(filename)
|
20
|
+
@stream.write(START_FIlE_TAMPLATE.sub('{{filename}}', filename))
|
21
|
+
yield self
|
22
|
+
@stream.write(END_FIlE_TAMPLATE)
|
23
|
+
end
|
24
|
+
|
25
|
+
def warning(warning)
|
26
|
+
@stream.write(WARNING_TEMPLATE.sub('{{line_number}}', warning.line_number.to_s).sub('{{message}}', warning.message))
|
27
|
+
end
|
28
|
+
|
29
|
+
def end
|
30
|
+
@stream.write(FOOTER_TEMPLATE)
|
31
|
+
end
|
32
|
+
|
33
|
+
HEADER_TEMPLATE = <<-END
|
34
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
35
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
36
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
37
|
+
<head>
|
38
|
+
<title>Excellent result</title>
|
39
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
40
|
+
<style type="text/css">
|
41
|
+
body {
|
42
|
+
margin: 0;
|
43
|
+
padding: 0;
|
44
|
+
background: #fff;
|
45
|
+
font-size: 80%;
|
46
|
+
font-family: "Lucida Grande", Helvetica, sans-serif;
|
47
|
+
}
|
48
|
+
|
49
|
+
#header {
|
50
|
+
background: #ccc;
|
51
|
+
color: #000;
|
52
|
+
height: 4em;
|
53
|
+
}
|
54
|
+
|
55
|
+
#header h1 {
|
56
|
+
font-size: 1.8em;
|
57
|
+
margin: 0px 10px 0px 10px;
|
58
|
+
padding: 10px;
|
59
|
+
position: absolute;
|
60
|
+
}
|
61
|
+
|
62
|
+
#results {
|
63
|
+
margin: 0px 10px 5px;
|
64
|
+
}
|
65
|
+
|
66
|
+
dt {
|
67
|
+
background: #ccc;
|
68
|
+
padding: 5px;
|
69
|
+
font-weight: bold;
|
70
|
+
margin: 30px 0 0 0;
|
71
|
+
}
|
72
|
+
|
73
|
+
dd {
|
74
|
+
margin: 5px 0px 5px 20px;
|
75
|
+
}
|
76
|
+
|
77
|
+
dd.warning {
|
78
|
+
background: #faf834;
|
79
|
+
}
|
80
|
+
|
81
|
+
dd.warning span.lineNumber {
|
82
|
+
background: #ccc;
|
83
|
+
font-weight: bold;
|
84
|
+
padding: 3px;
|
85
|
+
display: inline-block;
|
86
|
+
margin: 0 10px 0 0;
|
87
|
+
}
|
88
|
+
|
89
|
+
dd.warning span.number {
|
90
|
+
width: 30px;
|
91
|
+
text-align: right;
|
92
|
+
display: inline-block;
|
93
|
+
}
|
94
|
+
</style>
|
95
|
+
</head>
|
96
|
+
<body>
|
97
|
+
<div id="header">
|
98
|
+
<div id="label">
|
99
|
+
<h1>Excellent result</h1>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
<div id="results">
|
103
|
+
END
|
104
|
+
|
105
|
+
START_FIlE_TAMPLATE = <<-END
|
106
|
+
<div class="file">
|
107
|
+
<dl>
|
108
|
+
<dt>{{filename}}</dt>
|
109
|
+
END
|
110
|
+
|
111
|
+
END_FIlE_TAMPLATE = <<-END
|
112
|
+
</dl>
|
113
|
+
</div>
|
114
|
+
END
|
115
|
+
|
116
|
+
WARNING_TEMPLATE = <<-END
|
117
|
+
<dd class="warning"><span class="lineNumber">Line <span class="number">{{line_number}}</span></span>{{message}}</dd>
|
118
|
+
END
|
119
|
+
|
120
|
+
FOOTER_TEMPLATE = <<-END
|
121
|
+
</div>
|
122
|
+
</body>
|
123
|
+
</html>
|
124
|
+
END
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'simplabs/excellent/formatters/base'
|
2
|
+
|
3
|
+
module Simplabs
|
4
|
+
|
5
|
+
module Excellent
|
6
|
+
|
7
|
+
module Formatters
|
8
|
+
|
9
|
+
class Text < Base #:nodoc:
|
10
|
+
|
11
|
+
def initialize(stream = $stdout)
|
12
|
+
super
|
13
|
+
@total_warnings = 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
@stream.puts "\n Excellent result:\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
def file(filename)
|
21
|
+
@stream.puts "\n #{filename}\n"
|
22
|
+
yield self
|
23
|
+
end
|
24
|
+
|
25
|
+
def warning(warning)
|
26
|
+
@stream.puts " * Line #{warning.line_number.to_s.lpad(3)}: \e[33m#{warning.message}\e[0m"
|
27
|
+
@total_warnings += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def end
|
31
|
+
@stream.puts "\n Found #{@total_warnings} warnings.\n\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
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.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Otte-Witte
|
@@ -75,8 +75,13 @@ files:
|
|
75
75
|
- lib/simplabs/excellent/checks/rails.rb
|
76
76
|
- lib/simplabs/excellent/checks/singleton_variable_check.rb
|
77
77
|
- lib/simplabs/excellent/checks.rb
|
78
|
+
- lib/simplabs/excellent/command_line_runner.rb
|
78
79
|
- lib/simplabs/excellent/extensions/sexp.rb
|
79
80
|
- lib/simplabs/excellent/extensions/string.rb
|
81
|
+
- lib/simplabs/excellent/formatters/base.rb
|
82
|
+
- lib/simplabs/excellent/formatters/html.rb
|
83
|
+
- lib/simplabs/excellent/formatters/text.rb
|
84
|
+
- lib/simplabs/excellent/formatters.rb
|
80
85
|
- lib/simplabs/excellent/parsing/abc_measure.rb
|
81
86
|
- lib/simplabs/excellent/parsing/block_context.rb
|
82
87
|
- lib/simplabs/excellent/parsing/call_context.rb
|