Code/Mod
Codemod
- a piece of code meant to modify another bit of code, typically used as part of a Software/Library/Upgrade
- These can be multi-language Polyglot Codemod Engines
- Or they can be single language, many of which are in this ChatGPT/Response
- Codemod ecosystems cluster around language-specific Programming/Abstract/Syntax/Tree toolkits, but a handful are becoming de-facto standards across many codebases:
Snapshot
- #Examples
- These frameworks all expose reusable visitors, pattern-matching DSLs, and CLI runners that let you ship repeatable codemods at scale. (OpenRewrite Docs, GitHub, LibCST, GitHub, CommandMasters, GitHub, GitLab, Microsoft Learn, Spoon, Docs.rs, GitHub)
Poly-language & Enterprise Scale - see also Polyglot Codemod Engines
OpenRewrite
- Recipe-based engine that rewrites Java, Kotlin, Groovy, XML, YAML, JSON and even Terraform/HCL through a common visitor API. (OpenRewrite Docs)
- Moderne’s SaaS runner layers org-wide scanning and security policies on top. (OpenRewrite Docs)
JavaScript / Typescript
Framework Highlights jscodeshift Facebook-maintained CLI + recast backend; pattern helpers, VS Code debugger. GitHub Babel codemod (via @babel/traverse) Write transforms directly on Babel AST; often wrapped by jscodeshift. TS-Morph Typed TypeScript AST with project-wide manipulation (not strictly a codemod runner but often used as one).
#Python
- Py/Lib/LibCST – lossless concrete syntax tree + “CodemodCommand” scaffolding and parallel runner. (LibCST)
- My Note
- 2025-05-16 Fri
- used by Person/Eugene Yurtsev for LangChain/v/0/2 release; Upcoming 0.2 release (week of 05/20) · langchain-ai/langchain · Discussion #21437 · GitHub 2024/05
- someone suggested GritQL in this thread, and in LangChain/v/0/3/Migrate using langchain-cli they migrationed that as of 0.3, they are using gritQL for the codemod engine
- used by Person/Sebastian Ramirez for the Pydantic/v/1 to Pydantic/v/2 translator, Py/Lib/bump-pydantic; see bump-pydantic/bump_pydantic/codemods/add_annotations.py at main · pydantic/bump-pydantic · GitHub
- used by Person/Eugene Yurtsev for LangChain/v/0/2 release; Upcoming 0.2 release (week of 05/20) · langchain-ai/langchain · Discussion #21437 · GitHub 2024/05
- 2025-05-16 Fri
- My Note
- Bowler – fluent query DSL built on fissix, good for large-scale refactors. (GitHub)
- Py/Lib/LibCST – lossless concrete syntax tree + “CodemodCommand” scaffolding and parallel runner. (LibCST)
#Java & JVM languages
- Spoon – programmatic Java AST with code generation and transformation; integrates with Maven/Gradle. (Spoon)
- OpenRewrite (above) – brings codemods into build pipelines via Maven/Gradle plugins. (OpenRewrite Docs)
C / C++
- clang-tidy/clang-tooling – part of LLVM; custom checks double as codemods, fix-it hints can be auto-applied. (CommandMasters)
- Coccinelle – SmPL semantic-patch language designed for Linux-kernel-scale collateral evolutions. (GitLab)
C# / .NET
- Roslyn analyzers + CodeFix providers – first-class in Visual Studio; write analyzers that emit diagnostics and auto-fixes. (Microsoft Learn)
Scala
- Scalafix – integrates with sbt/mill; supports semantic rewrites using SemanticDB. (GitHub)
#Rust
- rustfix / cargo fix – consumes
rustcJSON suggestions to apply automated fixes, built into Cargo workflows. (Docs.rs)
- rustfix / cargo fix – consumes
#PHP
- Rector – rule-based refactoring engine covering PHP 5.3-8.x and frameworks like Symfony and PHPUnit. (GitHub)
Choosing a framework
- Language support & AST fidelity – pick the one that preserves formatting (LibCST, Spoon) if diff minimalism matters.
- Ecosystem integration – build-tool plugins (OpenRewrite, Scalafix, clang-tidy) ease CI rollout.
- Declarative vs imperative – SmPL (Coccinelle) and OpenRewrite yaml recipes favor pattern matching; Bowler/jscodeshift give imperative control.
- Scale & parallelization – Py/Lib/LibCST, jscodeshift and OpenRewrite offer built-in parallel runners for monorepos.
- These frameworks let you codify large-scale migrations—API changes, language upgrades, security fixes—into repeatable, review-friendly scripts instead of one-off search-and-replace.