Urgent.News

What's breaking now, across thousands of outlets.

Tech

Safely Pruning Dead Code and Dangling Imports with AST Transforms

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.…

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.

Reachability 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.

The 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.

To 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.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Native Desktop Themes for Production Apps

A desktop app needs more than larger versions of its phone controls. Dialogs need their own windows. Title bars, scrollbars, and keyboard focus need to behave as desktop users expect.

  • Codename One enables native desktop themes for production apps using single codebase.
  • Native themes include Fluent, Aqua, and Adwaita with light/dark appearances.
  • Settings tool supports themes, automatically selecting host OS theme.

More from Thursday 8 October →