rubycritic 2.2.0 → 2.3.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: 1bbd53ca30b1e2cae94b44246ca2df4f1ef200bb
4
- data.tar.gz: 584e3a45c1c3ae04c261366b706699c5087effea
3
+ metadata.gz: 08d300df3ff05cf7919348a8302d52623343c9b7
4
+ data.tar.gz: 75d743139e01f2310eec35c8300b25d0550f689a
5
5
  SHA512:
6
- metadata.gz: 9a452882ed7dc3cb9bd8ab6817650a4f475ea06cc465ff7c9d9290495578be1ad76c04eb31cd66155813a88d14ad28c44c43280f2bcef7d0a5a521d8e8abd97c
7
- data.tar.gz: 2b2f54e2f3f40363bdd9f628e0f0fa0ff742dde3ad217aa69f0d25e2bb0424bc3a8119a37937e42c49fbf197604c5e4ae54e1c8d0fb3459f90662461165f9609
6
+ metadata.gz: c3453709805cd4268e8093baf584b3db879c400bca3240e22c919dd1a3a6deea19d683750aaf48a9dca1e27c8c07374be50d7daccb009ede7fdcda14e22f6867
7
+ data.tar.gz: 2c746421764e0bef87f7798c09c7fbb4234758c73c9a408f776f7f4494231ba814b10e7750e678e9057817200a3ba1a3a96ae907752876be1075f47d33a18efe
@@ -1,3 +1,8 @@
1
+ # 2.3.0 / 2015-11-30
2
+
3
+ * [FEATURE] Added global score calculation
4
+ * [CHANGE] Bump Reek dependency to 3.7.1.
5
+
1
6
  # 2.2.0 / 2015-11-20
2
7
 
3
8
  * [CHANGE] Use `Reeks` default configuration loading.
@@ -1,5 +1,4 @@
1
- require "rubycritic/source_locator"
2
- require "rubycritic/core/analysed_module"
1
+ require "rubycritic/core/analysed_modules_collection"
3
2
  require "rubycritic/analysers/smells/flay"
4
3
  require "rubycritic/analysers/smells/flog"
5
4
  require "rubycritic/analysers/smells/reek"
@@ -29,9 +28,7 @@ module Rubycritic
29
28
  end
30
29
 
31
30
  def analysed_modules
32
- @analysed_modules ||= SourceLocator.new(@paths).pathnames.map do |pathname|
33
- AnalysedModule.new(:pathname => pathname)
34
- end
31
+ @analysed_modules ||= AnalysedModulesCollection.new(@paths)
35
32
  end
36
33
  end
37
34
 
@@ -0,0 +1,49 @@
1
+ require "rubycritic/source_locator"
2
+ require "rubycritic/core/analysed_module"
3
+
4
+ module Rubycritic
5
+ class AnalysedModulesCollection
6
+ include Enumerable
7
+
8
+ # Limit used to prevent very bad modules to have excessive impact in the
9
+ # overall result. See #limited_cost_for
10
+ COST_LIMIT = 32
11
+ # Score goes from 0 (worst) to 100 (perfect)
12
+ MAX_SCORE = 100
13
+ # Projects with an average cost of 16 (or above) will score 0, since 16
14
+ # is where the worst possible rating (F) starts
15
+ ZERO_SCORE_COST = 16
16
+ COST_MULTIPLIER = MAX_SCORE.to_f / ZERO_SCORE_COST
17
+
18
+ def initialize(paths)
19
+ @modules = SourceLocator.new(paths).pathnames.map do |pathname|
20
+ AnalysedModule.new(:pathname => pathname)
21
+ end
22
+ end
23
+
24
+ def each(&block)
25
+ @modules.each(&block)
26
+ end
27
+
28
+ def to_json(*options)
29
+ @modules.to_json(*options)
30
+ end
31
+
32
+ def score
33
+ MAX_SCORE - average_limited_cost * COST_MULTIPLIER
34
+ rescue
35
+ 0.0
36
+ end
37
+
38
+ private
39
+
40
+ def average_limited_cost
41
+ avg = map { |mod| limited_cost_for(mod) }.reduce(:+) / @modules.size.to_f
42
+ [avg, ZERO_SCORE_COST].min
43
+ end
44
+
45
+ def limited_cost_for(mod)
46
+ [mod.cost, COST_LIMIT].min
47
+ end
48
+ end
49
+ end
@@ -10,6 +10,8 @@ module Rubycritic
10
10
 
