Skip to content

Move to Allman, and let CSharpier hold it - #62

Merged
ipjohnson merged 3 commits into
mainfrom
csharpier-allman
Sep 13, 2026
Merged

ipjohnson merged 3 commits into
mainfrom
csharpier-allman

Conversation

@ipjohnson

Copy link
Copy Markdown
Owner

K&R goes, Allman arrives, and a formatter decides it from here rather than review. Allman is what the .NET templates emit and what every C# codebase around this one uses, and it is the one thing CSharpier offers no choice about, so taking its whole layout is what makes the style checkable.

Three commits, meant to be read in order:

  • 79a2881 reformats all 313 C# files. Machine-generated, no behaviour change.
  • 9cc0bba adds the enforcement: the pinned tool, a pre-commit hook, a CI step, .editorconfig, CONTRIBUTING.md.
  • 51a3ecb moves the code samples in the docs, which CSharpier cannot reach.

Reviewing this is mostly reviewing the second commit. The first is large and uninteresting; .git-blame-ignore-revs lists it so git blame keeps pointing at whoever actually wrote each line, and GitHub reads that file without being asked.

One step per clone

git config core.hooksPath .githooks

Git does not install hooks on clone, so this cannot be automated. The hook is the fast answer and --no-verify skips it, which is why build-package.yaml runs dotnet csharpier check . on every pull request. That step is what actually holds the formatting.

Three things deliberately left alone

Project files. CSharpier 1.x formats MSBuild XML too, but it reindents to two spaces while leaving the interior of multi-line comments where it was. Every commented csproj here came out with hanging comment bodies, so .csharpierignore excludes *.csproj, *.props and *.targets.

The generator test fixtures, 491 lines across 30 files. That is C# inside string literals, handed to Roslyn to compile, and several tests assert on the line and column a diagnostic lands at. Reformatting it would move the thing under test.

Everything about a doc sample except its braces. The third commit moves braces only rather than running the samples through CSharpier. CSharpier agrees on every brace and disagrees on plenty a sample decides on purpose: it collapses the fluent chain in the README onto one line, squashes comments aligned to be read down a column, and expands a one-line interface IEmailSender { void Send(string to); } into four. Verified by extracting all 227 fences and diffing against CSharpier's own output, which now differs on no brace.

Checked

Solution builds, 2258 tests pass on net8.0 and net10.0, dotnet csharpier check . is clean, and the VitePress site builds. The hook was tested on both paths, including a path with a space in it.

🤖 Generated with Claude Code

Ian Johnson and others added 3 commits September 13, 2026 12:45
The braces move from K&R to Allman, which is what the .NET ecosystem and every Microsoft
template use, and is the one thing CSharpier does not offer a choice about. Taking its
whole layout rather than a brace-only rewrite is what makes the style checkable instead of
a review topic.

The version is pinned in the tool manifest so a clone and CI agree on what formatted means.

Project files are excluded. CSharpier reindents MSBuild XML to two spaces but leaves the
interior of multi-line comments at its old indentation, and this repo's csproj comments are
long enough that every one of them would come out hanging.

No behaviour change: the solution builds and all 2258 tests pass before and after.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The formatter only holds if something runs it. The pre-commit hook is the fast answer and
the CI step is the guarantee, since a hook lives in a clone and --no-verify skips it.

.editorconfig repeats the same layout for the IDE. Without it Rider and Visual Studio
format to their own defaults as you type, and the next commit undoes it.

.git-blame-ignore-revs keeps the reformat from claiming the last change to every line.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
CSharpier does not reach these: a sample in a ``` fence is prose, and one in a <code>
block is a comment. They were the last K&R left outside the generator tests.

Brace placement only, rather than running the samples through CSharpier. It agrees on
every brace, and disagrees on much else a doc sample decides deliberately: it collapses
the fluent chain in the README onto one line, squashes comments that are aligned to be
read down the column, and expands a one-line `interface IEmailSender { void Send(); }`
into four. Checked by extracting all 227 fences and diffing against CSharpier's own
output, which now differs on no brace.

The generator tests keep theirs. Those samples are C# in a string, fed to Roslyn to
compile; several tests assert on the line and column a diagnostic lands at.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ipjohnson
ipjohnson merged commit d7a1a82 into main Sep 13, 2026
2 checks passed
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