From 3c5a472ebd18b828d8d51d974d167b5b5604e60f Mon Sep 17 00:00:00 2001 From: Thomas Goulet Date: Thu, 24 Jun 2021 18:47:14 -0400 Subject: [PATCH 1/7] Update Microsoft.CodeAnalysis.FxCopAnalyzers to 3.3.2. Remove Microsoft.CodeAnalysis.Common to avoid dependency conflicts. --- eng/WpfArcadeSdk/tools/CodeAnalysis.targets | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/WpfArcadeSdk/tools/CodeAnalysis.targets b/eng/WpfArcadeSdk/tools/CodeAnalysis.targets index 17ff34f4b5e..dcd84e745ba 100644 --- a/eng/WpfArcadeSdk/tools/CodeAnalysis.targets +++ b/eng/WpfArcadeSdk/tools/CodeAnalysis.targets @@ -6,8 +6,7 @@ - - + From 24c1731a5b4909d8a5a9c9134ee907039461ab64 Mon Sep 17 00:00:00 2001 From: Thomas Goulet Date: Thu, 24 Jun 2021 18:55:24 -0400 Subject: [PATCH 2/7] Disable rules to have a clean build --- .../tools/CodeAnalysis/WpfCodeAnalysis.ruleset | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset index 4b42f390946..8cfdf47250f 100644 --- a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset +++ b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset @@ -19,4 +19,11 @@ + + + + + + + \ No newline at end of file From d7e7b9067c891c49091ded2d2e1b352a39862895 Mon Sep 17 00:00:00 2001 From: Thomas Goulet Date: Sat, 26 Jun 2021 17:15:33 -0400 Subject: [PATCH 3/7] Enable CA1310 --- eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset | 1 - .../Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset index 8cfdf47250f..8f71f5b5a5b 100644 --- a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset +++ b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset @@ -21,7 +21,6 @@ - diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs index ad25b2ac38b..5311e046022 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs @@ -106,7 +106,7 @@ internal bool EndsEscapeSequence(char ch) internal bool Match(char start, char end) { - return _endChars.IndexOf(end.ToString()) == _startChars.IndexOf(start.ToString()); + return _endChars.IndexOf(end.ToString(), StringComparison.Ordinal) == _startChars.IndexOf(start.ToString(), StringComparison.Ordinal); } internal string StartBracketCharacters From e9ba026e381e4243047f2f40aaccfc08aabd88e2 Mon Sep 17 00:00:00 2001 From: Thomas Goulet Date: Sat, 26 Jun 2021 17:37:05 -0400 Subject: [PATCH 4/7] Enable CA1805 --- .../tools/CodeAnalysis/WpfCodeAnalysis.ruleset | 1 - .../Windows/Markup/RuntimeIdentifierPropertyAttribute.cs | 2 +- .../System/Windows/Markup/UidPropertyAttribute.cs | 2 +- .../System/Xaml/Context/ObjectWriterContext.cs | 2 +- .../src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs | 8 ++++---- .../System/Xaml/Parser/NamespacePrefixLookup.cs | 2 +- .../System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs | 2 +- .../src/System.Xaml/System/Xaml/Parser/XamlName.cs | 2 +- .../src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs | 6 +++--- .../src/System.Xaml/System/Xaml/Parser/XamlScanner.cs | 4 ++-- .../System/Xaml/Primitives/XamlBackgroundReader.cs | 4 ++-- .../System.Xaml/System/Xaml/Primitives/XamlNodeList.cs | 2 +- .../src/System.Xaml/System/Xaml/XamlObjectReader.cs | 2 +- .../src/System.Xaml/System/Xaml/XamlSchemaContext.cs | 2 +- 14 files changed, 20 insertions(+), 21 deletions(-) diff --git a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset index 8f71f5b5a5b..d870fe24b75 100644 --- a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset +++ b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset @@ -21,7 +21,6 @@ - diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs index 6362ed6d0e3..83c2b113810 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs @@ -48,7 +48,7 @@ public string Name } } - private string _name = null; + private string _name; } #endif diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/UidPropertyAttribute.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/UidPropertyAttribute.cs index 9696216f50d..07a19c167a7 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/UidPropertyAttribute.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/UidPropertyAttribute.cs @@ -54,6 +54,6 @@ public string Name } // The name of the property that is designated to accept the x:Uid value - private string _name = null; + private string _name; } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs index 21af3d22cf9..a50667e1c06 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs @@ -17,7 +17,7 @@ internal class ObjectWriterContext : XamlContext { private XamlContextStack _stack; - private object _rootInstance = null; + private object _rootInstance; ServiceProviderContext _serviceProviderContext; XamlRuntime _runtime; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs index d30ddbe68d8..a84dbcd4e11 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs @@ -38,7 +38,7 @@ internal IList NsDefs } // Note this, is the only dictionary that we synchronize, because XamlSchemaContext adds to it - private ConcurrentDictionary> _clrToXmlNs = null; + private ConcurrentDictionary> _clrToXmlNs; internal ConcurrentDictionary> ClrToXmlNs { get @@ -64,7 +64,7 @@ internal ICollection InternalsVisibleTo } } - private Dictionary _oldToNewNs = null; + private Dictionary _oldToNewNs; internal Dictionary OldToNewNs { get @@ -77,7 +77,7 @@ internal Dictionary OldToNewNs } } - private Dictionary _prefixes = null; + private Dictionary _prefixes; internal Dictionary Prefixes { get @@ -90,7 +90,7 @@ internal Dictionary Prefixes } } - private string _rootNamespace = null; + private string _rootNamespace; internal string RootNamespace { get diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NamespacePrefixLookup.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NamespacePrefixLookup.cs index 2a74fbf8dd9..5fbd785e46b 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NamespacePrefixLookup.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NamespacePrefixLookup.cs @@ -20,7 +20,7 @@ public NamespacePrefixLookup(out IEnumerable newNamespaces #region INamespacePrefixLookup Members - private int n = 0; + private int n; public string LookupPrefix(string ns) { // we really shouldn't generate extraneous new namespaces diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs index 92971ec55d2..b30d0b006cd 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs @@ -33,7 +33,7 @@ class SeenCtorDirectiveFlags } List _seenStack = new List(); - int _startObjectDepth = 0; + int _startObjectDepth; List _moveList; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs index 54e873c0771..c9798d80ea1 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs @@ -30,7 +30,7 @@ public XamlName(string prefix, string name) public abstract string ScopedName { get; } protected string _prefix; - protected string _namespace = null; + protected string _namespace; public string Prefix { get { return _prefix; } } public string Namespace { get { return _namespace; } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs index 187c7de0ce3..66823a8c7a9 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs @@ -931,7 +931,7 @@ private XamlNode Logic_StartItemsProperty(XamlType collectionType) #region Optimizations private readonly XamlTypeName arrayType = new XamlTypeName(@"http://schemas.microsoft.com/winfx/2006/xaml", "Array"); - private XamlType _arrayExtensionType = null; + private XamlType _arrayExtensionType; private XamlType ArrayExtensionType { get @@ -944,7 +944,7 @@ private XamlType ArrayExtensionType } } - private XamlMember _arrayTypeMember = null; + private XamlMember _arrayTypeMember; private XamlMember ArrayTypeMember { get @@ -957,7 +957,7 @@ private XamlMember ArrayTypeMember } } - private XamlMember _itemsTypeMember = null; + private XamlMember _itemsTypeMember; private XamlMember ItemsTypeMember { get diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs index 26d1000f586..960afb1045d 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs @@ -29,14 +29,14 @@ class XamlScanner XamlScannerStack _scannerStack; XamlParserContext _parserContext; - XamlText _accumulatedText = null; + XamlText _accumulatedText; List _attributes; int _nextAttribute; XamlScannerNode _currentNode; Queue _readNodesQueue; XamlXmlReaderSettings _settings; XamlAttribute _typeArgumentAttribute; - bool _hasKeyAttribute = false; + bool _hasKeyAttribute; internal XamlScanner(XamlParserContext context, XmlReader xmlReader, XamlXmlReaderSettings settings) { diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlBackgroundReader.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlBackgroundReader.cs index 49798482fc7..7b01fbb7823 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlBackgroundReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlBackgroundReader.cs @@ -29,8 +29,8 @@ public class XamlBackgroundReader : XamlReader, IXamlLineInfo XamlWriter _writer; bool _wrappedReaderHasLineInfo; - int _lineNumber=0; - int _linePosition=0; + int _lineNumber; + int _linePosition; Thread _thread; Exception _caughtException; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlNodeList.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlNodeList.cs index 6959d9854cb..a5634c6ec0a 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlNodeList.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlNodeList.cs @@ -16,7 +16,7 @@ namespace System.Xaml public class XamlNodeList { List _nodeList; - bool _readMode = false; + bool _readMode; XamlWriter _writer; bool _hasLineInfo; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs index d87821796c2..7e392514e4e 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs @@ -994,7 +994,7 @@ public virtual void EnsureNoDuplicateNames(Stack> namesInCurrent class ObjectMarkupInfo : ObjectOrValueMarkupInfo { List properties = new List(); - bool? isAttributableMarkupExtension = null; + bool? isAttributableMarkupExtension; public List Properties { get { return properties; } } public string Name { get; set; } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs index 07fc3679d69..0fb24ef6699 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs @@ -683,7 +683,7 @@ internal virtual XamlMember GetAttachableEvent(string name, MethodInfo adder) #region Settings // Unchanging, initialized in ctor - private readonly XamlSchemaContextSettings _settings = null; + private readonly XamlSchemaContextSettings _settings; public bool SupportMarkupExtensionsWithDuplicateArity { From d102362d40937b15b0e0452f86bdb6cbfc7687d0 Mon Sep 17 00:00:00 2001 From: Thomas Goulet Date: Sat, 26 Jun 2021 18:10:41 -0400 Subject: [PATCH 5/7] Enable CA2000 --- eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset | 1 - .../src/System.Xaml/System/Xaml/XamlServices.cs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset index d870fe24b75..e7c59c9ea64 100644 --- a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset +++ b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset @@ -21,7 +21,6 @@ - \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlServices.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlServices.cs index 7622a273997..3b6883320ac 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlServices.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlServices.cs @@ -8,6 +8,7 @@ namespace System.Xaml { + [Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The IDisposable types in this class don't require dispose.")] public static class XamlServices { // The main function is Load(XamlReader) From 077cb99297fcc19060426fa64f52ccc1e4d2bdbb Mon Sep 17 00:00:00 2001 From: Thomas Goulet Date: Sat, 26 Jun 2021 18:24:17 -0400 Subject: [PATCH 6/7] Enable CA2002 --- eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset | 1 - .../src/System.Xaml/System/Xaml/Schema/TypeReflector.cs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset index e7c59c9ea64..a69f4fa0633 100644 --- a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset +++ b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset @@ -21,6 +21,5 @@ - \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs index 3ffd1d9922a..fd98273cf23 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs @@ -13,6 +13,7 @@ namespace System.Xaml.Schema { + [Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2002:Do not lock on objects with weak identity", Justification = "This type is internal.")] class TypeReflector : Reflector { private const XamlCollectionKind XamlCollectionKindInvalid = (XamlCollectionKind)byte.MaxValue; From 619767856f1cee4e4ec71de8c43b64e8d8952826 Mon Sep 17 00:00:00 2001 From: Thomas Goulet Date: Wed, 28 Jul 2021 21:30:05 -0400 Subject: [PATCH 7/7] Enable CA1062 --- eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset | 3 --- .../src/System.Xaml/System/Windows/Markup/ValueSerializer.cs | 3 +++ .../src/System.Xaml/System/Xaml/XamlSchemaContext.cs | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset index a69f4fa0633..4b42f390946 100644 --- a/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset +++ b/eng/WpfArcadeSdk/tools/CodeAnalysis/WpfCodeAnalysis.ruleset @@ -19,7 +19,4 @@ - - - \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs index 75934717af3..b0af7e5f57c 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs @@ -244,6 +244,9 @@ public static ValueSerializer GetSerializerFor(PropertyDescriptor descriptor, IV /// protected Exception GetConvertToException(object value, Type destinationType) { + if (destinationType == null) + throw new ArgumentNullException(nameof(destinationType)); + string text; if (value == null) { diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs index 0fb24ef6699..788933c98a2 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs @@ -542,6 +542,9 @@ private ConcurrentDictionary, Xam public virtual XamlType GetXamlType(Type type) { + if (type == null) + throw new ArgumentNullException(nameof(type)); + return GetXamlType(type, XamlLanguage.TypeAlias(type)); }