|
| 1 | +# dprint-plugin-sql |
| 2 | + |
| 3 | +Wrapper around [sqlformat-rs](https://github.com/shssoichiro/sqlformat-rs) for use as a dprint formatting plugin. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +- `cargo test` — run all tests |
| 8 | +- `cargo build --target wasm32-unknown-unknown --features wasm --release` — build the wasm plugin |
| 9 | +- `cd deployment/npm && node setup.js && npm test` — test the npm package (requires wasm build first) |
| 10 | + |
| 11 | +## Architecture |
| 12 | + |
| 13 | +- `src/format_text.rs` — core formatting logic, delegates to `sqlformat::format()` |
| 14 | +- `src/wasm_plugin.rs` — dprint wasm plugin interface (compiled only for wasm32 target with `wasm` feature) |
| 15 | +- `src/configuration/` — config types, resolution, and builder |
| 16 | +- `deployment/npm/` — npm package that ships `plugin.wasm` |
| 17 | +- `deployment/schema.json` — JSON schema for plugin configuration |
| 18 | +- `scripts/update.ts` — Deno script that checks crates.io for new sqlformat versions and auto-publishes |
| 19 | +- `scripts/generateReleaseNotes.ts` — generates changelog for GitHub releases |
| 20 | + |
| 21 | +## Adding a new config option |
| 22 | + |
| 23 | +When sqlformat-rs adds new options: |
| 24 | + |
| 25 | +1. Add the field to `Configuration` in `src/configuration/configuration.rs` (add enums with `generate_str_to_from!` if needed) |
| 26 | +2. Add resolution in `src/configuration/resolve_config.rs` using `get_value()` |
| 27 | +3. Add a builder method in `src/configuration/builder.rs` and update the `check_all_values_set` test |
| 28 | +4. Wire it through in `src/format_text.rs` when constructing `FormatOptions` |
| 29 | +5. Add the property to `deployment/schema.json` |
| 30 | +6. Add a spec test file in `tests/specs/Config/` |
| 31 | + |
| 32 | +## Test specs |
| 33 | + |
| 34 | +Spec files live in `tests/specs/` and use the dprint-development format: |
| 35 | + |
| 36 | +- `== message ==` starts a test case |
| 37 | +- `[expect]` separates input from expected output |
| 38 | +- `~~ key: value, key: value ~~` at the top of a file sets config for all specs in that file |
| 39 | +- Each config variation needs its own file since config is file-level |
| 40 | + |
| 41 | +## Releases |
| 42 | + |
| 43 | +- Manual: trigger the `release` workflow with patch/minor |
| 44 | +- Automatic: `check_updates` workflow runs daily, detects new sqlformat versions, and auto-publishes |
| 45 | +- On tag push: CI creates a GitHub release with `plugin.wasm`, and `publish_npm` publishes to npm |
0 commit comments