Wednesday, March 20, 2024
Show HN: GritQL, a Rust CLI for rewriting source code https://ift.tt/36Ab5Sg
Show HN: GritQL, a Rust CLI for rewriting source code Hi everyone! I’m excited to open source GritQL, a Rust CLI for searching and transforming source code. GritQL comes from my experiences with conducting large scale refactors and migrations. Usually, I would start exploring a codebase with grep. This is easy to start with, but most migrations end up accumulating additional requirements like ensuring the right packages are imported and excluding cases which don’t have a viable migration path. Eventually, to build a complex migration, I usually ended up having to write a full codemod program with a tool like jscodeshift. This comes with its own problems: - Most of the exploratory work has to be abandoned as you figure out how to represent your original regex search as an AST. - Reading/writing a codemod requires mentally translating from AST names back to what source code actually looks like. - Performance is often an afterthought, so iterating on a large codemod can be painfully slow. - Codemod frameworks are language-specific, so if you’re hopping between multiple languages—or trying to migrate a shared API—you have to learn different tools. GritQL is an attempt to develop a powerful middle ground: - Exploratory analysis is easy: just put a code snippet in backticks and use $metavariables for placeholders. - Incrementally add complexity by introducing side conditions with where clauses. - Reuse named patterns to avoid rebuilding queries, and use shared patterns from our standard library for common tasks like ensuring modules are imported. - Iterate on large codebases quickly: we use Rust for maximum performance GritQL has already been used on thousands of repositories for complex migrations[1] but we're excited to collaborate more with the open source community. [1] Ex. https://ift.tt/yb2xqU1 https://ift.tt/ZTN7Uiq March 21, 2024 at 12:53AM
Subscribe to:
Post Comments (Atom)
Show HN: Announcing Nest2D.dev: Open-Source Server-Side Nesting for DXF https://ift.tt/p6yH0ub
Show HN: Announcing Nest2D.dev: Open-Source Server-Side Nesting for DXF https://ift.tt/HfEishx April 27, 2025 at 11:39PM
-
Show HN: High school robotics code/CAD/design binder release Hello HN! My name is Patrick, and I am a junior at my High School’s FRC robotic...
-
Show HN: D&D meets Siri – Interactive voice adventure Hey HN! I've been building tooling for voice-driven apps over the past few mon...
-
Show HN: I Made an AI Social Media Manager to Automate Content Creation Hey HN, I am a Solopreneur, and I love building apps to automate bor...
No comments:
Post a Comment