CodeQualityEnforcer 1.0.0
dotnet add package CodeQualityEnforcer --version 1.0.0
NuGet\Install-Package CodeQualityEnforcer -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeQualityEnforcer" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeQualityEnforcer --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CodeQualityEnforcer, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CodeQualityEnforcer as a Cake Addin #addin nuget:?package=CodeQualityEnforcer&version=1.0.0 // Install CodeQualityEnforcer as a Cake Tool #tool nuget:?package=CodeQualityEnforcer&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CodeQualityEnforcer
A zero-dependency NuGet package that enforces code quality rules in your .NET projects, including nullable reference types and method complexity limits.
Features
- Enables and enforces nullable reference types
- Limits method complexity to a maximum of 15 (matching SonarQube's default)
- Converts violations to compiler errors
- No runtime dependencies
- Compatible with all .NET projects supporting nullable reference types (C# 8.0+)
Installation
Install via NuGet Package Manager:
Install-Package CodeQualityEnforcer
Or using the .NET CLI:
dotnet add package CodeQualityEnforcer
What It Does
- Enforces Nullable Reference Types:
// Will not compile:
public class User
{
public string Name { get; set; } // Error: Must be nullable or initialized
}
// Fixed version:
public class User
{
public string Name { get; set; } = "";
// Or:
public string? Name { get; set; }
}
- Limits Method Complexity:
// Will not compile - too complex
public void ComplexMethod(int value)
{
if (value > 0)
for (int i = 0; i < value; i++)
if (i % 2 == 0)
foreach (var item in items)
if (item.IsValid)
try {
if (item.Value > 0)
while (item.Process())
if (item.Status)
// More nested conditions...
} catch {
// Error handling...
}
}
// Better version - split into smaller methods
public void ProcessItems(int value)
{
if (value <= 0) return;
for (int i = 0; i < value; i++)
{
if (i % 2 == 0)
{
ProcessValidItems(items);
}
}
}
private void ProcessValidItems(IEnumerable<Item> items)
{
foreach (var item in items.Where(i => i.IsValid))
{
ProcessSingleItem(item);
}
}
private void ProcessSingleItem(Item item)
{
// Process single item logic...
}
Requirements
- .NET projects that support nullable reference types (C# 8.0 or later)
- For .NET Core 3.1+ or .NET 5+
License
MIT
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 30 | 1/14/2025 |