feat(builtins): add csharpier C# formatter #1958
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1958"
general
weight: 0.35
jdx
Adds
Builtins.csharpier, a check/fix step that runs CSharpier, the opinionated C# formatter, on staged C# and MSBuild files.hk already has
Builtins.dotnet_format, butdotnet formatworks on a whole project or solution: it needs a single.csproj/.slnto discover, restores packages, and can compile analyzers, so the step isexclusiveand slow in a pre-commit hook. CSharpier formats only the files it is given, with no restore or build, so it fits a per-file hook and runs in parallel with other steps.With
class A{void M(){var x=1;}}staged inProgram.cs,hk checkfails with CSharpier's report:and
hk fixrewrites the file. CSharpier's own settings apply:.csharpierrc/.csharpierrc.json/.csharpierrc.yamland.editorconfig, and files listed in.csharpierignoreare skipped.Files. The step's glob is
*/.cs,*/.csx,*/.csproj,*/.propsand*/.targets. CSharpier 1.x formats MSBuild project files as well as C#, andcsharpier format .formats them too, so they are included. It also formats other XML (.xml,.config,.slnx,.xaml); those are left out because a project's other XML often belongs to another tool. Overrideglobto add them, or to drop the MSBuild files.Commands.
checkrunscsharpier check <files>andfixrunscsharpier format <files>.check_diffprints a patch built withhk util format-difffromcsharpier format --write-stdout <file>, sohk fixwithcheck_firstcan show and apply the change. It does not use CSharpier's stdin mode because CSharpier 1.4.2 crashes formatting stdin when--stdin-pathnames a file with no directory part (for exampleProgram.csat the repository root). CSharpier prints nothing for files it skips (generated files such as.g.cs, and files in.csharpierignoreor.gitignore), so a smallshwrapper prints those unchanged and the patch for the other files still applies. On Windows, where there is no POSIX shell,check_diffis empty and hk falls back tocheck.Versions and installing. The step targets the CSharpier 1.x CLI (tested with 1.4.2). The 0.x syntax,
dotnet csharpier --check, is not supported. CSharpier is a .NET tool and needs the .NET SDK both to install and to run. With mise:hk initsuggests the step when it finds a.csharpierrc,.csharpierignore, or a.config/dotnet-tools.jsonthat mentions csharpier.Tests.
hk test --step csharpierpasses on Linux with CSharpier 1.4.2 and .NET SDK 10.0.404: unformatted, formatted and syntax-error files for check; fix; diff tests for a root file, a file in a nested directory with a space in its name, a.csproj, and a set that includes a generated and an ignored file; and a.csharpierrc.jsonthat changes the indent size. To run these in CI,mise run test:bats:setupnow also installs .NET SDK 10.0.404 (added tomise.lock), andtest/builtins_tests.batsexportsDOTNET_ROOTas the real SDK directory behindmise where dotnet@10and puts it onPATH, because mise drops its own installs directory fromPATHwhen it runs a tool stub. The test fails with a clear message when no .NET SDK is installed. The csharpier cases also pass in the fullbuiltins tests runbats case. macOS and Windows were not tested.Requested in https://github.com/jdx/hk/discussions/1951.
AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: 2.1.332.
🤖 Generated with Claude Code
<!-- CURSOR_SUMMARY -->
---
<!-- /CURSOR_SUMMARY -->