BRO1502: Chained blocks should not be preceded by a blank line¶
else, catch and finally directly follow the block they continue. Replaces StyleCop SA1510.
Example¶
Before¶
public class Gate
{
public string Open(bool allowed)
{
if (allowed)
{
return "open";
}
else
{
return "closed";
}
}
}
After¶
public class Gate
{
public string Open(bool allowed)
{
if (allowed)
{
return "open";
}
else
{
return "closed";
}
}
}
Why¶
A blank line before else makes it look like the start of a new statement instead of part of the if. The same goes
for catch and finally after try.
How the fix works¶
The fix removes the blank lines directly above the keyword. It also applies when the if has no braces.
Not reported¶
- A comment or directive directly above the keyword, for example a comment explaining the
elsebranch. - The
whileof ado … whileloop, like StyleCop.
Compared with StyleCop¶
Same results as StyleCop.