Skip to content

Commit 21e58f2

Browse files
davidsmfreireclaude
andcommitted
feat(pre-commit): ship sqlshield as pre-commit hook
Add .pre-commit-hooks.yaml so users can wire sqlshield into their .pre-commit-config.yaml. Convert workspace root Cargo.toml to a combined package+workspace manifest with a `sqlshield-precommit` shim package (publish = false) that exposes the same `sqlshield` bin from sqlshield-cli/src/main.rs. This makes `cargo install --path .` (used by pre-commit's `language: rust`) succeed against the workspace root, which is otherwise a virtual manifest. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4bb1f66 commit 21e58f2

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- id: sqlshield
2+
name: sqlshield
3+
description: Schema-aware SQL linter for embedded queries in Python, Rust, Go, and JavaScript / TypeScript source files.
4+
entry: sqlshield
5+
language: rust
6+
pass_filenames: false
7+
files: \.(py|rs|go|js|ts|tsx|sql)$

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,33 @@ repository = "https://github.com/davidsmfreire/sqlshield"
1919
[workspace.dependencies]
2020
sqlshield = { version = "0.0.2", path = "sqlshield" }
2121
sqlshield-introspect = { version = "0.0.2", path = "sqlshield-introspect" }
22+
23+
# Root package exists solely so `cargo install --path .` (used by
24+
# pre-commit's `language: rust`) succeeds against this workspace. Not
25+
# published; mirrors `sqlshield-cli` and ships the same `sqlshield` bin.
26+
[package]
27+
name = "sqlshield-precommit"
28+
version.workspace = true
29+
authors.workspace = true
30+
edition.workspace = true
31+
rust-version.workspace = true
32+
license.workspace = true
33+
repository.workspace = true
34+
description = "pre-commit shim that installs the sqlshield CLI from this workspace root"
35+
publish = false
36+
37+
[[bin]]
38+
name = "sqlshield"
39+
path = "sqlshield-cli/src/main.rs"
40+
41+
[features]
42+
default = ["introspect"]
43+
introspect = ["dep:sqlshield-introspect"]
44+
45+
[dependencies]
46+
clap = { version = "4.4.18", features = ["derive"] }
47+
serde = { version = "1", features = ["derive"] }
48+
serde_json = "1"
49+
sqlshield = { workspace = true }
50+
sqlshield-introspect = { workspace = true, optional = true }
51+
toml = "0.8"

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,28 @@ A first-party VS Code extension lives at
154154
[`editors/vscode/`](editors/vscode/README.md) — it spawns `sqlshield-lsp`
155155
over stdio and forwards diagnostics as you type.
156156

157+
## pre-commit
158+
159+
sqlshield ships a [pre-commit](https://pre-commit.com/) hook so it can
160+
gate every commit alongside your other linters. Add it to
161+
`.pre-commit-config.yaml`:
162+
163+
```yaml
164+
- repo: https://github.com/davidsmfreire/sqlshield
165+
rev: sqlshield-cli-v0.0.2 # pin to a tagged release
166+
hooks:
167+
- id: sqlshield
168+
```
169+
170+
`pass_filenames: false` is hard-coded in the hook definition because
171+
sqlshield walks the directory itself (driven by `.sqlshield.toml` or its
172+
defaults) — file-by-file invocation isn't supported. The hook still
173+
runs only when files matching `\.(py|rs|go|js|ts|tsx|sql)$` change.
174+
175+
The hook uses `language: rust`, so pre-commit's first run compiles the
176+
CLI from source via `cargo install`. Subsequent runs reuse the cached
177+
binary.
178+
157179
## Python integration
158180

159181
[`sqlshield-py`](sqlshield-py/) exposes `validate_query` and

0 commit comments

Comments
 (0)