Skip to content

Support prek.toml#1271

Merged
j178 merged 5 commits intomasterfrom
prektoml
Feb 5, 2026
Merged

Support prek.toml#1271
j178 merged 5 commits intomasterfrom
prektoml

Conversation

@j178
Copy link
Owner

@j178 j178 commented Dec 23, 2025

Closes #593

@j178 j178 added the enhancement New feature or request label Dec 23, 2025
@j178 j178 changed the title prektoml Support prek.toml Dec 23, 2025
@j178 j178 marked this pull request as draft December 23, 2025 11:31
@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 91.37931% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.57%. Comparing base (d42b733) to head (af5b4d1).
⚠️ Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
crates/prek/src/cli/auto_update.rs 82.43% 13 Missing ⚠️
crates/prek/src/cli/sample_config.rs 88.88% 4 Missing ⚠️
crates/prek/src/hook.rs 50.00% 3 Missing ⚠️
crates/prek/src/workspace.rs 94.73% 2 Missing ⚠️
crates/prek/src/cli/try_repo.rs 96.96% 1 Missing ⚠️
crates/prek/src/config.rs 98.78% 1 Missing ⚠️
crates/prek/src/main.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #1271    +/-   ##
========================================
  Coverage   91.57%   91.57%            
========================================
  Files          92       92            
  Lines       17912    18122   +210     
========================================
+ Hits        16403    16596   +193     
- Misses       1509     1526    +17     

☔ 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.

@github-actions
Copy link

github-actions bot commented Dec 23, 2025

📦 Cargo Bloat Comparison

Binary size change: +1.72% (23.2 MiB → 23.6 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 80.5KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 71.3KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.6% 65.6KiB              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.5KiB              prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.8KiB              prek prek::cli::run::run::run::{{closure}}
 0.2%   0.4% 40.7KiB              prek prek::run::{{closure}}
 0.1%   0.3% 31.1KiB             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% 28.3KiB              prek prek::identify::by_extension::{{closure}}
 0.1%   0.2% 24.9KiB             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.2KiB              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.6KiB              prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 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.5KiB              prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 19.5KiB              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}}>
 0.1%   0.2% 19.2KiB              prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
38.3%  91.5%  9.0MiB                   And 20867 smaller methods. Use -n N to show more.
41.8% 100.0%  9.9MiB                   .text section size, the file size is 23.6MiB

Base Branch Results

 File  .text    Size             Crate Name
 0.3%   0.8% 76.3KiB             prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.7% 72.1KiB              prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.3%   0.7% 65.7KiB              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% 44.1KiB              prek prek::run::{{closure}}
 0.2%   0.4% 43.4KiB              prek prek::identify::by_extension::{{closure}}
 0.2%   0.4% 41.7KiB              prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 31.9KiB             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.2% 24.5KiB             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.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.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.2%  8.8MiB                   And 20376 smaller methods. Use -n N to show more.
41.6% 100.0%  9.7MiB                   .text section size, the file size is 23.2MiB

@j178 j178 force-pushed the prektoml branch 4 times, most recently from e7f23ae to ac9aae2 Compare December 24, 2025 08:07
@j178 j178 force-pushed the prektoml branch 2 times, most recently from ba41b8f to 9250c04 Compare December 31, 2025 03:13
@pygarap
Copy link

pygarap commented Jan 13, 2026

@j178 if prek.toml is the equivalent of .pre-commit-config.yaml, why not rename it to prek-config.toml and also add support for prek-hooks.toml as the equivalent of .pre-commit-hooks.yaml?

@ulgens
Copy link
Contributor

ulgens commented Jan 14, 2026

if prek.toml is the equivalent of .pre-commit-config.yaml, why not rename it to prek-config.toml and also add support for prek-hooks.toml as the equivalent of .pre-commit-hooks.yaml?

Similar question here. Will this be an alternative to .pre-commit-config.yaml file or is it to keep prek settings?

@OJFord
Copy link

OJFord commented Jan 14, 2026

@ulgens The description is 'Closes #593', it's the former. (Also as you can see clearly from:
https://github.com/j178/prek/pull/1271/changes#diff-ff219642554f55d0b52b321bd22873805b5075725d97a9caabd22f3e53f0c63bR132)

