Skip to content

Commit

Permalink
Merge pull request #3748 from bjornhellander/feature/sa1008-tuple-usi…
Browse files Browse the repository at this point in the history
…ng-alias

Update SA1008 to allow space before the opening parenthesis of a using alias definition of a tuple type
  • Loading branch information
sharwell authored Dec 18, 2023
2 parents 4495405 + 1fe592a commit e22309f
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 e22309f

Please sign in to comment.