|
| 1 | +# Repository Guidelines |
| 2 | + |
| 3 | +## Project Structure & Module Organization |
| 4 | +- `main.go` is the CLI entry point (`clickhouse-sql-parser`) for AST output and SQL formatting. |
| 5 | +- `parser/` contains core parser code: lexer (`lexer.go`), AST definitions (`ast.go`), traversal helpers (`walk.go`), and grammar-specific parser files (`parser_query.go`, `parser_table.go`, `parser_alter.go`, etc.). |
| 6 | +- Tests live next to source as `*_test.go` files, with fixtures under `parser/testdata/`. |
| 7 | +- Fixture groups are organized by SQL type (`basic/`, `query/`, `dml/`, `ddl/`), with generated expectations in `output/` (AST JSON) and `format/` (formatted SQL). |
| 8 | + |
| 9 | +## Build, Test, and Development Commands |
| 10 | +- `make` (or `go build -o clickhouse-sql-parser main.go`): build the CLI binary. |
| 11 | +- `make test`: run full test suite with race detection, coverage output (`coverage.out`), and compatibility tests. |
| 12 | +- `make update_test`: regenerate golden fixtures after intentional parser/formatter output changes. |
| 13 | +- `make lint`: run `golangci-lint` using the repo configuration. |
| 14 | +- `go test -bench=. -benchmem ./parser`: run parser benchmarks. |
| 15 | + |
| 16 | +## Coding Style & Naming Conventions |
| 17 | +- Use Go 1.21 conventions (`go.mod`) and keep code `gofmt`/`goimports` clean (enforced by lint). |
| 18 | +- Place parsing logic in the matching module by statement family (for example, query parsing in `parser/parser_query.go`). |
| 19 | +- Follow existing parser naming patterns such as `parseXxx` helpers and explicit AST type names. |
| 20 | +- Keep AST `String()` output deterministic; formatting changes must be reflected in golden files. |
| 21 | + |
| 22 | +## Testing Guidelines |
| 23 | +- Use Go’s `testing` package with `testify/require` assertions and `goldie` snapshot comparisons. |
| 24 | +- Add new SQL cases as `.sql` files under the appropriate `parser/testdata/<category>/` directory. |
| 25 | +- If expected outputs change, run `make update_test` and commit updated files in both `output/` and/or `format/`. |
| 26 | +- Prefer descriptive test names (`TestParser_*`, `TestWalk_*`) and subtests for per-fixture coverage. |
| 27 | + |
| 28 | +## Commit & Pull Request Guidelines |
| 29 | +- Match existing commit style: concise, imperative subjects like `Add support for ...` or `Fix parsing failure ...`, optionally with issue refs (for example `(#235)`). |
| 30 | +- Keep PRs focused; describe grammar/AST impact, include representative SQL examples, and note regenerated fixtures. |
| 31 | +- Before requesting review, run `make lint` and `make test` locally to mirror CI expectations. |
0 commit comments