Skip to content

refactor(core): remove unused calculateAllFileMetrics function and rename file#757

Merged
yamadashy merged 1 commit intomainfrom
refact/metrics
Aug 3, 2025
Merged

refactor(core): remove unused calculateAllFileMetrics function and rename file#757
yamadashy merged 1 commit intomainfrom
refact/metrics

Conversation

@yamadashy
Copy link
Owner

Summary

This PR removes the unused calculateAllFileMetrics function and renames the file to calculateSelectiveFileMetrics.ts to better reflect its purpose.

Changes made:

  • Removed calculateAllFileMetrics function that was only used in tests
  • Renamed calculateAllFileMetrics.tscalculateSelectiveFileMetrics.ts
  • Updated all imports and references across the codebase
  • Removed corresponding tests for the deleted function
  • Updated test file names and imports accordingly

The calculateAllFileMetrics function was redundant as only calculateSelectiveFileMetrics is used in production code. This simplifies the metrics calculation API and makes the codebase more maintainable.

Checklist

  • Run npm run test
  • Run npm run lint

🤖 Generated with Claude Code

…name file

Remove calculateAllFileMetrics function that was only used in tests and rename calculateAllFileMetrics.ts to calculateSelectiveFileMetrics.ts to match the remaining function. This simplifies the metrics calculation API by keeping only the selective file metrics functionality that is actually used in production code.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 3, 2025 05:21
@claude
Copy link
Contributor

claude bot commented Aug 3, 2025

Claude finished @yamadashy's task —— View job


PR Review Complete ✅

This is an excellent refactoring that improves code clarity and removes dead code. The changes are minimal, focused, and follow best practices.

Review Analysis:

✅ Code Quality & Best Practices

  • Clean removal of unused calculateAllFileMetrics function that was only used in tests
  • Improved naming: calculateSelectiveFileMetrics.ts better describes the function's purpose (processing only targeted files vs all files)
  • All imports and references properly updated across the codebase
  • Net code reduction (109 deletions, 6 additions) indicates good cleanup

✅ Architecture & Design

  • The selective approach is more efficient - only calculates token counts for top files by character count
  • Function signature in calculateSelectiveFileMetrics:10 clearly shows intent with targetFilePaths parameter
  • Maintains dependency injection pattern for testability (lines 15-17)

✅ Test Coverage

  • calculateSelectiveFileMetrics.test.ts properly tests both the main use case and edge case (no matching files)
  • diffTokenCount.test.ts cleaned up by removing tests for the deleted function
  • All remaining tests focus on actual production functionality

✅ Specific Highlights

  • calculateMetrics.ts:44 - The function call was already using calculateSelectiveFileMetrics, indicating this refactor completes a partially done migration
  • calculateSelectiveFileMetrics.ts:19-20 - Clean filtering logic using Set for O(1) lookup performance
  • Test files properly renamed to match the new function name

No Issues Found

  • All imports correctly updated
  • No breaking changes to public APIs
  • Error handling and cleanup logic preserved
  • Progress callback integration maintained

Final Assessment:

This refactoring exemplifies good software engineering practices: removing dead code, improving naming clarity, and maintaining test coverage. The changes are surgical and focused, making the codebase more maintainable without introducing any risks.

Recommendation: Approve


@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 3, 2025

Walkthrough

The changes remove the calculateAllFileMetrics function and its usage from both the codebase and related tests. The code now relies solely on calculateSelectiveFileMetrics and calculateGitDiffMetrics for metrics calculation. All references, imports, mocks, and tests associated with calculateAllFileMetrics have been deleted or updated accordingly.

Changes

Cohort / File(s) Change Summary
Core Metrics Calculation Logic
src/core/metrics/calculateMetrics.ts
Updated imports and dependency injection to remove calculateAllFileMetrics and use new metric functions. No internal logic changes.
Selective Metrics Implementation
src/core/metrics/calculateSelectiveFileMetrics.ts
Removed the calculateAllFileMetrics function; only calculateSelectiveFileMetrics remains exported.
Unit Tests for Metrics Calculation
tests/core/metrics/calculateMetrics.test.ts,
tests/core/metrics/calculateSelectiveFileMetrics.test.ts,
tests/core/metrics/diffTokenCount.test.ts
Removed all references, imports, mocks, and tests related to calculateAllFileMetrics. Tests now focus on selective metrics calculation.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant calculateMetrics
    participant calculateSelectiveFileMetrics
    participant calculateGitDiffMetrics

    Caller->>calculateMetrics: Invoke with files and options
    calculateMetrics->>calculateSelectiveFileMetrics: Calculate metrics for selective files
    calculateMetrics->>calculateGitDiffMetrics: Calculate metrics for git diff
    calculateMetrics-->>Caller: Return combined metrics result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refact/metrics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the metrics calculation module by removing an unused function and renaming the file to better reflect its purpose. The change eliminates redundancy in the codebase by keeping only the selective file metrics calculation function that is used in production.

  • Removed the unused calculateAllFileMetrics function from the codebase
  • Renamed file from calculateAllFileMetrics.ts to calculateSelectiveFileMetrics.ts
  • Updated all imports and test references to use the new file name

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/core/metrics/diffTokenCount.test.ts Removed mock references to the deleted calculateAllFileMetrics function
tests/core/metrics/calculateSelectiveFileMetrics.test.ts Updated imports and removed tests for the deleted function
tests/core/metrics/calculateMetrics.test.ts Updated imports and mock setup to reference the new file location
src/core/metrics/calculateSelectiveFileMetrics.ts Removed the calculateAllFileMetrics function while keeping calculateSelectiveFileMetrics
src/core/metrics/calculateMetrics.ts Updated imports to reference the new file location and removed unused dependency

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @yamadashy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on improving code maintainability and clarity by removing an identified unused function and renaming a core file to better represent its functionality. The changes streamline the metrics calculation logic by eliminating redundant code and updating all associated references and tests.

