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

More analyzer fixes. #11044

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 11 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ insert_final_newline = true
trim_trailing_whitespace = true

# avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error
# use language keywords instead of BCL types
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
Expand Down Expand Up @@ -93,6 +93,7 @@ dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
dotnet_style_prefer_collection_expression = true:suggestion

# C# files

[*.cs]

# These two conflict with our usage of CsWin32
Expand All @@ -103,12 +104,18 @@ dotnet_diagnostic.SYSLIB1054.severity = none
# SYSLIB1096: Convert to 'GeneratedComInterface'
dotnet_diagnostic.SYSLIB1096.severity = none

# CA1725: Parameter names should match base declaration
dotnet_diagnostic.CA1725.severity = error

# DOC100: Place text in paragraphs
dotnet_diagnostic.DOC100.severity = error

# CA1859: Use concrete types when possible for improved performance
dotnet_diagnostic.CA1859.severity = error

# IDE0003: Remove qualification
dotnet_diagnostic.IDE0003.severity = error

# .NET diagnostic
dotnet_diagnostic.RS0041.severity = none
dotnet_diagnostic.IDE0005.severity = error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
Get
If _commandLineArgs Is Nothing Then
'Get rid of Arg(0) which is the path of the executing program. Main(args() as string) doesn't report the name of the app and neither will we
Dim EnvArgs As String() = System.Environment.GetCommandLineArgs
Dim EnvArgs As String() = Environment.GetCommandLineArgs
If EnvArgs.GetLength(0) >= 2 Then '1 element means no args, just the executing program. >= 2 means executing program + one or more command line arguments
Dim NewArgs(EnvArgs.GetLength(0) - 2) As String 'dimming z(0) gives a z() of 1 element.
Array.Copy(EnvArgs, 1, NewArgs, 0, EnvArgs.GetLength(0) - 1) 'copy everything but the 0th element (the path of the executing program)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ Namespace Microsoft.VisualBasic.ApplicationServices
''' </remarks>
Protected Overridable Property InternalPrincipal() As IPrincipal
Get
Return System.Threading.Thread.CurrentPrincipal
Return Threading.Thread.CurrentPrincipal
End Get
Set(value As IPrincipal)
System.Threading.Thread.CurrentPrincipal = value
Threading.Thread.CurrentPrincipal = value
End Set
End Property

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
Friend Shared Function GetWin32Exception(
ResourceID As String, ParamArray PlaceHolders() As String) As ComponentModel.Win32Exception

Return New ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(), GetResourceString(ResourceID, PlaceHolders))
Return New ComponentModel.Win32Exception(Runtime.InteropServices.Marshal.GetLastWin32Error(), GetResourceString(ResourceID, PlaceHolders))
End Function

End Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Function

Friend Shared Function GetCultureInfo() As CultureInfo
Return System.Threading.Thread.CurrentThread.CurrentCulture
Return Threading.Thread.CurrentThread.CurrentCulture
End Function

End Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Namespace Microsoft.VisualBasic.Devices
''' <exception cref="InvalidOperationException">If no mouse is installed.</exception>
Public ReadOnly Property ButtonsSwapped() As Boolean
Get
If System.Windows.Forms.SystemInformation.MousePresent Then
If SystemInformation.MousePresent Then
Return SystemInformation.MouseButtonsSwapped
Else
Throw GetInvalidOperationException(SR.Mouse_NoMouseIsPresent)
Expand All @@ -43,7 +43,7 @@ Namespace Microsoft.VisualBasic.Devices
''' <exception cref="InvalidOperationException">If no mouse is installed.</exception>
Public ReadOnly Property WheelExists() As Boolean
Get
If System.Windows.Forms.SystemInformation.MousePresent Then
If SystemInformation.MousePresent Then
Return SystemInformation.MouseWheelPresent
Else
Throw GetInvalidOperationException(SR.Mouse_NoMouseIsPresent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Namespace Microsoft.VisualBasic.Devices
' We're safe from Ping(Nothing, ...) due to overload failure (Ping(String,...) vs. Ping(Uri,...)).
' However, it is good practice to verify address before calling address.Host.
If address Is Nothing Then
Throw ExceptionUtils.GetArgumentNullException("address")
Throw GetArgumentNullException("address")
End If
Return Ping(address.Host, DEFAULT_PING_TIMEOUT)
End Function
Expand All @@ -144,7 +144,7 @@ Namespace Microsoft.VisualBasic.Devices

' Make sure a network is available
If Not IsAvailable Then
Throw ExceptionUtils.GetInvalidOperationException(SR.Network_NetworkNotAvailable)
Throw GetInvalidOperationException(SR.Network_NetworkNotAvailable)
End If

Dim PingMaker As New NetInfoAlias.Ping
Expand All @@ -165,7 +165,7 @@ Namespace Microsoft.VisualBasic.Devices
' We're safe from Ping(Nothing, ...) due to overload failure (Ping(String,...) vs. Ping(Uri,...)).
' However, it is good practice to verify address before calling address.Host.
If address Is Nothing Then
Throw ExceptionUtils.GetArgumentNullException("address")
Throw GetArgumentNullException("address")
End If
Return Ping(address.Host, timeout)
End Function
Expand Down Expand Up @@ -254,7 +254,7 @@ Namespace Microsoft.VisualBasic.Devices
' We're safe from DownloadFile(Nothing, ...) due to overload failure (DownloadFile(String,...) vs. DownloadFile(Uri,...)).
' However, it is good practice to verify address before calling Trim.
If String.IsNullOrWhiteSpace(address) Then
Throw ExceptionUtils.GetArgumentNullException("address")
Throw GetArgumentNullException("address")
End If

Dim addressUri As Uri = GetUri(address.Trim())
Expand Down Expand Up @@ -356,7 +356,7 @@ Namespace Microsoft.VisualBasic.Devices
End If

If address Is Nothing Then
Throw ExceptionUtils.GetArgumentNullException("address")
Throw GetArgumentNullException("address")
End If

Using client As New WebClientExtended
Expand All @@ -370,8 +370,8 @@ Namespace Microsoft.VisualBasic.Devices

' Sometime a path that can't be parsed is normalized to the current directory. This makes sure we really
' have a file and path
If System.IO.Directory.Exists(fullFilename) Then
Throw ExceptionUtils.GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
If IO.Directory.Exists(fullFilename) Then
Throw GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
End If

'Throw if the file exists and the user doesn't want to overwrite
Expand All @@ -385,19 +385,19 @@ Namespace Microsoft.VisualBasic.Devices
End If

Dim dialog As ProgressDialog = Nothing
If showUI AndAlso System.Environment.UserInteractive Then
If showUI AndAlso Environment.UserInteractive Then
dialog = New ProgressDialog With {
.Text = GetResourceString(SR.ProgressDialogDownloadingTitle, address.AbsolutePath),
.LabelText = GetResourceString(SR.ProgressDialogDownloadingLabel, address.AbsolutePath, fullFilename)
}
End If

'Check to see if the target directory exists. If it doesn't, create it
Dim targetDirectory As String = System.IO.Path.GetDirectoryName(fullFilename)
Dim targetDirectory As String = IO.Path.GetDirectoryName(fullFilename)

' Make sure we have a meaningful directory. If we don't, the destinationFileName is suspect
If String.IsNullOrEmpty(targetDirectory) Then
Throw ExceptionUtils.GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
Throw GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
End If

If Not IO.Directory.Exists(targetDirectory) Then
Expand All @@ -411,7 +411,7 @@ Namespace Microsoft.VisualBasic.Devices
copier.DownloadFile(address, fullFilename)

'Handle a dialog cancel
If showUI AndAlso System.Environment.UserInteractive Then
If showUI AndAlso Environment.UserInteractive Then
If onUserCancel = UICancelOption.ThrowException And dialog.UserCanceledTheDialog Then
Throw New OperationCanceledException()
End If
Expand Down Expand Up @@ -501,15 +501,15 @@ Namespace Microsoft.VisualBasic.Devices
' We're safe from UploadFile(Nothing, ...) due to overload failure (UploadFile(String,...) vs. UploadFile(Uri,...)).
' However, it is good practice to verify address before calling address.Trim.
If String.IsNullOrWhiteSpace(address) Then
Throw ExceptionUtils.GetArgumentNullException("address")
Throw GetArgumentNullException("address")
End If

' Getting a uri will validate the form of the host address
Dim addressUri As Uri = GetUri(address.Trim())

' For uploads, we need to make sure the address includes the filename
If String.IsNullOrEmpty(IO.Path.GetFileName(addressUri.AbsolutePath)) Then
Throw ExceptionUtils.GetInvalidOperationException(SR.Network_UploadAddressNeedsFilename)
Throw GetInvalidOperationException(SR.Network_UploadAddressNeedsFilename)
End If

UploadFile(sourceFileName, addressUri, userName, password, showUI, connectionTimeout, onUserCancel)
Expand Down Expand Up @@ -604,7 +604,7 @@ Namespace Microsoft.VisualBasic.Devices
End If

If address Is Nothing Then
Throw ExceptionUtils.GetArgumentNullException("address")
Throw GetArgumentNullException("address")
End If

Using client As New WebClientExtended()
Expand All @@ -616,7 +616,7 @@ Namespace Microsoft.VisualBasic.Devices
End If

Dim Dialog As ProgressDialog = Nothing
If showUI AndAlso System.Environment.UserInteractive Then
If showUI AndAlso Environment.UserInteractive Then
Dialog = New ProgressDialog With {
.Text = GetResourceString(SR.ProgressDialogUploadingTitle, sourceFileName),
.LabelText = GetResourceString(SR.ProgressDialogUploadingLabel, sourceFileName, address.AbsolutePath)
Expand All @@ -630,7 +630,7 @@ Namespace Microsoft.VisualBasic.Devices
copier.UploadFile(sourceFileName, address)

'Handle a dialog cancel
If showUI AndAlso System.Environment.UserInteractive Then
If showUI AndAlso Environment.UserInteractive Then
If onUserCancel = UICancelOption.ThrowException And Dialog.UserCanceledTheDialog Then
Throw New OperationCanceledException()
End If
Expand Down Expand Up @@ -674,7 +674,7 @@ Namespace Microsoft.VisualBasic.Devices
ReDim _pingBuffer(BUFFER_SIZE - 1)
For i As Integer = 0 To BUFFER_SIZE - 1
'This is the same logic Ping.exe uses to fill it's buffer
_pingBuffer(i) = System.Convert.ToByte(Asc("a"c) + i Mod 23, System.Globalization.CultureInfo.InvariantCulture)
_pingBuffer(i) = Convert.ToByte(Asc("a"c) + i Mod 23, Globalization.CultureInfo.InvariantCulture)
Next
End If

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Namespace Microsoft.VisualBasic.Devices
''' <value>A string containing the name of the computer.</value>
Public ReadOnly Property Name() As String
Get
Return System.Environment.MachineName
Return Environment.MachineName
End Get
End Property

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Namespace Microsoft.VisualBasic.CompilerServices
End Sub

