Skip to content

Comments

Allow optional upgrade hints after semicolon in minimum_prek_version#1536

Merged
j178 merged 1 commit intomasterfrom
config-tests
Feb 2, 2026
Merged

Allow optional upgrade hints after semicolon in minimum_prek_version#1536
j178 merged 1 commit intomasterfrom
config-tests

Conversation

@j178
Copy link
Owner

@j178 j178 commented Feb 2, 2026

Closes #1490

Copilot AI review requested due to automatic review settings February 2, 2026 13:55
@j178 j178 added the enhancement New feature or request label Feb 2, 2026
@j178 j178 changed the title config tests Allow optional upgrade hints after semicolons in minimum_prek_version Feb 2, 2026
@j178 j178 changed the title Allow optional upgrade hints after semicolons in minimum_prek_version Allow optional upgrade hints after semicolon in minimum_prek_version Feb 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_version parsing 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
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 98.21429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.59%. Comparing base (c405db6) to head (4702728).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/config.rs 98.21% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 2, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (23.3 MiB → 23.3 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 75.6KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 70.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7% 65.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.8KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.7KiB              prek prek::run::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.5KiB              prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 31.7KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.4KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.3% 24.8KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.6KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.1KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.2KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.7KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 19.6KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.4KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
37.9%  91.3%  8.8MiB                   And 20524 smaller methods. Use -n N to show more.
41.5% 100.0%  9.7MiB                   .text section size, the file size is 23.3MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.7% 71.9KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 70.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7% 65.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 51.2KiB annotate_snippets annotate_snippets::renderer::render::render
 0.2%   0.5% 50.8KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 43.7KiB              prek prek::run::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.5KiB              prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 32.0KiB             prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.3% 28.4KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.3% 24.8KiB             prek? <prek::config::_::<impl serde_core::de::Deserialize for prek::config::Config>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 22.6KiB      serde_saphyr saphyr_parser_bw::scanner::Scanner<T>::fetch_more_tokens
 0.1%   0.2% 22.1KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.2KiB      clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.0KiB   cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.7KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 19.5KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.4KiB              prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB               std core::ptr::drop_in_place<prek::languages::<impl prek::config::Language>::install::{{closure}}>
37.9%  91.3%  8.8MiB                   And 20517 smaller methods. Use -n N to show more.
41.6% 100.0%  9.7MiB                   .text section size, the file size is 23.3MiB

@j178 j178 merged commit 1c1af94 into master Feb 2, 2026
49 checks passed
@j178 j178 deleted the config-tests branch February 2, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant