From 52d668b0e144a76bf104ec6afc20d8b1179bf412 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sun, 5 May 2024 10:20:00 -0700 Subject: [PATCH 1/2] Switch to static local functions --- src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs | 2 +- src/EditorFeatures/Core.Wpf/Lightup/LightupHelpers.cs | 4 ++-- .../CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs | 2 +- .../CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs | 4 ++-- .../Test/ExpressionCompiler/ExpressionCompilerTestHelpers.cs | 2 +- .../PropertySubPatternCompletionProvider.cs | 2 +- .../GenerateComparisonOperatorsTests.cs | 3 ++- .../AbstractCodeActionOrUserDiagnosticTest_NoEditor.cs | 2 +- src/Tools/BuildBoss/SolutionCheckerUtil.cs | 2 +- .../InProcess/InteractiveWindowInProcess.cs | 2 +- .../Portable/Serialization/SerializerService_Reference.cs | 2 +- src/Workspaces/CoreTest/ObjectSerializationTests.cs | 2 +- .../SolutionTests/SolutionWithSourceGeneratorTests.cs | 3 ++- 13 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs b/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs index 03a2dfe0fdc1a..5c3a2f0b11da4 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/CodeCleanupTests.cs @@ -841,7 +841,7 @@ private static string[] GetSupportedDiagnosticIdsForCodeCleanupService(string la var supportedDiagnostics = enabledDiagnostics.Diagnostics.SelectMany(x => x.DiagnosticIds).ToArray(); return supportedDiagnostics; - EditorTestWorkspace GetTestWorkspaceForLanguage(string language) + static EditorTestWorkspace GetTestWorkspaceForLanguage(string language) { if (language == LanguageNames.CSharp) { diff --git a/src/EditorFeatures/Core.Wpf/Lightup/LightupHelpers.cs b/src/EditorFeatures/Core.Wpf/Lightup/LightupHelpers.cs index fbc7a560ca3a4..6fda65becc9c9 100644 --- a/src/EditorFeatures/Core.Wpf/Lightup/LightupHelpers.cs +++ b/src/EditorFeatures/Core.Wpf/Lightup/LightupHelpers.cs @@ -377,7 +377,7 @@ TResult FallbackAccessor(T instance) private static Action CreateFallbackAction() { - void FallbackAction(T instance) + static void FallbackAction(T instance) { if (instance == null) { @@ -392,7 +392,7 @@ void FallbackAction(T instance) private static Action CreateFallbackAction() { - void FallbackAction(T instance, TArg arg) + static void FallbackAction(T instance, TArg arg) { if (instance == null) { diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs index 3bffa0849dc4e..4a05c589910c3 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionOrUserDiagnosticTest.cs @@ -259,7 +259,7 @@ private static void AddAnalyzerConfigDocumentWithOptions(EditorTestWorkspace wor Assert.True(applied); return; - string GenerateAnalyzerConfigText(OptionsCollectionAlias options) + static string GenerateAnalyzerConfigText(OptionsCollectionAlias options) { var textBuilder = new StringBuilder(); diff --git a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs index 1110ff1c127f4..439c9a71faea2 100644 --- a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs +++ b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs @@ -475,7 +475,7 @@ public void ShouldTryAgain_ObjectDisposedException() [Fact] public void ShouldTryAgain_RPC_E_DISCONNECTED() { - IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize) + static IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize) { Marshal.ThrowExceptionForHR(unchecked((int)0x80010108)); throw ExceptionUtilities.Unreachable(); @@ -489,7 +489,7 @@ IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize) [Fact] public void ShouldTryAgain_Exception() { - IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize) + static IntPtr gmdbpf(AssemblyIdentity assemblyIdentity, out uint uSize) { throw new Exception(); } diff --git a/src/ExpressionEvaluator/Core/Test/ExpressionCompiler/ExpressionCompilerTestHelpers.cs b/src/ExpressionEvaluator/Core/Test/ExpressionCompiler/ExpressionCompilerTestHelpers.cs index c0564d89ed97c..7838bdea83a01 100644 --- a/src/ExpressionEvaluator/Core/Test/ExpressionCompiler/ExpressionCompilerTestHelpers.cs +++ b/src/ExpressionEvaluator/Core/Test/ExpressionCompiler/ExpressionCompilerTestHelpers.cs @@ -547,7 +547,7 @@ internal static void VerifyResolutionRequests(EEMetadataReferenceResolver resolv actual.Free(); expected.Free(); - void sort(ArrayBuilder<(AssemblyIdentity, AssemblyIdentity, int)> builder) + static void sort(ArrayBuilder<(AssemblyIdentity, AssemblyIdentity, int)> builder) { builder.Sort((x, y) => AssemblyIdentityComparer.SimpleNameComparer.Compare(x.Item1.GetDisplayName(), y.Item1.GetDisplayName())); } diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/PropertySubPatternCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/PropertySubPatternCompletionProvider.cs index ec19bbc3cca08..b2bb05471d9c9 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/PropertySubPatternCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/PropertySubPatternCompletionProvider.cs @@ -196,7 +196,7 @@ private static (PropertyPatternClauseSyntax?, ExpressionSyntax?) TryGetPropertyP return default; - bool IsExtendedPropertyPattern(MemberAccessExpressionSyntax memberAccess, [NotNullWhen(true)] out PropertyPatternClauseSyntax? propertyPatternClause) + static bool IsExtendedPropertyPattern(MemberAccessExpressionSyntax memberAccess, [NotNullWhen(true)] out PropertyPatternClauseSyntax? propertyPatternClause) { while (memberAccess.Parent.IsKind(SyntaxKind.SimpleMemberAccessExpression)) { diff --git a/src/Features/CSharpTest/GenerateComparisonOperators/GenerateComparisonOperatorsTests.cs b/src/Features/CSharpTest/GenerateComparisonOperators/GenerateComparisonOperatorsTests.cs index c8b37d02f525e..8fceee7ca29c9 100644 --- a/src/Features/CSharpTest/GenerateComparisonOperators/GenerateComparisonOperatorsTests.cs +++ b/src/Features/CSharpTest/GenerateComparisonOperators/GenerateComparisonOperatorsTests.cs @@ -401,7 +401,8 @@ class C : IComparable, IComparable [||] } """; - string GetFixedCode(string type) + + static string GetFixedCode(string type) => $@"using System; class C : IComparable, IComparable diff --git a/src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionOrUserDiagnosticTest_NoEditor.cs b/src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionOrUserDiagnosticTest_NoEditor.cs index b0bdf4fd1c942..36d372197958c 100644 --- a/src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionOrUserDiagnosticTest_NoEditor.cs +++ b/src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionOrUserDiagnosticTest_NoEditor.cs @@ -262,7 +262,7 @@ private static void AddAnalyzerConfigDocumentWithOptions(TestWorkspace workspace Assert.True(applied); return; - string GenerateAnalyzerConfigText(OptionsCollectionAlias options) + static string GenerateAnalyzerConfigText(OptionsCollectionAlias options) { var textBuilder = new StringBuilder(); diff --git a/src/Tools/BuildBoss/SolutionCheckerUtil.cs b/src/Tools/BuildBoss/SolutionCheckerUtil.cs index 5b63e86c46a2f..92256e6695dc3 100644 --- a/src/Tools/BuildBoss/SolutionCheckerUtil.cs +++ b/src/Tools/BuildBoss/SolutionCheckerUtil.cs @@ -109,7 +109,7 @@ private bool CheckDuplicate(TextWriter textWriter, out Dictionary private bool CheckProjectSystemGuid(TextWriter textWriter, IEnumerable dataList) { - Guid getExpectedGuid(ProjectData data) + static Guid getExpectedGuid(ProjectData data) { var util = data.ProjectUtil; switch (ProjectEntryUtil.GetProjectFileType(data.FilePath)) diff --git a/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/InteractiveWindowInProcess.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/InteractiveWindowInProcess.cs index bf450cd2d9fb9..dd48c32854087 100644 --- a/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/InteractiveWindowInProcess.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/InteractiveWindowInProcess.cs @@ -259,7 +259,7 @@ public async Task VerifyTagsAsync(int expectedCount, CancellationToken can var view = await GetActiveTextViewAsync(cancellationToken); - bool filterTag(IMappingTagSpan tag) + static bool filterTag(IMappingTagSpan tag) { return tag.Tag.GetType().Equals(typeof(TTag)); } diff --git a/src/Workspaces/Core/Portable/Serialization/SerializerService_Reference.cs b/src/Workspaces/Core/Portable/Serialization/SerializerService_Reference.cs index cf1a74cb28203..67102657d9132 100644 --- a/src/Workspaces/Core/Portable/Serialization/SerializerService_Reference.cs +++ b/src/Workspaces/Core/Portable/Serialization/SerializerService_Reference.cs @@ -554,7 +554,7 @@ public override string ToString() Guids={modules.Select(m => GetMetadataGuid(m).ToString()).Join(",")} """; - ImmutableArray GetModules(Metadata? metadata) + static ImmutableArray GetModules(Metadata? metadata) { if (metadata is AssemblyMetadata assemblyMetadata) { diff --git a/src/Workspaces/CoreTest/ObjectSerializationTests.cs b/src/Workspaces/CoreTest/ObjectSerializationTests.cs index 5bbd3ec074128..91a75a4968f72 100644 --- a/src/Workspaces/CoreTest/ObjectSerializationTests.cs +++ b/src/Workspaces/CoreTest/ObjectSerializationTests.cs @@ -596,7 +596,7 @@ private static void TestRoundTripChar(Char ch) [Fact] public void TestRoundTripGuid() { - void test(Guid guid) + static void test(Guid guid) { TestRoundTrip(guid, (w, v) => w.WriteGuid(v), r => r.ReadGuid()); } diff --git a/src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs b/src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs index f8daa66a477e5..049702014b394 100644 --- a/src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs +++ b/src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs @@ -70,7 +70,8 @@ public async Task WithReferencesMethodCorrectlyUpdatesWithEqualReferences(TestHo // reference with another reference that's equal, we correctly update generators. We'll have the underlying generators // be different since two AnalyzerFileReferences that are value equal but different instances would have their own generators as well. const string SharedPath = "Z:\\Generator.dll"; - ISourceGenerator CreateGenerator() => new SingleFileTestGenerator("// StaticContent", hintName: "generated"); + + static ISourceGenerator CreateGenerator() => new SingleFileTestGenerator("// StaticContent", hintName: "generated"); var analyzerReference1 = new TestGeneratorReferenceWithFilePathEquality(CreateGenerator(), SharedPath); var analyzerReference2 = new TestGeneratorReferenceWithFilePathEquality(CreateGenerator(), SharedPath); From f2cb226dbd8c25740c6a22933d16fa038898e72c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sun, 5 May 2024 10:21:26 -0700 Subject: [PATCH 2/2] Apply suggestions from code review --- .../GenerateComparisonOperatorsTests.cs | 1 - .../CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Features/CSharpTest/GenerateComparisonOperators/GenerateComparisonOperatorsTests.cs b/src/Features/CSharpTest/GenerateComparisonOperators/GenerateComparisonOperatorsTests.cs index 8fceee7ca29c9..5dd27ea025918 100644 --- a/src/Features/CSharpTest/GenerateComparisonOperators/GenerateComparisonOperatorsTests.cs +++ b/src/Features/CSharpTest/GenerateComparisonOperators/GenerateComparisonOperatorsTests.cs @@ -401,7 +401,6 @@ class C : IComparable, IComparable [||] } """; - static string GetFixedCode(string type) => $@"using System; diff --git a/src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs b/src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs index 049702014b394..bb8a74e919e5a 100644 --- a/src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs +++ b/src/Workspaces/CoreTest/SolutionTests/SolutionWithSourceGeneratorTests.cs @@ -70,7 +70,6 @@ public async Task WithReferencesMethodCorrectlyUpdatesWithEqualReferences(TestHo // reference with another reference that's equal, we correctly update generators. We'll have the underlying generators // be different since two AnalyzerFileReferences that are value equal but different instances would have their own generators as well. const string SharedPath = "Z:\\Generator.dll"; - static ISourceGenerator CreateGenerator() => new SingleFileTestGenerator("// StaticContent", hintName: "generated"); var analyzerReference1 = new TestGeneratorReferenceWithFilePathEquality(CreateGenerator(), SharedPath);