Skip to content

Commit

Permalink
Enable IDE0170 (Simplify property pattern) and IDE0200 (remove unnece…
Browse files Browse the repository at this point in the history
…ssary lambda expression) (#71011)

As part of updating the config file with recently added rules, also turn on a few of them.
  • Loading branch information
stephentoub authored Jun 28, 2022
1 parent 14f993e commit 9f7bf79
Show file tree
Hide file tree
Showing 58 changed files with 138 additions and 139 deletions.
24 changes: 21 additions & 3 deletions eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1445,9 +1445,6 @@ dotnet_diagnostic.IDE0048.severity = silent
# IDE0049: Use language keywords instead of framework type names for type references
dotnet_diagnostic.IDE0049.severity = warning

# IDE0050: Convert anonymous type to tuple
dotnet_diagnostic.IDE0050.severity = suggestion

# IDE0051: Remove unused private members
dotnet_diagnostic.IDE0051.severity = suggestion

Expand Down Expand Up @@ -1569,6 +1566,27 @@ dotnet_diagnostic.IDE0160.severity = silent
# IDE0161: Convert to file-scoped namespace
dotnet_diagnostic.IDE0161.severity = silent

# IDE0170: Simplify property pattern
dotnet_diagnostic.IDE0170.severity = warning

# IDE0180: Use tuple swap
dotnet_diagnostic.IDE0180.severity = suggestion

# IDE0200: Remove unnecessary lambda expression
dotnet_diagnostic.IDE0200.severity = warning

# IDE0210: Use top-level statements
dotnet_diagnostic.IDE0210.severity = silent

# IDE0211: Use program main
dotnet_diagnostic.IDE0211.severity = silent

# IDE0220: foreach cast
dotnet_diagnostic.IDE0220.severity = silent

# IDE0230: Use UTF8 string literal
dotnet_diagnostic.IDE0230.severity = suggestion

# IDE1005: Delegate invocation can be simplified.
dotnet_diagnostic.IDE1005.severity = warning

Expand Down
24 changes: 21 additions & 3 deletions eng/CodeAnalysis.test.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1440,9 +1440,6 @@ dotnet_diagnostic.IDE0048.severity = silent
# IDE0049: Use language keywords instead of framework type names for type references
dotnet_diagnostic.IDE0049.severity = silent

# IDE0050: Convert anonymous type to tuple
dotnet_diagnostic.IDE0050.severity = silent

# IDE0051: Remove unused private members
dotnet_diagnostic.IDE0051.severity = silent

Expand Down Expand Up @@ -1563,6 +1560,27 @@ dotnet_diagnostic.IDE0160.severity = silent
# IDE0161: Convert to file-scoped namespace
dotnet_diagnostic.IDE0161.severity = silent

# IDE0170: Simplify property pattern
dotnet_diagnostic.IDE0170.severity = silent

# IDE0180: Use tuple swap
dotnet_diagnostic.IDE0180.severity = silent

# IDE0200: Remove unnecessary lambda expression
dotnet_diagnostic.IDE0200.severity = silent

# IDE0210: Use top-level statements
dotnet_diagnostic.IDE0210.severity = silent

# IDE0211: Use program main
dotnet_diagnostic.IDE0211.severity = silent

# IDE0220: foreach cast
dotnet_diagnostic.IDE0220.severity = silent

# IDE0230: Use UTF8 string literal
dotnet_diagnostic.IDE0230.severity = silent

# IDE1005: Delegate invocation can be simplified.
dotnet_diagnostic.IDE1005.severity = silent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ public static IntPtr OffsetOf(Type t, string fieldName)
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static byte ReadByte(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadByte(nativeHome, offset));
return ReadValueSlow(ptr, ofs, ReadByte);
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("ReadInt16(Object, Int32) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static short ReadInt16(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt16(nativeHome, offset));
return ReadValueSlow(ptr, ofs, ReadInt16);
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("ReadInt32(Object, Int32) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static int ReadInt32(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt32(nativeHome, offset));
return ReadValueSlow(ptr, ofs, ReadInt32);
}

[EditorBrowsable(EditorBrowsableState.Never)]
Expand All @@ -83,7 +83,7 @@ public static int ReadInt32(object ptr, int ofs)
public static long ReadInt64([MarshalAs(UnmanagedType.AsAny), In] object ptr, int ofs)
#pragma warning restore CS0618 // Type or member is obsolete
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt64(nativeHome, offset));
return ReadValueSlow(ptr, ofs, ReadInt64);
}

