Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated SA1015 analyzer to handle generic attributes (c# 11 preview) #3494

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}
}
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