Highlights

  • Code Cleanup & Optimization: The calculateAllFileMetrics function, identified as unused and redundant (only used in tests), has been completely removed from the codebase. This simplifies the metrics calculation API and reduces unnecessary code.
  • File Renaming for Clarity: The file src/core/metrics/calculateAllFileMetrics.ts has been renamed to src/core/metrics/calculateSelectiveFileMetrics.ts. This change better reflects the actual purpose of the remaining function within the file, which is calculateSelectiveFileMetrics.
  • Test Suite Refinement: Corresponding test files and test cases related to the removed calculateAllFileMetrics function have been deleted or updated. This includes renaming tests/core/metrics/calculateAllFileMetrics.test.ts to tests/core/metrics/calculateSelectiveFileMetrics.test.ts and removing specific tests for the deleted function.
  • Dependency Updates: All imports and references across the codebase, including in src/core/metrics/calculateMetrics.ts and various test files, have been updated to reflect the removal of the function and the file rename.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Aug 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.38%. Comparing base (0de1f02) to head (3261204).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #757      +/-   ##
==========================================
- Coverage   88.44%   88.38%   -0.06%     
==========================================
  Files         106      106              
  Lines        5987     5940      -47     
  Branches     1217     1212       -5     
==========================================
- Hits         5295     5250      -45     
+ Misses        692      690       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a solid refactoring. You've successfully removed the unused calculateAllFileMetrics function and cleaned up the related files and tests. The file rename to calculateSelectiveFileMetrics.ts is a great improvement for clarity. All the changes are consistent with the goal of simplifying the API and improving maintainability. I've reviewed the changes carefully and found no issues. Great work!

@yamadashy yamadashy merged commit ce017d3 into main Aug 3, 2025
55 of 56 checks passed
@yamadashy yamadashy deleted the refact/metrics branch August 3, 2025 05:24
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
tests/core/metrics/calculateSelectiveFileMetrics.test.ts (1)

8-10: Module mock will not be picked up because the specifier misses .js

calculateSelectiveFileMetrics.ts imports the real module via
'../../shared/processConcurrency.js', but the mock here omits the file-extension, so Vitest treats it as a different module and the mock is never applied.

-vi.mock('../../shared/processConcurrency', () => ({
+vi.mock('../../shared/processConcurrency.js', () => ({
   getProcessConcurrency: () => 1,
 }));
🧹 Nitpick comments (3)
tests/core/metrics/calculateSelectiveFileMetrics.test.ts (2)

12-21: Unused parameters in test helper

mockInitTaskRunner receives numOfTasks / workerPath but never uses them, which is slightly misleading for future readers.

If you don’t need them, prefix with _ or drop them:

-const mockInitTaskRunner = <T, R>(numOfTasks: number, workerPath: string) => {
+const mockInitTaskRunner = <T, R>(_numOfTasks: number, _workerPath: string) => {

43-46: Hard-coded token counts make the test brittle

Tokenisation algorithms (and even encoder versions) can change; asserting magic numbers like 13 and 75 risks false negatives. Consider stubbing the underlying TokenCounter (as you already do in other tests) or asserting relative ordering instead of exact counts.

tests/core/metrics/calculateMetrics.test.ts (1)

18-20: Unused mock

vi.mock('../../../src/core/metrics/aggregateMetrics.js') is declared but never referenced. If aggregateMetrics is no longer imported anywhere you can safely drop this line to keep the test lean.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0de1f02 and 3261204.

📒 Files selected for processing (5)
  • src/core/metrics/calculateMetrics.ts (1 hunks)
  • src/core/metrics/calculateSelectiveFileMetrics.ts (0 hunks)
  • tests/core/metrics/calculateMetrics.test.ts (2 hunks)
  • tests/core/metrics/calculateSelectiveFileMetrics.test.ts (2 hunks)
  • tests/core/metrics/diffTokenCount.test.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • tests/core/metrics/diffTokenCount.test.ts
  • src/core/metrics/calculateSelectiveFileMetrics.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Build and run (windows-latest, 23.x)
  • GitHub Check: Build and run (windows-latest, 24.x)
  • GitHub Check: Build and run (windows-latest, 21.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
src/core/metrics/calculateMetrics.ts (2)

5-8: Imports updated correctly – good cleanup

The removal of the obsolete calculateAllFileMetrics import and replacement with the selective/git-diff variants keeps this module focused on what it actually needs.


44-47: Possible missing options argument

calculateSelectiveFileMetrics is invoked with four arguments, but your new tests show it expects a fifth options parameter (to inject initTaskRunner). If that parameter is non-optional the code will now fail at runtime/compile-time.

Please verify the function signature and add the extra argument if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants