Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CA1822 in Visual Studio layer #50569

Merged
merged 28 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e1e9fa4
Enable CA1822 in Visual Studio layer
Youssef1313 Jan 17, 2021
96b0f6d
Update .editorconfig
Youssef1313 Jan 17, 2021
3c4382c
Fix CA1822 - iteration 1
Youssef1313 Jan 18, 2021
012325b
Fix CA1822 - iteration 2
Youssef1313 Jan 18, 2021
bc63693
Fix CA1822 - iteration 3
Youssef1313 Jan 18, 2021
8bf9c81
Fix CA1822 - iteration 4
Youssef1313 Jan 18, 2021
376b670
Fix CA1822 - iteration 5
Youssef1313 Jan 18, 2021
ec7382b
Fix CA1822 - iteration 6
Youssef1313 Jan 18, 2021
f0ea7a3
Fix CA1822 - iteration 7
Youssef1313 Jan 18, 2021
99befa1
Fix CA1822 - iteration 8
Youssef1313 Jan 18, 2021
de87ad7
Fix CA1822 - iteration 9
Youssef1313 Jan 18, 2021
c768901
Fix CA1822 - iteration 10
Youssef1313 Jan 18, 2021
139a937
Fix CA1822 - iteration 11
Youssef1313 Jan 18, 2021
d1183c9
Fix CA1822 - iteration 12
Youssef1313 Jan 18, 2021
5120f0e
Fix CA1822 - iteration 13
Youssef1313 Jan 18, 2021
55a6db8
Fix CA1822 - iteration 14
Youssef1313 Jan 18, 2021
d476569
Fix CA1822 - iteration 15
Youssef1313 Jan 18, 2021
d09960c
Merge branch 'main' into patch-43
Youssef1313 Jan 14, 2022
2dddbbc
Remove redundant option
Youssef1313 Jan 14, 2022
2ce0f30
Resolve missing conflict
Youssef1313 Jan 14, 2022
e7ad72d
More fixes
Youssef1313 Jan 14, 2022
46d0e54
One more method
Youssef1313 Jan 15, 2022
fad6bfc
Update AbstractCodeCleanUpFixer.cs
Youssef1313 Jan 17, 2022
32d502a
Update CodeDefinitionWindow_InProc.cs
Youssef1313 Jan 18, 2022
a77a092
Update MoveStaticMembersViewModelTest.vb
Youssef1313 Jan 18, 2022
1dc81f8
Update InteractiveWindow_InProc.cs
Youssef1313 Jan 19, 2022
4cae7ce
Update MoveStaticMembersViewModelTest.vb
Youssef1313 Jan 19, 2022
defb193
Update AbstractPersistentStorageTests.cs
Youssef1313 Jan 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/VisualStudio/CSharp/Test/GlyphExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void TestWithEventsMemberGlyph()
isWithEvents: true);
}

private void TestGlyph(
private static void TestGlyph(
StandardGlyphGroup expectedGlyphGroup,
SymbolKind kind = SymbolKind.Method,
Accessibility declaredAccessibility = Accessibility.NotApplicable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Interactive.Commands
[UseExportProvider]
public class ResetInteractiveTests
{
private string WorkspaceXmlStr =>
private const string WorkspaceXmlStr =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change to const.

@"<Workspace>
<Project Language=""Visual Basic"" AssemblyName=""ResetInteractiveVisualBasicSubproject"" CommonReferences=""true"">
<Document FilePath=""VisualBasicDocument""></Document>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public object GetService(Type serviceType)
}
}

private string GetText(AbstractOptionPreviewViewModel viewModel)
private static string GetText(AbstractOptionPreviewViewModel viewModel)
{
return viewModel.TextViewHost.TextView.TextBuffer.CurrentSnapshot.GetText().ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ public void Dispose()
_persistentFolderRoot.Dispose();
}

private string GetData1(Size size)
private static string GetData1(Size size)
=> size == Size.Small ? SmallData1 : size == Size.Medium ? MediumData1 : LargeData1;

private string GetData2(Size size)
private static string GetData2(Size size)
=> size == Size.Small ? SmallData2 : size == Size.Medium ? MediumData2 : LargeData2;

private Checksum? GetChecksum1(bool withChecksum)
private static Checksum? GetChecksum1(bool withChecksum)
=> withChecksum ? s_checksum1 : null;

private Checksum? GetChecksum2(bool withChecksum)
private static Checksum? GetChecksum2(bool withChecksum)
=> withChecksum ? s_checksum2 : null;

[Fact]
Expand Down Expand Up @@ -248,7 +248,7 @@ public async Task PersistentService_Document_SimultaneousWrites()
Assert.True(value < NumThreads);
}

