Skip to content

Commit

Permalink
Update editorconfig and fix violations
Browse files Browse the repository at this point in the history
Enables some new warnings around unsealed classes and unused members.

Also adds some words to the spelling dictionary file to reduce squiggles in the editor.
  • Loading branch information
drewnoakes committed Jul 4, 2023
1 parent bf4f33e commit 8d6e41f
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 188 deletions.
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ indent_size = 2
[*.json]
indent_size = 2

[*.groovy]
indent_size = 2

# Dotnet code style settings:
[*.{cs,vb}]
# Sort using and Import directives with System.* appearing first
Expand Down Expand Up @@ -234,6 +231,7 @@ dotnet_diagnostic.CA1821.severity = none # Remove empty Finalizers
dotnet_diagnostic.CA1823.severity = warning # Avoid unused private fields
dotnet_diagnostic.CA1824.severity = none # Mark assemblies with NeutralResourcesLanguageAttribute
dotnet_diagnostic.CA1851.severity = warning # Detect multiple enumeration
dotnet_diagnostic.CA1852.severity = warning # Seal internal types
dotnet_diagnostic.CA2200.severity = none # Rethrow to preserve stack details

# Microsoft.NetCore.Analyzers
Expand Down Expand Up @@ -386,6 +384,8 @@ dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessa
dotnet_diagnostic.IDE0030.severity = warning # Use coalesce expression (nullable) int? y = x.HasValue ? x.Value : 0 int? y = x ?? 0;
dotnet_diagnostic.IDE0030WithoutSuggestion.severity = error
dotnet_diagnostic.IDE0031.severity = warning # Use null propagation (nullable)
dotnet_diagnostic.IDE0051.severity = warning # Private member unused
dotnet_diagnostic.IDE0052.severity = warning # Remove unread private members
dotnet_diagnostic.IDE0079.severity = warning # Unused suppresion
dotnet_diagnostic.IDE0083.severity = warning # Use pattern matching
dotnet_diagnostic.IDE0084.severity = warning # Use IsNot
Expand Down
10 changes: 7 additions & 3 deletions spelling.dic
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ async
awaiter
blazor
boolean
bstr
cmdid
combobox
commandbar
csproj
debuggable
debugsettings
devdiv
Dirs
dirs
docdata
enum
enums
fsscript
func
fxcop
github
globbing
guid
hwnd
Impl
impl
intelli
intellisense
itemid
Expand Down Expand Up @@ -57,8 +59,10 @@ shproj
typeof
uint
unadvise
unescape
unescapes
ushort
Usings
usings
vswhidbey
xaml
xmlns
Expand Down
2 changes: 1 addition & 1 deletion src/Common/ManagedCodeMarkers.vb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Namespace Microsoft.Internal.Performance
' Singleton access
Public Shared ReadOnly Instance As CodeMarkers = New CodeMarkers()

Private Class NativeMethods
Private NotInheritable Class NativeMethods

' Add a private constructor to prevent compiler from generating a default constructor (FxCop warning CA1812)
Private Sub New()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Namespace Microsoft.VisualStudio.Editors.ApplicationDesigner
'''<summary>
''' custom build accessible object class
'''</summary>
Private Class DesignerTabButtonAccessibleObject
Private NotInheritable Class DesignerTabButtonAccessibleObject
Inherits ButtonBaseAccessibleObject

' button which this accessible object belongs to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ Namespace Microsoft.VisualStudio.Editors.ApplicationDesigner
''' b) has flatstyle
''' c) shows a border only when the mouse hovers over it
''' </summary>
Private Class ImageButton
Private NotInheritable Class ImageButton
Inherits Button

