ANcpLua.Analyzers
1.3.5
See the version list below for details.
dotnet add package ANcpLua.Analyzers --version 1.3.5
NuGet\Install-Package ANcpLua.Analyzers -Version 1.3.5
<PackageReference Include="ANcpLua.Analyzers" Version="1.3.5"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ANcpLua.Analyzers" Version="1.3.5" />
<PackageReference Include="ANcpLua.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ANcpLua.Analyzers --version 1.3.5
#r "nuget: ANcpLua.Analyzers, 1.3.5"
#:package ANcpLua.Analyzers@1.3.5
#addin nuget:?package=ANcpLua.Analyzers&version=1.3.5
#tool nuget:?package=ANcpLua.Analyzers&version=1.3.5
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.
Installation
dotnet add package ANcpLua.Analyzers
Or add to your project file:
<PackageReference Include="ANcpLua.Analyzers" Version="1.4.0" 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 | ⚠️ | ✔️ |
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
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 Checks
// Before: AL0014 triggered
if (x == null) { }
if (x != null) { }
// After: Use pattern matching
if (x is null) { }
if (x is not null) { }
Documentation
See the docs folder for detailed documentation on each rule, including examples and fix guidance.
ANcpLua.NET.Sdk Integration
This analyzer is auto-injected when using ANcpLua.NET.Sdk:
<Project Sdk="ANcpLua.NET.Sdk/1.3.18" />
SDK Features You Get "For Free"
| Feature | Benefit |
|---|---|
| Auto-injected analyzers | ANcpLua.Analyzers + BannedApiAnalyzers |
| Guard clauses | Throw.IfNull() replaces ArgumentNullException.ThrowIfNull() |
| Banned API enforcement | DateTime.Now, FluentAssertions, and 50+ APIs blocked |
| 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 { void M() { DateTime.Now; } }");
}
// 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);
}
}
Related Projects
- ANcpLua.NET.Sdk - MSBuild SDK that auto-injects this analyzer
- ANcpLua.Roslyn.Utilities - Roslyn utilities for source generators
License
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.Sbom.Targets (>= 4.1.5)
-
net10.0
- Microsoft.Sbom.Targets (>= 4.1.5)
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.6.13 | 57 | 1/18/2026 |
| 1.6.12 | 45 | 1/18/2026 |
| 1.6.11 | 53 | 1/18/2026 |
| 1.6.10 | 48 | 1/17/2026 |
| 1.6.7 | 42 | 1/16/2026 |
| 1.6.6 | 116 | 1/14/2026 |
| 1.6.5 | 89 | 1/14/2026 |
| 1.6.4 | 79 | 1/14/2026 |
| 1.6.3 | 80 | 1/14/2026 |
| 1.6.2 | 81 | 1/14/2026 |
| 1.6.1 | 352 | 1/14/2026 |
| 1.6.0 | 96 | 1/13/2026 |
| 1.5.3 | 123 | 1/10/2026 |
| 1.5.2 | 82 | 1/10/2026 |
| 1.5.1 | 274 | 1/2/2026 |
| 1.5.0 | 85 | 1/2/2026 |
| 1.4.0 | 88 | 1/1/2026 |
| 1.3.6 | 87 | 1/2/2026 |
| 1.3.5 | 84 | 1/2/2026 |
| 1.3.3 | 91 | 12/31/2025 |
| 1.3.2 | 87 | 12/31/2025 |
| 1.3.1 | 89 | 12/30/2025 |
| 1.0.10 | 94 | 12/30/2025 |
| 1.0.9 | 93 | 12/29/2025 |
| 1.0.4 | 853 | 12/24/2025 |
| 1.0.3 | 162 | 12/24/2025 |
| 1.0.2 | 163 | 12/24/2025 |