Skip to content

Commit 23815bd

Browse files
authored
Remove the @builtin group selector (#2628)
1 parent 67d2254 commit 23815bd

7 files changed

Lines changed: 31 additions & 59 deletions

File tree

‎crates/prek/src/cli/mod.rs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ pub(crate) struct RunArgs {
679679
///
680680
/// Can be specified multiple times; a hook may match any specified group.
681681
/// When combined with `--require-group`, both filters must match.
682-
/// `@ungrouped` matches hooks without groups, while `@builtin` matches
683-
/// hooks from the builtin repository.
682+
/// `@ungrouped` matches hooks without groups.
684683
#[arg(long = "group", value_name = "GROUP")]
685684
pub(crate) groups: Vec<String>,
686685

@@ -692,14 +691,14 @@ pub(crate) struct RunArgs {
692691
///
693692
/// For example, `--require-group fast --group format --group lint-only`
694693
/// selects hooks in `fast` and either `format` or `lint-only`.
695-
/// The special selectors `@ungrouped` and `@builtin` are also supported.
694+
/// The special selector `@ungrouped` is also supported.
696695
#[arg(long = "require-group", value_name = "GROUP")]
697696
pub(crate) required_groups: Vec<String>,
698697

699698
/// Do not run hooks belonging to the specified group.
700699
///
701700
/// Can be specified multiple times. Exclusion wins over inclusion.
702-
/// The special selectors `@ungrouped` and `@builtin` are also supported.
701+
/// The special selector `@ungrouped` is also supported.
703702
#[arg(long = "no-group", value_name = "GROUP")]
704703
pub(crate) no_groups: Vec<String>,
705704
}
@@ -786,22 +785,21 @@ pub(crate) struct ListArgs {
786785

787786
/// Show hooks belonging to the specified group.
788787
///
789-
/// Can be specified multiple times. `@ungrouped` matches hooks without
790-
/// groups, while `@builtin` matches hooks from the builtin repository.
788+
/// Can be specified multiple times. `@ungrouped` matches hooks without groups.
791789
#[arg(long = "group", value_name = "GROUP")]
792790
pub(crate) groups: Vec<String>,
793791

794792
/// Show hooks belonging to every specified group.
795793
///
796794
/// Can be specified multiple times. Composes with `--group` and `--no-group`.
797-
/// The special selectors `@ungrouped` and `@builtin` are also supported.
795+
/// The special selector `@ungrouped` is also supported.
798796
#[arg(long = "require-group", value_name = "GROUP")]
799797
pub(crate) required_groups: Vec<String>,
800798

801799
/// Do not show hooks belonging to the specified group.
802800
///
803801
/// Can be specified multiple times. Exclusion wins over inclusion.
804-
/// The special selectors `@ungrouped` and `@builtin` are also supported.
802+
/// The special selector `@ungrouped` is also supported.
805803
#[arg(long = "no-group", value_name = "GROUP")]
806804
pub(crate) no_groups: Vec<String>,
807805

‎crates/prek/src/cli/run/selector.rs‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
44
use std::sync::{Arc, Mutex};
55

66
use crate::config::validate_group_name;
7-
use crate::hook::{Hook, Repo};
7+
use crate::hook::Hook;
88
use crate::warn_user;
99

1010
use anyhow::anyhow;
@@ -434,21 +434,17 @@ pub(crate) struct GroupFilters {
434434
enum GroupSelector {
435435
Named(String),
436436
Ungrouped,
437-
Builtin,
438437
}
439438

440439
const UNGROUPED_GROUP: &str = "@ungrouped";
441-
const BUILTIN_GROUP: &str = "@builtin";
442440

443441
impl GroupSelector {
444442
fn parse(group: &str) -> Result<Self, &'static str> {
445-
match group {
446-
UNGROUPED_GROUP => Ok(Self::Ungrouped),
447-
BUILTIN_GROUP => Ok(Self::Builtin),
448-
_ => {
449-
validate_group_name(group)?;
450-
Ok(Self::Named(group.to_owned()))
451-
}
443+
if group == UNGROUPED_GROUP {
444+
Ok(Self::Ungrouped)
445+
} else {
446+
validate_group_name(group)?;
447+
Ok(Self::Named(group.to_owned()))
452448
}
453449
}
454450
}
@@ -458,7 +454,6 @@ impl Display for GroupSelector {
458454
match self {
459455
Self::Named(group) => f.write_str(group),
460456
Self::Ungrouped => f.write_str(UNGROUPED_GROUP),
461-
Self::Builtin => f.write_str(BUILTIN_GROUP),
462457
}
463458
}
464459
}
@@ -534,7 +529,6 @@ impl GroupFilters {
534529
self.matches_groups(|group| match group {
535530
GroupSelector::Named(group) => hook.groups.contains(group),
536531
GroupSelector::Ungrouped => hook.groups.is_empty(),
537-
GroupSelector::Builtin => matches!(hook.repo(), Repo::Builtin),
538532
})
539533
}
540534

@@ -544,7 +538,6 @@ impl GroupFilters {
544538
.groups
545539
.is_some_and(|groups| groups.iter().any(|hook_group| hook_group == group)),
546540
GroupSelector::Ungrouped => hook.groups.is_none_or(<[String]>::is_empty),
547-
GroupSelector::Builtin => false,
548541
})
549542
}
550543

‎crates/prek/src/config/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ mod tests {
410410
"group name `ci\tslow` cannot contain whitespace",
411411
),
412412
(
413-
r#"["@builtin"]"#,
414-
"group name `@builtin` uses the reserved `@` prefix",
413+
r#"["@custom"]"#,
414+
"group name `@custom` uses the reserved `@` prefix",
415415
),
416416
] {
417417
let yaml = indoc::formatdoc! {r"

‎crates/prek/tests/run.rs‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -938,14 +938,9 @@ fn run_group_without_stage_selects_hooks_across_stages() {
938938
}
939939

940940
#[test]
941-
fn run_reserved_groups_select_ungrouped_and_builtin_hooks() {
941+
fn run_ungrouped_group_selects_hooks_without_groups() {
942942
let context = TestEnv::new().with_config(indoc::indoc! {r#"
943943
repos:
944-
- repo: builtin
945-
hooks:
946-
- id: end-of-file-fixer
947-
groups: [other]
948-
949944
- repo: local
950945
hooks:
951946
- id: ungrouped
@@ -982,14 +977,11 @@ fn run_reserved_groups_select_ungrouped_and_builtin_hooks() {
982977
.arg("--group")
983978
.arg("ci")
984979
.arg("--group")
985-
.arg("@ungrouped")
986-
.arg("--group")
987-
.arg("@builtin"),
980+
.arg("@ungrouped"),
988981
@r#"
989982
success: true
990983
exit_code: 0
991984
----- stdout -----
992-
fix end of files.........................................................Passed
993985
Ungrouped................................................................Passed
994986
CI.......................................................................Passed
995987

‎docs/proposals/hook-groups.md‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,10 @@ its `groups` contains every required group.
105105
`--no-group <name>` is an exclude filter. A hook is removed if its `groups`
106106
contains any excluded group.
107107

108-
Two names are reserved as special selectors:
108+
`@ungrouped` is reserved as a special selector. It matches hooks whose
109+
effective `groups` list is empty.
109110

110-
- `@ungrouped` matches hooks whose effective `groups` list is empty.
111-
- `@builtin` matches hooks from the `builtin` repository, regardless of their
112-
configured groups.
113-
114-
They compose with all three options like ordinary group memberships, but cannot
111+
It composes with all three options like an ordinary group membership, but cannot
115112
be configured in a hook's `groups` list.
116113

117114
The three options compose independently of argument order, and exclusion wins:
@@ -138,7 +135,7 @@ prek run --all-files --group lint --group typecheck
138135
prek run --all-files --require-group lint --require-group fast
139136
prek run --all-files --no-group format
140137
prek run --all-files --group ci --require-group lint --no-group slow
141-
prek run --all-files --group ci --group @ungrouped --group @builtin
138+
prek run --all-files --group ci --group @ungrouped
142139
prek run --all-files --group ci --stage pre-push
143140
```
144141

@@ -285,12 +282,6 @@ they do not belong to the excluded group.
285282
`@ungrouped` also works with the other filters. `--require-group @ungrouped`
286283
keeps only ungrouped hooks, while `--no-group @ungrouped` removes them.
287284

288-
### Builtin Hooks
289-
290-
Every hook from a `repo: builtin` entry matches `@builtin`, whether or not it
291-
has configured groups. `@builtin` does not match `local`, `meta`, or remote
292-
hooks.
293-
294285
### Multiple Groups
295286

296287
A hook may belong to multiple groups:
@@ -328,7 +319,7 @@ for special CLI selectors.
328319
Invalid examples:
329320

330321
```yaml
331-
groups: ["", "ci slow", " ci", "ci\nslow", "@builtin"]
322+
groups: ["", "ci slow", " ci", "ci\nslow", "@custom"]
332323
```
333324

334325
Apart from the reserved `@` namespace, no fixed vocabulary should be enforced.

‎docs/reference/cli.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,20 @@ prek run [OPTIONS] [HOOK|PROJECT]...
233233
</dd><dt id="prek-run--glob"><a href="#prek-run--glob"><code>--glob</code></a> <i>pattern</i></dt><dd><p>Run hooks on tracked files matching the specified glob pattern.</p>
234234
<p>Patterns are matched against paths relative to the current working directory after applying <code>--cd</code>. Quote patterns to prevent shell expansion. This option can be repeated and combined with <code>--files</code> and <code>--directory</code>.</p>
235235
</dd><dt id="prek-run--group"><a href="#prek-run--group"><code>--group</code></a> <i>group</i></dt><dd><p>Run hooks belonging to the specified group.</p>
236-
<p>Can be specified multiple times; a hook may match any specified group. When combined with <code>--require-group</code>, both filters must match. <code>@ungrouped</code> matches hooks without groups, while <code>@builtin</code> matches hooks from the builtin repository.</p>
236+
<p>Can be specified multiple times; a hook may match any specified group. When combined with <code>--require-group</code>, both filters must match. <code>@ungrouped</code> matches hooks without groups.</p>
237237
</dd><dt id="prek-run--help"><a href="#prek-run--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
238238
</dd><dt id="prek-run--last-commit"><a href="#prek-run--last-commit"><code>--last-commit</code></a></dt><dd><p>Run hooks against the last commit. Equivalent to <code>--from-ref HEAD~1 --to-ref HEAD</code></p>
239239
</dd><dt id="prek-run--log-file"><a href="#prek-run--log-file"><code>--log-file</code></a> <i>log-file</i></dt><dd><p>Write trace logs to the specified file. If not specified, trace logs will be written to <code>$PREK_HOME/prek.log</code></p>
240240
</dd><dt id="prek-run--no-group"><a href="#prek-run--no-group"><code>--no-group</code></a> <i>group</i></dt><dd><p>Do not run hooks belonging to the specified group.</p>
241-
<p>Can be specified multiple times. Exclusion wins over inclusion. The special selectors <code>@ungrouped</code> and <code>@builtin</code> are also supported.</p>
241+
<p>Can be specified multiple times. Exclusion wins over inclusion. The special selector <code>@ungrouped</code> is also supported.</p>
242242
</dd><dt id="prek-run--no-progress"><a href="#prek-run--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
243243
<p>For example, spinners or progress bars.</p>
244244
</dd><dt id="prek-run--quiet"><a href="#prek-run--quiet"><code>--quiet</code></a>, <code>-q</code></dt><dd><p>Use quiet output.</p>
245245
<p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which prek will write no output to stdout.</p>
246246
<p>May also be set with the <code>PREK_QUIET</code> environment variable.</p></dd><dt id="prek-run--refresh"><a href="#prek-run--refresh"><code>--refresh</code></a></dt><dd><p>Refresh all cached data</p>
247247
</dd><dt id="prek-run--require-group"><a href="#prek-run--require-group"><code>--require-group</code></a> <i>group</i></dt><dd><p>Run hooks belonging to every specified group.</p>
248248
<p>Can be specified multiple times; a hook must match every specified group. When combined with <code>--group</code>, it must also match at least one <code>--group</code>. <code>--no-group</code> excludes matching hooks regardless of argument order.</p>
249-
<p>For example, <code>--require-group fast --group format --group lint-only</code> selects hooks in <code>fast</code> and either <code>format</code> or <code>lint-only</code>. The special selectors <code>@ungrouped</code> and <code>@builtin</code> are also supported.</p>
249+
<p>For example, <code>--require-group fast --group format --group lint-only</code> selects hooks in <code>fast</code> and either <code>format</code> or <code>lint-only</code>. The special selector <code>@ungrouped</code> is also supported.</p>
250250
</dd><dt id="prek-run--show-diff-on-failure"><a href="#prek-run--show-diff-on-failure"><code>--show-diff-on-failure</code></a></dt><dd><p>When hooks fail, run <code>git diff</code> directly afterward</p>
251251
</dd><dt id="prek-run--skip"><a href="#prek-run--skip"><code>--skip</code></a> <i>hook|project</i></dt><dd><p>Skip the specified hooks or projects.</p>
252252
<p>Supports flexible selector syntax:</p>
@@ -359,7 +359,7 @@ prek list [OPTIONS] [HOOK|PROJECT]...
359359
<li><code>never</code>: Disables colored output</li>
360360
</ul></dd><dt id="prek-list--config"><a href="#prek-list--config"><code>--config</code></a>, <code>-c</code> <i>config</i></dt><dd><p>Path to alternate config file</p>
361361
</dd><dt id="prek-list--group"><a href="#prek-list--group"><code>--group</code></a> <i>group</i></dt><dd><p>Show hooks belonging to the specified group.</p>
362-
<p>Can be specified multiple times. <code>@ungrouped</code> matches hooks without groups, while <code>@builtin</code> matches hooks from the builtin repository.</p>
362+
<p>Can be specified multiple times. <code>@ungrouped</code> matches hooks without groups.</p>
363363
</dd><dt id="prek-list--help"><a href="#prek-list--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>
364364
</dd><dt id="prek-list--hook-stage"><a href="#prek-list--hook-stage"><code>--hook-stage</code></a> <i>hook-stage</i></dt><dd><p>Show only hooks that has the specified stage</p>
365365
<p>Possible values:</p>
@@ -405,7 +405,7 @@ prek list [OPTIONS] [HOOK|PROJECT]...
405405
<li><code>system</code></li>
406406
</ul></dd><dt id="prek-list--log-file"><a href="#prek-list--log-file"><code>--log-file</code></a> <i>log-file</i></dt><dd><p>Write trace logs to the specified file. If not specified, trace logs will be written to <code>$PREK_HOME/prek.log</code></p>
407407
</dd><dt id="prek-list--no-group"><a href="#prek-list--no-group"><code>--no-group</code></a> <i>group</i></dt><dd><p>Do not show hooks belonging to the specified group.</p>
408-
<p>Can be specified multiple times. Exclusion wins over inclusion. The special selectors <code>@ungrouped</code> and <code>@builtin</code> are also supported.</p>
408+
<p>Can be specified multiple times. Exclusion wins over inclusion. The special selector <code>@ungrouped</code> is also supported.</p>
409409
</dd><dt id="prek-list--no-progress"><a href="#prek-list--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
410410
<p>For example, spinners or progress bars.</p>
411411
</dd><dt id="prek-list--output-format"><a href="#prek-list--output-format"><code>--output-format</code></a> <i>output-format</i></dt><dd><p>The output format</p>
@@ -417,7 +417,7 @@ prek list [OPTIONS] [HOOK|PROJECT]...
417417
<p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which prek will write no output to stdout.</p>
418418
<p>May also be set with the <code>PREK_QUIET</code> environment variable.</p></dd><dt id="prek-list--refresh"><a href="#prek-list--refresh"><code>--refresh</code></a></dt><dd><p>Refresh all cached data</p>
419419
</dd><dt id="prek-list--require-group"><a href="#prek-list--require-group"><code>--require-group</code></a> <i>group</i></dt><dd><p>Show hooks belonging to every specified group.</p>
420-
<p>Can be specified multiple times. Composes with <code>--group</code> and <code>--no-group</code>. The special selectors <code>@ungrouped</code> and <code>@builtin</code> are also supported.</p>
420+
<p>Can be specified multiple times. Composes with <code>--group</code> and <code>--no-group</code>. The special selector <code>@ungrouped</code> is also supported.</p>
421421
</dd><dt id="prek-list--skip"><a href="#prek-list--skip"><code>--skip</code></a> <i>hook|project</i></dt><dd><p>Skip the specified hooks or projects.</p>
422422
<p>Supports flexible selector syntax:</p>
423423
<ul>

‎docs/reference/configuration.md‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,11 +1163,9 @@ Group names cannot be empty, contain whitespace, or start with `@`. Names that
11631163
start with `@` are reserved for special selectors:
11641164

11651165
- `@ungrouped` matches hooks whose effective `groups` list is empty.
1166-
- `@builtin` matches hooks from the `builtin` repository, regardless of their
1167-
configured groups.
11681166

1169-
These selectors work with `--group`, `--require-group`, and `--no-group`. They
1170-
are virtual memberships and cannot be added to a hook's `groups` list.
1167+
This selector works with `--group`, `--require-group`, and `--no-group`. It is a
1168+
virtual membership and cannot be added to a hook's `groups` list.
11711169

11721170
`groups` is a project configuration field. If it appears in a remote
11731171
`.pre-commit-hooks.yaml` manifest, `prek` ignores it.
@@ -1222,10 +1220,10 @@ Run only the `ci` group:
12221220
prek run --all-files --group ci
12231221
```
12241222

1225-
Run the `ci` group together with ungrouped and builtin hooks:
1223+
Run the `ci` group together with ungrouped hooks:
12261224

12271225
```bash
1228-
prek run --all-files --group ci --group @ungrouped --group @builtin
1226+
prek run --all-files --group ci --group @ungrouped
12291227
```
12301228

12311229
Run only hooks belonging to both `lint` and `ci`:

0 commit comments

Comments
 (0)