diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1015CSharp8UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1015CSharp8UnitTests.cs index c465ce53a..f6f11ac92 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1015CSharp8UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1015CSharp8UnitTests.cs @@ -3,9 +3,37 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp7.SpacingRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.SpacingRules.SA1015ClosingGenericBracketsMustBeSpacedCorrectly, + StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>; public class SA1015CSharp8UnitTests : SA1015CSharp7UnitTests { + [Fact] + [WorkItem(3302, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3302")] + public async Task TestGenericTypePointerAsync() + { + const string testCode = @"using System; + +public struct Foo +{ + internal unsafe Foo|] * Next1; + internal unsafe Foo|]* Next2; +}"; + const string fixedCode = @"using System; + +public struct Foo +{ + internal unsafe Foo * Next1; + internal unsafe Foo* Next2; +}"; + + await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1023CSharp8UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1023CSharp8UnitTests.cs index 9d360bedd..3aa55bc9f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1023CSharp8UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1023CSharp8UnitTests.cs @@ -3,9 +3,39 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp7.SpacingRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.SpacingRules.SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly, + StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>; public class SA1023CSharp8UnitTests : SA1023CSharp7UnitTests { + [Fact] + [WorkItem(3302, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3302")] + public async Task TestGenericTypePointerAsync() + { + const string testCode = @"using System; + +public struct Foo +{ + internal unsafe Foo [|*|] Next1; + internal unsafe Foo[|*|]Next2; + internal unsafe Foo [|[|*|]|]Next3; +}"; + const string fixedCode = @"using System; + +public struct Foo +{ + internal unsafe Foo* Next1; + internal unsafe Foo* Next2; + internal unsafe Foo* Next3; +}"; + + await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs index 803913522..c175a35d9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1015ClosingGenericBracketsMustBeSpacedCorrectly.cs @@ -126,6 +126,11 @@ private static void HandleGreaterThanToken(SyntaxTreeAnalysisContext context, Sy allowTrailingSpace = true; break; + case SyntaxKind.AsteriskToken: + allowTrailingNoSpace = nextToken.Parent.IsKind(SyntaxKind.PointerType); + allowTrailingSpace = true; + break; + case SyntaxKind.QuestionToken: allowTrailingNoSpace = nextToken.Parent.IsKind(SyntaxKind.NullableType); allowTrailingSpace = true;