From 1bd6deec83a417829fa923f06b3225ab59ce9799 Mon Sep 17 00:00:00 2001 From: Thom Lamb Date: Wed, 27 May 2026 15:05:19 -0500 Subject: [PATCH] =?UTF-8?q?chore(sonar):=20mechanical=20src/=20cleanups=20?= =?UTF-8?q?=E2=80=94=20AsSpan,=20drop=20ContainsKey=20guard,=20simplify=20?= =?UTF-8?q?GetQuery=20(CA1846,=20CA1853,=20S2219)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `SqlParseException.cs:90` (CA1846): `sql.Substring(0, 197)` → `sql.AsSpan(0, 197)` in the truncated-SQL diagnostic message. Avoids an allocation in an already cold exception path. - `Snowflake/QueryBreakdown.cs:103` (CA1853): drop the redundant `Parameters.ContainsKey(...)` guard around `Parameters.Remove(...)`. `Dictionary.Remove` is a no-op if the key is absent, so the guard only doubled the work and computed the key string twice. - `LinqQueryBreakdown.cs:194` (S2219): collapse the now-stub `GetQuery()` (every branch returned `GetEmptyQueryable()` after the S1168 cleanup) to a single expression-bodied member. Updates the XML doc to describe the actual current behavior. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Breakdowns/LinqQueryBreakdown.cs | 30 ++++--------------- .../Breakdowns/QueryBreakdown.cs | 5 +--- .../Exceptions/SqlParseException.cs | 2 +- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/Strata.SqlTools.LinqToSql/Breakdowns/LinqQueryBreakdown.cs b/src/Strata.SqlTools.LinqToSql/Breakdowns/LinqQueryBreakdown.cs index 1f2d208..c96f31b 100644 --- a/src/Strata.SqlTools.LinqToSql/Breakdowns/LinqQueryBreakdown.cs +++ b/src/Strata.SqlTools.LinqToSql/Breakdowns/LinqQueryBreakdown.cs @@ -185,33 +185,13 @@ public class LinqQueryBreakdown : QueryBreakdown /// Gets a LINQ to SQL query of the specified type based on this breakdown. /// /// The entity type for the query. - /// An IQueryable of the specified type reconstructed from the breakdown; an empty queryable if the type doesn't match the original entity type or the original data source isn't available. + /// An empty queryable. Breakdown analysis is one-way; reconstruction requires the original provider, which is not preserved. /// - /// This method attempts to reconstruct a LINQ query from the analyzed components (WHERE, ORDER BY, etc.). - /// If a data source (IQueryable) is available in the breakdown's OriginalExpression, it will be used. - /// Otherwise, returns an empty queryable — breakdown analysis is one-way; reconstruction requires the original provider. + /// Always returns an empty queryable today. A future version may reconstruct the LINQ query from + /// when the provider is available; until then callers receive an + /// empty result rather than a null reference. /// - public override IQueryable GetQuery() where T : class - { - if (OriginalExpression == null) - { - return GetEmptyQueryable(); - } - - try - { - if (OriginalExpression is Expression && EntityType == typeof(T)) - { - return GetEmptyQueryable(); - } - - return GetEmptyQueryable(); - } - catch - { - return GetEmptyQueryable(); - } - } + public override IQueryable GetQuery() where T : class => GetEmptyQueryable(); /// /// Get and empty queryable of T diff --git a/src/Strata.SqlTools.Snowflake/Breakdowns/QueryBreakdown.cs b/src/Strata.SqlTools.Snowflake/Breakdowns/QueryBreakdown.cs index 773f3f7..fd5ba06 100644 --- a/src/Strata.SqlTools.Snowflake/Breakdowns/QueryBreakdown.cs +++ b/src/Strata.SqlTools.Snowflake/Breakdowns/QueryBreakdown.cs @@ -100,10 +100,7 @@ public class QueryBreakdown : SqlServerQueryBreakdown base.AddParameter(colonName.TrimStart(':', '@'), value); // Add both formats to dictionary for compatibility - if (Parameters.ContainsKey($"@{colonName.TrimStart(':', '@')}")) - { - Parameters.Remove($"@{colonName.TrimStart(':', '@')}"); - } + Parameters.Remove($"@{colonName.TrimStart(':', '@')}"); Parameters[colonName] = value; Parameters[atName] = value; } diff --git a/src/Strata.SqlTools.SqlServer/Exceptions/SqlParseException.cs b/src/Strata.SqlTools.SqlServer/Exceptions/SqlParseException.cs index ce55470..debd2e2 100644 --- a/src/Strata.SqlTools.SqlServer/Exceptions/SqlParseException.cs +++ b/src/Strata.SqlTools.SqlServer/Exceptions/SqlParseException.cs @@ -87,7 +87,7 @@ public class SqlParseException : Exception } else { - sb.AppendLine($"SQL (truncated): {sql.Substring(0, 197)}..."); + sb.AppendLine($"SQL (truncated): {sql.AsSpan(0, 197)}..."); } return sb.ToString();