{
  "id": 12935085,
  "title": "Safely Pruning Dead Code and Dangling Imports with AST Transforms",
  "url": "https://urgent.news/2026/10/08/safely-pruning-dead-code-and-dangling-imports-with-ast-transforms",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-08T19:22:18.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/vansharora21/safely-pruning-dead-code-and-dangling-imports-with-ast-transforms-2076"
  },
  "original_language": "en",
  "account": "Manual removal of outdated code and dangling imports is a time-consuming task. Deleting function bodies, export statements, and untangling obsolete imports requires careful testing to avoid introducing syntax errors. TokenCap, an automated refactoring tool, streamlines this process with a single command.\n\nReachability Confirmation: TokenCap verifies the target symbol against the call graph, ensuring it has no active callers. AST Node Removal locates the declaration statement node via Tree-sitter coordinates and eliminates it without disturbing surrounding indentation. Import Sweep inspects file imports, automatically removing any specifier used exclusively within the pruned function.\n\nThe tool provides a formatting cleanup, reconciling empty lines and commas for a clean, readable codebase. A CLI example demonstrates the safe removal of dead code in src/utils/formatters.js:formatLegacyCurrency. The dry run output confirms the removal of one function and one unused import with zero syntax errors.\n\nTo apply the changes directly to disk, simply omit the --dry-run flag. TokenCap's refactoring tools are available at tokencap.vansharora.app for further exploration.",
  "summary": "Deleting obsolete code manually is tedious. You delete the function body, then delete the export statement, run tests, see an unused import warning, and delete the import statement. In TokenCap, we automated this workflow via tokencap refactor rm-dead . How Atomic Pruning Works Reachability Confirmation: The target symbol is verified against the call graph to confirm it has zero active callers.…",
  "key_points": [
    "TokenCap automates refactoring of dead code and dangling imports",
    "Reachability Confirmation verifies symbols against call graph",
    "AST Node Removal eliminates declaration nodes without syntax errors"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}