Skip to content

Commit 01348b2

Browse files
authored
Add #:schema and #:tombi directives to generated prek.toml (#1597)
1 parent 71790f3 commit 01348b2

4 files changed

Lines changed: 21 additions & 4 deletions

File tree

crates/prek/src/cli/sample_config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ repos:
2424
"};
2525

2626
static SAMPLE_CONFIG_TOML: &str = indoc::indoc! {r#"
27-
#:schema: https://www.schemastore.org/prek.json
2827
# Configuration file for `prek`, a git hook framework written in Rust.
2928
# See https://prek.j178.dev for more information.
29+
#:schema https://www.schemastore.org/prek.json
30+
#:tombi toml-version = "v1.1.0"
3031
3132
[[repos]]
3233
repo = "builtin"

crates/prek/src/cli/yaml_to_toml.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ fn json_to_toml(value: &serde_json::Value) -> Result<String> {
7878
.context("Expected a top-level mapping in the config file")?;
7979

8080
let mut doc = DocumentMut::new();
81+
doc.decor_mut().set_prefix(indoc::indoc! {r#"
82+
# Configuration file for `prek`, a git hook framework written in Rust.
83+
# See https://prek.j178.dev for more information.
84+
#:schema https://www.schemastore.org/prek.json
85+
#:tombi toml-version = "v1.1.0"
86+
87+
"#});
88+
8189
for (key, value) in map {
8290
if key == "repos" {
8391
let repos = value.as_array().context("`repos` must be an array")?;

crates/prek/tests/sample_config.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ fn sample_config_toml() {
111111
"#);
112112

113113
insta::assert_snapshot!(context.read("prek.toml"), @r#"
114-
#:schema: https://www.schemastore.org/prek.json
115114
# Configuration file for `prek`, a git hook framework written in Rust.
116115
# See https://prek.j178.dev for more information.
116+
#:schema https://www.schemastore.org/prek.json
117+
#:tombi toml-version = "v1.1.0"
117118
118119
[[repos]]
119120
repo = "builtin"
@@ -133,9 +134,10 @@ fn sample_config_format() {
133134
success: true
134135
exit_code: 0
135136
----- stdout -----
136-
#:schema: https://www.schemastore.org/prek.json
137137
# Configuration file for `prek`, a git hook framework written in Rust.
138138
# See https://prek.j178.dev for more information.
139+
#:schema https://www.schemastore.org/prek.json
140+
#:tombi toml-version = "v1.1.0"
139141
140142
[[repos]]
141143
repo = "builtin"
@@ -222,9 +224,10 @@ fn respect_format_if_filename_missing() {
222224
");
223225

224226
insta::assert_snapshot!(context.read("prek.toml"), @r#"
225-
#:schema: https://www.schemastore.org/prek.json
226227
# Configuration file for `prek`, a git hook framework written in Rust.
227228
# See https://prek.j178.dev for more information.
229+
#:schema https://www.schemastore.org/prek.json
230+
#:tombi toml-version = "v1.1.0"
228231
229232
[[repos]]
230233
repo = "builtin"

crates/prek/tests/yaml_to_toml.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ fn yaml_to_toml_writes_default_output() -> anyhow::Result<()> {
7979
);
8080

8181
insta::assert_snapshot!(context.read(PREK_TOML), @r#"
82+
# Configuration file for `prek`, a git hook framework written in Rust.
83+
# See https://prek.j178.dev for more information.
84+
#:schema https://www.schemastore.org/prek.json
85+
#:tombi toml-version = "v1.1.0"
86+
8287
fail_fast = true
8388
default_install_hook_types = ["pre-push"]
8489
exclude = """

0 commit comments

Comments
 (0)