webpro / gritql

GritQL is a query language for searching, linting, and modifying code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GritQL

CI Status MIT License Discord

GritQL is a declarative query language for searching and modifying source code. GritQL focuses on a few areas:

  • 📖 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

Read the docs or try any query in the studio.

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

Find all your console.log calls:

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

Replace console.log with winston.log:

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

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

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

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.

About

GritQL is a query language for searching, linting, and modifying code.

License:MIT License


Languages

Language:C 96.4%Language:Rust 1.4%Language:JavaScript 1.0%Language:TypeScript 0.3%Language:Python 0.2%Language:CSS 0.2%Language:Go 0.2%Language:C++ 0.1%Language:Makefile 0.1%Language:Scheme 0.0%Language:HTML 0.0%Language:Shell 0.0%Language:Swift 0.0%Language:C# 0.0%Language:RenderScript 0.0%Language:Vue 0.0%Language:HCL 0.0%Language:Java 0.0%Language:CMake 0.0%Language:Solidity 0.0%Language:PLSQL 0.0%Language:Nix 0.0%Language:Ruby 0.0%