skunk 0.5.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,30 +10,38 @@ module RubyCritic
10
10
  # Returns a numeric value that represents the skunk_score of a module:
11
11
  #
12
12
  # If module is perfectly covered, skunk score is the same as the
13
- # `churn_times_cost`
13
+ # `cost`
14
14
  #
15
15
  # If module has no coverage, skunk score is a penalized value of
16
- # `churn_times_cost`
16
+ # `cost`
17
17
  #
18
- # For now the skunk_score is calculated by multiplying `churn_times_cost`
18
+ # For now the skunk_score is calculated by multiplying `cost`
19
19
  # times the lack of coverage.
20
20
  #
21
21
  # For example:
22
22
  #
23
- # When `churn_times_cost` is 100 and module is perfectly covered:
23
+ # When `cost` is 100 and module is perfectly covered:
24
24
  # skunk_score => 100
25
25
  #
26
- # When `churn_times_cost` is 100 and module is not covered at all:
26
+ # When `cost` is 100 and module is not covered at all:
27
27
  # skunk_score => 100 * 100 = 10_000
28
28
  #
29
- # When `churn_times_cost` is 100 and module is covered at 75%:
29
+ # When `cost` is 100 and module is covered at 75%:
30
30
  # skunk_score => 100 * 25 (percentage uncovered) = 2_500
31
31
  #
32
32
  # @return [Float]
33
33
  def skunk_score
34
34
  return cost.round(2) if coverage == PERFECT_COVERAGE
35
35
 
36
- (cost * (PERFECT_COVERAGE - coverage.to_i)).round(2)
36
+ (cost * penalty_factor).round(2)
37
+ end
38
+
39
+ # Returns a numeric value that represents the penalty factor based
40
+ # on the lack of code coverage (not enough test cases for this module)
41
+ #
42
+ # @return [Integer]
43
+ def penalty_factor
44
+ PERFECT_COVERAGE - coverage.to_i
37
45
  end
38
46
 
39
47
  # Returns the value of churn times cost.
data/lib/skunk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skunk
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.3"
5
5
  end
