Skip to content
Open
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
42 changes: 26 additions & 16 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 16:20:40 UTC using RuboCop version 1.81.1.
# on 2025-10-17 22:53:06 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 All @@ -13,16 +13,9 @@ Gemspec/RequiredRubyVersion:
- 'skunk.gemspec'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/ClosingHeredocIndentation:
Exclude:
- 'lib/skunk/commands/status_reporter.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/HeredocIndentation:
Lint/IneffectiveAccessModifier:
Exclude:
- 'lib/skunk/commands/status_reporter.rb'
- 'lib/skunk/generators/console/simple.rb'

# Offense count: 2
# Configuration parameters: AllowedParentClasses.
Expand All @@ -31,21 +24,21 @@ Lint/MissingSuper:
- 'lib/skunk/cli/application.rb'
- 'lib/skunk/generators/html/overview.rb'

# Offense count: 1
# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 18
Max: 24

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

# Offense count: 2
# Offense count: 5
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 13
Max: 18

# Offense count: 1
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
Expand All @@ -55,6 +48,16 @@ Naming/VariableNumber:
Exclude:
- 'lib/skunk/commands/status_sharer.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, EnforcedStyleForClasses, EnforcedStyleForModules.
# SupportedStyles: nested, compact
# SupportedStylesForClasses: ~, nested, compact
# SupportedStylesForModules: ~, nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'test/test_helper.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
Expand All @@ -63,3 +66,10 @@ Style/FrozenStringLiteralComment:
Exclude:
- '**/*.arb'
- 'bin/console'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Max: 124
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ puts ARGV.inspect
require "skunk/cli/application"
require "skunk/config"

Skunk::Config.formats = %i[json html]
Skunk::Config.formats = %i[json console html]
Skunk::Cli::Application.new(ARGV).execute
1 change: 1 addition & 0 deletions lib/skunk/cli/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require "skunk"
require "skunk/rubycritic/analysed_module"
require "skunk/rubycritic/analysed_modules_collection"
require "skunk/cli/options"
require "skunk/command_factory"
require "skunk/commands/status_sharer"
Expand Down
2 changes: 1 addition & 1 deletion lib/skunk/cli/options/argv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Argv < RubyCritic::Cli::Options::Argv
# :reek:Attribute
attr_accessor :output_filename

def parse # rubocop:disable Metrics/MethodLength
def parse
parser.new do |opts|
opts.banner = "Usage: skunk [options] [paths]\n"

Expand Down
1 change: 0 additions & 1 deletion lib/skunk/commands/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def report(analysed_modules)
Reporter.generate_report(analysed_modules)

status_reporter.analysed_modules = analysed_modules
status_reporter.score = analysed_modules.score
end
end
end
Expand Down
76 changes: 2 additions & 74 deletions lib/skunk/commands/status_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,91 +1,19 @@
# frozen_string_literal: true

require "erb"
require "rubycritic/commands/status_reporter"
require "terminal-table"

module Skunk
module Command
# Knows how to report status for stinky files
# Extends RubyCritic::Command::StatusReporter to silence the status message
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

TEMPLATE = ERB.new(<<-TEMPL
<%= _ttable %>\n
SkunkScore Total: <%= total_skunk_score %>
Modules Analysed: <%= analysed_modules_count %>
SkunkScore Average: <%= skunk_score_average %>
<% if worst %>Worst SkunkScore: <%= worst.skunk_score %> (<%= worst.pathname %>)<% end %>

Generated with Skunk v<%= Skunk::VERSION %>
TEMPL
)

# Returns a status message with a table of all analysed_modules and
# a skunk score average
def update_status_message
opts = table_options.merge(headings: HEADINGS, rows: table)

_ttable = Terminal::Table.new(opts)

@status_message = TEMPLATE.result(binding)
end

private

def analysed_modules_count
analysed_modules.analysed_modules_count
end

def worst
analysed_modules.worst_module
end

def sorted_modules
analysed_modules.sorted_modules
end

def total_skunk_score
analysed_modules.skunk_score_total
end

def total_churn_times_cost
analysed_modules.total_churn_times_cost
end

def skunk_score_average
analysed_modules.skunk_score_average
end

def table_options
max = sorted_modules.max_by { |a_mod| a_mod.pathname.to_s.length }
width = max.pathname.to_s.length + HEADINGS_WITHOUT_FILE_WIDTH
{
style: {
width: width
}
}
end

