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

Fix SonarQube's "'Any()' should be used to test for emptiness" / Code… #3404

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 src/Agent.Plugins/Artifact/FileContainerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private async Task DownloadFileContainerAsync(ArtifactDownloadParameters downloa
tracer.Info($"Start downloading FCS artifact- {artifact.Name}");
IEnumerable<Func<string, bool>> minimatcherFuncs = MinimatchHelper.GetMinimatchFuncs(minimatchPatterns, tracer);

if (minimatcherFuncs != null && minimatcherFuncs.Count() != 0)
if (minimatcherFuncs != null && minimatcherFuncs.Any())
{
items = this.GetFilteredItems(items, minimatcherFuncs);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Agent.Plugins/Artifact/PipelineArtifactServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal async Task DownloadAsync(
}

IEnumerable<BuildArtifact> pipelineArtifacts = artifacts.Where(a => string.Equals(a.Resource.Type, PipelineArtifactConstants.PipelineArtifact, StringComparison.OrdinalIgnoreCase));
if (pipelineArtifacts.Count() == 0)
if (!pipelineArtifacts.Any())
{
throw new ArgumentException("Could not find any pipeline artifacts in the build.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Agent.Sdk/ProcessInvoker.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void WindowsKillProcessTree()
Trace.Verbose($"Start killing process tree of process '{pid.Value}'.");
Stack<ProcessTerminationInfo> processesNeedtoKill = new Stack<ProcessTerminationInfo>();
processesNeedtoKill.Push(new ProcessTerminationInfo(pid.Value, false));
while (processesNeedtoKill.Count() > 0)
while (processesNeedtoKill.Any())
{
ProcessTerminationInfo procInfo = processesNeedtoKill.Pop();
List<int> childProcessesIds = new List<int>();
Expand Down
4 changes: 2 additions & 2 deletions src/Agent.Worker/Build/TrackingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ public void DisposeCollectedGarbage(IExecutionContext executionContext)
}

IEnumerable<string> gcTrackingFiles = Directory.EnumerateFiles(gcDirectory, "*.json");
if (gcTrackingFiles == null || gcTrackingFiles.Count() == 0)
if (gcTrackingFiles == null || !gcTrackingFiles.Any())
{
executionContext.Output(StringUtil.Loc("GCDirIsEmpty", gcDirectory));
return;
}

Trace.Info($"Find {gcTrackingFiles.Count()} GC tracking files.");

if (gcTrackingFiles.Count() > 0)
if (gcTrackingFiles.Any())
{
foreach (string gcFile in gcTrackingFiles)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Agent.Worker/CodeCoverage/CodeCoverageCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Execute(IExecutionContext context, Command command)
context.Output(StringUtil.Loc("ReadingCodeCoverageSummary", _summaryFileLocation));
var coverageData = reader.GetCodeCoverageSummary(context, _summaryFileLocation);

if (coverageData == null || coverageData.Count() == 0)
if (coverageData == null || !coverageData.Any())
{
context.Warning(StringUtil.Loc("CodeCoverageDataIsNull"));
}
Expand All @@ -93,7 +93,7 @@ private async Task PublishCodeCoverageAsync(
CancellationToken cancellationToken)
{
//step 2: publish code coverage summary to TFS
if (coverageData != null && coverageData.Count() > 0)
if (coverageData != null && coverageData.Any())
{
commandContext.Output(StringUtil.Loc("PublishingCodeCoverage"));
foreach (var coverage in coverageData)
Expand Down
4 changes: 2 additions & 2 deletions src/Agent.Worker/Release/ReleaseTrackingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ public void DisposeCollectedGarbage(IExecutionContext executionContext)
}

IEnumerable<string> gcTrackingFiles = Directory.EnumerateFiles(gcDirectory, "*.json");
if (gcTrackingFiles == null || gcTrackingFiles.Count() == 0)
if (gcTrackingFiles == null || !gcTrackingFiles.Any())
{
executionContext.Output(StringUtil.Loc("GCReleaseDirIsEmpty", gcDirectory));
return;
}

Trace.Info($"Find {gcTrackingFiles.Count()} GC tracking files.");

if (gcTrackingFiles.Count() > 0)
if (gcTrackingFiles.Any())
{
foreach (string gcFile in gcTrackingFiles)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Agent.Worker/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ from task in tasks
into taskGrouping
select taskGrouping.First();

if (uniqueTasks.Count() == 0)
if (!uniqueTasks.Any())
{
executionContext.Debug("There is no required tasks need to download.");
return;
Expand Down
6 changes: 3 additions & 3 deletions src/Test/L0/Listener/CommandSettingsL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ public void ValidateCommands()
var command = new CommandSettings(hc, args: new string[] { "badcommand" });

// Assert.
Assert.True(command.ParseErrors.Count() > 0);
Assert.True(command.ParseErrors.Any());
}
}

Expand All @@ -1168,7 +1168,7 @@ public void ValidateFlags()
var command = new CommandSettings(hc, args: new string[] { "--badflag" });

// Assert.
Assert.True(command.ParseErrors.Count() > 0);
Assert.True(command.ParseErrors.Any());
}
}

Expand All @@ -1183,7 +1183,7 @@ public void ValidateArgs()
var command = new CommandSettings(hc, args: new string[] { "--badargname", "bad arg value" });

// Assert.
Assert.True(command.ParseErrors.Count() > 0);
Assert.True(command.ParseErrors.Any());
}
}

Expand Down