From 532d4855a2194852f7391e64ff6663743246757e Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 13 Mar 2026 17:33:49 +0100 Subject: [PATCH 1/4] Add skill for using `dotnet format whitespace` --- plugins/dotnet/skills/dotnet-format/SKILL.md | 85 ++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 plugins/dotnet/skills/dotnet-format/SKILL.md diff --git a/plugins/dotnet/skills/dotnet-format/SKILL.md b/plugins/dotnet/skills/dotnet-format/SKILL.md new file mode 100644 index 0000000000..6feb1c650c --- /dev/null +++ b/plugins/dotnet/skills/dotnet-format/SKILL.md @@ -0,0 +1,85 @@ +--- +name: dotnet-format +description: > + Format C#/.NET source files using the dotnet-format whitespace formatter. + USE FOR: quickly fixing whitespace and indentation in one or more files after + code generation or editing, batch-formatting changed files before a commit. + DO NOT USE FOR: enforcing code-style analyzers (SA/IDE rules), fixing + non-whitespace style issues, or formatting entire large repositories at once. +--- + +# dotnet format (whitespace) + +`dotnet format whitespace` reformats indentation, trailing whitespace, and line endings in C#/VB files without applying analyzer or code-style fixes. It is the fastest `dotnet format` sub-command because it operates on syntax only and does not need to load the full workspace. It is also the safest because it never changes semantics. + +## When to Use + +- Fixing indentation or trailing whitespace in files you just created or edited +- Batch-formatting a set of changed files before committing +- Cleaning up generated code that has inconsistent whitespace + +## When Not to Use + +- You need code-style fixes (naming, `var` vs explicit type, etc.) — use `dotnet format style` instead +- You need analyzer-driven fixes (e.g., SA1200) — use `dotnet format analyzers` instead + +## Workflow + +### Step 1: Determine files to format + +Identify the file paths that need formatting — typically files that were just created or edited. + +### Step 2: Run `dotnet format whitespace` + +Use `--folder` mode to format without needing a project/solution file: + +```bash +# Format everything under the current directory +dotnet format whitespace --folder . + +# Format only specific files +dotnet format whitespace --folder . --include path/to/File1.cs --include path/to/File2.cs +``` + +Key flags: + +Always use `--folder` — without it, the tool loads the full MSBuild workspace which is much slower and unnecessary for whitespace-only formatting. + +| Flag | Purpose | +|------|---------| +| `--folder` | Treats the argument as a plain directory — avoids loading the full workspace | +| `--include ` | Restricts formatting to the specified file(s); repeat for multiple files. Optional — omit to format all files in the folder | +| `--verify-no-changes` | Exits non-zero if any file would change (useful for CI checks) | + +Multiple files example: + +```bash +dotnet format whitespace --folder . \ + --include src/Models/User.cs \ + --include src/Services/AuthService.cs \ + --include tests/AuthTests.cs +``` + +### Step 3: Verify the result + +Review the formatted files to confirm only whitespace changed. If you need to verify programmatically: + +```bash +dotnet format whitespace --folder . --include path/to/File.cs --verify-no-changes +``` + +A zero exit code means the file is already correctly formatted. + +## Validation + +- [ ] `dotnet format whitespace` exits with code 0 +- [ ] Only whitespace/indentation changed — no semantic modifications +- [ ] Formatted files still compile successfully + +## Common Pitfalls + +| Pitfall | Solution | +|---------|----------| +| Running without `--folder` | Loads the full MSBuild workspace, which is slow and unnecessary for whitespace formatting. Always use `--folder .` | +| Formatting the entire repo unintentionally | Pass `--include` with specific file paths when you only want to format a subset | +| `.editorconfig` not found | `dotnet format` inherits `.editorconfig` settings; ensure one exists in a parent directory for consistent results | From 6eee56a37d6c460b8ace3e92229f5917cf2b196a Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 13 Mar 2026 20:29:27 +0100 Subject: [PATCH 2/4] Improve wording Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- plugins/dotnet/skills/dotnet-format/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dotnet/skills/dotnet-format/SKILL.md b/plugins/dotnet/skills/dotnet-format/SKILL.md index 6feb1c650c..59d9c64b75 100644 --- a/plugins/dotnet/skills/dotnet-format/SKILL.md +++ b/plugins/dotnet/skills/dotnet-format/SKILL.md @@ -10,7 +10,7 @@ description: > # dotnet format (whitespace) -`dotnet format whitespace` reformats indentation, trailing whitespace, and line endings in C#/VB files without applying analyzer or code-style fixes. It is the fastest `dotnet format` sub-command because it operates on syntax only and does not need to load the full workspace. It is also the safest because it never changes semantics. +`dotnet format whitespace` reformats indentation, trailing whitespace, and line endings in C#/VB files without applying analyzer or code-style fixes. When used with `--folder`, it is the fastest `dotnet format` sub-command because in that mode it operates on syntax only and does not need to load the full MSBuild workspace; when run against a project or solution it still loads the workspace. It is also the safest because it never changes semantics. ## When to Use From 41b3703eefd7fa53461eca4765cf86218fd7e28d Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 13 Mar 2026 20:33:42 +0100 Subject: [PATCH 3/4] Improve wording Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- plugins/dotnet/skills/dotnet-format/SKILL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dotnet/skills/dotnet-format/SKILL.md b/plugins/dotnet/skills/dotnet-format/SKILL.md index 59d9c64b75..b4458273a5 100644 --- a/plugins/dotnet/skills/dotnet-format/SKILL.md +++ b/plugins/dotnet/skills/dotnet-format/SKILL.md @@ -1,7 +1,7 @@ --- name: dotnet-format description: > - Format C#/.NET source files using the dotnet-format whitespace formatter. + Format C#/.NET source files using the `dotnet format whitespace` subcommand. USE FOR: quickly fixing whitespace and indentation in one or more files after code generation or editing, batch-formatting changed files before a commit. DO NOT USE FOR: enforcing code-style analyzers (SA/IDE rules), fixing From 0e9cdd34aa624fd40cc24755b9a89492550074f0 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 20 Mar 2026 13:42:41 +0100 Subject: [PATCH 4/4] Add eval for dotnet-format skill Add two evaluation scenarios: - Format specific files after editing (tests --folder + --include usage) - Verify formatting without modifying files (tests --verify-no-changes) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/dotnet/dotnet-format/eval.yaml | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/dotnet/dotnet-format/eval.yaml diff --git a/tests/dotnet/dotnet-format/eval.yaml b/tests/dotnet/dotnet-format/eval.yaml new file mode 100644 index 0000000000..f44caab42b --- /dev/null +++ b/tests/dotnet/dotnet-format/eval.yaml @@ -0,0 +1,37 @@ +scenarios: + - name: "Format specific files after editing" + prompt: | + I just refactored two C# files and the indentation is all messed up: + - src/Services/OrderService.cs + - src/Models/Order.cs + + I don't have a solution file in the current directory. Can you fix the whitespace formatting? + assertions: + - type: "output_contains" + value: "dotnet format whitespace" + - type: "output_contains" + value: "--folder" + - type: "output_matches" + pattern: "--include" + rubric: + - "Uses `dotnet format whitespace` specifically, not `dotnet format` without a subcommand or `dotnet format style`" + - "Uses --folder mode to avoid loading the MSBuild workspace" + - "Uses --include to target the specific files rather than formatting the entire directory" + timeout: 120 + + - name: "Verify whitespace formatting without modifying files" + prompt: | + I just ran `dotnet format whitespace` on some files in my repo but I want to + double-check that `src/Services/PaymentService.cs` is now correctly formatted. + Can you verify the formatting without modifying the file? I don't have a .sln + file in this directory. + assertions: + - type: "output_contains" + value: "dotnet format whitespace" + - type: "output_contains" + value: "--verify-no-changes" + rubric: + - "Uses `dotnet format whitespace` with `--verify-no-changes` to verify without modifying the file" + - "Uses --folder mode since there is no solution file available" + - "Uses --include to target the specific file rather than checking the entire directory" + timeout: 120