11
11
  def initialize(analysed_modules)
12
12
  @turbulence_data = Turbulence.data(analysed_modules)
13
+ @score = analysed_modules.score
14
+ @max_score = AnalysedModulesCollection::MAX_SCORE
13
15
  end
14
16
 
15
17
  def file_name
@@ -1,3 +1,7 @@
1
+ <div class="chart-container">
2
+ <h2>Score: <%= @score.round(2) %> / <%= @max_score %></h2>
3
+ </div>
4
+
1
5
  <div id="js-chart-container" class="chart-container"></div>
2
6
 
3
7
  <script type="text/javascript">
@@ -21,7 +21,8 @@ module Rubycritic
21
21
  :version => Rubycritic::VERSION
22
22
  }
23
23
  },
24
- :analysed_modules => @analysed_modules
24
+ :analysed_modules => @analysed_modules,
25
+ :score => @analysed_modules.score
25
26
  }
26
27
  end
27
28
  end
@@ -1,3 +1,3 @@
1
1
  module Rubycritic
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency "virtus", "~> 1.0"
24
24
  spec.add_runtime_dependency "flay", "2.6.1"
25
25
  spec.add_runtime_dependency "flog", "4.3.2"
26
- spec.add_runtime_dependency "reek", "3.6.0"
26
+ spec.add_runtime_dependency "reek", "3.7.1"
27
27
  spec.add_runtime_dependency "parser", ">= 2.2.0", "< 3.0"
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -16,10 +16,10 @@ describe Rubycritic::Analyser::ReekSmells do
16
16
 
17
17
  it "creates smells with messages" do
18
18
  first_smell = @analysed_module.smells.first
19
- first_smell.message.must_equal "has no descriptive comment"
19
+ first_smell.message.must_equal "has boolean parameter 'reek'"
20
20
 
21
21
  last_smell = @analysed_module.smells.last
22
- last_smell.message.must_equal "has boolean parameter 'reek'"
22
+ last_smell.message.must_equal "has no descriptive comment"
23
23
  end
24
24
  end
25
25
  end
