Skip to content

Commit

Permalink
Switch to new Microsoft.CodeAnalysis.NetAnalyzers package (dotnet#38346)
Browse files Browse the repository at this point in the history
And update to the latest beta bits available.
  • Loading branch information
stephentoub authored Jun 25, 2020
1 parent 4d561f4 commit 8b36909
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 47 deletions.
2 changes: 1 addition & 1 deletion eng/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup Condition="'$(EnableAnalyzers)' == 'true'">
<PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="3.3.0-beta1.20324.2" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" PrivateAssets="all" />
</ItemGroup>
</Project>
35 changes: 27 additions & 8 deletions eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<RuleSet Name="Microsoft.Analyzers.ManagedCodeAnalysis" Description="Microsoft.Analyzers.ManagedCodeAnalysis" ToolsVersion="14.0">
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rules AnalyzerId="Microsoft.CodeAnalysis.NetAnalyzers" RuleNamespace="Microsoft.CodeAnalysis.NetAnalyzers">
<Rule Id="CA1000" Action="None" /> <!-- Do not declare static members on generic types -->
<Rule Id="CA1001" Action="None" /> <!-- Types that own disposable fields should be disposable -->
<Rule Id="CA1002" Action="None" /> <!-- Do not expose generic lists -->
<Rule Id="CA1003" Action="None" /> <!-- Use generic event handler instances -->
<Rule Id="CA1005" Action="None" /> <!-- Avoid excessive parameters on generic types -->
<Rule Id="CA1008" Action="None" /> <!-- Enums should have zero value -->
<Rule Id="CA1010" Action="None" /> <!-- Generic interface should also be implemented -->
<Rule Id="CA1012" Action="None" /> <!-- Abstract types should not have constructors -->
Expand All @@ -25,6 +27,9 @@
<Rule Id="CA1041" Action="None" /> <!-- Provide ObsoleteAttribute message -->
<Rule Id="CA1043" Action="None" /> <!-- Use Integral Or String Argument For Indexers -->
<Rule Id="CA1044" Action="None" /> <!-- Properties should not be write only -->
<Rule Id="CA1045" Action="None" /> <!-- Do not pass types by reference -->
<Rule Id="CA1046" Action="None" /> <!-- Do not overload equality operator on reference types -->
<Rule Id="CA1047" Action="Warning" /> <!-- Do not declare protected member in sealed type -->
<Rule Id="CA1050" Action="Warning" /> <!-- Declare types in namespaces -->
<Rule Id="CA1051" Action="None" /> <!-- Do not declare visible instance fields -->
<Rule Id="CA1052" Action="None" /> <!-- Static holder types should be Static or NotInheritable -->
Expand All @@ -38,10 +43,11 @@
<Rule Id="CA1063" Action="None" /> <!-- Implement IDisposable Correctly -->
<Rule Id="CA1064" Action="None" /> <!-- Exceptions should be public -->
<Rule Id="CA1065" Action="None" /> <!-- Do not raise exceptions in unexpected locations -->
<Rule Id="CA1066" Action="None" /> <!-- Type {0} should implement IEquatable<T> because it overrides Equals -->
<Rule Id="CA1066" Action="None" /> <!-- Implement IEquatable when overriding Object.Equals -->
<Rule Id="CA1067" Action="None" /> <!-- Override Object.Equals(object) when implementing IEquatable<T> -->
<Rule Id="CA1068" Action="None" /> <!-- CancellationToken parameters must come last -->
<Rule Id="CA1069" Action="None" /> <!-- Enums values should not be duplicated -->
<Rule Id="CA1070" Action="Info" /> <!-- Do not declare event fields as virtual -->
<Rule Id="CA1200" Action="Warning" /> <!-- Avoid using cref tags with a prefix -->
<Rule Id="CA1303" Action="None" /> <!-- Do not pass literals as localized parameters -->
<Rule Id="CA1304" Action="None" /> <!-- Specify CultureInfo -->
Expand All @@ -57,21 +63,22 @@
<Rule Id="CA1507" Action="Warning" /> <!-- Use nameof to express symbol names -->
<Rule Id="CA1508" Action="None" /> <!-- Avoid dead conditional code -->
<Rule Id="CA1509" Action="None" /> <!-- Invalid entry in code metrics rule specification file -->
<Rule Id="CA1700" Action="None" /> <!-- Do not name enum values 'Reserved' -->
<Rule Id="CA1707" Action="None" /> <!-- Identifiers should not contain underscores -->
<Rule Id="CA1708" Action="None" /> <!-- Identifiers should differ by more than case -->
<Rule Id="CA1710" Action="None" /> <!-- Identifiers should have correct suffix -->
<Rule Id="CA1711" Action="None" /> <!-- Identifiers should not have incorrect suffix -->
<Rule Id="CA1712" Action="None" /> <!-- Do not prefix enum values with type name -->
<Rule Id="CA1714" Action="None" /> <!-- Flags enums should have plural names -->
<Rule Id="CA1713" Action="None" /> <!-- Events should not have 'Before' or 'After' prefix -->
<Rule Id="CA1715" Action="None" /> <!-- Identifiers should have correct prefix -->
<Rule Id="CA1716" Action="None" /> <!-- Identifiers should not match keywords -->
<Rule Id="CA1717" Action="None" /> <!-- Only FlagsAttribute enums should have plural names -->
<Rule Id="CA1720" Action="None" /> <!-- Identifier contains type name -->
<Rule Id="CA1721" Action="None" /> <!-- Property names should not match get methods -->
<Rule Id="CA1724" Action="None" /> <!-- Type names should not match namespaces -->
<Rule Id="CA1725" Action="Info" /> <!-- Parameter names should match base declaration -->
<Rule Id="CA1801" Action="None" /> <!-- Review unused parameters -->
<Rule Id="CA1802" Action="Warning" /> <!-- Use literals where appropriate -->
<Rule Id="CA1805" Action="Info" /> <!-- Do not initialize unnecessarily -->
<Rule Id="CA1806" Action="None" /> <!-- Do not ignore method results -->
<Rule Id="CA1810" Action="Warning" /> <!-- Initialize reference type static fields inline -->
<Rule Id="CA1812" Action="None" /> <!-- Avoid uninstantiated internal classes -->
Expand All @@ -90,17 +97,27 @@
<Rule Id="CA1827" Action="Warning" /> <!-- Do not use Count() or LongCount() when Any() can be used -->
<Rule Id="CA1828" Action="Warning" /> <!-- Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used -->
<Rule Id="CA1829" Action="Warning" /> <!-- Use Length/Count property instead of Count() when available -->
<Rule Id="CA1830" Action="Warning" /> <!-- Prefer strongly-typed Append and Insert method overloads on StringBuilder. -->
<Rule Id="CA1831" Action="Warning" /> <!-- Use AsSpan or AsMemory instead of Range-based indexers when appropriate -->
<Rule Id="CA1832" Action="Warning" /> <!-- Use AsSpan or AsMemory instead of Range-based indexers when appropriate -->
<Rule Id="CA1833" Action="Warning" /> <!-- Use AsSpan or AsMemory instead of Range-based indexers when appropriate -->
<Rule Id="CA1834" Action="Warning" /> <!-- Consider using 'StringBuilder.Append(char)' when applicable. -->
<Rule Id="CA1835" Action="Warning" /> <!-- Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' -->
<Rule Id="CA1836" Action="Info" /> <!-- Prefer IsEmpty over Count -->
<Rule Id="CA2000" Action="None" /> <!-- Dispose objects before losing scope -->
<Rule Id="CA2002" Action="None" /> <!-- Do not lock on objects with weak identity -->
<Rule Id="CA2007" Action="Warning" /> <!-- Consider calling ConfigureAwait on the awaited task -->
<Rule Id="CA2008" Action="Warning" /> <!-- Do not create tasks without passing a TaskScheduler -->
<Rule Id="CA2009" Action="Warning" /> <!-- Do not call ToImmutableCollection on an ImmutableCollection value -->
<Rule Id="CA2010" Action="None" /> <!-- Always consume the value returned by methods marked with PreserveSigAttribute -->
<Rule Id="CA2011" Action="Warning" /> <!-- Avoid infinite recursion -->
<Rule Id="CA2012" Action="Warning" /> <!-- Use ValueTasks correctly -->
<Rule Id="CA2013" Action="Warning" /> <!-- Do not use ReferenceEquals with value types -->
<Rule Id="CA2014" Action="Warning" /> <!-- Do not use stackalloc in loops. -->
<Rule Id="CA2015" Action="Warning" /> <!-- Do not define finalizers for types derived from MemoryManager<T> -->
<Rule Id="CA2016" Action="Info" /> <!-- Forward the 'CancellationToken' parameter to methods that take one -->
<Rule Id="CA2100" Action="None" /> <!-- Review SQL queries for security vulnerabilities -->
<Rule Id="CA2101" Action="None" /> <!-- Specify marshaling for P/Invoke string arguments -->
<Rule Id="CA2109" Action="None" /> <!-- Review visible event handlers -->
<Rule Id="CA2119" Action="None" /> <!-- Seal methods that satisfy private interfaces -->
<Rule Id="CA2153" Action="None" /> <!-- Do Not Catch Corrupted State Exceptions -->
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
Expand Down Expand Up @@ -131,6 +148,9 @@
<Rule Id="CA2244" Action="None" /> <!-- Do not duplicate indexed element initializations -->
<Rule Id="CA2245" Action="Warning" /> <!-- Do not assign a property to itself. -->
<Rule Id="CA2246" Action="None" /> <!-- Assigning symbol and its member in the same statement. -->
<Rule Id="CA2247" Action="Warning" /> <!-- Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum. -->
<Rule Id="CA2248" Action="Warning" /> <!-- Provide correct 'enum' argument to 'Enum.HasFlag' -->
<Rule Id="CA2249" Action="Warning" /> <!-- Consider using 'string.Contains' instead of 'string.IndexOf' -->
<Rule Id="CA2300" Action="None" /> <!-- Do not use insecure deserializer BinaryFormatter -->
<Rule Id="CA2301" Action="None" /> <!-- Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder -->
<Rule Id="CA2302" Action="None" /> <!-- Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize -->
Expand Down Expand Up @@ -165,11 +185,11 @@
<Rule Id="CA3147" Action="Warning" /> <!-- Mark Verb Handlers With Validate Antiforgery Token -->
<Rule Id="CA5350" Action="Warning" /> <!-- Do Not Use Weak Cryptographic Algorithms -->
<Rule Id="CA5351" Action="Warning" /> <!-- Do Not Use Broken Cryptographic Algorithms -->
<Rule Id="CA5358" Action="None" /> <!-- Do Not Use Unsafe Cipher Modes -->
<Rule Id="CA5358" Action="None" /> <!-- Review cipher mode usage with cryptography experts -->
<Rule Id="CA5359" Action="Warning" /> <!-- Do Not Disable Certificate Validation -->
<Rule Id="CA5360" Action="Warning" /> <!-- Do Not Call Dangerous Methods In Deserialization -->
<Rule Id="CA5361" Action="Warning" /> <!-- Do Not Disable SChannel Use of Strong Crypto -->
<Rule Id="CA5362" Action="None" /> <!-- Do Not Refer Self In Serializable Class -->
<Rule Id="CA5362" Action="None" /> <!-- Potential reference cycle in deserialized object graph -->
<Rule Id="CA5363" Action="Warning" /> <!-- Do Not Disable Request Validation -->
<Rule Id="CA5364" Action="Warning" /> <!-- Do Not Use Deprecated Security Protocols -->
<Rule Id="CA5365" Action="Warning" /> <!-- Do Not Disable HTTP Header Checking -->
Expand Down Expand Up @@ -211,7 +231,6 @@
<Rule Id="CA5401" Action="None" /> <!-- Do not use CreateEncryptor with non-default IV -->
<Rule Id="CA5402" Action="None" /> <!-- Use CreateEncryptor with the default IV -->
<Rule Id="CA5403" Action="None" /> <!-- Do not hard-code certificate -->
<Rule Id="CA9999" Action="Warning" /> <!-- Analyzer version mismatch -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="AD0001" Action="None" /> <!-- Analyzer threw an exception -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ internal static int GetKeyValuePair(string connectionString, int currentPosition
return currentPosition;
}

#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'. This file is built into libraries that don't have string.Contains(char).
private static bool IsValueValidInternal(string keyvalue)
{
if (null != keyvalue)
Expand Down Expand Up @@ -423,6 +424,7 @@ private static bool IsKeyNameValid(string keyname)
}
return false;
}
#pragma warning restore CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'

