Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main] Update dependencies from dotnet/roslyn-analyzers #89630

Merged
merged 20 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
81a6878
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Jul 28, 2023
99a2229
Fix new analyzer errors
lewing Jul 28, 2023
7db61f3
Fix another IndexOf usage
lewing Jul 28, 2023
bb4c767
Fix another warning
lewing Jul 28, 2023
8ed82ef
More analyzer fixes
lewing Jul 28, 2023
3b1c2c0
Fix roslyn analyzer issues
radical Jul 29, 2023
dbb6a54
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Jul 29, 2023
ffd9319
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Jul 31, 2023
91aea07
Fix more warnings, degrade severity of CA1862
buyaa-n Aug 1, 2023
5dbae01
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Aug 1, 2023
a6c5ed8
Revert unwanted change
buyaa-n Aug 1, 2023
d79086d
Merge branch 'darc-main-85a6f497-d4ac-4076-916f-09908274a169' of gith…
buyaa-n Aug 1, 2023
58614b0
Small update
buyaa-n Aug 1, 2023
e861843
Use OrdinalIgnoreCase
buyaa-n Aug 1, 2023
dc95192
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Aug 2, 2023
ce2d061
Fix more warnings caused by bugfix in CA1864
buyaa-n Aug 3, 2023
16aaa1d
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Aug 3, 2023
e9db46b
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Aug 4, 2023
a2f16c3
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Aug 5, 2023
ca00a3e
Update dependencies from https://github.com/dotnet/roslyn-analyzers b…
dotnet-maestro[bot] Aug 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ dotnet_diagnostic.CA1860.severity = warning
dotnet_diagnostic.CA1861.severity = warning

# CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons
dotnet_diagnostic.CA1862.severity = warning
dotnet_diagnostic.CA1862.severity = info

