chore(pre-commit): format .NET code via a local dotnet-format hook#182
Merged
Conversation
The .pre-commit-config.yaml shipped empty (repos: []) while its header and AGENTS.md both promised "automatic .NET code formatting" — a no-op that delivers nothing and diverges from go-template, whose config runs a real golangci-lint-fmt + local hook. Wire up the .NET equivalent: a local dotnet-format hook (mirroring go-template's local-hook pattern) that runs "dotnet format" on staged C# changes, so adopters get format-on-commit that matches the template's EnforceCodeStyleInBuild / TreatWarningsAsErrors stance. Running the new hook surfaced pre-existing drift the in-build analyzers miss: both example .cs files carried a UTF-8 BOM, violating the repo's own .editorconfig charset = utf-8 rule (charset/BOM is not a build-enforced analyzer rule). Stripped the BOM so the scaffold is dotnet-format-clean and the hook passes on first run for adopters. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the branch is 100%. Coverage data for the branch is not yet available. Show a code coverage summary of the most covered files.
Code Coverage is in Public Preview. Learn more and provide us with your feedback. |
There was a problem hiding this comment.
Pull request overview
Wires up the previously-empty .pre-commit-config.yaml with a local dotnet-format hook that runs dotnet format on staged C# changes, removes pre-existing UTF-8 BOMs from the two example .cs files (which violated .editorconfig's charset = utf-8), and updates AGENTS.md to describe the now-configured hook.
Changes:
- Add a local
dotnet-formatpre-commit hook triggered by*.cschanges. - Strip UTF-8 BOM from
ExampleClass.csandExampleClassTests.cs. - Update
AGENTS.mdto reflect the configured hook (replacing the prior "no hooks configured yet" wording).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
.pre-commit-config.yaml |
Replaces empty repos: [] with a local dotnet format hook scoped to *.cs. |
src/Example/ExampleClass.cs |
Removes leading UTF-8 BOM. |
tests/Example.Tests/ExampleClassTests.cs |
Removes leading UTF-8 BOM. |
AGENTS.md |
Updates description of .pre-commit-config.yaml to mention the new hook and opt-in via pre-commit install. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
.pre-commit-config.yamlshipped empty (repos: []) while both its header comment andAGENTS.mdpromised "automatic .NET code formatting" — a no-op that delivers nothing. It also diverges from its sibling go-template, which ships a working config (golangci-lint-fmt+ a local hook). This is the pre-commit watch-item flagged in the roadmap epic #167 ("either populate with a useful hook (e.g.dotnet format) or drop it").Change
Wire up the .NET equivalent of go-template's setup — a local
dotnet-formathook (mirroring go-template's local-hook pattern) that runsdotnet formaton staged C# changes:Adopters opt in with
pre-commit installand get format-on-commit that matches the template'sEnforceCodeStyleInBuild/TreatWarningsAsErrorsstance — catching formatting locally before it becomes a CI build error.AGENTS.mdupdated to describe the configured hook (was "empty/prepared … no hooks configured yet").Real finding the hook surfaced
Running the new hook revealed pre-existing drift the in-build analyzers miss: both example
.csfiles carried a UTF-8 BOM (EF BB BF), violating the repo's own.editorconfigcharset = utf-8rule (charset/BOM normalization is adotnet formatconcern, not a build-enforced analyzer rule, so it slipped past CI). Stripped the BOM so the scaffold isdotnet format-clean and the hook passes on first run for adopters.Validation (local, .NET 10.0.300 SDK)
pre-commit validate-config✅ ·yamllint✅ (only the cosmeticdocument-startwarning, matching the original file and go-template's config)pre-commit run dotnet-format --all-files→ Failed once (fixed the BOM drift), then Passed clean (idempotent) ✅dotnet build -c Release→ 0 warnings, 0 errors ✅ ·dotnet test -c Release→ 2 passed ✅Notes
chore:so it does not cut a NuGet release.