Skip to content

Commit

Permalink
Fix handling of nullable suppression operator after parentheses
Browse files Browse the repository at this point in the history
Fixes #2991
  • Loading branch information
sharwell committed Sep 3, 2019
1 parent e35d446 commit 4ff982f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,44 @@

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

public class SA1009CSharp8UnitTests : SA1009CSharp7UnitTests
{
[Fact]
[WorkItem(2991, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2991")]
public async Task TestFollowedBySuppressionOperatorAsync()
{
const string testCode = @"
public class Foo
{
public void TestMethod<T>()
{
if (default(T[|)|] ! is null)
{
}
}
}";
const string fixedCode = @"
public class Foo
{
public void TestMethod<T>()
{
if (default(T)! is null)
{
}
}
}";

await VerifyCSharpFixAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ private static void HandleCloseParenToken(SyntaxTreeAnalysisContext context, Syn
precedesStickyCharacter = nextToken.Parent is InterpolationSyntax;
break;

case SyntaxKind.ExclamationToken when nextToken.Parent.IsKind(SyntaxKindEx.SuppressNullableWarningExpression):
precedesStickyCharacter = true;
break;

default:
precedesStickyCharacter = false;
break;
Expand Down

0 comments on commit 4ff982f

Please sign in to comment.