Skip to content

Commit

Permalink
Apply code fixes from recently added analyzers (#36097)
Browse files Browse the repository at this point in the history
* Apply code-fixes from recently added analyzers

* Test CI with the analyzers enabled

* Fix build break

* Sneaked in from a merge?
  • Loading branch information
Prashanth Govindarajan authored Jun 3, 2020
1 parent 15e2ee6 commit 6b6f520
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn),0419,0649</NoWarn>
<NoWarn>$(NoWarn),0419,0649,CA2249,CA1830</NoWarn>
<Nullable>enable</Nullable>

<!-- Ignore all previous constants since SPCL is sensitive to what is defined and the Sdk adds some by default -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Color ConvertFromString(string strValue, CultureInfo culture)
// If the value is a 6 digit hex number only, then
// we want to treat the Alpha as 255, not 0
//
if (text.IndexOf(sep) == -1)
if (!text.Contains(sep))
{
// text can be '' (empty quoted string)
if (text.Length >= 2 && (text[0] == '\'' || text[0] == '"') && text[0] == text[text.Length - 1])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CS1573</NoWarn>
<NoWarn>$(NoWarn);CS1573;CA2249</NoWarn>
<DefineConstants>$(DefineConstants);REGISTRY_ASSEMBLY</DefineConstants>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetFrameworkCurrent)-Windows_NT;netstandard2.0-Windows_NT;netstandard2.0-Unix;netstandard2.0;net461-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
// <value> -> <value>
builder.Append(keyValue);
}
// string.Contains(char) is .NetCore2.1+ specific
else if ((-1 != keyValue.IndexOf('\"')) && (-1 == keyValue.IndexOf('\'')))
else if ((keyValue.Contains('\"')) && (!keyValue.Contains('\'')))
{
// <val"ue> -> <'val"ue'>
builder.Append('\'');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ private void ScanName(char chEnd, char esc, string charsToEscape)
{
if (text[_pos] == esc)
{
if (_pos + 1 < text.Length && charsToEscape.IndexOf(text[_pos + 1]) >= 0)
if (_pos + 1 < text.Length && charsToEscape.Contains(text[_pos + 1]))
{
_pos++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ internal static string ParseName(char[] text, int start, int pos)
{
if (text[i] == esc)
{
if (i + 1 < pos && charsToEscape.IndexOf(text[i + 1]) >= 0)
if (i + 1 < pos && charsToEscape.Contains(text[i + 1]))
{
i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ public string SimpleTypeQualifiedName

internal string QualifiedName(string name)
{
int iStart = name.IndexOf(':');
if (iStart == -1)
if (!name.Contains(':'))
return Keywords.XSD_PREFIXCOLON + name;
else
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ private void CollectElementsAnnotations(XmlSchema schema, ArrayList schemaList)

internal static string QualifiedName(string name)
{
int iStart = name.IndexOf(':');
if (iStart == -1)
if (!name.Contains(':'))
return Keywords.XSD_PREFIXCOLON + name;
else
return name;
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NoWarn>$(NoWarn);CA2249</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;netcoreapp2.0-FreeBSD;netcoreapp2.0-Linux;netcoreapp2.0-OSX;netcoreapp2.0-Windows_NT;net461-Windows_NT;netstandard2.0;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetFrameworkCurrent)-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);FLAVOR_WHIDBEY;PAPI_AD;PAPI_REGSAM;USE_CTX_CACHE</DefineConstants>
<NoWarn>$(NoWarn);8073;CA1810</NoWarn>
<NoWarn>$(NoWarn);8073;CA1810;CA2249</NoWarn>
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;netstandard2.0;netcoreapp2.0-Windows_NT;_$(NetFrameworkCurrent)</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public bool KeepAlive
header = header.ToLowerInvariant();
_keepAlive =
header.IndexOf("close", StringComparison.OrdinalIgnoreCase) < 0 ||
header.IndexOf("keep-alive", StringComparison.OrdinalIgnoreCase) >= 0;
header.Contains("keep-alive", StringComparison.OrdinalIgnoreCase);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public bool UseDefaultCredentials

private static Uri? CreateProxyUri(string? address) =>
address == null ? null :
address.IndexOf("://", StringComparison.Ordinal) == -1 ? new Uri("http://" + address) :
!address.Contains("://") ? new Uri("http://" + address) :
new Uri(address);

private void UpdateRegexList(bool canThrow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5489,26 +5489,26 @@ public void StartEvent(string eventName, EventAttribute eventAttribute)
byteArrArgIndices = null;

events.Append(" <event").
Append(" value=\"").Append(eventAttribute.EventId).Append("\"").
Append(" version=\"").Append(eventAttribute.Version).Append("\"").
Append(" level=\"").Append(GetLevelName(eventAttribute.Level)).Append("\"").
Append(" symbol=\"").Append(eventName).Append("\"");
Append(" value=\"").Append(eventAttribute.EventId).Append('"').
Append(" version=\"").Append(eventAttribute.Version).Append('"').
Append(" level=\"").Append(GetLevelName(eventAttribute.Level)).Append('"').
Append(" symbol=\"").Append(eventName).Append('"');

// at this point we add to the manifest's stringTab a message that is as-of-yet
// "untranslated to manifest convention", b/c we don't have the number or position
// of any byte[] args (which require string format index updates)
WriteMessageAttrib(events, "event", eventName, eventAttribute.Message);

if (eventAttribute.Keywords != 0)
events.Append(" keywords=\"").Append(GetKeywords((ulong)eventAttribute.Keywords, eventName)).Append("\"");
events.Append(" keywords=\"").Append(GetKeywords((ulong)eventAttribute.Keywords, eventName)).Append('"');
if (eventAttribute.Opcode != 0)
events.Append(" opcode=\"").Append(GetOpcodeName(eventAttribute.Opcode, eventName)).Append("\"");
events.Append(" opcode=\"").Append(GetOpcodeName(eventAttribute.Opcode, eventName)).Append('"');
if (eventAttribute.Task != 0)
events.Append(" task=\"").Append(GetTaskName(eventAttribute.Task, eventName)).Append("\"");
events.Append(" task=\"").Append(GetTaskName(eventAttribute.Task, eventName)).Append('"');
#if FEATURE_MANAGED_ETW_CHANNELS
if (eventAttribute.Channel != 0)
{
events.Append(" channel=\"").Append(GetChannelName(eventAttribute.Channel, eventName, eventAttribute.Message)).Append("\"");
events.Append(" channel=\"").Append(GetChannelName(eventAttribute.Channel, eventName, eventAttribute.Message)).Append('"');
}
#endif
}
Expand All @@ -5529,7 +5529,7 @@ public void AddEventParameter(Type type, string name)
templates.Append(" <data name=\"").Append(name).AppendLine("Size\" inType=\"win:UInt32\"/>");
}
numParams++;
templates.Append(" <data name=\"").Append(name).Append("\" inType=\"").Append(GetTypeName(type)).Append("\"");
templates.Append(" <data name=\"").Append(name).Append("\" inType=\"").Append(GetTypeName(type)).Append('"');
// TODO: for 'byte*' types it assumes the user provided length is named using the same naming convention
// as for 'byte[]' args (blob_arg_name + "Size")
if ((type.IsArray || type.IsPointer) && type.GetElementType() == typeof(byte))
Expand All @@ -5540,7 +5540,7 @@ public void AddEventParameter(Type type, string name)
// ETW does not support 64-bit value maps, so we don't specify these as ETW maps
if (type.IsEnum() && Enum.GetUnderlyingType(type) != typeof(ulong) && Enum.GetUnderlyingType(type) != typeof(long))
{
templates.Append(" map=\"").Append(type.Name).Append("\"");
templates.Append(" map=\"").Append(type.Name).Append('"');
mapsTab ??= new Dictionary<string, Type>();
if (!mapsTab.ContainsKey(type.Name))
mapsTab.Add(type.Name, type); // Remember that we need to dump the type enumeration
Expand Down Expand Up @@ -5680,16 +5680,16 @@ private string CreateManifestString()
fullName ??= providerName + "/" + channelInfo.Name;

sb.Append(" <").Append(ElementName);
sb.Append(" chid=\"").Append(channelInfo.Name).Append("\"");
sb.Append(" name=\"").Append(fullName).Append("\"");
sb.Append(" chid=\"").Append(channelInfo.Name).Append('"');
sb.Append(" name=\"").Append(fullName).Append('"');
if (ElementName == "channel") // not applicable to importChannels.
{
Debug.Assert(channelInfo.Name != null);
WriteMessageAttrib(sb, "channel", channelInfo.Name, null);
sb.Append(" value=\"").Append(channel).Append("\"");
sb.Append(" value=\"").Append(channel).Append('"');
if (channelType != null)
sb.Append(" type=\"").Append(channelType).Append("\"");
sb.Append(" enabled=\"").Append(enabled ? "true" : "false").Append("\"");
sb.Append(" type=\"").Append(channelType).Append('"');
sb.Append(" enabled=\"").Append(enabled ? "true" : "false").Append('"');
#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
if (access != null)
sb.Append(" access=\"").Append(access).Append("\"");
Expand Down Expand Up @@ -5747,7 +5747,7 @@ private string CreateManifestString()
// TODO: Warn people about the dropping of values.
if (isbitmap && ((hexValue & (hexValue - 1)) != 0 || hexValue == 0))
continue;
sb.Append(" <map value=\"0x").Append(hexValue.ToString("x", CultureInfo.InvariantCulture)).Append("\"");
sb.Append(" <map value=\"0x").Append(hexValue.ToString("x", CultureInfo.InvariantCulture)).Append('"');
WriteMessageAttrib(sb, "map", enumType.Name + "." + staticField.Name, staticField.Name);
sb.AppendLine("/>");
anyValuesWritten = true;
Expand Down Expand Up @@ -5847,7 +5847,7 @@ private string CreateManifestString()
#region private
private void WriteNameAndMessageAttribs(StringBuilder stringBuilder, string elementName, string name)
{
stringBuilder.Append(" name=\"").Append(name).Append("\"");
stringBuilder.Append(" name=\"").Append(name).Append('"');
WriteMessageAttrib(sb, elementName, name, name);
}
private void WriteMessageAttrib(StringBuilder stringBuilder, string elementName, string name, string? value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ public override void WriteCData(string? text)
try
{
AutoComplete(Token.CData);
if (null != text && text.IndexOf("]]>", StringComparison.Ordinal) >= 0)
if (null != text && text.Contains("]]>"))
{
throw new ArgumentException(SR.Xml_InvalidCDataChars);
}
Expand All @@ -768,7 +768,7 @@ public override void WriteComment(string text)
{
try
{
if (null != text && (text.IndexOf("--", StringComparison.Ordinal) >= 0 || (text.Length != 0 && text[text.Length - 1] == '-')))
if (null != text && (text.Contains("--") || (text.Length != 0 && text[text.Length - 1] == '-')))
{
throw new ArgumentException(SR.Xml_InvalidCommentChars);
}
Expand All @@ -792,7 +792,7 @@ public override void WriteProcessingInstruction(string name, string? text)
{
try
{
if (null != text && text.IndexOf("?>", StringComparison.Ordinal) >= 0)
if (null != text && text.Contains("?>"))
{
throw new ArgumentException(SR.Xml_InvalidPiChars);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public DecimalFormatter(string formatPicture, DecimalFormat decimalFormat)
}
}
// Escape characters having special meaning for CLR
if (ClrSpecialChars.IndexOf(ch) >= 0)
if (ClrSpecialChars.Contains(ch))
{
temp.Append('\\');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ private string LexKindToString(LexKind t)

if (LexKind.LastNonChar < t)
{
Debug.Assert("()[].@,*/$}".IndexOf((char)t) >= 0);
Debug.Assert("()[].@,*/$}".Contains((char)t));
return char.ToString((char)t);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefaultLanguage>en-US</DefaultLanguage>
<NoWarn>$(NoWarn);CA2249</NoWarn>
<CLSCompliant>false</CLSCompliant>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard1.1;netstandard2.0</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA2249</NoWarn>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;netstandard2.0;netstandard2.0-Windows_NT;net461-Windows_NT;$(NetFrameworkCurrent)-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>
Expand Down

0 comments on commit 6b6f520

Please sign in to comment.