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

Reproducer for #8988 S1172 FP: Don't report on partial method parameters #8989

Merged
merged 11 commits into from
Mar 28, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,33 @@ public void MethodParameterUnused_CSharp10_RoslynCfg() =>

[TestMethod]
public void MethodParameterUnused_CSharp11_CS() =>
roslynCS
.AddPaths("MethodParameterUnused.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.Verify();
roslynCS.AddPaths("MethodParameterUnused.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.Verify();

[TestMethod]
public void MethodParameterUnused_GeneratedCode_CS() =>
roslynCS.AddSnippet("""
using System.CodeDom.Compiler;

[GeneratedCode("TestTool", "Version")]
public partial class Generated
{
private partial void M(int a, int unused);
}
""")
.AddSnippet("""
cristian-ambrosini-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
using System;

public partial class Generated
{
private partial void M(int a, int unused) // Noncompliant FP
{
Console.WriteLine(a);
}
}
""")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.Verify();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ private void Argument_UsedInGenericAttributeByNameOf<TArgument>(TArgument argume
}
}

namespace Issue_8988
{
public partial class PartialMethod
{
private partial string ExtendedPartialMethod(string one, string two);
}

public partial class PartialMethod
{
private partial string ExtendedPartialMethod(string one, string two) // Noncompliant FP
{
return two;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@ partial class MethodAssignedToActionFromPartialClass
public System.Action<int> MyReference = MethodAssignedToActionFromPartialClass.MyMethod5;
}

public partial class PartialMethod
{
partial void FalsePositive(string one, string two);
}

public partial class PartialMethod
{
partial void FalsePositive(string two) // Fixed
{
Console.Write(two);
}
}

public class Dead
{
private int Method1(int p) => (new Func<int>(() => { p = 10; return p; }))(); // Not reporting on this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,19 @@ partial class MethodAssignedToActionFromPartialClass
public System.Action<int> MyReference = MethodAssignedToActionFromPartialClass.MyMethod5;
}

public partial class PartialMethod
{
partial void FalsePositive(string one, string two);
}

public partial class PartialMethod
{
partial void FalsePositive(string one, string two) // Noncompliant FP
{
Console.Write(two);
}
}
cristian-ambrosini-sonarsource marked this conversation as resolved.
Show resolved Hide resolved

public class Dead
{
private int Method1(int p) => (new Func<int>(() => { p = 10; return p; }))(); // Not reporting on this
Expand Down
Loading