From c5e6735b7af572c713f91d75ac2988dc6df260ee Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 22 Sep 2025 09:20:32 -0400 Subject: [PATCH] Some more analyzer cleanup (#815) --- dotnet/.editorconfig | 35 ++++++++++--------- .../AgentWebChat.AppHost/ModelExtensions.cs | 6 ++-- .../Components/Pages/Home.razor | 14 ++++---- .../Step04_CodeInterpreter/Program.cs | 2 +- .../Step04_CodeInterpreter/Program.cs | 2 +- .../ExperimentalAttribute.cs | 2 -- .../Interpreter/WorkflowActionVisitor.cs | 8 ++--- .../ObjectModel/QuestionExecutor.cs | 2 +- .../FileSystemJsonCheckpointStore.cs | 4 +-- .../Checkpointing/InputPortInfo.cs | 4 +-- .../Checkpointing/JsonCheckpointStore.cs | 2 +- .../JsonConverterDictionarySupportBase.cs | 5 +-- .../Checkpointing/ScopeKeyConverter.cs | 20 +++++++---- .../WorkflowBuilder.cs | 4 +-- .../A2AHostAgent.cs | 2 -- .../AgentRunResponse.cs | 2 -- .../AssistantClientResultExtensions.cs | 2 -- .../InProcessActorContext.cs | 12 +++---- .../ChatCompletion/ChatClientAgent.cs | 2 -- dotnet/src/Shared/Throw/Throw.cs | 10 ------ .../AgentTests.cs | 4 +-- .../AzureAIAgentsPersistentFixture.cs | 6 ++-- .../CopilotStudioFixture.cs | 3 -- ...CosmosActorStateStorageConcurrencyTests.cs | 4 +-- .../CosmosActorStateStorageTests.cs | 4 +-- .../DeclarativeWorkflowTest.cs | 4 +-- .../Framework/AgentFixture.cs | 2 +- .../PowerFx/WorkflowExpressionEngineTests.cs | 2 +- .../JsonSerializationTests.cs | 8 ++--- .../Sample/02_Simple_Workflow_Condition.cs | 4 +-- .../Sample/03_Simple_Workflow_Loop.cs | 28 +++------------ .../04_Simple_Workflow_ExternalRequest.cs | 2 +- .../SampleSmokeTest.cs | 2 +- .../A2AAgentTests.cs | 2 +- .../AgentThreadTests.cs | 8 +++-- .../AgentProxyTests.cs | 4 +-- .../AgentProxyThreadTests.cs | 2 +- .../JsonSerializationTests.cs | 2 -- .../OpenTelemetryAgentTests.cs | 8 +++-- .../OpenAIAssistantFixture.cs | 4 +-- .../OpenAIChatCompletionFixture.cs | 4 +-- .../OpenAIResponseFixture.cs | 6 ++-- 42 files changed, 100 insertions(+), 153 deletions(-) diff --git a/dotnet/.editorconfig b/dotnet/.editorconfig index 535c42a7f8..7f1d309dc4 100644 --- a/dotnet/.editorconfig +++ b/dotnet/.editorconfig @@ -137,7 +137,6 @@ dotnet_diagnostic.IDE0005.severity = warning # Remove unnecessary using directiv dotnet_diagnostic.IDE0009.severity = warning # Add this or Me qualification dotnet_diagnostic.IDE0011.severity = warning # Add braces dotnet_diagnostic.IDE0018.severity = warning # Inline variable declaration - dotnet_diagnostic.IDE0032.severity = warning # Use auto-implemented property dotnet_diagnostic.IDE0034.severity = warning # Simplify 'default' expression dotnet_diagnostic.IDE0035.severity = warning # Remove unreachable code @@ -153,8 +152,9 @@ dotnet_diagnostic.IDE0073.severity = warning # Require file header dotnet_diagnostic.IDE0082.severity = warning # Convert typeof to nameof dotnet_diagnostic.IDE0090.severity = warning # Simplify new expression dotnet_diagnostic.IDE0161.severity = warning # Use file-scoped namespace +dotnet_diagnostic.IDE0280.severity = warning # Use nameof -dotnet_diagnostic.VSTHRD111.severity = error # Use .ConfigureAwait(bool) +dotnet_diagnostic.VSTHRD111.severity = warning # Use .ConfigureAwait(bool) dotnet_diagnostic.VSTHRD200.severity = warning # Use Async suffix for async methods dotnet_diagnostic.RCS1021.severity = warning # Use expression-bodied lambda. @@ -175,20 +175,21 @@ dotnet_diagnostic.RCS1201.severity = warning # Use method chaining. dotnet_diagnostic.IDE0001.severity = warning # Simplify name dotnet_diagnostic.IDE0002.severity = warning # Simplify member access dotnet_diagnostic.IDE0004.severity = warning # Remove unnecessary cast +dotnet_diagnostic.IDE0032.severity = warning # Use auto property dotnet_diagnostic.IDE0035.severity = warning # Remove unreachable code +dotnet_diagnostic.IDE0047.severity = warning # Parentheses can be removed dotnet_diagnostic.IDE0051.severity = warning # Remove unused private member dotnet_diagnostic.IDE0052.severity = warning # Remove unread private member dotnet_diagnostic.IDE0059.severity = warning # Unnecessary assignment of a value dotnet_diagnostic.IDE0110.severity = warning # Remove unnecessary discards -dotnet_diagnostic.IDE0032.severity = warning # Use auto property -dotnet_diagnostic.IDE0047.severity = warning # Parentheses can be removed -dotnet_diagnostic.IDE1006.severity = error # Naming rule violations +dotnet_diagnostic.IDE1006.severity = warning # Naming rule violations # Suppressed diagnostics dotnet_diagnostic.CA1002.severity = none # Change 'List' in '...' to use 'Collection' ... dotnet_diagnostic.CA1031.severity = none # Do not catch general exception types dotnet_diagnostic.CA1032.severity = none # We're using RCS1194 which seems to cover more ctors dotnet_diagnostic.CA1034.severity = none # Do not nest type. Alternatively, change its accessibility so that it is not externally visible +dotnet_diagnostic.CA1054.severity = none # Uri parameters should not be strings dotnet_diagnostic.CA1062.severity = none # Disable null check, C# already does it for us dotnet_diagnostic.CA1303.severity = none # Do not pass literals as localized parameters dotnet_diagnostic.CA1305.severity = none # Operation could vary based on current user's locale settings @@ -197,12 +198,13 @@ dotnet_diagnostic.CA1508.severity = none # Avoid dead conditional code. Too many dotnet_diagnostic.CA1510.severity = none # ArgumentNullException.Throw dotnet_diagnostic.CA1512.severity = none # ArgumentOutOfRangeException.Throw dotnet_diagnostic.CA1515.severity = none # Making public types from exes internal +dotnet_diagnostic.CA1846.severity = none # Prefer 'AsSpan' over 'Substring' dotnet_diagnostic.CA1848.severity = none # For improved performance, use the LoggerMessage delegates dotnet_diagnostic.CA1849.severity = none # Use async equivalent; analyzer is currently noisy dotnet_diagnostic.CA1865.severity = none # StartsWith(char) dotnet_diagnostic.CA1867.severity = none # EndsWith(char) dotnet_diagnostic.CS1998.severity = none # async method lacks 'await' operators and will run synchronously -dotnet_diagnostic.CA2000.severity = suggestion # Call System.IDisposable.Dispose on object before all references to it are out of scope +dotnet_diagnostic.CA2000.severity = none # Call System.IDisposable.Dispose on object before all references to it are out of scope dotnet_diagnostic.CA2225.severity = none # Operator overloads have named alternates dotnet_diagnostic.CA2227.severity = none # Change to be read-only by removing the property setter dotnet_diagnostic.CA2253.severity = none # Named placeholders in the logging message template should not be comprised of only numeric characters @@ -213,7 +215,9 @@ dotnet_diagnostic.CA5394.severity = none # Do not use insecure sources of random dotnet_diagnostic.VSTHRD003.severity = none # Waiting on thread from another context dotnet_diagnostic.VSTHRD103.severity = none # Use async equivalent; analyzer is currently noisy dotnet_diagnostic.VSTHRD111.severity = none # Use .ConfigureAwait(bool) is hidden by default, set to none to prevent IDE from changing on autosave + dotnet_diagnostic.xUnit1004.severity = none # Test methods should not be skipped. Remove the Skip property to start running the test again. +dotnet_diagnostic.xUnit1042.severity = none # Untyped data rows dotnet_diagnostic.RCS1032.severity = none # Remove redundant parentheses. dotnet_diagnostic.RCS1074.severity = none # Remove redundant constructor. @@ -234,29 +238,28 @@ dotnet_diagnostic.RCS1226.severity = none # Add paragraph to documentation comme dotnet_diagnostic.RCS1229.severity = none # Use async/await when necessary. dotnet_diagnostic.RCS1234.severity = none # Enum duplicate value dotnet_diagnostic.RCS1238.severity = none # Avoid nested ?: operators. -dotnet_diagnostic.RCS1241.severity = none # Implement IComparable when implementing IComparable. +dotnet_diagnostic.RCS1241.severity = none # Implement IComparable when implementing IComparable +dotnet_diagnostic.RCS1246.severity = none # Use element access +dotnet_diagnostic.RCS1261.severity = none # Resource can be disposed asynchronously dotnet_diagnostic.IDE0010.severity = none # Populate switch dotnet_diagnostic.IDE0021.severity = none # Use block body for constructors dotnet_diagnostic.IDE0022.severity = none # Use block body for methods dotnet_diagnostic.IDE0024.severity = none # Use block body for operator -dotnet_diagnostic.IDE0058.severity = none # Remove unused expression value +dotnet_diagnostic.IDE0042.severity = none # Variable declaration can be deconstructed +dotnet_diagnostic.IDE0046.severity = none # if statement can be simplified +dotnet_diagnostic.IDE0056.severity = none # Indexing can be simplified +dotnet_diagnostic.IDE0057.severity = none # Substring can be simplified dotnet_diagnostic.IDE0060.severity = none # Remove unused parameter dotnet_diagnostic.IDE0061.severity = none # Use block body for local function dotnet_diagnostic.IDE0079.severity = none # Remove unnecessary suppression. dotnet_diagnostic.IDE0080.severity = none # Remove unnecessary suppression operator. dotnet_diagnostic.IDE0100.severity = none # Remove unnecessary equality operator dotnet_diagnostic.IDE0130.severity = none # Namespace does not match folder structure -dotnet_diagnostic.IDE0290.severity = none # Use primary constructor dotnet_diagnostic.IDE0160.severity = none # Use block-scoped namespace -dotnet_diagnostic.IDE1006.severity = warning # Naming rule violations -dotnet_diagnostic.IDE0042.severity = none # Variable declaration can be deconstructed -dotnet_diagnostic.IDE0046.severity = suggestion # If statement can be simplified -dotnet_diagnostic.IDE0056.severity = suggestion # Indexing can be simplified -dotnet_diagnostic.IDE0057.severity = suggestion # Substring can be simplified -dotnet_diagnostic.IDE0079.severity = none # Remove unnecessary suppression dotnet_diagnostic.IDE0290.severity = none # Use primary constructor -dotnet_diagnostic.IDE0046.severity = none # if statement can be simplified +dotnet_diagnostic.IDE0305.severity = none # ToList can be simplified +dotnet_diagnostic.IDE0330.severity = none # Use 'System.Threading.Lock' # Testing dotnet_diagnostic.Moq1400.severity = none # Explicitly choose a mocking behavior instead of relying on the default (Loose) behavior diff --git a/dotnet/samples/AgentWebChat/AgentWebChat.AppHost/ModelExtensions.cs b/dotnet/samples/AgentWebChat/AgentWebChat.AppHost/ModelExtensions.cs index a44e9734f4..40237ef360 100644 --- a/dotnet/samples/AgentWebChat/AgentWebChat.AppHost/ModelExtensions.cs +++ b/dotnet/samples/AgentWebChat/AgentWebChat.AppHost/ModelExtensions.cs @@ -115,7 +115,7 @@ public static class ModelExtensions new("ConnectionString", csTask.Result ) { IsSensitive = true } ] }); -#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits +#pragma warning restore VSTHRD002 } builder.Resource.UnderlyingResource = builder.Resource; @@ -175,7 +175,7 @@ public static class ModelExtensions new("ConnectionString", csTask.Result ) { IsSensitive = true } ] }); -#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits +#pragma warning restore VSTHRD002 } builder.Resource.UnderlyingResource = builder.Resource; @@ -214,7 +214,7 @@ public static class ModelExtensions new("ConnectionString", csTask.Result ) { IsSensitive = true } ] }); -#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits +#pragma warning restore VSTHRD002 } builder.Resource.UnderlyingResource = builder.Resource; diff --git a/dotnet/samples/AgentWebChat/AgentWebChat.Web/Components/Pages/Home.razor b/dotnet/samples/AgentWebChat/AgentWebChat.Web/Components/Pages/Home.razor index ae7932d566..c7dad1acbd 100644 --- a/dotnet/samples/AgentWebChat/AgentWebChat.Web/Components/Pages/Home.razor +++ b/dotnet/samples/AgentWebChat/AgentWebChat.Web/Components/Pages/Home.razor @@ -37,7 +37,7 @@ } - @if (!string.IsNullOrEmpty(selectedAgentName) && currentConversation == null) + @if (!string.IsNullOrEmpty(selectedAgentName) && currentConversation is null) {