Skip to content

Commit

Permalink
Fix SA1009 handling of record inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Dec 5, 2020
1 parent 363a36c commit 847d8f0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,54 @@

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

public class SA1009CSharp9UnitTests : SA1009CSharp8UnitTests
{
[Fact]
[WorkItem(3248, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3248")]
public async Task TestRecordInheritanceAsync()
{
const string testCode = @"
public abstract record BaseQuery<T>;
public record MyQuery1( {|#0:)|}: BaseQuery<object>;
public record MyQuery2( {|#1:)|} : BaseQuery<object>;
public record MyQuery3({|#2:)|}: BaseQuery<object>;";
const string fixedCode = @"
public abstract record BaseQuery<T>;
public record MyQuery1() : BaseQuery<object>;
public record MyQuery2() : BaseQuery<object>;
public record MyQuery3() : BaseQuery<object>;";

await new CSharpTest(LanguageVersion.CSharp9)
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
ExpectedDiagnostics =
{
// /0/Test0.cs(3,25): warning SA1009: Closing parenthesis should not be preceded by a space
Diagnostic(DescriptorNotPreceded).WithLocation(0),

// /0/Test0.cs(3,25): warning SA1009: Closing parenthesis should be followed by a space
Diagnostic(DescriptorFollowed).WithLocation(0),

// /0/Test0.cs(4,25): warning SA1009: Closing parenthesis should not be preceded by a space
Diagnostic(DescriptorNotPreceded).WithLocation(1),

// /0/Test0.cs(5,24): warning SA1009: Closing parenthesis should be followed by a space
Diagnostic(DescriptorFollowed).WithLocation(2),
},
TestCode = testCode,
FixedCode = fixedCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ private static void HandleCloseParenToken(SyntaxTreeAnalysisContext context, Syn
bool requireSpace =
nextToken.Parent.IsKind(SyntaxKind.ConditionalExpression)
|| nextToken.Parent.IsKind(SyntaxKind.BaseConstructorInitializer)
|| nextToken.Parent.IsKind(SyntaxKind.ThisConstructorInitializer);
|| nextToken.Parent.IsKind(SyntaxKind.ThisConstructorInitializer)
|| nextToken.Parent.IsKind(SyntaxKind.BaseList);
precedesStickyCharacter = !requireSpace;
break;

Expand Down

0 comments on commit 847d8f0

Please sign in to comment.