ANcpLua.Analyzers 1.5.3

dotnet add package ANcpLua.Analyzers --version 1.5.3
                    
NuGet\Install-Package ANcpLua.Analyzers -Version 1.5.3
                    
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="ANcpLua.Analyzers" Version="1.5.3">
  <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.
<PackageVersion Include="ANcpLua.Analyzers" Version="1.5.3" />
                    
Directory.Packages.props
<PackageReference Include="ANcpLua.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ANcpLua.Analyzers --version 1.5.3
                    
#r "nuget: ANcpLua.Analyzers, 1.5.3"
                    
#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.
#:package ANcpLua.Analyzers@1.5.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ANcpLua.Analyzers&version=1.5.3
                    
Install as a Cake Addin
#tool nuget:?package=ANcpLua.Analyzers&version=1.5.3
                    
Install as a Cake Tool

NuGet Target: .NET Standard 2.0 License: MIT

ANcpLua.Analyzers

Roslyn analyzers for C# code quality, focusing on modern .NET patterns and best practices. Catches common mistakes at compile time with actionable diagnostics and automatic code fixes.

Layer 2 Package: This is a downstream package that uses ANcpLua.NET.Sdk for its build infrastructure. If you use ANcpLua.NET.Sdk, this analyzer package is auto-injected to all your projects.

Installation

dotnet add package ANcpLua.Analyzers

Or add to your project file:

<PackageReference Include="ANcpLua.Analyzers" PrivateAssets="all" />

Rules

Rule Category Description Severity Enabled Code Fix
AL0001 Design Prohibit reassignment of primary constructor parameters ✔️
AL0002 Design Don't repeat negated patterns ⚠️ ✔️ ✔️
AL0003 Reliability Don't divide by constant zero ✔️
AL0004 Usage Use pattern matching for Span constant comparison ⚠️ ✔️ ✔️
AL0005 Usage Use SequenceEqual for Span non-constant comparison ⚠️ ✔️ ✔️
AL0006 Design Field name conflicts with primary constructor parameter ⚠️ ✔️
AL0007 Usage GetSchema should be explicitly implemented ⚠️ ✔️
AL0008 Usage GetSchema must return null and not be abstract ⚠️ ✔️ ✔️
AL0009 Usage Don't call IXmlSerializable.GetSchema ⚠️ ✔️
AL0010 Design Type should be partial for source generator support ℹ️ ✔️
AL0011 Threading Avoid lock keyword on non-Lock types ⚠️ ✔️
AL0012 OpenTelemetry Deprecated semantic convention attribute ⚠️ ✔️ ✔️
AL0013 OpenTelemetry Missing telemetry schema URL ℹ️ ✔️
AL0014 Style Prefer pattern matching for null and zero comparisons ℹ️ ✔️ ✔️
AL0015 Style Normalize null-guard style ℹ️ ✔️ ✔️
AL0016 Style Combine declaration with subsequent null-check ℹ️ ✔️ ✔️
AL0017 VersionManagement Hardcoded package version in Directory.Packages.props ⚠️ ✔️
AL0020 AspNetCore IFormCollection requires explicit [FromForm] ✔️
AL0021 AspNetCore Multiple structured form sources ✔️
AL0022 AspNetCore Mixed form collection and DTO ✔️
AL0023 AspNetCore Unsupported form type ✔️
AL0024 AspNetCore Form and body conflict ✔️

Legend: ❌ Error · ⚠️ Warning · ℹ️ Info

Configuration

Configure rule severity in your .editorconfig:

[*.cs]
# AL0001: Prohibit reassignment of primary constructor parameters
dotnet_diagnostic.AL0001.severity = error

# AL0002: Don't repeat negated patterns
dotnet_diagnostic.AL0002.severity = warning

# AL0003: Don't divide by constant zero
dotnet_diagnostic.AL0003.severity = error

# AL0004: Use pattern matching for Span constant comparison
dotnet_diagnostic.AL0004.severity = warning

# AL0005: Use SequenceEqual for Span non-constant comparison
dotnet_diagnostic.AL0005.severity = warning

# AL0006: Field name conflicts with primary constructor parameter
dotnet_diagnostic.AL0006.severity = warning

# AL0007: GetSchema should be explicitly implemented
dotnet_diagnostic.AL0007.severity = warning

# AL0008: GetSchema must return null and not be abstract
dotnet_diagnostic.AL0008.severity = warning

