-
Notifications
You must be signed in to change notification settings - Fork 371
Add skill for using dotnet format whitespace
#358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| name: dotnet-format | ||
| description: > | ||
| 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 | ||
| 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. 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 | ||
|
|
||
| - 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 <path>` | 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) | | ||
|
jjonescz marked this conversation as resolved.
|
||
|
|
||
| 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 .` | | ||
|
jjonescz marked this conversation as resolved.
|
||
| | 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 | | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: | ||
|
Comment on lines
+9
to
+16
|
||
| - "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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This skill adds a new
plugins/dotnet/skills/dotnet-formatentry, but the dotnet plugin README’s skill list doesn’t includedotnet-format(it currently lists onlycsharp-scripts,dotnet-pinvoke, andnuget-trusted-publishing). Please updateplugins/dotnet/README.mdto keep the published skill inventory accurate.This issue also appears on line 15 of the same file.