Skip to content

lint: cleanup no-unused-vars (513 → 29) via codemod + ignore-pattern widening#37

Closed
adm01-debug wants to merge 1 commit into
mainfrom
claude/lint-unused-vars-sweep
Closed

lint: cleanup no-unused-vars (513 → 29) via codemod + ignore-pattern widening#37
adm01-debug wants to merge 1 commit into
mainfrom
claude/lint-unused-vars-sweep

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

Summary

ESLint problems: 1925 → 1448 (−477 on this branch). 484 of 513 @typescript-eslint/no-unused-vars violations auto-resolved.

scripts/codemod-unused-vars.mjs (new)

ESLint-driven codemod that walks the JSON output, locates each unused identifier, and applies the appropriate transform per declaration kind:

Kind Transform
IMPORT named specifier Remove from import { ... }; drop the entire line if the brace becomes empty
IMPORT default Drop the entire import line
FUNCTION PARAMETER Rename to _name (cannot remove without breaking arity)
DESTRUCTURED VARIABLE Rename to _name (siblings may be used)
LOCAL const/let Rename to _name (RHS may have side effects; safer than removal)
Already-prefixed (_name) Skip

Multi-line imports — handled correctly via look-back to find the enclosing import { ... } block when the line itself doesn't start with import.

node scripts/codemod-unused-vars.mjs            # rewrite src/
node scripts/codemod-unused-vars.mjs --check    # CI gate
node scripts/codemod-unused-vars.mjs --dry-run  # preview only

Edits applied

Files changed: 272. Edits — imports: 262, params: 45,
destructure: 130, locals: 43, skipped: 33.

eslint.config.js — widen ignore patterns

Added caughtErrorsIgnorePattern and destructuredArrayIgnorePattern to all four scoped configs. Both default to ^_ to match the existing args/vars pattern. This silences correctly-prefixed catch bindings like catch (_e) and intentional array-destructure ignores like [, _, third].

Remaining 29 cases

Destructured object args inside multi-line function signatures — e.g. function VideoGrid({ filteredVideos, variantMap, ... }). Renaming variantMap_variantMap would break the destructure target name. Proper fix is aliasing: { variantMap: _variantMap }, which is too case-by-case for a regex codemod. Tracked in the eslint roadmap for follow-up.

Validation

Metric Before After
Total problems 1925 1448
Errors 1426 949
no-unused-vars violations 513 29
tsc --noEmit exit 0 exit 0
npm run test failing 10/43 (pre-existing, see PR #28) 10/43 (same)

https://claude.ai/code/session_01KWeDG


Generated by Claude Code

Reduces ESLint problem count by another ~480 (1939 → 1448 since
session start, 1925 → 1448 on this branch).

## scripts/codemod-unused-vars.mjs (new)

ESLint-driven codemod that walks the JSON output, locates each
unused identifier, and applies the appropriate transform per
declaration kind:

  - Unused IMPORT named specifiers → removed from the import; the
    full import is dropped if the brace becomes empty.
  - Unused IMPORT default → import line removed.
  - Unused FUNCTION PARAMETERS / DESTRUCTURED VARS / LOCALS → renamed
    to '_name' so the eslint argsIgnorePattern/varsIgnorePattern
    treats them as intentional (safer than removal: RHS may have
    side effects).
  - Already-prefixed names ('_name') → skipped.
  - Multi-line imports — handled correctly via look-back to find the
    enclosing 'import \{ ... \}' block when the line itself doesn't
    start with 'import'.

Run: node scripts/codemod-unused-vars.mjs            # rewrite src/
     node scripts/codemod-unused-vars.mjs --check    # CI gate
     node scripts/codemod-unused-vars.mjs --dry-run

Result: 484 of 513 violations auto-resolved across 272 files
(262 import removals, 45 param renames, 130 destructure renames,
43 local renames, 14 silenced by config widening below).

## eslint.config.js — widen ignore patterns

Added 'caughtErrorsIgnorePattern' and 'destructuredArrayIgnorePattern'
to all four scoped configs (src/, e2e/, tests/, scripts/). Both
default to '^_' to match the existing args/vars pattern. This silences
correctly-prefixed catch bindings like 'catch (\_e)' and intentional
array-destructure ignores like '[, _, third]'.

## Remaining 29 cases

Destructured object args inside multi-line function signatures —
e.g. 'function VideoGrid(\{ filteredVideos, variantMap, ... \})'.
Renaming 'variantMap' → '\_variantMap' would break the destructure
target name. Proper fix is aliasing: '\{ variantMap: \_variantMap \}',
which is too case-by-case for a regex codemod. Tracked in the eslint
roadmap for follow-up.

## Validation

  eslint  1925 → 1448 problems (1426 → 949 errors)
  unused-vars  513 → 29 violations
  tsc     exit 0
  tests   43 failures (same as main; covered by PR #28)
@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: b0bce874-0457-4376-9e12-d2d025216bf0

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-unused-vars-sweep

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