chore: re-enable the prefer-const ESLint rule#250
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (41)
📝 WalkthroughWalkthroughThis PR enables the ESLint ChangesPrefer-const linting and refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
src/api/providers/anthropic-vertex.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. src/api/providers/anthropic.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. src/api/providers/bedrock.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.
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. Comment |
There was a problem hiding this comment.
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-constas an error with{ destructuring: "all" }in the ESLint flat config. - Apply mostly mechanical
let→constfixes across services, core, API providers, transforms, and tests. - Consolidate a few declare-then-assign patterns into single
constdeclarations.
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 | let → const 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 Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Summary
prefer-constwas disabled insrc/eslint.config.mjsunder a// TODO: These should be fixed and the rules re-enabledcomment. This re-enables it.["error", { destructuring: "all" }]. Withdestructuring: "all"it only flags a destructuring declaration when every binding can beconst; the default ("any") flags mixed const/let destructures and would force splitting them.eslint --fix):let→const.constdeclaration:api/providers/minimax.ts—streamapi/transform/cache-strategy/__tests__/cache-strategy.spec.ts—strategy(×2)core/tools/ExecuteCommandTool.ts—onCompletedPromise(the explicitPromise<void>type is preserved;resolveOnCompletedstaysletas it is assigned inside the executor)services/mcp/McpHub.ts—cancellationDisposablemoved to its single assignment site; thecleanupclosure that references it only runs asynchronously, so it is always initialized first.No behavior change.
Test plan
eslint .is clean acrosssrc/with the rule active.tsc --noEmitis clean.cache-strategy,ExecuteCommandTool,McpHub,minimax— 137 passed).Summary by CodeRabbit
Release Notes