Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve S2094: Add exceptions #1575

Merged
merged 5 commits into from Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions rules/S2094/csharp/rule.adoc
Expand Up @@ -18,6 +18,22 @@ 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.

----
using Microsoft.AspNetCore.Mvc.RazorPages;

public class EmptyPageModel: PageModel // Compliant - an empty PageModel can be fully functional, the C# code can be in the cshtml file
{
}
----

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

'''
Expand Down
17 changes: 16 additions & 1 deletion rules/S2094/vbnet/rule.adoc
@@ -1,4 +1,4 @@
include::../description.adoc[]
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.

== Noncompliant Code Example

Expand All @@ -18,6 +18,21 @@ Public Interface IEmpty
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.
----
Imports Microsoft.AspNetCore.Mvc.RazorPages

Public Class EmptyPageModel ' Compliant - an empty PageModel can be fully functional, the VB code can be in the vbhtml file
Inherits PageModel
End Class
----

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

'''
Expand Down