Skip to content

validate-lint-format.sh: Rust and Nickel arms ask a different question than their tool #932

Description

@hyperpolymath

Summary

.githooks/validate-lint-format.sh gates its Rust arm on whether the repo tracks a Cargo.toml anywhere, then runs cargo from the repo root. cargo asks a different question: is there a Cargo.toml in the current directory or a parent. This repo has none at the root, so the arm fires and then fails for a reason that has nothing to do with the staged code.

This is the recurring estate trap: a guard that asks a different question than its consumer. The comment above the arm (lines 82–86) even names the failure it is trying to prevent — it just prevents it in the wrong repo shape.

Measured evidence

$ ls Cargo.toml
ls: cannot access 'Cargo.toml': No such file or directory

$ git ls-files | grep -c 'Cargo\.toml$'
12

$ cargo fmt --all --check ; echo rc=$?
error: could not find `Cargo.toml` in `<repo root>` or any parent directory
rc=1

$ cargo clippy --all-targets -- -D warnings ; echo rc=$?
rc=101

tracks 'Cargo.toml' '*/Cargo.toml' (.githooks/validate-lint-format.sh:66) returns true because 12 manifests are tracked, so the arm always fires. The consequence: any commit staging a .rs file is rejected, and the message reads Rust: sources are not formatted (cargo fmt --check), which misnames the cause.

There is a second arm with the same shape. The Nickel arm globs *.ncl and feeds every match to nickel, but the .k9.ncl population is mixed:

total .ncl files:                    36
.k9.ncl files:                       16
.k9.ncl starting with `K9!`:          8   # not Nickel source at all

nickel fails those 8 at line 1 column 0 with a parse error on K9!. Extension is not a valid discriminator here; the K9! content marker is.

Acceptance criteria

  • The Rust arm runs cargo per crate directory (from each staged file's nearest ancestor Cargo.toml), not once from the repo root.
  • With a .rs staged in a crate that is clean, the hook passes; the root having no Cargo.toml is not itself a failure.
  • A could not find Cargo.toml condition is reported as a tooling/scope error naming the directory, never as sources are not formatted.
  • The Nickel arm skips files whose first bytes are K9!, and says how many it skipped — a denominator, not silence.
  • bash -n clean; the arms stay read-only (--check only, no cargo fmt without --check).

Found while measuring #931. Related: the pin-detector defect in #931 is the same trap in a different file.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions