Skip to content

Commit

Permalink
Fix unused type parameter (RCS1164) (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Sep 2, 2023
1 parent 6d2eb38 commit 0568588
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix [RCS1164](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1164) ([#1196](https://github.com/JosefPihrt/Roslynator/pull/1196)).

## [4.5.0] - 2023-08-27

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public override void VisitBracketedParameterList(BracketedParameterListSyntax no

public override void VisitParameterList(ParameterListSyntax node)
{
if (node.IsParentKind(SyntaxKind.MethodDeclaration, SyntaxKind.LocalFunctionStatement))
if (node.IsParentKind(SyntaxKind.MethodDeclaration, SyntaxKind.LocalFunctionStatement, SyntaxKind.ParenthesizedLambdaExpression))
base.VisitParameterList(node);
}

Expand Down
45 changes: 45 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1164UnusedTypeParameterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Josef Pihrt and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Roslynator.CSharp.CodeFixes;
using Roslynator.Testing.CSharp;
using Xunit;

namespace Roslynator.CSharp.Analysis.Tests;

public class RCS1164UnusedTypeParameterTests : AbstractCSharpDiagnosticVerifier<UnusedParameter.UnusedParameterAnalyzer, UnusedParameterCodeFixProvider>
{
public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.UnusedTypeParameter;

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UnusedTypeParameter)]
public async Task TestNoDiagnostic_DependencyPropertyEventArgs()
{
await VerifyNoDiagnosticAsync(@"
using System;
public static class TestClass
{
public static void RunDelegate<T>(object arg)
{
RunDelegate(arg, (T arg) =>
{
if (arg is string stringArg)
{
Console.WriteLine(stringArg);
}
}
);
}
private static void RunDelegate(
object arg,
Delegate _delegate
)
{
_delegate.DynamicInvoke(arg);
}
}
");
}
}

0 comments on commit 0568588

Please sign in to comment.