private void DoSimultaneousWrites(Func<string, Task> write)
private static void DoSimultaneousWrites(Func<string, Task> write)
{
var barrier = new Barrier(NumThreads);
var countdown = new CountdownEvent(NumThreads);
Expand Down Expand Up @@ -812,7 +812,7 @@ public TestPersistentStorageLocationService()
public override bool IsSupported(Workspace workspace) => true;
}

private void DoSimultaneousReads(Func<Task<string>> read, string expectedValue)
private static void DoSimultaneousReads(Func<Task<string>> read, string expectedValue)
{
var barrier = new Barrier(NumThreads);
var countdown = new CountdownEvent(NumThreads);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static IEnumerable<AnalyzerPerformanceInfo> CreateSnapshots(Dictionary<s
}
}

private (Dictionary<string, double[]> matrix, int dataCount) CreateMatrix(string testFile)
private static (Dictionary<string, double[]> matrix, int dataCount) CreateMatrix(string testFile)
{
var matrix = new Dictionary<string, double[]>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ public class A
Assert.False(ignorableAssemblyList.Includes(alpha))
End Sub

Private Function BuildLibrary(directory As DisposableDirectory, fileContents As String, libraryName As String, ParamArray referenceNames As String()) As String
Private Shared Function BuildLibrary(directory As DisposableDirectory, fileContents As String, libraryName As String, ParamArray referenceNames As String()) As String
Dim sourceFile = directory.CreateFile(libraryName + ".cs").WriteAllText(fileContents).Path
Dim tempOut = Path.Combine(directory.Path, libraryName + ".out")
Dim libraryOut = Path.Combine(directory.Path, libraryName + ".dll")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class MyClass
Assert.True(viewModel.TrySubmit())
End Sub

Private Sub AssertTypeBindingIconAndTextIs(viewModel As AddParameterDialogViewModel, currentIcon As String, expectedMessage As String)
Private Shared Sub AssertTypeBindingIconAndTextIs(viewModel As AddParameterDialogViewModel, currentIcon As String, expectedMessage As String)
Assert.True(viewModel.TypeIsEmptyImage = If(NameOf(viewModel.TypeIsEmptyImage) = currentIcon, Visibility.Visible, Visibility.Collapsed))
Assert.True(viewModel.TypeDoesNotParseImage = If(NameOf(viewModel.TypeDoesNotParseImage) = currentIcon, Visibility.Visible, Visibility.Collapsed))
Assert.True(viewModel.TypeDoesNotBindImage = If(NameOf(viewModel.TypeDoesNotBindImage) = currentIcon, Visibility.Visible, Visibility.Collapsed))
Expand All @@ -262,7 +262,7 @@ class MyClass
Assert.Equal(expectedMessage, viewModel.TypeBindsDynamicStatus)
End Sub

Private Sub VerifyOpeningState(viewModel As AddParameterDialogViewModel)
Private Shared Sub VerifyOpeningState(viewModel As AddParameterDialogViewModel)
Assert.True(viewModel.TypeBindsDynamicStatus = ServicesVSResources.Please_enter_a_type_name)

Assert.True(viewModel.TypeIsEmptyImage = Visibility.Visible)
Expand All @@ -285,7 +285,7 @@ class MyClass
Assert.Equal(ServicesVSResources.A_type_and_name_must_be_provided, message)
End Sub

Private Function GetViewModelTestStateAsync(
Private Shared Function GetViewModelTestStateAsync(
markup As XElement,
languageName As String) As AddParameterViewModelTestState

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,23 +393,23 @@ class Goo

End Sub

Private Sub AssertPermuted(permutation As Integer(), actualParameterList As List(Of ChangeSignatureDialogViewModel.ParameterViewModel), originalParameterList As ImmutableArray(Of IParameterSymbol))
Private Shared Sub AssertPermuted(permutation As Integer(), actualParameterList As List(Of ChangeSignatureDialogViewModel.ParameterViewModel), originalParameterList As ImmutableArray(Of IParameterSymbol))
Dim finalParameterList = actualParameterList.Where(Function(p) Not p.IsRemoved)
For index = 0 To permutation.Length - 1
Dim expected = originalParameterList(permutation(index))
Assert.Equal(expected, DirectCast(finalParameterList(index), ExistingParameterViewModel).ParameterSymbol)
Next
End Sub

Private Sub VerifyOpeningState(viewModel As ChangeSignatureDialogViewModel, openingSignatureDisplay As String)
Private Shared Sub VerifyOpeningState(viewModel As ChangeSignatureDialogViewModel, openingSignatureDisplay As String)
Assert.Equal(openingSignatureDisplay, viewModel.TEST_GetSignatureDisplayText())
Dim message As String = Nothing
Assert.False(viewModel.CanSubmit(message))
Assert.Equal(ServicesVSResources.You_must_change_the_signature, message)
Assert.False(viewModel.CanMoveUp)
End Sub

Private Sub VerifyParameterInfo(
Private Shared Sub VerifyParameterInfo(
viewModel As ChangeSignatureDialogViewModel,
parameterIndex As Integer,
Optional modifier As String = Nothing,
Expand Down Expand Up @@ -446,7 +446,7 @@ class Goo
End If
End Sub

Private Async Function GetViewModelTestStateAsync(
Private Shared Async Function GetViewModelTestStateAsync(
markup As XElement,
languageName As String) As Tasks.Task(Of ChangeSignatureViewModelTestState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ClassView

#End Region

Private Sub Test(
Private Shared Sub Test(
workspaceDefinition As XElement,
ParamArray presentationNodes As NodeVerifier()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,13 +1109,13 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CodeModel
End Sub)
End Sub

Private Sub TestAllParameterNamesByName(parameters As EnvDTE.CodeElements, expectedParameterNames() As String)
Private Shared Sub TestAllParameterNamesByName(parameters As EnvDTE.CodeElements, expectedParameterNames() As String)
For index = 0 To expectedParameterNames.Count() - 1
Assert.NotNull(parameters.Item(expectedParameterNames(index)))
Next
End Sub

Private Sub TestAllParameterNamesByIndex(parameters As EnvDTE.CodeElements, expectedParameterNames() As String)
Private Shared Sub TestAllParameterNamesByIndex(parameters As EnvDTE.CodeElements, expectedParameterNames() As String)
For index = 0 To expectedParameterNames.Count() - 1
' index + 1 for Item because Parameters are not zero indexed
Assert.Equal(expectedParameterNames(index), parameters.Item(index + 1).Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.CommonControls
Assert.False(FindMemberByName("FooEvent", viewModel.Members).IsChecked)
End Function

Private Function FindMemberByName(name As String, memberArray As ImmutableArray(Of PullMemberUpSymbolViewModel)) As PullMemberUpSymbolViewModel
Private Shared Function FindMemberByName(name As String, memberArray As ImmutableArray(Of PullMemberUpSymbolViewModel)) As PullMemberUpSymbolViewModel
Dim member = memberArray.FirstOrDefault(Function(memberViewModel) memberViewModel.SymbolName.Equals(name))
If (member Is Nothing) Then
Assert.True(False, $"No member called {name} found")
End If
Return member
End Function

Private Async Function GetViewModelAsync(markup As XElement, languageName As String) As Task(Of MemberSelectionViewModel)
Private Shared Async Function GetViewModelAsync(markup As XElement, languageName As String) As Task(Of MemberSelectionViewModel)
Dim workspaceXml =
<Workspace>
<Project Language=<%= languageName %> CommonReferences="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class $$MyClass
monitor.Detach()
End Function

Private Async Function GetViewModelAsync(markup As XElement,
Private Shared Async Function GetViewModelAsync(markup As XElement,
languageName As String,
defaultTypeName As String,
Optional defaultNamespace As String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class C
End Using
End Function

Private Function CreateCSharpSnippetExpansionNoteTestState(xElement As XElement, ParamArray snippetShortcuts As String()) As TestState
Private Shared Function CreateCSharpSnippetExpansionNoteTestState(xElement As XElement, ParamArray snippetShortcuts As String()) As TestState
Dim state = TestStateFactory.CreateCSharpTestState(
xElement,
extraExportedTypes:=New List(Of Type) From {GetType(CSharpMockCompletionProvider), GetType(TestCSharpSnippetInfoService)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ End Class]]></document>
End Using
End Function

Private Function CreateVisualBasicSnippetExpansionNoteTestState(xElement As XElement, ParamArray snippetShortcuts As String()) As TestState
Private Shared Function CreateVisualBasicSnippetExpansionNoteTestState(xElement As XElement, ParamArray snippetShortcuts As String()) As TestState
Dim state = TestStateFactory.CreateVisualBasicTestState(
xElement,
New List(Of Type) From {GetType(VisualBasicMockCompletionProvider), GetType(TestVisualBasicSnippetInfoService)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
End Using
End Function

Private Sub RunCompilerAnalyzer(workspace As TestWorkspace)
Private Shared Sub RunCompilerAnalyzer(workspace As TestWorkspace)
Dim snapshot = workspace.CurrentSolution

Dim analyzerService = Assert.IsType(Of DiagnosticAnalyzerService)(workspace.ExportProvider.GetExportedValue(Of IDiagnosticAnalyzerService)())
Expand All @@ -786,11 +786,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
service.GetTestAccessor().WaitUntilCompletion(workspace, SpecializedCollections.SingletonEnumerable(analyzerService.CreateIncrementalAnalyzer(workspace)).WhereNotNull().ToImmutableArray())
End Sub

Private Function CreateItem(documentId As DocumentId, Optional severity As DiagnosticSeverity = DiagnosticSeverity.Error) As DiagnosticData
Private Shared Function CreateItem(documentId As DocumentId, Optional severity As DiagnosticSeverity = DiagnosticSeverity.Error) As DiagnosticData
Return CreateItem(documentId.ProjectId, documentId, severity)
End Function

Private Function CreateItem(projectId As ProjectId, documentId As DocumentId, Optional severity As DiagnosticSeverity = DiagnosticSeverity.Error, Optional link As String = Nothing) As DiagnosticData
Private Shared Function CreateItem(projectId As ProjectId, documentId As DocumentId, Optional severity As DiagnosticSeverity = DiagnosticSeverity.Error, Optional link As String = Nothing) As DiagnosticData
Return New DiagnosticData(
id:="test",
category:="test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
End Using
End Sub

Private Function CreateItem(documentId As DocumentId) As TodoCommentData
Private Shared Function CreateItem(documentId As DocumentId) As TodoCommentData
Return New TodoCommentData(
priority:=0,
message:="test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public class $$MyClass
Assert.Equal("Goo(string)", viewModel.MemberContainers.ElementAt(4).SymbolName)
End Function

Private Async Function GetViewModelAsync(markup As XElement,
Private Shared Async Function GetViewModelAsync(markup As XElement,
languageName As String,
defaultInterfaceName As String,
Optional defaultNamespace As String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,12 @@ namespace A
File.Delete(pathString)
End Function

Private Function PopulateProjectFolders(list As List(Of String), ParamArray values As String()) As List(Of String)
Private Shared Function PopulateProjectFolders(list As List(Of String), ParamArray values As String()) As List(Of String)
list.AddRange(values)
Return list
End Function

Private Function GetOneProjectWorkspace(
Private Shared Function GetOneProjectWorkspace(
documentContent As XElement,
languageName As String,
projectName As String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.GoToDefinition
<[UseExportProvider]>
Public Class GoToDefinitionApiTests

Private Async Function TestAsync(workspaceDefinition As XElement, expectSuccess As Boolean) As Tasks.Task
Private Shared Async Function TestAsync(workspaceDefinition As XElement, expectSuccess As Boolean) As Tasks.Task
Using workspace = TestWorkspace.Create(workspaceDefinition, composition:=GoToTestHelpers.Composition)
Dim solution = workspace.CurrentSolution
Dim cursorDocument = workspace.Documents.First(Function(d) d.CursorPosition.HasValue)
Expand Down
4 changes: 2 additions & 2 deletions src/VisualStudio/Core/Test/LanguageBlockTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ System.Console$$.WriteLine(message)
", LanguageNames.VisualBasic, SourceCodeKind.Regular)
End Sub

Private Sub VerifyNoBlock(markup As String, languageName As String, Optional sourceCodeKind As SourceCodeKind = SourceCodeKind.Regular)
Private Shared Sub VerifyNoBlock(markup As String, languageName As String, Optional sourceCodeKind As SourceCodeKind = SourceCodeKind.Regular)
Dim xml = <Workspace>
<Project Language=<%= languageName %> CommonReferences="True">
<Document>
Expand All @@ -257,7 +257,7 @@ System.Console$$.WriteLine(message)
End Using
End Sub

Private Sub VerifyBlock(markup As String, languageName As String, expectedDescription As String)
Private Shared Sub VerifyBlock(markup As String, languageName As String, expectedDescription As String)
Dim xml = <Workspace>
<Project Language=<%= languageName %> CommonReferences="True">
<Document>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.MoveToNamespace
Assert.False(viewModel.ShowMessage)
End Sub

Private Function CreateViewModel(Optional defaultNamespace As String = Nothing, Optional availableNamespaces As ImmutableArray(Of String) = Nothing) As MoveToNamespaceDialogViewModel
Private Shared Function CreateViewModel(Optional defaultNamespace As String = Nothing, Optional availableNamespaces As ImmutableArray(Of String) = Nothing) As MoveToNamespaceDialogViewModel
If (defaultNamespace Is Nothing) Then
defaultNamespace = "Default.Namespace"
End If
Expand Down
4 changes: 2 additions & 2 deletions src/VisualStudio/Core/Test/Preview/PreviewChangesTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ End Class
Next
End Sub

Private Sub AssertChildCount(list As ChangeList, count As UInteger)
Private Shared Sub AssertChildCount(list As ChangeList, count As UInteger)
Dim actualCount As UInteger = Nothing
list.GetItemCount(actualCount)
Assert.Equal(count, actualCount)
End Sub

Private Sub AssertChildText(list As ChangeList, index As UInteger, text As String)
Private Shared Sub AssertChildText(list As ChangeList, index As UInteger, text As String)
Dim actualText As String = Nothing
list.GetText(index, Nothing, actualText)
Assert.Equal(text, actualText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Imports Roslyn.Test.Utilities
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression
<UseExportProvider, Trait(Traits.Feature, Traits.Features.Progression)>
Public Class GraphNodeCreationTests
Private Async Function AssertCreatedNodeIsAsync(code As String, expectedId As String, xml As XElement, Optional language As String = "C#") As Task
Private Shared Async Function AssertCreatedNodeIsAsync(code As String, expectedId As String, xml As XElement, Optional language As String = "C#") As Task
Using testState = ProgressionTestState.Create(
<Workspace>
<Project Language=<%= language %> CommonReferences="true" FilePath="Z:\Project.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Imports Roslyn.Test.Utilities
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression
<UseExportProvider, Trait(Traits.Feature, Traits.Features.Progression)>
Public Class GraphNodeIdTests
Private Async Function AssertMarkedNodeIdIsAsync(code As String, expectedId As String, Optional language As String = "C#", Optional symbolTransform As Func(Of ISymbol, ISymbol) = Nothing) As Task
Private Shared Async Function AssertMarkedNodeIdIsAsync(code As String, expectedId As String, Optional language As String = "C#", Optional symbolTransform As Func(Of ISymbol, ISymbol) = Nothing) As Task
Using testState = ProgressionTestState.Create(
<Workspace>
<Project Language=<%= language %> CommonReferences="true" FilePath="Z:\Project.csproj">
Expand Down
Loading