Skip to content

Commit

Permalink
Reproducer for #8988 S1172 FP: Don't report on partial method paramet…
Browse files Browse the repository at this point in the history
…ers (#8989)
  • Loading branch information
martin-strecker-sonarsource authored Mar 28, 2024
1 parent 6f9fee8 commit af1b44f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,35 @@ 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]
// https://github.com/SonarSource/sonar-dotnet/issues/8988
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("""
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,20 @@ private void Argument_UsedInGenericAttributeByNameOf<TArgument>(TArgument argume
}
}

// https://github.com/SonarSource/sonar-dotnet/issues/8988
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,20 @@ partial class MethodAssignedToActionFromPartialClass
public System.Action<int> MyReference = MethodAssignedToActionFromPartialClass.MyMethod5;
}

// https://github.com/SonarSource/sonar-dotnet/issues/8988
public partial class PartialMethod_Issue_8988
{
partial void Partial(string one, string two);
}

public partial class PartialMethod_Issue_8988
{
partial void Partial(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,20 @@ partial class MethodAssignedToActionFromPartialClass
public System.Action<int> MyReference = MethodAssignedToActionFromPartialClass.MyMethod5;
}

// https://github.com/SonarSource/sonar-dotnet/issues/8988
public partial class PartialMethod_Issue_8988
{
partial void Partial(string one, string two);
}

public partial class PartialMethod_Issue_8988
{
partial void Partial(string one, string two) // Noncompliant FP
{
Console.Write(two);
}
}

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

0 comments on commit af1b44f

Please sign in to comment.