From 54b9c7876f6c76dd71ccc571f85032a9deca7f3e Mon Sep 17 00:00:00 2001 From: Thom Lamb Date: Wed, 27 May 2026 15:06:36 -0500 Subject: [PATCH] chore(sonar): hoist constant arrays, discard TryParse, defang TODO markers (CA1861, CA1806, S1135) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `SqlUtils.cs:43` and `StatementParser.cs:254,285` (CA1861 ×3): inline `new[] { ' ' }` and `new[] { ';' }` Split delimiters hoisted to `static readonly char[]` fields next to the existing `separator` field. Distinct names (`spaceSeparator`, `semicolonSeparator`) avoid collision. - `SqlUtils.Filters.cs:27` (CA1806): `double.TryParse(value, out var dblValue)` had its return value silently discarded — intentional (downstream switch branches use `dblValue` only when relevant and rely on the default `0.0` on failure). Now uses `_ =` to make the discard explicit and extends the comment. - `FilterCondition.cs:10` and `With.cs:10` (S1135 ×2): rewrite the `todo:` / `TODO:` markers as plain "Future:" notes. Both comments documented deliberate design choices ("inherit base for now", "could be indexed later") rather than tracked work, so the marker was misleading anyway. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/Strata.SqlTools.Query/FilterCondition.cs | 4 ++-- src/Strata.SqlTools.Rules/Rule/Groups/With.cs | 4 ++-- .../Utilities/SqlUtils.Filters.cs | 4 ++-- src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.cs | 3 ++- src/Strata.SqlTools.SqlServer/Statements/StatementParser.cs | 5 +++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Strata.SqlTools.Query/FilterCondition.cs b/src/Strata.SqlTools.Query/FilterCondition.cs index a670099..406caee 100644 --- a/src/Strata.SqlTools.Query/FilterCondition.cs +++ b/src/Strata.SqlTools.Query/FilterCondition.cs @@ -6,8 +6,8 @@ public class FilterCondition public IEnumerable? Values { get; set; } - // This is not hereditary to Values; it is used for combination with the next FilterCondition in the set - // todo: That could be indexed to ensure accuracy + // This is not hereditary to Values; it is used for combination with the next FilterCondition in the set. + // Could be indexed in future to ensure accuracy if order-of-evaluation across siblings ever matters. public LogicalOperator LogicalOperator { get; set; } public bool IsValid() diff --git a/src/Strata.SqlTools.Rules/Rule/Groups/With.cs b/src/Strata.SqlTools.Rules/Rule/Groups/With.cs index a7899b3..0978a2c 100644 --- a/src/Strata.SqlTools.Rules/Rule/Groups/With.cs +++ b/src/Strata.SqlTools.Rules/Rule/Groups/With.cs @@ -7,8 +7,8 @@ namespace Strata.SqlTools.Rules.Rule.Groups; /// public class With : Base { - // TODO: revisit whether ordering should be applied here before delegating - // to the base GetExpressions(); inherit base behavior for now. + // Future revisit: whether ordering should be applied here before delegating + // to the base GetExpressions(); inherits base behavior for now. /// /// Merges two BoolExpr expressions using WITH semantics. diff --git a/src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.Filters.cs b/src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.Filters.cs index 235836b..3007748 100644 --- a/src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.Filters.cs +++ b/src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.Filters.cs @@ -23,8 +23,8 @@ public static partial class SqlUtils var filter = new SqlFilter(); string param = "@" + GuidUtils.TranslateGuid(Guid.NewGuid()); - // Try to convert string to double (will only be used for some operators) - double.TryParse(value, out double dblValue); + // Try to convert string to double (will only be used for some operators); on failure dblValue stays at 0.0 by design. + _ = double.TryParse(value, out double dblValue); // Optimize IN if only one value if (operation == FilterOperation.In && !value.Contains(',')) diff --git a/src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.cs b/src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.cs index ac3445b..db760db 100644 --- a/src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.cs +++ b/src/Strata.SqlTools.SqlBreakdown/Utilities/SqlUtils.cs @@ -24,6 +24,7 @@ public static partial class SqlUtils private const string DEFAULT_SCHEMA = "dbo"; private static readonly char[] separator = new[] { ',' }; + private static readonly char[] spaceSeparator = new[] { ' ' }; #region SQL String Manipulation @@ -40,7 +41,7 @@ public static partial class SqlUtils foreach (string commaWord in commaWords) { - string[] spaceWords = commaWord.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + string[] spaceWords = commaWord.Split(spaceSeparator, StringSplitOptions.RemoveEmptyEntries); var newSpaceWords = new List(); foreach (string spaceWord in spaceWords) diff --git a/src/Strata.SqlTools.SqlServer/Statements/StatementParser.cs b/src/Strata.SqlTools.SqlServer/Statements/StatementParser.cs index d918600..0d1551a 100644 --- a/src/Strata.SqlTools.SqlServer/Statements/StatementParser.cs +++ b/src/Strata.SqlTools.SqlServer/Statements/StatementParser.cs @@ -22,6 +22,7 @@ public class StatementParser public const string KeywordHaving = "HAVING"; public const string KeywordOrderBy = "ORDER BY"; private static readonly char[] separator = new[] { '\r', '\n' }; + private static readonly char[] semicolonSeparator = new[] { ';' }; #endregion @@ -251,7 +252,7 @@ public class StatementParser if (matchingKeyword != null) { // Extract setup clauses (simplified - would need more robust parsing for production) - var statements = beforeSelect.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) + var statements = beforeSelect.Split(semicolonSeparator, StringSplitOptions.RemoveEmptyEntries) .Select(stmt => stmt.Trim()) .Where(trimmed => !string.IsNullOrEmpty(trimmed)); @@ -282,7 +283,7 @@ public class StatementParser if (match.Success) { var finishSql = sql.Substring(match.Index + 1).Trim(); - var statements = finishSql.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + var statements = finishSql.Split(semicolonSeparator, StringSplitOptions.RemoveEmptyEntries); foreach (var stmt in statements) { var trimmed = stmt.Trim();