Friend Sub InitialSetHandle(h As IntPtr)
Debug.Assert(MyBase.IsInvalid, "Safe handle should only be set once.")
MyBase.SetHandle(h)
Debug.Assert(IsInvalid, "Safe handle should only be set once.")
SetHandle(h)
End Sub

Protected Overrides Function ReleaseHandle() As Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
'
'MyCancelButton
'
MyCancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
MyCancelButton.DialogResult = DialogResult.Cancel
resources.ApplyResources(MyCancelButton, "MyCancelButton", CultureInfo.CurrentUICulture)
MyCancelButton.Name = "MyCancelButton"
'
Expand All @@ -77,7 +77,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
Controls.Add(Label)
Controls.Add(OKButton)
Controls.Add(MyCancelButton)
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
FormBorderStyle = FormBorderStyle.FixedDialog
MaximizeBox = False
MinimizeBox = False
Name = "VBInputBox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ Namespace Microsoft.VisualBasic
Dim vbhost As IVbHost
Dim ParentWindow As IWin32Window = Nothing

vbhost = CompilerServices.HostServices.VBHost
vbhost = HostServices.VBHost
If vbhost IsNot Nothing Then 'If we are hosted then we want to use the host as the parent window. If no parent window that's fine.
ParentWindow = vbhost.GetParentWindow()
End If

