Skip to main content

Module common

Module common 

Source
Expand description

Shared plumbing for the linter-orchestration hooks.

Nine of them do the same four things: collect staged files of some kind, bail out if there are none, resolve a tool, run it. In shell that was ~65 lines apiece, mostly duplicated; here it is a handful of helpers and each hook keeps only what is actually specific to it.

Enums§

Restaged
What a re-stage actually did. THREE answers, because the old bool conflated two of them and the conflation shipped unformatted code.

Functions§

fail
first_existing
The first of names that exists at the repo root — how these hooks decide a repo has opted into a tool.
fixing_enabled
Whether the user asked for checks to repair what they find.
fixing_requested
What the CONFIG says, ignoring whether the current run may act on it.
hl
Orange, for the fragments these hooks highlight.
not_the_index
Whether the file set every check sees is something other than the index.
ok
override_file_set
Make every subsequent staged_files answer from files instead of the index. Only the first call counts.
program
Resolve a tool name to a full path for spawning.
repo_root
Repo root, or “.” when git cannot say.
repo_root_checked
Repo root, or an error naming the problem.
resolve_tool
Resolve a tool, preferring the repo’s PINNED copy so the hook matches CI.
restage
Re-stage exactly the paths a fixer rewrote, and say what happened.
run
Run argv from root, inheriting stdio. True when it exits 0.
run_quiet
As run, but with the tool’s own output discarded.
staged_files
An empty exts returns them all.
strip_git_env
Strip git’s own environment before handing a Command to another tool.
warn
which
First match for tool on PATH.