Fork of biomejs/gritql used as the pinned structural rewrite engine for Singularity code rules.
  • Rust 93.1%
  • Jupyter Notebook 3.1%
  • TypeScript 2.1%
  • JavaScript 1.1%
  • Python 0.3%
  • Other 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Mikael Hugo 11f2958811
Some checks failed
release-plz / release-plz (push) Has been cancelled
main / Rust tests (marzano) (push) Has been cancelled
main / Rust wasm (push) Has been cancelled
code quality / clippy_check (push) Has been cancelled
Deploy Next.js docs to GitHub Pages / build (push) Has been cancelled
Deploy Next.js docs to GitHub Pages / deploy (push) Has been cancelled
main / Test the standard library (push) Has been cancelled
chore: remove generated tree-sitter build outputs
2026-07-09 13:58:40 +00:00
.github chore(security): update github actions and pin to commit sha (#677) 2026-04-28 09:23:22 +01:00
.grit feat: improved notebook support (#354) 2024-05-26 02:03:22 -07:00
__generated__/grit-wasm-bindings feat: add docs directly to open source repo (#640) 2025-05-18 15:59:14 -07:00
assets chore: improve README (#41) 2024-03-20 14:19:05 -04:00
crates fix(core): correct deletion index calculation for char indices (#668) 2025-12-01 02:59:23 -08:00
docs fix(docs): repair input changes on playground (#666) 2025-11-14 00:14:55 -08:00
js/gritql chore(security): update github actions and pin to commit sha (#677) 2026-04-28 09:23:22 +01:00
python build: Update python packaging (#648) 2025-06-24 09:24:20 -07:00
resources chore: remove generated tree-sitter build outputs 2026-07-09 13:58:40 +00:00
vendor fix: switch clippy lint to direct usage (#599) 2025-01-07 09:56:15 -06:00
.coderabbit.yaml chore: tune coderabbit config (#220) 2024-04-12 18:45:14 -07:00
.gitattributes chore: remove vendored code from github language attributes (#47) 2024-03-21 15:03:25 -04:00
.gitignore ci: use depot workflows (#680) 2026-04-16 11:07:01 +01:00
.gitmodules feat: 570 kotlin support (#573) 2025-01-25 12:13:10 -06:00
.release-plz.toml chore: disable releases on GitHub (#367) 2024-06-02 18:41:07 -07:00
Cargo.lock feat: initial commit of napi bindings (#617) 2026-03-14 13:59:58 -07:00
Cargo.toml feat: initial commit of napi bindings (#617) 2026-03-14 13:59:58 -07:00
CONTRIBUTING.md chore: some general housekeeping (#690) 2026-04-16 22:37:02 +02:00
LICENSE chore: some general housekeeping (#690) 2026-04-16 22:37:02 +02:00
package.json feat: add docs directly to open source repo (#640) 2025-05-18 15:59:14 -07:00
README.md chore: some general housekeeping (#690) 2026-04-16 22:37:02 +02:00
renovate.json5 fix: renovate issue (#683) 2026-04-16 11:10:15 +01:00
rust-toolchain.toml ci: use depot workflows (#680) 2026-04-16 11:07:01 +01:00
SECURITY.md chore: Add SECURITY.md (#14) 2024-03-13 10:05:21 -04:00

Grit logo


GritQL is a declarative query language for searching and modifying source code.

  • 📖 Start simply without learning AST details: any code snippet is a valid GritQL query
  • Use Rust and query optimization to scale up to 10M+ line repositories
  • 📦 Use Grit's built-in module system to reuse 200+ standard patterns or share your own
  • ♻️ Once you learn GritQL, you can use it to rewrite any target language: JavaScript/TypeScript, Python, JSON, Java, Terraform, Solidity, CSS, Markdown, YAML, Rust, Go, or SQL
  • 🔧 GritQL makes it easy to include auto-fix rules for faster remediation

Getting started

Read the documentation, interactive tutorial, or run grit --help.

Installation

Install the Grit CLI:

curl -fsSL https://docs.grit.io/install | bash

Usage

Search for all your console.log calls by putting the desired pattern in backticks:

grit apply '`console.log($_)`'

Replace console.log with winston.log, using => to create rewrites:

grit apply '`console.log($msg)` => `winston.log($msg)`'

Save the pattern to a grit.yaml file and exclude test cases in a where clause:

cat << 'EOF' > .grit/grit.yaml
patterns:
  - name: use_winston
    level: error
    body: |
      `console.log($msg)` => `winston.log($msg)` where {
        $msg <: not within or { `it($_, $_)`, `test($_, $_)`, `describe($_, $_)` }
      }
EOF
grit apply use_winston

Run grit check to enforce your patterns as custom lints.

grit check

Examples

Remove all console.log calls, unless they are inside a try-catch block

`console.log($log)` => . where {
  $log <: not within `try { $_ } catch { $_ }`
}

Replace a method call with a new method call

`$instance.oldMethod($args)` => `$instance.newMethod($args)` where {
  $program <: contains `$instance = new TargetClass($_)`
}

More examples

Many more examples can be found in the GritQL standard library.

Patterns can be combined to create complex queries, including large refactors.

Why GritQL?

GritQL comes from our experiences with conducting large scale refactors and migrations.

Usually, migrations start with exploratory work to figure out the scope of the problem—often using simple grep searches. These are easy to start with, but most migrations end up accumulating additional requirements like ensuring the right packages are imported and excluding cases which dont have a viable migration path.

Eventually, any complex migration ends up being a full codemod program written 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.
  • Most frameworks are not composable, so youre stuck copying patterns back and forth.
  • Performance is often an afterthought, so iterating on a large codemod can be painfully slow.
  • Codemod frameworks are language-specific, so if youre hopping between multiple languages—or trying to migrate a shared API—you have to learn different frameworks.

GritQL is our attempt to develop a powerful middle ground:

  • Exploratory analysis is easy: just put a code snippet in backticks and use $metavariables for holes you want to represent.
  • 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.
  • Written in Rust for maximum performance: rewrite millions of lines of code in seconds.

Acknowledgements

GritQL uses tree-sitter for all language parsers and benefits greatly from the Rust ecosystem.

GritQL is released under the MIT license.

Contributing

Contributions are welcome. To get started, check out the contributing guidelines.

You can also join us on Discord.