Analyzers
The SnowBank.Core and FoundationDB.Client packages include Roslyn analyzers. They run in every project that references the packages, and report code that compiles but fails at run time, can lose data, or does more work than needed. Each diagnostic names the fix. Most have a code fix, in the IDE and through dotnet format analyzers --diagnostics <ID>.
A project that references FoundationDB.Client runs both analyzers. A project that references only SnowBank.Core runs the SBK rules.
| Tier | Severity | IDs |
|---|---|---|
| Fails every time at run time, or does not compile | Error | SBK0xxx, FDB0xxx |
| Can corrupt or lose data | Warning | SBK1xxx, FDB1xxx |
| Correct but slower | Warning | SBK2xxx, FDB2xxx |
The performance rules (SBK2xxx, FDB2xxx) stay quiet in a test project, recognized by a reference to NUnit, xUnit, MSTest or TUnit: a test feeds the plain factories on purpose, to exercise them, and uses the BCL encoders as oracles. The other tiers run in tests too.
Mute a whole tier in .editorconfig:
dotnet_analyzer_diagnostic.category-FdbPerformance.severity = none
dotnet_analyzer_diagnostic.category-SnowBankPerformance.severity = none
A dotnet_diagnostic.<ID>.severity line for one rule takes precedence over the category line.
Rules
| ID | Title | Severity | Analyzer |
|---|---|---|---|
| FDB0001 | IFdbDatabase requested from dependency injection | Error | FoundationDB.Client |
| FDB0002 | Watch created with the transaction's own token | Error | FoundationDB.Client |
| FDB0003 | Watch awaited inside the handler that created it | Error | FoundationDB.Client |
| FDB0100 | Removed API | Error | FoundationDB.Client |
| FDB1001 | Subspace or layer state stored across transactions | Warning (correctness) | FoundationDB.Client |
| FDB1002 | Subspace returned out of a retry-loop handler | Warning (correctness) | FoundationDB.Client |
| FDB1003 | Byte-order atomic on a value that is not a little-endian number | Warning (correctness) | FoundationDB.Client |
| FDB1004 | Id or clock read inside a retry-loop handler | Warning (correctness) | FoundationDB.Client |
| FDB1005 | Missing key tested with Slice.Empty | Warning (correctness) | FoundationDB.Client |
| FDB1006 | Version-stamped key written with Set | Warning (correctness) | FoundationDB.Client |
| FDB2001 | Value built with a Core factory in a transaction write | Warning (performance) | FoundationDB.Client |
| FDB2002 | Key serialized with .ToSlice() before a transaction call | Warning (performance) | FoundationDB.Client |
| FDB2003 | Database obtained only to run a retry loop | Warning (performance) | FoundationDB.Client |
| SBK0001 | Slice.FromStringAscii on text that cannot be encoded | Error | SnowBank.Core |
| SBK0002 | Mutation of a read-only JSON value | Error | SnowBank.Core |
| SBK0100 | Removed API | Error | SnowBank.Core |
| SBK1001 | Pooled buffer escaping its using scope | Warning (correctness) | SnowBank.Core |
| SBK1002 | Binary prefix encoded as UTF-8 text | Warning (correctness) | SnowBank.Core |
| SBK1003 | Null test on a JSON value | Warning (correctness) | SnowBank.Core |
| SBK1004 | Contract.Requires used to validate a public argument | Warning (correctness) | SnowBank.Core |
| SBK2001 | Pooled buffer never returned | Warning (performance) | SnowBank.Core |
| SBK2002 | Slice to byte[] round trip | Warning (performance) | SnowBank.Core |