Skip to content

Commit

Permalink
Update SA1008 to require a space before the opening parenthesis of a …
Browse files Browse the repository at this point in the history
…using alias definition of a tuple type

#3743
  • Loading branch information
bjornhellander committed Dec 15, 2023
1 parent be49652 commit 1fe592a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@

namespace StyleCop.Analyzers.Test.CSharp12.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using StyleCop.Analyzers.Test.CSharp11.SpacingRules;
using Xunit;

using static StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly,
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;

public partial class SA1008CSharp12UnitTests : SA1008CSharp11UnitTests
{
[Fact]
[WorkItem(3743, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3743")]
public async Task TestTupleUsingAliasAsync()
{
const string testCode = @"
using TestAlias ={|#0:(|}string X, bool Y);";

const string fixedCode = @"
using TestAlias = (string X, bool Y);";

var expected = Diagnostic(DescriptorPreceded).WithLocation(0);
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ private static void HandleOpenParenToken(SyntaxTreeAnalysisContext context, Synt

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

0 comments on commit 1fe592a

Please sign in to comment.