1 year ago
#355197
AlienFromCA
Why is SonarAnalyzer reporting 'Unused method parameters should be removed'?
I am having an issue with SonarLint/Analyzer's (SonarAnalzer.CSharp (8.36.1.44192)) reporting of the "Unused method parameters should be removed" (1172) rule. I wish to know what I might be doing incorrectly here. The message from SonarSource is seemingly to generic and immediately confusing considering the actual use of the parameter, as seen below.
As far as research goes, I have read many other posts here about the same issue, all seemingly slightly different than my situation (many are for Java), where mine seems far more basic in its design. I also can not find an issue on SonarSource's site about this.
The report from SonarAnalzer, in Visual Studio, is on the single parameter: CommunicationsQueueItem item
. This however seems erroneous as the value is used, so long as it is not null, as seen here (screenshot below):
private async Task<bool> Send(CommunicationsQueueItem item)
{
var result = false;
if (item != null)
{
if (item.Type == Core.Domain.Enums.CommunicationType.Email)
result = await _emailProvider.SendEmail(
item.From, item.To, item.Cc, item.Bcc, item.Subject, item.Body
);
else
result = await _psProvider.SendMessage(item.From, item.To, item.Subject, item.Body);
}
return result;
}
Changing the code to test for the possible null condition and return earlier allows the warning to go away, but it is fundamentally the same thing, just with an extra return statement:
private async Task<bool> Send(CommunicationsQueueItem item)
{
var result = false;
if (item == null) return result;
if (item.Type == Core.Domain.Enums.CommunicationType.Email)
result = await _emailProvider.SendEmail(
item.From, item.To, item.Cc, item.Bcc, item.Subject, item.Body
);
else
result = await _psProvider.SendMessage(item.From, item.To, item.Subject, item.Body);
return result;
}
I appreciate the help, and look forward to the very simple or silly thing I am probably missing. Here is a screenshot of the reported issue in VS2022:
c#
sonarlint
0 Answers
Your Answer