Skip to content

chore: re-enable the prefer-const ESLint rule#250

Open
0xMink wants to merge 1 commit into
mainfrom
chore/eslint-prefer-const
Open

chore: re-enable the prefer-const ESLint rule#250
0xMink wants to merge 1 commit into
mainfrom
chore/eslint-prefer-const

Conversation

@0xMink
Copy link
Copy Markdown
Contributor

@0xMink 0xMink commented May 22, 2026

Summary

prefer-const was disabled in src/eslint.config.mjs under a // TODO: These should be fixed and the rules re-enabled comment. This re-enables it.

  • The rule is enabled as ["error", { destructuring: "all" }]. With destructuring: "all" it only flags a destructuring declaration when every binding can be const; the default ("any") flags mixed const/let destructures and would force splitting them.
  • ~90 violations are auto-fixed (eslint --fix): letconst.
  • 5 declare-then-assign cases were merged by hand into a single const declaration:
    • api/providers/minimax.tsstream
    • api/transform/cache-strategy/__tests__/cache-strategy.spec.tsstrategy (×2)
    • core/tools/ExecuteCommandTool.tsonCompletedPromise (the explicit Promise<void> type is preserved; resolveOnCompleted stays let as it is assigned inside the executor)
    • services/mcp/McpHub.tscancellationDisposable moved to its single assignment site; the cleanup closure that references it only runs asynchronously, so it is always initialized first.

No behavior change.

Test plan

  • eslint . is clean across src/ with the rule active.
  • tsc --noEmit is clean.
  • Tests for the hand-edited modules pass (cache-strategy, ExecuteCommandTool, McpHub, minimax — 137 passed).

Summary by CodeRabbit

Release Notes

  • Refactor
    • Improved code quality and consistency by enforcing stricter immutability patterns throughout the codebase.

Review Change Stack

prefer-const was disabled in src/eslint.config.mjs under a "TODO: re-enable" comment. Re-enabled with { destructuring: "all" } so it only flags a destructuring declaration when every binding can be const. Most violations were auto-fixed (let -> const); five declare-then-assign cases were merged by hand into a single const declaration. No behavior change — tsc and the tests for the touched modules pass.
Copilot AI review requested due to automatic review settings May 22, 2026 07:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 84715402-b5f1-4bac-98f3-664eda04a322

📥 Commits

Reviewing files that changed from the base of the PR and between 45b239c and 21dd749.

📒 Files selected for processing (41)
  • src/api/providers/anthropic-vertex.ts
  • src/api/providers/anthropic.ts
  • src/api/providers/bedrock.ts
  • src/api/providers/fake-ai.ts
  • src/api/providers/fetchers/ollama.ts
  • src/api/providers/gemini.ts
  • src/api/providers/lite-llm.ts
  • src/api/providers/minimax.ts
  • src/api/providers/openai-codex.ts
  • src/api/providers/openai-native.ts
  • src/api/providers/openrouter.ts
  • src/api/providers/requesty.ts
  • src/api/providers/unbound.ts
  • src/api/providers/vertex.ts
  • src/api/transform/cache-strategy/__tests__/cache-strategy.spec.ts
  • src/api/transform/cache-strategy/multi-point-strategy.ts
  • src/api/transform/caching/vercel-ai-gateway.ts
  • src/api/transform/model-params.ts
  • src/api/transform/openai-format.ts
  • src/core/config/CustomModesManager.ts
  • src/core/config/ProviderSettingsManager.ts
  • src/core/config/__tests__/CustomModesManager.exportImportSlugChange.spec.ts
  • src/core/config/__tests__/CustomModesManager.spec.ts
  • src/core/context-tracking/FileContextTracker.ts
  • src/core/diff/strategies/multi-search-replace.ts
  • src/core/environment/getEnvironmentDetails.ts
  • src/core/prompts/sections/system-info.ts
  • src/core/task/Task.ts
  • src/core/tools/ExecuteCommandTool.ts
  • src/core/tools/WriteToFileTool.ts
  • src/core/tools/accessMcpResourceTool.ts
  • src/core/webview/ClineProvider.ts
  • src/eslint.config.mjs
  • src/integrations/misc/extract-text.ts
  • src/integrations/terminal/ExecaTerminalProcess.ts
  • src/integrations/workspace/__tests__/WorkspaceTracker.spec.ts
  • src/services/code-index/embedders/bedrock.ts
  • src/services/code-index/orchestrator.ts
  • src/services/glob/list-files.ts
  • src/services/mcp/McpHub.ts
  • src/services/ripgrep/index.ts

📝 Walkthrough

Walkthrough

This PR enables the ESLint prefer-const rule with destructuring enforcement and refactors the entire codebase to use const instead of let for variables that don't require reassignment, improving code immutability and consistency across API providers, transformation layers, configuration management, and core services.

Changes

Prefer-const linting and refactoring

Layer / File(s) Summary
ESLint prefer-const rule enablement
src/eslint.config.mjs
ESLint configuration is updated to enforce prefer-const rule with destructuring: "all", changing from disabled ("off") to error-level enforcement. This triggers the downstream refactoring across the codebase.
API provider handlers const refactoring
src/api/providers/anthropic-vertex.ts, src/api/providers/anthropic.ts, src/api/providers/bedrock.ts, src/api/providers/fake-ai.ts, src/api/providers/fetchers/ollama.ts, src/api/providers/gemini.ts, src/api/providers/lite-llm.ts, src/api/providers/minimax.ts, src/api/providers/openai-codex.ts, src/api/providers/openai-native.ts, src/api/providers/openrouter.ts, src/api/providers/requesty.ts, src/api/providers/unbound.ts, src/api/providers/vertex.ts
All API provider handler classes refactored to use const for destructured model parameters (id, temperature, maxTokens), computed model identifiers, and request-related local variables. No changes to request/response logic or exported APIs.
Transform and cache strategy const refactoring
src/api/transform/cache-strategy/__tests__/cache-strategy.spec.ts, src/api/transform/cache-strategy/multi-point-strategy.ts, src/api/transform/caching/vercel-ai-gateway.ts, src/api/transform/model-params.ts, src/api/transform/openai-format.ts
Cache strategy instantiations, message conversion accumulators (toolResultImages, tool_calls), and model parameter variables updated to use const declarations while preserving push-based population and transformation logic.
Configuration and custom modes management const refactoring
src/core/config/CustomModesManager.ts, src/core/config/ProviderSettingsManager.ts, src/core/config/__tests__/CustomModesManager.exportImportSlugChange.spec.ts, src/core/config/__tests__/CustomModesManager.spec.ts
Configuration managers and test files refactored to use const for file accumulator arrays and profile name variables; type annotations standardized on Record<string, string> where applicable, with population logic preserved.
Core tools, context tracking, and service utilities const refactoring
src/core/context-tracking/FileContextTracker.ts, src/core/diff/strategies/multi-search-replace.ts, src/core/environment/getEnvironmentDetails.ts, src/core/prompts/sections/system-info.ts, src/core/task/Task.ts, src/core/tools/WriteToFileTool.ts, src/core/tools/accessMcpResourceTool.ts, src/integrations/misc/extract-text.ts, src/integrations/terminal/ExecaTerminalProcess.ts, src/integrations/workspace/__tests__/WorkspaceTracker.spec.ts, src/services/code-index/embedders/bedrock.ts, src/services/code-index/orchestrator.ts, src/services/glob/list-files.ts, src/services/ripgrep/index.ts
File tracking, diff strategy processing, environment collection, and service implementations updated to use const for accumulators and computed values; fuzzy-search state initialization reorganized without logic changes.
Complex state and promise coordination refactoring
src/core/tools/ExecuteCommandTool.ts, src/core/webview/ClineProvider.ts, src/services/mcp/McpHub.ts
Promise initialization pattern refactored in ExecuteCommandTool to define promise directly with const; ClineProvider callback handlers and state construction updated to use const with feature flags hard-set to false; McpHub OAuth flow variable scope adjusted with const at point of registration rather than pre-declaration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • taltas
  • hannesrudolph

Poem

