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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ serde_stacker = { version = "0.1.12" }
serde-saphyr = { version = "0.0.21", default-features = false }
shlex = { version = "1.3.0" }
globset = { version = "0.4.18" }
similar = { version = "2.7.0" }
strum = { version = "0.28.0", features = ["derive"] }
target-lexicon = { version = "0.13.0" }
tempfile = { version = "3.25.0" }
Expand Down
1 change: 1 addition & 0 deletions crates/prek/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ serde_json = { workspace = true }
serde_stacker = { workspace = true }
serde-saphyr = { workspace = true }
shlex = { workspace = true }
similar = { workspace = true }
strum = { workspace = true }
target-lexicon = { workspace = true }
tempfile = { workspace = true }
Expand Down
14 changes: 14 additions & 0 deletions crates/prek/src/hooks/builtin_hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub(crate) enum BuiltinHooks {
FixByteOrderMarker,
MixedLineEnding,
NoCommitToBranch,
PrettyFormatJson,
TrailingWhitespace,
}

Expand Down Expand Up @@ -97,6 +98,7 @@ impl BuiltinHooks {
}
Self::MixedLineEnding => pre_commit_hooks::mixed_line_ending(hook, filenames).await,
Self::NoCommitToBranch => pre_commit_hooks::no_commit_to_branch(hook).await,
Self::PrettyFormatJson => pre_commit_hooks::pretty_format_json(hook, filenames).await,
Self::TrailingWhitespace => {
pre_commit_hooks::fix_trailing_whitespace(hook, filenames).await
}
Expand Down Expand Up @@ -362,6 +364,18 @@ impl BuiltinHook {
..Default::default()
},
},
BuiltinHooks::PrettyFormatJson => BuiltinHook {
id: "pretty-format-json".to_string(),
name: "pretty format json".to_string(),
entry: "pretty-format-json".to_string(),
priority: None,
options: HookOptions {
description: Some("checks that JSON files are pretty-formatted.".to_string()),
types: Some(tags::TAG_SET_JSON),
stages: Some([Stage::PreCommit, Stage::PrePush, Stage::Manual].into()),
..Default::default()
},
},
BuiltinHooks::TrailingWhitespace => BuiltinHook {
id: "trailing-whitespace".to_string(),
name: "trim trailing whitespace".to_string(),
Expand Down
6 changes: 6 additions & 0 deletions crates/prek/src/hooks/pre_commit_hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod fix_end_of_file;
mod fix_trailing_whitespace;
mod mixed_line_ending;
mod no_commit_to_branch;
mod pretty_format_json;
mod shebangs;

pub(crate) use check_added_large_files::check_added_large_files;
Expand All @@ -45,6 +46,7 @@ pub(crate) use fix_end_of_file::fix_end_of_file;
pub(crate) use fix_trailing_whitespace::fix_trailing_whitespace;
pub(crate) use mixed_line_ending::mixed_line_ending;
pub(crate) use no_commit_to_branch::no_commit_to_branch;
pub(crate) use pretty_format_json::pretty_format_json;

/// Hooks from `https://github.com/pre-commit/pre-commit-hooks`.
#[derive(strum::EnumString)]
Expand All @@ -68,6 +70,10 @@ pub(crate) enum PreCommitHooks {
MixedLineEnding,
DetectPrivateKey,
NoCommitToBranch,
// `pretty-format-json` is intentionally builtin-only for now. Do not enable
// automatic fast-path replacement until parity coverage against upstream
// Python is broad enough to trust it as the default implementation.
// PrettyFormatJson,
TrailingWhitespace,
}

Expand Down
Loading
Loading