Update CodeAnalysis config with recent rules (#100146)

This commit is contained in:
Stephen Toub 2024-03-25 08:46:15 -04:00 committed by GitHub
parent 330b70cfac
commit c659c6e511
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 117 additions and 30 deletions

View File

@ -489,6 +489,15 @@ dotnet_diagnostic.CA1863.severity = suggestion
# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1864.severity = warning
# CA1865: Use char overload
dotnet_diagnostic.CA1865.severity = warning
# CA1866: Use char overload
dotnet_diagnostic.CA1866.severity = warning
# CA1867: Use char overload
dotnet_diagnostic.CA1867.severity = warning
# CA1868: Unnecessary call to 'Contains' for sets
dotnet_diagnostic.CA1868.severity = warning
@ -501,6 +510,9 @@ dotnet_diagnostic.CA1870.severity = warning
# CA1871: Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'
dotnet_diagnostic.CA1871.severity = warning
# CA1872: Prefer 'Convert.ToHexString' and 'Convert.ToHexStringLower' over call chains based on 'BitConverter.ToString'
dotnet_diagnostic.CA1872.severity = warning
# CA2000: Dispose objects before losing scope
dotnet_diagnostic.CA2000.severity = none
@ -610,9 +622,6 @@ dotnet_diagnostic.CA2226.severity = none
# CA2227: Collection properties should be read only
dotnet_diagnostic.CA2227.severity = none
# CA2229: Implement serialization constructors
dotnet_diagnostic.CA2229.severity = warning
# CA2231: Overload operator equals on overriding value type Equals
dotnet_diagnostic.CA2231.severity = none
@ -692,7 +701,7 @@ dotnet_diagnostic.CA2261.severity = warning
dotnet_diagnostic.CA2262.severity = warning
# CA2263: Prefer generic overload when type is known
dotnet_diagnostic.CA2263.severity = info
dotnet_diagnostic.CA2263.severity = suggestion
# CA2264: Do not pass a non-nullable value to 'ArgumentNullException.ThrowIfNull'
dotnet_diagnostic.CA2264.severity = warning
@ -1827,7 +1836,7 @@ dotnet_diagnostic.IDE0200.severity = warning
# IDE0210: Use top-level statements
dotnet_diagnostic.IDE0210.severity = none
# IDE0211: Use program main
# IDE0211: Convert to 'Program.Main' style program
dotnet_diagnostic.IDE0211.severity = none
# IDE0220: foreach cast
@ -1845,6 +1854,9 @@ dotnet_diagnostic.IDE0241.severity = suggestion
# IDE0250: Make struct readonly
dotnet_diagnostic.IDE0250.severity = suggestion
# IDE0251: Make member readonly
dotnet_diagnostic.IDE0251.severity = suggestion
# IDE0260: Use pattern matching
dotnet_diagnostic.IDE0260.severity = suggestion
@ -1854,6 +1866,27 @@ dotnet_diagnostic.IDE0270.severity = suggestion
# IDE0280: Use 'nameof'
dotnet_diagnostic.IDE0280.severity = warning
# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = suggestion
# IDE0300: Use collection expression for array
dotnet_diagnostic.IDE0300.severity = suggestion
# IDE0301: Use collection expression for empty
dotnet_diagnostic.IDE0301.severity = suggestion
# IDE0302: Use collection expression for stackalloc
dotnet_diagnostic.IDE0302.severity = suggestion
# IDE0303: Use collection expression for Create()
dotnet_diagnostic.IDE0303.severity = suggestion
# IDE0304: Use collection expression for builder
dotnet_diagnostic.IDE0304.severity = suggestion
# IDE0305: Use collection expression for fluent
dotnet_diagnostic.IDE0305.severity = suggestion
# IDE1005: Delegate invocation can be simplified.
dotnet_diagnostic.IDE1005.severity = warning
@ -1874,3 +1907,9 @@ dotnet_diagnostic.IDE2003.severity = silent
# IDE2004: Blank line not allowed after constructor initializer colon
dotnet_diagnostic.IDE2004.severity = silent
# IDE2005: Blank line not allowed after conditional expression token
dotnet_diagnostic.IDE2005.severity = silent
# IDE2006: Blank line not allowed after arrow expression clause token
dotnet_diagnostic.IDE2006.severity = silent

View File

@ -486,6 +486,15 @@ dotnet_diagnostic.CA1863.severity = none
# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1864.severity = none
# CA1865: Use char overload
dotnet_diagnostic.CA1865.severity = none
# CA1866: Use char overload
dotnet_diagnostic.CA1866.severity = none
# CA1867: Use char overload
dotnet_diagnostic.CA1867.severity = none
# CA1868: Unnecessary call to 'Contains' for sets
dotnet_diagnostic.CA1868.severity = none
@ -498,6 +507,9 @@ dotnet_diagnostic.CA1870.severity = none
# CA1871: Do not pass a nullable struct to 'ArgumentNullException.ThrowIfNull'
dotnet_diagnostic.CA1871.severity = none
# CA1872: Prefer 'Convert.ToHexString' and 'Convert.ToHexStringLower' over call chains based on 'BitConverter.ToString'
dotnet_diagnostic.CA1872.severity = none
# CA2000: Dispose objects before losing scope
dotnet_diagnostic.CA2000.severity = none
@ -1821,7 +1833,7 @@ dotnet_diagnostic.IDE0200.severity = silent
# IDE0210: Use top-level statements
dotnet_diagnostic.IDE0210.severity = silent
# IDE0211: Use program main
# IDE0211: Convert to 'Program.Main' style program
dotnet_diagnostic.IDE0211.severity = silent
# IDE0220: foreach cast
@ -1839,6 +1851,9 @@ dotnet_diagnostic.IDE0241.severity = silent
# IDE0250: Make struct readonly
dotnet_diagnostic.IDE0250.severity = silent
# IDE0251: Make member readonly
dotnet_diagnostic.IDE0251.severity = silent
# IDE0260: Use pattern matching
dotnet_diagnostic.IDE0260.severity = silent
@ -1848,6 +1863,27 @@ dotnet_diagnostic.IDE0270.severity = silent
# IDE0280: Use 'nameof'
dotnet_diagnostic.IDE0280.severity = silent
# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = silent
# IDE0300: Use collection expression for array
dotnet_diagnostic.IDE0300.severity = silent
# IDE0301: Use collection expression for empty
dotnet_diagnostic.IDE0301.severity = silent
# IDE0302: Use collection expression for stackalloc
dotnet_diagnostic.IDE0302.severity = silent
# IDE0303: Use collection expression for Create()
dotnet_diagnostic.IDE0303.severity = silent
# IDE0304: Use collection expression for builder
dotnet_diagnostic.IDE0304.severity = silent
# IDE0305: Use collection expression for fluent
dotnet_diagnostic.IDE0305.severity = silent
# IDE1005: Delegate invocation can be simplified.
dotnet_diagnostic.IDE1005.severity = silent
@ -1869,6 +1905,12 @@ dotnet_diagnostic.IDE2003.severity = silent
# IDE2004: Blank line not allowed after constructor initializer colon
dotnet_diagnostic.IDE2004.severity = silent
# IDE2005: Blank line not allowed after conditional expression token
dotnet_diagnostic.IDE2005.severity = silent
# IDE2006: Blank line not allowed after arrow expression clause token
dotnet_diagnostic.IDE2006.severity = silent
# xUnit1000: Test classes must be public
dotnet_diagnostic.xUnit1000.severity = warning

View File

@ -108,7 +108,7 @@ namespace ILCompiler
hash = SHA256.HashData(GetBytesFromString(literal));
}
mangledName += "_" + BitConverter.ToString(hash).Replace("-", "");
mangledName += "_" + Convert.ToHexString(hash);
}
return mangledName;

