Skip to content

Fix FilePattern schema to accept plain strings#1564

Merged
j178 merged 2 commits intomasterfrom
copilot/fix-schema-bug-filepattern
Feb 4, 2026
Merged

Fix FilePattern schema to accept plain strings#1564
j178 merged 2 commits intomasterfrom
copilot/fix-schema-bug-filepattern

Conversation

Copy link
Contributor

Copilot AI commented Feb 4, 2026

The JSON schema for FilePattern required object notation ({ regex: "..." } or { glob: "..." }), but the deserializer accepts plain strings as regex patterns. This caused existing pre-commit configs to fail validation:

exclude: foo  # Failed schema validation but deserializes correctly

Changes

  • Updated FilePattern::json_schema() to accept plain strings as the first oneOf variant
  • Removed the non-existent { regex: "..." } object format
  • Regenerated prek.schema.json

The schema now matches deserialization behavior, accepting:

  • Plain strings (treated as regex): exclude: foo
  • Glob objects: exclude: { glob: "*.py" }
  • Glob arrays: exclude: { glob: ["*.py", "*.pyc"] }

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek run -v ests/.tmpxZ661R/home/tools/bun/1--no-legend -c 26059e236b3af6dd -c rgo/bin/git -c core.autocrlf=fa/usr/bin/runc -c /usr/lib/git-cor/var/run/docker/runtime-runc/moby -c alse diff cal/share/prek/tjson prek lse REDACTED cal/share/prek/tests/.tmp47umK4/--log (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek run [email protected] -c init.defaultBranch=master init -c ash -c core.autocrlf=fa-V=full -c /home/REDACTED/woradd inst�� [email protected] runtime-runc/moby ker/cli-plugins/docker-buildx io.containerd.rugit -c ndor/bin/git ests/.tmpmkmZcy/-c (dns block)
  • https://api.github.com/repos/JuliaData/Parsers.jl/tarball/7d2f8f21da5db6a806faf7b9b292296da42b2810
    • Triggering command: /usr/bin/julia julia --startup-file=no --project=/home/REDACTED/.local/share/prek/tests/.tmpQgvNJR/home/hooks/julia-mo2YGycXuPDVHTHr66kQ -e using Pkg Pkg.instantiate() if !isempty(ARGS) Pkg.add(ARGS) end -- JSON cal/bin/git io.containerd.rucabal -c b6bd62e0e24da6a3--installdir (http block)
  • https://api.github.com/repos/JuliaIO/JSON.jl/tarball/b3ad4a0255688dcb895a52fafbaae3023b588a90
    • Triggering command: /usr/bin/julia julia --startup-file=no --project=/home/REDACTED/.local/share/prek/tests/.tmpQgvNJR/home/hooks/julia-mo2YGycXuPDVHTHr66kQ -e using Pkg Pkg.instantiate() if !isempty(ARGS) Pkg.add(ARGS) end -- JSON cal/bin/git io.containerd.rucabal -c b6bd62e0e24da6a3--installdir (http block)
  • https://api.github.com/repos/JuliaLang/Example.jl/tarball/e1f0e1a832ccd8e97d6d0348dec33ee139a5aeaf
    • Triggering command: /usr/bin/julia julia --startup-file=no --project=/home/REDACTED/.local/share/prek/tests/.tmpi2ZPor/home/hooks/julia-OxpLueuq5IwZtYFFtqW0 -e using Pkg Pkg.instantiate() if !isempty(ARGS) Pkg.add(ARGS) end -- ions }}' 14.1 -- vethd953e24 t 14.1 buil�� --tag prek-2f61e2cf9121d624 ./runghc-9.14.1 org.opencontainejulia 62d173ef org.opencontaine--project=/home/REDACTED/.local/share/prek/tests/.tmpQgvNJR/home/hooks/julia-mo2YGycXuPDVHTHr66kQ ./runghc-9.14.1 (http block)
  • https://api.github.com/repos/JuliaLang/PrecompileTools.jl/tarball/07a921781cab75691315adc645096ed5e370cb77
    • Triggering command: /usr/bin/julia julia --startup-file=no --project=/home/REDACTED/.local/share/prek/tests/.tmpQgvNJR/home/hooks/julia-mo2YGycXuPDVHTHr66kQ -e using Pkg Pkg.instantiate() if !isempty(ARGS) Pkg.add(ARGS) end -- JSON cal/bin/git io.containerd.rucabal -c b6bd62e0e24da6a3--installdir (http block)
  • https://api.github.com/repos/JuliaPackaging/Preferences.jl/tarball/522f093a29b31a93e34eaea17ba055d850edea28
    • Triggering command: /usr/bin/julia julia --startup-file=no --project=/home/REDACTED/.local/share/prek/tests/.tmpQgvNJR/home/hooks/julia-mo2YGycXuPDVHTHr66kQ -e using Pkg Pkg.instantiate() if !isempty(ARGS) Pkg.add(ARGS) end -- JSON cal/bin/git io.containerd.rucabal -c b6bd62e0e24da6a3--installdir (http block)
  • https://api.github.com/repos/JuliaServices/StructUtils.jl/tarball/9297459be9e338e546f5c4bedb59b3b5674da7f1
    • Triggering command: /usr/bin/julia julia --startup-file=no --project=/home/REDACTED/.local/share/prek/tests/.tmpQgvNJR/home/hooks/julia-mo2YGycXuPDVHTHr66kQ -e using Pkg Pkg.instantiate() if !isempty(ARGS) Pkg.add(ARGS) end -- JSON cal/bin/git io.containerd.rucabal -c b6bd62e0e24da6a3--installdir (http block)
  • mirrors.aliyun.com
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek run [email protected] commit -m Add large file -c e -c lse -c -config.yaml rev-�� SMonitor=false add ch=master alse -c git git (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek run [email protected] -c init.defaultBranch=master init -c rgo/bin/git -c lse -c est -c alse -c e -c lse -c est (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek hook-impl --hook-dir /home/REDACTED/.local/share/prek/tests/.tmp3rS68w/temp/.git/hooks --script-version 4 --hook-type=pre-commit -- -c MRTUXB -c git -c alse -c e -c lse -c est (dns block)
  • mirrors.cloud.tencent.com
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek run [email protected] commit -m Add large file -c e -c lse -c -config.yaml rev-�� SMonitor=false add ch=master alse -c git git (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek run [email protected] -c init.defaultBranch=master init -c rgo/bin/git -c lse -c est -c alse -c e -c lse -c est (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek hook-impl --hook-dir /home/REDACTED/.local/share/prek/tests/.tmp3rS68w/temp/.git/hooks --script-version 4 --hook-type=pre-commit -- -c MRTUXB -c git -c alse -c e -c lse -c est (dns block)
  • pkg.julialang.org
    • Triggering command: /usr/bin/julia julia --startup-file=no --project=/home/REDACTED/.local/share/prek/tests/.tmpQgvNJR/home/hooks/julia-mo2YGycXuPDVHTHr66kQ -e using Pkg Pkg.instantiate() if !isempty(ARGS) Pkg.add(ARGS) end -- JSON cal/bin/git io.containerd.rucabal -c b6bd62e0e24da6a3--installdir (dns block)
    • Triggering command: /usr/bin/julia julia --startup-file=no --project=/home/REDACTED/.local/share/prek/tests/.tmpi2ZPor/home/hooks/julia-OxpLueuq5IwZtYFFtqW0 -e using Pkg Pkg.instantiate() if !isempty(ARGS) Pkg.add(ARGS) end -- ions }}' 14.1 -- vethd953e24 t 14.1 buil�� --tag prek-2f61e2cf9121d624 ./runghc-9.14.1 org.opencontainejulia 62d173ef org.opencontaine--project=/home/REDACTED/.local/share/prek/tests/.tmpQgvNJR/home/hooks/julia-mo2YGycXuPDVHTHr66kQ ./runghc-9.14.1 (dns block)
  • pypi.tuna.tsinghua.edu.cn
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek run [email protected] commit -m Add large file -c e -c lse -c -config.yaml rev-�� SMonitor=false add ch=master alse -c git git (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek run [email protected] -c init.defaultBranch=master init -c rgo/bin/git -c lse -c est -c alse -c e -c lse -c est (dns block)
    • Triggering command: /home/REDACTED/work/prek/prek/target/debug/prek /home/REDACTED/work/prek/prek/target/debug/prek hook-impl --hook-dir /home/REDACTED/.local/share/prek/tests/.tmp3rS68w/temp/.git/hooks --script-version 4 --hook-type=pre-commit -- -c MRTUXB -c git -c alse -c e -c lse -c est (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Schema bug: FilePattern doesn't include strings so validation of pre-commit compatible config files fails</issue_title>
<issue_description>### Summary

Existing pre-commit config files that use file patterns like exclude don't pass yaml schema validation in prek.

This is the definition of global file exclude patterns: use FilePattern.

    "exclude": {
      "description": "Global file exclude pattern.",
      "anyOf": [
        {
          "$ref": "#/definitions/FilePattern"
        },
        {
          "type": "null"
        }
      ]
    },

FilePattern is:

    "FilePattern": {
      "description": "A file pattern, either a regex or glob pattern(s).",
      "type": "object",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "regex": {
              "description": "A regular expression pattern.",
              "type": "string"
            }
          },
          "required": [
            "regex"
          ]
        },
        {
          "type": "object",
          "properties": {
            "glob": {
              "oneOf": [
                {
                  "description": "A glob pattern.",
                  "type": "string"
                },
                {
                  "description": "A list of glob patterns.",
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              ]
            }
          },
          "required": [
            "glob"
          ]
        }
      ]
    },

Note that it doesn't include being a plain string at the top level of FilePattern. i.e.:

---
exclude: foo

This means that existing pre-commit config files that use exclusions don't pass validation with the provided JSON schema.

Platform

n/a

Version

d42b733

.pre-commit-config.yaml

---
$schema: https://raw.githubusercontent.com/j178/prek/refs/heads/master/prek.schema.json
# yaml-language-server: $schema=https://raw.githubusercontent.com/j178/prek/refs/heads/master/prek.schema.json
exclude: foo

Log file

N/A you don't have to run prek.</issue_description>

<agent_instructions>fix the json schema, regex is not a real key, run config::_gen to regenerate the schema file</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix schema validation for FilePattern in pre-commit config Fix FilePattern schema to accept plain strings Feb 4, 2026
Copilot AI requested a review from j178 February 4, 2026 21:22
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.56%. Comparing base (d42b733) to head (1dfe6d3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1564      +/-   ##
==========================================
- Coverage   91.57%   91.56%   -0.02%     
==========================================
  Files          92       92              
  Lines       17912    17907       -5     
==========================================
- Hits        16403    16396       -7     
- Misses       1509     1511       +2     

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

@j178 j178 marked this pull request as ready for review February 4, 2026 21:23
Copilot AI review requested due to automatic review settings February 4, 2026 21: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

This PR fixes a critical schema validation bug where the JSON schema for FilePattern didn't accept plain strings, causing existing pre-commit configs to fail validation even though they deserialize correctly.

Changes:

  • Updated FilePattern::json_schema() to accept plain strings as regex patterns (replacing the non-existent { regex: "..." } object format)
  • Regenerated prek.schema.json to reflect the correct schema

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/prek/src/schema.rs Fixed FilePattern schema to accept plain strings as the first oneOf variant, matching deserializer behavior
prek.schema.json Regenerated schema file reflecting the corrected FilePattern definition

@prek-ci-bot
Copy link

prek-ci-bot bot commented Feb 4, 2026

📦 Cargo Bloat Comparison

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

Expand for cargo-bloat output

Head 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 20377 smaller methods. Use -n N to show more.
41.6% 100.0%  9.7MiB                   .text section size, the file size is 23.2MiB

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 20377 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 merged commit bed1058 into master Feb 4, 2026
55 checks passed
@j178 j178 deleted the copilot/fix-schema-bug-filepattern branch February 4, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema bug: FilePattern doesn't include strings so validation of pre-commit compatible config files fails

3 participants