Merge pull request 'chore(sonar): apply collection-expression syntax across all sites (IDE0028)' (#13) from chore/sonarqube-info-prod-bulk into main
SonarQube Analysis / sonarqube (push) Successful in 2m55s

Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
2026-05-26 17:05:56 -05:00
24 changed files with 46 additions and 46 deletions
@@ -113,10 +113,10 @@ public class QueryBreakdownEntity
/// <summary> /// <summary>
/// Navigation property for the related query parameters. /// Navigation property for the related query parameters.
/// </summary> /// </summary>
public virtual ICollection<QueryParameterEntity> Parameters { get; set; } = new List<QueryParameterEntity>(); public virtual ICollection<QueryParameterEntity> Parameters { get; set; } = [];
/// <summary> /// <summary>
/// Navigation property for the related WITH clauses (CTEs). /// Navigation property for the related WITH clauses (CTEs).
/// </summary> /// </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) 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) internal static string SerializeArrayList(ArrayList list)
@@ -241,7 +241,7 @@ public class QueryBreakdownMapper : IQueryBreakdownMapper
internal static ArrayList DeserializeArrayList(string json) 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(); var arrayList = new ArrayList();
foreach (var item in stringList) foreach (var item in stringList)
{ {
@@ -262,7 +262,7 @@ public class QueryBreakdownMapper : IQueryBreakdownMapper
internal static Dictionary<string, object> DeserializeDictionary(string json) 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>(); var result = new Dictionary<string, object>();
foreach (var kvp in stringDict) foreach (var kvp in stringDict)
{ {
@@ -96,9 +96,9 @@ public class QueryCollectionAnalyzer
if (_queries.Count == 0) if (_queries.Count == 0)
{ {
return new QueryCollectionStatistics( return new QueryCollectionStatistics(
0, 0, new List<LinqQueryBreakdown>(), 0, 0, [],
new Dictionary<string, int>(), [],
new Dictionary<string, int>(), [],
0, 0, 0, 0.0, 0); 0, 0, 0, 0.0, 0);
} }
@@ -34,7 +34,7 @@ public class LinqQueryBreakdown : QueryBreakdown
/// <summary> /// <summary>
/// Gets or sets the list of LINQ method calls in the query chain. /// Gets or sets the list of LINQ method calls in the query chain.
/// </summary> /// </summary>
public List<string> MethodCallChain { get; set; } = new(); public List<string> MethodCallChain { get; set; } = [];
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="LinqQueryBreakdown"/> class. /// 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> /// <returns>An InsertBreakdown representing the bulk insert operation.</returns>
public static Breakdowns.SqlServer.InsertBreakdown AnalyzeInsertRange<T>(IEnumerable<T> entities) where T : class 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) if (entitiesList.Count == 0)
{ {
throw new ArgumentException("Must provide at least one entity to insert.", nameof(entities)); throw new ArgumentException("Must provide at least one entity to insert.", nameof(entities));
@@ -8,7 +8,7 @@ namespace Strata.SqlTools.Builders.LinqToSql;
/// </summary> /// </summary>
public class LinqQueryBreakdownBuilder public class LinqQueryBreakdownBuilder
{ {
private readonly List<string> _selectColumns = new(); private readonly List<string> _selectColumns = [];
private string? _fromTable; private string? _fromTable;
private string? _whereClause; private string? _whereClause;
private string? _groupByClause; private string? _groupByClause;
@@ -47,7 +47,7 @@ public record QueryValidationIssue(
/// </summary> /// </summary>
public class QueryValidator public class QueryValidator
{ {
private readonly List<QueryValidationIssue> _issues = new(); private readonly List<QueryValidationIssue> _issues = [];
/// <summary> /// <summary>
/// Gets the list of validation issues found. /// Gets the list of validation issues found.
@@ -11,7 +11,7 @@ public class LinqExpressionVisitor : ExpressionVisitor
{ {
private readonly StringBuilder _whereBuilder = new(); private readonly StringBuilder _whereBuilder = new();
private readonly StringBuilder _orderByBuilder = new(); private readonly StringBuilder _orderByBuilder = new();
private readonly List<string> _methodCalls = new(); private readonly List<string> _methodCalls = [];
private bool _isInWhereClause; private bool _isInWhereClause;
/// <summary> /// <summary>
+1 -1
View File
@@ -12,7 +12,7 @@ public class FilterGroup
public FilterGroup() public FilterGroup()
{ {
LogicalOperator = LogicalOperator.And; LogicalOperator = LogicalOperator.And;
Filters = new List<Filter>(); Filters = [];
} }
[JsonConstructor] [JsonConstructor]
+3 -3
View File
@@ -16,9 +16,9 @@ public class QueryConfig
public QueryConfig() public QueryConfig()
{ {
Rows = new List<Row>(); Rows = [];
Values = new List<Value>(); Values = [];
FilterGroups = new List<FilterGroup>(); FilterGroups = [];
} }
[JsonConstructor] [JsonConstructor]
+1 -1
View File
@@ -22,6 +22,6 @@ public class Value
Calculation = calculation; Calculation = calculation;
CalculationDataColumnIds = calculationDataColumnIds ?? Array.Empty<int>(); CalculationDataColumnIds = calculationDataColumnIds ?? Array.Empty<int>();
AliasedIds = aliasedIds ?? Array.Empty<string>(); 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) public ProcedureBreakdown(string procedureName, Dictionary<string, string> parameters, bool isMicrosoftSql = false)
: this(procedureName, isMicrosoftSql) : this(procedureName, isMicrosoftSql)
{ {
Parameters = parameters ?? new Dictionary<string, string>(); Parameters = parameters ?? [];
} }
/// <summary> /// <summary>
@@ -20,7 +20,7 @@ public class RawSqlBreakdown : ISqlBreakdown
/// <summary> /// <summary>
/// Gets or sets the setup clauses to execute before the main statement. /// Gets or sets the setup clauses to execute before the main statement.
/// </summary> /// </summary>
public List<string> SetupClauses { get; set; } = new List<string>(); public List<string> SetupClauses { get; set; } = [];
/// <summary> /// <summary>
/// Gets a value indicating whether setup clauses are being used. /// Gets a value indicating whether setup clauses are being used.
@@ -30,7 +30,7 @@ public class RawSqlBreakdown : ISqlBreakdown
/// <summary> /// <summary>
/// Gets or sets the finish clauses to execute after the main statement. /// Gets or sets the finish clauses to execute after the main statement.
/// </summary> /// </summary>
public ArrayList FinishClauses { get; set; } = new ArrayList(); public ArrayList FinishClauses { get; set; } = [];
/// <summary> /// <summary>
/// Gets a value indicating whether finish clauses are being used. /// Gets a value indicating whether finish clauses are being used.
@@ -14,8 +14,8 @@ public abstract class SqlBreakdownBase : ISqlBreakdown
/// </summary> /// </summary>
protected SqlBreakdownBase() protected SqlBreakdownBase()
{ {
SetupClauses = new List<string>(); SetupClauses = [];
FinishClauses = new ArrayList(); FinishClauses = [];
} }
/// <summary> /// <summary>
@@ -22,7 +22,7 @@ public class SqlBreakdownCollection : ICollection<ISqlBreakdown>
/// </summary> /// </summary>
public SqlBreakdownCollection() public SqlBreakdownCollection()
{ {
_breakdowns = new List<ISqlBreakdown>(); _breakdowns = [];
} }
/// <summary> /// <summary>
@@ -18,7 +18,7 @@ public class SqlFilter : ISqlAppendable
public SqlFilter() public SqlFilter()
{ {
_sqlExpression = new StringBuilder(); _sqlExpression = new StringBuilder();
_parameterValues = new Dictionary<string, object>(); _parameterValues = [];
} }
/// <summary> /// <summary>
@@ -29,7 +29,7 @@ public class SqlFilter : ISqlAppendable
public SqlFilter(string expression, params object[] parameterNameValue) public SqlFilter(string expression, params object[] parameterNameValue)
{ {
_sqlExpression = new StringBuilder(expression); _sqlExpression = new StringBuilder(expression);
_parameterValues = new Dictionary<string, object>(); _parameterValues = [];
if (parameterNameValue.Length % 2 != 0) if (parameterNameValue.Length % 2 != 0)
{ {
@@ -49,7 +49,7 @@ public class SqlFilter : ISqlAppendable
public SqlFilter(SqlFilter filter) public SqlFilter(SqlFilter filter)
{ {
_sqlExpression = new StringBuilder(filter.SqlExpression); _sqlExpression = new StringBuilder(filter.SqlExpression);
_parameterValues = new Dictionary<string, object>(); _parameterValues = [];
foreach (var key in filter.ParameterValues.Keys) foreach (var key in filter.ParameterValues.Keys)
{ {
@@ -18,7 +18,7 @@ public class SqlFrom
public SqlFrom(string tableExpression, string tableAlias) public SqlFrom(string tableExpression, string tableAlias)
{ {
_firstTable = new SqlTable(tableExpression, tableAlias); _firstTable = new SqlTable(tableExpression, tableAlias);
_joins = new List<SqlJoin>(); _joins = [];
} }
/// <summary> /// <summary>
@@ -348,13 +348,13 @@ public class HierarchicalData : IHierarchicalData
private Dictionary<Guid, List<IHierarchicalData>> _childDataMap; private Dictionary<Guid, List<IHierarchicalData>> _childDataMap;
[JsonConstructor] [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, public HierarchicalData(Guid dataSourceGuid, IFlatData rootData) : this(dataSourceGuid, rootData,
new List<IHierarchicalData>()) [])
{ {
} }
@@ -388,7 +388,7 @@ public class HierarchicalData : IHierarchicalData
return _childDataMap[dataSourceGuid]; return _childDataMap[dataSourceGuid];
} }
return new List<IHierarchicalData>(); return [];
} }
public bool TryAddChildData(Guid datasourceGuid, IEnumerable<IHierarchicalData> data) public bool TryAddChildData(Guid datasourceGuid, IEnumerable<IHierarchicalData> data)
@@ -114,7 +114,7 @@ public static class ArrayUtils
{ {
if (string.IsNullOrEmpty(csv)) if (string.IsNullOrEmpty(csv))
{ {
return new List<Guid>(); return [];
} }
try try
@@ -392,7 +392,7 @@ public static class ArrayUtils
{ {
if (string.IsNullOrEmpty(guidListAsString)) if (string.IsNullOrEmpty(guidListAsString))
{ {
return new List<Guid>(); return [];
} }
var list = new List<Guid>(); var list = new List<Guid>();
@@ -61,8 +61,8 @@ public static partial class SqlUtils
/// </summary> /// </summary>
/// <returns>A list of system schema names.</returns> /// <returns>A list of system schema names.</returns>
public static List<string> GetSystemSchemas() public static List<string> GetSystemSchemas()
=> new List<string> =>
{ [
DEFAULT_SCHEMA, DEFAULT_SCHEMA,
"int", // integration "int", // integration
"perf", "perf",
@@ -73,6 +73,6 @@ public static partial class SqlUtils
"upg", "upg",
"irc", // irc chat rooms "irc", // irc chat rooms
"migration" "migration"
}; ];
} }
@@ -450,13 +450,13 @@ public static partial class SqlUtils
/// </summary> /// </summary>
/// <returns>An enumerable collection of SQL data types suitable for identity columns.</returns> /// <returns>An enumerable collection of SQL data types suitable for identity columns.</returns>
public static IEnumerable<SqlDataType> IdentityColumnTypes() public static IEnumerable<SqlDataType> IdentityColumnTypes()
=> new List<SqlDataType> =>
{ [
SqlDataType.BigInt, SqlDataType.BigInt,
SqlDataType.TinyInt, SqlDataType.TinyInt,
SqlDataType.Int, SqlDataType.Int,
SqlDataType.SmallInt SqlDataType.SmallInt
}; ];
/// <summary> /// <summary>
/// Gets the SQL sort direction string for a given sort direction enumeration. /// Gets the SQL sort direction string for a given sort direction enumeration.
@@ -20,7 +20,7 @@ public class ProcedureBreakdown : SqlBreakdownBase
{ {
Parser = new StatementParser(); Parser = new StatementParser();
ProcedureName = new SqlClause(); ProcedureName = new SqlClause();
Parameters = new Dictionary<string, string>(); Parameters = [];
} }
/// <summary> /// <summary>
@@ -41,7 +41,7 @@ public class ProcedureBreakdown : SqlBreakdownBase
/// <param name="parameters">The parameters dictionary (parameter name -> value expression).</param> /// <param name="parameters">The parameters dictionary (parameter name -> value expression).</param>
public ProcedureBreakdown(string procedureName, Dictionary<string, string> parameters) : this(procedureName) public ProcedureBreakdown(string procedureName, Dictionary<string, string> parameters) : this(procedureName)
{ {
Parameters = parameters ?? new Dictionary<string, string>(); Parameters = parameters ?? [];
} }
/// <summary> /// <summary>
@@ -41,8 +41,8 @@ public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
public QueryBreakdown() : base() public QueryBreakdown() : base()
{ {
Parser = new StatementParser(); Parser = new StatementParser();
_parameterList = new List<IQueryParam>(); _parameterList = [];
_withClauses = new List<IWithClause>(); _withClauses = [];
// Initialize backing fields directly to avoid triggering cache invalidation // Initialize backing fields directly to avoid triggering cache invalidation
_selectClause = new SqlExpressionClause(splitOnComma: true); _selectClause = new SqlExpressionClause(splitOnComma: true);
@@ -117,7 +117,7 @@ public class QueryBreakdown : SqlBreakdownBase, IQueryBreakdown
/// Gets the parameter dictionary containing parameter names and their values. /// Gets the parameter dictionary containing parameter names and their values.
/// Parameter values can be set/updated after parsing. /// Parameter values can be set/updated after parsing.
/// </summary> /// </summary>
public Dictionary<string, object> Parameters { get; } = new Dictionary<string, object>(); public Dictionary<string, object> Parameters { get; } = [];
/// <summary> /// <summary>
/// Gets the WITH clauses (Common Table Expressions) as an ordered list. /// Gets the WITH clauses (Common Table Expressions) as an ordered list.
@@ -26,7 +26,7 @@ public abstract class QueryBreakdownCollectionBase<TQuery> : SqlBreakdownCollect
/// </summary> /// </summary>
protected QueryBreakdownCollectionBase() : base() protected QueryBreakdownCollectionBase() : base()
{ {
QueryBreakdownList = new List<TQuery>(); QueryBreakdownList = [];
} }
/// <summary> /// <summary>
@@ -143,7 +143,7 @@ public class StatementParser
#pragma warning disable S127 // "for" loop stop conditions should be invariant #pragma warning disable S127 // "for" loop stop conditions should be invariant
public virtual string ExtractSqlComments(string sql, out List<string> comments) public virtual string ExtractSqlComments(string sql, out List<string> comments)
{ {
comments = new List<string>(); comments = [];
var result = new StringBuilder(); var result = new StringBuilder();
var inString = false; var inString = false;
char stringChar = '\0'; char stringChar = '\0';