Skip to content

Commit

Permalink
Enable TODO analyzers (#10109)
Browse files Browse the repository at this point in the history
Remove TODO from root .editorconfig and add temporary/permanent overrides. Fix the few instances in tests and a few random files in the other sources related to these analyzers.
  • Loading branch information
JeremyKuhne authored Nov 25, 2024
1 parent a3ea647 commit d32d194
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 40 deletions.
14 changes: 7 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.DotNet.Wpf/cycle-breakers/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
21 changes: 19 additions & 2 deletions src/Microsoft.DotNet.Wpf/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -342,4 +351,12 @@ dotnet_diagnostic.SA1513.severity = suggestion
dotnet_diagnostic.SA1518.severity = suggestion

# SYSLIB1045: Convert to 'GeneratedRegexAttribute'.
dotnet_diagnostic.SYSLIB1045.severity = suggestion
dotnet_diagnostic.SYSLIB1045.severity = suggestion

# ---------------------
# Ref specific C# files
# ---------------------
[*/ref/*.cs]

# CA1812: Remove empty finalizers
dotnet_diagnostic.CA1821.severity = none
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -239,7 +239,7 @@ public DateTime GetLastChangeTime(string srcFile)
//
public bool Exists(string fileName)
{
bool fileExists = false;
bool fileExists;

if (fileName == null)
{
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -434,7 +434,7 @@ private bool IsFileInHostManager(string destinationFile)

private Task _buildTask;
private IVsMSBuildTaskFileManager _hostFileManager;
private Nullable<bool> _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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -344,7 +344,7 @@ internal static string GetResourceIdForResourceFile(
string sourceDir,
bool requestExtensionChange)
{
string relPath = String.Empty;
string relPath;

// Please note the subtle distinction between <Link /> and <LogicalName />.
// <Link /> is treated as a fully resolvable path and is put through the same
Expand All @@ -356,7 +356,7 @@ internal static string GetResourceIdForResourceFile(
// said in most of the regular scenarios using <Link /> or <Logical /> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public class ButtonTests
[WpfFact]
public void Button_Create()
{
Button button = new();
Button _ = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void StaticExtensionConverter_ConvertToString_ReturnsExpected()
{
var extension = new StaticExtension("member");
TypeConverter converter = TypeDescriptor.GetConverter(extension);
InstanceDescriptor descriptor = Assert.IsType<InstanceDescriptor>(converter.ConvertTo(extension, typeof(InstanceDescriptor)));
Assert.IsType<InstanceDescriptor>(converter.ConvertTo(extension, typeof(InstanceDescriptor)));
Assert.Equal(extension.ToString(), converter.ConvertTo(extension, typeof(string)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void TypeExtensionConverter_ConvertToString_ReturnsExpected()
{
var extension = new TypeExtension("member");
TypeConverter converter = TypeDescriptor.GetConverter(extension);
InstanceDescriptor descriptor = Assert.IsType<InstanceDescriptor>(converter.ConvertTo(extension, typeof(InstanceDescriptor)));
Assert.IsType<InstanceDescriptor>(converter.ConvertTo(extension, typeof(InstanceDescriptor)));
Assert.Equal(extension.ToString(), converter.ConvertTo(extension, typeof(string)));
}

Expand Down

0 comments on commit d32d194

Please sign in to comment.