Skip to content

Commit 4134976

Browse files
committed
Update dotnet format documentation for clarity and accuracy
1 parent ad0e164 commit 4134976

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

docs/core/tools/dotnet-format.md

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: dotnet format command
33
description: The dotnet format command formats code to match EditorConfig settings for the current directory.
4-
ms.date: 07/12/2021
4+
ms.date: 09/29/2025
55
---
66
# dotnet format
77

8-
**This article applies to:** ✔️ .NET 6.x SDK and later versions
8+
**This article applies to:** ✔️ .NET 6 and later versions
99

1010
## Name
1111

@@ -14,7 +14,7 @@ ms.date: 07/12/2021
1414
## Synopsis
1515

1616
```dotnetcli
17-
dotnet format [<PROJECT | SOLUTION>] [command] [options]
17+
dotnet format [<PROJECT | SOLUTION>] [--diagnostics <DIAGNOSTICS>] [--exclude-diagnostics <EXCLUDE-DIAGNOSTICS>] [--severity <SEVERITY>] [--no-restore] [--verify-no-changes] [--include <INCLUDE>] [--exclude <EXCLUDE>] [--include-generated] [-v|--verbosity <LEVEL>] [--binarylog <BINARY-LOG-PATH>] [--report <REPORT-PATH>] [--version]
1818
1919
dotnet format -h|--help
2020
```
@@ -33,49 +33,55 @@ The MSBuild project or solution to run code formatting on. If a project or solut
3333

3434
None of the options below are required for the `dotnet format` command to succeed, but you can use them to further customize what is formatted and by which rules.
3535

36-
* **`--diagnostics <DIAGNOSTICS>`**
36+
- **`--diagnostics <DIAGNOSTICS>`**
3737

3838
A space-separated list of diagnostic IDs to use as a filter when fixing code style or third-party issues. Default value is whichever IDs are listed in the *.editorconfig* file. For a list of built-in analyzer rule IDs that you can specify, see the [list of IDs for code-analysis style rules](../../fundamentals/code-analysis/style-rules/index.md).
3939

40-
* **`--severity`**
40+
- **`--exclude-diagnostics <EXCLUDE-DIAGNOSTICS>`**
41+
42+
A space-separated list of diagnostic IDs to exclude when fixing code style or third-party issues. Default value is none. For a list of built-in analyzer rule IDs that you can specify, see the [list of IDs for code-analysis style rules](../../fundamentals/code-analysis/style-rules/index.md).
43+
44+
- **`--severity`**
4145

4246
The minimum severity of diagnostics to fix. Allowed values are `info`, `warn`, and `error`. The default value is `warn`.
4347

44-
* **`--no-restore`**
48+
- **`--no-restore`**
4549

4650
Doesn't execute an implicit restore before formatting. Default is to do implicit restore.
4751

48-
* **`--verify-no-changes`**
52+
- **`--verify-no-changes`**
4953

5054
Verifies that no formatting changes would be performed. Terminates with a non zero exit code if any files would have been formatted.
5155

52-
* **`--include <INCLUDE>`**
56+
- **`--include <INCLUDE>`**
5357

5458
A space-separated list of relative file or folder paths to include in formatting. The default is all files in the solution or project.
5559

56-
* **`--exclude <EXCLUDE>`**
60+
- **`--exclude <EXCLUDE>`**
5761

5862
A space-separated list of relative file or folder paths to exclude from formatting. The default is none.
5963

60-
* **`--include-generated`**
64+
- **`--include-generated`**
6165

6266
Formats files generated by the SDK.
6367

64-
* **`-v|--verbosity <LEVEL>`**
68+
- **`-v|--verbosity <LEVEL>`**
6569

6670
Sets the verbosity level. Allowed values are `q[uiet]`, `m[inimal]`, `n[ormal]`, `d[etailed]`, and `diag[nostic]`. Default value is `m[inimal]`.
6771

68-
* **`--binarylog <BINARY-LOG-PATH>`**
72+
- **`--binarylog <BINARY-LOG-PATH>`**
6973

7074
Logs all project or solution load information to a binary log file.
7175

72-
* **`--report <REPORT-PATH>`**
76+
- **`--report <REPORT-PATH>`**
7377

