1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-09 17:44:48 +09:00

Enable new analyzers CA1862, CA1864 in runtime and fix findings. (#88700)

* Enable new analyzers CA1862, CA1864 in runtime and fix findings
This commit is contained in:
Buyaa Namnan 2023-07-13 19:57:02 -07:00 committed by GitHub
parent b4118a6a81
commit 9409e2d501
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 36 additions and 67 deletions

View file

@ -474,6 +474,12 @@ dotnet_diagnostic.CA1860.severity = warning
# CA1861: Avoid constant arrays as arguments # CA1861: Avoid constant arrays as arguments
dotnet_diagnostic.CA1861.severity = warning dotnet_diagnostic.CA1861.severity = warning
# CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons
dotnet_diagnostic.CA1862.severity = warning
# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1864.severity = warning
# CA2000: Dispose objects before losing scope # CA2000: Dispose objects before losing scope
dotnet_diagnostic.CA2000.severity = none dotnet_diagnostic.CA2000.severity = none

View file

@ -471,6 +471,12 @@ dotnet_diagnostic.CA1860.severity = none
# CA1861: Avoid constant arrays as arguments # CA1861: Avoid constant arrays as arguments
dotnet_diagnostic.CA1861.severity = none dotnet_diagnostic.CA1861.severity = none
# CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons
dotnet_diagnostic.CA1862.severity = none
# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1864.severity = none
# CA2000: Dispose objects before losing scope # CA2000: Dispose objects before losing scope
dotnet_diagnostic.CA2000.severity = none dotnet_diagnostic.CA2000.severity = none

View file

@ -353,8 +353,7 @@ namespace ILCompiler
lock (this) lock (this)
{ {
// Ensure that name is unique and update our tables accordingly. // Ensure that name is unique and update our tables accordingly.
if (!_mangledTypeNames.ContainsKey(type)) _mangledTypeNames.TryAdd(type, mangledName);
_mangledTypeNames.Add(type, mangledName);
} }
return mangledName; return mangledName;
@ -386,8 +385,7 @@ namespace ILCompiler
lock (this) lock (this)
{ {
if (!_mangledMethodNames.ContainsKey(method)) _mangledMethodNames.TryAdd(method, utf8MangledName);
_mangledMethodNames.Add(method, utf8MangledName);
} }
return utf8MangledName; return utf8MangledName;
@ -557,8 +555,7 @@ namespace ILCompiler
{ {
lock (this) lock (this)
{ {
if (!_unqualifiedMangledMethodNames.ContainsKey(method)) _unqualifiedMangledMethodNames.TryAdd(method, utf8MangledName);
_unqualifiedMangledMethodNames.Add(method, utf8MangledName);
} }
} }
@ -622,8 +619,7 @@ namespace ILCompiler
lock (this) lock (this)
{ {
if (!_mangledFieldNames.ContainsKey(field)) _mangledFieldNames.TryAdd(field, utf8MangledName);
_mangledFieldNames.Add(field, utf8MangledName);
} }
return utf8MangledName; return utf8MangledName;
@ -644,8 +640,7 @@ namespace ILCompiler
lock (this) lock (this)
{ {
if (!_mangledStringLiterals.ContainsKey(literal)) _mangledStringLiterals.TryAdd(literal, mangledName);
_mangledStringLiterals.Add(literal, mangledName);
} }
return mangledName; return mangledName;

View file

@ -51,10 +51,7 @@ Arch: {Arch}
MethodProfileData[] dataArray = methodData.ToArray(); MethodProfileData[] dataArray = methodData.ToArray();
foreach (MethodProfileData data in dataArray) foreach (MethodProfileData data in dataArray)
{ {
if (!_methodData.ContainsKey(data.Method)) _methodData.TryAdd(data.Method, data);
{
_methodData.Add(data.Method, data);
}
} }
_partialNGen = partialNGen; _partialNGen = partialNGen;
_config = config; _config = config;

View file

@ -129,8 +129,9 @@ namespace System.Diagnostics.Metrics
if (state != null) if (state != null)
{ {
_beginInstrumentMeasurements(instrument); _beginInstrumentMeasurements(instrument);
#pragma warning disable CA1864 // Prefer the 'IDictionary.TryAdd(TKey, TValue)' method. IDictionary.TryAdd() is not available in one of the builds
if (!_instruments.ContainsKey(instrument)) if (!_instruments.ContainsKey(instrument))
#pragma warning restore CA1864
{ {
// This has side effects that prompt MeasurementsCompleted // This has side effects that prompt MeasurementsCompleted
// to be called if this is called multiple times on an // to be called if this is called multiple times on an

View file

@ -522,7 +522,7 @@ namespace System.Diagnostics
} }
else else
{ {
if (processInfos.ContainsKey(processInfo.ProcessId)) if (!processInfos.TryAdd(processInfo.ProcessId, processInfo))
{ {
// We've found two entries in the perfcounters that claim to be the // We've found two entries in the perfcounters that claim to be the
// same process. We throw an exception. Is this really going to be // same process. We throw an exception. Is this really going to be
@ -549,7 +549,6 @@ namespace System.Diagnostics
} }
} }
processInfo.ProcessName = instanceName.ToString(); processInfo.ProcessName = instanceName.ToString();
processInfos.Add(processInfo.ProcessId, processInfo);
} }
} }
} }

