hn.today

Show HN: Treepeat – Code similarity detection using Tree-sitter

github.com4 points0 comments
Screenshot of Show HN: Treepeat – Code similarity detection using Tree-sitter

Treepeat is a command-line tool that detects duplicate, near-duplicate, and structurally similar code by parsing source files with Tree-sitter, normalizing their ASTs, and comparing fingerprints using locality-sensitive hashing. It supports multiple languages (including Python, JavaScript/TypeScript, Go, Rust, Java/Kotlin, SQL, HTML/CSS, Bash, Lua, Markdown, YAML and more) and is offered as a proof-of-concept package installable via pip. Normalization rulesets control sensitivity: "none" reports exact duplicate blocks, "default" ignores whitespace/strings and high-level AST differences for near-duplicates, and "loose" anonymizes identifiers and constants to reveal structural similarity. The project encourages contributions and includes documentation, ADRs, and a performance harness.

Usage centers on a detect command with flags to set similarity percentage, minimum matched lines, side-by-side diffs, output format (console or SARIF for CI), verbosity, and interactive progress. Additional commands list ruleset rules per language and show how source is tokenized and normalized for debugging. Developer conveniences include make targets for setup and tests, a tools/perf harness for benchmarking real repos, and standard project files (license, README, tests). The implementation emphasizes language-aware, AST-based matches rather than simple line-based heuristics.

Read on github.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.