Skip to main content
ANcpLua.Analyzers provides 44 diagnostic rules and 2 refactorings for C# code quality, organized by category.

Design Rules

RuleSeverityDescription
AL0001ErrorProhibit reassignment of primary constructor params
AL0002WarningDon’t repeat negated patterns
AL0006WarningField name conflicts with primary constructor parameter
AL0010InfoType should be partial for source generator support

Reliability Rules

RuleSeverityDescription
AL0003ErrorDon’t divide by constant zero

Usage Rules

RuleSeverityDescription
AL0004WarningUse pattern matching for Span constant comparison
AL0005WarningUse SequenceEqual for Span non-constant comparison
AL0007ErrorGetSchema should be explicitly implemented
AL0008ErrorGetSchema must return null and not be abstract
AL0009ErrorDon’t call IXmlSerializable.GetSchema
AL0025WarningAnonymous function can be made static
AL0026WarningAvoid DateTime.Now/UtcNow, use TimeProvider
AL0027WarningAvoid Newtonsoft.Json, use System.Text.Json

Threading Rules

RuleSeverityDescription
AL0011WarningAvoid lock keyword on non-Lock types (.NET 9+)

OpenTelemetry Rules

RuleSeverityDescription
AL0012WarningDeprecated OTel semantic convention attribute
AL0013InfoMissing telemetry schema URL

Style Rules

RuleSeverityDescription
AL0014WarningPrefer pattern matching for null/zero comparisons
AL0015InfoNormalize null-guard style
AL0016InfoCombine declaration with subsequent null-check

Version Management Rules

RuleSeverityDescription
AL0017WarningHardcoded package version in Directory.Packages.props
AL0018WarningVersion.props not imported in Directory.Build.props

ASP.NET Core Rules

RuleSeverityDescription
AL0020ErrorIFormCollection requires explicit [FromForm] attribute
AL0021ErrorMultiple structured form sources conflict
AL0022ErrorMixed IFormCollection and DTO form binding unsupported
AL0023ErrorType cannot be form-bound (abstract, interface, no constructor)
AL0024Error[FromForm] and [FromBody] conflict on same method

Roslyn Utilities Rules

RuleSeverityDescription
AL0028InfoUse IsEqualTo instead of SymbolEqualityComparer.Equals
AL0029InfoUse HasAttribute instead of GetAttributes() patterns
AL0030InfoUse Implements/InheritsFrom instead of type hierarchy loops
AL0031InfoUse IsMethodNamed/TryGetConstantValue extensions
AL0032InfoUse OrEmpty() instead of null-coalescing
AL0033InfoUse ToImmutableArrayOrEmpty() extension
AL0034InfoUse WhereNotNull() instead of Where(x => x != null)
AL0035InfoUse GetFullyQualifiedName/GetMetadataName()
AL0036WarningUse Guard.NotNull() instead of throw pattern
AL0037WarningUse TryParseInt32/Guid/etc. extensions
AL0038WarningUse GetOrNull/GetOrDefault instead of TryGetValue
AL0039WarningUse EqualsIgnoreCase/StartsWithOrdinal extensions
AL0040WarningUse GetConstructorArgument/GetNamedArgument extensions

AOT/Trim Safety Rules

RuleSeverityDescription
AL0041Error[AotTest]/[TrimTest] must return int
AL0042Warning[AotTest]/[TrimTest] should return 100 on success
AL0043Warning[TrimSafe] code must not call [RequiresUnreferencedCode]
AL0044Warning[AotSafe] code must not call [RequiresDynamicCode]

Refactorings

RuleDescription
AR0001Snake Case To Pascal Case
AR0002Make Static Lambda

Configuration

All rules can be configured via .editorconfig:
[*.cs]
# Disable a rule
dotnet_diagnostic.AL0001.severity = none

# Change severity
dotnet_diagnostic.AL0014.severity = warning

# Enable OpenTelemetry rules as errors in production code
[src/**/*.cs]
dotnet_diagnostic.AL0012.severity = error
dotnet_diagnostic.AL0013.severity = warning

# Relax ASP.NET Core rules in test projects
[tests/**/*.cs]
dotnet_diagnostic.AL0020.severity = none

Rule Severity Levels

SeverityBuild BehaviorUse For
ErrorBreaks buildCritical issues, runtime exceptions
WarningShows in build outputImportant issues to address
InfoIDE only by defaultSuggestions and improvements
NoneDisabledRules not applicable to project