Skip to main content

Ignoring Code

Use .csharpierignore to bypass formatting specific files and folders.

Use csharpier-ignore comments to bypass formatting specific parts of files.

Ignoring Files .csharpierignore

Add a .csharpierignore file to ignore additional files and folders. The file uses gitignore syntax

Example

Uploads/
**/App_Data/*.cs

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

Node Module Files

  • Any file that matches the gitignore syntax **/node_modules/**/*.cs

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