Skip to content

Commit

Permalink
Fix SonarQube's "'Any()' should be used to test for emptiness" / Code…
Browse files Browse the repository at this point in the history
… Smell (#3404)
  • Loading branch information
marodev authored and ivanduplenskikh committed Nov 8, 2023
1 parent 3aa7285 commit 2e9439b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Agent.Plugins/Artifact/PipelineArtifactServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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 @@ -338,15 +338,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 @@ -69,7 +69,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 @@ -95,7 +95,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

0 comments on commit 2e9439b

Please sign in to comment.