Skip to content

fix(ci): exempt SDK-written lock files from the newline hook - #40

Merged
mxwlf merged 2 commits into
mainfrom
fix/sdk-lockfile-newline
Nov 10, 2026
Merged

mxwlf merged 2 commits into
mainfrom
fix/sdk-lockfile-newline

Conversation

@mxwlf

@mxwlf mxwlf commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Every Dependabot NuGet bump fails make ci on the same hook:

fix end of files.......................Failed
- hook id: end-of-file-fixer
Fixing test/unit/library.example.tests.unit/packages.lock.json
-}
\ No newline at end of file

#36 and #37 are both stuck on it right now, and so are four PRs in a repo generated from this template.

The .NET SDK writes packages.lock.json and .config/dotnet-tools.json without a final newline. Our own commits look clean because end-of-file-fixer appends one before the file reaches a commit, so the committed files end 0a while anything the SDK regenerates ends 7d. Dependabot's updater never runs pre-commit, so its lock files arrive raw, the hook rewrites them in CI, and the run fails.

This excludes those two paths from that one hook. Dependabot cannot be taught to run pre-commit, and .gitattributes is no help either: text normalisation rewrites CRLF, it cannot add a missing final newline.

Checked against a worktree of origin/dependabot/nuget/dot-config/routine-a79334c9c9, where all three generated files are missing the newline:

  • with the exclude, end-of-file-fixer passes and leaves those files byte-identical
  • a hand-made file with no final newline still fails the hook
  • make ci passes on this branch

Scoped by filename rather than by extension, so ordinary JSON keeps the rule.

baseline-drift then reported the change, because it compares our shared pre-commit definitions against the reviewed git-template checkout:

pre-commit configuration differs: https://github.com/pre-commit/pre-commit-hooks

The exclude cannot move upstream. git-template is language neutral and has no packages.lock.json or .config/dotnet-tools.json, so the hook and the SDK only disagree here. The second commit records it in .github/git-baseline-exceptions.json, the way docs/security-baseline.md prescribes. Checked against the pinned baseline 3908f46: the check prints the accepted difference and exits 0.

end-of-file-fixer and the .NET SDK disagree about two files, and the SDK
wins. `dotnet restore` writes packages.lock.json with the closing brace
as its last byte, and `dotnet tool` does the same to
.config/dotnet-tools.json.

A human never sees it, because the hook appends the newline before the
file reaches a commit. Dependabot's updater does not run pre-commit, so
its regenerated lock files reach CI raw, and `make ci` fails on a file
nobody wrote. That happens on every NuGet bump.

Exclude the two files by name, so a hand-written JSON file missing its
final newline is still caught.
`baseline-drift` compares this repository's shared pre-commit definitions
with the reviewed git-template checkout, so excluding the SDK-written
lock files from end-of-file-fixer reports:

    pre-commit configuration differs: https://github.com/pre-commit/pre-commit-hooks

The exclude cannot move upstream. git-template is language neutral and
has no packages.lock.json or .config/dotnet-tools.json, so the hook and
the SDK only disagree here. Record it as a deliberate difference, which
is what .github/git-baseline-exceptions.json is for.

Verified against the pinned baseline 3908f46 in both repositories: the
check reports the accepted difference and exits 0.
@mxwlf
mxwlf merged commit 34a1c8a into main Nov 10, 2026
11 checks passed
@mxwlf
mxwlf deleted the fix/sdk-lockfile-newline branch November 10, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant