Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73e14e6

Browse files
authored
Revert "Allow optional upgrade hints after semicolon in minimum_prek_version" (j178#1538)
1 parent 1c1af94 commit 73e14e6

2 files changed

Lines changed: 5 additions & 87 deletions

File tree

crates/prek/src/config.rs

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,38 +1126,25 @@ fn deserialize_and_validate_minimum_version<'de, D>(
11261126
where
11271127
D: Deserializer<'de>,
11281128
{
1129-
let raw = String::deserialize(deserializer)?;
1130-
let (version_str, upgrade_hint) = match raw.split_once(';') {
1131-
Some((version, hint)) => {
1132-
let trimmed_hint = hint.trim();
1133-
if trimmed_hint.is_empty() {
1134-
(version, None)
1135-
} else {
1136-
(version, Some(trimmed_hint))
1137-
}
1138-
}
1139-
None => (raw.as_str(), None),
1140-
};
1141-
let version_str = version_str.trim();
1142-
if version_str.is_empty() {
1129+
let s = String::deserialize(deserializer)?;
1130+
if s.is_empty() {
11431131
return Ok(None);
11441132
}
11451133

1146-
let version = version_str
1134+
let version = s
11471135
.parse::<semver::Version>()
11481136
.map_err(serde::de::Error::custom)?;
11491137
let cur_version = version::version()
11501138
.version
11511139
.parse::<semver::Version>()
11521140
.expect("Invalid prek version");
11531141
if version > cur_version {
1154-
let hint = upgrade_hint.unwrap_or("Please consider updating prek.");
11551142
return Err(serde::de::Error::custom(format!(
1156-
"Required minimum prek version `{version}` is greater than current version `{cur_version}`. {hint}",
1143+
"Required minimum prek version `{version}` is greater than current version `{cur_version}`. Please consider updating prek.",
11571144
)));
11581145
}
11591146

1160-
Ok(Some(version_str.to_string()))
1147+
Ok(Some(s))
11611148
}
11621149

11631150
/// Deserializes a vector of strings and validates that each is a known file type tag.
@@ -1702,52 +1689,6 @@ mod tests {
17021689
");
17031690
}
17041691

1705-
#[test]
1706-
fn test_upgrade_hint() {
1707-
// Test that hint is included in error message when version is too new
1708-
let yaml = indoc::indoc! {r"
1709-
repos:
1710-
- repo: local
1711-
hooks:
1712-
- id: test-hook
1713-
name: Test Hook
1714-
entry: echo test
1715-
language: system
1716-
minimum_prek_version: '10.0.0; Use `brew upgrade` to upgrade prek'
1717-
"};
1718-
let err = serde_saphyr::from_str::<Config>(yaml).unwrap_err();
1719-
insta::assert_snapshot!(err, @"
1720-
error: line 8 column 23: Required minimum prek version `10.0.0` is greater than current version `0.3.1`. Use `brew upgrade` to upgrade prek at line 8, column 23
1721-
--> <input>:8:23
1722-
|
1723-
6 | entry: echo test
1724-
7 | language: system
1725-
8 | minimum_prek_version: '10.0.0; Use `brew upgrade` to upgrade prek'
1726-
| ^ Required minimum prek version `10.0.0` is greater than current version `0.3.1`. Use `brew upgrade` to upgrade prek at line 8, column 23
1727-
");
1728-
1729-
let yaml = indoc::indoc! {r"
1730-
repos:
1731-
- repo: local
1732-
hooks:
1733-
- id: test-hook
1734-
name: Test Hook
1735-
entry: echo test
1736-
language: system
1737-
minimum_prek_version: '10.0.0; '
1738-
"};
1739-
let err = serde_saphyr::from_str::<Config>(yaml).unwrap_err();
1740-
insta::assert_snapshot!(err, @"
1741-
error: line 8 column 23: Required minimum prek version `10.0.0` is greater than current version `0.3.1`. Please consider updating prek. at line 8, column 23
1742-
--> <input>:8:23
1743-
|
1744-
6 | entry: echo test
1745-
7 | language: system
1746-
8 | minimum_prek_version: '10.0.0; '
1747-
| ^ Required minimum prek version `10.0.0` is greater than current version `0.3.1`. Please consider updating prek. at line 8, column 23
1748-
");
1749-
}
1750-
17511692
#[test]
17521693
fn test_validate_type_tags() {
17531694
// Valid tags should parse successfully

docs/configuration.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,6 @@ Example:
301301
minimum_prek_version: '0.2.0'
302302
```
303303

304-
You can append an optional upgrade hint after a semicolon. The hint is shown only
305-
when validation fails.
306-
307-
Example:
308-
309-
```yaml
310-
minimum_prek_version: '0.2.0; Use brew upgrade to upgrade prek'
311-
```
312-
313304
#### `orphan`
314305

315306
<a id="prek-only-orphan"></a>
@@ -830,20 +821,6 @@ Require a minimum `prek` version for this specific hook.
830821
- Type: string (version)
831822
- Default: unset
832823

833-
You can append an optional upgrade hint after a semicolon. The hint is shown only
834-
when validation fails.
835-
836-
Example:
837-
838-
```yaml
839-
hooks:
840-
- id: my-hook
841-
name: My Hook
842-
language: system
843-
entry: echo hello
844-
minimum_prek_version: '0.2.0; Use brew upgrade to upgrade prek'
845-
```
846-
847824
## Environment variables
848825

849826
prek supports the following environment variables:

0 commit comments

Comments
 (0)