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

S3241: Add support for record structs #5622

Merged
merged 4 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
}