diff --git a/analyzers/rspec/cs/S1144.html b/analyzers/rspec/cs/S1144.html index 9284f1debd9..206e9a052a7 100644 --- a/analyzers/rspec/cs/S1144.html +++ b/analyzers/rspec/cs/S1144.html @@ -3,6 +3,23 @@

Why is this an issue?

A type or member that is never called is dead code, and should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

This rule detects type or members that are never referenced from inside a translation unit, and cannot be referenced from the outside.

+

Exceptions

+

This rule doesn’t raise issues on:

+

Code examples

Noncompliant code example

@@ -30,22 +47,6 @@ 

Compliant solution

private class UsedClass {...} }
-

Exceptions

-

This rule doesn’t raise issues on:

-

Resources

Documentation

By enforcing the presence of assertions, this rule aims to enhance the reliability and comprehensiveness of tests by ensuring that they provide @@ -26,7 +27,8 @@

Exceptions

Test methods that include a call to a custom assertion method will not raise any issues.

How to fix it

To address this issue, you should include assertions to validate the expected behavior. Choose an appropriate assertion method provided by your -testing framework (such as MSTest, NUnit, xUnit) or select a suitable assertion library like FluentAssertions, NFluent, NSubstitute, or Shouldly.

+testing framework (such as MSTest, NUnit, xUnit) or select a suitable assertion library like FluentAssertions, NFluent, NSubstitute, Moq, or +Shouldly.

In addition to using built-in assertion methods, you also have the option to create custom assertion methods. To do this, declare an attribute named [AssertionMethodAttribute] and apply it to the respective method. This allows you to encapsulate specific validation logic within your custom assertion methods without raising the issue. Here’s an example:

diff --git a/analyzers/rspec/cs/S3247.html b/analyzers/rspec/cs/S3247.html index 2b77c694187..9779a1f6057 100644 --- a/analyzers/rspec/cs/S3247.html +++ b/analyzers/rspec/cs/S3247.html @@ -1,27 +1,41 @@

Why is this an issue?

-

Because the is operator performs a cast if the object is not null, using is to check type and then casting the same -argument to that type, necessarily performs two casts. The same result can be achieved more efficiently with a single cast using as, -followed by a null-check.

-

Noncompliant code example

-
+

In C#, the is +type testing operator can be used to check if the run-time type of an object is compatible with a given type. If the object is not null, then the +is operator performs a cast, and so performing another cast following the check result is redundant.

+

This can impact:

+ +

How to fix it

+

Use pattern macthing to perform the check +and retrieve the cast result.

+

Code examples

+

Noncompliant code example

+
 if (x is Fruit)  // Noncompliant
 {
   var f = (Fruit)x; // or x as Fruit
   // ...
 }
 
-

Compliant solution

-
-// C# 6
-var f = x as Fruit;
-if (f != null)
-{
-  // ...
-}
-// C# 7
+

Compliant solution

+
 if (x is Fruit fruit)
 {
   // ...
 }
 
+

Resources

+

Documentation

+ diff --git a/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json b/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json index 8365c7c6a1f..b22ee121e7f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json +++ b/analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json @@ -3,7 +3,7 @@ "languages": [ "CSH" ], - "latest-update": "2024-06-24T13:02:32.572091600Z", + "latest-update": "2024-07-11T14:36:23.720511300Z", "options": { "no-language-in-filenames": true } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json b/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json index dd65fd75807..0077de6372a 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json +++ b/analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json @@ -3,7 +3,7 @@ "languages": [ "VBNET" ], - "latest-update": "2024-06-24T13:03:10.676891100Z", + "latest-update": "2024-07-11T14:37:00.682263800Z", "options": { "no-language-in-filenames": true }