@@ -0,0 +1,11 @@
1
+ **IMPORTANT**: Please read the README before submitting pull requests for this project. Additionally, if your PR closes any open GitHub issue, make sure you include Closes #XXXX in your comment.
2
+
3
+ - [ ] Add an entry to `CHANGELOG.md` that links to this PR under the "main (unreleased)" heading.
4
+
5
+ Description:
6
+
7
+ Please include a summary of the change and which issue is fixed or which feature is introduced.
8
+
9
+ If changes to the behavior are made, clearly describe what changes.
10
+
11
+ I will abide by the [code of conduct](https://github.com/fastruby/skunk/blob/main/CODE_OF_CONDUCT.md).
data/skunk.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.description = "Knows how to calculate the SkunkScore for a set of Ruby modules"
15
15
  spec.homepage = "https://github.com/fastruby/skunk"
16
16
 
17
- spec.required_ruby_version = [">= 2.4.0", "< 3.1.0"]
17
+ spec.required_ruby_version = [">= 2.4.0"]
18
18
 
19
19
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
20
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.metadata["homepage_uri"] = spec.homepage
25
25
  spec.metadata["source_code_uri"] = "https://github.com/fastruby/skunk"
26
- spec.metadata["changelog_uri"] = "https://github.com/fastruby/skunk/changelog"
26
+ spec.metadata["changelog_uri"] = "https://github.com/fastruby/skunk/blob/main/CHANGELOG.md"
27
27
  else
28
28
  raise "RubyGems 2.0 or newer is required to protect against " \
29
29
  "public gem pushes."
@@ -39,19 +39,18 @@ Gem::Specification.new do |spec|
39
39
  spec.require_paths = ["lib"]
40
40
 
41
41
  spec.add_dependency "rubycritic", ">= 4.5.2", "< 5.0"
42
- spec.add_dependency "terminal-table", "~> 1.8.0"
42
+ spec.add_dependency "terminal-table", "~> 3.0"
43
43
 
44
- spec.add_development_dependency "byebug", "~> 11"
45
44
  spec.add_development_dependency "codecov", "~> 0.1.16"
45
+ spec.add_development_dependency "debug"
46
46
  spec.add_development_dependency "minitest", "~> 5.8.4"
47
47
  spec.add_development_dependency "minitest-around", "~> 0.5.0"
48
48
  spec.add_development_dependency "minitest-stub_any_instance", "~> 1.0.2"
49
49
  spec.add_development_dependency "minitest-stub-const", "~> 0.6"
50
50
  spec.add_development_dependency "rake", "~> 13.0"
51
- spec.add_development_dependency "reek", "~> 6.0.0"
52
- spec.add_development_dependency "rubocop", "~> 1.0"
51
+ spec.add_development_dependency "reek"
52
+ spec.add_development_dependency "rubocop"
53
53
  spec.add_development_dependency "simplecov", "~> 0.18"
54
54
  spec.add_development_dependency "simplecov-console", "0.5.0"
55
- spec.add_development_dependency "vcr", "~> 6.0.0"
56
55
  spec.add_development_dependency "webmock", "~> 3.10.0"
57
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernesto Tagwerker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-18 00:00:00.000000000 Z
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubycritic
@@ -36,42 +36,42 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 1.8.0
39
+ version: '3.0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.8.0
46
+ version: '3.0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: byebug
48
+ name: codecov
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '11'
53
+ version: 0.1.16
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '11'
60
+ version: 0.1.16
61
61
  - !ruby/object:Gem::Dependency
62
- name: codecov
62
+ name: debug
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 0.1.16
67
+ version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 0.1.16
74
+ version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: minitest
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -146,30 +146,30 @@ dependencies:
146
146
  name: reek
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
- - - "~>"
149
+ - - ">="
150
150
  - !ruby/object:Gem::Version
151
- version: 6.0.0
151
+ version: '0'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - "~>"
156
+ - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: 6.0.0
158
+ version: '0'
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: rubocop
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
- - - "~>"
163
+ - - ">="
164
164
  - !ruby/object:Gem::Version
165
- version: '1.0'
165
+ version: '0'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - "~>"
170
+ - - ">="
171
171
  - !ruby/object:Gem::Version
172
- version: '1.0'
172
+ version: '0'
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: simplecov
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -198,20 +198,6 @@ dependencies:
198
198
  - - '='
199
199
  - !ruby/object:Gem::Version
200
200
  version: 0.5.0
201
- - !ruby/object:Gem::Dependency
202
- name: vcr
203
- requirement: !ruby/object:Gem::Requirement
204
- requirements:
205
- - - "~>"
206
- - !ruby/object:Gem::Version
207
- version: 6.0.0
208
- type: :development
209
- prerelease: false
210
- version_requirements: !ruby/object:Gem::Requirement
211
- requirements:
212
- - - "~>"
213
- - !ruby/object:Gem::Version
214
- version: 6.0.0
215
201
  - !ruby/object:Gem::Dependency
216
202
  name: webmock
217
203
  requirement: !ruby/object:Gem::Requirement
@@ -243,10 +229,11 @@ files:
243
229
  - ".rubocop.yml"
244
230
  - ".rubocop_todo.yml"
245
231
  - CHANGELOG.md
246
- - CODEOWNERS
247
232
  - CODE_OF_CONDUCT.md
233
+ - CONTRIBUTING.md
248
234
  - Gemfile
249
235
  - Gemfile-Ruby-2-4
236
+ - Gemfile-Ruby-2-5
250
237
  - LICENSE.txt
251
238
  - README.md
252
239
  - Rakefile
@@ -254,23 +241,24 @@ files:
254
241
  - fastruby-logo.png
255
242
  - lib/skunk.rb
256
243
  - lib/skunk/cli/application.rb
257
- - lib/skunk/cli/command_factory.rb
258
- - lib/skunk/cli/commands/base.rb
259
- - lib/skunk/cli/commands/compare.rb
260
- - lib/skunk/cli/commands/compare_score.rb
261
- - lib/skunk/cli/commands/default.rb
262
- - lib/skunk/cli/commands/help.rb
263
- - lib/skunk/cli/commands/output.rb
264
- - lib/skunk/cli/commands/shareable.rb
265
- - lib/skunk/cli/commands/status_reporter.rb
266
- - lib/skunk/cli/commands/status_sharer.rb
267
- - lib/skunk/cli/commands/version.rb
268
244
  - lib/skunk/cli/options.rb
269
245
  - lib/skunk/cli/options/argv.rb
246
+ - lib/skunk/command_factory.rb
247
+ - lib/skunk/commands/base.rb
248
+ - lib/skunk/commands/compare.rb
249
+ - lib/skunk/commands/compare_score.rb
250
+ - lib/skunk/commands/default.rb
251
+ - lib/skunk/commands/help.rb
252
+ - lib/skunk/commands/output.rb
253
+ - lib/skunk/commands/shareable.rb
254
+ - lib/skunk/commands/status_reporter.rb
255
+ - lib/skunk/commands/status_sharer.rb
256
+ - lib/skunk/commands/version.rb
270
257
  - lib/skunk/rubycritic/analysed_module.rb
271
258
  - lib/skunk/rubycritic/analysed_modules_collection.rb
272
259
  - lib/skunk/version.rb
273
260
  - logo.png
261
+ - pull_request_template.md
274
262
  - samples/engines/spec/nested_sample_spec.rb
275
263
  - samples/rubycritic/analysed_module.rb
276
264
  - skunk.gemspec
@@ -281,7 +269,7 @@ metadata:
281
269
  allowed_push_host: https://www.rubygems.org
282
270
  homepage_uri: https://github.com/fastruby/skunk
283
271
  source_code_uri: https://github.com/fastruby/skunk
284
- changelog_uri: https://github.com/fastruby/skunk/changelog
272
+ changelog_uri: https://github.com/fastruby/skunk/blob/main/CHANGELOG.md
285
273
  post_install_message:
286
274
  rdoc_options: []
287
275
  require_paths:
@@ -291,16 +279,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
291
279
  - - ">="
292
280
  - !ruby/object:Gem::Version
293
281
  version: 2.4.0
294
- - - "<"
295
- - !ruby/object:Gem::Version
296
- version: 3.1.0
297
282
  required_rubygems_version: !ruby/object:Gem::Requirement
298
283
  requirements:
299
284
  - - ">="
300
285
  - !ruby/object:Gem::Version
301
286
  version: '0'
302
287
  requirements: []
303
- rubygems_version: 3.0.9
288
+ rubygems_version: 3.4.21
304
289
  signing_key:
305
290
  specification_version: 4
306
291
  summary: A library to assess code quality vs. code coverage
data/CODEOWNERS DELETED
@@ -1,5 +0,0 @@
1
-
2
- # These code owners will be the default owners to everything in the repository.
3
- # Unless a posterior rule has precedence, they will be automatically requested
4
- # for review when a pull request is opened.
5
- * @fastruby/black-bunny-brigade
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rubycritic/command_factory"
4
-
5
- module Skunk
6
- module Cli
7
- # Knows how to calculate the command that was request by the CLI user
8
- class CommandFactory < RubyCritic::CommandFactory
9
- COMMAND_CLASS_MODES = %i[version help default compare].freeze
10
-
11
- # Returns the command class based on the command that was executed
12
- #
13
- # @param mode
14
- # @return [Class]
15
- def self.command_class(mode)
16
- mode = mode.to_s.split("_").first.to_sym
17
- if COMMAND_CLASS_MODES.include? mode
18
- require "skunk/cli/commands/#{mode}"
19
- Command.const_get(mode.capitalize)
20
- else
21
- require "skunk/cli/commands/default"
22
- Command::Default
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rubycritic/commands/base"
4
- require "skunk/cli/commands/status_reporter"
5
-
6
- module Skunk
7
- module Cli
8
- module Command
9
- # Base class for `Skunk` commands. It knows how to build a command with
10
- # options. It always uses a [Skunk::Command::StatusReporter] as its
11
- # reporter object.
12
- class Base < RubyCritic::Command::Base
13
- def initialize(options)
14
- @options = options
15
- @status_reporter = Skunk::Command::StatusReporter.new(@options)
16
- end
17
-
18
- def share(_); end
19
- end
20
- end
21
- end
22
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rubycritic/commands/compare"
4
- require "skunk/rubycritic/analysed_modules_collection"
5
- require "skunk/cli/commands/output"
6
- require "skunk/cli/commands/shareable"
7
- require "skunk/cli/commands/compare_score"
8
-
9
- # nodoc #
10
- module Skunk
11
- module Cli
12
- module Command
13
- # Knows how to compare two branches and their skunk score average
14
- class Compare < RubyCritic::Command::Compare
15
- include Skunk::Cli::Command::Shareable
16
-
17
- def initialize(options)
18
- super
19
- @options = options
20
- @status_reporter = Skunk::Command::StatusReporter.new(options)
21
- end
22
-
23
- def execute
24
- compare_branches
25
- status_reporter
26
- end
27
-
28
- # switch branch and analyse files but don't generate a report
29
- def analyse_branch(branch)
30
- ::RubyCritic::SourceControlSystem::Git.switch_branch(::RubyCritic::Config.send(branch))
31
- critic = critique(branch)
32
- ::RubyCritic::Config.send(:"#{branch}_score=", critic.skunk_score_average)
33
- ::RubyCritic::Config.root = branch_directory(branch)
34
- end
35
-
36
- # generate report only for modified files but don't report it
37
- def analyse_modified_files
38
- modified_files = ::RubyCritic::Config
39
- .feature_branch_collection
40
- .where(::RubyCritic::SourceControlSystem::Git.modified_files)
41
- ::RubyCritic::AnalysedModulesCollection.new(modified_files.map(&:path),
42
- modified_files)
43
- ::RubyCritic::Config.root = "#{::RubyCritic::Config.root}/compare"
44
- end
45
-
46
- # create a txt file with the branch score details
47
- def build_details
48
- details = CompareScore.new(
49
- ::RubyCritic::Config.base_branch,
50
- ::RubyCritic::Config.feature_branch,
51
- ::RubyCritic::Config.base_branch_score.to_f.round(2),
52
- ::RubyCritic::Config.feature_branch_score.to_f.round(2)
53
- ).message
54
-
55
- Skunk::Command::Output.create_directory(::RubyCritic::Config.compare_root_directory)
56
- File.open(build_details_path, "w") { |file| file.write(details) }
57
- puts details
58
- end
59
-
60
- def build_details_path
61
- "#{::RubyCritic::Config.compare_root_directory}/build_details.txt"
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # nodoc #
4
- module Skunk
5
- module Cli
6
- module Command
7
- # Knows how to describe score evolution between two branches
8
- class CompareScore
9
- def initialize(base_branch, feature_branch, base_branch_score, feature_branch_score)
10
- @base_branch = base_branch
11
- @feature_branch = feature_branch
12
- @base_branch_score = base_branch_score
13
- @feature_branch_score = feature_branch_score
14
- end
15
-
16
- def message
17
- "Base branch (#{@base_branch}) "\
18
- "average skunk score: #{@base_branch_score} \n"\
19
- "Feature branch (#{@feature_branch}) "\
20
- "average skunk score: #{@feature_branch_score} \n"\
21
- "#{score_evolution_message}"
22
- end
23
-
24
- def score_evolution_message
25
- "Skunk score average is #{score_evolution} #{score_evolution_appreciation} \n"
26
- end
27
-
28
- def score_evolution_appreciation
29
- @feature_branch_score > @base_branch_score ? "worse" : "better"
30
- end
31
-
32
- def score_evolution
33
- return "Infinitely" if @base_branch_score.zero?
34
-
35
- precentage = (100 * (@base_branch_score - @feature_branch_score) / @base_branch_score)
36
- "#{precentage.round(0).abs}%"
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rubycritic/commands/default"
4
- require "rubycritic/analysers_runner"
5
- require "rubycritic/revision_comparator"
6
- require "rubycritic/reporter"
7
-
8
- require "skunk/cli/commands/base"
9
- require "skunk/cli/commands/shareable"
10
- require "skunk/cli/commands/status_reporter"
11
-
12
- module Skunk
13
- module Cli
14
- module Command
15
- # Default command runs a critique using RubyCritic and uses
16
- # Skunk::Command::StatusReporter to report status
17
- class Default < RubyCritic::Command::Default
18
- include Skunk::Cli::Command::Shareable
19
-
20
- def initialize(options)
21
- super
22
- @options = options
23
- @status_reporter = Skunk::Command::StatusReporter.new(options)
24
- end
25
-
26
- # It generates a report and it returns an instance of
27
- # Skunk::Command::StatusReporter
28
- #
29
- # @return [Skunk::Command::StatusReporter]
30
- def execute
31
- RubyCritic::Config.formats = []
32
-
33
- report(critique)
34
-
35
- status_reporter
36
- end
37
-
38
- # It connects the Skunk::Command::StatusReporter with the collection
39
- # of analysed modules.
40
- #
41
- # @param [RubyCritic::AnalysedModulesCollection] A collection of analysed modules
42
- def report(analysed_modules)
43
- status_reporter.analysed_modules = analysed_modules
44
- status_reporter.score = analysed_modules.score
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "skunk/cli/commands/base"
4
- require "rubycritic/commands/help"
5
-
6
- module Skunk
7
- module Cli
8
- module Command
9
- # Knows how to guide user into using `skunk` properly
10
- class Help < Skunk::Cli::Command::Base
11
- # Outputs a help message
12
- def execute
13
- puts options[:help_text]
14
- status_reporter
15
- end
16
-
17
- private
18
-
19
- attr_reader :options, :status_reporter
20
- end
21
- end
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Skunk
4
- module Cli
5
- module Command
6
- # This is a module that will be used for sharing reports to a server
7
- module Shareable
8
- # It shares the report using SHARE_URL or https://skunk.fastruby.io. It
9
- # will post all results in JSON format and return a status message.
10
- #
11
- # @param [Skunk::Command::StatusReporter] A status reporter with analysed modules
12
- # :reek:FeatureEnvy
13
- def share(reporter)
14
- sharer = Skunk::Command::StatusSharer.new(@options)
15
- sharer.status_reporter = reporter
16
- sharer.share
17
- end
18
- end
19
- end
20
- end
21
- end
File without changes