Repository navigation
Frontal's git-hook gates as a pre-commit + lefthook remote #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e8e77f6
00357ac
ba3ca29
5800938
7d69843
130194f
f116681
445b718
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| cache: npm | ||
|
|
||
| # Dev dependencies bring @biomejs/biome (on node_modules/.bin, which the | ||
| # test runner prepends to PATH) and the ultracite preset used by biome.jsonc. | ||
| - name: Install dev dependencies | ||
| run: npm ci | ||
|
|
||
| # Install the tools the hooks need. The hooks fail loudly when a tool | ||
| # is missing (ensure-tool.mjs), so the test suite only runs the cases | ||
| # whose tools are actually installed. | ||
| - name: Install ruff | ||
| run: pipx install ruff | ||
|
|
||
| - name: Install rustfmt + clippy | ||
| run: rustup component add rustfmt clippy | ||
|
|
||
| # Install buf from the official GitHub release binary. The old | ||
| # https://buf.build/install.sh installer URL now returns an HTML page | ||
| # (not a script), so download the pinned release binary directly | ||
| # instead. curl -f fails the step on any HTTP error. | ||
| - name: Install buf | ||
| run: | | ||
| BUF_VERSION="1.75.0" | ||
| mkdir -p "$HOME/.buf/bin" | ||
| curl -fsSL -o "$HOME/.buf/bin/buf" \ | ||
| "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-$(uname -s)-$(uname -m)" | ||
| chmod +x "$HOME/.buf/bin/buf" | ||
| echo "$HOME/.buf/bin" >> "$GITHUB_PATH" | ||
|
|
||
| - name: Verify buf | ||
| run: buf --version | ||
|
|
||
| # go and cargo ship with the ubuntu-latest runner image. | ||
| # biome comes from the devDependencies installed above (all 15 cases run). | ||
|
|
||
| - name: Run biome self-check | ||
| run: npm run check | ||
|
|
||
| - name: Run hook tests | ||
| run: npm test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Create GitHub Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| generate_release_notes: true | ||
| draft: false | ||
| prerelease: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| node_modules/ |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,98 +1,67 @@ | ||||
| # Pre-commit framework configuration | ||||
| # Pre-commit framework configuration for this repository (self-test). | ||||
| # | ||||
| # When you contribute to this repo, pre-commit will run the hooks against | ||||
| # your staged changes — the same hooks that external consumers use. | ||||
| fail_fast: false | ||||
| default_install_hook_types: [pre-commit, commit-msg] | ||||
| default_install_hook_types: [ pre-commit, commit-msg ] | ||||
|
|
||||
| repos: | ||||
| # Biome (JS/TS/JSON/YAML) | ||||
| - repo: local | ||||
| hooks: | ||||
| - id: biome-check | ||||
| name: biome check | ||||
| entry: bunx biome check --write --no-errors-on-unmatched | ||||
| - id: frontal-biome | ||||
| name: frontal biome check | ||||
| entry: sh -c 'node hooks/ensure-tool.mjs pnpm && pnpm exec biome check --no-errors-on-unmatched "$@"' | ||||
| language: system | ||||
| files: \.(ts|tsx|mts|cts|js|jsx|mjs|cjs|json|jsonc|yaml|yml)$ | ||||
| stages: [pre-commit] | ||||
| files: \.(ts|tsx|js|jsx|json)$ | ||||
| exclude: "^packages/design-system/" | ||||
| stages: [ pre-commit ] | ||||
|
|
||||
| - id: biome-format | ||||
| name: biome format | ||||
| entry: bunx biome format --write --no-errors-on-unmatched | ||||
| - id: frontal-ruff | ||||
| name: frontal ruff check + format | ||||
| entry: sh -c 'node hooks/ensure-tool.mjs ruff && ruff check "$@" && ruff format --check "$@"' | ||||
| language: system | ||||
| files: \.(ts|tsx|mts|cts|js|jsx|mjs|cjs|json|jsonc|yaml|yml)$ | ||||
| stages: [pre-commit] | ||||
| files: \.py$ | ||||
| exclude: "(^|/)(vendor|gen|generated|node_modules)/" | ||||
| stages: [ pre-commit ] | ||||
|
|
||||
| # Rust | ||||
| - repo: local | ||||
| hooks: | ||||
| - id: cargo-fmt | ||||
| name: cargo fmt | ||||
| entry: cargo fmt | ||||
| - id: frontal-rustfmt | ||||
| name: frontal rustfmt (staged) | ||||
| entry: sh -c 'node hooks/ensure-tool.mjs rustfmt && rust_files=$(git diff --cached --name-only --diff-filter=ACMR -- "*.rs" | grep -vE "(^|/)gen/" || true); if [ -n "$rust_files" ]; then printf "%s\n" "$rust_files" | xargs rustfmt --edition 2024 --check; fi' | ||||
| language: system | ||||
| files: \.rs$ | ||||
| pass_filenames: false | ||||
| stages: [pre-commit] | ||||
| stages: [ pre-commit ] | ||||
|
|
||||
| - id: cargo-clippy | ||||
| name: cargo clippy | ||||
| entry: cargo clippy -- -D warnings | ||||
| - id: frontal-clippy | ||||
| name: frontal cargo clippy (scoped) | ||||
| entry: sh -c 'node hooks/ensure-tool.mjs cargo && node hooks/clippy-scoped.mjs' | ||||
| language: system | ||||
| files: \.rs$ | ||||
| pass_filenames: false | ||||
| stages: [pre-commit] | ||||
|
|
||||
| # Go | ||||
| - repo: local | ||||
| hooks: | ||||
| - id: gofmt | ||||
| name: gofmt | ||||
| entry: gofmt -w | ||||
| language: system | ||||
| files: \.go$ | ||||
| stages: [pre-commit] | ||||
|
|
||||
| - id: goimports | ||||
| name: goimports | ||||
| entry: goimports -w | ||||
| language: system | ||||
| files: \.go$ | ||||
| stages: [pre-commit] | ||||
| stages: [ pre-commit ] | ||||
|
|
||||
| - id: golangci-lint | ||||
| name: golangci-lint | ||||
| entry: golangci-lint run --fix | ||||
| - id: frontal-go-vet | ||||
| name: frontal go vet (scoped) | ||||
| entry: sh -c 'node hooks/ensure-tool.mjs go && node hooks/go-vet-scoped.mjs' | ||||
| language: system | ||||
| files: \.go$ | ||||
| pass_filenames: false | ||||
| stages: [pre-commit] | ||||
|
|
||||
| # Python | ||||
| - repo: local | ||||
| hooks: | ||||
| - id: ruff-lint | ||||
| name: ruff lint | ||||
| entry: ruff check --fix | ||||
| language: system | ||||
| files: \.py$ | ||||
| stages: [pre-commit] | ||||
|
|
||||
| - id: ruff-format | ||||
| name: ruff format | ||||
| entry: ruff format | ||||
| language: system | ||||
| files: \.py$ | ||||
| stages: [pre-commit] | ||||
| stages: [ pre-commit ] | ||||
|
|
||||
| - id: black | ||||
| name: black | ||||
| entry: black | ||||
| - id: frontal-buf-lint | ||||
| name: frontal buf lint (scoped) | ||||
| entry: sh -c 'node hooks/ensure-tool.mjs buf && node hooks/buf-lint-scoped.mjs' | ||||
| language: system | ||||
| files: \.py$ | ||||
| stages: [pre-commit] | ||||
| files: \.proto$ | ||||
| pass_filenames: false | ||||
| stages: [ pre-commit ] | ||||
|
|
||||
| # Conventional Commits | ||||
| - repo: local | ||||
| hooks: | ||||
| - id: commitlint | ||||
| name: commitlint | ||||
| entry: bunx commitlint --edit | ||||
| - id: frontal-commit-msg | ||||
| name: frontal commit-msg (Conventional Commits) | ||||
| # The commit-msg file arrives as the first positional param, which | ||||
| # `sh -c` consumes as $0. The hook reads from that path (or stdin). | ||||
| entry: sh -c 'node hooks/check-commit-message.mjs "$0"' | ||||
| language: system | ||||
| stages: [commit-msg] | ||||
| pass_filenames: false | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For In that case The harness passes the path anyway, so the test hides the defect. Remove Proposed fix
Committable suggestion
|
||||
| always_run: true | ||||
| stages: [ commit-msg ] | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,135 @@ | ||
| - id: frontal-lint | ||
| name: Frontal lint | ||
| description: Lint with Frontal | ||
| entry: frontal lint | ||
| language: system | ||
| types_or: [python, javascript, typescript] | ||
| stages: [pre-commit] | ||
| # --------------------------------------------------------------------------- | ||
| # Frontal's git-hook gates, republished for external repositories. | ||
| # | ||
| # Source of truth: frontal/lefthook.yml + scripts/hooks/run-checks.mjs. | ||
| # Do not add rules here that do not exist in those files. | ||
| # | ||
| # Every hook fails loudly when its tool is missing (hooks/ensure-tool.mjs). | ||
| # Shared excludes: vendor/, gen/, generated/, node_modules/ | ||
| # | ||
| # Each hook is `language: script`: pre-commit resolves the `entry` script to | ||
| # an ABSOLUTE path inside the hook CHECKOUT (the runner's clone of this repo) | ||
| # and executes it directly, with the CONSUMER repo as cwd. Each script | ||
| # resolves its `node hooks/…` calls against the checkout as an absolute path | ||
| # (derived from the script's own location) WITHOUT changing the consumer's | ||
| # working directory — so biome/ruff/scoped runners see the consumer repo as | ||
| # their project root, exactly as the consumer's own config expects. | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| # ---- Biome (JS/TS/JSON) --------------------------------------------------- | ||
| # Mirrors lefthook `biome`: | ||
| # glob: *.{ts,tsx,js,jsx,json} | ||
| # exclude: ^packages/design-system/ | ||
| # run: biome check --no-errors-on-unmatched {staged_files} | ||
| # Check-only (no --write); pre-commit passes staged files as arguments. | ||
| # The ultracite preset lives in this repo's biome.json (consumers extend it | ||
| # the same way: { "extends": ["ultracite/biome/core"] } + the two npm | ||
| # devDependencies @biomejs/biome and ultracite). | ||
| - id: frontal-biome | ||
| name: frontal biome check | ||
| description: Biome check (check-only) on staged JS/TS/JSON files | ||
| entry: hooks/biome.sh | ||
| language: script | ||
| files: \.(ts|tsx|js|jsx|json)$ | ||
| exclude: "^packages/design-system/" | ||
| stages: [ pre-commit ] | ||
|
|
||
| # ---- Ruff (Python lint + format) ------------------------------------------ | ||
| # Mirrors lefthook `python-ruff` and `python-format`: | ||
| # glob: *.py | ||
| # exclude: (^|/)(vendor|gen/python|generated)/ | ||
| # run: ruff check {staged_files} (python-ruff) | ||
| # run: ruff format --check {staged_files} (python-format) | ||
| # The two lefthook commands are merged here: ruff check && ruff format --check. | ||
| # Black is intentionally absent — frontal uses ruff exclusively. | ||
| - id: frontal-ruff | ||
| name: frontal ruff check + format | ||
| description: ruff check and ruff format --check on staged Python files | ||
| entry: hooks/ruff.sh | ||
| language: script | ||
| files: \.py$ | ||
| exclude: "(^|/)(vendor|gen|generated|node_modules)/" | ||
| stages: [ pre-commit ] | ||
|
|
||
| # ---- Rustfmt (staged files only) ------------------------------------------ | ||
| # Mirrors lefthook `rust-fmt`: | ||
| # rust_files=$(git diff --cached --name-only --diff-filter=ACMR -- '*.rs' | ||
| # | grep -vE '(^|/)gen/') | ||
| # printf '%s\n' "$rust_files" | xargs rustfmt --edition 2024 --check | ||
| # Staged files only — never the whole workspace. | ||
| # The script re-reads the staged file list from git so that renames (which | ||
| # pre-commit passes as "old new" pairs) do not confuse rustfmt. | ||
| - id: frontal-rustfmt | ||
| name: frontal rustfmt (staged) | ||
| description: rustfmt --edition 2024 --check on staged Rust files only | ||
| entry: hooks/rustfmt.sh | ||
| language: script | ||
| files: \.rs$ | ||
| pass_filenames: false | ||
| stages: [ pre-commit ] | ||
|
|
||
| # ---- Clippy (scoped per crate workspace) ----------------------------------- | ||
| # Mirrors run-checks.mjs `rust:clippy:<workspace>`: | ||
| # cwd: <crate workspace dir> | ||
| # cmd: cargo clippy -p <crate1> -p <crate2> … --all-targets -- -D warnings | ||
| # For each staged .rs file, the owning workspace is resolved (nearest ancestor | ||
| # Cargo.toml declaring [workspace]; this is the clippy working directory) and | ||
| # the crate name is read from the nearest Cargo.toml declaring [package] (the | ||
| # owning crate — a different manifest for workspace members). One clippy run | ||
| # per workspace covers all of its staged crates. | ||
| # Toolchain is picked from the workspace directory (rust-toolchain.toml). | ||
| - id: frontal-clippy | ||
| name: frontal cargo clippy (scoped) | ||
| description: cargo clippy --all-targets -D warnings on the crates that own staged Rust files | ||
| entry: hooks/clippy.sh | ||
| language: script | ||
| files: \.rs$ | ||
| pass_filenames: false | ||
| stages: [ pre-commit ] | ||
|
|
||
| # ---- Go vet (scoped per module) -------------------------------------------- | ||
| # Mirrors run-checks.mjs `go:vet:<dir>`: | ||
| # cwd: <dir containing go.mod> | ||
| # cmd: go vet ./... | ||
| # For each staged .go file the owning Go module is resolved by walking up to | ||
| # the nearest go.mod. One `go vet ./...` per affected module. | ||
| - id: frontal-go-vet | ||
| name: frontal go vet (scoped) | ||
| description: go vet ./... in each Go module that owns a staged Go file | ||
| entry: hooks/go-vet.sh | ||
| language: script | ||
| files: \.go$ | ||
| pass_filenames: false | ||
| stages: [ pre-commit ] | ||
|
|
||
| # ---- Buf lint (scoped per proto module) ------------------------------------ | ||
| # Mirrors run-checks.mjs `proto:lint:<dir>`: | ||
| # In-workspace modules → buf lint from repo root (buf.yaml workspace) | ||
| # Standalone modules → buf lint in the module directory | ||
| # A module is in-workspace when its path appears in the root buf.yaml | ||
| # modules list; otherwise it is linted module-scoped. | ||
| - id: frontal-buf-lint | ||
| name: frontal buf lint (scoped) | ||
| description: buf lint for each proto module that owns a staged .proto file | ||
| entry: hooks/buf-lint.sh | ||
| language: script | ||
| files: \.proto$ | ||
| pass_filenames: false | ||
| stages: [ pre-commit ] | ||
|
|
||
| # ---- Commit message (Conventional Commits) --------------------------------- | ||
| # Replaces commitlint. Rules are identical to | ||
| # frontal/scripts/hooks/check-commit-message.mjs (copied verbatim into | ||
| # hooks/check-commit-message.mjs in this repository). | ||
| - id: frontal-commit-msg | ||
| name: frontal commit-msg (Conventional Commits) | ||
| description: Validate commit message against Conventional Commits (replaces commitlint) | ||
| # The hook reads the message from the file passed by the runner. With | ||
| # `language: script` the entry script is executed directly (no `--` | ||
| # placeholder), so the commit-msg file path arrives as the script's first | ||
| # positional arg ($1); the script resolves the checker against the checkout | ||
| # and passes the message path as its first argument. | ||
| entry: hooks/commit-msg.sh | ||
| language: script | ||
| always_run: true | ||
| stages: [ commit-msg ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first staged file is dropped from
"$@"in the Biome and Ruff entries.pre-commit appends filenames after the
entrycommand string. Withsh -c '<cmd>' a b c, additional arguments after the command string become $0, $1, .... The first staged file therefore lands in$0, and"$@"holds only the remaining files.If one file is staged,
"$@"is empty.biome check --no-errors-on-unmatchedandruff checkthen run with no path arguments and lint the whole working directory. The staged file is not targeted. With several files, the first one is never checked.The test harness inserts a
$0-placeholderfor these hooks. This hides the defect, because pre-commit does not insert a placeholder.Add a dummy
$0to the end of the entry string:Proposed fix
Apply the same
--change to thefrontal-ruffentry. Remove the placeholder fromrunHookintests/run-hooks.test.mjs, so the test uses the entry exactly as pre-commit runs it.Also applies to: 19-25