Skip to content

Commit 9df78b1

Browse files
committed
Fix SA1008 for positional pattern after comma
Fixes #3198
1 parent cf2cd83 commit 9df78b1

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,43 @@ await VerifyCSharpFixAsync(
109109
fixedCode,
110110
CancellationToken.None).ConfigureAwait(false);
111111
}
112+
113+
[Fact]
114+
[WorkItem(3198, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3198")]
115+
public async Task TestInPositionalPatternAsync()
116+
{
117+
var testCode = @"
118+
class C
119+
{
120+
void M((bool A, bool B) tuple)
121+
{
122+
_ = (tuple, tuple) is{|#0:(|} (true, true),{|#1:(|} true, true));
123+
}
124+
}
125+
";
126+
var fixedCode = @"
127+
class C
128+
{
129+
void M((bool A, bool B) tuple)
130+
{
131+
_ = (tuple, tuple) is ((true, true), (true, true));
132+
}
133+
}
134+
";
135+
DiagnosticResult[] expectedResults =
136+
{
137+
Diagnostic(DescriptorPreceded).WithLocation(0),
138+
Diagnostic(DescriptorNotFollowed).WithLocation(0),
139+
Diagnostic(DescriptorPreceded).WithLocation(1),
140+
Diagnostic(DescriptorNotFollowed).WithLocation(1),
141+
};
142+
143+
await VerifyCSharpFixAsync(
144+
LanguageVersion.CSharp8,
145+
testCode,
146+
expectedResults,
147+
fixedCode,
148+
CancellationToken.None).ConfigureAwait(false);
149+
}
112150
}
113151
}

StyleCop.Analyzers/StyleCop.Analyzers/SpacingRules/SA1008OpeningParenthesisMustBeSpacedCorrectly.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
185185
break;
186186

187187
case SyntaxKindEx.PositionalPatternClause:
188-
haveLeadingSpace = prevToken.IsKind(SyntaxKind.IsKeyword);
188+
haveLeadingSpace = prevToken.IsKind(SyntaxKind.IsKeyword)
189+
|| prevToken.IsKind(SyntaxKind.CommaToken);
189190
break;
190191

191192
case SyntaxKind.ArgumentList:

0 commit comments

Comments
 (0)