Design Rules
Reliability Rules
| Rule | Severity | Description |
|---|---|---|
| AL0003 | Error | Don’t divide by constant zero |
Usage Rules
| Rule | Severity | Description |
|---|---|---|
| AL0004 | Warning | Use pattern matching for Span constant comparison |
| AL0005 | Warning | Use SequenceEqual for Span non-constant comparison |
| AL0007 | Error | GetSchema should be explicitly implemented |
| AL0008 | Error | GetSchema must return null and not be abstract |
| AL0009 | Error | Don’t call IXmlSerializable.GetSchema |
| AL0025 | Warning | Anonymous function can be made static |
| AL0026 | Warning | Avoid DateTime.Now/UtcNow, use TimeProvider |
| AL0027 | Warning | Avoid Newtonsoft.Json, use System.Text.Json |
Threading Rules
| Rule | Severity | Description |
|---|---|---|
| AL0011 | Warning | Avoid lock keyword on non-Lock types (.NET 9+) |
OpenTelemetry Rules
Style Rules
Version Management Rules
ASP.NET Core Rules
| Rule | Severity | Description |
|---|---|---|
| AL0020 | Error | IFormCollection requires explicit [FromForm] attribute |
| AL0021 | Error | Multiple structured form sources conflict |
| AL0022 | Error | Mixed IFormCollection and DTO form binding unsupported |
| AL0023 | Error | Type cannot be form-bound (abstract, interface, no constructor) |
| AL0024 | Error | [FromForm] and [FromBody] conflict on same method |
Roslyn Utilities Rules
| Rule | Severity | Description |
|---|---|---|
| AL0028 | Info | Use IsEqualTo instead of SymbolEqualityComparer.Equals |
| AL0029 | Info | Use HasAttribute instead of GetAttributes() patterns |
| AL0030 | Info | Use Implements/InheritsFrom instead of type hierarchy loops |
| AL0031 | Info | Use IsMethodNamed/TryGetConstantValue extensions |
| AL0032 | Info | Use OrEmpty() instead of null-coalescing |
| AL0033 | Info | Use ToImmutableArrayOrEmpty() extension |
| AL0034 | Info | Use WhereNotNull() instead of Where(x => x != null) |
| AL0035 | Info | Use GetFullyQualifiedName/GetMetadataName() |
| AL0036 | Warning | Use Guard.NotNull() instead of throw pattern |
| AL0037 | Warning | Use TryParseInt32/Guid/etc. extensions |
| AL0038 | Warning | Use GetOrNull/GetOrDefault instead of TryGetValue |
| AL0039 | Warning | Use EqualsIgnoreCase/StartsWithOrdinal extensions |
| AL0040 | Warning | Use GetConstructorArgument/GetNamedArgument extensions |
AOT/Trim Safety Rules
Refactorings
Configuration
All rules can be configured via.editorconfig:
Rule Severity Levels
| Severity | Build Behavior | Use For |
|---|---|---|
| Error | Breaks build | Critical issues, runtime exceptions |
| Warning | Shows in build output | Important issues to address |
| Info | IDE only by default | Suggestions and improvements |
| None | Disabled | Rules not applicable to project |
