r/mcp • • 5d ago

showcase Dead code detection for 19 languages with one table and no call graph

I wanted dead-code removal that works the same in Python, Go, TypeScript, Rust, Lua and the rest, without a parser per language.

The rule is a count: a name is dead when every mention of it is inside its own definition. Any other mention anywhere (another file, a string, a template, a YAML file) keeps it alive.

  1. One scanner blanks comments and strings for every language, from a table entry.
  2. A definition is a regex plus how its block ends: braces, indentation or an end keyword.
  3. A count can miss dead code. It can't invent it.
  4. Then the project's own tests run after every deletion, and whatever breaks them is put back.

What a count can't see (a public method called through an interface, a subclass a framework registers) is marked risky and left for a reviewer.

A language is about twenty lines in src/lang.rs.

https://github.com/EL4CTEO/shrink-anything · MIT

1 Upvotes

0 comments sorted by