Allow optional upgrade hints after semicolon in minimum_prek_version#1536
Allow optional upgrade hints after semicolon in minimum_prek_version#1536
minimum_prek_version#1536Conversation
minimum_prek_version
minimum_prek_versionminimum_prek_version
There was a problem hiding this comment.
Pull request overview
This PR adds support for optional upgrade hints in minimum_prek_version fields and includes additional config parsing tests. The upgrade hint feature allows users to specify custom instructions (e.g., "Use brew upgrade to upgrade prek") that will be displayed when version validation fails.
Changes:
- Enhanced
minimum_prek_versionparsing to accept an optional upgrade hint after a semicolon - Added documentation for the upgrade hint feature in both top-level config and hook-level config sections
- Added comprehensive tests for config parsing error messages (local/meta/builtin hooks)
- Added tests for the upgrade hint feature with various edge cases
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| docs/configuration.md | Documents the new semicolon-separated upgrade hint syntax with examples for both top-level and hook-level configs |
| crates/prek/src/config.rs | Implements parsing logic to extract and display upgrade hints, adds tests for new parsing scenarios and upgrade hint behavior |
Comments suppressed due to low confidence (1)
crates/prek/src/config.rs:1749
- There is no test case that verifies what happens when a valid version with an upgrade hint is successfully parsed (i.e., when the version requirement is satisfied). Consider adding a test case that uses a valid version like '0.1.0; Use brew upgrade' to ensure the hint is correctly stripped from the stored value and only the version string is retained in the config.
name: My Hook
entry: echo
language: system
types: [python, file]
types_or: [text, binary]
exclude_types: [symlink]
"};
let result = serde_saphyr::from_str::<Config>(yaml_valid);
assert!(result.is_ok(), "Should parse valid tags successfully");
// Empty lists and missing keys should also be fine
let yaml_empty = indoc::indoc! { r"
repos:
- repo: local
hooks:
- id: my-hook
name: My Hook
entry: echo
language: system
types: []
exclude_types: []
# types_or is missing, which is also valid
"};
let result_empty = serde_saphyr::from_str::<Config>(yaml_empty);
assert!(
result_empty.is_ok(),
"Should parse empty/missing tags successfully"
);
// Invalid tag in 'types' should fail
let yaml_invalid_types = indoc::indoc! { r"
repos:
- repo: local
hooks:
- id: my-hook
name: My Hook
entry: echo
language: system
types: [pythoon] # Deliberate typo
"};
let err = serde_saphyr::from_str::<Config>(yaml_invalid_types).unwrap_err();
insta::assert_snapshot!(err, @"
error: line 4 column 9: Type tag `pythoon` is not recognized. Check for typos or upgrade prek to get new tags. at line 4, column 9
--> <input>:4:9
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1536 +/- ##
==========================================
+ Coverage 91.56% 91.59% +0.03%
==========================================
Files 90 90
Lines 17906 18008 +102
==========================================
+ Hits 16395 16494 +99
- Misses 1511 1514 +3 ☔ 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 |
Closes #1490