Ignoring Code
CSharpier supports
.csharpierignore
and.gitignore
to bypass formatting specific files and folders.csharpier-ignore
comments to bypass formatting specific parts of files.
Ignoring Files
Add a .csharpierignore
file to ignore additional files and folders. The file uses gitignore syntax
Example
Uploads/
**/App_Data/*.cs
.gitignore
Disabled for performance issues as of 1.0.1 see #1588
CSharpier will read the contents of .gitignore
files and use them in addition to a .csharpierignore
file to determine if a file should be ignored.
If a directory tree contains a .csharpierignore
file then patterns in that file will always take priority over any .gitignore
file in the same tree.
To enable formatting of a file that is ignored via a .gitignore
add a negated pattern.
# .gitignore
**/generated
# .csharpierignore
!**/generated
Files Ignored by Default
Csharpier will ignore the following files
SDK Generated Files
See Configuration for including these files
- Any file that begins with
TemporaryGeneratedFile_
- Any file that ends with
.designer.cs
- Any file that ends with
.generated.cs
- Any file that ends with
.g.cs
- Any file that ends with
.g.i.cs
- Any file that begins with a comment that contains
<autogenerated
or<auto-generated
Special Case Files
- Any file that matches the gitignore syntax
**/node_modules
**/obj
**/.git
Ignoring Code
Add a // csharpier-ignore
comment to exclude the next node from formatting. This is valid on statements and members.
// csharpier-ignore
public class Unformatted {
private string unformatted;
}
public class ClassName
{
// csharpier-ignore
private string unformatted;
// csharpier-ignore
public void MethodName( ) {
var unformatted = "";
}
public void MethodName()
{
// csharpier-ignore
var unformatted = true;
if (true)
{
// csharpier-ignore
var unformatted = true;
}
}
}
Use a ranged ignore to exclude multiple lines from formatting. A range is not valid in all contexts. Currently it works with statements, members and object initializer expressions.
// csharpier-ignore-start
public class Unformatted1 { }
public class Unformatted2 { }
// csharpier-ignore-end
public class ClassName
{
// csharpier-ignore-start
private string unformatted1;
private string unformatted2;
public void MethodName( ) {
var unformatted = "";
}
// csharpier-ignore-end
public void MethodName()
{
// csharpier-ignore-start
var unformatted1 = true;
var unformatted2 = true;
if (false) {
return;
}
// csharpier-ignore-end
if (true)
{
// csharpier-ignore-start
var unformatted3 = true;
var unformatted4 = true;
// csharpier-ignore-end
var formatted = true;
}
return new SomeClass
{
// csharpier-ignore-start
SomeProperty = true
// csharpier-ignore-end
}
}
As of 0.23.0 both types of ignores can include a description as part of the comment. The description must be seperated from the comment by at least one - character.
// csharpier-ignore - class copied as-is from another project
public class Unformatted {
private string unformatted;
}
// csharpier-ignore-start -- class copied as-is from another project
public class Unformatted1 { }
public class Unformatted2 { }
// csharpier-ignore-end