# CA1863: Use 'CompositeFormat'
dotnet_diagnostic.CA1863.severity = suggestion
Expand Down
8 changes: 4 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>7829f6b85177e96de89bc67f32b61d74ac590f5a</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.23364.2">
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.23380.2">
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
<Sha>45879f0b46557886b8d553d121a81866f67ce08a</Sha>
<Sha>366736f79ace382243ae02e9fd13b5362df40281</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview.23364.2">
<Dependency Name="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview.23380.2">
<Uri>https://github.com/dotnet/roslyn-analyzers</Uri>
<Sha>45879f0b46557886b8d553d121a81866f67ce08a</Sha>
<Sha>366736f79ace382243ae02e9fd13b5362df40281</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.ApiCompat.Task" Version="8.0.100-preview.7.23329.3">
<Uri>https://github.com/dotnet/sdk</Uri>
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</ItemGroup>
<PropertyGroup>
<!-- dotnet/roslyn-analyzers dependencies -->
<MicrosoftCodeAnalysisAnalyzersVersion>3.11.0-beta1.23364.2</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>8.0.0-preview.23364.2</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisAnalyzersVersion>3.11.0-beta1.23380.2</MicrosoftCodeAnalysisAnalyzersVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>8.0.0-preview.23380.2</MicrosoftCodeAnalysisNetAnalyzersVersion>
<!-- dotnet/roslyn dependencies -->
<!--
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.
Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/tools/Common/Compiler/ProcessLinkerXmlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected virtual void ProcessTypes(ModuleDesc assembly, XPathNavigator nav, boo

string fullname = GetFullName(typeNav);

if (fullname.IndexOf("*") != -1)
if (fullname.Contains('*'))
{
if (ProcessTypePattern(fullname, assembly, typeNav))
continue;
Expand Down Expand Up @@ -762,8 +762,7 @@ public class CecilCompatibleTypeParser
public static TypeDesc? GetType(ModuleDesc assembly, string fullName)
{
Debug.Assert(!string.IsNullOrEmpty(fullName));
var position = fullName.IndexOf('/');
if (position > 0)
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
if (fullName.Contains('/'))
return GetNestedType(assembly, fullName);
string @namespace, name;
SplitFullName(fullName, out @namespace, out name);
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/Common/src/System/CodeDom/CodeTypeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ private void Initialize(string? typeName, CodeTypeReferenceOptions options)
}

// Now see if we have some arity. baseType could be null if this is an array type.
#if NET5_0_OR_GREATER
if (_baseType != null && _baseType.Contains('`')) // string.Contains(char) is .NetCore2.1+ specific
#else
if (_baseType != null && _baseType.IndexOf('`') != -1) // string.Contains(char) is .NetCore2.1+ specific
#endif
{
_needsFixup = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static bool IsWhitespace(char ch)
throw ADP.InvalidMultipartNameToManyParts(property, name, limit);
}

if (-1 != leftQuote.IndexOf(separator) || -1 != rightQuote.IndexOf(separator) || leftQuote.Length != rightQuote.Length)
if (leftQuote.Contains(separator) || rightQuote.Contains(separator) || leftQuote.Length != rightQuote.Length)
{
throw ADP.InvalidMultipartNameIncorrectUsageOfQuotes(property, name);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ private static bool IsWhitespace(char ch)
state = MPIState.MPI_ParseQuote;
}
else
if (-1 != rightQuote.IndexOf(testchar))
if (rightQuote.Contains(testchar))
{ // If we shouldn't see a right quote
throw ADP.InvalidMultipartNameIncorrectUsageOfQuotes(property, name);
}
Expand All @@ -133,12 +133,12 @@ private static bool IsWhitespace(char ch)
state = MPIState.MPI_Value;
}
else // Quotes are not valid inside a non-quoted name
if (-1 != rightQuote.IndexOf(testchar))
if (rightQuote.Contains(testchar))
{
throw ADP.InvalidMultipartNameIncorrectUsageOfQuotes(property, name);
}
else
if (-1 != leftQuote.IndexOf(testchar))
if (leftQuote.Contains(testchar))
{
throw ADP.InvalidMultipartNameIncorrectUsageOfQuotes(property, name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ private IChangeToken GetOrAddChangeToken(string pattern)
}

IChangeToken changeToken;
#if NET5_0_OR_GREATER
bool isWildCard = pattern.Contains('*');
#else
bool isWildCard = pattern.IndexOf('*') != -1;
#endif
if (isWildCard || IsDirectoryPath(pattern))
{
changeToken = GetOrAddWildcardChangeToken(pattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ Namespace Microsoft.VisualBasic.FileIO

' If user wants to ignore case, convert new string to lower case. m_SearchText was converted in constructor.
If m_IgnoreCase Then
Return New String(CharBuffer).ToUpper(CultureInfo.CurrentCulture).Contains(m_SearchText)
Return New String(CharBuffer).Contains(m_SearchText, StringComparison.CurrentCultureIgnoreCase)
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
Else
Return New String(CharBuffer).Contains(m_SearchText)
End If
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ Namespace Microsoft.VisualBasic
Return False
End If

If (Path.IndexOf("*"c) <> -1) Then
If (Path.Contains("*"c)) Then
Return True
End If

If (Path.IndexOf("?"c) <> -1) Then
If (Path.Contains("?"c)) Then
Return True
End If

Expand Down Expand Up @@ -1315,7 +1315,7 @@ Namespace Microsoft.VisualBasic
Friend Function VB6CheckPathname(ByVal oAssemblyData As AssemblyData, ByVal sPath As String, ByVal mode As OpenMode) As String
Dim Result As String
' Error if wildcard characters in pathname
If (sPath.IndexOf("?"c) <> -1 OrElse sPath.IndexOf("*"c) <> -1) Then
If (sPath.Contains("?"c) OrElse sPath.Contains("*"c)) Then
Throw New ArgumentException(SR.Format(SR.Argument_InvalidPathChars1, sPath))
End If

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ private string QuoteSnippetString(string value)
// If the string is short, use C style quoting (e.g "\r\n")
// Also do it if it is too long to fit in one line
// If the string contains '\0', verbatim style won't work.
#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'
if (value.Length < 256 || value.Length > 1500 || (value.IndexOf('\0') != -1)) // string.Contains(char) is .NetCore2.1+ specific
return QuoteSnippetStringCStyle(value);
#pragma warning restore CA2249

// Otherwise, use 'verbatim' style quoting (e.g. @"foo")
return QuoteSnippetStringVerbatimStyle(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override bool IsValid(object? value)
{
if (!(char.IsDigit(c)
|| char.IsWhiteSpace(c)
|| AdditionalPhoneNumberCharacters.IndexOf(c) != -1))
|| AdditionalPhoneNumberCharacters.Contains(c)))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>disable</Nullable>
<NoWarn>$(NoWarn);nullable</NoWarn>
<NoWarn>$(NoWarn);CA2249;nullable</NoWarn>
<!-- opt-out of trimming until it works https://github.com/dotnet/runtime/issues/49062 -->
<IsTrimmable>false</IsTrimmable>
<EnableAOTAnalyzer>false</EnableAOTAnalyzer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,11 +733,11 @@ private void BuildInformation(DataTable schemaTable)
string quotePrefix = QuotePrefix;
string quoteSuffix = QuoteSuffix;

if (!string.IsNullOrEmpty(quotePrefix) && (-1 != baseTableName.IndexOf(quotePrefix, StringComparison.Ordinal)))
if (!string.IsNullOrEmpty(quotePrefix) && baseTableName.Contains(quotePrefix, StringComparison.Ordinal))
{
throw ADP.DynamicSQLNestedQuote(baseTableName, quotePrefix);
}
if (!string.IsNullOrEmpty(quoteSuffix) && (-1 != baseTableName.IndexOf(quoteSuffix, StringComparison.Ordinal)))
if (!string.IsNullOrEmpty(quoteSuffix) && baseTableName.Contains(quoteSuffix, StringComparison.Ordinal))
{
throw ADP.DynamicSQLNestedQuote(baseTableName, quoteSuffix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ private static string EscapeSpecialCharacters(string path)
// This is currently enforced by the order of characters in the s_specialCharacterChars array
foreach (char c in s_specialCharacterChars)
{
#if NET5_0_OR_GREATER
if (path.Contains(c))
#else
if (path.IndexOf(c) != -1)
#endif
{
path = path.Replace(c.ToString(), Uri.HexEscape(c));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ bool IEqualityComparer<string>.Equals(string? extensionA, string? extensionB)
//with the rules for comparing/normalizing partnames.
//Refer to PackUriHelper.ValidatedPartUri.GetNormalizedPartUri method.
//Currently normalization just involves upper-casing ASCII and hence the simplification.
return extensionA.ToUpperInvariant() == extensionB.ToUpperInvariant();
return extensionA.Equals(extensionB, StringComparison.InvariantCultureIgnoreCase);
}

int IEqualityComparer<string>.GetHashCode(string extension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static void AddPrefixInternal(string p, HttpListener listener)
if (lp.Path!.Contains('%'))
throw new HttpListenerException((int)HttpStatusCode.BadRequest, SR.net_invalid_path);

if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1)
if (lp.Path.Contains("//"))
throw new HttpListenerException((int)HttpStatusCode.BadRequest, SR.net_invalid_path);

// listens on all the interfaces if host name cannot be parsed by IPAddress.
Expand Down Expand Up @@ -206,7 +206,7 @@ private static void RemovePrefixInternal(string prefix, HttpListener listener)
if (lp.Path!.Contains('%'))
return;

if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1)
if (lp.Path.Contains("//"))
return;

HttpEndPointListener epl = GetEPListener(lp.Host!, lp.Port, listener, lp.Secure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public bool Contains(char value)

public bool Contains(char value, StringComparison comparisonType)
{
#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'... this is the implementation of Contains!
return IndexOf(value, comparisonType) != -1;
#pragma warning restore CA2249
}

// Returns the index of the first occurrence of a specified character in the current instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public static bool NeedsEscapingInTypeName(this char c)

public static string UnescapeTypeNameIdentifier(this string identifier)
{
#if NET5_0_OR_GREATER
if (identifier.Contains('\\'))
#else
if (identifier.IndexOf('\\') != -1)
#endif
{
StringBuilder sbUnescapedName = new StringBuilder(identifier.Length);
for (int i = 0; i < identifier.Length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,12 @@ private void ReadItemFrom(XmlReader reader, SyndicationItem result, Uri feedBase
{
bool isPermalink = true;
string permalinkString = reader.GetAttribute(Rss20Constants.IsPermaLinkTag, Rss20Constants.Rss20Namespace);
if ((permalinkString != null) && (permalinkString.ToUpperInvariant() == "FALSE"))
if (permalinkString != null &&
#if NET5_0_OR_GREATER
permalinkString.Equals("FALSE", StringComparison.InvariantCultureIgnoreCase))
#else
permalinkString.ToUpperInvariant() == "FALSE")
#endif
{
isPermalink = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ internal static void ParseText(IElement parent, string sChars, string pronunciat
}

string sToken = sChars.Substring(i, iTokenEnd - i);
if (sToken.IndexOf('"') != -1)
if (sToken.Contains('"'))
{
// "The token string is not allowed to contain double quote character."
XmlParser.ThrowSrgsException(SRID.InvalidTokenString);
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ protected override int ExecuteTool(string pathToTool, string responseFileCommand

protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
{
if (!ShowCompilerWarnings && singleLine.IndexOf("warning:", StringComparison.OrdinalIgnoreCase) != -1)
if (!ShowCompilerWarnings && singleLine.Contains("warning:", StringComparison.OrdinalIgnoreCase))
{
Log.LogMessage(MessageImportance.Normal, singleLine);
WarningsDetected = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void UpdateAppRef(string sdkPath, string version)
private string GetNuGetConfig()
{
string contents = File.ReadAllText(TemplateNuGetConfigPath);
if (contents.IndexOf(s_nugetInsertionTag, StringComparison.InvariantCultureIgnoreCase) < 0)
if (!contents.Contains(s_nugetInsertionTag, StringComparison.InvariantCultureIgnoreCase))
throw new LogAsErrorException($"Could not find {s_nugetInsertionTag} in {TemplateNuGetConfigPath}");

return contents.Replace(s_nugetInsertionTag, $@"<add key=""nuget-local"" value=""{LocalNuGetsPath}"" />");
Expand Down Expand Up @@ -423,7 +423,7 @@ internal sealed record InstallWorkloadRequest(
public string Version => Workload.GetMetadata("Version");
public string TargetPath => Target.GetMetadata("InstallPath");
public string StampPath => Target.GetMetadata("StampPath");
public bool IgnoreErrors => Workload.GetMetadata("IgnoreErrors").ToLowerInvariant() == "true";
public bool IgnoreErrors => Workload.GetMetadata("IgnoreErrors").Equals("true", StringComparison.InvariantCultureIgnoreCase);
public string WorkloadId => Workload.ItemSpec;

public bool Validate(TaskLoggingHelper log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected virtual void ProcessTypes (AssemblyDefinition assembly, XPathNavigator

string fullname = GetFullName (typeNav);

if (fullname.IndexOf ("*") != -1) {
if (fullname.Contains ('*')) {
if (ProcessTypePattern (fullname, assembly, typeNav))
continue;
}
Expand Down