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

CA1801 False positive for events #2338

Closed
patriksvensson opened this issue Apr 14, 2019 · 2 comments
Closed

CA1801 False positive for events #2338

patriksvensson opened this issue Apr 14, 2019 · 2 comments
Assignees
Labels
Bug The product is not behaving according to its current intended design

Comments

@patriksvensson
Copy link

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

Example: v2.9.1

Diagnostic ID

Example: CA1801

Repro steps

I subscribed to an event in XAML (UWP) that generates a event callback in the code-behind file.

<controls:NavigationListView x:Name="MyListView"
    ItemsSource="{x:Bind MenuCommands, Mode=OneWay}"
    ItemInvoked="MyListView_ItemInvoked" />
private void MyListView_ItemInvoked(object sender, ListViewItem e)
{
   // Code here that does not use sender.
}

Expected behavior

I did not expect to get a warning saying that sender is not being used since I cannot remove the parameter without compilation errors.

Actual behavior

I get a warning telling me that not all parameters in the event callback is used (sender).

@mavasani mavasani added Area-Microsoft.CodeQuality.Analyzers Bug The product is not behaving according to its current intended design labels Apr 15, 2019
@mavasani mavasani self-assigned this Apr 15, 2019
@mavasani
Copy link
Contributor

mavasani commented May 6, 2019

@patriksvensson We special case the analyzer to not flag event handler methods that have a special signature:

  1. 2 parameters
  2. First parameter is of type object
  3. Second parameter is of type EventArgs or is a sub-type of EventArgs

It seems that your mentioned signature does not meet the criteria in 3. Did you mean to use ListViewItemEventArgs instead of ListViewItem as the second parameter?

@mavasani
Copy link
Contributor

Kindly refer to the suggestion 1. in #2593 (comment) - you should rename your parameter with one of the allowed discard symbol names to ensure it is not flagged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The product is not behaving according to its current intended design
Projects
None yet
Development

No branches or pull requests

2 participants