Refactor Skunk Analysis: centralize Skunk attributes#127
Conversation
Refactor Skunk analysis integration by removing the Analysis class and adding its methods directly to RubyCritic::AnalysedModulesCollection. Update related files to utilize the new methods for Skunk score calculations and reporting.
There was a problem hiding this comment.
Pull Request Overview
This PR refactors Skunk analysis by moving functionality from a separate Analysis class into RubyCritic::AnalysedModulesCollection as instance methods. This provides better encapsulation and follows Ruby's module-based architecture patterns.
- Adds Skunk-specific methods directly to AnalysedModulesCollection for calculating scores and filtering modules
- Updates dependent classes (StatusReporter, Html::Overview, Json::Simple) to use collection methods instead of separate analysis class
- Removes the standalone SkunkData class and integrates its functionality into the collection
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_helper.rb | Adds require for skunk gem |
| test/lib/skunk/rubycritic/analysed_modules_collection_test.rb | New comprehensive test suite for collection methods |
| test/lib/skunk/generators/html/path_truncator_test.rb | Removes rubocop disable comments |
| test/lib/skunk/config_test.rb | Adds documentation comments and clarifies duplicate test |
| test/lib/skunk/commands/status_reporter_test.rb | Adds require for analysed_modules_collection |
| lib/skunk/rubycritic/analysed_modules_collection.rb | Monkey-patches collection with Skunk analysis methods |
| lib/skunk/generators/json/simple.rb | Simplifies by using collection's to_hash method |
| lib/skunk/generators/html/templates/skunk_overview.html.erb | Updates template to use collection methods directly |
| lib/skunk/generators/html/skunk_data.rb | Removes entire file (functionality moved to collection) |
| lib/skunk/generators/html/overview.rb | Refactored to use collection methods instead of SkunkData |
| lib/skunk/commands/status_reporter.rb | Delegates analysis methods to collection |
| .rubocop_todo.yml | Updates timestamp and block length metrics |
| .reek.yml | Adds exclusions for new test methods |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| def test_add_format_ignores_duplicates | ||
| Config.add_format(:html) | ||
| Config.add_format(:html) | ||
| Config.add_format(:html) # This should be ignored as duplicate |
There was a problem hiding this comment.
[nitpick] The inline comment is redundant since the test method name 'test_add_format_ignores_duplicates' and the assertion already make the intent clear.
| Config.add_format(:html) # This should be ignored as duplicate | |
| Config.add_format(:html) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Since now we have multiple reports, I hope that also tracks on you, and let me know if you find a better way to manage the Skunk Scores Chears, |
|
Taking a look at this now |
fbuys
left a comment
There was a problem hiding this comment.
This looks good and works as expected locally for me.
| def skunk_score_average | ||
| num_modules = @modules.size | ||
| if num_modules.positive? | ||
| sum(&:skunk_score) / num_modules.to_f | ||
| else | ||
| 0.0 | ||
| return 0.0 if analysed_modules_count.zero? | ||
|
|
||
| (skunk_score_total.to_d / analysed_modules_count).to_f.round(2) |
There was a problem hiding this comment.
Hey @etagwerker I wanted to highlight this change.
This change would alter how we calculate the average (only consider non_test_modules going forward).
The change makes sense to me, but it might affect any analysis that we have done or wish to do.
Co-authored-by: Francois <buys.fran@gmail.com>
Summary
This PR refactors the Skunk analysis, integrating its methods directly into RubyCritic::AnalysedModulesCollection. This approach provides better encapsulation and follows Ruby's module-based architecture patterns.
Changes
• Enhanced RubyCritic::AnalysedModulesCollection: Added Skunk-specific methods directly to the collection:
skunk_score- Calculate total Skunk score for all modulesaverage_skunk_score- Calculate average Skunk scoreworst_modules- Find modules with highest Skunk scorestest_modules- Filter test modules from the collectionto_h- Convert collection to hash format for JSON serialization• Updated dependent classes: Modified all classes that previously used the Analysis class:
StatusReporter: Now uses collection methods directlyHtml::Overview: Simplified by using collection methodsJson::Simple: Uses collection'sto_hmethod for consistent data structureBenefits
• Better encapsulation: Skunk analysis logic is now part of the RubyCritic ecosystem
• Reduced complexity: Eliminates the need for a separate analysis class
• Improved maintainability: Changes to analysis logic are centralized in the collection
• Consistent API: All report generators now use the same collection-based interface
• Follows Ruby patterns: Uses module-based architecture instead of standalone classes
Testing
• All existing tests pass
• Updated test suite to work with the new module-based approach
• Maintained comprehensive coverage of all Skunk analysis functionality
This refactoring improves code organization by integrating Skunk analysis directly into the RubyCritic framework while maintaining all existing functionality.