rubycritic 2.4.1 → 2.5.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/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/lib/rubycritic.rb +1 -19
- data/lib/rubycritic/cli/application.rb +2 -1
- data/lib/rubycritic/cli/options.rb +3 -2
- data/lib/rubycritic/command_factory.rb +24 -0
- data/lib/rubycritic/core/analysed_module.rb +4 -0
- data/lib/rubycritic/core/smell.rb +1 -1
- data/lib/rubycritic/generators/console_report.rb +18 -0
- data/lib/rubycritic/generators/text/list.rb +43 -0
- data/lib/rubycritic/generators/text/templates/list.erb +12 -0
- data/lib/rubycritic/reporter.rb +3 -0
- data/lib/rubycritic/version.rb +1 -1
- data/rubycritic.gemspec +1 -0
- data/test/lib/rubycritic/generators/console_report_test.rb +81 -0
- data/test/lib/rubycritic/{report_generators → generators}/turbulence_test.rb +0 -0
- data/test/lib/rubycritic/{report_generators → generators}/view_helpers_test.rb +0 -0
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5adb91703b4aa88b8328579edf0f7c085641db2d
|
4
|
+
data.tar.gz: 64b6f7e6ea46022ab9a585cc77badb21d1a350d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60f3072ea06df5f44c7e609c6e130e65034d07e88a3a03b0aaa50f7542887a0054781aa9c0652945c16420ba3786cd3e3b830164e1cf654e72efdc8c6feaf750
|
7
|
+
data.tar.gz: beaecb13950c18aa46dd3482ac62da1136caaad868bc451bfc28a46a5c9d8f9329e03f43ad81b2de5a77b0bf722bb5d5bf8deca97040a52def39d855c333d9a2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/rubycritic.rb
CHANGED
@@ -1,22 +1,4 @@
|
|
1
|
-
require "rubycritic/
|
1
|
+
require "rubycritic/command_factory"
|
2
2
|
|
3
3
|
module Rubycritic
|
4
|
-
def self.create(options = {})
|
5
|
-
options_hash = options.to_h
|
6
|
-
Config.set(options_hash)
|
7
|
-
case Config.mode
|
8
|
-
when :version
|
9
|
-
require "rubycritic/commands/version"
|
10
|
-
Command::Version.new
|
11
|
-
when :help
|
12
|
-
require "rubycritic/commands/help"
|
13
|
-
Command::Help.new(options.help_text)
|
14
|
-
when :ci
|
15
|
-
require "rubycritic/commands/ci"
|
16
|
-
Command::Ci.new(options_hash[:paths])
|
17
|
-
else
|
18
|
-
require "rubycritic/commands/default"
|
19
|
-
Command::Default.new(options_hash[:paths])
|
20
|
-
end
|
21
|
-
end
|
22
4
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "rubycritic"
|
2
2
|
require "rubycritic/cli/options"
|
3
|
+
require "rubycritic/command_factory"
|
3
4
|
|
4
5
|
module Rubycritic
|
5
6
|
module Cli
|
@@ -13,7 +14,7 @@ module Rubycritic
|
|
13
14
|
|
14
15
|
def execute
|
15
16
|
parsed_options = @options.parse
|
16
|
-
::Rubycritic.create(parsed_options).execute
|
17
|
+
::Rubycritic::CommandFactory.create(parsed_options).execute
|
17
18
|
STATUS_SUCCESS
|
18
19
|
rescue OptionParser::InvalidOption => error
|
19
20
|
$stderr.puts "Error: #{error}"
|
@@ -19,10 +19,11 @@ module Rubycritic
|
|
19
19
|
|
20
20
|
opts.on(
|
21
21
|
"-f", "--format [FORMAT]",
|
22
|
-
[:html, :json],
|
22
|
+
[:html, :json, :console],
|
23
23
|
"Report smells in the given format:",
|
24
24
|
" html (default)",
|
25
|
-
" json"
|
25
|
+
" json",
|
26
|
+
" console"
|
26
27
|
) do |format|
|
27
28
|
@format = format
|
28
29
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rubycritic/configuration"
|
2
|
+
|
3
|
+
module Rubycritic
|
4
|
+
class CommandFactory
|
5
|
+
def self.create(options = {})
|
6
|
+
options_hash = options.to_h
|
7
|
+
Config.set(options_hash)
|
8
|
+
case Config.mode
|
9
|
+
when :version
|
10
|
+
require "rubycritic/commands/version"
|
11
|
+
Command::Version.new
|
12
|
+
when :help
|
13
|
+
require "rubycritic/commands/help"
|
14
|
+
Command::Help.new(options.help_text)
|
15
|
+
when :ci
|
16
|
+
require "rubycritic/commands/ci"
|
17
|
+
Command::Ci.new(options_hash[:paths])
|
18
|
+
else
|
19
|
+
require "rubycritic/commands/default"
|
20
|
+
Command::Default.new(options_hash[:paths])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rubycritic/generators/text/list"
|
2
|
+
|
3
|
+
module Rubycritic
|
4
|
+
module Generator
|
5
|
+
class ConsoleReport
|
6
|
+
def initialize(analysed_modules)
|
7
|
+
@analysed_modules = analysed_modules
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_report
|
11
|
+
reports = @analysed_modules.sort.map do |mod|
|
12
|
+
Text::List.new(mod).render
|
13
|
+
end
|
14
|
+
puts reports.join("\n")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "colorize"
|
2
|
+
|
3
|
+
module Rubycritic
|
4
|
+
module Generator
|
5
|
+
module Text
|
6
|
+
class List
|
7
|
+
class << self
|
8
|
+
TEMPLATE_PATH = File.expand_path("../templates/list.erb", __FILE__)
|
9
|
+
|
10
|
+
def erb_template
|
11
|
+
@erb_template ||= ERB.new(File.read(TEMPLATE_PATH), nil, "-")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RATING_TO_COLOR = {
|
16
|
+
"A" => :green,
|
17
|
+
"B" => :green,
|
18
|
+
"C" => :yellow,
|
19
|
+
"D" => :light_red,
|
20
|
+
"F" => :red
|
21
|
+
}
|
22
|
+
|
23
|
+
def initialize(analysed_module)
|
24
|
+
@analysed_module = analysed_module
|
25
|
+
end
|
26
|
+
|
27
|
+
def render
|
28
|
+
erb_template.result(binding)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def erb_template
|
34
|
+
self.class.erb_template
|
35
|
+
end
|
36
|
+
|
37
|
+
def color
|
38
|
+
@color ||= RATING_TO_COLOR[@analysed_module.rating.to_s]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%= @analysed_module.name.colorize(color) %>:
|
2
|
+
Rating: <%= @analysed_module.rating.to_s.colorize(color) %>
|
3
|
+
Churn: <%= @analysed_module.churn %>
|
4
|
+
Complexity: <%= @analysed_module.complexity %>
|
5
|
+
Duplication: <%= @analysed_module.duplication %>
|
6
|
+
Smells: <%= @analysed_module.smells.count %>
|
7
|
+
<%- @analysed_module.smells.each do |smell| -%>
|
8
|
+
* <%= smell %>
|
9
|
+
<%- smell.locations.each do |location| -%>
|
10
|
+
- <%= location %>
|
11
|
+
<%- end -%>
|
12
|
+
<%- end -%>
|
data/lib/rubycritic/reporter.rb
CHANGED
@@ -10,6 +10,9 @@ module Rubycritic
|
|
10
10
|
when :json
|
11
11
|
require "rubycritic/generators/json_report"
|
12
12
|
Generator::JsonReport
|
13
|
+
when :console
|
14
|
+
require "rubycritic/generators/console_report"
|
15
|
+
Generator::ConsoleReport
|
13
16
|
else
|
14
17
|
require "rubycritic/generators/html_report"
|
15
18
|
Generator::HtmlReport
|
data/lib/rubycritic/version.rb
CHANGED
data/rubycritic.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_runtime_dependency "flog", "4.3.2"
|
26
26
|
spec.add_runtime_dependency "reek", "3.8.1"
|
27
27
|
spec.add_runtime_dependency "parser", ">= 2.2.0", "< 3.0"
|
28
|
+
spec.add_runtime_dependency "colorize"
|
28
29
|
|
29
30
|
spec.add_development_dependency "bundler", "~> 1.3"
|
30
31
|
spec.add_development_dependency "rake"
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rubycritic/generators/console_report"
|
3
|
+
require "rubycritic/core/rating"
|
4
|
+
require "rubycritic/core/smell"
|
5
|
+
|
6
|
+
describe Rubycritic::Generator::ConsoleReport do
|
7
|
+
describe "#generate_report" do
|
8
|
+
before do
|
9
|
+
@mock_analysed_module = mock_analysed_module
|
10
|
+
capture_output_streams do
|
11
|
+
report = Rubycritic::Generator::ConsoleReport.new([@mock_analysed_module])
|
12
|
+
report.generate_report
|
13
|
+
@output = $stdout.tap(&:rewind).read
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "outputs the report to the stdout" do
|
18
|
+
assert @output.size > 0, "expected report to be output to stdout"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "starts the report with the module's name" do
|
22
|
+
lines = @output.split("\n")
|
23
|
+
assert lines[0][/#{mock_analysed_module.name}/]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "includes the module's rating in the report" do
|
27
|
+
assert output_contains?("Rating", @mock_analysed_module.rating)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "includes the module's rating in the report" do
|
31
|
+
assert output_contains?("Churn", @mock_analysed_module.churn)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "includes the module's rating in the report" do
|
35
|
+
assert output_contains?("Complexity", @mock_analysed_module.complexity)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "includes the module's rating in the report" do
|
39
|
+
assert output_contains?("Duplication", @mock_analysed_module.duplication)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "includes the number of smells in the report" do
|
43
|
+
assert output_contains?("Smells", @mock_analysed_module.smells.count)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "includes the smell and its attributes in the report" do
|
47
|
+
@mock_analysed_module.smells.each do |smell|
|
48
|
+
assert output_contains?(smell), "expected smell type and context to be reported"
|
49
|
+
smell.locations.each do |location|
|
50
|
+
assert output_contains?(location), "expected all smell locations to be reported"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def output_contains?(*strs)
|
56
|
+
@lines ||= @output.split("\n")
|
57
|
+
expr = strs.map(&:to_s).map! { |s| Regexp.escape(s) }.join(".*")
|
58
|
+
@lines.any? { |l| l[/#{expr}/] }
|
59
|
+
end
|
60
|
+
|
61
|
+
def mock_analysed_module
|
62
|
+
OpenStruct.new(
|
63
|
+
:name => "TestModule",
|
64
|
+
:rating => Rubycritic::Rating.from_cost(3),
|
65
|
+
:churn => 10,
|
66
|
+
:complexity => 0,
|
67
|
+
:duplication => 20,
|
68
|
+
:smells => [mock_smell]
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def mock_smell
|
73
|
+
smell = Rubycritic::Smell.new
|
74
|
+
smell.locations << Rubycritic::Location.new(__FILE__, 3)
|
75
|
+
smell.type = "SmellySmell"
|
76
|
+
smell.context = "You"
|
77
|
+
smell.message = "Seriously, take a shower or something"
|
78
|
+
smell
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubycritic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Simoes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -86,6 +86,20 @@ dependencies:
|
|
86
86
|
- - "<"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '3.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: colorize
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
104
|
name: bundler
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -193,6 +207,7 @@ files:
|
|
193
207
|
- lib/rubycritic/cli/application.rb
|
194
208
|
- lib/rubycritic/cli/options.rb
|
195
209
|
- lib/rubycritic/colorize.rb
|
210
|
+
- lib/rubycritic/command_factory.rb
|
196
211
|
- lib/rubycritic/commands/ci.rb
|
197
212
|
- lib/rubycritic/commands/default.rb
|
198
213
|
- lib/rubycritic/commands/help.rb
|
@@ -203,6 +218,7 @@ files:
|
|
203
218
|
- lib/rubycritic/core/location.rb
|
204
219
|
- lib/rubycritic/core/rating.rb
|
205
220
|
- lib/rubycritic/core/smell.rb
|
221
|
+
- lib/rubycritic/generators/console_report.rb
|
206
222
|
- lib/rubycritic/generators/html/assets/javascripts/application.js
|
207
223
|
- lib/rubycritic/generators/html/assets/javascripts/highcharts.src-4.0.1.js
|
208
224
|
- lib/rubycritic/generators/html/assets/javascripts/jquery-2.1.0.js
|
@@ -231,6 +247,8 @@ files:
|
|
231
247
|
- lib/rubycritic/generators/html_report.rb
|
232
248
|
- lib/rubycritic/generators/json/simple.rb
|
233
249
|
- lib/rubycritic/generators/json_report.rb
|
250
|
+
- lib/rubycritic/generators/text/list.rb
|
251
|
+
- lib/rubycritic/generators/text/templates/list.erb
|
234
252
|
- lib/rubycritic/reporter.rb
|
235
253
|
- lib/rubycritic/revision_comparator.rb
|
236
254
|
- lib/rubycritic/serializer.rb
|
@@ -256,8 +274,9 @@ files:
|
|
256
274
|
- test/lib/rubycritic/core/location_test.rb
|
257
275
|
- test/lib/rubycritic/core/smell_test.rb
|
258
276
|
- test/lib/rubycritic/core/smells_array_test.rb
|
259
|
-
- test/lib/rubycritic/
|
260
|
-
- test/lib/rubycritic/
|
277
|
+
- test/lib/rubycritic/generators/console_report_test.rb
|
278
|
+
- test/lib/rubycritic/generators/turbulence_test.rb
|
279
|
+
- test/lib/rubycritic/generators/view_helpers_test.rb
|
261
280
|
- test/lib/rubycritic/smells_status_setter_test.rb
|
262
281
|
- test/lib/rubycritic/source_control_systems/base_test.rb
|
263
282
|
- test/lib/rubycritic/source_control_systems/double_test.rb
|
@@ -322,8 +341,9 @@ test_files:
|
|
322
341
|
- test/lib/rubycritic/core/location_test.rb
|
323
342
|
- test/lib/rubycritic/core/smell_test.rb
|
324
343
|
- test/lib/rubycritic/core/smells_array_test.rb
|
325
|
-
- test/lib/rubycritic/
|
326
|
-
- test/lib/rubycritic/
|
344
|
+
- test/lib/rubycritic/generators/console_report_test.rb
|
345
|
+
- test/lib/rubycritic/generators/turbulence_test.rb
|
346
|
+
- test/lib/rubycritic/generators/view_helpers_test.rb
|
327
347
|
- test/lib/rubycritic/smells_status_setter_test.rb
|
328
348
|
- test/lib/rubycritic/source_control_systems/base_test.rb
|
329
349
|
- test/lib/rubycritic/source_control_systems/double_test.rb
|