You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Any file that begins with ```TemporaryGeneratedFile_```
4
+
- Any file that ends with ```.designer.cs```
5
+
- Any file that ends with ```.generated.cs```
6
+
- Any file that ends with ```.g.cs```
7
+
- Any file that ends with ```.g.i.cs```
8
+
- Any file that begins with a comment that contains ```<autogenerated``` or ```<auto-generated```
9
+
10
+
Add a ```.csharpierignore``` file to ignore additional files and folders. The file uses [gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format)
CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules. The printing process was ported from [prettier](https://github.com/prettier/prettier) but has evolved over time.
2
+
CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.
3
+
The printing process was ported from [prettier](https://github.com/prettier/prettier) but has evolved over time.
4
+
CSharpier provides a few basic options that affect formatting and has no plans to add more. It follows the [Option Philosophy](https://prettier.io/docs/en/option-philosophy.html) of prettier
By default csharpier will validate any files it formats by comparing the resulting syntax tree to the original.
61
-
Formatting will take longer, but csharpier will validate the formatted syntax tree against the original and warn if it believes it introduced breaking changes.
62
-
63
63
Run csharpier from the directory you wish to format.
64
64
```console
65
65
dotnet csharpier
66
66
```
67
67
68
-
## Configuration
69
-
CSharpier has support for a configuration file. You can use any of the following files
70
-
- A ```.csharpierrc``` file in JSON or YAML.
71
-
- A ```.csharpierrc.json``` or ```.csharpierrc.yaml``` file.
72
-
73
-
### Configuration Options
74
-
JSON
75
-
```json
76
-
{
77
-
"printWidth": 100,
78
-
"useTabs": false,
79
-
"tabWidth": 4,
80
-
"endOfLine": "auto"
81
-
}
82
-
```
83
-
YAML
84
-
```json
85
-
printWidth: 100
86
-
useTabs: false
87
-
tabWidth: 4
88
-
endOfLine: auto
89
-
```
90
-
91
-
#### Print Width
92
-
Specify at what point the printer will wrap content. This is not a hard limit. Some lines will be shorter or longer.
93
-
94
-
Default 100
95
-
#### Use Tabs
96
-
Indent lines with tabs instead of spaces.
97
-
98
-
Default false
99
-
#### Tab Width
100
-
Specify the number of spaces used per indentation level.
101
-
102
-
Default 4
103
-
#### End of Line
104
-
Specify what type of line endings will be printed in files.
105
-
Options
106
-
- "auto" - Detects which type of line ending to used based on the first one it encounters in the file **Default**
107
-
- "lf" - Line feed only (\n)
108
-
- "crlf" Carriage return and line feed (\r\n)
109
-
110
-
### Ignoring Files
111
-
Csharpier will ignore the following files
112
-
- Any file that begins with ```TemporaryGeneratedFile_```
113
-
- Any file that ends with ```.designer.cs```
114
-
- Any file that ends with ```.generated.cs```
115
-
- Any file that ends with ```.g.cs```
116
-
- Any file that ends with ```.g.i.cs```
117
-
- Any file that begins with a comment that contains ```<autogenerated``` or ```<auto-generated```
118
-
119
-
Add a ```.csharpierignore``` file to ignore additional files and folders. The file uses [gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format)
120
-
121
-
Example
122
-
```
123
-
Uploads/
124
-
**/App_Data/*.cs
125
-
```
126
-
127
-
### Command Line Options
128
-
```console
129
-
Usage:
130
-
dotnet-csharpier [options] [<directoryOrFile>]
131
-
132
-
Arguments:
133
-
<directoryOrFile> A path to a directory containing files to format or a file to format. If a path is not specified the current directory is used
134
-
135
-
Options:
136
-
--check Check that files are formatted. Will not write any changes.
137
-
--fast Skip comparing syntax tree of formatted file to original file to validate changes.
138
-
--skip-write Skip writing changes. Generally used for testing to ensure csharpier doesn't throw any errors or cause syntax tree validation failures.
139
-
--version Show version information
140
-
-?, -h, --help Show help and usage information
141
-
142
-
143
-
```
144
-
145
-
### \<directoryOrFile\>
146
-
Currently CSharpier only supports being passed a directory to recursively scan for .cs files or a single file to format.
147
-
If a directory is not supplied, it will use the current directory.
148
-
149
-
### --check
150
-
Used to check if your files are already formatted. Outputs any files that have not already been formatted.
151
-
This will return exit code 1 if there are unformatted files which is useful for CI pipelines.
152
-
153
-
### --fast
154
-
CSharpier validates the changes it makes to a file.
155
-
It does this by comparing the syntax tree before and after formatting, but ignoring any whitespace trivia in the syntax tree.
156
-
If a file fails validation, CSharpier will output the lines that differ. If this happens it indicates a bug in CSharpier's code.
157
-
This validation may be skipped by passing the --fast argument. Validation appears to increase the formatting time by ~50%.
158
-
159
-
An example of CSharpier finding a file that failed validation.
160
-
```
161
-
\src\[Snip]\AbstractReferenceFinder_GlobalSuppressions.cs - failed syntax tree validation
162
-
Original: Around Line 280
163
-
}
164
-
165
-
if (prefix.Span[^2] is < 'A' or > 'Z')
166
-
{
167
-
return false;
168
-
}
169
-
170
-
if (prefix.Span[^1] is not ':')
171
-
Formatted: Around Line 330
172
-
}
173
-
174
-
if (prefix.Span[^2] is )
175
-
{
176
-
return false;
177
-
}
178
-
179
-
if (prefix.Span[^1] is not ':')
180
-
```
181
-
182
-
## More Documentation
183
-
[Editors and CI/CD](Docs/EditorsAndCICD.md)
68
+
## Documentation
69
+
[Command Line Interface](Docs/CLI.md)
70
+
[Configuration File](Docs/Configure.md)
71
+
[Editors and CI/CD](Docs/EditorsAndCICD.md)
72
+
[Ignoring Files](Docs/Ignore.md)
73
+
[ChangeLog](CHANGELOG.md)
184
74
185
75
## Contributing
186
76
See [Development Readme](CONTRIBUTING.md)
187
77
188
78
Join Us [](https://discord.gg/HfAKGEZQcX)
0 commit comments