Same as this which was closed but still applies to the latest release.
Version: SonarQube Version 9.9 (build 65466)
Rule: C# / S1172
The rule (do not include unused parameters) is triggered with this code:
private WebAppOpenEntitySectionDto? BuildSection(
IReadOnlyDictionary<WebAppEntityTypes, WebAppOpenEntityGroupDto> entities, // <- considered unused
WebAppSectionDto? section,
IEnumerable<WebAppEntityTypes> sectionEntities
)
{
var groups = sectionEntities.Select(entities.GetValueOrDefault).Where(item => item != null); // <- actually used here
return new()
{
// init
};
}
Hello @m-gallesio, and thank you for reporting this to us.
Could you please provide us with a minimal code reproducer that uses system libraries?
I used my colleague’s example from the post you linked above, and S1172 does not raise for me as well.
Which MSBuild version do you use to build the project?
Best Regards
Mary
I am using Visual Studio 2022 with the default .NET 7.0 SDK.
After some more testing, I found out this problem only happens for private methods:
using System.Collections.Generic;
using System.Linq;
namespace Test;
public class Test
{
private void BuildSectionPrivate(
IReadOnlyDictionary<int, string> items, // <- triggers the rule
IEnumerable<int> values
)
{
var groups = values.Select(items.GetValueOrDefault);
}
public void BuildSectionPublic(
IReadOnlyDictionary<int, string> items, // <- does not trigger the rule
IEnumerable<int> values
)
{
var groups = values.Select(items.GetValueOrDefault);
}
}
Hell @m-gallesio!
Indeed this is an FP.
I noticed that the FP is only raised when the parameter is used as a method group specifically in a private method. For example, if we change GetValueOrDefault
for ContainsKey
it’s not raised anymore.
There is already an open issue for this - please follow it for any updates.
Thanks a lot!