Cleanup

Curb formats from syntax alone — no workspace, no compilation. That is what lets it run inside dotnet build before the compiler runs. Semantic code style is out of that scope: whether a using directive is unused, or a field is only ever assigned in a constructor, is a question only a compilation can answer.

curb cleanup closes part of that gap. The compiler decides whether a rule applies and writes the answer to a SARIF log. curb cleanup reads that log and applies the rewrite. No CSharpCompilation, no SemanticModel, no Workspaces.

Shell
dotnet build
curb cleanup
dotnet build
  1. fails, or warns, on the rules you escalated
  2. fixes the ones Curb owns
  3. clean

curb sets $(ErrorLog) to $(IntermediateOutputPath)curb.sarif when the project has not set one, so the log exists without anyone asking for it. curb cleanup with no arguments searches the current directory for those logs.

Flag What it does
-s, --sarif-log <path> Name a specific log file, instead of searching for one. Repeatable.
-f, --files <path> Restrict cleanup to these files. Repeatable.
--check Report what would change without writing.
--forward Hand the remainder to dotnet format style after cleanup finishes.
curb rules List every rule and which tool fixes it.

The third build is the verify step you were going to run after any change anyway. A bad fix is a compile error you see immediately.

Mechanism Effect
dotnet_diagnostic.IDEnnnn.severity = none, or not setting it The build never reports it, so cleanup never sees it.
#pragma warning disable IDEnnnn The compiler suppresses it before it reaches the log.
generated_code = true, <auto-generated> Reused from the formatter via FormatOptions.Excluded.
Curb_Diagnostics=false The MSBuild package stops setting $(ErrorLog).
Curb_Bypass=true Everything, formatter included.
A $(ErrorLog) the project already set Curb stands down and never overwrites it.

Three layers keep applying a verdict from a previous build safe:

  1. The node-kind gate. Every fixer declares the syntax it applies to, and the reported position must resolve to it. A diagnostic pointing at a using directive that is no longer there simply does not apply.
  2. The freshness gate. A file whose last-write time is newer than the log is skipped. A span is an offset into the bytes the compiler read; applying it to different bytes is how a tool corrupts source.
  3. The declared-delta verifiers, unchanged from the formatter. A fix says which tokens it removes; ContentVerifier and TokenStreamComparer hold the rest of the file to a strict compare.

Overlapping fixes drop both, never one. Dropping both means a second pass sees the same overlap and drops it again, so the output is a fixed point.

A multi-targeted project writes one log per target framework, so a site every framework agrees on is reported once per log. Each site is fixed once: repeats are folded across logs, and a diagnostic asking for exactly the edits another already asked for counts as fixed without editing again.

Each target framework compiles a file separately and reaches its own verdict, and they do not always match. net10.0 reports using MyCompat; unnecessary (IDE0005) because string.Contains(char) exists there, while netstandard2.0 needs the directive for the extension method that fills the gap. Removing it would break the netstandard2.0 build. A LangVersion or Nullable that differs by framework does the same to IDE0090, IDE0034 or IDE0240.

So a site (rule, file, start and end) is fixed only when every compilation that read the file reported it. Otherwise it is declined, counted under refused, and printed with which frameworks reported it and which did not:

Text
src/Lib/Tags.cs: IDE0005: reported for net10.0 but not for netstandard2.0, which compiles this file too, so fixing it could break that build

Sites are compared exactly. If two frameworks report IDE0005 runs of different lengths over the same directives, those are two different sites, and both are declined.

A compilation read a file when:

  1. its log reported anything at all in the file, any rule at any severity; or
  2. its compile list names the file. The MSBuild package writes curb.files, the project's @(Compile), beside each curb.sarif; or
  3. it has no compile list and is the same project built for another framework. Logs are grouped by the target framework directory in their path: obj/Debug/net10.0/ and obj/Debug/netstandard2.0/ are one project's two frameworks.

The third rule is the cautious one. A log that says nothing about a file may have compiled it and found nothing to report, or may never have seen it, as with a Compile item that has a framework condition. Without a compile list the two cases look the same, so Curb assumes the framework compiled the file and declines. With the list, a file only one framework compiles keeps its fixes.

A single-target project, or a log whose path has no target framework directory, forms a group of its own, so it behaves exactly as before. In a console build log the frameworks come from MSBuild's [project.csproj::TargetFramework=net10.0] suffix. A framework that printed nothing at all for the project cannot be seen there, which is one more reason SARIF is the primary format. An edit never joins two tokens into one; where a replacement would leave var touching the name after it, a space goes between them.

curb rules is the live answer. Ten rules today: IDE0005, IDE0007, IDE0034, IDE0040, IDE0044, IDE0071, IDE0090, IDE0240, IDE0250, IDE0251.

Roslyn emits one IDE0005 per maximal contiguous run of unnecessary directives. The span is a delete instruction. The rule refuses any file containing #if: the compiler decided for one symbol set, and a directive needed only under another would be reported as unnecessary and then lost.

Rule Why
IDE0008 use explicit type The diagnostic does not carry the type name, so the fix is not derivable from the span.
IDE0051 / IDE0052 unused members The fix deletes a declaration. Curb never destroys code.
IDE1006 / IDE0130 naming A rename touches every reference site, can compile while changing which overload binds, and breaks reflection and serialisation strings. Never.
IDE0160 block namespace Curb converts to file-scoped and never back; removing braces can change what a name resolves to.
Rule Fix If the verdict were wrong
IDE0040 accessibility Writes out the accessibility C# already applied Nothing changes; the keyword was already in force.
IDE0044 readonly Inserts readonly into a field's modifier list A compile error — a write through ref or Interlocked the analyser missed.
IDE0090 new() Drops the type name after new A compile error: if the target type were not known, new() is an error.
IDE0007 var Replaces a local's type with var Silent. It compiles and may narrow the declared type. The only rule whose mistake is quiet; built last and leans hardest on the freshness gate.
IDE0250 readonly struct Inserts readonly on a struct Does not compile if some member mutates.
IDE0251 readonly member Inserts readonly on a struct member Does not compile if the member mutates.
IDE0034 simplify default Drops (T) from default(T) A bare default with no inferable target is an error.
IDE0071 simplify interpolation Drops a redundant .ToString() Refused when the call takes arguments, to avoid silently losing the format.
IDE0240 redundant #nullable Removes the directive's line Verified by ContentVerifier rather than TokenStreamComparer, since trivia is not in the token stream.

Curb is not a replacement for dotnet format style. With --forward, it names the remaining diagnostics exactly and hands them to dotnet format:

Text
Cleaned 1 file(s) from 1 log(s) in 105ms — 2 fix(es) in 1 file(s), 0 refused, 0 stale, 0 skipped, 0 failed
  forwarding 1 rule(s) in 1 file(s) to `dotnet format style`: IDE0071
  curb 105ms · dotnet format 2366ms (22.5x) — the difference is the workspace load, which no amount of scoping avoids

Both timings are printed because the difference is the point. Nothing else tells you which half of the wait belongs to which tool.