Skip to content

Commit d32d194

Browse files
authored
Enable TODO analyzers (#10109)
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.
1 parent a3ea647 commit d32d194

File tree

9 files changed

+52
-40
lines changed

9 files changed

+52
-40
lines changed

.editorconfig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ dotnet_diagnostic.IDE0057.severity = suggestion
264264
dotnet_diagnostic.IDE0058.severity = silent
265265

266266
# IDE0059: Unnecessary assignment of a value
267-
dotnet_diagnostic.IDE0059.severity = none # TODO: warning
267+
dotnet_diagnostic.IDE0059.severity = warning
268268

269269
# IDE0060: Remove unused parameter
270270
dotnet_diagnostic.IDE0060.severity = silent
@@ -707,7 +707,7 @@ dotnet_diagnostic.CA1819.severity = none
707707
dotnet_diagnostic.CA1820.severity = none
708708

709709
# CA1821: Remove empty Finalizers
710-
dotnet_diagnostic.CA1821.severity = none # TODO: warning
710+
dotnet_diagnostic.CA1821.severity = warning
711711

712712
# CA1822: Mark members as static
713713
dotnet_diagnostic.CA1822.severity = warning
@@ -1276,7 +1276,7 @@ dotnet_diagnostic.CA5405.severity = error
12761276
dotnet_diagnostic.CS1573.severity = none
12771277

12781278
# IL3000: Avoid using accessing Assembly file path when publishing as a single-file
1279-
dotnet_diagnostic.IL3000.severity = none # TODO: warning
1279+
dotnet_diagnostic.IL3000.severity = warning
12801280

12811281
# IL3001: Avoid using accessing Assembly file path when publishing as a single-file
12821282
dotnet_diagnostic.IL3001.severity = warning
@@ -1522,8 +1522,8 @@ dotnet_diagnostic.SA1204.severity = none
15221522
# SA1205: Partial elements should declare an access modifier
15231523
dotnet_diagnostic.SA1205.severity = warning
15241524

1525-
# SA1206: Keyword ordering - TODO Re-enable as warning after https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3527
1526-
dotnet_diagnostic.SA1206.severity = suggestion
1525+
# SA1206: Keyword ordering
1526+
dotnet_diagnostic.SA1206.severity = warning
15271527

15281528
# SA1207: Protected should come before internal
15291529
dotnet_diagnostic.SA1207.severity = none
@@ -1562,7 +1562,7 @@ dotnet_diagnostic.SA1300.severity = none
15621562
dotnet_diagnostic.SA1301.severity = none
15631563

15641564
# SA1302: Interface names should begin with I
1565-
dotnet_diagnostic.SA1302.severity = none # TODO: warning
1565+
dotnet_diagnostic.SA1302.severity = warning
15661566

15671567
# SA1303: Const field names should begin with upper-case letter
15681568
dotnet_diagnostic.SA1303.severity = none
@@ -1616,7 +1616,7 @@ dotnet_diagnostic.SA1402.severity = none
16161616
dotnet_diagnostic.SA1403.severity = none
16171617

16181618
# SA1404: Code analysis suppression should have justification
1619-
dotnet_diagnostic.SA1404.severity = none # TODO: warning
1619+
dotnet_diagnostic.SA1404.severity = warning
16201620

16211621
# SA1405: Debug.Assert should provide message text
16221622
dotnet_diagnostic.SA1405.severity = none

src/Microsoft.DotNet.Wpf/cycle-breakers/.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ dotnet_diagnostic.CA1066.severity = none
1414
# CA1725: Parameter names should match base declaration
1515
dotnet_diagnostic.CA1725.severity = none
1616

17+
# CA1812: Remove empty finalizers
18+
dotnet_diagnostic.CA1821.severity = none
19+
1720
# CA1822: Mark members as static
1821
dotnet_diagnostic.CA1822.severity = none
1922

@@ -37,3 +40,6 @@ dotnet_diagnostic.IDE0251.severity = none
3740

3841
# IDE1006: Naming Styles
3942
dotnet_diagnostic.IDE1006.severity = suggestion
43+
44+
# SA1206: Keyword ordering
45+
dotnet_diagnostic.SA1206.severity = suggestion

src/Microsoft.DotNet.Wpf/src/.editorconfig

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ dotnet_diagnostic.CA1810.severity = suggestion
8787
# in the GlobalSuppressions file.
8888

8989
# CA1815: Override equals and operator equals on value types
90-
dotnet_diagnostic.CA1815.severity = none
90+
dotnet_diagnostic.CA1815.severity = suggestion
9191

9292
# CA1822: Mark members as static
9393
dotnet_diagnostic.CA1822.severity = suggestion
@@ -233,6 +233,9 @@ dotnet_diagnostic.IDE0052.severity = suggestion
233233
# IDE0057: Use range operator
234234
dotnet_diagnostic.IDE0057.severity = suggestion
235235

236+
# IDE0059: Unnecessary assignment of a value
237+
dotnet_diagnostic.IDE0059.severity = suggestion
238+
236239
# IDE0060: Remove unused parameter
237240
dotnet_diagnostic.IDE0060.severity = suggestion
238241

@@ -317,9 +320,15 @@ dotnet_diagnostic.SA1129.severity = suggestion
317320
# SA1131: Constant values should appear on the right-hand side of comparisons
318321
dotnet_diagnostic.SA1131.severity = suggestion
319322

323+
# SA1206: Keyword ordering
324+
dotnet_diagnostic.SA1206.severity = suggestion
325+
320326
# SA1400: Member should declare an access modifier
321327
dotnet_diagnostic.SA1400.severity = suggestion
322328

329+
# SA1404: Code analysis suppression should have justification
330+
dotnet_diagnostic.SA1404.severity = suggestion
331+
323332
# SA1408: Conditional expressions should declare precedence
324333
dotnet_diagnostic.SA1408.severity = suggestion
325334

@@ -342,4 +351,12 @@ dotnet_diagnostic.SA1513.severity = suggestion
342351
dotnet_diagnostic.SA1518.severity = suggestion
343352

344353
# SYSLIB1045: Convert to 'GeneratedRegexAttribute'.
345-
dotnet_diagnostic.SYSLIB1045.severity = suggestion
354+
dotnet_diagnostic.SYSLIB1045.severity = suggestion
355+
356+
# ---------------------
357+
# Ref specific C# files
358+
# ---------------------
359+
[*/ref/*.cs]
360+
361+
# CA1812: Remove empty finalizers
362+
dotnet_diagnostic.CA1821.severity = none

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/TaskFileService.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

@@ -121,9 +121,9 @@ public TaskFileService(Task buildTask)
121121
//
122122
public Stream GetContent(string srcFile)
123123
{
124-
Stream fileStream = null;
124+
Stream fileStream;
125125

126-
if (String.IsNullOrEmpty(srcFile))
126+
if (string.IsNullOrEmpty(srcFile))
127127
{
128128
throw new ArgumentNullException(nameof(srcFile));
129129
}
@@ -213,9 +213,9 @@ public byte[] GetChecksum(string fileName, Guid hashGuid)
213213
//
214214
public DateTime GetLastChangeTime(string srcFile)
215215
{
216-
DateTime lastChangeDT = new DateTime(0);
216+
DateTime lastChangeDT;
217217

218-
if (String.IsNullOrEmpty(srcFile))
218+
if (string.IsNullOrEmpty(srcFile))
219219
{
220220
throw new ArgumentNullException(nameof(srcFile));
221221
}
@@ -239,7 +239,7 @@ public DateTime GetLastChangeTime(string srcFile)
239239
//
240240
public bool Exists(string fileName)
241241
{
242-
bool fileExists = false;
242+
bool fileExists;
243243

244244
if (fileName == null)
245245
{
@@ -285,7 +285,7 @@ public void Delete(string fileName)
285285
//
286286
public void WriteFile(byte[] contentArray, string destinationFile)
287287
{
288-
if (String.IsNullOrEmpty(destinationFile))
288+
if (string.IsNullOrEmpty(destinationFile))
289289
{
290290
throw new ArgumentNullException(nameof(destinationFile));
291291
}
@@ -329,7 +329,7 @@ public void WriteFile(byte[] contentArray, string destinationFile)
329329
public void WriteGeneratedCodeFile(byte[] contentArray, string destinationFileBaseName,
330330
string generatedExtension, string intellisenseGeneratedExtension, string languageSourceExtension)
331331
{
332-
if (String.IsNullOrEmpty(destinationFileBaseName))
332+
if (string.IsNullOrEmpty(destinationFileBaseName))
333333
{
334334
throw new ArgumentNullException(nameof(destinationFileBaseName));
335335
}
@@ -434,7 +434,7 @@ private bool IsFileInHostManager(string destinationFile)
434434

435435
private Task _buildTask;
436436
private IVsMSBuildTaskFileManager _hostFileManager;
437-
private Nullable<bool> _isRealBuild;
437+
private bool? _isRealBuild;
438438
private static Guid s_hashSHA256Guid = new Guid(0x8829d00f, 0x11b8, 0x4213, 0x87, 0x8b, 0x77, 0x0e, 0x85, 0x97, 0xac, 0x16);
439439
private static Guid s_hashSHA1Guid = new Guid(0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60);
440440
private static Guid s_hashMD5Guid = new Guid(0x406ea660, 0x64cf, 0x4c82, 0xb6, 0xf0, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99);

src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

@@ -344,7 +344,7 @@ internal static string GetResourceIdForResourceFile(
344344
string sourceDir,
345345
bool requestExtensionChange)
346346
{
347-
string relPath = String.Empty;
347+
string relPath;
348348

349349
// Please note the subtle distinction between <Link /> and <LogicalName />.
350350
// <Link /> is treated as a fully resolvable path and is put through the same
@@ -356,7 +356,7 @@ internal static string GetResourceIdForResourceFile(
356356
// said in most of the regular scenarios using <Link /> or <Logical /> will result in
357357
// the same resourceId being picked.
358358

359-
if (!String.IsNullOrEmpty(logicalName))
359+
if (!string.IsNullOrEmpty(logicalName))
360360
{
361361
// Use the LogicalName when there is one
362362
logicalName = ReplaceXAMLWithBAML(filePath, logicalName, requestExtensionChange);

src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/TypeConverterHelper.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

@@ -102,29 +102,18 @@ internal static Type GetConverterType(MemberInfo memberInfo)
102102
{
103103
Debug.Assert(null != memberInfo, "Null passed for memberInfo to GetConverterType");
104104

105-
Type converterType = null;
106-
107105
// Try looking for the TypeConverter for the type using reflection.
108-
string converterName = ReflectionHelper.GetTypeConverterAttributeData(memberInfo, out converterType);
109-
110-
if (converterType == null)
111-
{
112-
converterType = GetConverterTypeFromName(converterName);
113-
}
114-
115-
return converterType;
106+
string converterName = ReflectionHelper.GetTypeConverterAttributeData(memberInfo, out Type converterType);
107+
return converterType ?? GetConverterTypeFromName(converterName);
116108
}
117109
#endif
118110
internal static Type? GetConverterType(Type type)
119111
{
120-
Debug.Assert(null != type, "Null passed for type to GetConverterType");
112+
Debug.Assert(type is not null, "Null passed for type to GetConverterType");
121113

122114
// Try looking for the TypeConverter for the type using reflection.
123115
string? converterName = ReflectionHelper.GetTypeConverterAttributeData(type, out Type? converterType);
124-
125-
converterType ??= GetConverterTypeFromName(converterName);
126-
127-
return converterType;
116+
return converterType ?? GetConverterTypeFromName(converterName);
128117
}
129118

130119
private static Type? GetConverterTypeFromName(string? converterName)

src/Microsoft.DotNet.Wpf/tests/UnitTests/PresentationFramework.Fluent.Tests/System/Windows/Controls/ButtonTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public class ButtonTests
88
[WpfFact]
99
public void Button_Create()
1010
{
11-
Button button = new();
11+
Button _ = new();
1212
}
1313
}

src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/StaticExtensionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public void StaticExtensionConverter_ConvertToString_ReturnsExpected()
223223
{
224224
var extension = new StaticExtension("member");
225225
TypeConverter converter = TypeDescriptor.GetConverter(extension);
226-
InstanceDescriptor descriptor = Assert.IsType<InstanceDescriptor>(converter.ConvertTo(extension, typeof(InstanceDescriptor)));
226+
Assert.IsType<InstanceDescriptor>(converter.ConvertTo(extension, typeof(InstanceDescriptor)));
227227
Assert.Equal(extension.ToString(), converter.ConvertTo(extension, typeof(string)));
228228
}
229229

src/Microsoft.DotNet.Wpf/tests/UnitTests/System.Xaml.Tests/System/Windows/Markup/TypeExtensionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void TypeExtensionConverter_ConvertToString_ReturnsExpected()
184184
{
185185
var extension = new TypeExtension("member");
186186
TypeConverter converter = TypeDescriptor.GetConverter(extension);
187-
InstanceDescriptor descriptor = Assert.IsType<InstanceDescriptor>(converter.ConvertTo(extension, typeof(InstanceDescriptor)));
187+
Assert.IsType<InstanceDescriptor>(converter.ConvertTo(extension, typeof(InstanceDescriptor)));
188188
Assert.Equal(extension.ToString(), converter.ConvertTo(extension, typeof(string)));
189189
}
190190

0 commit comments

Comments
 (0)