Skip to content

Commit

Permalink
Updated SA1015 analyzer to handle generic attributes (c# 11 preview)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornhellander committed May 2, 2022
1 parent 4fba7cd commit 0d459d4
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 0d459d4

Please sign in to comment.