Skip to content

lint: promote 105 safe any patterns to unknown (no-explicit-any −97)#38

Closed
adm01-debug wants to merge 1 commit into
mainfrom
claude/lint-no-explicit-any
Closed

lint: promote 105 safe any patterns to unknown (no-explicit-any −97)#38
adm01-debug wants to merge 1 commit into
mainfrom
claude/lint-no-explicit-any

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

Summary

ESLint: 1939 → 1856 problems (−83). 97 of 257 no-explicit-any violations resolved. No type errors introduced — all 105 mechanical transforms compile cleanly.

scripts/codemod-any-to-unknown.mjs (new)

Targeted codemod that promotes any to unknown only in patterns where the change is mechanical and the narrowing it forces is a net positive:

Pattern Count Why it's safe
[key: string]: any 9 Index signature — consumer must narrow before using value
useState<any> 5 React state — narrow on read; setter still accepts anything
as any 20 Cast — as unknown requires a 2nd cast, surfacing the danger zone
Record<string, any> 32 Same as [key: string]: any
Map<K, any> 2 Same
: any[] 37 Array — members must be narrowed before use
Total 105 across 67 files

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)

  • 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 (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

Metric Before After
Total problems 1939 1856
no-explicit-any 257 160
tsc --noEmit exit 0 exit 0
npm run test failing 10/43 (pre-existing, see PR #28) 10/43 (same)
Counts by pattern:
  index-signature          9
  useState-generic         5
  as-any                   20
  record-string-any        32
  map-value-any            2
  set-any                  0
  any-array-annotation     37
node scripts/codemod-any-to-unknown.mjs            # rewrite src/
node scripts/codemod-any-to-unknown.mjs --check    # CI gate
node scripts/codemod-any-to-unknown.mjs --dry-run  # preview

https://claude.ai/code/session_01KWeDG


Generated by Claude Code

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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ba02c32-b704-45e7-852d-3b8c10f0e068

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/lint-no-explicit-any

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.

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