Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ detectors:
- initialize
- Skunk::Cli::Application#execute
- Skunk::Cli::Options::Argv#parse
- Skunk::Analysis#test_module?
- add_mock_methods_to_module
TooManyInstanceVariables:
exclude:
- Skunk::Generator::Html::FileData
Expand All @@ -38,10 +40,20 @@ detectors:
- Skunk::Command::StatusSharer#share_url_empty?
- Skunk::Configuration#supported_format?
- Skunk::Configuration#supported_formats
- Skunk::Analysis#test_module?
- Skunk::ConfigTest#setup
ManualDispatch:
exclude:
- Skunk::Config#self.method_missing
- Skunk::Config#self.respond_to_missing?
BooleanParameter:
exclude:
- Skunk::Config#self.respond_to_missing?
DuplicateMethodCall:
exclude:
- Skunk::ConfigTest#test_add_format_ignores_duplicates
FeatureEnvy:
exclude:
- Skunk::Command::StatusReporter#table
- Skunk::Generator::HtmlReport#create_directories_and_files
- add_mock_methods_to_module
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-10-17 11:20:00 UTC using RuboCop version 1.81.1.
# on 2025-10-17 16:20:40 UTC using RuboCop version 1.81.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -36,11 +36,11 @@ Lint/MissingSuper:
Metrics/AbcSize:
Max: 18

# Offense count: 8
# Offense count: 12
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 82
Max: 233

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## main [(unreleased)](https://github.com/fastruby/skunk/compare/v0.5.4...HEAD)

