-
Notifications
You must be signed in to change notification settings - Fork 466
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 in Azure Functions where attribute is needed, but parameter is not #2589
Comments
The recommended approach we're using in dotnet/roslyn for these cases is to assign the unused parameter to a discard within the method: // Not required by this implementation
_ = someUnusedParameter; The shapes proposal sounds like it could provide some benefits in this scenario, similar to how interfaces already trigger exclusions for this rule today. |
We have also changed the IDE implementation of unused parameter rule to exclude parameter symbols with discard symbol name: http://source.roslyn.io/#Microsoft.CodeAnalysis.Features/RemoveUnusedParametersAndValues/AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.cs,226. // Ignore special parameter names for methods that need a specific signature.
// For example, methods used as a delegate in a different type or project.
// This also serves as a convenient way to suppress instances of unused parameter diagnostic
// without disabling the diagnostic completely.
// We ignore parameter names that start with an underscore and are optionally followed by an integer,
// such as '_', '_1', '_2', etc. I am going to implement the same for CA1801 and the user can choose between either using a special name OR the approach suggested by @sharwell above. |
I'm not sure this a bug, or an odd use case, but I'm interested in workarounds if it's not.
Analyzer package
Microsoft.CodeAnalysis.FxCopAnalyzers
Package Version
v2.9.3 (Latest)
Diagnostic ID
CA1801
Repro steps
Expected behavior
No warning is generated. The parameter has to be there because the attribute needs to be there.
Actual behavior
Warning is generated.
The text was updated successfully, but these errors were encountered: