From 6bc7e682c579c60d763abfd0a55c8f330ef4150f Mon Sep 17 00:00:00 2001 From: Stuart Meeks Date: Sat, 22 Aug 2026 02:18:47 +0000 Subject: [PATCH] fix: bind using directly to constructed TestConsole (cs/local-not-disposed) The build-mode: none CodeQL run reopened cs/local-not-disposed on the Width(120) test: `using var test = new TestConsole().Width(120)` binds the using to Width()'s return value, and CodeQL cannot prove a fluent method returns its receiver, so it saw the `new TestConsole()` as an undisposed disposable. Split the fluent call onto its own statement so the using binds directly to the construction. Behaviour-preserving; 80/80 tests pass on both TFMs. Co-Authored-By: Claude Opus 4.8 --- CHANGELOG.md | 5 ++++- .../SplashScreenTests.cs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87da8e7..e437c74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `char.IsAsciiHexDigit`, which is available on both shipped target frameworks and reads as the intent. The two `TestConsole` instances in `SplashScreenTests` are now disposed via `using` (`cs/local-not-disposed`); `TestConsole` is `IDisposable` and both were - leaking. No behaviour, public API or rendered output changed. + leaking. The `Width(120)` call is now a separate statement rather than chained into the + `using` initializer, so the `using` binds directly to the constructed console — CodeQL + cannot prove a fluent method returns its receiver, so the chained form left the + construction flagged as undisposed. No behaviour, public API or rendered output changed. ### Changed diff --git a/tests/NextIteration.SpectreConsole.Splash.Tests/SplashScreenTests.cs b/tests/NextIteration.SpectreConsole.Splash.Tests/SplashScreenTests.cs index 4905c19..1941850 100644 --- a/tests/NextIteration.SpectreConsole.Splash.Tests/SplashScreenTests.cs +++ b/tests/NextIteration.SpectreConsole.Splash.Tests/SplashScreenTests.cs @@ -49,7 +49,8 @@ public void Show_writes_to_AnsiConsole() public void Show_with_custom_tagline_emits_it() { var prev = AnsiConsole.Console; - using var test = new TestConsole().Width(120); + using var test = new TestConsole(); + test.Width(120); AnsiConsole.Console = test; try {