Skip to content

Commit c6906ae

Browse files
authored
Update dependencies from dotnet/roslyn-analyzers, config new analyzers (#99343)
* Reapply "[main] Update dependencies from dotnet/roslyn-analyzers (#98984)" (#99327) * Configure new analyzers severity in src and test projects * Fix some of CA2263 warnings
1 parent c806bf6 commit c6906ae

File tree

16 files changed

+68
-24
lines changed

16 files changed

+68
-24
lines changed

eng/CodeAnalysis.src.globalconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ dotnet_diagnostic.CA1512.severity = warning
274274
# CA1513: Use ObjectDisposedException throw helper
275275
dotnet_diagnostic.CA1513.severity = warning
276276

277+
# CA1514: Avoid redundant length argument
278+
dotnet_diagnostic.CA1514.severity = warning
279+
280+
# CA1515: Consider making public types internal
281+
dotnet_diagnostic.CA1515.severity = none
282+
277283
# CA1700: Do not name enum values 'Reserved'
278284
dotnet_diagnostic.CA1700.severity = none
279285

@@ -492,6 +498,9 @@ dotnet_diagnostic.CA1869.severity = warning
492498
# CA1870: Use a cached 'SearchValues' instance
493499
dotnet_diagnostic.CA1870.severity = warning
494500

501+
# CA1871: Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'
502+
dotnet_diagnostic.CA1871.severity = warning
503+
495504
# CA2000: Dispose objects before losing scope
496505
dotnet_diagnostic.CA2000.severity = none
497506

@@ -679,6 +688,18 @@ dotnet_diagnostic.CA2260.severity = warning
679688
# CA2261: Do not use ConfigureAwaitOptions.SuppressThrowing with Task<TResult>
680689
dotnet_diagnostic.CA2261.severity = warning
681690

691+
# CA2262: Set 'MaxResponseHeadersLength' properly
692+
dotnet_diagnostic.CA2262.severity = warning
693+
694+
# CA2263: Prefer generic overload when type is known
695+
dotnet_diagnostic.CA2263.severity = info
696+
697+
# CA2264: Do not pass a non-nullable value to 'ArgumentNullException.ThrowIfNull'
698+
dotnet_diagnostic.CA2264.severity = warning
699+
700+
# CA2265: Do not compare Span<T> to 'null' or 'default'
701+
dotnet_diagnostic.CA2265.severity = warning
702+
682703
# CA2300: Do not use insecure deserializer BinaryFormatter
683704
dotnet_diagnostic.CA2300.severity = none
684705

eng/CodeAnalysis.test.globalconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ dotnet_diagnostic.CA1512.severity = none
273273
# CA1513: Use ObjectDisposedException throw helper
274274
dotnet_diagnostic.CA1513.severity = none
275275

276+
# CA1514: Avoid redundant length argument
277+
dotnet_diagnostic.CA1514.severity = none
278+
279+
# CA1515: Consider making public types internal
280+
dotnet_diagnostic.CA1515.severity = none
281+
276282
# CA1700: Do not name enum values 'Reserved'
277283
dotnet_diagnostic.CA1700.severity = none
278284

@@ -489,6 +495,9 @@ dotnet_diagnostic.CA1869.severity = none
489495
# CA1870: Use a cached 'SearchValues' instance
490496
dotnet_diagnostic.CA1870.severity = none
491497

498+
# CA1871: Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'
499+
dotnet_diagnostic.CA1871.severity = none
500+
492501
# CA2000: Dispose objects before losing scope
493502
dotnet_diagnostic.CA2000.severity = none
494503

@@ -675,6 +684,18 @@ dotnet_diagnostic.CA2260.severity = none
675684
# CA2261: Do not use ConfigureAwaitOptions.SuppressThrowing with Task<TResult>
676685
dotnet_diagnostic.CA2261.severity = none
677686

687+
# CA2262: Set 'MaxResponseHeadersLength' properly
688+
dotnet_diagnostic.CA2262.severity = none
689+
690+
# CA2263: Prefer generic overload when type is known
691+
dotnet_diagnostic.CA2263.severity = none
692+
693+
# CA2264: Do not pass a non-nullable value to 'ArgumentNullException.ThrowIfNull'
694+
dotnet_diagnostic.CA2264.severity = none
695+
696+
# CA2265: Do not compare Span<T> to 'null' or 'default'
697+
dotnet_diagnostic.CA2265.severity = none
698+
678699
# CA2300: Do not use insecure deserializer BinaryFormatter
679700
dotnet_diagnostic.CA2300.severity = none
680701

eng/Version.Details.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,13 @@
404404
<Uri>https://github.com/dotnet/roslyn</Uri>
405405
<Sha>77372c66fd54927312b5b0a2e399e192f74445c9</Sha>
406406
</Dependency>
407-
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.24122.2">
407+
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.24155.1">
408408
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
409-
<Sha>ba8b7f2c3ae092d0301f0c5e49bd30340af553c8</Sha>
409+
<Sha>628d239421a3ae54464c60901fd9b831b3f01efa</Sha>
410410
</Dependency>
411-
<Dependency Name="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0-preview.24122.2">
411+
<Dependency Name="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0-preview.24155.1">
412412
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
413-
<Sha>ba8b7f2c3ae092d0301f0c5e49bd30340af553c8</Sha>
413+
<Sha>628d239421a3ae54464c60901fd9b831b3f01efa</Sha>
414414
</Dependency>
415415
<!-- Intermediate is necessary for source build. -->
416416
<Dependency Name="Microsoft.SourceBuild.Intermediate.roslyn" Version="4.10.0-2.24114.13">

eng/Versions.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
</ItemGroup>
3535
<PropertyGroup>
3636
<!-- dotnet/roslyn-analyzers dependencies -->
37-
<MicrosoftCodeAnalysisAnalyzersVersion>3.11.0-beta1.24122.2</MicrosoftCodeAnalysisAnalyzersVersion>
38-
<MicrosoftCodeAnalysisNetAnalyzersVersion>9.0.0-preview.24122.2</MicrosoftCodeAnalysisNetAnalyzersVersion>
37+
<MicrosoftCodeAnalysisAnalyzersVersion>3.11.0-beta1.24155.1</MicrosoftCodeAnalysisAnalyzersVersion>
38+
<MicrosoftCodeAnalysisNetAnalyzersVersion>9.0.0-preview.24155.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
3939
<!-- dotnet/roslyn dependencies -->
4040
<!--
4141
These versions should not be used by any project that contributes to the design-time experience in VS, such as an analyzer, code-fix, or generator assembly.

src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public class InstructionSetSupportBuilder
175175
private static Dictionary<TargetArchitecture, Dictionary<string, InstructionSet>> ComputeInstructionSetSupport()
176176
{
177177
var supportMatrix = new Dictionary<TargetArchitecture, Dictionary<string, InstructionSet>>();
178-
foreach (TargetArchitecture arch in Enum.GetValues(typeof(TargetArchitecture)))
178+
foreach (TargetArchitecture arch in Enum.GetValues<TargetArchitecture>())
179179
{
180180
supportMatrix[arch] = ComputeInstructSetSupportForArch(arch);
181181
}
@@ -186,7 +186,7 @@ private static Dictionary<TargetArchitecture, Dictionary<string, InstructionSet>
186186
private static Dictionary<TargetArchitecture, InstructionSetFlags> ComputeNonSpecifiableInstructionSetSupport()
187187
{
188188
var matrix = new Dictionary<TargetArchitecture, InstructionSetFlags>();
189-
foreach (TargetArchitecture arch in Enum.GetValues(typeof(TargetArchitecture)))
189+
foreach (TargetArchitecture arch in Enum.GetValues<TargetArchitecture>())
190190
{
191191
matrix[arch] = ComputeNonSpecifiableInstructionSetSupportForArch(arch);
192192
}

src/coreclr/tools/aot/ILCompiler.MetadataTransform/Internal/Metadata/NativeFormat/Writer/NativeMetadataWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ public partial class MethodSemantics
875875
{
876876
public override string ToString()
877877
{
878-
string str = Enum.GetName(typeof(MethodSemanticsAttributes), Attributes);
878+
string str = Enum.GetName(Attributes);
879879
return str + " : " + Method.ToString();
880880
}
881881
}
@@ -903,7 +903,7 @@ public partial class PropertySignature
903903
{
904904
public override string ToString()
905905
{
906-
return string.Join(" ", Enum.GetName(typeof(CallingConventions), CallingConvention),
906+
return string.Join(" ", Enum.GetName(CallingConvention),
907907
Type.ToString()) + "(" + ToString(Parameters) + ")";
908908
}
909909
}

src/libraries/Common/src/System/Resources/ResourceWriter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,11 @@ private static ResourceTypeCode FindTypeCode(object? value, List<string> types)
488488
if (typeName.StartsWith("ResourceTypeCode.", StringComparison.Ordinal))
489489
{
490490
typeName = typeName.Substring(17); // Remove through '.'
491+
#if NETCOREAPP
492+
ResourceTypeCode typeCode = Enum.Parse<ResourceTypeCode>(typeName);
493+
#else
491494
ResourceTypeCode typeCode = (ResourceTypeCode)Enum.Parse(typeof(ResourceTypeCode), typeName);
495+
#endif
492496
return typeCode;
493497
}
494498
}

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/Schema/DatabaseGeneratedAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class DatabaseGeneratedAttribute : Attribute
1515
/// <param name="databaseGeneratedOption">The pattern used to generate values for the property in the database.</param>
1616
public DatabaseGeneratedAttribute(DatabaseGeneratedOption databaseGeneratedOption)
1717
{
18-
if (!(Enum.IsDefined(typeof(DatabaseGeneratedOption), databaseGeneratedOption)))
18+
if (!Enum.IsDefined(databaseGeneratedOption))
1919
{
2020
throw new ArgumentOutOfRangeException(nameof(databaseGeneratedOption));
2121
}

src/libraries/System.Configuration.ConfigurationManager/src/System/Diagnostics/TraceConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static void InitializingTraceSource(object sender, InitializingTraceSour
5555

5656
if (!string.IsNullOrEmpty(sourceElement.SwitchValue))
5757
{
58-
traceSource.Switch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), sourceElement.SwitchValue);
58+
traceSource.Switch.Level = Enum.Parse<SourceLevels>(sourceElement.SwitchValue);
5959
}
6060
}
6161
}
@@ -74,7 +74,7 @@ private static void InitializingTraceSource(object sender, InitializingTraceSour
7474
// The SwitchValue changed; just update our internalSwitch.
7575
if (!string.IsNullOrEmpty(sourceElement.SwitchValue))
7676
{
77-
traceSource.Switch.Level = (SourceLevels)Enum.Parse(typeof(SourceLevels), sourceElement.SwitchValue);
77+
traceSource.Switch.Level = Enum.Parse<SourceLevels>(sourceElement.SwitchValue);
7878
}
7979
else
8080
{

src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public EventLogEntryType EntryType
3939
get => _entryType;
4040
set
4141
{
42-
if (!Enum.IsDefined(typeof(EventLogEntryType), value))
42+
if (!Enum.IsDefined(value))
4343
throw new InvalidEnumArgumentException(nameof(EntryType), (int)value, typeof(EventLogEntryType));
4444

4545
_entryType = value;

0 commit comments

Comments
 (0)