Skip to content

Commit

Permalink
Merge pull request #3494 from bjornhellander/feature/genericattribute
Browse files Browse the repository at this point in the history
Updated SA1015 analyzer to handle generic attributes (c# 11 preview)
  • Loading branch information
sharwell authored May 3, 2022
2 parents 4fba7cd + 0d459d4 commit e017492
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,36 @@

namespace StyleCop.Analyzers.Test.CSharp11.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp10.SpacingRules;
using Xunit;

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

public class SA1015CSharp11UnitTests : SA1015CSharp10UnitTests
{
[Fact]
[WorkItem(3487, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3487")]
public async Task TestGenericAttributeAsync()
{
var testCode = $@"
using System;
public class MyAttribute<T> : Attribute
{{
}}
public class MyClass
{{
[MyAttribute<int>]
public double MyDouble {{ get; set; }}
}}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ private static void HandleGreaterThanToken(SyntaxTreeAnalysisContext context, Sy
// values[x as T<int>]
// ^^
case SyntaxKind.CloseBracketToken when nextToken.Parent.IsKind(SyntaxKind.BracketedArgumentList):
// [MyAttribute<T>]
// ^^
case SyntaxKind.CloseBracketToken when nextToken.Parent.IsKind(SyntaxKind.AttributeList):
allowTrailingNoSpace = true;
allowTrailingSpace = false;
break;
Expand Down

0 comments on commit e017492

Please sign in to comment.