Public Sub New()
Expand Down Expand Up @@ -633,7 +633,7 @@ Namespace Microsoft.VisualStudio.Editors.ApplicationDesigner
'''<summary>
''' custom build accessible object class
'''</summary>
Private Class DesignerTabControlAccessibleObject
Private NotInheritable Class DesignerTabControlAccessibleObject
Inherits ControlAccessibleObject

' button which this accessible object belongs to
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.VisualStudio.AppDesigner/Common/Utils.vb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Namespace Microsoft.VisualStudio.Editors.AppDesCommon
'Property page GUIDs. These are used only for sorting the tabs in the project designer, and for providing a
' unique ID for SQM. Both cases are optional (we handle getting property pages with GUIDs we don't recognize).
'PERF: NOTE: Initializing GUIDs from numeric values as below is a lot faster than initializing from strings.
Public Class KnownPropertyPageGuids
Public NotInheritable Class KnownPropertyPageGuids
Public Shared ReadOnly GuidApplicationPage_VB As Guid = New Guid(&H8998E48EUI, &HB89AUS, &H4034US, &HB6, &H6E, &H35, &H3D, &H8C, &H1F, &HDC, &H2E)
Public Shared ReadOnly GuidApplicationPage_VB_WPF As Guid = New Guid(&HAA1F44UI, &H2BA3US, &H4EAAUS, &HB5, &H4A, &HCE, &H18, &H0, &HE, &H6C, &H5D)
Public Shared ReadOnly GuidApplicationPage_CS As Guid = New Guid(&H5E9A8AC2UI, &H4F34US, &H4521US, CByte(&H85), CByte(&H8F), CByte(&H4C), CByte(&H24), CByte(&H8B), CByte(&HA3), CByte(&H15), CByte(&H32))
Expand Down Expand Up @@ -592,7 +592,7 @@ Namespace Microsoft.VisualStudio.Editors.AppDesCommon
End Function

#Region "Telemetry"
Public Class TelemetryLogger
Public NotInheritable Class TelemetryLogger

'A list of known editor guids
' Each property page will be reported back to telemetry with the 1-based index in which it is present
Expand Down Expand Up @@ -692,7 +692,7 @@ Namespace Microsoft.VisualStudio.Editors.AppDesCommon
End Class
#End Region

Public Class ObjectSerializer
Public NotInheritable Class ObjectSerializer

' KnownType information is used by DataContractSerializer for serialization of types that it may not know of currently.
' Size is used in Bitmap and has issues being recognized in DataContractSerializer for the unit tests of this class.
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.VisualStudio.AppDesigner/Common/WaitCursor.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
' Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.
' Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

Option Strict On
Option Explicit On
Expand All @@ -20,7 +20,7 @@ Namespace Microsoft.VisualStudio.Editors.AppDesCommon
' End Using
' End Sub
'**************************************************************************
Friend Class WaitCursor
Friend NotInheritable Class WaitCursor
Implements IDisposable

Private _previousCursor As Cursor
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.VisualStudio.AppDesigner/Common/switches.vb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Namespace Microsoft.VisualStudio.Editors.AppDesCommon
''' <summary>
''' Contains predefined switches for enabling/disabling trace output or code instrumentation.
''' </summary>
Friend Class Switches
Friend NotInheritable Class Switches

'------------- Resource Editor -------------

Expand Down Expand Up @@ -395,7 +395,7 @@ Namespace Microsoft.VisualStudio.Editors.AppDesCommon
''' <summary>
''' A Switch which has a simple enum value (either as integer or string representation)
''' </summary>
Public Class EnumSwitch(Of T)
Public NotInheritable Class EnumSwitch(Of T)
Inherits Switch

Public Sub New(DisplayName As String, Description As String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Imports Microsoft.VisualStudio.Editors.AppDesInterop

Namespace Microsoft.VisualStudio.Editors.AppDesCommon

Friend Class WmUserConstants
Friend NotInheritable Class WmUserConstants
Public Const WM_REFPAGE_REFERENCES_REFRESH As Integer = Win32Constant.WM_USER + 21
Public Const WM_REFPAGE_IMPORTCHANGED As Integer = Win32Constant.WM_USER + 22
Public Const WM_REFPAGE_IMPORTS_REFRESH As Integer = Win32Constant.WM_USER + 24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ Namespace Microsoft.VisualStudio.Editors.AppDesDesignerFramework
''' A toplevel control is needed to handle SystemEvents. When the control is hosted in a native window, there will be no parent WinForm control.
''' Form could handle this correctly. However, for some reason, we couldn't use it here. We have to create a customized class to make a non-form topLevel control.
''' </summary>
Private Class TopLevelControl
Private NotInheritable Class TopLevelControl
Inherits Control

