Skip to content

Commit 1fe592a

Browse files
Update SA1008 to require a space before the opening parenthesis of a using alias definition of a tuple type
#3743
1 parent be49652 commit 1fe592a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/SpacingRules/SA1008CSharp12UnitTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,30 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;
9+
using Xunit;
10+
11+
using static StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly;
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
13+
StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly,
14+
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
715

816
public partial class SA1008CSharp12UnitTests : SA1008CSharp11UnitTests
917
{
18+
[Fact]
19+
[WorkItem(3743, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3743")]
20+
public async Task TestTupleUsingAliasAsync()
21+
{
22+
const string testCode = @"
23+
using TestAlias ={|#0:(|}string X, bool Y);";
24+
25+
const string fixedCode = @"
26+
using TestAlias = (string X, bool Y);";
27+
28+
var expected = Diagnostic(DescriptorPreceded).WithLocation(0);
29+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
30+
}
1031
}
1132
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,12 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt
249249

250250
case SyntaxKindEx.TupleType:
251251
// Comma covers tuple types in parameters and nested within other tuple types.
252+
// Equals covers definition of a tuple type alias.
252253
// 'out', 'ref', 'in', 'params' parameters are covered by IsKeywordKind.
253254
// Attributes of parameters are covered by checking the previous token's parent.
254255
// Return types are handled by a helper.
255256
haveLeadingSpace = prevToken.IsKind(SyntaxKind.CommaToken)
257+
|| prevToken.IsKind(SyntaxKind.EqualsToken)
256258
|| SyntaxFacts.IsKeywordKind(prevToken.Kind())
257259
|| prevToken.Parent.IsKind(SyntaxKind.AttributeList)
258260
|| ((TypeSyntax)token.Parent).GetContainingNotEnclosingType().IsReturnType();

0 commit comments

Comments
 (0)