* [REFACTOR: Centralize Skunk analysis into RubyCritic module](https://github.com/fastruby/skunk/pull/127)
* [FEATURE: Add Skunk HTML Report](https://github.com/fastruby/skunk/pull/123)
* [FEATURE: Add Skunk::Config class](https://github.com/fastruby/skunk/pull/123)
* [FEATURE: Add Ruby 3.4 compatibility](https://github.com/fastruby/skunk/pull/124)
Expand Down
25 changes: 10 additions & 15 deletions lib/skunk/commands/status_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module Command
class StatusReporter < RubyCritic::Command::StatusReporter
attr_accessor :analysed_modules

def initialize(options = {})
super(options)
end

HEADINGS = %w[file skunk_score churn_times_cost churn cost coverage].freeze
HEADINGS_WITHOUT_FILE = HEADINGS - %w[file]
HEADINGS_WITHOUT_FILE_WIDTH = HEADINGS_WITHOUT_FILE.size * 17 # padding
Expand Down Expand Up @@ -38,36 +42,27 @@ def update_status_message
private

def analysed_modules_count
@analysed_modules_count ||= non_test_modules.count
end

def non_test_modules
@non_test_modules ||= analysed_modules.reject do |a_module|
module_path = a_module.pathname.dirname.to_s
module_path.start_with?("test", "spec") || module_path.end_with?("test", "spec")
end
analysed_modules.analysed_modules_count
end

def worst
@worst ||= sorted_modules.first
analysed_modules.worst_module
end

def sorted_modules
@sorted_modules ||= non_test_modules.sort_by(&:skunk_score).reverse!
analysed_modules.sorted_modules
end

def total_skunk_score
@total_skunk_score ||= non_test_modules.sum(&:skunk_score)
analysed_modules.skunk_score_total
end

def total_churn_times_cost
non_test_modules.sum(&:churn_times_cost)
analysed_modules.total_churn_times_cost
end

def skunk_score_average
return 0 if analysed_modules_count.zero?

(total_skunk_score.to_d / analysed_modules_count).to_f.round(2)
analysed_modules.skunk_score_average
end

def table_options
Expand Down
24 changes: 22 additions & 2 deletions lib/skunk/generators/html/overview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require "rubycritic/generators/html/base"

require "skunk/generators/html/path_truncator"
require "skunk/generators/html/skunk_data"
require "skunk/generators/html/file_data"
require "skunk/rubycritic/analysed_modules_collection"

module Skunk
module Generator
Expand All @@ -19,7 +20,8 @@ def self.erb_template(template_path)

def initialize(analysed_modules)
@analysed_modules = analysed_modules
@data = SkunkData.new(analysed_modules)
@generated_at = Time.now.strftime("%Y-%m-%d %H:%M:%S")
@skunk_version = Skunk::VERSION
end

def file_name
Expand All @@ -29,6 +31,24 @@ def file_name
def render
TEMPLATE.result(binding)
end

def analysed_modules_count
@analysed_modules.analysed_modules_count
end

def skunk_score_total
@analysed_modules.skunk_score_total
end

def skunk_score_average
@analysed_modules.skunk_score_average
end

def files
@files ||= @analysed_modules.sorted_modules.map do |module_data|
FileData.new(module_data)
end
end
end
end
end
Expand Down
59 changes: 0 additions & 59 deletions lib/skunk/generators/html/skunk_data.rb

This file was deleted.

10 changes: 5 additions & 5 deletions lib/skunk/generators/html/templates/skunk_overview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@

<section class="cards">
<div class="card">
<div class="value"><%= @data.analysed_modules_count %></div>
<div class="value"><%= analysed_modules_count %></div>
<div class="label">Modules Analysed</div>
</div>
<div class="card">
<div class="value"><%= @data.skunk_score_total %></div>
<div class="value"><%= skunk_score_total %></div>
<div class="label">Total Skunk Score</div>
</div>
<div class="card">
<div class="value"><%= @data.skunk_score_average %></div>
<div class="value"><%= skunk_score_average %></div>
<div class="label">Average Skunk Score</div>
</div>
</section>
Expand All @@ -269,7 +269,7 @@
</tr>
</thead>
<tbody>
<% @data.files.each do |item| %>
<% files.each do |item| %>
<tr class="table-row">
<td class="filename">
<span><%= item.file %></span>
Expand Down Expand Up @@ -301,7 +301,7 @@
</section>

<footer class="footer">
<p>Generated with Skunk v<%= @data.skunk_version %> on <%= @data.generated_at %></p>
<p>Generated with Skunk v<%= @skunk_version %> on <%= @generated_at %></p>
</footer>
</div>
</body>
Expand Down
45 changes: 2 additions & 43 deletions lib/skunk/generators/json/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "pathname"

require "rubycritic/configuration"
require "skunk/rubycritic/analysed_modules_collection"

module Skunk
module Generator
Expand All @@ -20,14 +21,7 @@ def render
end

def data
{
analysed_modules_count: analysed_modules_count,
skunk_score_total: skunk_score_total,
skunk_score_average: calculate_average,
worst_pathname: find_worst_module&.pathname,
worst_score: find_worst_module&.skunk_score,
files: build_files
}
@analysed_modules.to_hash
end

def file_directory
Expand All @@ -37,41 +31,6 @@ def file_directory
def file_pathname
Pathname.new(file_directory).join(FILE_NAME)
end

private

def analysed_modules_count
@analysed_modules_count ||= non_test_modules.count
end

def calculate_average
return 0 if analysed_modules_count.zero?

(skunk_score_total.to_d / analysed_modules_count).to_f.round(2)
end

def skunk_score_total
@skunk_score_total ||= non_test_modules.sum(&:skunk_score)
end

def non_test_modules
@non_test_modules ||= @analysed_modules.reject do |a_module|
module_path = a_module.pathname.dirname.to_s
module_path.start_with?("test", "spec") || module_path.end_with?("test", "spec")
end
end

def find_worst_module
@find_worst_module ||= sorted_modules.first
end

def sorted_modules
@sorted_modules ||= non_test_modules.sort_by(&:skunk_score).reverse!
end

def build_files
@build_files ||= sorted_modules.map(&:to_hash)
end
end
end
end
Expand Down
Loading