If String.IsNullOrEmpty(Title) Then
If vbhost Is Nothing Then
Title = GetTitleFromAssembly(System.Reflection.Assembly.GetCallingAssembly())
Title = GetTitleFromAssembly(Reflection.Assembly.GetCallingAssembly())
Else
Title = vbhost.GetWindowTitle()
End If
Expand All @@ -297,7 +297,7 @@ Namespace Microsoft.VisualBasic
'Threading state can only be set once, and will most often be already set
'but set to STA and check if it isn't STA, then we need to start another thread
'to display the InputBox
If System.Threading.Thread.CurrentThread.GetApartmentState() <> Threading.ApartmentState.STA Then
If Thread.CurrentThread.GetApartmentState() <> ApartmentState.STA Then
Dim InputHandler As New InputBoxHandler(Prompt, Title, DefaultResponse, XPos, YPos, ParentWindow)
Dim thread As New Thread(New ThreadStart(AddressOf InputHandler.StartHere))
thread.Start()
Expand Down Expand Up @@ -355,7 +355,7 @@ Namespace Microsoft.VisualBasic
Dim vbhost As IVbHost
Dim ParentWindow As IWin32Window = Nothing

vbhost = CompilerServices.HostServices.VBHost
vbhost = HostServices.VBHost
If vbhost IsNot Nothing Then
ParentWindow = vbhost.GetParentWindow()
End If
Expand Down Expand Up @@ -387,7 +387,7 @@ Namespace Microsoft.VisualBasic
Try
If Title Is Nothing Then
If vbhost Is Nothing Then
sTitle = GetTitleFromAssembly(System.Reflection.Assembly.GetCallingAssembly())
sTitle = GetTitleFromAssembly(Reflection.Assembly.GetCallingAssembly())
Else
sTitle = vbhost.GetWindowTitle()
End If
Expand All @@ -404,7 +404,7 @@ Namespace Microsoft.VisualBasic
Throw New ArgumentException(GetResourceString(SR.Argument_InvalidValueType2, "Title", "String"))
End Try

Return CType(System.Windows.Forms.MessageBox.Show(ParentWindow, sPrompt, sTitle,
Return CType(MessageBox.Show(ParentWindow, sPrompt, sTitle,
CType(Buttons And &HF, MessageBoxButtons),
CType(Buttons And &HF0, MessageBoxIcon),
CType(Buttons And &HF00, MessageBoxDefaultButton),
Expand Down
Loading