''' <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Namespace Microsoft.VisualStudio.Editors.PropertyPages
End Enum

'Used for caching property change notification until after Apply is done
Private Class PropertyChange
Private NotInheritable Class PropertyChange
Public ReadOnly DispId As Integer
Public ReadOnly Source As PropertyChangeSource

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ Namespace Microsoft.VisualStudio.Editors.PropertyPages
''' Helper class for PropertyDescriptorSetValue - detects if a PropertyDescriptor.SetValue
''' fails due to a canceled checkout...
''' </summary>
Private Class PropertyDescriptorSetValueHelper
Private NotInheritable Class PropertyDescriptorSetValueHelper
Private _valueChangedWasFired As Boolean

''' <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Namespace Microsoft.VisualStudio.Editors.PropertyPages
''' <summary>
''' The exception will be thrown when validation failed...
''' </summary>
Friend Class ValidationException
Friend NotInheritable Class ValidationException
Inherits ApplicationException

Private ReadOnly _validationResult As ValidationResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Namespace Microsoft.VisualStudio.Editors.AppDesInterop
Public Const UISF_HIDEFOCUS As Integer = &H1
Public Const UISF_HIDEACCEL As Integer = &H2

Public Class ConnectionPointCookie
Public NotInheritable Class ConnectionPointCookie
Private _connectionPoint As IConnectionPoint
Private _connectionPoint2 As ComTypes.IConnectionPoint
Private _cookie As UInteger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices.Handlers
[Export(typeof(IWorkspaceUpdateHandler))]
internal class ProjectFilePathAndDisplayNameEvaluationHandler : IWorkspaceUpdateHandler, IProjectEvaluationHandler
{
private readonly UnconfiguredProject _project;
private readonly IImplicitlyActiveDimensionProvider _implicitlyActiveDimensionProvider;

[ImportingConstructor]
public ProjectFilePathAndDisplayNameEvaluationHandler(UnconfiguredProject project, IImplicitlyActiveDimensionProvider implicitlyActiveDimensionProvider)
public ProjectFilePathAndDisplayNameEvaluationHandler(UnconfiguredProject _, IImplicitlyActiveDimensionProvider implicitlyActiveDimensionProvider)
{
_project = project;
_implicitlyActiveDimensionProvider = implicitlyActiveDimensionProvider;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ private string GetText(Location startLocation, Location endLocation)
return GetText(startLocation.LineIndex, startLocation.CharIndex, endLocation.LineIndex, endLocation.CharIndex);
}

/// <summary>
/// Retrieves the text starting at the given point and with the given length
/// </summary>
private string GetText(Location startLocation, int count)
{
return GetText(startLocation.LineIndex, startLocation.CharIndex, count);
}

/// <summary>
/// Retrieves all of the text in the buffer
/// </summary>
Expand Down Expand Up @@ -294,12 +286,7 @@ private static int FindClosingAngleBracketHelper(string line)
{
MoveToApplicationRootElement(reader);
XamlProperty? prop = FindPropertyAsAttributeInCurrentElement(reader, ApplicationElementName, propertyName);
if (prop is null)
{
prop = FindPropertyAsChildElementInCurrentElement(reader, ApplicationElementName, propertyName);
}

return prop;
return prop ?? FindPropertyAsChildElementInCurrentElement(reader, ApplicationElementName, propertyName);
}

private XamlPropertyInAttributeSyntax? FindPropertyAsAttributeInCurrentElement(XmlTextReader reader, string optionalPropertyQualifier, string propertyName)
Expand Down Expand Up @@ -411,7 +398,6 @@ private static int FindClosingAngleBracketHelper(string line)
// Found

Location tagStart = new(reader);
Location tagEnd = new(reader);

Location? startTagEndingBracketLocation = FindClosingAngleBracket(tagStart);
if (startTagEndingBracketLocation is null)
Expand Down Expand Up @@ -469,7 +455,6 @@ private static int FindClosingAngleBracketHelper(string line)
}

// Reader is at location 'x' of </xyz>. So we want -2 from this location.
Location currentPosition2 = new(reader);
Location valueEndPlusOne = new Location(reader).Shift(-2);

