mirror of
https://github.com/j178/prek.git
synced 2026-04-03 17:34:03 +02:00
3.3 KiB
3.3 KiB
Copilot instructions for prek
Code requirements
- Concise, idiomatic Rust (2024 edition).
- Proper error handling (no unwraps, panics, etc. in app code).
- Clear separation of concerns (e.g., config parsing vs. execution).
- Thorough test coverage (unit + integration tests, snapshot testing where appropriate).
Big picture
- Rust workspace under
crates/*. The main CLI binary iscrates/prek(src/main.rs). prekis a Rust reimplementation ofpre-commit: configuration parsing lives incrates/prek/src/config.rs, execution/dispatch is incrates/prek/src/run.rs, and integration tests exercise the CLI end-to-end undercrates/prek/tests/.- User-facing output is centralized:
- Warnings go through
warn_user!/warn_user_once!incrates/prek/src/warnings.rs(can be disabled via-q/-qq). - Progress/output selection is via
Printerincrates/prek/src/printer.rs.
- Warnings go through
- Cross-process coordination uses a store under
$PREK_HOME(seeStore::from_settings/Store::lock_asyncincrates/prek/src/store.rs).
Developer workflows (preferred)
- Lint/format like CI:
mise run lint(runscargo fmt+cargo clippy --all-targets --all-features --workspace -- -D warnings). - Run all tests:
mise run test(workspace, all targets/features). - Snapshot-first test workflow (insta):
- Unit/bin tests with review UI:
mise run test-unit -- <filter>ormise run test-all-unit. - Integration tests with review UI:
mise run test-integration <test> [filter]ormise run test-all-integration. - Snapshots live under
crates/prek/src/snapshots/and are used heavily by tests incrates/prek/tests/.
- Unit/bin tests with review UI:
Project-specific conventions
- Prefer
fs-err/fs-err::tokiooverstd::fs/tokio::fsfor filesystem operations (see many modules, e.g.crates/prek/src/store.rs). - Prefer
anyhow::Resultfor app-level flows andthiserrorfor typed errors when there’s a clear domain (seecrates/prek/src/store.rs). - Logging uses
tracing; default behavior is configured incrates/prek/src/main.rsand can be overridden viaRUST_LOG. - CLI is defined with
clapundercrates/prek/src/cli/(entry incrates/prek/src/cli/mod.rs). If adding a command, keep wiring consistent with existingcli/*modules.
Tests and fixtures
- Integration tests use
TestContexthelpers incrates/prek/tests/common/mod.rsand snapshot macros likecmd_snapshot!. - Tests often normalize paths with regex filters; prefer using
context.filters()for stable snapshots. - DO NOT run whole-workspace tests in CI; they are slow. Use
cargo test -p prek --lib <unit-test> -- --exact(orcargo test -p prek --bin prek <unit-test> -- --exact) for unit tests andcargo test -p prek --test <test> -- <filter>for integration tests. - Use
cargo insta review --acceptto accept snapshot changes after running tests locally.
Docs + generated artifacts
- Docs are built with MkDocs (see
mkdocs.yml); run locally viamise run build-docs. - CLI reference + JSON schema are generated via
mise run generate(see tasks inmise.toml).
When changing behavior
- If a change affects user-visible output, update the relevant snapshot(s) under
crates/prek/tests/(use thecargo instareview flow). - Keep output stable and routed through existing printer/warning macros rather than printing directly.