|
| 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 | + |
0 commit comments