#if DEBUG
private static Dictionary<string, string> SplitConnectionString(string connectionString, Dictionary<string, string> synonyms, bool firstKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ internal static void ValidateSubprotocol(string subProtocol)
}

if (!char.IsLetterOrDigit(ch) &&
#pragma warning disable CA2249 // Consider using 'string.Contains' instead of 'string.IndexOf'. This file is built into a project that doesn't have string.Contains(char).
Separators.IndexOf(ch) >= 0)
#pragma warning restore CA2249
{
invalidChar = ch.ToString();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<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>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>
<NoWarn>$(NoWarn);CA2249</NoWarn>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
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
Expand Up @@ -4,6 +4,7 @@
<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)-illumos;$(NetCoreAppCurrent)-Solaris;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetFrameworkCurrent)-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>
<NoWarn>$(NoWarn);CA2249</NoWarn>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;netstandard2.0;netcoreapp2.0-Windows_NT;_$(NetFrameworkCurrent)</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<NoWarn>$(NoWarn);CA2249</NoWarn>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ protected override Task SerializeToStreamAsync(Stream stream, TransportContext?
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken)
{
byte[] data = await GetResponseData().ConfigureAwait(continueOnCapturedContext: true);
await stream.WriteAsync(data, 0, data.Length, cancellationToken).ConfigureAwait(continueOnCapturedContext: true);
await stream.WriteAsync(data, cancellationToken).ConfigureAwait(continueOnCapturedContext: true);
}
protected internal override bool TryComputeLength(out long length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ internal Task InternalWriteAsync(byte[] buffer, int offset, int count) =>

private async Task InternalWriteIgnoreErrorsAsync(byte[] buffer, int offset, int count)
{
try { await _stream.WriteAsync(buffer, offset, count).ConfigureAwait(false); }
try { await _stream.WriteAsync(buffer.AsMemory(offset, count)).ConfigureAwait(false); }
catch { }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ public static Icmpv6StatisticsTable ParseIcmpv6FromSnmp6File(string filePath)
{
string fileContents = File.ReadAllText(filePath);
RowConfigReader reader = new RowConfigReader(fileContents);
int Icmp6OutErrorsIdx = fileContents.IndexOf("Icmp6OutErrors", StringComparison.Ordinal);
bool hasIcmp6OutErrors = fileContents.Contains("Icmp6OutErrors");

return new Icmpv6StatisticsTable()
{
InMsgs = reader.GetNextValueAsInt64("Icmp6InMsgs"),
InErrors = reader.GetNextValueAsInt64("Icmp6InErrors"),
OutMsgs = reader.GetNextValueAsInt64("Icmp6OutMsgs"),
OutErrors = Icmp6OutErrorsIdx == -1 ? 0 : reader.GetNextValueAsInt64("Icmp6OutErrors"),
OutErrors = hasIcmp6OutErrors ? reader.GetNextValueAsInt64("Icmp6OutErrors") : 0,
InDestUnreachs = reader.GetNextValueAsInt64("Icmp6InDestUnreachs"),
InPktTooBigs = reader.GetNextValueAsInt64("Icmp6InPktTooBigs"),
InTimeExcds = reader.GetNextValueAsInt64("Icmp6InTimeExcds"),
Expand Down Expand Up @@ -388,17 +388,17 @@ internal static UdpGlobalStatisticsTable ParseUdpv6GlobalStatisticsFromSnmp6File
{
string fileContents = File.ReadAllText(filePath);
RowConfigReader reader = new RowConfigReader(fileContents);
int udp6ErrorsIdx = fileContents.IndexOf("Udp6SndbufErrors", StringComparison.Ordinal);
bool hasUdp6Errors = fileContents.Contains("Udp6SndbufErrors");

return new UdpGlobalStatisticsTable()
{
InDatagrams = reader.GetNextValueAsInt64("Udp6InDatagrams"),
NoPorts = reader.GetNextValueAsInt64("Udp6NoPorts"),
InErrors = reader.GetNextValueAsInt64("Udp6InErrors"),
OutDatagrams = reader.GetNextValueAsInt64("Udp6OutDatagrams"),
RcvbufErrors = udp6ErrorsIdx == -1 ? 0 : reader.GetNextValueAsInt64("Udp6RcvbufErrors"),
SndbufErrors = udp6ErrorsIdx == -1 ? 0 : reader.GetNextValueAsInt64("Udp6SndbufErrors"),
InCsumErrors = udp6ErrorsIdx == -1 ? 0 : reader.GetNextValueAsInt64("Udp6InCsumErrors"),
RcvbufErrors = hasUdp6Errors ? reader.GetNextValueAsInt64("Udp6RcvbufErrors") : 0,
SndbufErrors = hasUdp6Errors ? reader.GetNextValueAsInt64("Udp6SndbufErrors") : 0,
InCsumErrors = hasUdp6Errors ? reader.GetNextValueAsInt64("Udp6InCsumErrors") : 0,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public override string ToString()
{
sb.Append("<null>");
}
sb.Append(Environment.NewLineConst);
sb.AppendLine();

return sb.ToString();
}
Expand Down
Loading

0 comments on commit 8b36909

Please sign in to comment.