Skip to content

Commit 32d1e4a

Browse files
Merge pull request #64 from bjornhellander/feature/sa1003-null-suppression-before-invocation
Update SA1003SymbolsMustBeSpacedCorrectly to forbid space between a postfix operator and an opening parenthesis
2 parents 738ff91 + e306fc0 commit 32d1e4a

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1003CSharp8UnitTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,38 @@ public void TestMethod(string? x)
185185
}
186186
}
187187
}
188+
";
189+
190+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
191+
}
192+
193+
[Fact]
194+
public async Task TestNullForgivingOperatorBeforeInvocationAsync()
195+
{
196+
var testCode = @"
197+
namespace TestNamespace
198+
{
199+
public class TestClass
200+
{
201+
public void TestMethod(System.Action? x)
202+
{
203+
x[|!|] ();
204+
}
205+
}
206+
}
207+
";
208+
209+
var fixedCode = @"
210+
namespace TestNamespace
211+
{
212+
public class TestClass
213+
{
214+
public void TestMethod(System.Action? x)
215+
{
216+
x!();
217+
}
218+
}
219+
}
188220
";
189221

190222
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1003SymbolsMustBeSpacedCorrectly.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ private static void HandlePostfixUnaryExpression(SyntaxNodeAnalysisContext conte
304304
{
305305
case SyntaxKind.CloseParenToken:
306306
case SyntaxKind.OpenBracketToken: // Example: x![i]
307+
case SyntaxKind.OpenParenToken: // Example: x!()
307308
case SyntaxKind.CloseBracketToken:
308309
case SyntaxKind.SemicolonToken:
309310
case SyntaxKind.CommaToken:

0 commit comments

Comments
 (0)