// Get the inner text and unescape it.
Expand Down Expand Up @@ -499,10 +484,7 @@ private static int FindClosingAngleBracketHelper(string line)

private void SetApplicationPropertyValue(string propertyName, string? value)
{
if (value is null)
{
value = string.Empty;
}
value ??= string.Empty;

using BufferLock bufferLock = new(_vsTextLines, this);

Expand Down Expand Up @@ -549,14 +531,6 @@ private void SetApplicationPropertyValue(string propertyName, string? value)
}
}

/// <summary>
/// Replace the text at the given location in the buffer with new text.
/// </summary>
private void ReplaceText(Location sourceStart, int sourceLength, string newText)
{
((IReplaceText)this).ReplaceText(sourceStart, new Location(sourceStart.LineIndex, sourceStart.CharIndex + sourceLength), newText);
}

/// <summary>
/// Replace the text at the given location in the buffer with new text.
/// </summary>
Expand All @@ -576,48 +550,6 @@ void IReplaceText.ReplaceText(Location sourceStart, Location sourceEnd, string n
}
}

/// <summary>
/// Given the location of the start of an element tag, makes sure that it has an end tag.
/// If the element tag is closed by "/>" instead of an end element, it is expanded
/// into a start and end tag.
/// </summary>
/// <param name="tagStartLocation"></param>
/// <param name="elementName">The name of the element at the given location</param>
private void MakeSureElementHasStartAndEndTag(Location tagStartLocation, string elementName)
{
if (!"<".Equals(GetText(tagStartLocation, 1), StringComparison.Ordinal))
{
DiagnosticsDebug.Fail("MakeSureElementHasStartAndEndTags: The start location doesn't point to the start of an element tag");
ThrowUnexpectedFormatException(tagStartLocation);
}

Location? startTagEndingBracketLocation = FindClosingAngleBracket(tagStartLocation);
if (startTagEndingBracketLocation is null)
{
ThrowUnexpectedFormatException(tagStartLocation);
}

if (">".Equals(GetText(startTagEndingBracketLocation, 1), StringComparison.Ordinal))
{
// The element tag is of the <xxx> form. We assume that there is an ending </xxx> tag, and
// we don't need to do anything.
}
else
{
// It must be an empty tag of the <xxx/> form.
string slashAndEndBracket = "/>";
if (!slashAndEndBracket.Equals(GetText(startTagEndingBracketLocation, slashAndEndBracket.Length), StringComparison.Ordinal))
{
DiagnosticsDebug.Fail("FindClosingAngleBracket returned the wrong location?");
ThrowUnexpectedFormatException(startTagEndingBracketLocation);
}

// We need to change <xxx attributes/> into <xxx attributes></xxx>
string newText = "></" + elementName + ">";
ReplaceText(startTagEndingBracketLocation, slashAndEndBracket.Length, newText);
}
}

/// <summary>
/// Finds the value of the StartupUri property inside the xaml file. If
/// the property is not set in the xaml, an empty string is returned.
Expand Down Expand Up @@ -655,29 +587,6 @@ private static void ThrowUnexpectedFormatException(Location location)
throw new XamlReadWriteException(string.Format(VSResources.WPFApp_Xaml_UnexpectedFormat_2, location.LineIndex + 1, location.CharIndex + 1));
}

/// <summary>
/// Verify the validity of the Application.xaml file, and throw an exception if
/// problems are found.
/// </summary>
private void VerifyAppXamlIsValidAndThrowIfNot()
{
using BufferLock bufferLock = new(_vsTextLines, this);

XmlTextReader reader = CreateXmlTextReader();
MoveToApplicationRootElement(reader);

// Read through the Application element, including any child elements, to
// ensure everything is properly closed.
// The name of the element to find is irrelevant, as there shouldn't be
// any elements following Application.
reader.ReadToFollowing("Dummy Element");

// If we made it to here, the .xaml file should be well-formed enough for us to read
// it properly. As a final check, though, try getting some common properties.
GetStartupUri();
GetShutdownMode();
}

void IDebugLockCheck.OnBufferLock()
{
_debugBufferLockCount++;
Expand Down
Loading

0 comments on commit 8d6e41f

Please sign in to comment.