From 288928a21f6a7df4439a643f19b2574b87c247c9 Mon Sep 17 00:00:00 2001 From: Tim Pohlmann Date: Thu, 11 Apr 2024 16:44:35 +0200 Subject: [PATCH 1/2] Add more exceptions --- rules/S2094/csharp/rule.adoc | 6 +----- rules/S2094/exceptions-dotnet.adoc | 13 +++++++++++++ rules/S2094/vbnet/rule.adoc | 9 +++------ 3 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 rules/S2094/exceptions-dotnet.adoc diff --git a/rules/S2094/csharp/rule.adoc b/rules/S2094/csharp/rule.adoc index e01bf1734b4..34f7d21cc25 100644 --- a/rules/S2094/csharp/rule.adoc +++ b/rules/S2094/csharp/rule.adoc @@ -22,11 +22,7 @@ public interface IEmpty === Exceptions -Partial classes are ignored entirely, as they are often used with Source Generators. -Subclasses of System.Exception are ignored, as even an empty Exception class can provide useful information by its type name alone. -Subclasses of System.Attribute are ignored, as well as classes which are annotated with attributes. -Subclasses of generic classes are ignored, as even when empty they can be used for type specialization. -Subclasses of certain framework types - like the PageModel class used in ASP.NET Core Razor Pages - are also ignored. +include::../exceptions-dotnet.adoc[] [source,csharp] ---- diff --git a/rules/S2094/exceptions-dotnet.adoc b/rules/S2094/exceptions-dotnet.adoc new file mode 100644 index 00000000000..0986efff458 --- /dev/null +++ b/rules/S2094/exceptions-dotnet.adoc @@ -0,0 +1,13 @@ +Partial classes are ignored entirely, as source generators often use them. + +Classes with names ending in `Command`, `Message`, or `Event` are ignored as messaging libraries often use them. + +Subclasses of `System.Exception` are ignored; even an empty Exception class can provide helpful information by its type name alone. + +Subclasses of `System.Attribute` and classes annotated with attributes are ignored. + +Subclasses of generic classes are ignored, as they can be used for type specialization even when empty. + +Subclasses of certain framework types — like the `PageModel` class used in ASP.NET Core Razor Pages — are ignored. + +Subclass of a class with non-public default constructors are ignored, as they widen the constructor accessibility. \ No newline at end of file diff --git a/rules/S2094/vbnet/rule.adoc b/rules/S2094/vbnet/rule.adoc index 1bc34ea4566..4de99520fff 100644 --- a/rules/S2094/vbnet/rule.adoc +++ b/rules/S2094/vbnet/rule.adoc @@ -1,6 +1,6 @@ == Why is this an issue? -There is no good excuse for an empty class. If it's being used simply as a common extension point, it should be replaced with an ``++Interface++``. If it was stubbed in as a placeholder for future development it should be fleshed-out. In any other case, it should be eliminated. +include::../description.adoc[] === Noncompliant code example @@ -22,11 +22,8 @@ End Interface === Exceptions -Partial classes are ignored entirely, as they are often used with Source Generators. -Subclasses of System.Exception are ignored, as even an empty Exception class can provide useful information by its type name alone. -Subclasses of System.Attribute are ignored, as well as classes which are annotated with attributes. -Subclasses of generic classes are ignored, as even when empty they can be used for type specialization. -Subclasses of certain framework types - like the PageModel class used in ASP.NET Core Razor Pages - are also ignored. +include::../exceptions-dotnet.adoc[] + [source,vbnet] ---- Imports Microsoft.AspNetCore.Mvc.RazorPages From 05f2d8b1f5daf47626dd0a6963ef38744cd5393b Mon Sep 17 00:00:00 2001 From: Tim Pohlmann Date: Mon, 15 Apr 2024 10:37:26 +0200 Subject: [PATCH 2/2] Review 1 --- rules/S2094/exceptions-dotnet.adoc | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/rules/S2094/exceptions-dotnet.adoc b/rules/S2094/exceptions-dotnet.adoc index 0986efff458..e3b3b3f47bf 100644 --- a/rules/S2094/exceptions-dotnet.adoc +++ b/rules/S2094/exceptions-dotnet.adoc @@ -1,13 +1,7 @@ -Partial classes are ignored entirely, as source generators often use them. - -Classes with names ending in `Command`, `Message`, or `Event` are ignored as messaging libraries often use them. - -Subclasses of `System.Exception` are ignored; even an empty Exception class can provide helpful information by its type name alone. - -Subclasses of `System.Attribute` and classes annotated with attributes are ignored. - -Subclasses of generic classes are ignored, as they can be used for type specialization even when empty. - -Subclasses of certain framework types — like the `PageModel` class used in ASP.NET Core Razor Pages — are ignored. - -Subclass of a class with non-public default constructors are ignored, as they widen the constructor accessibility. \ No newline at end of file +- Partial classes are ignored entirely, as source generators often use them. +- Classes with names ending in `Command`, `Message`, or `Event` are ignored as messaging libraries often use them. +- Subclasses of `System.Exception` are ignored; even an empty Exception class can provide helpful information by its type name alone. +- Subclasses of `System.Attribute` and classes annotated with attributes are ignored. +- Subclasses of generic classes are ignored, as they can be used for type specialization even when empty. +- Subclasses of certain framework types — like the `PageModel` class used in ASP.NET Core Razor Pages — are ignored. +- Subclass of a class with non-public default constructors are ignored, as they widen the constructor accessibility. \ No newline at end of file