Skip to content

Commit

Permalink
Promote S4052 to Sonar way (#4134)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsolt-kolbay-sonarsource authored Aug 9, 2024
1 parent a36ad0a commit f4259f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion rules/S4052/csharp/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"sqKey": "S4052",
"scope": "All",
"defaultQualityProfiles": [

"Sonar way"
],
"quickfix": "unknown"
}
37 changes: 18 additions & 19 deletions rules/S4052/csharp/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
== Why is this an issue?

With the advent of .NET framework version 2, certain practices have become obsolete.

In particular, exceptions should now extend ``++System.Exception++`` instead of ``++System.ApplicationException++``. Similarly, generic collections should be used instead of the older, non-generic, ones. Finally when creating an XML view, you should not extend ``++System.Xml.XmlDocument++``.
With the advent of .NET Framework 2.0, certain practices and types have become obsolete.

In particular, exceptions should now extend `System.Exception` instead of `System.ApplicationException`. Similarly, generic collections should be used instead of the older, non-generic, ones. Finally when creating an XML view, you should not extend `System.Xml.XmlDocument`.
This rule raises an issue when an externally visible type extends one of these types:

* ``++System.ApplicationException++``
* ``++System.Xml.XmlDocument++``
* ``++System.Collections.CollectionBase++``
* ``++System.Collections.DictionaryBase++``
* ``++System.Collections.Queue++``
* ``++System.Collections.ReadOnlyCollectionBase++``
* ``++System.Collections.SortedList++``
* ``++System.Collections.Stack++``
* https://learn.microsoft.com/en-us/dotnet/api/system.applicationexception[System.ApplicationException]
* https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmldocument[System.Xml.XmlDocument]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.collectionbase[System.Collections.CollectionBase]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.dictionarybase[System.Collections.DictionaryBase]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.queue[System.Collections.Queue]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.readonlycollectionbase[System.Collections.ReadOnlyCollectionBase]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.sortedlist[System.Collections.SortedList]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.stack[System.Collections.Stack]
== How to fix it

=== Code examples

=== Noncompliant code example
==== Noncompliant code example

[source,csharp]
[source,csharp,diff-id=1,diff-type=noncompliant]
----
using System;
using System.Collections;
Expand All @@ -31,13 +33,12 @@ namespace MyLibrary
}
----

==== Compliant solution

=== Compliant solution

[source,csharp]
[source,csharp,diff-id=1,diff-type=compliant]
----
using System;
using System.Collections;
using System.Collections.ObjectModel;
namespace MyLibrary
{
Expand All @@ -47,7 +48,6 @@ namespace MyLibrary
}
----


ifdef::env-github,rspecator-view[]

'''
Expand All @@ -58,5 +58,4 @@ ifdef::env-github,rspecator-view[]

Refactor this type not to derive from an outdated type '{0}'.


endif::env-github,rspecator-view[]

0 comments on commit f4259f2

Please sign in to comment.