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

Handle DependencyPropertyChangedEventArgs (RCS1163) #1068

Merged
merged 5 commits into from
Apr 9, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [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).
- 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

Expand Down
1 change: 1 addition & 0 deletions src/Core/MetadataNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Core/SymbolUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DependencyPropertyChangedEventArgs> Changed;
}

namespace System.Windows
{
public class DependencyPropertyChangedEventArgs
{
}
}
");
}
}