From 625715ce581f3c3c458112b6ca9c28bf8a96a74e Mon Sep 17 00:00:00 2001 From: = Date: Fri, 7 Aug 2026 21:54:37 +0200 Subject: [PATCH] style: resolve the two open SonarQube issues - WorkspaceRootService (IDE0270): collapse the `is null` guard into a `?? throw` on the await, folding the McpException rationale comment into the single block above the assignment. - ClassDiagramCoverageTests (IDE0028): build the TheoryData via its params constructor instead of a collection initializer. A collection expression also clears IDE0028 but lowers through `new TheoryData([])` plus Add calls, which trips CA1825 (zero-length array allocation). Co-Authored-By: Claude Opus 5 (1M context) --- src/ProjGraph.Mcp/WorkspaceRootService.cs | 11 ++++------- .../ClassDiagramCoverageTests.cs | 6 ++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/ProjGraph.Mcp/WorkspaceRootService.cs b/src/ProjGraph.Mcp/WorkspaceRootService.cs index 47c835c..77a8cd9 100644 --- a/src/ProjGraph.Mcp/WorkspaceRootService.cs +++ b/src/ProjGraph.Mcp/WorkspaceRootService.cs @@ -49,16 +49,13 @@ public async Task TryResolveAsync(string path, McpServer server, Cancell // Resolved into a local: on the per-request revision the roots belong to this request only, // so an overlapping request must not be able to swap them out from under this one. - var roots = await ResolveRootsAsync(server, ct); - - // Every failure below throws McpException: the SDK replaces the message of any other + // + // Every failure from here on throws McpException: the SDK replaces the message of any other // exception type with a generic "An error occurred invoking '…'", so the guidance // (most importantly "provide an absolute path") would never reach the client. - if (roots is null) - { - throw new McpException( + var roots = await ResolveRootsAsync(server, ct) + ?? throw new McpException( "Client does not support workspace roots. Please provide an absolute path."); - } var matches = ResolveMatches(roots, path); diff --git a/tests/ProjGraph.Tests.Unit.ClassDiagram/ClassDiagramCoverageTests.cs b/tests/ProjGraph.Tests.Unit.ClassDiagram/ClassDiagramCoverageTests.cs index d4f4113..3b33904 100644 --- a/tests/ProjGraph.Tests.Unit.ClassDiagram/ClassDiagramCoverageTests.cs +++ b/tests/ProjGraph.Tests.Unit.ClassDiagram/ClassDiagramCoverageTests.cs @@ -59,11 +59,9 @@ public void DiscoverCsFiles_UnreadableSubdirectory_ShouldBeSkippedWithoutFailing result.Should().BeEquivalentTo("/root/Ok.cs"); } - public static TheoryData DirectoryReadFailures => new() - { + public static TheoryData DirectoryReadFailures => new( new UnauthorizedAccessException("denied"), - new IOException("device not ready") - }; + new IOException("device not ready")); [Fact] public void DiscoverCsFiles_UnreadableSubdirectory_ShouldNotStopSiblingDirectories()