Skip to content

refactor(eslint-plugin-query): remove unused ast-utils helpers#11115

Open
electrohyun wants to merge 2 commits into
TanStack:mainfrom
electrohyun:refactor/remove-unused-ast-utils
Open

refactor(eslint-plugin-query): remove unused ast-utils helpers#11115
electrohyun wants to merge 2 commits into
TanStack:mainfrom
electrohyun:refactor/remove-unused-ast-utils

Conversation

@electrohyun

@electrohyun electrohyun commented Jul 24, 2026

Copy link
Copy Markdown

🎯 Changes

TL;DR: the ASTUtils object has five unused helpers. Removing them drops 194 lines, and all 1,709 tests still pass.

Hello, I came across this while running test coverage on @tanstack/eslint-plugin-query: the file src/utils/ast-utils.ts sits far below the rest of the package (41% line coverage vs. a ~83% package average):

ast-utils.ts line coverage before: 41%
File            | % Stmts | % Branch | % Funcs | % Lines
----------------|---------|----------|---------|--------
All files       |  82.98  |  76.03   |  89.54  |  83.44
 ast-utils.ts   |  42.33  |  34.10   |  63.15  |  41.04   -> outlier

To see why, I traced every ASTUtils.<member> reference across src/, matching each against the member's own definition range so that self-recursive calls don't count as usage. Five members turned out to be dead code (see the References column below).

  • ASTUtils is not exported from src/index.ts, and the exports field in package.json only exposes "." and "./package.json", so these members aren't reachable as public API.
  • ASTUtils is exported as a single object, and per knip's docs knip does not yet detect unused members of objects (only of enums and classes), which is why this was never surfaced.

Removed helpers

Function What it did References
getNestedIdentifiers Recursively collected every Identifier node nested within a node none (self-recursive calls only)
getNestedReturnStatements Recursively collected every ReturnStatement node within a node none (self-recursive calls only)
getClosestVariableDeclarator Walked up the ancestor chain to the nearest VariableDeclarator none
mapKeyNodeToBaseText Stripped optional-chaining (?.) and non-null (!) operators from mapKeyNodeToText's result none
mapKeyNodeToText Returned the source text of a key node after traversing up member expressions only from mapKeyNodeToBaseText, so unused once that is removed
ast-utils.ts line coverage after removing the helpers: 95%

This removes 194 lines. All 1,709 tests still pass, which confirms nothing was using this code. Line coverage of ast-utils.ts then rises from 41% -> 95% (package: 83% -> 93%) as a side effect of dropping code that was never covered.

If any of these helpers were intentionally kept for use in upcoming rules, please let me know. In that case I'm happy to switch this PR from removing them to adding test coverage for them instead.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.

I added a patch changeset because previous internal-code removals (#10082, #10574) included one. If you consider this purely internal and prefer no release, let me know and I'll drop it.

Summary by CodeRabbit

  • Chores
    • Removed unused internal code-analysis helpers.
    • No changes to user-facing functionality or public APIs.
  • Release
    • Prepared a patch release for the ESLint plugin.

Remove five unused helpers from the ASTUtils object in ast-utils.ts:
getNestedIdentifiers, getNestedReturnStatements, getClosestVariableDeclarator,
mapKeyNodeToText and mapKeyNodeToBaseText.

None are referenced by any rule or other module, and ASTUtils is not part of
the package's public API (it is not exported from index.ts). knip does not flag
them because ASTUtils is exported as a single object, so member-level dead code
slips past it.

All 1709 tests pass and ast-utils.ts line coverage rises from 41% to 95%.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 2714062d-2752-4bef-aa89-31944776cf9a

📥 Commits

Reviewing files that changed from the base of the PR and between fd50fa1 and 2739709.

📒 Files selected for processing (2)
  • .changeset/remove-unused-ast-utils-helpers.md
  • packages/eslint-plugin-query/src/utils/ast-utils.ts
💤 Files with no reviewable changes (1)
  • packages/eslint-plugin-query/src/utils/ast-utils.ts

📝 Walkthrough

Walkthrough

Five unused internal ASTUtils helpers were removed from the ESLint plugin, and a patch-level changeset documenting the cleanup was added.

Changes

AST utilities cleanup

Layer / File(s) Summary
Remove unused ASTUtils helpers
packages/eslint-plugin-query/src/utils/ast-utils.ts, .changeset/remove-unused-ast-utils-helpers.md
Removes nested identifier and return collectors, key text mappers, and closest variable declarator lookup, with a patch release changeset documenting the removal.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing unused ast-utils helpers.
Description check ✅ Passed The description follows the required template and includes changes, checklist items, and release impact with a changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

1 participant