Skip to content

Softlr/Suppress

Repository files navigation

.NET Quality Gate Status

Description

This library allows easy suppression of C# code analyzers warnings by defining a bunch of contants for all of the rules. The following analyzers are supported:

Known limitations

ReSharper rules cannot be suppressed with constants defined this way, this is by design.

Installation

Run the following command in Visual Studio Package Manager Console.

Install-Package Softlr.Suppress

Usage

Simply reference specific constant from the Softlr.Suppress class in SuppressMessageAttribute like so

using System.Diagnostics.CodeAnalysis;

[SuppressMessage(Softl.Suppress.CODE_CRACKER, Softlr.Suppress.CC0001)]
[SuppressMessage(Softl.Suppress.FXCOP, Softlr.Suppress.CA1000)]
[SuppressMessage(Softl.Suppress.SONARQUBE, Softlr.Suppress.S100)]
[SuppressMessage(Softl.Suppress.STYLECOP, Softlr.Suppress.SA1001)]
public class MyClass
{
    // ...
}

or use the using static to import all constants

using System.Diagnostics.CodeAnalysis;
using static Softlr.Suppress;

[SuppressMessage(CODE_CRACKER, CC0001)]
[SuppressMessage(FXCOP, CA1000)]
[SuppressMessage(SONARQUBE, S100)]
[SuppressMessage(STYLECOP, SA1001)]
public class MyClass
{
    // ...
}

or, if you are using C# 10 or newer (net6.0+) you can declare the suppression constants as global and not have to reference it again in every file where you need to use any of the constants.

global using System.Diagnostics.CodeAnalysis;
global using static Softlr.Suppress;

[SuppressMessage(CODE_CRACKER, CC0001)]
[SuppressMessage(FXCOP, CA1000)]
[SuppressMessage(SONARQUBE, S100)]
[SuppressMessage(STYLECOP, SA1001)]
public class MyClass
{
    // ...
}

When referencing Softlr.Suppress library in a project that creates a NuGet package the reference for this library doesn't need to be defined as a NuGet dependency. If you are generating NuGet packages with project files, this can be achieved with PrivateAssets metadata.

<PackageReference Include="Softlr.Suppress" Version="1.0.0">
    <PrivateAssets>all</PrivateAssets>
</PackageReference>