diff --git a/.cursor/rules/csharp-style.md b/.cursor/rules/csharp-style.md index 9a9c298..641404f 100644 --- a/.cursor/rules/csharp-style.md +++ b/.cursor/rules/csharp-style.md @@ -135,7 +135,16 @@ var store = secondScope.ServiceProvider.GetRequiredService(); // - Use **`///` XML doc comments** on public APIs (types and members) when behavior or contracts are not obvious. - **Primary-constructor records:** include a **``** plus **``** for every constructor parameter (Roslynator RCS1139 / RCS1263). Do not leave orphaned `` lines without a summary on the type. -## Null checks (IDE0270) (`*.Tests`) +## Null checks (IDE0270) + +- Prefer **`?? throw`** over `if (x is null) { throw … }` when assigning a non-null local from a nullable expression. + +```csharp +var root = FindDockerComposeRoot() + ?? throw new InvalidOperationException("…"); +``` + +## Test project layout (`*.Tests`) - **Mirror the server project:** place test types under the same relative path as the production code they exercise (e.g. `NeonSprawl.Server/Game/PositionState/PositionStateApi.cs` → `NeonSprawl.Server.Tests/Game/PositionState/PositionStateApiTests.cs`). - Use a namespace that matches the folder tree under the test assembly root, e.g. `NeonSprawl.Server.Tests.Game.PositionState` for files in `Game/PositionState/`.