def table
sorted_modules.map do |a_mod|
[
a_mod.pathname,
a_mod.skunk_score,
a_mod.churn_times_cost,
a_mod.churn,
a_mod.cost.round(2),
a_mod.coverage.round(2)
]
end
@status_message = ""
end
end
end
Expand Down
13 changes: 7 additions & 6 deletions lib/skunk/commands/status_sharer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ def base_url

def json_summary
result = {
total_skunk_score: total_skunk_score,
analysed_modules_count: analysed_modules_count,
skunk_score_average: skunk_score_average,
total_skunk_score: analysed_modules.skunk_score_total,
analysed_modules_count: analysed_modules.analysed_modules_count,
skunk_score_average: analysed_modules.skunk_score_average,
skunk_version: Skunk::VERSION
}

if worst
if analysed_modules&.worst_module
worst = analysed_modules.worst_module
result[:worst_skunk_score] = {
file: worst.pathname.to_s,
file: worst.pathname,
skunk_score: worst.skunk_score
}
end
Expand All @@ -57,7 +58,7 @@ def json_summary
end

def json_results
sorted_modules.map(&:to_hash)
analysed_modules.sorted_modules.map(&:to_hash)
end

# :reek:UtilityFunction
Expand Down
2 changes: 1 addition & 1 deletion lib/skunk/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Skunk
# Utility module for format validation
module FormatValidator
# Supported output formats
SUPPORTED_FORMATS = %i[json html].freeze
SUPPORTED_FORMATS = %i[json html console].freeze

# Check if a format is supported
# @param format [Symbol] Format to check
Expand Down
92 changes: 92 additions & 0 deletions lib/skunk/generators/console/simple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# frozen_string_literal: true

require "erb"
require "terminal-table"

module Skunk
module Generator
module Console
# Generates a console report for the analysed modules.
class Simple
def initialize(analysed_modules)
@analysed_modules = analysed_modules
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

TEMPLATE = ERB.new(<<~TEMPL
<%= _ttable %>

SkunkScore Total: <%= total_skunk_score %>
Modules Analysed: <%= analysed_modules_count %>
SkunkScore Average: <%= skunk_score_average %>
<% if worst %>Worst SkunkScore: <%= worst.skunk_score %> (<%= worst.pathname %>)<% end %>

Generated with Skunk v<%= Skunk::VERSION %>
TEMPL
)

def render
opts = table_options.merge(headings: HEADINGS, rows: table)
_ttable = Terminal::Table.new(opts)
TEMPLATE.result(binding)
end

private

def analysed_modules_count
@analysed_modules.analysed_modules_count
end

def worst
@analysed_modules.worst_module
end

def sorted_modules
@analysed_modules.sorted_modules
end

def total_skunk_score
@analysed_modules.skunk_score_total
end

def total_churn_times_cost
@analysed_modules.total_churn_times_cost
end

def skunk_score_average
@analysed_modules.skunk_score_average
end

def table_options
return { style: { width: 100 } } if sorted_modules.empty?

max = sorted_modules.max_by { |a_mod| a_mod.pathname.to_s.length }
width = max.pathname.to_s.length + HEADINGS_WITHOUT_FILE_WIDTH
{
style: {
width: width
}
}
end

def table
@analysed_modules.files_as_hash.map { |file_hash| self.class.format_hash_row(file_hash) }
end

def self.format_hash_row(file_hash)
[
file_hash[:file],
file_hash[:skunk_score],
file_hash[:churn_times_cost],
file_hash[:churn],
file_hash[:cost],
file_hash[:coverage]
]
end
end
end
end
end
27 changes: 27 additions & 0 deletions lib/skunk/generators/console_report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "erb"
require "terminal-table"

require "skunk/generators/console/simple"

module Skunk
module Generator
# Generates a console report for the analysed modules.
class ConsoleReport
def initialize(analysed_modules)
@analysed_modules = analysed_modules
end

def generate_report
puts generator.render
end

private

def generator
@generator ||= Skunk::Generator::Console::Simple.new(@analysed_modules)
end
end
end
end
9 changes: 8 additions & 1 deletion lib/skunk/generators/html_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(analysed_modules)

def generate_report
create_directories_and_files
puts "Skunk report generated at #{report_location}"
puts "#{report_name} generated at #{report_location}"
browser.open unless RubyCritic::Config.no_browser
end

Expand All @@ -40,6 +40,13 @@ def generators
def overview_generator
@overview_generator ||= Skunk::Generator::Html::Overview.new(@analysed_modules)
end

def report_name
self.class.name.split("::").last
.gsub(/([a-z])([A-Z])/, '\1 \2')
.downcase
.capitalize
end
end
end
end
Loading