Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/prek/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,10 @@ where
I: Iterator<Item = &'a str>,
{
for key in keys {
// Silently ignore extension keys starting with 'x-' (used for YAML anchors and custom metadata).
if key.starts_with("x-") {
Comment thread
j178 marked this conversation as resolved.
continue;
}
let path = if prefix.is_empty() {
key.to_string()
} else {
Expand Down
29 changes: 28 additions & 1 deletion crates/prek/tests/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,18 @@ fn unexpected_keys_warning() {
let context = TestContext::new();

context.write_pre_commit_config(indoc::indoc! {r"
x-anchor: &anchor
language: system
repos:
- repo: local
unexpected_repo_key: some_value
x-repo-key: some_value
hooks:
- id: test-hook
name: Test Hook
entry: echo test
language: system
<<: *anchor
x-hook-key: some_value
unexpected_top_level_key: some_value
another_unknown: test
minimum_pre_commit_version: 1.0.0
Expand Down Expand Up @@ -357,4 +361,27 @@ fn unexpected_keys_warning() {
- `repos[0].hooks[0].unexpected_hook_key_4`
success: All configs are valid
");

context.write_pre_commit_config(indoc::indoc! {r"
x-anchor: &anchor
language: system
repos:
- repo: local
x-repo-key: test
hooks:
- id: test-hook
name: Test Hook
entry: echo test
<<: *anchor
x-hook-key: test
"});

cmd_snapshot!(context.filters(), context.validate_config().arg(PRE_COMMIT_CONFIG_YAML), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
success: All configs are valid
");
}
4 changes: 4 additions & 0 deletions docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ The cooldown age is computed from the tag creation timestamp for annotated tags,

The legacy `auto_update` key is still accepted as an alias for `update`.

## Extension keys (`x-`)

Any key starting with `x-` (a lowercase `x` followed by a hyphen) is silently ignored by `prek` at any level of the configuration. This supports custom metadata without triggering unexpected key warnings.

## Top-level keys

### `repos` (required)
Expand Down
Loading