From a03a3f4f9825aaa4778e389566f1f5bcc27ad58d Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 9 Apr 2023 09:47:19 +0200 Subject: [PATCH 1/4] Handle DependencyPropertyChangedEventArgs --- src/Core/MetadataNames.cs | 1 + src/Core/SymbolUtility.cs | 3 +- .../RCS1163UnusedParameterTests.cs | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Core/MetadataNames.cs b/src/Core/MetadataNames.cs index 87af341efa..d5d49a311b 100644 --- a/src/Core/MetadataNames.cs +++ b/src/Core/MetadataNames.cs @@ -66,6 +66,7 @@ internal static class MetadataNames public static readonly MetadataName System_Threading_Tasks_ValueTask_T = MetadataName.Parse("System.Threading.Tasks.ValueTask`1"); public static readonly MetadataName System_TimeSpan = MetadataName.Parse("System.TimeSpan"); public static readonly MetadataName System_ValueType = MetadataName.Parse("System.ValueType"); + public static readonly MetadataName System_Windows_DependencyPropertyChangedEventArgs = MetadataName.Parse("System.Windows.DependencyPropertyChangedEventArgs"); public static class WinRT { diff --git a/src/Core/SymbolUtility.cs b/src/Core/SymbolUtility.cs index 5aab127a95..ffb097f0d2 100644 --- a/src/Core/SymbolUtility.cs +++ b/src/Core/SymbolUtility.cs @@ -82,7 +82,8 @@ public static bool IsEventHandlerMethod(IMethodSymbol methodSymbol) if (type.Kind == SymbolKind.TypeParameter) return type.Name.EndsWith("EventArgs", StringComparison.Ordinal); - return type.EqualsOrInheritsFrom(MetadataNames.System_EventArgs); + return type.EqualsOrInheritsFrom(MetadataNames.System_EventArgs) + || type.HasMetadataName(MetadataNames.System_Windows_DependencyPropertyChangedEventArgs); } } diff --git a/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs b/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs index 3142e46f53..41a3537f0b 100644 --- a/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs @@ -204,4 +204,37 @@ public static int GetCount(__arglist) } "); } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UnusedParameter)] + public async Task TestNoDiagnostic_DependencyPropertyEventArgs() + { + await VerifyNoDiagnosticAsync(@" +using System; +using System.Windows; + +static class C +{ + public static void M(this Foo foo) + { + foo.Changed += Foo_Changed; + + void Foo_Changed(object sender, DependencyPropertyChangedEventArgs e) + { + } + } +} + +public class Foo +{ + public event EventHandler Changed; +} + +namespace System.Windows +{ + public class DependencyPropertyChangedEventArgs : EventArgs + { + } +} + "); + } } From 2deb2afc165d48537e58164a6d1c9257350121e9 Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 9 Apr 2023 09:54:35 +0200 Subject: [PATCH 2/4] changelog --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 8b0456ba06..1109c798ac 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Do not remove braces in the cases where there are overlapping local variables. ([RCS1031](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1013.md), [RCS1211](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1211.md), [RCS1208](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1208.md)) ([#1039](https://github.com/JosefPihrt/Roslynator/pull/1039)). - [CLI] Analyze command does not create the XML output file and returns incorrect exit code when only compiler diagnostics are reported ([#1056](https://github.com/JosefPihrt/Roslynator/pull/1056) by @PeterKaszab). - [CLI] Fix exit code when multiple projects are processed ([#1061](https://github.com/JosefPihrt/Roslynator/pull/1061) by @PeterKaszab). +- Do not report `System.Windows.DependencyPropertyChangedEventArgs` as unused parameter ([RCS1163](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1163.md)) ([#1068](https://github.com/JosefPihrt/Roslynator/pull/1068)). ## [4.2.0] - 2022-11-27 From fbcee1b57e08481febd8bed14d2c802da665c29f Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 9 Apr 2023 09:56:06 +0200 Subject: [PATCH 3/4] update --- src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs b/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs index 41a3537f0b..2869c7a851 100644 --- a/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs @@ -231,7 +231,7 @@ public class Foo namespace System.Windows { - public class DependencyPropertyChangedEventArgs : EventArgs + public class DependencyPropertyChangedEventArgs { } } From 36124d86e5d00394517699540e9e16a3b0e4c88f Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 9 Apr 2023 09:57:48 +0200 Subject: [PATCH 4/4] update --- ChangeLog.md | 1 - 1 file changed, 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 68be86b987..c187b27a9d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -33,7 +33,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix code fix for CS0164 ([#1031](https://github.com/JosefPihrt/Roslynator/pull/1031)). - Do not report `System.Windows.DependencyPropertyChangedEventArgs` as unused parameter ([RCS1163](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1163.md)) ([#1068](https://github.com/JosefPihrt/Roslynator/pull/1068)). - ## [4.2.0] - 2022-11-27 ### Added