diff --git a/.editorconfig b/.editorconfig index 0184b2ddfb4..faea5eabbec 100644 --- a/.editorconfig +++ b/.editorconfig @@ -264,7 +264,7 @@ dotnet_diagnostic.IDE0057.severity = suggestion dotnet_diagnostic.IDE0058.severity = silent # IDE0059: Unnecessary assignment of a value -dotnet_diagnostic.IDE0059.severity = none # TODO: warning +dotnet_diagnostic.IDE0059.severity = warning # IDE0060: Remove unused parameter dotnet_diagnostic.IDE0060.severity = silent @@ -707,7 +707,7 @@ dotnet_diagnostic.CA1819.severity = none dotnet_diagnostic.CA1820.severity = none # CA1821: Remove empty Finalizers -dotnet_diagnostic.CA1821.severity = none # TODO: warning +dotnet_diagnostic.CA1821.severity = warning # CA1822: Mark members as static dotnet_diagnostic.CA1822.severity = warning @@ -1276,7 +1276,7 @@ dotnet_diagnostic.CA5405.severity = error dotnet_diagnostic.CS1573.severity = none # IL3000: Avoid using accessing Assembly file path when publishing as a single-file -dotnet_diagnostic.IL3000.severity = none # TODO: warning +dotnet_diagnostic.IL3000.severity = warning # IL3001: Avoid using accessing Assembly file path when publishing as a single-file dotnet_diagnostic.IL3001.severity = warning @@ -1522,8 +1522,8 @@ dotnet_diagnostic.SA1204.severity = none # SA1205: Partial elements should declare an access modifier dotnet_diagnostic.SA1205.severity = warning -# SA1206: Keyword ordering - TODO Re-enable as warning after https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3527 -dotnet_diagnostic.SA1206.severity = suggestion +# SA1206: Keyword ordering +dotnet_diagnostic.SA1206.severity = warning # SA1207: Protected should come before internal dotnet_diagnostic.SA1207.severity = none @@ -1562,7 +1562,7 @@ dotnet_diagnostic.SA1300.severity = none dotnet_diagnostic.SA1301.severity = none # SA1302: Interface names should begin with I -dotnet_diagnostic.SA1302.severity = none # TODO: warning +dotnet_diagnostic.SA1302.severity = warning # SA1303: Const field names should begin with upper-case letter dotnet_diagnostic.SA1303.severity = none @@ -1616,7 +1616,7 @@ dotnet_diagnostic.SA1402.severity = none dotnet_diagnostic.SA1403.severity = none # SA1404: Code analysis suppression should have justification -dotnet_diagnostic.SA1404.severity = none # TODO: warning +dotnet_diagnostic.SA1404.severity = warning # SA1405: Debug.Assert should provide message text dotnet_diagnostic.SA1405.severity = none diff --git a/src/Microsoft.DotNet.Wpf/cycle-breakers/.editorconfig b/src/Microsoft.DotNet.Wpf/cycle-breakers/.editorconfig index 58c105528bb..0a10a68e6ad 100644 --- a/src/Microsoft.DotNet.Wpf/cycle-breakers/.editorconfig +++ b/src/Microsoft.DotNet.Wpf/cycle-breakers/.editorconfig @@ -14,6 +14,9 @@ dotnet_diagnostic.CA1066.severity = none # CA1725: Parameter names should match base declaration dotnet_diagnostic.CA1725.severity = none +# CA1812: Remove empty finalizers +dotnet_diagnostic.CA1821.severity = none + # CA1822: Mark members as static dotnet_diagnostic.CA1822.severity = none @@ -37,3 +40,6 @@ dotnet_diagnostic.IDE0251.severity = none # IDE1006: Naming Styles dotnet_diagnostic.IDE1006.severity = suggestion + +# SA1206: Keyword ordering +dotnet_diagnostic.SA1206.severity = suggestion diff --git a/src/Microsoft.DotNet.Wpf/src/.editorconfig b/src/Microsoft.DotNet.Wpf/src/.editorconfig index 597fadf387e..27d970fb0af 100644 --- a/src/Microsoft.DotNet.Wpf/src/.editorconfig +++ b/src/Microsoft.DotNet.Wpf/src/.editorconfig @@ -87,7 +87,7 @@ dotnet_diagnostic.CA1810.severity = suggestion # in the GlobalSuppressions file. # CA1815: Override equals and operator equals on value types -dotnet_diagnostic.CA1815.severity = none +dotnet_diagnostic.CA1815.severity = suggestion # CA1822: Mark members as static dotnet_diagnostic.CA1822.severity = suggestion @@ -233,6 +233,9 @@ dotnet_diagnostic.IDE0052.severity = suggestion # IDE0057: Use range operator dotnet_diagnostic.IDE0057.severity = suggestion +# IDE0059: Unnecessary assignment of a value +dotnet_diagnostic.IDE0059.severity = suggestion + # IDE0060: Remove unused parameter dotnet_diagnostic.IDE0060.severity = suggestion @@ -317,9 +320,15 @@ dotnet_diagnostic.SA1129.severity = suggestion # SA1131: Constant values should appear on the right-hand side of comparisons dotnet_diagnostic.SA1131.severity = suggestion +# SA1206: Keyword ordering +dotnet_diagnostic.SA1206.severity = suggestion + # SA1400: Member should declare an access modifier dotnet_diagnostic.SA1400.severity = suggestion +# SA1404: Code analysis suppression should have justification +dotnet_diagnostic.SA1404.severity = suggestion + # SA1408: Conditional expressions should declare precedence dotnet_diagnostic.SA1408.severity = suggestion @@ -342,4 +351,12 @@ dotnet_diagnostic.SA1513.severity = suggestion dotnet_diagnostic.SA1518.severity = suggestion # SYSLIB1045: Convert to 'GeneratedRegexAttribute'. -dotnet_diagnostic.SYSLIB1045.severity = suggestion \ No newline at end of file +dotnet_diagnostic.SYSLIB1045.severity = suggestion + +# --------------------- +# Ref specific C# files +# --------------------- +[*/ref/*.cs] + +# CA1812: Remove empty finalizers +dotnet_diagnostic.CA1821.severity = none \ No newline at end of file diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs index 6bf2edd2637..b0ccdc55dcb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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 file in the project root for more information. @@ -121,9 +121,9 @@ public TaskFileService(Task buildTask) // public Stream GetContent(string srcFile) { - Stream fileStream = null; + Stream fileStream; - if (String.IsNullOrEmpty(srcFile)) + if (string.IsNullOrEmpty(srcFile)) { throw new ArgumentNullException(nameof(srcFile)); } @@ -213,9 +213,9 @@ public byte[] GetChecksum(string fileName, Guid hashGuid) // public DateTime GetLastChangeTime(string srcFile) { - DateTime lastChangeDT = new DateTime(0); + DateTime lastChangeDT; - if (String.IsNullOrEmpty(srcFile)) + if (string.IsNullOrEmpty(srcFile)) { throw new ArgumentNullException(nameof(srcFile)); } @@ -239,7 +239,7 @@ public DateTime GetLastChangeTime(string srcFile) // public bool Exists(string fileName) { - bool fileExists = false; + bool fileExists; if (fileName == null) { @@ -285,7 +285,7 @@ public void Delete(string fileName) // public void WriteFile(byte[] contentArray, string destinationFile) { - if (String.IsNullOrEmpty(destinationFile)) + if (string.IsNullOrEmpty(destinationFile)) { throw new ArgumentNullException(nameof(destinationFile)); } @@ -329,7 +329,7 @@ public void WriteFile(byte[] contentArray, string destinationFile) public void WriteGeneratedCodeFile(byte[] contentArray, string destinationFileBaseName, string generatedExtension, string intellisenseGeneratedExtension, string languageSourceExtension) { - if (String.IsNullOrEmpty(destinationFileBaseName)) + if (string.IsNullOrEmpty(destinationFileBaseName)) { throw new ArgumentNullException(nameof(destinationFileBaseName)); } @@ -434,7 +434,7 @@ private bool IsFileInHostManager(string destinationFile) private Task _buildTask; private IVsMSBuildTaskFileManager _hostFileManager; - private Nullable _isRealBuild; + private bool? _isRealBuild; private static Guid s_hashSHA256Guid = new Guid(0x8829d00f, 0x11b8, 0x4213, 0x87, 0x8b, 0x77, 0x0e, 0x85, 0x97, 0xac, 0x16); private static Guid s_hashSHA1Guid = new Guid(0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60); private static Guid s_hashMD5Guid = new Guid(0x406ea660, 0x64cf, 0x4c82, 0xb6, 0xf0, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs index abfc4bbb8e3..17bd2c0a374 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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 file in the project root for more information. @@ -344,7 +344,7 @@ internal static string GetResourceIdForResourceFile( string sourceDir, bool requestExtensionChange) { - string relPath = String.Empty; + string relPath; // Please note the subtle distinction between and . // is treated as a fully resolvable path and is put through the same @@ -356,7 +356,7 @@ internal static string GetResourceIdForResourceFile( // said in most of the regular scenarios using or will result in // the same resourceId being picked. - if (!String.IsNullOrEmpty(logicalName)) + if (!string.IsNullOrEmpty(logicalName)) { // Use the LogicalName when there is one logicalName = ReplaceXAMLWithBAML(filePath, logicalName, requestExtensionChange); diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs index 9c6afe1c2f8..2290eb97481 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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 file in the project root for more information. @@ -102,29 +102,18 @@ internal static Type GetConverterType(MemberInfo memberInfo) { Debug.Assert(null != memberInfo, "Null passed for memberInfo to GetConverterType"); - Type converterType = null; - // Try looking for the TypeConverter for the type using reflection. - string converterName = ReflectionHelper.GetTypeConverterAttributeData(memberInfo, out converterType); - - if (converterType == null) - { - converterType = GetConverterTypeFromName(converterName); - } - - return converterType; + string converterName = ReflectionHelper.GetTypeConverterAttributeData(memberInfo, out Type converterType); + return converterType ?? GetConverterTypeFromName(converterName); } #endif internal static Type? GetConverterType(Type type) { - Debug.Assert(null != type, "Null passed for type to GetConverterType"); + Debug.Assert(type is not null, "Null passed for type to GetConverterType"); // Try looking for the TypeConverter for the type using reflection. string? converterName = ReflectionHelper.GetTypeConverterAttributeData(type, out Type? converterType); - - converterType ??= GetConverterTypeFromName(converterName); - - return converterType; + return converterType ?? GetConverterTypeFromName(converterName); } private static Type? GetConverterTypeFromName(string? converterName) diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationFramework.Fluent.Tests/System/Windows/Controls/ButtonTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationFramework.Fluent.Tests/System/Windows/Controls/ButtonTests.cs index 0b151e08147..53e2292f506 100644 --- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationFramework.Fluent.Tests/System/Windows/Controls/ButtonTests.cs +++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationFramework.Fluent.Tests/System/Windows/Controls/ButtonTests.cs @@ -8,6 +8,6 @@ public class ButtonTests [WpfFact] public void Button_Create() { - Button button = new(); + Button _ = new(); } } diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/StaticExtensionTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/StaticExtensionTests.cs index ef56b83f4e2..ff39b7abc70 100644 --- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/StaticExtensionTests.cs +++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/StaticExtensionTests.cs @@ -223,7 +223,7 @@ public void StaticExtensionConverter_ConvertToString_ReturnsExpected() { var extension = new StaticExtension("member"); TypeConverter converter = TypeDescriptor.GetConverter(extension); - InstanceDescriptor descriptor = Assert.IsType(converter.ConvertTo(extension, typeof(InstanceDescriptor))); + Assert.IsType(converter.ConvertTo(extension, typeof(InstanceDescriptor))); Assert.Equal(extension.ToString(), converter.ConvertTo(extension, typeof(string))); } diff --git a/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/TypeExtensionTests.cs b/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/TypeExtensionTests.cs index 3abbfc2f3d7..1c97fb7d60a 100644 --- a/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/TypeExtensionTests.cs +++ b/src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/TypeExtensionTests.cs @@ -184,7 +184,7 @@ public void TypeExtensionConverter_ConvertToString_ReturnsExpected() { var extension = new TypeExtension("member"); TypeConverter converter = TypeDescriptor.GetConverter(extension); - InstanceDescriptor descriptor = Assert.IsType(converter.ConvertTo(extension, typeof(InstanceDescriptor))); + Assert.IsType(converter.ConvertTo(extension, typeof(InstanceDescriptor))); Assert.Equal(extension.ToString(), converter.ConvertTo(extension, typeof(string))); }