chore(sonar): apply collection-expression syntax across all sites (IDE0028)
SonarQube Analysis / sonarqube (pull_request) Successful in 2m47s
SonarQube Analysis / sonarqube (pull_request) Successful in 2m47s
Manual sweep of all 42 IDE0028 sites flagged by SonarQube — `dotnet format
analyzers --diagnostics IDE0028` declined to fix these (no .editorconfig
opt-in for `dotnet_style_prefer_collection_expression`), so applied by
hand. The repo already targets `<LangVersion>latest</LangVersion>` on
net8.0, so C# 12 collection expressions are available.
Pattern: `new List<T>()` / `new Dictionary<K,V>()` / `new ArrayList()` /
`new()` -> `[]` for empty; `new List<T> { ... }` -> `[...]` for literal.
24 files touched in src/{EFCore, LinqToSql, Query, Snowflake, SqlBreakdown,
SqlServer}; tests untouched (no IDE0028 sites in test code).
Build clean (35 warnings unchanged from baseline, 0 errors). All tests
remain green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
c38d122d76
commit
0f8d505616
@@ -113,10 +113,10 @@ public class QueryBreakdownEntity
|
||||
/// <summary>
|
||||
/// Navigation property for the related query parameters.
|
||||
/// </summary>
|
||||
public virtual ICollection<QueryParameterEntity> Parameters { get; set; } = new List<QueryParameterEntity>();
|
||||
public virtual ICollection<QueryParameterEntity> Parameters { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Navigation property for the related WITH clauses (CTEs).
|
||||
/// </summary>
|
||||
public virtual ICollection<WithClauseEntity> WithClauses { get; set; } = new List<WithClauseEntity>();
|
||||
public virtual ICollection<WithClauseEntity> WithClauses { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public class QueryBreakdownMapper : IQueryBreakdownMapper
|
||||
|
||||
internal static List<string> DeserializeList(string json)
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<string>>(json) ?? new List<string>();
|
||||
return JsonSerializer.Deserialize<List<string>>(json) ?? [];
|
||||
}
|
||||
|
||||
internal static string SerializeArrayList(ArrayList list)
|
||||
@@ -241,7 +241,7 @@ public class QueryBreakdownMapper : IQueryBreakdownMapper
|
||||
|
||||
internal static ArrayList DeserializeArrayList(string json)
|
||||
{
|
||||
var stringList = JsonSerializer.Deserialize<List<string>>(json) ?? new List<string>();
|
||||
var stringList = JsonSerializer.Deserialize<List<string>>(json) ?? [];
|
||||
var arrayList = new ArrayList();
|
||||
foreach (var item in stringList)
|
||||
{
|
||||
@@ -262,7 +262,7 @@ public class QueryBreakdownMapper : IQueryBreakdownMapper
|
||||
|
||||
internal static Dictionary<string, object> DeserializeDictionary(string json)
|
||||
{
|
||||
var stringDict = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? new Dictionary<string, string>();
|
||||
var stringDict = JsonSerializer.Deserialize<Dictionary<string, string>>(json) ?? [];
|
||||
var result = new Dictionary<string, object>();
|
||||
foreach (var kvp in stringDict)
|
||||
{
|
||||
|
||||
@@ -96,9 +96,9 @@ public class QueryCollectionAnalyzer
|
||||
if (_queries.Count == 0)
|
||||
{
|
||||
return new QueryCollectionStatistics(
|
||||
0, 0, new List<LinqQueryBreakdown>(),
|
||||
new Dictionary<string, int>(),
|
||||
new Dictionary<string, int>(),
|
||||
0, 0, [],
|
||||
[],
|
||||
[],
|
||||
0, 0, 0, 0.0, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class LinqQueryBreakdown : QueryBreakdown
|
||||
/// <summary>
|
||||
/// Gets or sets the list of LINQ method calls in the query chain.
|
||||
/// </summary>
|
||||
public List<string> MethodCallChain { get; set; } = new();
|
||||
public List<string> MethodCallChain { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LinqQueryBreakdown"/> class.
|
||||
@@ -260,7 +260,7 @@ public class LinqQueryBreakdown : QueryBreakdown
|
||||
/// <returns>An InsertBreakdown representing the bulk insert operation.</returns>
|
||||
public static Breakdowns.SqlServer.InsertBreakdown AnalyzeInsertRange<T>(IEnumerable<T> entities) where T : class
|
||||
{
|
||||
var entitiesList = entities?.ToList() ?? new List<T>();
|
||||
var entitiesList = entities?.ToList() ?? [];
|
||||
if (entitiesList.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("Must provide at least one entity to insert.", nameof(entities));
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Strata.SqlTools.Builders.LinqToSql;
|
||||
/// </summary>
|
||||
public class LinqQueryBreakdownBuilder
|
||||
{
|
||||
private readonly List<string> _selectColumns = new();
|
||||
private readonly List<string> _selectColumns = [];
|
||||
private string? _fromTable;
|
||||
private string? _whereClause;
|
||||
private string? _groupByClause;
|
||||
|
||||
@@ -47,7 +47,7 @@ public record QueryValidationIssue(
|
||||
/// </summary>
|
||||
public class QueryValidator
|
||||
{
|
||||
private readonly List<QueryValidationIssue> _issues = new();
|
||||
private readonly List<QueryValidationIssue> _issues = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of validation issues found.
|
||||
|
||||
@@ -11,7 +11,7 @@ public class LinqExpressionVisitor : ExpressionVisitor
|
||||
{
|
||||
private readonly StringBuilder _whereBuilder = new();
|
||||
private readonly StringBuilder _orderByBuilder = new();
|
||||
private readonly List<string> _methodCalls = new();
|
||||
private readonly List<string> _methodCalls = [];
|
||||
private bool _isInWhereClause;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -12,7 +12,7 @@ public class FilterGroup
|
||||
public FilterGroup()
|
||||
{
|
||||
LogicalOperator = LogicalOperator.And;
|
||||
Filters = new List<Filter>();
|
||||
Filters = [];
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
|
||||
@@ -16,9 +16,9 @@ public class QueryConfig
|
||||
|
||||
public QueryConfig()
|
||||
{
|
||||
Rows = new List<Row>();
|
||||
Values = new List<Value>();
|
||||
FilterGroups = new List<FilterGroup>();
|
||||
Rows = [];
|
||||
Values = [];
|
||||
FilterGroups = [];
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
|
||||
@@ -22,6 +22,6 @@ public class Value
|
||||
Calculation = calculation;
|
||||
CalculationDataColumnIds = calculationDataColumnIds ?? Array.Empty<int>();
|
||||
AliasedIds = aliasedIds ?? Array.Empty<string>();
|
||||
FilterGroups = filterGroups?.Where(x => x.IsValid()).ToList() ?? new List<CalculationFilterGroup>();
|
||||
FilterGroups = filterGroups?.Where(x => x.IsValid()).ToList() ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ProcedureBreakdown : SqlServerProcedureBreakdown
|
||||
public ProcedureBreakdown(string procedureName, Dictionary<string, string> parameters, bool isMicrosoftSql = false)
|
||||
: this(procedureName, isMicrosoftSql)
|
||||
{
|
||||
Parameters = parameters ?? new Dictionary<string, string>();
|
||||
Parameters = parameters ?? [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -20,7 +20,7 @@ public class RawSqlBreakdown : ISqlBreakdown
|
||||
/// <summary>
|
||||
/// Gets or sets the setup clauses to execute before the main statement.
|
||||
/// </summary>
|
||||
public List<string> SetupClauses { get; set; } = new List<string>();
|
||||
public List<string> SetupClauses { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether setup clauses are being used.
|
||||
@@ -30,7 +30,7 @@ public class RawSqlBreakdown : ISqlBreakdown
|
||||
/// <summary>
|
||||
/// Gets or sets the finish clauses to execute after the main statement.
|
||||
/// </summary>
|
||||
public ArrayList FinishClauses { get; set; } = new ArrayList();
|
||||
public ArrayList FinishClauses { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether finish clauses are being used.
|
||||
|
||||
@@ -14,8 +14,8 @@ public abstract class SqlBreakdownBase : ISqlBreakdown
|
||||
/// </summary>
|
||||
protected SqlBreakdownBase()
|
||||
{
|
||||
SetupClauses = new List<string>();
|
||||
FinishClauses = new ArrayList();
|
||||
SetupClauses = [];
|
||||
FinishClauses = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -22,7 +22,7 @@ public class SqlBreakdownCollection : ICollection<ISqlBreakdown>
|
||||
/// </summary>
|
||||
public SqlBreakdownCollection()
|
||||
{
|
||||
_breakdowns = new List<ISqlBreakdown>();
|
||||
_breakdowns = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -18,7 +18,7 @@ public class SqlFilter : ISqlAppendable
|
||||
public SqlFilter()
|
||||
{
|
||||
_sqlExpression = new StringBuilder();
|
||||
_parameterValues = new Dictionary<string, object>();
|
||||
_parameterValues = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,7 +29,7 @@ public class SqlFilter : ISqlAppendable
|
||||
public SqlFilter(string expression, params object[] parameterNameValue)
|
||||
{
|
||||
_sqlExpression = new StringBuilder(expression);
|
||||
_parameterValues = new Dictionary<string, object>();
|
||||
_parameterValues = [];
|
||||
|
||||
if (parameterNameValue.Length % 2 != 0)
|
||||
{
|
||||
@@ -49,7 +49,7 @@ public class SqlFilter : ISqlAppendable
|
||||
public SqlFilter(SqlFilter filter)
|
||||
{
|
||||
_sqlExpression = new StringBuilder(filter.SqlExpression);
|
||||
_parameterValues = new Dictionary<string, object>();
|
||||
_parameterValues = [];
|
||||
|
||||
foreach (var key in filter.ParameterValues.Keys)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ public class SqlFrom
|
||||
public SqlFrom(string tableExpression, string tableAlias)
|
||||
{
|
||||
_firstTable = new SqlTable(tableExpression, tableAlias);
|
||||
_joins = new List<SqlJoin>();
|
||||
_joins = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -348,13 +348,13 @@ public class HierarchicalData : IHierarchicalData
|
||||
private Dictionary<Guid, List<IHierarchicalData>> _childDataMap;
|
||||
|
||||
[JsonConstructor]
|
||||
public HierarchicalData() : this(Guid.Empty, default!, new List<IHierarchicalData>())
|
||||
public HierarchicalData() : this(Guid.Empty, default!, [])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public HierarchicalData(Guid dataSourceGuid, IFlatData rootData) : this(dataSourceGuid, rootData,
|
||||
new List<IHierarchicalData>())
|
||||
[])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ public class HierarchicalData : IHierarchicalData
|
||||
return _childDataMap[dataSourceGuid];
|
||||
}
|
||||
|
||||
return new List<IHierarchicalData>();
|
||||
return [];
|
||||
}
|
||||
|
||||
public bool TryAddChildData(Guid datasourceGuid, IEnumerable<IHierarchicalData> data)
|
||||
|
||||
@@ -114,7 +114,7 @@ public static class ArrayUtils
|
||||
{
|
||||
if (string.IsNullOrEmpty(csv))
|
||||
{
|
||||
return new List<Guid>();
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
@@ -392,7 +392,7 @@ public static class ArrayUtils
|
||||
{
|
||||
if (string.IsNullOrEmpty(guidListAsString))
|
||||
{
|
||||
return new List<Guid>();
|
||||
return [];
|
||||
}
|
||||
|
||||
var list = new List<Guid>();
|
||||
|
||||
@@ -61,8 +61,8 @@ public static partial class SqlUtils
|
||||
/// </summary>
|
||||
/// <returns>A list of system schema names.</returns>
|
||||
public static List<string> GetSystemSchemas()
|
||||
=> new List<string>
|
||||
{
|
||||
=>
|
||||
[
|
||||
DEFAULT_SCHEMA,
|
||||
"int", // integration
|
||||
"perf",
|
||||
@@ -73,6 +73,6 @@ public static partial class SqlUtils
|
||||
"upg",
|
||||
"irc", // irc chat rooms
|
||||
"migration"
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -450,13 +450,13 @@ public static partial class SqlUtils
|
||||
/// </summary>
|
||||
/// <returns>An enumerable collection of SQL data types suitable for identity columns.</returns>
|
||||
public static IEnumerable<SqlDataType> IdentityColumnTypes()
|
||||
=> new List<SqlDataType>
|
||||
{
|
||||
=>
|
||||
[
|
||||
SqlDataType.BigInt,
|
||||
SqlDataType.TinyInt,
|
||||
SqlDataType.Int,
|
||||
SqlDataType.SmallInt
|
||||
};
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the SQL sort direction string for a given sort direction enumeration.
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ProcedureBreakdown : SqlBreakdownBase
|
||||
{
|
||||
Parser = new StatementParser();
|
||||
ProcedureName = new SqlClause();
|
||||
Parameters = new Dictionary<string, string>();
|
||||
Parameters = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,7 +41,7 @@ public class ProcedureBreakdown : SqlBreakdownBase
|
||||
/// <param name="parameters">The parameters dictionary (parameter name -> value expression).</param>
|
||||
public ProcedureBreakdown(string procedureName, Dictionary<string, string> parameters) : this(procedureName)
|
||||
{
|
||||
Parameters = parameters ?? new Dictionary<string, string>();
|
||||
Parameters = parameters ?? [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -41,8 +41,8 @@ public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
|
||||
public QueryBreakdown() : base()
|
||||
{
|
||||
Parser = new StatementParser();
|
||||
_parameterList = new List<IQueryParam>();
|
||||
_withClauses = new List<IWithClause>();
|
||||
_parameterList = [];
|
||||
_withClauses = [];
|
||||
|
||||
// Initialize backing fields directly to avoid triggering cache invalidation
|
||||
_selectClause = new SqlExpressionClause(splitOnComma: true);
|
||||
@@ -117,7 +117,7 @@ public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
|
||||
/// Gets the parameter dictionary containing parameter names and their values.
|
||||
/// Parameter values can be set/updated after parsing.
|
||||
/// </summary>
|
||||
public Dictionary<string, object> Parameters { get; } = new Dictionary<string, object>();
|
||||
public Dictionary<string, object> Parameters { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WITH clauses (Common Table Expressions) as an ordered list.
|
||||
|
||||
@@ -26,7 +26,7 @@ public abstract class QueryBreakdownCollectionBase<TQuery> : SqlBreakdownCollect
|
||||
/// </summary>
|
||||
protected QueryBreakdownCollectionBase() : base()
|
||||
{
|
||||
QueryBreakdownList = new List<TQuery>();
|
||||
QueryBreakdownList = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -143,7 +143,7 @@ public class StatementParser
|
||||
#pragma warning disable S127 // "for" loop stop conditions should be invariant
|
||||
public virtual string ExtractSqlComments(string sql, out List<string> comments)
|
||||
{
|
||||
comments = new List<string>();
|
||||
comments = [];
|
||||
var result = new StringBuilder();
|
||||
var inString = false;
|
||||
char stringChar = '\0';
|
||||
|
||||
Reference in New Issue
Block a user