7478
Produces a JSON report in the directory specified by `<REPORT_PATH>`.
7579

76-
* **`-h|--help`**
80+
- **`--version`**
81+
82+
Displays version information.
7783

78-
Shows help and usage information
84+
[!INCLUDE [help](../../../includes/cli-help.md)]
7985

8086
## Subcommands
8187

@@ -89,7 +95,7 @@ The `dotnet format whitespace` subcommand only runs formatting rules associated
8995

9096
#### Options
9197

92-
* **`--folder`**
98+
- **`--folder`**
9399

94100
Treat the `<PROJECT | SOLUTION>` argument as a path to a simple folder of code files.
95101

@@ -103,11 +109,11 @@ The `dotnet format style` subcommand only runs formatting rules associated with
103109

104110
#### Options
105111

106-
* **`--diagnostics <DIAGNOSTICS>`**
112+
- **`--diagnostics <DIAGNOSTICS>`**
107113

108114
A space-separated list of diagnostic IDs to use as a filter when fixing code style issues. Default value is whichever IDs are listed in the *.editorconfig* file. For a list of built-in code style analyzer rule IDs that you can specify, see the [list of IDs for code-analysis style rules](../../fundamentals/code-analysis/style-rules/index.md).
109115

110-
* **`--severity`**
116+
- **`--severity`**
111117

112118
The minimum severity of diagnostics to fix. Allowed values are `info`, `warn`, and `error`. The default value is `warn`
113119

@@ -121,59 +127,59 @@ The `dotnet format analyzers` subcommand only runs formatting rules associated w
121127

122128
##### Options
123129

124-
* **`--diagnostics <DIAGNOSTICS>`**
130+
- **`--diagnostics <DIAGNOSTICS>`**
125131

126132
A space-separated list of diagnostic IDs to use as a filter when fixing non code style issues. Default value is whichever IDs are listed in the *.editorconfig* file. For a list of built-in analyzer rule IDs that you can specify, see the [list of IDs for quality rules](../../fundamentals/code-analysis/quality-rules/index.md). For third-party analyzers refer to their documentation.
127133

128-
* **`--severity`**
134+
- **`--severity`**
129135

130136
The minimum severity of diagnostics to fix. Allowed values are `info`, `warn`, and `error`. The default value is `warn`.
131137

132138
## Examples
133139

134-
* Format all code in the solution:
140+
- Format all code in the solution:
135141

136142
```dotnetcli
137143
dotnet format ./solution.sln
138144
```
139145

140-
* Clean up all code in the application project:
146+
- Clean up all code in the application project:
141147

142148
```dotnetcli
143149
dotnet format ./src/application.csproj
144150
```
145151

146-
* Verify that all code is correctly formatted:
152+
- Verify that all code is correctly formatted:
147153

148154
```dotnetcli
149155
dotnet format --verify-no-changes
150156
```
151157

152-
* Clean up all code in the *src* and *tests* directory but not in *src/submodule-a*:
158+
- Clean up all code in the *src* and *tests* directory but not in *src/submodule-a*:
153159

154160
```dotnetcli
155161
dotnet format --include ./src/ ./tests/ --exclude ./src/submodule-a/
156162
```
157163

158-
* Fix a specific **code style** issue:
164+
- Fix a specific **code style** issue:
159165

160166
```dotnetcli
161167
dotnet format style --diagnostics IDE0005 --severity info
162168
```
163169

164-
* Fix all **code style** issues that have severity `info`, `warning` or `error`:
170+
- Fix all **code style** issues that have severity `info`, `warning` or `error`:
165171

166172
```dotnetcli
167173
dotnet format style --severity info
168174
```
169175

170-
* Fix a specific (non code style) analyzer issue:
176+
- Fix a specific (non code style) analyzer issue:
171177

172178
```dotnetcli
173179
dotnet format analyzers --diagnostics CA1831 --severity warn
174180
```
175181

176-
* Fix all non code style issues that have severity `info`, `warning` or `error`:
182+
- Fix all non code style issues that have severity `info`, `warning` or `error`:
177183

178184
```dotnetcli
179185
dotnet format analyzers --severity info

0 commit comments

Comments
 (0)