mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Address CA1829 (Avoiding Count LINQ method calls when equivalent + more efficient properties exist) (#1961)
* Address CA1829 (Avoid Count LINQ Method Calls) * Remove other change * CA1829 removal * CA1829 (remove whitespace)
This commit is contained in:
@@ -18,7 +18,6 @@ dotnet_analyzer_diagnostic.severity = error
|
||||
# investigated and either fixed or marked as acceptable with
|
||||
# a reason why
|
||||
dotnet_diagnostic.IDE0018.severity = none
|
||||
dotnet_diagnostic.CA1829.severity = none
|
||||
dotnet_diagnostic.CA1806.severity = none
|
||||
dotnet_diagnostic.IDE0078.severity = none
|
||||
dotnet_diagnostic.IDE0019.severity = none
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Kusto.Language;
|
||||
using Kusto.Language.Editor;
|
||||
using Microsoft.Kusto.ServiceLayer.DataSource.Intellisense;
|
||||
@@ -59,7 +58,7 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource.Kusto
|
||||
|
||||
// build a list of Kusto script file markers from the errors.
|
||||
List<ScriptFileMarker> markers = new List<ScriptFileMarker>();
|
||||
if (parseResult != null && parseResult.Count() > 0)
|
||||
if (parseResult != null && parseResult.Count > 0)
|
||||
{
|
||||
foreach (var error in parseResult)
|
||||
{
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace Microsoft.Kusto.ServiceLayer.ObjectExplorer.Nodes
|
||||
private void DoSort()
|
||||
{
|
||||
List<TreeNode> sorted = this.OrderBy(x => x).ToList();
|
||||
for (int i = 0; i < sorted.Count(); i++)
|
||||
for (int i = 0; i < sorted.Count; i++)
|
||||
{
|
||||
int index = IndexOf(sorted[i]);
|
||||
if (index != i)
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
|
||||
|
||||
ServiceResponse<TResult>[] resultList = new ServiceResponse<TResult>[inputList.Count];
|
||||
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
||||
var tasks = Enumerable.Range(0, inputList.Count())
|
||||
var tasks = Enumerable.Range(0, inputList.Count)
|
||||
.Select(async i =>
|
||||
{
|
||||
ServiceResponse<TResult> result = await GetResult(config, inputList[i], lookupKey, cancellationToken,
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
private void DoSort()
|
||||
{
|
||||
List<TreeNode> sorted = this.OrderBy(x => x).ToList();
|
||||
for (int i = 0; i < sorted.Count(); i++)
|
||||
for (int i = 0; i < sorted.Count; i++)
|
||||
{
|
||||
int index = IndexOf(sorted[i]);
|
||||
if (index != i)
|
||||
|
||||
@@ -399,7 +399,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
// extract full object name from quickInfo text
|
||||
string[] tokens = quickInfoText.Split(' ');
|
||||
List<string> tokenList = tokens.Where(el => el.IndexOf(tokenText, caseSensitivity) >= 0).ToList();
|
||||
return (tokenList?.Count() > 0) ? tokenList[0] : null;
|
||||
return (tokenList?.Count > 0) ? tokenList[0] : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -418,7 +418,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
// extract string denoting the token type from quickInfo text
|
||||
string[] tokens = quickInfoText.Split(' ');
|
||||
List<int> indexList = tokens.Select((s, i) => new { i, s }).Where(el => (el.s).IndexOf(tokenText, caseSensitivity) >= 0).Select(el => el.i).ToList();
|
||||
return (indexList?.Count() > 0) ? String.Join(" ", tokens.Take(indexList[0])) : null;
|
||||
return (indexList?.Count > 0) ? String.Join(" ", tokens.Take(indexList[0])) : null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1033,7 +1033,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
|
||||
indexVM.FilterPredicate.Value = index.FilterPredicate;
|
||||
indexVM.FilterPredicate.Enabled = !index.IsClustered || index.FilterPredicate != null;
|
||||
indexVM.IncludedColumns.Enabled = !index.IsClustered || index.IncludedColumns.Count() > 0;
|
||||
indexVM.IncludedColumns.Enabled = !index.IsClustered || index.IncludedColumns.Count > 0;
|
||||
indexVM.IncludedColumns.CanAddRows = !index.IsClustered;
|
||||
|
||||
foreach (var column in index.IncludedColumns)
|
||||
@@ -1058,7 +1058,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
indexVM.IsClustered.Checked = index.IsClustered;
|
||||
indexVM.FilterPredicate.Value = index.FilterPredicate;
|
||||
indexVM.FilterPredicate.Enabled = !index.IsClustered || index.FilterPredicate != null;
|
||||
indexVM.Columns.Enabled = !index.IsClustered || index.Columns.Count() > 0;
|
||||
indexVM.Columns.Enabled = !index.IsClustered || index.Columns.Count > 0;
|
||||
indexVM.Columns.CanAddRows = !index.IsClustered;
|
||||
indexVM.ColumnsDisplayValue.Enabled = false;
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery
|
||||
//Some tests still verify the number of backup sets that are executed which in some cases can be less than the selected list
|
||||
if (verifyDatabase == null && selectedBackupSets != null)
|
||||
{
|
||||
Assert.AreEqual(selectedBackupSets.Count(), restoreDataObject.RestorePlanToExecute.RestoreOperations.Count());
|
||||
Assert.AreEqual(selectedBackupSets.Length, restoreDataObject.RestorePlanToExecute.RestoreOperations.Count);
|
||||
}
|
||||
}
|
||||
if (executionMode.HasFlag(TaskExecutionModeFlag.Script))
|
||||
|
||||
@@ -240,7 +240,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery
|
||||
string targetDbName = testDb.DatabaseName;
|
||||
bool canRestore = true;
|
||||
var response = await VerifyRestore(backupFiles, null, canRestore, TaskExecutionModeFlag.None, targetDbName, null, null);
|
||||
Assert.True(response.BackupSetsToRestore.Count() >= 2);
|
||||
Assert.True(response.BackupSetsToRestore.Length >= 2);
|
||||
var allIds = response.BackupSetsToRestore.Select(x => x.Id).ToList();
|
||||
if (backupSetIndexToDelete >= 0)
|
||||
{
|
||||
@@ -269,7 +269,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery
|
||||
return true;
|
||||
});
|
||||
|
||||
for (int i = 0; i < response.BackupSetsToRestore.Count(); i++)
|
||||
for (int i = 0; i < response.BackupSetsToRestore.Length; i++)
|
||||
{
|
||||
DatabaseFileInfo databaseInfo = response.BackupSetsToRestore[i];
|
||||
Assert.AreEqual(databaseInfo.IsSelected, expectedSelectedIndexes.Contains(i));
|
||||
@@ -337,7 +337,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery
|
||||
string[] backupFileNames = new string[] { "FullBackup.bak", "DiffBackup.bak" };
|
||||
bool canRestore = true;
|
||||
var response = await VerifyRestore(backupFileNames, null, canRestore, TaskExecutionModeFlag.None, "RestoredFromTwoBackupFile");
|
||||
Assert.True(response.BackupSetsToRestore.Count() == 2);
|
||||
Assert.True(response.BackupSetsToRestore.Length == 2);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
@@ -347,7 +347,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery
|
||||
string[] backupFileNames = new string[] { "FullBackup.bak", "DiffBackup.bak" };
|
||||
bool canRestore = true;
|
||||
var response = await VerifyRestore(backupFileNames, null, canRestore, TaskExecutionModeFlag.None, "RestoredFromTwoBackupFile");
|
||||
Assert.True(response.BackupSetsToRestore.Count() == 2);
|
||||
Assert.True(response.BackupSetsToRestore.Length == 2);
|
||||
var fileInfo = response.BackupSetsToRestore.FirstOrDefault(x => x.GetPropertyValueAsString(BackupSetInfo.BackupTypePropertyName) != RestoreConstants.TypeFull);
|
||||
if (fileInfo != null)
|
||||
{
|
||||
@@ -363,7 +363,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery
|
||||
string[] backupFileNames = new string[] { "FullBackup.bak", "DiffBackup.bak" };
|
||||
bool canRestore = true;
|
||||
var response = await VerifyRestore(backupFileNames, null, canRestore, TaskExecutionModeFlag.None, "RestoredFromTwoBackupFile");
|
||||
Assert.True(response.BackupSetsToRestore.Count() == 2);
|
||||
Assert.True(response.BackupSetsToRestore.Length == 2);
|
||||
var fileInfo = response.BackupSetsToRestore.FirstOrDefault(x => x.GetPropertyValueAsString(BackupSetInfo.BackupTypePropertyName) == RestoreConstants.TypeFull);
|
||||
if (fileInfo != null)
|
||||
{
|
||||
@@ -662,7 +662,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery
|
||||
//Some tests still verify the number of backup sets that are executed which in some cases can be less than the selected list
|
||||
if (verifyDatabase == null && selectedBackupSets != null)
|
||||
{
|
||||
Assert.That(restoreDataObject.RestorePlanToExecute.RestoreOperations.Count(), Is.EqualTo(selectedBackupSets.Count()), $"{nameof(restoreDataObject.RestorePlanToExecute.RestoreOperations)} contains different number of objects than {nameof(selectedBackupSets)}");
|
||||
Assert.That(restoreDataObject.RestorePlanToExecute.RestoreOperations.Count, Is.EqualTo(selectedBackupSets.Length), $"{nameof(restoreDataObject.RestorePlanToExecute.RestoreOperations)} contains different number of objects than {nameof(selectedBackupSets)}");
|
||||
}
|
||||
}
|
||||
if (executionMode.HasFlag(TaskExecutionModeFlag.Script))
|
||||
|
||||
@@ -253,7 +253,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Metadata
|
||||
return result.Metadata == null;
|
||||
}
|
||||
|
||||
if(expectedMetadataList.Count() != result.Metadata.Count())
|
||||
if(expectedMetadataList.Count != result.Metadata.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1801,7 +1801,7 @@ WITH VALUES
|
||||
Assert.NotNull(schemaCompareOpenScmpOperation.Result);
|
||||
Assert.True(schemaCompareOpenScmpOperation.Result.Success);
|
||||
Assert.That(schemaCompareOpenScmpOperation.Result.ExcludedSourceElements, Is.Not.Empty);
|
||||
Assert.AreEqual(1, schemaCompareOpenScmpOperation.Result.ExcludedSourceElements.Count());
|
||||
Assert.AreEqual(1, schemaCompareOpenScmpOperation.Result.ExcludedSourceElements.Count);
|
||||
Assert.That(schemaCompareOpenScmpOperation.Result.ExcludedTargetElements, Is.Empty);
|
||||
|
||||
if (targetEndpointType == SchemaCompareEndpointType.Project)
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
details.HostNameInCertificate = expectedForStrings + index++;
|
||||
details.Port = expectedForInt + index++;
|
||||
|
||||
if (optionMetadata.Options.Count() != details.Options.Count)
|
||||
if (optionMetadata.Options.Length != details.Options.Count)
|
||||
{
|
||||
var optionsNotInMetadata = details.Options.Where(o => !optionMetadata.Options.Any(m => m.Name == o.Key));
|
||||
var optionNames = optionsNotInMetadata.Any() ? optionsNotInMetadata.Select(s => s.Key).Aggregate((i, j) => i + "," + j) : null;
|
||||
|
||||
@@ -42,9 +42,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
|
||||
AutoCompletionResult result = completionService.CreateCompletions(connectionInfo, docInfo, useLowerCaseSuggestions);
|
||||
Assert.NotNull(result);
|
||||
var count = result.CompletionItems == null ? 0 : result.CompletionItems.Count();
|
||||
var count = result.CompletionItems == null ? 0 : result.CompletionItems.Length;
|
||||
|
||||
Assert.That(count, Is.Not.EqualTo(defaultCompletionList.Count()));
|
||||
Assert.That(count, Is.Not.EqualTo(defaultCompletionList.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -65,7 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
|
||||
AutoCompletionResult result = completionService.CreateCompletions(connectionInfo, docInfo, useLowerCaseSuggestions);
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(result.CompletionItems.Count(), defaultCompletionList.Count());
|
||||
Assert.AreEqual(result.CompletionItems.Length, defaultCompletionList.Length);
|
||||
Thread.Sleep(3000);
|
||||
Assert.True(connectionInfo.IntellisenseMetrics.Quantile.Any());
|
||||
}
|
||||
|
||||
@@ -475,7 +475,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
|
||||
private void VerifyServerNodeChildren(NodeInfo[] children)
|
||||
{
|
||||
Assert.NotNull(children);
|
||||
Assert.True(children.Count() == 3);
|
||||
Assert.True(children.Length == 3);
|
||||
Assert.True(children.All((x => x.NodeType == "Folder")));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
|
||||
Assert.False(list.Any(x => x.Name == "db2" && x.ServerInstanceInfo.Name == ""));
|
||||
Assert.True(list.Any(x => x.Name == "" && x.ServerInstanceInfo.Name == "server"));
|
||||
Assert.False(list.Any(x => x.Name == "db4" && x.ServerInstanceInfo.Name == ""));
|
||||
Assert.True(list.Count() == 2);
|
||||
Assert.True(list.Count == 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
|
||||
Assert.True(list.Any(x => x.Name == "db2" && x.ServerInstanceInfo.Name == "server1"));
|
||||
Assert.True(list.Any(x => x.Name == "db4" && x.ServerInstanceInfo.Name == "server2"));
|
||||
Assert.False(list.Any(x => x.Name == "db3" && x.ServerInstanceInfo.Name == "error"));
|
||||
Assert.True(list.Count() == 3);
|
||||
Assert.True(list.Count == 3);
|
||||
Assert.NotNull(response.Errors);
|
||||
Assert.True(response.Errors.Count() == 1);
|
||||
}
|
||||
@@ -147,7 +147,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
|
||||
Assert.True(result.Any(x => x.Name == databaseName && x.ServerInstanceInfo.Name == serverName));
|
||||
}
|
||||
}
|
||||
Assert.True(result.Count() == numberOfDatabases);
|
||||
Assert.True(result.Count == numberOfDatabases);
|
||||
}
|
||||
|
||||
private void AddDatabases(Dictionary<string, List<string>> subscriptionToDatabaseMap, int numberOfDatabases)
|
||||
|
||||
Reference in New Issue
Block a user