diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1611CSharp9UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1611CSharp9UnitTests.cs
index 004f297bd..3bed2e128 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1611CSharp9UnitTests.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1611CSharp9UnitTests.cs
@@ -37,5 +37,24 @@ public async Task TestPrimaryRecordConstructorIncludeMissingParametersAsync(stri
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
+
+ [Fact]
+ [WorkItem(3977, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3977")]
+ public async Task TestLambdaDiscardParametersAsync()
+ {
+ var testCode = @"
+/// Test class.
+public class TestClass
+{
+ /// Test method.
+ public void TestMethod()
+ {
+ System.Func handler = (_, _) => 0;
+ }
+}
+";
+
+ await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
+ }
}
}
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1612CSharp9UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1612CSharp9UnitTests.cs
index 19d9c78db..3beab799b 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1612CSharp9UnitTests.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1612CSharp9UnitTests.cs
@@ -3,9 +3,31 @@
namespace StyleCop.Analyzers.Test.CSharp9.DocumentationRules
{
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp8.DocumentationRules;
+ using Xunit;
public partial class SA1612CSharp9UnitTests : SA1612CSharp8UnitTests
{
+ [Fact]
+ [WorkItem(3977, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3977")]
+ public async Task TestLambdaDiscardParametersAsync()
+ {
+ var testCode = @"
+/// Test class.
+public class TestClass
+{
+ /// Test method.
+ public void TestMethod()
+ {
+ System.Func handler = (_, _) => 0;
+ }
+}
+";
+
+ await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
+ }
}
}
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1312CSharp9UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1312CSharp9UnitTests.cs
index ab3ed34dd..e4ca713b2 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1312CSharp9UnitTests.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1312CSharp9UnitTests.cs
@@ -3,9 +3,34 @@
namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
{
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp8.NamingRules;
+ using Xunit;
+ using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
+ StyleCop.Analyzers.NamingRules.SA1312VariableNamesMustBeginWithLowerCaseLetter,
+ StyleCop.Analyzers.NamingRules.RenameToLowerCaseCodeFixProvider>;
public partial class SA1312CSharp9UnitTests : SA1312CSharp8UnitTests
{
+ [Fact]
+ [WorkItem(3977, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3977")]
+ public async Task TestLambdaDiscardParametersDoNotReportAsync()
+ {
+ var testCode = @"
+using System;
+
+public class TestClass
+{
+ public void Test()
+ {
+ Func handler = (_, _) => 0;
+ }
+}
+";
+
+ await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
+ }
}
}
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1313CSharp9UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1313CSharp9UnitTests.cs
index bd393fb24..f095ea1a1 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1313CSharp9UnitTests.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1313CSharp9UnitTests.cs
@@ -14,6 +14,25 @@ namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
public partial class SA1313CSharp9UnitTests : SA1313CSharp8UnitTests
{
+ [Fact]
+ [WorkItem(3977, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3977")]
+ public async Task TestLambdaDiscardParametersAsync()
+ {
+ var testCode = @"
+using System;
+
+public class TestClass
+{
+ public void Test()
+ {
+ Action handler = (_, _) => { };
+ }
+}
+";
+
+ await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
+ }
+
[Fact]
[WorkItem(3168, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3168")]
[WorkItem(3181, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3181")]
diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1612UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1612UnitTests.cs
index 5c2728e8f..6c6fd303e 100644
--- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1612UnitTests.cs
+++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1612UnitTests.cs
@@ -1,8 +1,6 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
-#nullable disable
-
namespace StyleCop.Analyzers.Test.DocumentationRules
{
using System.Collections.Generic;
@@ -562,35 +560,13 @@ public class ClassName
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}
- private static DiagnosticResult[] GetExpectedDiagnostics(DiagnosticResult normallyExpected, string declaration)
- {
- return GetExpectedDiagnostics(new[] { normallyExpected }, declaration);
- }
-
- // Syntax node actions for type declarations with a primary constructor were called twice
- // before support for c# 11 was added.
- private static DiagnosticResult[] GetExpectedDiagnostics(DiagnosticResult[] normallyExpected, string declaration)
- {
- var isPrimaryConstructor = declaration.Contains("record") || declaration.Contains("class") || declaration.Contains("struct");
-
- if (isPrimaryConstructor && !LightupHelpers.SupportsCSharp11)
- {
- // Diagnostic issued twice because of https://github.com/dotnet/roslyn/issues/53136 and https://github.com/dotnet/roslyn/issues/70488
- return normallyExpected.Concat(normallyExpected).ToArray();
- }
- else
- {
- return normallyExpected;
- }
- }
-
- private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
+ protected static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
=> VerifyCSharpDiagnosticAsync(source, testSettings: null, expected, ignoreCompilerDiagnostics: false, cancellationToken);
- private static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken)
+ protected static Task VerifyCSharpDiagnosticAsync(string source, string? testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken)
=> VerifyCSharpDiagnosticAsync(source, testSettings, expected, ignoreCompilerDiagnostics: false, cancellationToken);
- private static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, bool ignoreCompilerDiagnostics, CancellationToken cancellationToken)
+ protected static Task VerifyCSharpDiagnosticAsync(string source, string? testSettings, DiagnosticResult[] expected, bool ignoreCompilerDiagnostics, CancellationToken cancellationToken)
{
string contentWithoutParamDocumentation = @"
@@ -696,5 +672,27 @@ private static Task VerifyCSharpDiagnosticAsync(string source, string testSettin
test.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync(cancellationToken);
}
+
+ private static DiagnosticResult[] GetExpectedDiagnostics(DiagnosticResult normallyExpected, string declaration)
+ {
+ return GetExpectedDiagnostics(new[] { normallyExpected }, declaration);
+ }
+
+ // Syntax node actions for type declarations with a primary constructor were called twice
+ // before support for c# 11 was added.
+ private static DiagnosticResult[] GetExpectedDiagnostics(DiagnosticResult[] normallyExpected, string declaration)
+ {
+ var isPrimaryConstructor = declaration.Contains("record") || declaration.Contains("class") || declaration.Contains("struct");
+
+ if (isPrimaryConstructor && !LightupHelpers.SupportsCSharp11)
+ {
+ // Diagnostic issued twice because of https://github.com/dotnet/roslyn/issues/53136 and https://github.com/dotnet/roslyn/issues/70488
+ return normallyExpected.Concat(normallyExpected).ToArray();
+ }
+ else
+ {
+ return normallyExpected;
+ }
+ }
}
}