Skip to content

Commit

Permalink
Merge pull request #3245 from pantosha/fix-3240
Browse files Browse the repository at this point in the history
Update SA1413 to support with initializer
  • Loading branch information
sharwell authored Nov 20, 2020
2 parents a283433 + 610aa69 commit aa26bda
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,66 @@

namespace StyleCop.Analyzers.Test.CSharp9.MaintainabilityRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp8.MaintainabilityRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.MaintainabilityRules.SA1413UseTrailingCommasInMultiLineInitializers,
StyleCop.Analyzers.MaintainabilityRules.SA1413CodeFixProvider>;

public class SA1413CSharp9UnitTests : SA1413CSharp8UnitTests
{
[Fact]
[WorkItem(3240, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3240")]
public async Task VerifyWithInitializerAsync()
{
var testCode = @"namespace TestNamespace
{
public record R
{
public int A { get; set; }
public int B { get; set; }
void M()
{
_ = this with { A = 1, B = 2 };
_ = this with { A = 1, B = 2, };
_ = this with
{
A = 1,
[|B = 2|]
};
}
}
}
";
var fixedCode = @"namespace TestNamespace
{
public record R
{
public int A { get; set; }
public int B { get; set; }
void M()
{
_ = this with { A = 1, B = 2 };
_ = this with { A = 1, B = 2, };
_ = this with
{
A = 1,
B = 2,
};
}
}
}
";

await VerifyCSharpFixAsync(LanguageVersion.CSharp9, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal class SA1413UseTrailingCommasInMultiLineInitializers : DiagnosticAnalyz
private static readonly Action<SyntaxNodeAnalysisContext> HandleSwitchExpressionAction = HandleSwitchExpression;

private static readonly ImmutableArray<SyntaxKind> ObjectInitializerKinds =
ImmutableArray.Create(SyntaxKind.ObjectInitializerExpression, SyntaxKind.ArrayInitializerExpression, SyntaxKind.CollectionInitializerExpression);
ImmutableArray.Create(SyntaxKind.ObjectInitializerExpression, SyntaxKind.ArrayInitializerExpression, SyntaxKind.CollectionInitializerExpression, SyntaxKindEx.WithInitializerExpression);

/// <inheritdoc/>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
Expand Down

0 comments on commit aa26bda

Please sign in to comment.