Skip to content

Commit

Permalink
chore: add some basic Grit patterns (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Lars Kappert <[email protected]>
  • Loading branch information
morgante and webpro authored Mar 9, 2024
1 parent 45180ff commit 300cebb
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
target
.grit
2 changes: 2 additions & 0 deletions .grit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gritmodules*
*.log
14 changes: 14 additions & 0 deletions .grit/grit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 0.0.1
patterns:
- name: github.com/getgrit/stdlib#*
- name: no_println_in_lsp
description: Don't use println!() in LSP code, it breaks the LSP stdio protocol.
level: error
body: |
engine marzano(0.1)
language rust
`println!($_)` => . where {
$filename <: not includes "test.rs",
$absolute_filename <: includes "apps/marzano/lsp",
}
23 changes: 23 additions & 0 deletions .grit/patterns/flushable_unwrap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Force flushing

Prevent returning without flushing the emitter in `apply_pattern.rs`.

```grit
language rust
pattern flushable_return() {
`$expression?` where {
$expression <: not includes "flush",
$expression <: not within `let mut emitter: MessengerVariant = $_;`,
$expression => `flushable_unwrap!(emitter, $expression)`
}
}
file(name=includes "apply_pattern.rs", $body) where {
$body <: contains `pub(crate) async fn run_apply_pattern(
$_
) -> Result<()> { $func }` where {
$func <: contains flushable_return()
}
}
```
28 changes: 28 additions & 0 deletions .grit/patterns/no_panic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
level: info
---

# Avoid panic

Panics should be avoided in core Grit code. Instead, use `?` to propagate errors.

```grit
language rust
file($name, $body) where {
$name <: includes "marzano/lsp",
$body <: contains `$foo.unwrap()` => `$foo?`,
}
```

## Sample

```rust
// @filename: marzano/lsp/foo.rs
let x = bar().unwrap();
```

```rust
// @filename: marzano/lsp/foo.rs
let x = bar()?;
```
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# GritQL

[![CI Status](https://img.shields.io/github/actions/workflow/status/getgrit/tree-sitter-gritql/ci.yml)](https://github.com/getgrit/tree-sitter-gritql/actions/workflows/ci.yml)
[![MIT License](https://img.shields.io/github/license/getgrit/tree-sitter-gritql)](https://github.com/getgrit/tree-sitter-gritql/blob/main/LICENSE)
[![CI Status](https://img.shields.io/github/actions/workflow/status/getgrit/gritql/main.yml)](https://github.com/getgrit/gritql/actions/workflows/main.yml)
[![MIT License](https://img.shields.io/github/license/getgrit/gritql)](https://github.com/getgrit/gritql/blob/main/LICENSE)
[![Discord](https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord)](https://docs.grit.io/discord)

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

0 comments on commit 300cebb

Please sign in to comment.