# AL0009: Don't call IXmlSerializable.GetSchema
dotnet_diagnostic.AL0009.severity = warning

# AL0010: Type should be partial for source generator support
dotnet_diagnostic.AL0010.severity = none

# AL0011: Avoid lock keyword on non-Lock types
dotnet_diagnostic.AL0011.severity = warning

# AL0012: Deprecated semantic convention attribute
dotnet_diagnostic.AL0012.severity = warning

# AL0013: Missing telemetry schema URL
dotnet_diagnostic.AL0013.severity = suggestion

# AL0014: Prefer pattern matching for null and zero comparisons
dotnet_diagnostic.AL0014.severity = suggestion

# AL0015: Normalize null-guard style
dotnet_diagnostic.AL0015.severity = suggestion

# AL0016: Combine declaration with subsequent null-check
dotnet_diagnostic.AL0016.severity = suggestion

# AL0017: Hardcoded package version
dotnet_diagnostic.AL0017.severity = warning

# AL0020-AL0024: ASP.NET Core form binding
dotnet_diagnostic.AL0020.severity = error
dotnet_diagnostic.AL0021.severity = error
dotnet_diagnostic.AL0022.severity = error
dotnet_diagnostic.AL0023.severity = error
dotnet_diagnostic.AL0024.severity = error

Examples

AL0001: Primary Constructor Parameter Reassignment

// Error: Primary constructor parameter 'x' should not be reassigned
public class Example(int x)
{
    public void SetX(int value) => x = value;  // AL0001
}

// Fix: Use a separate field
public class Example(int x)
{
    private int _x = x;
    public void SetX(int value) => _x = value;
}

AL0014: Pattern Matching for Null and Zero Comparisons

// Before: AL0014 triggered
if (x == null) { }
if (x != null) { }
if (count == 0) { }
if (count != 0) { }

// After: Use pattern matching
if (x is null) { }
if (x is not null) { }
if (count is 0) { }
if (count is not 0) { }

Note: This analyzer skips code inside expression trees (Expression<T>) where pattern matching is not supported.

ANcpLua.NET.Sdk Integration

This analyzer is auto-injected when using ANcpLua.NET.Sdk:


<Project Sdk="ANcpLua.NET.Sdk" />

SDK Features You Get "For Free"

Feature Benefit
Auto-injected analyzers ANcpLua.Analyzers + BannedApiAnalyzers
Guard clauses Throw.IfNull() replaces ArgumentNullException.ThrowIfNull()
Banned API enforcement 50+ banned APIs enforced at compile time
Test framework xUnit v3 + AwesomeAssertions auto-configured
Code quality Comprehensive .editorconfig with 100s of rules

Guard Clauses (Auto-Injected)

// Available in all SDK projects - replaces ArgumentNullException.ThrowIfNull
public void Process(string name, List<int> items)
{
    Throw.IfNull(name);                // Auto-captures param name
    Throw.IfNullOrEmpty(items);        // Works on collections
    Throw.IfNullOrWhitespace(name);    // String validation
    Throw.IfOutOfRange(myEnum);        // Enum validation
    Throw.IfLessThan(count, 0);        // Range checks
}

Test Base Classes (SDK Test Projects)

// Analyzer testing - pre-configured with .NET 10 reference assemblies
public class MyAnalyzerTests : AnalyzerTest<MyDiagnosticAnalyzer>
{
    [Fact]
    public Task DetectsIssue() => VerifyAsync("class C { int x = 1 / 0; }");
}

// Integration testing - WebApplicationFactory + FakeLogCollector
public class ApiTests : IntegrationTestBase<Program>
{
    [Fact]
    public async Task GetUsers_ReturnsOk()
    {
        var response = await Client.GetAsync("/api/users");
        response.StatusCode.Should().Be(HttpStatusCode.OK);
    }
}

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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.5.3 31 1/10/2026
1.5.2 36 1/10/2026
1.5.1 255 1/2/2026
1.5.0 83 1/2/2026
1.4.0 87 1/1/2026
1.3.6 86 1/2/2026
1.3.5 83 1/2/2026
1.3.3 90 12/31/2025
1.3.2 85 12/31/2025
1.3.1 83 12/30/2025
1.0.10 93 12/30/2025
1.0.9 89 12/29/2025
1.0.4 851 12/24/2025
1.0.3 160 12/24/2025
1.0.2 163 12/24/2025