View file

@ -667,11 +667,10 @@ namespace System.DirectoryServices.AccountManagement
if (null == foreignSid.sidIssuerName) if (null == foreignSid.sidIssuerName)
{ {
// create and return the unknown principal if it is not yet present in usersVisited // create and return the unknown principal if it is not yet present in usersVisited
if (!_usersVisited.ContainsKey(foreignSid.name)) if (_usersVisited.TryAdd(foreignSid.name, true))
{ {
byte[] sid = Utils.ConvertNativeSidToByteArray(foreignSid.pSid); byte[] sid = Utils.ConvertNativeSidToByteArray(foreignSid.pSid);
UnknownPrincipal unknownPrincipal = UnknownPrincipal.CreateUnknownPrincipal(_storeCtx.OwningContext, sid, foreignSid.name); UnknownPrincipal unknownPrincipal = UnknownPrincipal.CreateUnknownPrincipal(_storeCtx.OwningContext, sid, foreignSid.name);
_usersVisited.Add(foreignSid.name, true);
this.current = null; this.current = null;
_currentForeignDE = null; _currentForeignDE = null;
_currentForeignPrincipal = unknownPrincipal; _currentForeignPrincipal = unknownPrincipal;

View file

@ -157,10 +157,7 @@ namespace System.Xml.Schema
XmlSchemaInfo? si = o.Annotation<XmlSchemaInfo>(); XmlSchemaInfo? si = o.Annotation<XmlSchemaInfo>();
if (si != null) if (si != null)
{ {
if (!schemaInfos.ContainsKey(si)) schemaInfos.TryAdd(si, si);
{
schemaInfos.Add(si, si);
}
o.RemoveAnnotations<XmlSchemaInfo>(); o.RemoveAnnotations<XmlSchemaInfo>();
} }
if (!schemaInfos.TryGetValue(schemaInfo, out si)) if (!schemaInfos.TryGetValue(schemaInfo, out si))

View file

@ -1229,17 +1229,11 @@ namespace System.Xml
if (isParamEntity) if (isParamEntity)
{ {
if (!_schemaInfo.ParameterEntities.ContainsKey(entityName)) _schemaInfo.ParameterEntities.TryAdd(entityName, entity);
{
_schemaInfo.ParameterEntities.Add(entityName, entity);
}
} }
else else
{ {
if (!_schemaInfo.GeneralEntities.ContainsKey(entityName)) _schemaInfo.GeneralEntities.TryAdd(entityName, entity);
{
_schemaInfo.GeneralEntities.Add(entityName, entity);
}
} }
entity.DeclaredInExternal = !ParsingInternalSubset; entity.DeclaredInExternal = !ParsingInternalSubset;
entity.ParsingInProgress = true; entity.ParsingInProgress = true;

View file

@ -861,17 +861,11 @@ namespace System.Xml
if (isParamEntity) if (isParamEntity)
{ {
if (!_schemaInfo.ParameterEntities.ContainsKey(entityName)) _schemaInfo.ParameterEntities.TryAdd(entityName, entity);
{
_schemaInfo.ParameterEntities.Add(entityName, entity);
}
} }
else else
{ {
if (!_schemaInfo.GeneralEntities.ContainsKey(entityName)) _schemaInfo.GeneralEntities.TryAdd(entityName, entity);
{
_schemaInfo.GeneralEntities.Add(entityName, entity);
}
} }
entity.DeclaredInExternal = !ParsingInternalSubset; entity.DeclaredInExternal = !ParsingInternalSubset;
entity.ParsingInProgress = true; entity.ParsingInProgress = true;

View file

@ -305,10 +305,7 @@ namespace System.Xml.Schema
SchemaNotation no = new SchemaNotation(notation.QualifiedName); SchemaNotation no = new SchemaNotation(notation.QualifiedName);
no.SystemLiteral = notation.System; no.SystemLiteral = notation.System;
no.Pubid = notation.Public; no.Pubid = notation.Public;
if (!schemaInfo.Notations.ContainsKey(no.Name.Name)) schemaInfo.Notations.TryAdd(no.Name.Name, no);
{
schemaInfo.Notations.Add(no.Name.Name, no);
}
} }
} }

