Show precise location for config parsing error#1530
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1530 +/- ##
==========================================
- Coverage 91.93% 91.57% -0.37%
==========================================
Files 89 90 +1
Lines 18288 17882 -406
==========================================
- Hits 16813 16375 -438
- Misses 1475 1507 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📦 Cargo Bloat ComparisonBinary size change: +0.00% (23.3 MiB → 23.3 MiB) Expand for cargo-bloat outputHead Branch ResultsBase Branch Results |
There was a problem hiding this comment.
Pull request overview
This PR refines configuration parsing so that errors point to the precise location in the YAML, and it slightly relaxes some parsing (e.g., numeric rev values) while keeping strong validation. It also refactors schemars-related JSON schema generation into a dedicated module and updates tests and snapshots to cover the new behaviors.
Changes:
- Replace the old
Repowire-format parsing with a customDeserializeimplementation that distinguishes local/meta/builtin/remote repos and produces detailed, field-level errors (e.g., missingrev, forbiddenrevon local/meta/builtin, missing hook fields). - Improve type-tag and minimum-version error messages and add support for numeric
revvalues parsed as strings, with corresponding unit tests and insta snapshots for various repo/hook configurations and YAML merge-key scenarios. - Extract schemars
JsonSchemaimplementations into a newschemamodule, wire it via theschemarsfeature, and update themisegeneratetask to run the CLI-reference and JSON-schema generators sequentially.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
mise.toml |
Updates the generate task to sequentially run the CLI-reference and JSON-schema generation subtasks using the run = [{ task = ... }] syntax. |
crates/prek/tests/validate.rs |
Adjusts expected validate output to reflect the new, more precise config error messages and the acceptance of numeric rev values. |
crates/prek/tests/install.rs |
Updates the install warning snapshot to match the new config parsing error text (dropping the old Invalid remote repo: prefix and pointing to the exact field location). |
crates/prek/src/config.rs |
Refactors repo and hook parsing: adds Language as #[non_exhaustive], centralizes Formatter use, tightens serde attributes, replaces the Repo wire-type with a custom Deserialize visitor that enforces repo-kind-specific rules and produces precise error locations, tweaks type-tag and minimum-version error messages, and adds/updates unit tests and insta snapshots (including merge-key and numeric-rev cases). |
crates/prek/src/schema.rs |
New module that houses schemars JsonSchema implementations for FilePattern, predefined hooks (MetaHook, BuiltinHook), repo kind schemas, and Repo, mirroring prior behavior but separating schema logic from config parsing. |
crates/prek/src/main.rs |
Conditionally includes the new schema module under the schemars feature so JSON schema generation continues to work via the existing config test harness. |
crates/prek/src/snapshots/prek__config__tests__read_config_with_nested_merge_keys.snap |
Adds snapshot for reading configs that use nested YAML merge keys, verifying the final Config structure. |
crates/prek/src/snapshots/prek__config__tests__read_config_with_merge_keys.snap |
Adds snapshot for reading configs with top-level merge keys in repo hooks, ensuring merge resolution is reflected in Config. |
crates/prek/src/snapshots/prek__config__tests__parse_repos.snap |
Snapshot for basic local repo parsing, confirming the Config shape with a simple local hook. |
crates/prek/src/snapshots/prek__config__tests__parse_repos-2.snap |
Snapshot for local repo parsing that includes _unused_keys for extra fields, validating how unexpected keys are tracked. |
crates/prek/src/snapshots/prek__config__tests__parse_repos-3.snap |
Snapshot for local repos with unknown fields at the repo level, ensuring _unused_keys is populated correctly. |
crates/prek/src/snapshots/prek__config__tests__parse_repos-4.snap |
Snapshot for remote repo parsing with rev and minimal hook definitions, validating the RemoteRepo representation. |
crates/prek/src/snapshots/prek__config__tests__parse_repos-6.snap |
Additional remote-repo snapshot (typos repo) confirming the structure of RemoteRepo and its hooks after parsing. |
crates/prek/src/snapshots/prek__config__tests__parse_hooks-3.snap |
Snapshot for local hook parsing with explicit language, verifying the resulting Config/LocalHook structure. |
crates/prek/src/snapshots/prek__config__tests__numeric_rev_is_parsed_as_string.snap |
Snapshot proving that numeric rev values are parsed as strings in remote repos. |
crates/prek/src/snapshots/prek__config__tests__meta_hooks-5.snap |
Snapshot for valid meta-hook configuration, ensuring predefined meta hooks expand into the expected MetaRepo/MetaHook structures. |
crates/prek/src/snapshots/prek__config__tests__language_version.snap |
Snapshot for various language_version values on local hooks, confirming correct parsing and storage in HookOptions. |
6b03eec to
a37537f
Compare
Finally, we can actually fix #783, big thanks to serde‑saphyr and @bourumir-wyngs!
For this invalid config:
Before:
After: