meziantou / Meziantou.Analyzer

A Roslyn analyzer to enforce some good practices in C#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MA0053

EngRajabi opened this issue · comments

Version of the Meziantou.Analyzer NuGet package

2.0.109

Rule Identifier

MA0053

Target Framework

net7

C# Language version

C# 11

Description

If you have a class that has children. This roll issues an error

Reproduction Steps

code:

public class BaseErrorRs // Non compliant
{
}

public sealed class ShaparakProviderHarimOtpResponse : BaseErrorRs // compliant
{
}

config
dotnet_diagnostic.MA0053.severity = error
MA0053.public_class_should_be_sealed = true
#MA0053.class_with_virtual_member_should_be_sealed = true
MA0053.exceptions_should_be_sealed = true

Other information

If the class has children, no error should be issued

I cannot reproduce your error.

public class A // no diagnostic as the class cannot be sealed (B inherits from this class)
{
}

public sealed class B : A // compliant as the class is sealed
{
}

Note: A Roslyn analyzer can only analyze a single project at a time and cannot analyze a full solution. So, if the inheritor is in another project, it cannot be found. In this case, you need to manually disable the warning using an attribute or #pragma warnings disable

It is true. The problem is that they are separate from the two projects