View file

@ -299,10 +299,7 @@ namespace System.Xml.Schema
foreach (string tns in sinfo.TargetNamespaces.Keys) foreach (string tns in sinfo.TargetNamespaces.Keys)
{ {
if (!_targetNamespaces.ContainsKey(tns)) _targetNamespaces.TryAdd(tns, true);
{
_targetNamespaces.Add(tns, true);
}
} }
foreach (KeyValuePair<XmlQualifiedName, SchemaElementDecl> entry in sinfo._elementDecls) foreach (KeyValuePair<XmlQualifiedName, SchemaElementDecl> entry in sinfo._elementDecls)
@ -321,17 +318,11 @@ namespace System.Xml.Schema
} }
foreach (SchemaAttDef attdef in sinfo.AttributeDecls.Values) foreach (SchemaAttDef attdef in sinfo.AttributeDecls.Values)
{ {
if (!_attributeDecls.ContainsKey(attdef.Name)) _attributeDecls.TryAdd(attdef.Name, attdef);
{
_attributeDecls.Add(attdef.Name, attdef);
}
} }
foreach (SchemaNotation notation in sinfo.Notations.Values) foreach (SchemaNotation notation in sinfo.Notations.Values)
{ {
if (!Notations.ContainsKey(notation.Name.Name)) Notations.TryAdd(notation.Name.Name, notation);
{
Notations.Add(notation.Name.Name, notation);
}
} }
} }

View file

@ -167,10 +167,7 @@ namespace System.Xml.Schema
SchemaNotation no = new SchemaNotation(notation!.QualifiedName); SchemaNotation no = new SchemaNotation(notation!.QualifiedName);
no.SystemLiteral = notation.System; no.SystemLiteral = notation.System;
no.Pubid = notation.Public; no.Pubid = notation.Public;
if (!schemaInfo.Notations.ContainsKey(no.Name.Name)) schemaInfo.Notations.TryAdd(no.Name.Name, no);
{
schemaInfo.Notations.Add(no.Name.Name, no);
}
} }
} }

View file

@ -1051,11 +1051,7 @@ namespace System.Xml.Schema
// Global AttributeTypes are URN qualified so that we can look them up across schemas. // Global AttributeTypes are URN qualified so that we can look them up across schemas.
qname = new XmlQualifiedName(qname.Name, builder._TargetNamespace); qname = new XmlQualifiedName(qname.Name, builder._TargetNamespace);
builder._AttributeDef._AttDef.Name = qname; builder._AttributeDef._AttDef.Name = qname;
if (!builder._SchemaInfo.AttributeDecls.ContainsKey(qname)) if (!builder._SchemaInfo.AttributeDecls.TryAdd(qname, builder._AttributeDef._AttDef))
{
builder._SchemaInfo.AttributeDecls.Add(qname, builder._AttributeDef._AttDef);
}
else
{ {
builder.SendValidationEvent(SR.Sch_DupAttribute, XmlQualifiedName.ToString(qname.Name, prefix)); builder.SendValidationEvent(SR.Sch_DupAttribute, XmlQualifiedName.ToString(qname.Name, prefix));
} }

View file

@ -577,6 +577,7 @@ public class ComputeWasmPublishAssets : Task
foreach (var candidate in resolvedFilesToPublish) foreach (var candidate in resolvedFilesToPublish)
{ {
#pragma warning disable CA1864 // Prefer the 'IDictionary.TryAdd(TKey, TValue)' method. Dictionary.TryAdd() not available in .Net framework.
if (AssetsComputingHelper.ShouldFilterCandidate(candidate, TimeZoneSupport, InvariantGlobalization, CopySymbols, customIcuCandidateFilename, EnableThreads, EmitSourceMap, out var reason)) if (AssetsComputingHelper.ShouldFilterCandidate(candidate, TimeZoneSupport, InvariantGlobalization, CopySymbols, customIcuCandidateFilename, EnableThreads, EmitSourceMap, out var reason))
{ {
Log.LogMessage(MessageImportance.Low, "Skipping asset '{0}' because '{1}'", candidate.ItemSpec, reason); Log.LogMessage(MessageImportance.Low, "Skipping asset '{0}' because '{1}'", candidate.ItemSpec, reason);
@ -654,6 +655,7 @@ public class ComputeWasmPublishAssets : Task
} }
continue; continue;
} }
#pragma warning restore CA1864
} }
} }

View file

@ -72,9 +72,7 @@ namespace TLens.Analyzers
methods.Add (method); methods.Add (method);
} }
if (!fields.ContainsKey (field)) if (!fields.TryAdd (field, access))
fields.Add (field, access);
else
fields[field] |= access; fields[field] |= access;
} }
} }