Skip to content

Commit 2f061b9

Browse files
committed
chore: prepare claude loop
1 parent 8ee97ba commit 2f061b9

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ node_modules/
2424

2525
**/dist/
2626
.claude-session-id
27+
28+
squawk/

PLAN.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
The goal is to port all missing rules from Squawk to our analyser.
2+
3+
Our analyser lives in the `pgt_analyser` crate. There is a `CONTRIBUTING.md` guide in that crate which explains how to add new rules. Please also read existing rules to see how it all works.
4+
5+
Then, I want you to check the rules in the squawk project which I copied here for convenience. The rules are in `squawk/linter/src/rules`. The implementation should be very similar to what we have, and porting them straightforward. Here a few things to watch out for though:
6+
7+
- although both libraries are using `libpg_query` to parse the SQL, the bindings can be different. Ours is in the `pgt_query` crate of you need a reference. The `protobuf.rs` file contains the full thing.
8+
- the context for each rule is different, but you can get the same information out of it:
9+
```rust
10+
pub struct RuleContext<'a, R: Rule> {
11+
// the ast of the target statement
12+
stmt: &'a pgt_query::NodeEnum,
13+
// options for that specific rule
14+
options: &'a R::Options,
15+
// the schema cache - also includes the postgres version
16+
schema_cache: Option<&'a SchemaCache>,
17+
// the file context which contains other statements in that file in case you need them
18+
file_context: &'a AnalysedFileContext,
19+
}
20+
```
21+
22+
In squawk, you will see:
23+
```rust
24+
// all statements of that file -> our analyser goes statement by statement but has access to the files content via `file_context`
25+
tree: &[RawStmt],
26+
// the postgres version -> we store it in the schema cache
27+
_pg_version: Option<Version>,
28+
// for us, this is always true
29+
_assume_in_transaction: bool,
30+
31+
```
32+
33+
If you learn something new that might help in porting all the rules, please update this document.
34+
35+
Please update the list below with the rules that we need to migrate, and the ones that are already migrated. Keep the list up-to-date.
36+
37+
TODO:
38+
39+
40+
DONE:
41+
42+

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,6 @@ quick-modify:
152152
# just show-logs | bunyan
153153
show-logs:
154154
tail -f $(ls $PGT_LOG_PATH/server.log.* | sort -t- -k2,2 -k3,3 -k4,4 | tail -n 1)
155+
156+
port-squawk:
157+
unset ANTHROPIC_API_KEY && claude --dangerously-skip-permissions < PLAN.md

0 commit comments

Comments
 (0)