From 7228633c9b313a58c4a318fefe22997f30c39163 Mon Sep 17 00:00:00 2001 From: Andrei Epure Date: Mon, 16 Nov 2020 11:22:24 +0100 Subject: [PATCH] address comments --- .../Rules/ExpressionComplexityTest.cs | 23 +++++++------------ ...nShouldNotBeThrownFromUnexpectedMethods.cs | 6 +++++ .../TestCases/ExpressionComplexity.CSharp9.cs | 5 +++- ...thodShouldBeInSeparateNamespace.CSharp9.cs | 7 +++++- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules/ExpressionComplexityTest.cs b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules/ExpressionComplexityTest.cs index 63bad952ea6..6dd3925fb47 100644 --- a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules/ExpressionComplexityTest.cs +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules/ExpressionComplexityTest.cs @@ -28,28 +28,21 @@ public class ExpressionComplexityTest { [TestMethod] [TestCategory("Rule")] - public void ExpressionComplexity_CSharp() - { - var diagnostic = new SonarAnalyzer.Rules.CSharp.ExpressionComplexity { Maximum = 3}; + public void ExpressionComplexity_CSharp() => Verifier.VerifyAnalyzer(@"TestCases\ExpressionComplexity.cs", - diagnostic, + new SonarAnalyzer.Rules.CSharp.ExpressionComplexity { Maximum = 3}, options: ParseOptionsHelper.FromCSharp8); - } [TestMethod] [TestCategory("Rule")] - public void ExpressionComplexity_CSharp9() - { - var diagnostic = new SonarAnalyzer.Rules.CSharp.ExpressionComplexity { Maximum = 3}; - Verifier.VerifyAnalyzerFromCSharp9Console(@"TestCases\ExpressionComplexity.CSharp9.cs", diagnostic); - } + public void ExpressionComplexity_CSharp9() => + Verifier.VerifyAnalyzerFromCSharp9Console(@"TestCases\ExpressionComplexity.CSharp9.cs", + new SonarAnalyzer.Rules.CSharp.ExpressionComplexity { Maximum = 3}); [TestMethod] [TestCategory("Rule")] - public void ExpressionComplexity_VisualBasic() - { - var diagnostic = new SonarAnalyzer.Rules.VisualBasic.ExpressionComplexity { Maximum = 3 }; - Verifier.VerifyAnalyzer(@"TestCases\ExpressionComplexity.vb", diagnostic); - } + public void ExpressionComplexity_VisualBasic() => + Verifier.VerifyAnalyzer(@"TestCases\ExpressionComplexity.vb", + new SonarAnalyzer.Rules.VisualBasic.ExpressionComplexity { Maximum = 3 }); } } diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExceptionShouldNotBeThrownFromUnexpectedMethods.cs b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExceptionShouldNotBeThrownFromUnexpectedMethods.cs index 3da8383eff9..b704426686e 100644 --- a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExceptionShouldNotBeThrownFromUnexpectedMethods.cs +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExceptionShouldNotBeThrownFromUnexpectedMethods.cs @@ -262,4 +262,10 @@ public void Dispose() throw new Exception(); // Noncompliant } } + + class ArrowMethods : IDisposable + { + static ArrowMethods() => throw new Exception(); // FN, needs support for throw expressions + public void Dispose() => throw new Exception(); // FN + } } diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExpressionComplexity.CSharp9.cs b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExpressionComplexity.CSharp9.cs index 07ab38ad6bf..d24bc8498e3 100644 --- a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExpressionComplexity.CSharp9.cs +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExpressionComplexity.CSharp9.cs @@ -1,4 +1,7 @@ -object x = null; +var d1 = true && false && true && false && true && true; // Noncompliant + +object x = null; + if (x is true or true or true or true or true) { } // FN if (x is true and true and true and true and true) { } // FN diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExtensionMethodShouldBeInSeparateNamespace.CSharp9.cs b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExtensionMethodShouldBeInSeparateNamespace.CSharp9.cs index ccbdbeef374..fb48e876e5d 100644 --- a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExtensionMethodShouldBeInSeparateNamespace.CSharp9.cs +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/ExtensionMethodShouldBeInSeparateNamespace.CSharp9.cs @@ -1,7 +1,12 @@ -var x = 1; +var isTopLevelFile = true; public record GlobalRecord { } +public static class GlobalExtensions +{ + public static void Bar(this GlobalRecord r) { } // Noncompliant +} + namespace MyLibrary { public record Foo { }