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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94afa6a36845ed427f723017ab3ae8c1dbb1bf45
4
- data.tar.gz: 76b2b5a795e9c0f4a64c612211f0dda8c23058b5
3
+ metadata.gz: 5adb91703b4aa88b8328579edf0f7c085641db2d
4
+ data.tar.gz: 64b6f7e6ea46022ab9a585cc77badb21d1a350d2
5
5
  SHA512:
6
- metadata.gz: 83dc3bddc791df06b118ebce1a51a7aec17f4f524736dd80c8ee2f37bcd29df7b44221ea3f32a1a00efb605ab9e3e3984143c84be117d7102b7a88e9a4c2213d
7
- data.tar.gz: 13f1c532c8c0586d4791ffdae390666388a88889bbb436c8d86a16964932baf66fd39e338adcb2bf0a3b9b85990f0891a26c795a8aa1ce7732418430a37393d1
6
+ metadata.gz: 60f3072ea06df5f44c7e609c6e130e65034d07e88a3a03b0aaa50f7542887a0054781aa9c0652945c16420ba3786cd3e3b830164e1cf654e72efdc8c6feaf750
7
+ data.tar.gz: beaecb13950c18aa46dd3482ac62da1136caaad868bc451bfc28a46a5c9d8f9329e03f43ad81b2de5a77b0bf722bb5d5bf8deca97040a52def39d855c333d9a2
data/.travis.yml CHANGED
@@ -13,4 +13,5 @@ matrix:
13
13
  - rvm: jruby
14
14
  fast_finish: true
15
15
 
16
+ before_install: "gem update bundler"
16
17
  script: "bundle exec rake"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.5.0 / 2015-01-16
2
+
3
+ * [FEATURE] Add a ConsoleReport format (by Josh Bodah)
4
+
1
5
  # 2.4.1 / 2015-12-27
2
6
 
3
7
  * [CHANGE] Bump Reek to 3.8.1
data/lib/rubycritic.rb CHANGED
@@ -1,22 +1,4 @@
1
- require "rubycritic/configuration"
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
@@ -43,6 +43,10 @@ module Rubycritic
43
43
  smells.select { |smell| smell.at_location?(location) }
44
44
  end
45
45
 
46
+ def <=>(other)
47
+ [rating.to_s, name] <=> [other.rating.to_s, other.name]
48
+ end
49
+
46
50
  def to_h
47
51
  {
48
52
  :name => name,
@@ -8,7 +8,7 @@ module Rubycritic
8
8
 
9
9
  attribute :context
10
10
  attribute :cost
11
- attribute :locations
11
+ attribute :locations, Array, :default => []
12
12
  attribute :message
13
13
  attribute :score
14
14
  attribute :status
@@ -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 -%>
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rubycritic
2
- VERSION = "2.4.1"
2
+ VERSION = "2.5.0"
3
3
  end
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
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.1
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: 2015-12-30 00:00:00.000000000 Z
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/report_generators/turbulence_test.rb
260
- - test/lib/rubycritic/report_generators/view_helpers_test.rb
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/report_generators/turbulence_test.rb
326
- - test/lib/rubycritic/report_generators/view_helpers_test.rb
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