DotNetAnalyzers / StyleCopAnalyzers

An implementation of StyleCop rules using the .NET Compiler Platform
MIT License
2.66k stars 507 forks source link

Incorrect indentation in SA1519 code fix #2183

Open sharwell opened 8 years ago

sharwell commented 8 years ago

The following code results in SA1519 getting reported:

using (default(IDisposable))
using (default(IDisposable))
{
}

When the code fix is applied, the output has the wrong indentation.

Expected

using (default(IDisposable))
{
    using (default(IDisposable))
    {
    }
}

Actual

using (default(IDisposable))
{
    using (default(IDisposable))
{
}
}

:memo: See #2181 for the pull request where this behavior was introduced.

CosminRadu commented 6 years ago

I would even suggest allowing multiple using statements without braces for each level, as this actually increases code readability.

sharwell commented 6 years ago

@CosminRadu The feature you describe is controlled by an option (which defaults to allowing the case you describe): https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/Configuration.md#consecutive-using-statements-without-braces

The bug only occurs when that setting is set to not allow consecutive using statements.