A rabbit hops through const declarations,
Where let once varied without hesitation,
Now immutable paths are clearly drawn,
Linting rules ensure all are gone—
Immutability shines, bright and new! 🐰✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks the required sections from the template: Related GitHub Issue (no issue number provided), Test Procedure (testing steps not detailed), and Pre-Submission Checklist (not completed). While a custom summary is provided, required template elements are missing. Add the Related GitHub Issue section with the issue number, detail specific test procedures for reviewers to verify, and complete the Pre-Submission Checklist to meet template requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore: re-enable the prefer-const ESLint rule' accurately summarizes the main change: re-enabling a previously disabled ESLint rule.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/eslint-prefer-const

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/api/providers/anthropic-vertex.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/api/providers/anthropic.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

src/api/providers/bedrock.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 38 others

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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

Re-enables the ESLint prefer-const rule and updates the codebase to comply, primarily by converting let declarations to const where variables are never reassigned (plus a handful of manual declare-then-assign consolidations).

Changes:

  • Re-enable prefer-const as an error with { destructuring: "all" } in the ESLint flat config.
  • Apply mostly mechanical letconst fixes across services, core, API providers, transforms, and tests.
  • Consolidate a few declare-then-assign patterns into single const declarations.

Reviewed changes

Copilot reviewed 41 out of 41 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/eslint.config.mjs Re-enables prefer-const with desired options.
src/services/ripgrep/index.ts letconst for computed total results.
src/services/mcp/McpHub.ts Makes cancellation disposable a const at assignment site.
src/services/glob/list-files.ts results array binding made const (still mutated via push).
src/services/code-index/orchestrator.ts batchErrors binding made const in two scopes.
src/services/code-index/embedders/bedrock.ts modelId binding made const.
src/integrations/workspace/tests/WorkspaceTracker.spec.ts normalizedPath binding made const in mock.
src/integrations/terminal/ExecaTerminalProcess.ts output slice binding made const.
src/integrations/misc/extract-text.ts crPos / segment bindings made const.
src/core/webview/ClineProvider.ts await getState() destructures and fixed-false flags made const.
src/core/tools/WriteToFileTool.ts newContent binding made const in partial handler.
src/core/tools/ExecuteCommandTool.ts Consolidates onCompletedPromise into single const declaration.
src/core/tools/accessMcpResourceTool.ts images binding made const (still mutated via push).
src/core/task/Task.ts Several array/object bindings made const where not reassigned.
src/core/prompts/sections/system-info.ts details template binding made const.
src/core/environment/getEnvironmentDetails.ts terminalOutputs binding made const (still mutated).
src/core/diff/strategies/multi-search-replace.ts Several intermediate bindings made const.
src/core/context-tracking/FileContextTracker.ts newEntry binding made const.
src/core/config/ProviderSettingsManager.ts finalName bindings made const in cloud profile sync.
src/core/config/CustomModesManager.ts rulesFiles binding made const (still mutated).
src/core/config/tests/CustomModesManager.spec.ts Test local accumulators made const.
src/core/config/tests/CustomModesManager.exportImportSlugChange.spec.ts Test local accumulators made const.
src/api/transform/openai-format.ts Tool-result/tool-call intermediate arrays made const.
src/api/transform/model-params.ts verbosity binding made const.
src/api/transform/caching/vercel-ai-gateway.ts lastTextPart binding made const.
src/api/transform/cache-strategy/multi-point-strategy.ts cacheResult binding made const.
src/api/transform/cache-strategy/tests/cache-strategy.spec.ts Consolidates strategy into single const in two tests.
src/api/providers/vertex.ts Selected model id binding made const.
src/api/providers/unbound.ts openAiMessages binding made const.
src/api/providers/requesty.ts openAiMessages binding made const.
src/api/providers/openrouter.ts fetchModel() destructure made const.
src/api/providers/openai-native.ts Token total initializers made const within stream handler.
src/api/providers/openai-codex.ts Selected model id binding made const.
src/api/providers/minimax.ts Consolidates stream into single const declaration.
src/api/providers/lite-llm.ts maxTokens local binding made const.
src/api/providers/gemini.ts Selected model id and cost intermediate binding made const.
src/api/providers/fetchers/ollama.ts modelInfoPromises binding made const.
src/api/providers/fake-ai.ts fakeAiMap binding made const.
src/api/providers/bedrock.ts Several locals made const; minor formatting in invoked model extraction.
src/api/providers/anthropic.ts Model destructure and selected model id binding made const.
src/api/providers/anthropic-vertex.ts Model destructures and selected model id binding made const.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

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