lint: promote 105 safe any patterns to unknown (no-explicit-any −97)#38
Closed
adm01-debug wants to merge 1 commit into
Closed
lint: promote 105 safe any patterns to unknown (no-explicit-any −97)#38adm01-debug wants to merge 1 commit into
any patterns to unknown (no-explicit-any −97)#38adm01-debug wants to merge 1 commit into
Conversation
Reduces ESLint problem count by ~80 in the safe subset of
no-explicit-any without breaking any TypeScript types.
## scripts/codemod-any-to-unknown.mjs (new)
Targeted codemod that promotes 'any' to 'unknown' ONLY in patterns
where the change is mechanical and the type narrowing it forces is
a net positive:
Pattern Count Why safe
──────────────────────────────────────────────────────────────────
[key: string]: any 9 Index sig — consumer must
narrow before using value.
useState<any> 5 React state — narrow on read.
as any 20 Cast — 'as unknown' surfaces
the danger zone with one
extra cast.
Record<string, any> 32 Same as #1.
Map<K, any> 2 Same.
Set<any> 0 n/a in this codebase.
: any[] 37 Array members must narrow.
TOTAL 105 transforms across 67 files
The codemod uses a comment+string-stripping pre-pass so regex
matches don't trigger on documentation. All transforms are applied
right-to-left to preserve offsets across multiple matches per file.
## NOT handled (kept as 'any', tracked as roadmap)
- Bare ': any' parameter / return / variable annotations (~150
cases). Mechanical promotion to 'unknown' cascades type errors
through every consumer; these need contextual review.
- Generic args on RPC helpers ('invokeXxx<any>'). These are
deliberate 'narrow at the call site' markers; bumping them
breaks the API contract.
## Validation
no-explicit-any 257 → 160 violations
eslint 1939 → 1856 problems
tsc exit 0 (no type errors introduced)
tests no regressions
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
This was referenced Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ESLint: 1939 → 1856 problems (−83). 97 of 257
no-explicit-anyviolations resolved. No type errors introduced — all 105 mechanical transforms compile cleanly.scripts/codemod-any-to-unknown.mjs (new)
Targeted codemod that promotes
anytounknownonly in patterns where the change is mechanical and the narrowing it forces is a net positive:[key: string]: anyuseState<any>as anyas unknownrequires a 2nd cast, surfacing the danger zoneRecord<string, any>[key: string]: anyMap<K, any>: any[]The codemod pre-strips comments and string literals (replacing them with whitespace, length-preserving) so regex matches don't trigger inside documentation. Replacements applied right-to-left to preserve offsets.
NOT handled (kept as
any, tracked as roadmap): anyparameter/return/variable annotations (~150 cases). Mechanical promotion tounknowncascades type errors through every consumer; these need contextual review.invokeExternalRpc<any>,selectCrmById<any>). These are deliberate "narrow at the call site" markers; bumping them breaks the established API contract.These belong in dedicated follow-up PRs, ideally one per feature area.
Validation
no-explicit-anytsc --noEmitnpm run testfailinghttps://claude.ai/code/session_01KWeDG
Generated by Claude Code