Skip to content

Commit

Permalink
Review 1 Addendum
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Pohlmann committed May 13, 2024
1 parent d67893b commit 8f4f5f6
Show file tree
Hide file tree
Showing 25 changed files with 353 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class AbstractTypesShouldNotHaveConstructorsTest
public void AbstractTypesShouldNotHaveConstructors_CSharp12() =>
builder.AddPaths("AbstractTypesShouldNotHaveConstructors.CSharp12.cs")
.WithOptions(ParseOptionsHelper.FromCSharp12)
.VerifyNoIssues(); // primary constructors are compliant
.VerifyNoIssues();

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public class BasicsController : Controller {{(compliant ? string.Empty : " // No
builderVB
.AddPaths("RouteTemplateShouldNotStartWithSlash.AspNetCore.vb")
.AddReferences(AspNetCoreReferences)
.VerifyNoIssues(); // FN
.VerifyNoIssues();

[TestMethod]
public void RouteTemplateShouldNotStartWithSlash_CSharp12() =>
Expand Down Expand Up @@ -194,7 +194,7 @@ public class BasicsController : Controller {{(compliant ? string.Empty : " // No
builderVB
.AddPaths("RouteTemplateShouldNotStartWithSlash.AspNet4x.vb")
.AddReferences(AspNet4xReferences(aspNetMvcVersion))
.VerifyNoIssues(); // FN, VB is not supported
.VerifyNoIssues();

[DataRow("/Index2", false)]
[DataRow(@"\Index2", true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class BypassingAccessibilityTest

[TestMethod]
public void BypassingAccessibility_CSharp12() =>
builderCS.AddPaths("BypassingAccessibility.CSharp12.cs").WithOptions(ParseOptionsHelper.FromCSharp12).VerifyNoIssues(); // zero-overhead member access is not supported yet
builderCS.AddPaths("BypassingAccessibility.CSharp12.cs").WithOptions(ParseOptionsHelper.FromCSharp12).VerifyNoIssues();

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CalculationsShouldNotOverflowTest

[TestMethod]
public void CalculationsShouldNotOverflow_CSharp8() =>
builderCS.AddPaths("CalculationsShouldNotOverflow.CSharp8.cs").WithOptions(ParseOptionsHelper.FromCSharp8).VerifyNoIssues(); // switch exressions are not supported yet
builderCS.AddPaths("CalculationsShouldNotOverflow.CSharp8.cs").WithOptions(ParseOptionsHelper.FromCSharp8).VerifyNoIssues();

#if NET

Expand All @@ -61,7 +61,7 @@ public class CalculationsShouldNotOverflowTest

[TestMethod]
public void CalculationsShouldNotOverflow_CSharp11() =>
builderCS.AddPaths("CalculationsShouldNotOverflow.CSharp11.cs").WithOptions(ParseOptionsHelper.FromCSharp11).VerifyNoIssues(); // list patterns are not supported yet
builderCS.AddPaths("CalculationsShouldNotOverflow.CSharp11.cs").WithOptions(ParseOptionsHelper.FromCSharp11).VerifyNoIssues();

#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,35 @@
using Microsoft.CodeAnalysis.CSharp;
using SonarAnalyzer.Rules.CSharp;

namespace SonarAnalyzer.Test.Rules
namespace SonarAnalyzer.Test.Rules;

[TestClass]
public class CallerInformationParametersShouldBeLastTest
{
[TestClass]
public class CallerInformationParametersShouldBeLastTest
{
private readonly VerifierBuilder builder = new VerifierBuilder<CallerInformationParametersShouldBeLast>();
private readonly VerifierBuilder builder = new VerifierBuilder<CallerInformationParametersShouldBeLast>();

[TestMethod]
public void CallerInformationParametersShouldBeLast() =>
builder.AddPaths("CallerInformationParametersShouldBeLast.cs").Verify();
[TestMethod]
public void CallerInformationParametersShouldBeLast() =>
builder.AddPaths("CallerInformationParametersShouldBeLast.cs").Verify();

#if NET

[TestMethod]
public void CallerInformationParametersShouldBeLast_CSharp9() =>
builder.AddPaths("CallerInformationParametersShouldBeLast.CSharp9.cs").WithTopLevelStatements().Verify();
[TestMethod]
public void CallerInformationParametersShouldBeLast_CSharp9() =>
builder.AddPaths("CallerInformationParametersShouldBeLast.CSharp9.cs").WithTopLevelStatements().Verify();

[TestMethod]
public void CallerInformationParametersShouldBeLast_CSharp10() =>
builder.AddPaths("CallerInformationParametersShouldBeLast.CSharp10.cs").WithOptions(ParseOptionsHelper.FromCSharp10).Verify();
[TestMethod]
public void CallerInformationParametersShouldBeLast_CSharp10() =>
builder.AddPaths("CallerInformationParametersShouldBeLast.CSharp10.cs").WithOptions(ParseOptionsHelper.FromCSharp10).Verify();

[TestMethod]
public void CallerInformationParametersShouldBeLast_CSharp11() =>
builder.AddPaths("CallerInformationParametersShouldBeLast.CSharp11.cs").WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues(); // overriding an abstract default implementation is compliant
[TestMethod]
public void CallerInformationParametersShouldBeLast_CSharp11() =>
builder.AddPaths("CallerInformationParametersShouldBeLast.CSharp11.cs").WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues();

#endif

[TestMethod]
public void CallerInformationParametersShouldBeLastInvalidSyntax() =>
builder.AddPaths("CallerInformationParametersShouldBeLastInvalidSyntax.cs").WithLanguageVersion(LanguageVersion.CSharp7).WithConcurrentAnalysis(false).Verify();
}
[TestMethod]
public void CallerInformationParametersShouldBeLastInvalidSyntax() =>
builder.AddPaths("CallerInformationParametersShouldBeLastInvalidSyntax.cs").WithLanguageVersion(LanguageVersion.CSharp7).WithConcurrentAnalysis(false).Verify();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public class ClassNamedExceptionTest
builderCS
.AddPaths("ClassNamedException.CSharp9.cs")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.VerifyNoIssues(); // records are compliant
.VerifyNoIssues();

[TestMethod]
public void ClassNamedException_FromCSharp10() =>
builderCS
.AddPaths("ClassNamedException.CSharp10.cs")
.WithOptions(ParseOptionsHelper.FromCSharp10)
.VerifyNoIssues(); // records are compliant
.VerifyNoIssues();

[TestMethod]
public void ClassNamedException_VB() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,37 @@

using SonarAnalyzer.Rules.CSharp;

namespace SonarAnalyzer.Test.Rules
namespace SonarAnalyzer.Test.Rules;

[TestClass]
public class ClassWithOnlyStaticMemberTest
{
[TestClass]
public class ClassWithOnlyStaticMemberTest
{
private readonly VerifierBuilder builder = new VerifierBuilder<ClassWithOnlyStaticMember>();
private readonly VerifierBuilder builder = new VerifierBuilder<ClassWithOnlyStaticMember>();

[TestMethod]
public void ClassWithOnlyStaticMember() =>
builder.AddPaths("ClassWithOnlyStaticMember.cs").Verify();
[TestMethod]
public void ClassWithOnlyStaticMember() =>
builder.AddPaths("ClassWithOnlyStaticMember.cs").Verify();

#if NET

[TestMethod]
public void ClassWithOnlyStaticMember_CSharp9() =>
builder.AddPaths("ClassWithOnlyStaticMember.CSharp9.cs")
.WithTopLevelStatements()
.VerifyNoIssues(); // records are compliant
[TestMethod]
public void ClassWithOnlyStaticMember_CSharp9() =>
builder.AddPaths("ClassWithOnlyStaticMember.CSharp9.cs")
.WithTopLevelStatements()
.VerifyNoIssues();

[TestMethod]
public void ClassWithOnlyStaticMember_CSharp11() =>
builder.AddPaths("ClassWithOnlyStaticMember.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues(); // inheriting from interfaces with default members is compliant
[TestMethod]
public void ClassWithOnlyStaticMember_CSharp11() =>
builder.AddPaths("ClassWithOnlyStaticMember.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues();

[TestMethod]
public void ClassWithOnlyStaticMember_CSharp12() =>
builder.AddPaths("ClassWithOnlyStaticMember.CSharp12.cs")
.WithOptions(ParseOptionsHelper.FromCSharp12)
.Verify();
[TestMethod]
public void ClassWithOnlyStaticMember_CSharp12() =>
builder.AddPaths("ClassWithOnlyStaticMember.CSharp12.cs")
.WithOptions(ParseOptionsHelper.FromCSharp12)
.Verify();

#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class DateAndTimeShouldNotBeUsedAsTypeForPrimaryKeyTest
verifierCS
.AddPaths("DateAndTimeShouldNotBeUsedAsTypeForPrimaryKey.CSharp9.cs")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.VerifyNoIssues(); // records are compliant
.VerifyNoIssues();

#if NET

Expand All @@ -68,11 +68,11 @@ public class DateAndTimeShouldNotBeUsedAsTypeForPrimaryKeyTest

[TestMethod]
public void DateAndTimeShouldNotBeUsedAsTypeForPrimaryKey_FluentApi_CS() =>
verifierCS.AddPaths("DateAndTimeShouldNotBeUsedAsTypeForPrimaryKey.FluentApi.cs").VerifyNoIssues(); // FN, Fluent API is not supported
verifierCS.AddPaths("DateAndTimeShouldNotBeUsedAsTypeForPrimaryKey.FluentApi.cs").VerifyNoIssues();

[TestMethod]
public void DateAndTimeShouldNotBeUsedAsTypeForPrimaryKey_FluentApi_VB() =>
verifierVB.AddPaths("DateAndTimeShouldNotBeUsedAsTypeForPrimaryKey.FluentApi.vb").VerifyNoIssues(); // FN, Fluent API is not supported
verifierVB.AddPaths("DateAndTimeShouldNotBeUsedAsTypeForPrimaryKey.FluentApi.vb").VerifyNoIssues();

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DisposableNotDisposedTest
public void DisposableNotDisposed_ILogger() =>
builder.AddPaths("DisposableNotDisposed.ILogger.cs")
.AddReferences(NuGetMetadataReference.MicrosoftExtensionsLoggingPackages(Constants.NuGetLatestVersion).ToArray())
.VerifyNoIssues(); // FN, ILogger is not supported
.VerifyNoIssues();

#if NET

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,31 @@

using SonarAnalyzer.Rules.CSharp;

namespace SonarAnalyzer.Test.Rules
namespace SonarAnalyzer.Test.Rules;

[TestClass]
public class DoNotCopyArraysInPropertiesTest
{
[TestClass]
public class DoNotCopyArraysInPropertiesTest
{
private readonly VerifierBuilder builder = new VerifierBuilder<DoNotCopyArraysInProperties>();
private readonly VerifierBuilder builder = new VerifierBuilder<DoNotCopyArraysInProperties>();

[TestMethod]
public void DoNotCopyArraysInProperties() =>
builder.AddPaths("DoNotCopyArraysInProperties.cs").Verify();
[TestMethod]
public void DoNotCopyArraysInProperties() =>
builder.AddPaths("DoNotCopyArraysInProperties.cs").Verify();

#if NET

[TestMethod]
public void DoNotCopyArraysInProperties_CSharp9() =>
builder.AddPaths("DoNotCopyArraysInProperties.CSharp9.cs")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.Verify();
[TestMethod]
public void DoNotCopyArraysInProperties_CSharp9() =>
builder.AddPaths("DoNotCopyArraysInProperties.CSharp9.cs")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.Verify();

[TestMethod]
public void DoNotCopyArraysInProperties_CSharp12() =>
builder.AddPaths("DoNotCopyArraysInProperties.CSharp12.cs")
.WithOptions(ParseOptionsHelper.FromCSharp12)
.VerifyNoIssues(); // FN, collection initializers are not supported
[TestMethod]
public void DoNotCopyArraysInProperties_CSharp12() =>
builder.AddPaths("DoNotCopyArraysInProperties.CSharp12.cs")
.WithOptions(ParseOptionsHelper.FromCSharp12)
.VerifyNoIssues();

#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class DoNotDecreaseMemberVisibilityTest
public void DoNotDecreaseMemberVisibility_CSharp11() =>
builder.AddPaths("DoNotDecreaseMemberVisibility.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues(); // static interface methods are compliant
.VerifyNoIssues();

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,34 @@

using SonarAnalyzer.Rules.CSharp;

namespace SonarAnalyzer.Test.Rules
namespace SonarAnalyzer.Test.Rules;

[TestClass]
public class DoNotHideBaseClassMethodsTest
{
[TestClass]
public class DoNotHideBaseClassMethodsTest
{
private readonly VerifierBuilder builder = new VerifierBuilder<DoNotHideBaseClassMethods>();
private readonly VerifierBuilder builder = new VerifierBuilder<DoNotHideBaseClassMethods>();

[TestMethod]
public void DoNotHideBaseClassMethods() =>
builder.AddPaths("DoNotHideBaseClassMethods.cs", "DoNotHideBaseClassMethods2.cs")
.WithAutogenerateConcurrentFiles(false)
.Verify();
[TestMethod]
public void DoNotHideBaseClassMethods() =>
builder.AddPaths("DoNotHideBaseClassMethods.cs", "DoNotHideBaseClassMethods2.cs")
.WithAutogenerateConcurrentFiles(false)
.Verify();

#if NET

[TestMethod]
public void DoNotHideBaseClassMethods_CSharp9() =>
builder.AddPaths("DoNotHideBaseClassMethods.CSharp9.cs")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.WithConcurrentAnalysis(false)
.Verify();
[TestMethod]
public void DoNotHideBaseClassMethods_CSharp9() =>
builder.AddPaths("DoNotHideBaseClassMethods.CSharp9.cs")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.WithConcurrentAnalysis(false)
.Verify();

[TestMethod]
public void DoNotHideBaseClassMethods_CSharp11() =>
builder.AddPaths("DoNotHideBaseClassMethods.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues(); // hiding static interface methods is compliant
[TestMethod]
public void DoNotHideBaseClassMethods_CSharp11() =>
builder.AddPaths("DoNotHideBaseClassMethods.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues();

#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,31 @@

using SonarAnalyzer.Rules.CSharp;

namespace SonarAnalyzer.Test.Rules
namespace SonarAnalyzer.Test.Rules;

[TestClass]
public class DoNotOverloadOperatorEqualTest
{
[TestClass]
public class DoNotOverloadOperatorEqualTest
{
private readonly VerifierBuilder builder = new VerifierBuilder<DoNotOverloadOperatorEqual>();
private readonly VerifierBuilder builder = new VerifierBuilder<DoNotOverloadOperatorEqual>();

[TestMethod]
public void DoNotOverloadOperatorEqual() =>
builder.AddPaths("DoNotOverloadOperatorEqual.cs").Verify();
[TestMethod]
public void DoNotOverloadOperatorEqual() =>
builder.AddPaths("DoNotOverloadOperatorEqual.cs").Verify();

#if NET

[TestMethod]
public void DoNotOverloadOperatorEqual_CSharp9() =>
builder.AddPaths("DoNotOverloadOperatorEqual.CSharp9.cs")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.Verify();
[TestMethod]
public void DoNotOverloadOperatorEqual_CSharp9() =>
builder.AddPaths("DoNotOverloadOperatorEqual.CSharp9.cs")
.WithOptions(ParseOptionsHelper.FromCSharp9)
.Verify();

[TestMethod]
public void DoNotOverloadOperatorEqual_CSharp11() =>
builder.AddPaths("DoNotOverloadOperatorEqual.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues(); // overloading as a static interface method is compliant
[TestMethod]
public void DoNotOverloadOperatorEqual_CSharp11() =>
builder.AddPaths("DoNotOverloadOperatorEqual.CSharp11.cs")
.WithOptions(ParseOptionsHelper.FromCSharp11)
.VerifyNoIssues();

#endif

}
}

0 comments on commit 8f4f5f6

Please sign in to comment.