@@ -0,0 +1,109 @@
1
+ require "test_helper"
2
+ require "rubycritic/core/analysed_modules_collection"
3
+
4
+ describe Rubycritic::AnalysedModulesCollection do
5
+ subject { Rubycritic::AnalysedModulesCollection.new(paths) }
6
+
7
+ describe ".new" do
8
+ context "with an empty path" do
9
+ let(:paths) { "" }
10
+
11
+ it "returns an empty collection" do
12
+ subject.count.must_equal 0
13
+ end
14
+ end
15
+
16
+ context "with a list of files" do
17
+ let(:paths) { %w(test/samples/doesnt_exist.rb test/samples/unparsable.rb test/samples/empty.rb) }
18
+
19
+ it "registers one AnalysedModule element per existent file" do
20
+ subject.count.must_equal 2
21
+ subject.all? { |a| a.is_a?(Rubycritic::AnalysedModule) }.must_equal true
22
+ end
23
+ end
24
+
25
+ context "with a directory" do
26
+ let(:paths) { "test/samples/" }
27
+
28
+ it "recursively registers all files" do
29
+ subject.count.must_equal 13
30
+ end
31
+ end
32
+
33
+ context "with redundant paths" do
34
+ let(:paths) { %w(test/samples/flog test/samples/flog/complex.rb) }
35
+
36
+ it "returns a redundant collection" do
37
+ subject.count.must_equal 3
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#score" do
43
+ context "with no modules" do
44
+ let(:paths) { "" }
45
+
46
+ it "returns zero" do
47
+ subject.score.must_equal 0.0
48
+ end
49
+ end
50
+
51
+ context "with not analysed modules" do
52
+ let(:paths) { "test/samples/flog" }
53
+
54
+ it "returns zero" do
55
+ subject.score.must_equal 0.0
56
+ end
57
+ end
58
+
59
+ context "with analysed modules" do
60
+ before do
61
+ subject.each_with_index do |mod, i|
62
+ mod.expects(:cost).returns costs[i]
63
+ end
64
+ end
65
+
66
+ let(:paths) { %w(test/samples/flog test/samples/flay) }
67
+
68
+ context "with perfect modules" do
69
+ let(:costs) { [0.0, 0.0, 0.0, 0.0] }
70
+
71
+ it "returns the maximum score" do
72
+ subject.score.must_equal 100.0
73
+ end
74
+ end
75
+
76
+ context "with very bad modules" do
77
+ let(:costs) { [16.0, 16.0, 16.0, 16.0] }
78
+
79
+ it "returns zero" do
80
+ subject.score.must_equal 0.0
81
+ end
82
+ end
83
+
84
+ context "with horrible modules" do
85
+ let(:costs) { [32.0, 32.0, 32.0, 32.0] }
86
+
87
+ it "returns zero" do
88
+ subject.score.must_equal 0.0
89
+ end
90
+ end
91
+
92
+ context "with mixed modules" do
93
+ let(:costs) { [32.0, 2.0, 0.0, 2.0] }
94
+
95
+ it "properly calculates the score" do
96
+ subject.score.must_equal 43.75
97
+ end
98
+ end
99
+
100
+ context "with a module above the cost limit" do
101
+ let(:costs) { [220.0, 2.0, 0.0, 2.0] }
102
+
103
+ it "reduces the impact in the result" do
104
+ subject.score.must_equal 43.75
105
+ end
106
+ end
107
+ end
108
+ end
109
+ 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.2.0
4
+ version: 2.3.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-11-24 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 3.6.0
61
+ version: 3.7.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 3.6.0
68
+ version: 3.7.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: parser
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -198,6 +198,7 @@ files:
198
198
  - lib/rubycritic/commands/version.rb
199
199
  - lib/rubycritic/configuration.rb
200
200
  - lib/rubycritic/core/analysed_module.rb
201
+ - lib/rubycritic/core/analysed_modules_collection.rb
201
202
  - lib/rubycritic/core/location.rb
202
203
  - lib/rubycritic/core/rating.rb
203
204
  - lib/rubycritic/core/smell.rb
@@ -250,6 +251,7 @@ files:
250
251
  - test/lib/rubycritic/analysers/smells/reek_test.rb
251
252
  - test/lib/rubycritic/configuration_test.rb
252
253
  - test/lib/rubycritic/core/analysed_module_test.rb
254
+ - test/lib/rubycritic/core/analysed_modules_collection_test.rb
253
255
  - test/lib/rubycritic/core/location_test.rb
254
256
  - test/lib/rubycritic/core/smell_test.rb
255
257
  - test/lib/rubycritic/core/smells_array_test.rb
@@ -300,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
300
302
  version: '0'
301
303
  requirements: []
302
304
  rubyforge_project:
303
- rubygems_version: 2.4.6
305
+ rubygems_version: 2.4.5
304
306
  signing_key:
305
307
  specification_version: 4
306
308
  summary: RubyCritic is a Ruby code quality reporter
@@ -315,6 +317,7 @@ test_files:
315
317
  - test/lib/rubycritic/analysers/smells/reek_test.rb
316
318
  - test/lib/rubycritic/configuration_test.rb
317
319
  - test/lib/rubycritic/core/analysed_module_test.rb
320
+ - test/lib/rubycritic/core/analysed_modules_collection_test.rb
318
321
  - test/lib/rubycritic/core/location_test.rb
319
322
  - test/lib/rubycritic/core/smell_test.rb
320
323
  - test/lib/rubycritic/core/smells_array_test.rb