/// <summary>Read value from marshaled object (marshaled using AsAny).</summary>
Expand Down Expand Up @@ -125,31 +125,31 @@ private static unsafe T ReadValueSlow<T>(object ptr, int ofs, Func<IntPtr, int,
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteByte(object ptr, int ofs, byte val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, byte value) => WriteByte(nativeHome, offset, value));
WriteValueSlow(ptr, ofs, val, WriteByte);
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt16(object ptr, int ofs, short val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, short value) => Marshal.WriteInt16(nativeHome, offset, value));
WriteValueSlow(ptr, ofs, val, Marshal.WriteInt16);
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("WriteInt32(Object, Int32, Int32) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt32(object ptr, int ofs, int val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, int value) => Marshal.WriteInt32(nativeHome, offset, value));
WriteValueSlow(ptr, ofs, val, Marshal.WriteInt32);
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("WriteInt64(Object, Int32, Int64) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt64(object ptr, int ofs, long val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, long value) => Marshal.WriteInt64(nativeHome, offset, value));
WriteValueSlow(ptr, ofs, val, Marshal.WriteInt64);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ internal static byte[] GetAsn1IntegerBytes(SafeSharedAsn1IntegerHandle asn1Integ
// wrong endianness here), DER encode it, then use the DER reader to skip past the tag
// and length.
byte[] derEncoded = OpenSslEncode(
handle => GetAsn1IntegerDerSize(handle),
(handle, buf) => EncodeAsn1Integer(handle, buf),
GetAsn1IntegerDerSize,
EncodeAsn1Integer,
asn1Integer);

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static partial class Crypto

internal static int ResolveRequiredNid(string oid)
{
return s_nidLookup.GetOrAdd(oid, s => LookupNid(s));
return s_nidLookup.GetOrAdd(oid, LookupNid);
}

private static int LookupNid(string oid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,25 @@ private static partial int CryptoNative_X509StoreSetVerifyTime(

internal static byte[] GetAsn1StringBytes(IntPtr asn1)
{
return GetDynamicBuffer((ptr, buf, i) => GetAsn1StringBytes(ptr, buf, i), asn1);
return GetDynamicBuffer(GetAsn1StringBytes, asn1);
}

internal static byte[] GetX509Thumbprint(SafeX509Handle x509)
{
return GetDynamicBuffer((handle, buf, i) => GetX509Thumbprint(handle, buf, i), x509);
return GetDynamicBuffer(GetX509Thumbprint, x509);
}

internal static X500DistinguishedName LoadX500Name(IntPtr namePtr)
{
CheckValidOpenSslHandle(namePtr);

byte[] buf = GetDynamicBuffer((ptr, buf1, i) => GetX509NameRawBytes(ptr, buf1, i), namePtr);
byte[] buf = GetDynamicBuffer(GetX509NameRawBytes, namePtr);
return new X500DistinguishedName(buf);
}

internal static byte[] GetX509PublicKeyParameterBytes(SafeX509Handle x509)
{
return GetDynamicBuffer((handle, buf, i) => GetX509PublicKeyParameterBytes(handle, buf, i), x509);
return GetDynamicBuffer(GetX509PublicKeyParameterBytes, x509);
}

internal static void X509StoreSetVerifyTime(SafeX509StoreHandle ctx, DateTime verifyTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static partial class Crypto
{
internal static ArraySegment<byte> RentAsn1StringBytes(IntPtr asn1)
{
return RentDynamicBuffer((ptr, buf, i) => GetAsn1StringBytes(ptr, buf, i), asn1);
return RentDynamicBuffer(GetAsn1StringBytes, asn1);
}

private static ArraySegment<byte> RentDynamicBuffer<THandle>(NegativeSizeReadMethod<THandle> method, THandle handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal static SafeSharedAsn1IntegerHandle X509GetSerialNumber(SafeX509Handle x
CheckValidOpenSslHandle(x);

return SafeInteriorHandle.OpenInteriorHandle(
handle => X509GetSerialNumber_private(handle),
X509GetSerialNumber_private,
x);
}

Expand All @@ -117,7 +117,7 @@ internal static SafeSharedAsn1OctetStringHandle X509FindExtensionData(SafeX509Ha
CheckValidOpenSslHandle(x);

return SafeInteriorHandle.OpenInteriorHandle(
(handle, arg) => CryptoNative_X509FindExtensionData(handle, arg),
CryptoNative_X509FindExtensionData,
x,
extensionNid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static X500DistinguishedName LoadX500Name(SafeSharedX509NameHandle name
{
CheckValidOpenSslHandle(namePtr);

byte[] buf = GetDynamicBuffer((ptr, buf1, i) => GetX509NameRawBytes(ptr, buf1, i), namePtr);
byte[] buf = GetDynamicBuffer(GetX509NameRawBytes, namePtr);
return new X500DistinguishedName(buf);
}

Expand All @@ -33,7 +33,7 @@ internal static SafeSharedX509NameHandle GetX509NameStackField(SafeSharedX509Nam
CheckValidOpenSslHandle(sk);

return SafeInteriorHandle.OpenInteriorHandle(
(handle, i) => GetX509NameStackField_private(handle, i),
GetX509NameStackField_private,
sk,
loc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal static void X509StoreCtxResetForSignatureError(
internal static SafeSharedX509StackHandle X509StoreCtxGetSharedUntrusted(SafeX509StoreCtxHandle ctx)
{
return SafeInteriorHandle.OpenInteriorHandle(
x => X509StoreCtxGetSharedUntrusted_private(x),
X509StoreCtxGetSharedUntrusted_private,
ctx);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override byte[] DeriveKeyFromHash(
hashAlgorithm,
secretPrepend,
secretAppend,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

public override byte[] DeriveKeyFromHmac(
Expand All @@ -54,7 +54,7 @@ public override byte[] DeriveKeyFromHmac(
hmacKey,
secretPrepend,
secretAppend,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed)
Expand All @@ -69,7 +69,7 @@ public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey
otherPartyPublicKey,
prfLabel,
prfSeed,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override byte[] DeriveKeyFromHash(
hashAlgorithm,
secretPrepend,
secretAppend,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

public override byte[] DeriveKeyFromHmac(
Expand All @@ -51,7 +51,7 @@ public override byte[] DeriveKeyFromHmac(
hmacKey,
secretPrepend,
secretAppend,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed)
Expand All @@ -66,7 +66,7 @@ public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey
otherPartyPublicKey,
prfLabel,
prfSeed,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public override byte[] DeriveKeyFromHash(
hashAlgorithm,
secretPrepend,
secretAppend,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

public override byte[] DeriveKeyFromHmac(
Expand All @@ -157,7 +157,7 @@ public override byte[] DeriveKeyFromHmac(
hmacKey,
secretPrepend,
secretAppend,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed)
Expand All @@ -172,7 +172,7 @@ public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey
otherPartyPublicKey,
prfLabel,
prfSeed,
(pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher));
DeriveSecretAgreement);
}

private byte[]? DeriveSecretAgreement(ECDiffieHellmanPublicKey otherPartyPublicKey, IncrementalHash? hasher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void AddSource(IConfigurationSource source)
IConfigurationProvider provider = source.Build(this);

provider.Load();
_changeTokenRegistrations.Add(ChangeToken.OnChange(() => provider.GetReloadToken(), () => RaiseChanged()));
_changeTokenRegistrations.Add(ChangeToken.OnChange(provider.GetReloadToken, RaiseChanged));

_providerManager.AddProvider(provider);
RaiseChanged();
Expand All @@ -143,7 +143,7 @@ private void ReloadSources()
foreach (IConfigurationProvider p in newProvidersList)
{
p.Load();
_changeTokenRegistrations.Add(ChangeToken.OnChange(() => p.GetReloadToken(), () => RaiseChanged()));
_changeTokenRegistrations.Add(ChangeToken.OnChange(p.GetReloadToken, RaiseChanged));
}

_providerManager.ReplaceProviders(newProvidersList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ConfigurationRoot(IList<IConfigurationProvider> providers)
foreach (IConfigurationProvider p in providers)
{
p.Load();
_changeTokenRegistrations.Add(ChangeToken.OnChange(() => p.GetReloadToken(), () => RaiseChanged()));
_changeTokenRegistrations.Add(ChangeToken.OnChange(p.GetReloadToken, RaiseChanged));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private static bool AreCompatible(DynamicallyAccessedMemberTypes serviceDynamica
{
if (!_stackGuard.TryEnterOnCurrentStack())
{
return _stackGuard.RunOnEmptyStack((type, chain) => CreateCallSite(type, chain), serviceType, callSiteChain);
return _stackGuard.RunOnEmptyStack(CreateCallSite, serviceType, callSiteChain);
}

// We need to lock the resolution process for a single service type at a time:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected virtual TResult VisitCallSite(ServiceCallSite callSite, TArgument argu
{
if (!_stackGuard.TryEnterOnCurrentStack())
{
return _stackGuard.RunOnEmptyStack((c, a) => VisitCallSite(c, a), callSite, argument);
return _stackGuard.RunOnEmptyStack(VisitCallSite, callSite, argument);
}

switch (callSite.Cache.Location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public PhysicalFileProvider(string root, ExclusionFilters filters)
}

_filters = filters;
_fileWatcherFactory = () => CreateFileWatcher();
_fileWatcherFactory = CreateFileWatcher;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public Task WaitForStartAsync(CancellationToken cancellationToken)
{
Logger.LogInformation("Application is shutting down...");
});
ApplicationLifetime.ApplicationStopped.Register(() =>
{
_delayStop.Set();
});
ApplicationLifetime.ApplicationStopped.Register(_delayStop.Set);

Thread thread = new Thread(Run);
thread.IsBackground = true;
Expand Down
Loading

0 comments on commit 9f7bf79

Please sign in to comment.