NoSpaceAfterBrace

NoSpaceAfterBrace

Summary

A brace (‘{’ or ‘}’) must be followed by a white space.

Default severity

Warning

Description

An opening brace (‘{’) that is not the last character on the line must be followed by a single space or a closing brace (‘}’).

A closing brace (‘}’) that is not the last character on the line must be followed by a single space, a closing parenthesis (‘)’), an opening bracket (‘[’), a comma (‘,’), a period (‘.’), an exclamation mark (‘!’), a question mark (‘?’), or a semicolon (‘;’).

Note that this analyzer and the NoSpaceBeforeBrace analyzer are intended to be used together and replace SA1012 and SA1013 with them, allowing us to write empty braces ({}) as follows:

Action doNothing = () => {};

if (maybeString is {} s)
{
    ⋮
}

Code fix

The code fix provides an option inserting a space after the brace.

Example

Diagnostic

string[] array = {"" };

Action doNothing = () => {return; };

if (array is {Length: 0 }z)
{
}

Code fix

string[] array = { "" };

Action doNothing = () => { return; };

if (array is { Length: 0 } z)
{
}