Skip to content

The pattern book

Indentation

indent_style = space

Selects tabs or spaces for indentation written by layout rules.

  • Values: space tab
  • 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
Input
class Example
{
string Text = "DressSharp";
}

Code unchanged.

indent_size = 4

Sets indentation width, or follows tab_width when set to tab.

  • Values: positive integer tab
  • 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
Input
class Example
{
string Text = "DressSharp";
}

Code unchanged.

tab_width = 4

Sets 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
Input
class Example
{
string Text = "DressSharp";
}

Code unchanged.

csharp_indent_labels = one_less_than_current

Controls syntax indentation. Only indentation whitespace changes.

  • Values: flush_left no_change one_less_than_current
  • Default: one_less_than_current
  • Applies to: Syntax indentation.
  • Guarantee: Only indentation whitespace changes.
Input
class Example
{
void Run()
{
label:
Work();
}
}
class Example
{
void Run()
{
label:
label:
Work();
}
}
csharp_indent_block_contents = true

Controls syntax indentation. Only indentation whitespace changes.

  • Values: true false
  • Default: true
  • Applies to: Syntax indentation.
  • Guarantee: Only indentation whitespace changes.
Input
if (ready)
{
Work();
}
if (ready)
{
Work();
Work();
}
csharp_indent_braces = false

Controls syntax indentation. Only indentation whitespace changes.

  • Values: true false
  • Default: false
  • Applies to: Syntax indentation.
  • Guarantee: Only indentation whitespace changes.
  • Shown with: csharp_indent_block_contents = true
Input
if (ready)
{
Work();
}

Code unchanged.

dress_switch_expression_indentation = indented

Indents 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: indented not_indented
  • Default: indented
  • Applies to: Multiline switch expression braces.
  • Guarantee: Only indentation whitespace changes.
Input
var value = input switch
{
true => 1,
false => 0
};

Code unchanged.

dress_lambda_block_indentation = indented

Indents 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: indented not_indented
  • Default: indented
  • Applies to: Multiline lambda block braces.
  • Guarantee: Only indentation whitespace changes.
Input
var callback = () =>
{
Work();
return true;
};
var callback = () =>
{
{
Work();
return true;
};
};
csharp_indent_case_contents = true

Controls syntax indentation. Only indentation whitespace changes.

  • Values: true false
  • Default: true
  • Applies to: Syntax indentation.
  • Guarantee: Only indentation whitespace changes.
  • Shown with: csharp_indent_switch_labels = true
Input
switch (value)
{
case 1:
Work();
break;
}
switch (value)
{
case 1:
Work();
break;
Work();
break;
}
csharp_indent_switch_labels = true

Controls syntax indentation. Only indentation whitespace changes.

  • Values: true false
  • Default: true
  • Applies to: Syntax indentation.
  • Guarantee: Only indentation whitespace changes.
  • Shown with: csharp_indent_case_contents = true
Input
switch (value)
{
case 1:
Work();
break;
}
switch (value)
{
case 1:
Work();
break;
case 1:
Work();
break;
}
csharp_indent_case_contents_when_block = false

Controls syntax indentation. Only indentation whitespace changes.

  • Values: true false
  • Default: false
  • Applies to: Syntax indentation.
  • Guarantee: Only indentation whitespace changes.
  • Shown with: csharp_indent_switch_labels = true, csharp_indent_block_contents = true
Input
switch (value)
{
case 1:
{
Work();
break;
}
}

Code unchanged.

dress_object_initializer_indentation = indented

Controls multiline non-empty initializer delimiters. Only delimiter indentation changes.

  • Values: indented not_indented
  • Default: indented
  • Applies to: Multiline non-empty initializer delimiters.
  • Guarantee: Only delimiter indentation changes.
Input
class Example
{
object Value = new Example
{
Number = 1
};
int Number { get; set; }
}
class Example
{
object Value = new Example
{
{
Number = 1
};
};
int Number { get; set; }
}
dress_collection_initializer_indentation = indented

Controls multiline non-empty initializer delimiters. Only delimiter indentation changes.

  • Values: indented not_indented
  • Default: indented
  • Applies to: Multiline non-empty initializer delimiters.
  • Guarantee: Only delimiter indentation changes.
Input
var values = new List<int>
{
1,
2
};
var values = new List<int>
{
{
1,
2
};
};
dress_array_initializer_indentation = indented

Controls multiline non-empty initializer delimiters. Only delimiter indentation changes.

  • Values: indented not_indented
  • Default: indented
  • Applies to: Multiline non-empty initializer delimiters.
  • Guarantee: Only delimiter indentation changes.
Input
var values = new[]
{
1,
2
};
var values = new[]
{
{
1,
2
};
};
dress_with_initializer_indentation = indented

Controls multiline non-empty initializer delimiters. Only delimiter indentation changes.

  • Values: indented not_indented
  • Default: indented
  • Applies to: Multiline non-empty initializer delimiters.
  • Guarantee: Only delimiter indentation changes.
Input
var value = original with
{
First = 1,
Second = 2
};
var value = original with
{
{
First = 1,
Second = 2
};
};
dress_collection_expression_indentation = indented

Controls multiline non-empty collection expression delimiters outside arguments, including assignments and returns.

  • Values: indented not_indented
  • Default: indented
  • Applies to: Multiline non-empty initializer delimiters.
  • Guarantee: Only delimiter indentation changes.
Input
class Example
{
string[] Values =
[
"first",
"second"
];
}
class Example
{
string[] Values =
[
[
"first",
"second"
];
];
}

Collection expression argument indentation

Section titled “Collection expression argument indentation”
dress_collection_expression_argument_indentation = not_indented

Controls multiline non-empty collection expression delimiters when the expression is an argument, including named arguments.

  • Values: indented not_indented
  • Default: not_indented
  • Applies to: Multiline non-empty initializer delimiters.
  • Guarantee: Only delimiter indentation changes.
Input
class Example
{
void M() => Process(
[
"first",
"second"
]);
}

Code unchanged.