Skip to content

Commit

Permalink
S3241: Add support for record structs (#5622)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource authored May 4, 2022
1 parent 4ecc46c commit 2715ff8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public static bool IsNodeContainerTypeDeclaration(SyntaxNode node) =>
IsNodeStructOrClassOrRecordDeclaration(node) || node.IsKind(SyntaxKind.InterfaceDeclaration);

private static bool IsNodeStructOrClassOrRecordDeclaration(SyntaxNode node) =>
node.IsAnyKind(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKindEx.RecordClassDeclaration);
node.IsAnyKind(SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration, SyntaxKindEx.RecordClassDeclaration, SyntaxKindEx.RecordStructDeclaration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,31 @@ namespace SonarAnalyzer.UnitTest.Rules
[TestClass]
public class UnusedReturnValueTest
{
private readonly VerifierBuilder builder = new VerifierBuilder<UnusedReturnValue>();

[TestMethod]
public void UnusedReturnValue() =>
OldVerifier.VerifyAnalyzer(
@"TestCases\UnusedReturnValue.cs",
new UnusedReturnValue(),
ParseOptionsHelper.FromCSharp8);
builder.AddPaths("UnusedReturnValue.cs").WithOptions(ParseOptionsHelper.FromCSharp8).Verify();

[TestMethod]
public void UnusedReturnValueWithPartialClasses() =>
OldVerifier.VerifyAnalyzer(
new[] { @"TestCases\UnusedReturnValue.part1.cs", @"TestCases\UnusedReturnValue.part2.cs", @"TestCases\UnusedReturnValue.External.cs" },
new UnusedReturnValue(),
ParseOptionsHelper.FromCSharp8);
builder.AddPaths("UnusedReturnValue.part1.cs", "UnusedReturnValue.part2.cs", "UnusedReturnValue.External.cs").WithOptions(ParseOptionsHelper.FromCSharp8).Verify();

#if NET

[TestMethod]
public void UnusedReturnValue_CSharp9() =>
OldVerifier.VerifyAnalyzerFromCSharp9Console(@"TestCases\UnusedReturnValue.CSharp9.cs", new UnusedReturnValue());
builder.AddPaths("UnusedReturnValue.CSharp9.cs").WithTopLevelStatements().Verify();

[TestMethod]
public void UnusedReturnValue_CSharp10() =>
OldVerifier.VerifyAnalyzerFromCSharp10Console(@"TestCases\UnusedReturnValue.CSharp10.cs", new UnusedReturnValue());
builder.AddPaths("UnusedReturnValue.CSharp10.cs").WithTopLevelStatements().WithOptions(ParseOptionsHelper.FromCSharp10).Verify();

[TestMethod]
public void UnusedReturnValue_CSharpPreview() =>
OldVerifier.VerifyAnalyzerCSharpPreviewLibrary(@"TestCases\UnusedReturnValue.CSharpPreview.cs", new UnusedReturnValue());
builder.AddPaths("UnusedReturnValue.CSharpPreview.cs").WithOptions(ParseOptionsHelper.CSharpPreview).Verify();

#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Test()
var o = SomeGenericMethod2<object>();
}

private T SomeGenericMethod<T>() where T : class { return null; } // FN
private T SomeGenericMethod<T>() where T : class { return null; } // Noncompliant {{Change return type to 'void'; not a single caller uses the returned value.}}
private T SomeGenericMethod2<T>() where T : class { return null; }
}

Expand All @@ -57,6 +57,6 @@ public void Test()
var o = SomeGenericMethod2<object>();
}

private T SomeGenericMethod<T>() where T : class { return null; } // FN
private T SomeGenericMethod<T>() where T : class { return null; } // Noncompliant {{Change return type to 'void'; not a single caller uses the returned value.}}
private T SomeGenericMethod2<T>() where T : class { return null; }
}

0 comments on commit 2715ff8

Please sign in to comment.