Skip to content

Commit

Permalink
Simplification of Any (#4863)
Browse files Browse the repository at this point in the history
  • Loading branch information
AZero13 authored Oct 26, 2022
1 parent 489467c commit f7d1aeb
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ private async Task PerformV2RestoreAsync(string packagesConfigFilePath, string i
packageSaveMode = EffectivePackageSaveMode;
}

var missingPackageReferences = installedPackageReferences.Where(reference =>
!nuGetPackageManager.PackageExistsInPackagesFolder(reference.PackageIdentity, packageSaveMode)).Any();
var missingPackageReferences = installedPackageReferences.Any(reference => !nuGetPackageManager.PackageExistsInPackagesFolder(reference.PackageIdentity, packageSaveMode));

if (!missingPackageReferences)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ private async Task<IReadOnlyList<ProjectAction>> ResolveActionsForUpdateAsync(
CancellationToken token)
{
bool includePrerelease = packagesToUpdate
.Where(package => package.Version.IsPrerelease)
.Any();
.Any(package => package.Version.IsPrerelease);

string[] projectIds = uiService.Projects.Select(project => project.ProjectId).ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,9 @@ internal void ClearPackageLevelGrouping()
internal void AddPackageLevelGrouping()
{
ItemsView.Refresh();
if (ItemsView.OfType<PackageItemViewModel>()
.Where(p => p.PackageLevel == PackageLevel.Transitive)
.Any() == true)
if (ItemsView
.OfType<PackageItemViewModel>()
.Any(p => p.PackageLevel == PackageLevel.Transitive))
{
ItemsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(PackageItemViewModel.PackageLevel)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/NuGet.Core/NuGet.Packaging/PackageExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ private static async Task VerifyPackageSignatureAsync(
if (packageExtractionContext.Logger is ICollectorLogger collectorLogger)
{
// collectorLogger.Errors is a collection of errors and warnings, we just need to fail if there are errors.
if (collectorLogger.Errors.Where(e => e.Level >= LogLevel.Error).Any())
if (collectorLogger.Errors.Any(e => e.Level >= LogLevel.Error))
{
// Send empty results since errors and warnings have already been logged
throw new SignatureException(results: Enumerable.Empty<PackageVerificationResult>().ToList(), package: package);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3598,7 +3598,7 @@ public void RestoreNetCore_ProjectToProject_NETCore_TransitiveForAllEdges()
// Find all non _._ compile assets
var flowingCompile = assetsFile.Targets.Single(target => string.IsNullOrEmpty(target.RuntimeIdentifier)).Libraries
.Where(e => e.Type == "project")
.Where(e => e.CompileTimeAssemblies.Where(f => !f.Path.EndsWith("_._")).Any())
.Where(e => e.CompileTimeAssemblies.Any(f => !f.Path.EndsWith("_._")))
.Select(e => e.Name)
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase);

Expand All @@ -3607,7 +3607,7 @@ public void RestoreNetCore_ProjectToProject_NETCore_TransitiveForAllEdges()
// Runtime should always flow
var flowingRuntime = assetsFile.Targets.Single(target => string.IsNullOrEmpty(target.RuntimeIdentifier)).Libraries
.Where(e => e.Type == "project")
.Where(e => e.RuntimeAssemblies.Where(f => !f.Path.EndsWith("_._")).Any())
.Where(e => e.RuntimeAssemblies.Any(f => !f.Path.EndsWith("_._")))
.Select(e => e.Name)
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase);

Expand Down Expand Up @@ -3702,7 +3702,7 @@ public void RestoreNetCore_ProjectToProject_NETCore_TransitiveOffForAllEdges()
// Find all non _._ compile assets
var flowingCompile = assetsFile.Targets.Single(e => string.IsNullOrEmpty(e.RuntimeIdentifier)).Libraries
.Where(e => e.Type == "project")
.Where(e => e.CompileTimeAssemblies.Where(f => !f.Path.EndsWith("_._")).Any())
.Where(e => e.CompileTimeAssemblies.Any(f => !f.Path.EndsWith("_._")))
.Select(e => e.Name)
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase);

Expand All @@ -3711,7 +3711,7 @@ public void RestoreNetCore_ProjectToProject_NETCore_TransitiveOffForAllEdges()
// Runtime should always flow
var flowingRuntime = assetsFile.Targets.Single(e => string.IsNullOrEmpty(e.RuntimeIdentifier)).Libraries
.Where(e => e.Type == "project")
.Where(e => e.RuntimeAssemblies.Where(f => !f.Path.EndsWith("_._")).Any())
.Where(e => e.RuntimeAssemblies.Any(f => !f.Path.EndsWith("_._")))
.Select(e => e.Name)
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public async Task NETCoreProject2Project_VerifyCompileForTransitiveSettings(stri
// Find all non _._ compile assets
var flowingCompile = assetsFile.Targets.Single().Libraries
.Where(e => e.Type == "project")
.Where(e => e.CompileTimeAssemblies.Where(f => !f.Path.EndsWith("_._")).Any())
.Where(e => e.CompileTimeAssemblies.Any(f => !f.Path.EndsWith("_._")))
.Select(e => e.Name)
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase);

Expand All @@ -221,7 +221,7 @@ public async Task NETCoreProject2Project_VerifyCompileForTransitiveSettings(stri
// Runtime should always flow
var flowingRuntime = assetsFile.Targets.Single().Libraries
.Where(e => e.Type == "project")
.Where(e => e.RuntimeAssemblies.Where(f => !f.Path.EndsWith("_._")).Any())
.Where(e => e.RuntimeAssemblies.Any(f => !f.Path.EndsWith("_._")))
.Select(e => e.Name)
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ public async Task RestoreCommand_CentralVersion_AssetsFile_VerifyProjectsReferen
Assert.True(result.Success);
Assert.NotNull(targetLib);
Assert.Equal(1, targetLib.Dependencies.Count);
Assert.True(targetLib.Dependencies.Where(d => d.Id == packageName).Any());
Assert.True(targetLib.Dependencies.Any(d => d.Id == packageName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4457,7 +4457,7 @@ await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, sharpDXDXGIv2
// Check the number of packages and packages returned by PackagesConfigProject after the installation
packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList();
Assert.Equal(2, packagesInPackagesConfig.Count);
Assert.True(packagesInPackagesConfig.Where(p => p.PackageIdentity.Equals(sharpDXDXGIv263Package)).Any());
Assert.True(packagesInPackagesConfig.Any(p => p.PackageIdentity.Equals(sharpDXDXGIv263Package)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5114,9 +5114,9 @@ private static bool FileExistsCaseSensitively(string expectedFilePath)
{
var directoryPath = Path.GetDirectoryName(expectedFilePath);

return Directory.GetFiles(directoryPath, "*", SearchOption.TopDirectoryOnly)
.Where(filePath => string.Equals(filePath, expectedFilePath, StringComparison.Ordinal))
.Any();
return Directory
.GetFiles(directoryPath, "*", SearchOption.TopDirectoryOnly)
.Any(filePath => string.Equals(filePath, expectedFilePath, StringComparison.Ordinal));
}

private sealed class ExtractPackageAsyncTest : IDisposable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Task RemoveReferenceAsync(string name)

public bool FileExistsInProject(string path)
{
return Files.Where(c => path.Equals(c, StringComparison.OrdinalIgnoreCase)).Any();
return Files.Any(c => path.Equals(c, StringComparison.OrdinalIgnoreCase));
}

public void SetPropertyValue(string propertyName, dynamic value)
Expand Down
8 changes: 4 additions & 4 deletions test/TestUtilities/Test.Utility/Signing/SigningTestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public static void AssertOfflineRevocation(IEnumerable<ILogMessage> issues, LogL
bool isOfflineRevocation = issues.Any(issue =>
issue.Code == NuGetLogCode.NU3018 &&
issue.Level == logLevel &&
issue.Message.Split(new[] { ' ', ':' }).Where(WORDEXTFLAGS => WORDEXTFLAGS == offlineRevocation).Any());
issue.Message.Split(new[] { ' ', ':' }).Any(WORDEXTFLAGS => WORDEXTFLAGS == offlineRevocation));

Assert.True(isOfflineRevocation);
}
Expand Down Expand Up @@ -841,7 +841,7 @@ public static void AssertRevocationStatusUnknown(IEnumerable<ILogMessage> issues
bool isRevocationStatusUnknown = issues.Any(issue =>
issue.Code == code &&
issue.Level == logLevel &&
issue.Message.Split(new[] { ' ', ':' }).Where(WORDEXTFLAGS => WORDEXTFLAGS == revocationStatusUnknown).Any());
issue.Message.Split(new[] { ' ', ':' }).Any(WORDEXTFLAGS => WORDEXTFLAGS == revocationStatusUnknown));

Assert.True(isRevocationStatusUnknown);
}
Expand All @@ -854,7 +854,7 @@ public static void AssertUntrustedRoot(IEnumerable<ILogMessage> issues, NuGetLog
issue.Code == code &&
issue.Level == logLevel &&
(issue.Message.Contains("certificate is not trusted by the trust provider") ||
issue.Message.Split(new[] { ' ', ':' }).Where(WORDEXTFLAGS => WORDEXTFLAGS == untrustedRoot).Any()));
issue.Message.Split(new[] { ' ', ':' }).Any(WORDEXTFLAGS => WORDEXTFLAGS == untrustedRoot)));

Assert.True(isUntrustedRoot);
}
Expand All @@ -871,7 +871,7 @@ public static void AssertNotTimeValid(IEnumerable<ILogMessage> issues, LogLevel
bool isNotTimeValid = issues.Any(issue =>
issue.Code == NuGetLogCode.NU3018 &&
issue.Level == logLevel &&
issue.Message.Split(new[] { ' ', ':' }).Where(WORDEXTFLAGS => WORDEXTFLAGS == notTimeValid).Any());
issue.Message.Split(new[] { ' ', ':' }).Any(WORDEXTFLAGS => WORDEXTFLAGS == notTimeValid));

Assert.True(isNotTimeValid);
}
Expand Down

0 comments on commit f7d1aeb

Please sign in to comment.