View File

@ -92,7 +92,7 @@ namespace ILCompiler.ObjectWriter
Name =
section == ObjectNodeSection.TLSSection ? ".tls$" :
section == ObjectNodeSection.HydrationTargetSection ? "hydrated" :
(section.Name.StartsWith(".") ? section.Name : "." + section.Name),
(section.Name.StartsWith('.') ? section.Name : "." + section.Name),
SectionCharacteristics = section.Type switch
{
SectionType.ReadOnly =>

View File

@ -72,7 +72,7 @@ namespace ILCompiler
int valueIndex = 0;
foreach (string line in _runtimeOptions)
{
int indexOfEquals = line.IndexOf("=");
int indexOfEquals = line.IndexOf('=');
if (indexOfEquals > 0)
{
string key = line.Substring(0, indexOfEquals);

View File

@ -70,7 +70,7 @@ namespace ILCompiler
private string HashData(byte[] data)
{
return BitConverter.ToString(_sha256.ComputeHash(data)).Replace("-", "").ToLowerInvariant();
return Convert.ToHexStringLower(_sha256.ComputeHash(data));
}
internal override void End()

View File

@ -4,6 +4,7 @@
<AssemblyName>ILCompiler.Compiler</AssemblyName>
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA1866;CA1867</NoWarn>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Platforms>x64;x86</Platforms>
<PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -373,7 +373,7 @@ namespace Internal.Metadata.NativeFormat.Writer
// 3rd, the name, Quote the string if not already quoted
string asString = rec.ToString(false);
bool alreadyQuoted = asString.StartsWith("\"") && asString.EndsWith("\"");
bool alreadyQuoted = asString.StartsWith('\"') && asString.EndsWith('\"');
if (!alreadyQuoted)
{
LogWriter.Write("\"");

View File

@ -5,6 +5,7 @@
<AssemblyName>ILCompiler.TypeSystem</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
<NoWarn>$(NoWarn);CA1866</NoWarn>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Platforms>x64;x86</Platforms>
<PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<NoWarn>$(NoWarn);CA1866</NoWarn>
<EnableDefaultItems>true</EnableDefaultItems>
<IsPackable>true</IsPackable>
<PackageDescription>Command line configuration provider implementation for Microsoft.Extensions.Configuration. This package enables you to read configuration parameters from the command line arguments of your application. You can use CommandLineConfigurationExtensions.AddCommandLine extension method on IConfigurationBuilder to add the command line configuration provider to the configuration builder.</PackageDescription>

View File

@ -4,6 +4,7 @@
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<RootNamespace>Microsoft.Extensions.FileProviders</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA1865;CA1866</NoWarn>
<EnableDefaultItems>true</EnableDefaultItems>
<IsPackable>true</IsPackable>
<PackageDescription>File provider for physical files for Microsoft.Extensions.FileProviders.</PackageDescription>

View File

@ -5,7 +5,7 @@
<TargetFrameworks Condition="'$(NetCoreAppPrevious)' != ''">$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeInternalObsoleteAttribute>true</IncludeInternalObsoleteAttribute>
<NoWarn>$(NoWarn);IDE0059;IDE0060;CA1822</NoWarn>
<NoWarn>$(NoWarn);IDE0059;IDE0060;CA1822;CA1865</NoWarn>
<EnableAOTAnalyzer>false</EnableAOTAnalyzer>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>

View File

@ -5,7 +5,7 @@
<TargetFrameworks Condition="'$(NetCoreAppPrevious)' != ''">$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);0618</NoWarn>
<NoWarn>$(NoWarn);IDE0059;IDE0060;CA1822</NoWarn>
<NoWarn>$(NoWarn);IDE0059;IDE0060;CA1822;CA1865</NoWarn>
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>

View File

@ -7,6 +7,7 @@
<EnableAOTAnalyzer>false</EnableAOTAnalyzer>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
<NoWarn>$(NoWarn);CA1865</NoWarn>
<PackageDescription>Provides read-only reflection on assemblies in an isolated context with support for assemblies that target different processor architectures and runtimes. Using MetadataLoadContext enables you to inspect assemblies without loading them into the main execution context. Assemblies in MetadataLoadContext are treated only as metadata, that is, you can read information about their members, but cannot execute any code contained in them.</PackageDescription>
</PropertyGroup>

View File

@ -333,7 +333,7 @@ namespace System.Runtime.InteropServices.JavaScript
var nameSpace = "";
var shortClassName = className;
var idx = fqn.LastIndexOf(".");
var idx = fqn.LastIndexOf('.');
if (idx != -1)
{
nameSpace = fqn.Substring(0, idx);

View File

@ -4,7 +4,7 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks Condition="'$(NetCoreAppPrevious)' != ''">$(TargetFrameworks);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA2249</NoWarn>
<NoWarn>$(NoWarn);CA2249;CA1865</NoWarn>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
<PackageDescription>Provides the System.ServiceProcess.ServiceController class, which allows you to connect to a Windows service, manipulate it, or get information about it.

View File

@ -204,7 +204,7 @@ namespace GenDefinedCharList
// Ranges are represented within angle brackets, such as the following:
// DC00;<Low Surrogate, First>;Cs;0;L;;;;;N;;;;;
// DFFF;<Low Surrogate, Last>;Cs;0;L;;;;;N;;;;;
if (rawName.StartsWith("<", StringComparison.Ordinal))
if (rawName.StartsWith('<'))
{
if (rawName.EndsWith(", First>", StringComparison.Ordinal))
{

View File

@ -582,7 +582,7 @@ namespace System.Text.RegularExpressions.Tests
Assert.Equal(expectedMin, tree.FindOptimizations.MinRequiredLength);
if (!pattern.EndsWith("$", StringComparison.Ordinal) &&
if (!pattern.EndsWith('$') &&
!pattern.EndsWith(@"\Z", StringComparison.OrdinalIgnoreCase))
{
// MaxPossibleLength is currently only computed/stored if there's a trailing End{Z} anchor as the max length is otherwise unused

View File

@ -1446,7 +1446,7 @@ namespace Microsoft.WebAssembly.Diagnostics
{
string key = sourceLinkDocument.Key;
if (!key.EndsWith("*", StringComparison.OrdinalIgnoreCase))
if (!key.EndsWith('*'))
{
continue;
}

View File

@ -1373,7 +1373,7 @@ namespace Microsoft.WebAssembly.Diagnostics
using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdAssembly.GetName, commandParamsWriter, token);
var name = retDebuggerCmdReader.ReadString();
return name.Remove(name.IndexOf(",")) + ".dll";
return name.Remove(name.IndexOf(',')) + ".dll";
}
public async Task<string> GetMethodName(int methodId, CancellationToken token)
@ -2185,7 +2185,7 @@ namespace Microsoft.WebAssembly.Diagnostics
asyncLocal["name"] = match.Groups["varName"].Value;
}
}
else if (fieldName.StartsWith("$"))
else if (fieldName.StartsWith('$'))
{
continue;
}

View File

@ -746,7 +746,7 @@ namespace Mono.Options
public override bool GetArguments(string value, out IEnumerable<string> replacement)
{
if (string.IsNullOrEmpty(value) || !value.StartsWith("@"))
if (string.IsNullOrEmpty(value) || !value.StartsWith('@'))
{
replacement = null;
return false;

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>$(AspNetCoreAppCurrent)</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<NoWarn>$(NoWarn),CA2007</NoWarn>
<NoWarn>$(NoWarn);CA2007</NoWarn>
<Nullable>enable</Nullable>
<UseAppHost>false</UseAppHost>
<RollForward>LatestMajor</RollForward>

View File

@ -206,7 +206,7 @@ public partial class ApkBuilder
// also, aapt is not happy about zip files
return false;
}
if (fileName.StartsWith("."))
if (fileName.StartsWith('.'))
{
// aapt complains on such files
return false;

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
<NoWarn>$(NoWarn),CA1050,CA1850,CA1845,CA1859,NU5128</NoWarn>
<NoWarn>$(NoWarn),CA1050,CA1850,CA1845,CA1859;CA1866,NU5128</NoWarn>
<RootNamespace>Microsoft.NET.Sdk.WebAssembly</RootNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

View File

@ -100,7 +100,7 @@ namespace Mono.Linker
{
result = new Queue<string> ();
foreach (string arg in args) {
if (arg.StartsWith ("@")) {
if (arg.StartsWith ('@')) {
try {
string responseFileName = arg.Substring (1);
using (var responseFileText = new StreamReader (responseFileName))
@ -933,7 +933,7 @@ namespace Mono.Linker
bool TryGetCustomAssembly (ref string arg, [NotNullWhen (true)] out Assembly? assembly)
{
assembly = null;
int pos = arg.IndexOf (",");
int pos = arg.IndexOf (',');
if (pos == -1)
return false;
@ -963,7 +963,7 @@ namespace Mono.Linker
}
customStepName = parts[1];
if (!parts[0].StartsWith ("-") && !parts[0].StartsWith ("+")) {
if (!parts[0].StartsWith ('-') && !parts[0].StartsWith ('+')) {
Context.LogError (null, DiagnosticId.ExpectedSignToControlNewStepInsertion);
return false;
}
@ -1239,7 +1239,7 @@ namespace Mono.Linker
return true;
}
if (arg.StartsWith ("-") || arg.StartsWith ("/")) {
if (arg.StartsWith ('-') || arg.StartsWith ('/')) {
action (true);
return true;
}
@ -1272,7 +1272,7 @@ namespace Mono.Linker
return null;
var arg = arguments.Peek ();
if (arg.StartsWith ("-") || arg.StartsWith ("/"))
if (arg.StartsWith ('-') || arg.StartsWith ('/'))
return null;
arguments.Dequeue ();

View File

@ -267,7 +267,7 @@ namespace Mono.Linker
public TypeDefinition? GetType (string fullName)
{
int pos = fullName.IndexOf (",");
int pos = fullName.IndexOf (',');
fullName = TypeReferenceExtensions.ToCecilName (fullName);
if (pos == -1) {
foreach (AssemblyDefinition asm in GetReferencedAssemblies ()) {

View File

@ -16,6 +16,7 @@
<!-- There are currently no translations, so the satellite assemblies are a waste of space. -->
<EnableXlfLocalization>false</EnableXlfLocalization>
<NoWarn Condition="'$(DotNetBuildSourceOnly)' == 'true'">$(NoWarn);CS8524</NoWarn>
<NoWarn>$(NoWarn);CA1866</NoWarn>
<ContractProject>$(MSBuildThisFileDirectory)ref\Mono.Linker.csproj</ContractProject>
<RollForward>Major</RollForward>
<UseAppHost>false</UseAppHost>