The pattern book
Indentation
Indent style
Section titled “Indent style”indent_style = spaceSelects tabs or spaces for indentation written by layout rules.
- Values:
spacetab - Default:
space - Applies to: File representation or shared layout settings.
- Guarantee: The configured value is applied by its owning formatter stage.
- Shown with:
csharp_indent_block_contents = true
class Example{ string Text = "DressSharp";}Code unchanged.
class Example{ string Text = "DressSharp"; string Text = "DressSharp";}Indent size
Section titled “Indent size”indent_size = 4Sets indentation width, or follows tab_width when set to tab.
- Values:
positive integertab - Default:
4 - Applies to: File representation or shared layout settings.
- Guarantee: The configured value is applied by its owning formatter stage.
- Shown with:
indent_style = space,csharp_indent_block_contents = true
class Example{ string Text = "DressSharp";}Code unchanged.
class Example{ string Text = "DressSharp"; string Text = "DressSharp";}class Example{ string Text = "DressSharp"; string Text = "DressSharp";}class Example{ string Text = "DressSharp"; string Text = "DressSharp";}Code unchanged.
Tab width
Section titled “Tab width”tab_width = 4Sets the display width used for tab indentation.
- Values:
positive integer - Default:
4 - Applies to: File representation or shared layout settings.
- Guarantee: The configured value is applied by its owning formatter stage.
- Shown with:
indent_style = space,indent_size = tab,csharp_indent_block_contents = true
class Example{ string Text = "DressSharp";}Code unchanged.
class Example{ string Text = "DressSharp"; string Text = "DressSharp";}class Example{ string Text = "DressSharp"; string Text = "DressSharp";}class Example{ string Text = "DressSharp"; string Text = "DressSharp";}Indent labels
Section titled “Indent labels”csharp_indent_labels = one_less_than_currentControls syntax indentation. Only indentation whitespace changes.
- Values:
flush_leftno_changeone_less_than_current - Default:
one_less_than_current - Applies to: Syntax indentation.
- Guarantee: Only indentation whitespace changes.
class Example{ void Run() { label: Work(); }}class Example{ void Run() { label:label: Work(); }}class Example{ void Run() { label:label: Work(); }}Code unchanged.
Indent block contents
Section titled “Indent block contents”csharp_indent_block_contents = trueControls syntax indentation. Only indentation whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Syntax indentation.
- Guarantee: Only indentation whitespace changes.
if (ready){Work();}if (ready){Work(); Work();}Code unchanged.
Indent braces
Section titled “Indent braces”csharp_indent_braces = falseControls syntax indentation. Only indentation whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Syntax indentation.
- Guarantee: Only indentation whitespace changes.
- Shown with:
csharp_indent_block_contents = true
if (ready){ Work();}Code unchanged.
if (ready){ Work();} { Work(); }Switch expression indentation
Section titled “Switch expression indentation”dress_switch_expression_indentation = indentedIndents multiline switch expression braces one level from the line containing switch, or aligns them with that line. Overrides csharp_indent_braces for switch expressions; arms follow csharp_indent_block_contents.
- Values:
indentednot_indented - Default:
indented - Applies to: Multiline switch expression braces.
- Guarantee: Only indentation whitespace changes.
var value = input switch { true => 1, false => 0 };Code unchanged.
var value = input switch {{ true => 1, false => 0 };};Lambda block indentation
Section titled “Lambda block indentation”dress_lambda_block_indentation = indentedIndents multiline lambda block braces one level from the lambda’s starting line, or aligns them with that line. Overrides csharp_indent_braces for lambda blocks; contents follow csharp_indent_block_contents.
- Values:
indentednot_indented - Default:
indented - Applies to: Multiline lambda block braces.
- Guarantee: Only indentation whitespace changes.
var callback = () =>{ Work(); return true;};var callback = () =>{ { Work(); return true;}; };Code unchanged.
Switch statements
Section titled “Switch statements”Indent case contents
Section titled “Indent case contents”csharp_indent_case_contents = trueControls syntax indentation. Only indentation whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Syntax indentation.
- Guarantee: Only indentation whitespace changes.
- Shown with:
csharp_indent_switch_labels = true
switch (value){ case 1: Work(); break;}switch (value){ case 1: Work(); break; Work(); break;}Code unchanged.
Indent switch labels
Section titled “Indent switch labels”csharp_indent_switch_labels = trueControls syntax indentation. Only indentation whitespace changes.
- Values:
truefalse - Default:
true - Applies to: Syntax indentation.
- Guarantee: Only indentation whitespace changes.
- Shown with:
csharp_indent_case_contents = true
switch (value){case 1: Work(); break;}switch (value){case 1: Work(); break; case 1: Work(); break;}Code unchanged.
Indent case contents when block
Section titled “Indent case contents when block”csharp_indent_case_contents_when_block = falseControls syntax indentation. Only indentation whitespace changes.
- Values:
truefalse - Default:
false - Applies to: Syntax indentation.
- Guarantee: Only indentation whitespace changes.
- Shown with:
csharp_indent_switch_labels = true,csharp_indent_block_contents = true
switch (value){ case 1: { Work(); break; }}Code unchanged.
switch (value){ case 1: { Work(); break; } { Work(); break; }}Initializers and collections
Section titled “Initializers and collections”Object initializer indentation
Section titled “Object initializer indentation”dress_object_initializer_indentation = indentedControls multiline non-empty initializer delimiters. Only delimiter indentation changes.
- Values:
indentednot_indented - Default:
indented - Applies to: Multiline non-empty initializer delimiters.
- Guarantee: Only delimiter indentation changes.
class Example{ object Value = new Example { Number = 1 }; int Number { get; set; }}class Example{ object Value = new Example { { Number = 1 }; }; int Number { get; set; }}Code unchanged.
Collection initializer indentation
Section titled “Collection initializer indentation”dress_collection_initializer_indentation = indentedControls multiline non-empty initializer delimiters. Only delimiter indentation changes.
- Values:
indentednot_indented - Default:
indented - Applies to: Multiline non-empty initializer delimiters.
- Guarantee: Only delimiter indentation changes.
var values = new List<int>{ 1, 2};var values = new List<int>{ { 1, 2}; };Code unchanged.
Array initializer indentation
Section titled “Array initializer indentation”dress_array_initializer_indentation = indentedControls multiline non-empty initializer delimiters. Only delimiter indentation changes.
- Values:
indentednot_indented - Default:
indented - Applies to: Multiline non-empty initializer delimiters.
- Guarantee: Only delimiter indentation changes.
var values = new[]{ 1, 2};var values = new[]{ { 1, 2}; };Code unchanged.
With initializer indentation
Section titled “With initializer indentation”dress_with_initializer_indentation = indentedControls multiline non-empty initializer delimiters. Only delimiter indentation changes.
- Values:
indentednot_indented - Default:
indented - Applies to: Multiline non-empty initializer delimiters.
- Guarantee: Only delimiter indentation changes.
var value = original with{ First = 1, Second = 2};var value = original with{ { First = 1, Second = 2}; };Code unchanged.
Collection expression indentation
Section titled “Collection expression indentation”dress_collection_expression_indentation = indentedControls multiline non-empty collection expression delimiters outside arguments, including assignments and returns.
- Values:
indentednot_indented - Default:
indented - Applies to: Multiline non-empty initializer delimiters.
- Guarantee: Only delimiter indentation changes.
class Example{ string[] Values = [ "first", "second" ];}class Example{ string[] Values = [ [ "first", "second" ]; ];}Code unchanged.
Collection expression argument indentation
Section titled “Collection expression argument indentation”dress_collection_expression_argument_indentation = not_indentedControls multiline non-empty collection expression delimiters when the expression is an argument, including named arguments.
- Values:
indentednot_indented - Default:
not_indented - Applies to: Multiline non-empty initializer delimiters.
- Guarantee: Only delimiter indentation changes.
class Example{ void M() => Process( [ "first", "second" ]);}Code unchanged.
class Example{ void M() => Process( [ [ "first", "second" ]); ]);}