Regarding the name, my 2p would be that prek.toml makes more sense if you forget the history. It's a toml file, obviously it's some kind of config, it doesn't need to be called that the same way I don't have Cargo-config.toml or pyproject-config.toml. (In fairness, it does seem more popular in the JS world to have *.config.js, but I suppose back to my first point - unlike toml, js isn't readily apparent as a config file.)

@ulgens
Copy link
Contributor

ulgens commented Jan 17, 2026

@OJFord Oh, thank you. Checking it again now, it seems clear but I was confused at the time.

@pygarap
Copy link

pygarap commented Jan 17, 2026

But what about prek-hooks.toml?

@j178 j178 added this to the v0.3.0 milestone Jan 19, 2026
@j178 j178 force-pushed the prektoml branch 6 times, most recently from b51aab5 to a95d7a7 Compare February 3, 2026 15:43
@j178 j178 force-pushed the prektoml branch 2 times, most recently from f7a7700 to 20bdc34 Compare February 4, 2026 11:40
@j178 j178 marked this pull request as ready for review February 4, 2026 12:23
Copilot AI review requested due to automatic review settings February 4, 2026 12:23
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

Adds first-class support for a TOML-based configuration file (prek.toml) alongside existing .pre-commit-config.yaml configs, including updated workspace discovery, CLI behavior, and documentation.

Changes:

  • Add TOML config loading and recognize prek.toml (with defined filename precedence).
  • Update CLI commands (sample-config, try-repo, auto-update) to generate/read/update TOML configs.
  • Refresh docs and integration/unit snapshots to cover TOML + new messaging.

Reviewed changes

Copilot reviewed 36 out of 38 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
docs/configuration.md Documents prek.toml, precedence rules, and TOML/YAML examples.
docs/cli.md Updates CLI reference to include sample-config --format.
crates/prek/tests/workspace.rs Updates workspace discovery snapshots/error messaging for TOML support.
crates/prek/tests/validate.rs Uses renamed consts for YAML config filename.
crates/prek/tests/try_repo.rs Updates try-repo snapshots for generated prek.toml output.
crates/prek/tests/sample_config.rs Adds coverage for TOML sample config output and --format.
crates/prek/tests/run.rs Adds/updates tests for precedence and running with prek.toml.
crates/prek/tests/meta_hooks.rs Updates tests to use renamed YAML config constant.
crates/prek/tests/list.rs Updates “no config found” snapshot for TOML awareness.
crates/prek/tests/languages/swift.rs Renames manifest const usage in tests.
crates/prek/tests/languages/script.rs Renames YAML config const usage in tests.
crates/prek/tests/languages/python.rs Renames manifest const usage in tests.
crates/prek/tests/languages/golang.rs Renames config/manifest const usage in tests.
crates/prek/tests/install.rs Renames YAML config const usage in tests.
crates/prek/tests/hook_impl.rs Updates snapshots and constants for TOML-aware discovery.
crates/prek/tests/common/mod.rs Updates workspace helpers to write YAML config via new const.
crates/prek/tests/cache.rs Updates tracked-config filename constants.
crates/prek/tests/builtin_hooks.rs Updates YAML config constant usage in tests.
crates/prek/tests/auto_update.rs Adds TOML auto-update coverage (including comment preservation).
crates/prek/src/workspace.rs Adds config filename precedence, TOML discovery, and updated errors.
crates/prek/src/snapshots/prek__config__tests__read_yaml_config.snap New snapshot for YAML config parsing test naming.
crates/prek/src/snapshots/prek__config__tests__read_toml_config.snap New snapshot covering TOML config parsing.
crates/prek/src/snapshots/prek__config__tests__meta_hooks-5.snap Updates meta-hooks snapshot to include prek.toml.
crates/prek/src/main.rs Routes cache dir output to “important” stdout; wires new sample-config args.
crates/prek/src/hooks/meta_hooks.rs Expands meta-hook config file matching to include prek.toml.
crates/prek/src/hook.rs Renames manifest const and updates related tests.
crates/prek/src/config.rs Adds TOML parsing path + error variant; adds TOML parsing tests/snapshots.
crates/prek/src/cli/try_repo.rs Generates a TOML config for try-repo via toml_edit.
crates/prek/src/cli/sample_config.rs Adds TOML sample config + format selection + improved file creation.
crates/prek/src/cli/mod.rs Adds SampleConfigFormat/--format and new -f target handling.
crates/prek/src/cli/install.rs Uses unified CONFIG_FILENAMES fallback list.
crates/prek/src/cli/hook_impl.rs Updates missing-config error matching for renamed variant.
crates/prek/src/cli/cache_gc.rs Updates handling of config “not found” after removing NotFound variant.
crates/prek/src/cli/auto_update.rs Adds TOML rewrite path using toml_edit and keeps YAML behavior.
crates/prek/Cargo.toml Adds toml_edit dependency.
crates/prek-consts/src/lib.rs Introduces PREK_TOML, renamed constants, and CONFIG_FILENAMES.
Cargo.toml Adds workspace dependency for toml_edit.
Cargo.lock Locks toml_edit and transitive deps.

Comment on lines +26 to +37
static SAMPLE_CONFIG_TOML: &str = indoc::indoc! {r#"
#:schema: https://json.schemastore.org/prek.json
# Configuration file for `prek`, a git hook framework written in Rust.
# See https://prek.j178.dev for more information.

[[repos]]
repo = "builtin"
hooks = [
{ id = "trailing-whitespace" },
{ id = "end-of-file-fixer" },
{ id = "check-added-large-files" },
]"#};
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

SAMPLE_CONFIG_TOML currently ends at the closing ] without a trailing newline (the raw string terminator is on the same line). This makes the generated prek.toml file differ from typical POSIX text-file conventions and from the integration test snapshot expectations (which include a final newline). Consider adding a trailing newline to the TOML template and using write! vs writeln! consistently for stdout vs file output to avoid double blank lines.

Copilot uses AI. Check for mistakes.
@j178 j178 merged commit d784a47 into master Feb 5, 2026
49 checks passed
@j178 j178 deleted the prektoml branch February 5, 2026 09:10
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.

Support prek.{yaml/toml} ?

4 participants