TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Codemodder – A new codemod library for Java and Python

37 pointsby nahsraover 1 year ago
Hi HN, I’m here to show you a new codemod library. In case you’re not familiar with the term &quot;codemod&quot;, here’s how it was originally defined AFAICT:<p>&gt; Codemod is a tool&#x2F;library to assist you with large-scale codebase refactors<p>Codemods are awesome, but I felt they were far from their potential, and so I’m very proud to show you all an early version of a codemod library we’ve built called Codemodder (<a href="https:&#x2F;&#x2F;codemodder.io" rel="nofollow">https:&#x2F;&#x2F;codemodder.io</a>) that we think moves the &quot;field&quot; forward. Codemodder supports both Python and Java (<a href="https:&#x2F;&#x2F;github.com&#x2F;pixee&#x2F;codemodder-python">https:&#x2F;&#x2F;github.com&#x2F;pixee&#x2F;codemodder-python</a> and <a href="https:&#x2F;&#x2F;github.com&#x2F;pixee&#x2F;codemodder-java">https:&#x2F;&#x2F;github.com&#x2F;pixee&#x2F;codemodder-java</a>). The license is AGPL, please don’t kill me.<p>Primarily, what makes Codemodder different is our design philosophy. Instead of trying to write a new library for both finding code and changing code, which is what traditional codemod libraries do, we aim to provide an easy-to-use orchestration library that helps connect idiomatic tools for querying source code and idiomatic tools for mutating source code.<p>So, if you love your current linter, Semgrep, Sonar, or PMD, CodeQL or whatever for querying source code – use them! If you love JavaParser or libCST for changing source code – use them! We’ll provide you with all the glue and make building, testing, packaging and orchestrating them easy.<p>Here are the problems with existing codemod libraries as they exist today, and how Codemodder solves them.<p>1. They’re not expressive enough. They tend to offer barebones APIs for querying code. There’s simply no way for these libraries to compete with purpose-built static analysis tools for querying code, so we should use them instead.<p>2. They produce changes without any context. Understanding why a code change is made is important. If the change was obvious to the developer receiving the code change, they probably wouldn’t have made the mistake in the first place! Storytelling is everything, and so we guide you towards making changes that are more likely to be merged.<p>3. They don’t handle injecting dependencies well. I have to say we’re not great at this yet either, but we have some of the basics and will invest more.<p>4. Most apps involve multiple languages, but all of today’s codemod libraries are for one language, so they are hard to orchestrate for a single project. We’ve put a lot of work into making sure these libraries are aligned with open source API contracts and formats (<a href="https:&#x2F;&#x2F;github.com&#x2F;pixee&#x2F;codemodder-specs">https:&#x2F;&#x2F;github.com&#x2F;pixee&#x2F;codemodder-specs</a>) so they can be orchestrated similarly by downstream automation.<p>The idea is &quot;don’t write another PR comment saying the same thing, write a codemod to just make the change automatically for you every time&quot;. We hope you like it, and are excited to get any feedback you might have!

3 comments

westurnerover 1 year ago
How does libCST compare to e.g. pyCQA&#x2F;redbaron? What about for EA Evolutionary Algorithms; does it preserve comments, or update docstrings and type annotations in mutating the code under test?<p>Is it necessary to run `black` (and `precommit run --all-files`) to format the code after mutating it?<p>Instagram&#x2F;LibCST: <a href="https:&#x2F;&#x2F;github.com&#x2F;Instagram&#x2F;LibCST">https:&#x2F;&#x2F;github.com&#x2F;Instagram&#x2F;LibCST</a><p>PyCQA&#x2F;redbaron: <a href="https:&#x2F;&#x2F;github.com&#x2F;PyCQA&#x2F;redbaron">https:&#x2F;&#x2F;github.com&#x2F;PyCQA&#x2F;redbaron</a><p>E.g. PyCQA&#x2F;bandit does static analysis for security issues in Python code: <a href="https:&#x2F;&#x2F;github.com&#x2F;PyCQA&#x2F;bandit">https:&#x2F;&#x2F;github.com&#x2F;PyCQA&#x2F;bandit</a><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=38677294">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=38677294</a><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24511280">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24511280</a> ... <a href="https:&#x2F;&#x2F;analysis-tools.dev&#x2F;tools?languages=python" rel="nofollow">https:&#x2F;&#x2F;analysis-tools.dev&#x2F;tools?languages=python</a>
评论 #39112803 未加载
morganteover 1 year ago
Interesting approach of basically providing a meta-layer on top of existing tools.<p>Do you have an example of how you inject context into the codemods? The approach we&#x27;ve taken at Grit is two-fold:<p>1. When something <i>must</i> be addressed (ex. `todo`), we have functions that wrap messages into the source code to ensure anyone sees the info until it&#x27;s fixed. We pick up these messages automatically on our SaaS platform.<p>2. For non-blocking comments, we have a `log` function that any query can call to surface info into the result stream on the CLI + pull requests without it ending up in the final PR.<p>&gt;4. all of today’s codemod libraries are for one language, so they are hard to orchestrate for a single project.<p>This isn&#x27;t entirely true! Grit, my project, was built to be multi-language from the start: <a href="https:&#x2F;&#x2F;docs.grit.io&#x2F;language&#x2F;overview" rel="nofollow">https:&#x2F;&#x2F;docs.grit.io&#x2F;language&#x2F;overview</a><p>[0] <a href="https:&#x2F;&#x2F;docs.grit.io&#x2F;language&#x2F;functions#todo" rel="nofollow">https:&#x2F;&#x2F;docs.grit.io&#x2F;language&#x2F;functions#todo</a>
评论 #39126059 未加载
blackfurover 1 year ago
Have you heard about Mixin? What advantages could Codemodder have over SpongePowered Mixins?
评论 #39118979 未加载