Merge pull request 'chore(sonar)!: clear all 17 remaining src/ code smells' (#16) from fix/sonarqube-prod-misc-17 into main
SonarQube Analysis / sonarqube (push) Successful in 3m53s

Reviewed-on: #16
This commit was merged in pull request #16.
This commit is contained in:
2026-05-27 15:12:00 -05:00
25 changed files with 26 additions and 108 deletions
@@ -185,33 +185,13 @@ public class LinqQueryBreakdown : QueryBreakdown
/// Gets a LINQ to SQL query of the specified type based on this breakdown.
/// </summary>
/// <typeparam name="T">The entity type for the query.</typeparam>
/// <returns>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.</returns>
/// <returns>An empty queryable. Breakdown analysis is one-way; reconstruction requires the original provider, which is not preserved.</returns>
/// <remarks>
/// 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
/// <see cref="OriginalExpression"/> when the provider is available; until then callers receive an
/// empty result rather than a null reference.
/// </remarks>
public override IQueryable<T> GetQuery<T>() where T : class
{
if (OriginalExpression == null)
{
return GetEmptyQueryable<T>();
}
try
{
if (OriginalExpression is Expression && EntityType == typeof(T))
{
return GetEmptyQueryable<T>();
}
return GetEmptyQueryable<T>();
}
catch
{
return GetEmptyQueryable<T>();
}
}
public override IQueryable<T> GetQuery<T>() where T : class => GetEmptyQueryable<T>();
/// <summary>
/// Get and empty queryable of T
@@ -6,7 +6,7 @@ namespace Strata.SqlTools.Markdown.LinqToSql;
/// Generates Mermaid diagram markdown from LINQ to SQL QueryBreakdown objects.
/// Creates flowchart visualizations showing the LINQ query structure and flow.
/// </summary>
public class QueryBreakdownGenerator
public static class QueryBreakdownGenerator
{
/// <summary>
/// Generates a Mermaid flowchart diagram from a LINQ to SQL QueryBreakdown.
@@ -8,7 +8,7 @@ namespace Strata.SqlTools.Markdown.LinqToSql;
/// Generates Mermaid diagrams for LINQ to SQL statements, including sequence diagrams
/// for statement execution flow and entity-relationship diagrams.
/// </summary>
public class SqlStatementGenerator
public static class SqlStatementGenerator
{
/// <summary>
/// Generates a Mermaid sequence diagram showing LINQ to SQL statement execution flow.
@@ -6,7 +6,7 @@ namespace Strata.SqlTools.Markdown.PostgreSql;
/// Generates Mermaid diagram markdown from PostgreSQL SQL QueryBreakdown objects.
/// Creates flowchart visualizations showing the query structure and flow.
/// </summary>
public class QueryBreakdownGenerator
public static class QueryBreakdownGenerator
{
/// <summary>
/// Generates a Mermaid flowchart diagram from a PostgreSQL QueryBreakdown.
@@ -6,7 +6,7 @@ namespace Strata.SqlTools.Markdown.PostgreSql;
/// Generates Mermaid diagrams for PostgreSQL SQL statements, including sequence diagrams
/// for statement execution flow and entity-relationship diagrams.
/// </summary>
public class SqlStatementGenerator
public static class SqlStatementGenerator
{
/// <summary>
/// Generates a Mermaid sequence diagram showing PostgreSQL SQL statement execution flow.
@@ -6,7 +6,7 @@ namespace Strata.SqlTools.Markdown.Snowflake;
/// Generates Mermaid diagram markdown from Snowflake SQL QueryBreakdown objects.
/// Creates flowchart visualizations showing the query structure and flow.
/// </summary>
public class QueryBreakdownGenerator
public static class QueryBreakdownGenerator
{
/// <summary>
/// Generates a Mermaid flowchart diagram from a Snowflake QueryBreakdown.
@@ -6,7 +6,7 @@ namespace Strata.SqlTools.Markdown.Snowflake;
/// Generates Mermaid diagrams for Snowflake SQL statements, including sequence diagrams
/// for statement execution flow and entity-relationship diagrams.
/// </summary>
public class SqlStatementGenerator
public static class SqlStatementGenerator
{
/// <summary>
/// Generates a Mermaid sequence diagram showing Snowflake SQL statement execution flow.
@@ -8,7 +8,7 @@ namespace Strata.SqlTools.Markdown.SqlServer;
/// Generates Mermaid diagram markdown from SQL QueryBreakdown objects.
/// Creates flowchart visualizations showing the query structure and flow.
/// </summary>
public class QueryBreakdownGenerator
public static class QueryBreakdownGenerator
{
/// <summary>
/// Generates a Mermaid flowchart diagram from a QueryBreakdown.
@@ -6,7 +6,7 @@ namespace Strata.SqlTools.Markdown.SqlServer;
/// <summary>
/// Generates Mermaid sequence diagrams from SQL statements to visualize statement execution flow.
/// </summary>
public class SqlStatementGenerator
public static class SqlStatementGenerator
{
/// <summary>
/// Generates a Mermaid sequence diagram showing SQL statement execution.
+2 -2
View File
@@ -6,8 +6,8 @@ public class FilterCondition
public IEnumerable<object>? 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()
@@ -7,8 +7,8 @@ namespace Strata.SqlTools.Rules.Rule.Groups;
/// </summary>
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.
/// <summary>
/// Merges two BoolExpr expressions using WITH semantics.
@@ -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;
}
@@ -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(','))
@@ -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<string>();
foreach (string spaceWord in spaceWords)
@@ -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();
@@ -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();
@@ -6,13 +6,11 @@ namespace Strata.SqlTools.Markdown.Tests.LinqToSql;
[TestFixture]
public class QueryBreakdownGeneratorTests
{
private QueryBreakdownGenerator _generator = null!;
private TestDataContext _context = null!;
[SetUp]
public void Setup()
{
_generator = new QueryBreakdownGenerator();
_context = new TestDataContext();
}
@@ -6,14 +6,6 @@ namespace Strata.SqlTools.Markdown.Tests.LinqToSql;
[TestFixture]
public class SqlStatementGeneratorTests
{
private SqlStatementGenerator _generator = null!;
[SetUp]
public void Setup()
{
_generator = new SqlStatementGenerator();
}
[Test]
public void GenerateLinqPipelineDiagram_BasicQuery_GeneratesSequenceDiagram()
{
@@ -6,14 +6,6 @@ namespace Strata.SqlTools.Markdown.Tests.PostgreSql;
[TestFixture]
public class QueryBreakdownGeneratorTests
{
private QueryBreakdownGenerator _generator = null!;
[SetUp]
public void Setup()
{
_generator = new QueryBreakdownGenerator();
}
[Test]
public void GenerateMermaidDiagram_SimplePostgreSqlQuery_GeneratesValidMermaid()
{
@@ -6,14 +6,6 @@ namespace Strata.SqlTools.Markdown.Tests.PostgreSql;
[TestFixture]
public class SqlStatementGeneratorTests
{
private SqlStatementGenerator _generator = null!;
[SetUp]
public void Setup()
{
_generator = new SqlStatementGenerator();
}
[Test]
public void GenerateSequenceDiagram_PostgreSqlQuery_GeneratesValidDiagram()
{
@@ -6,14 +6,6 @@ namespace Strata.SqlTools.Markdown.Tests.Snowflake;
[TestFixture]
public class QueryBreakdownGeneratorTests
{
private QueryBreakdownGenerator _generator = null!;
[SetUp]
public void Setup()
{
_generator = new QueryBreakdownGenerator();
}
[Test]
public void GenerateMermaidDiagram_SimpleSnowflakeQuery_GeneratesValidMermaid()
{
@@ -6,14 +6,6 @@ namespace Strata.SqlTools.Markdown.Tests.Snowflake;
[TestFixture]
public class SqlStatementGeneratorTests
{
private SqlStatementGenerator _generator = null!;
[SetUp]
public void Setup()
{
_generator = new SqlStatementGenerator();
}
[Test]
public void GenerateSequenceDiagram_SnowflakeQuery_GeneratesValidDiagram()
{
@@ -7,14 +7,6 @@ namespace Strata.SqlTools.Markdown.Tests.SqlServer;
[TestFixture]
public class QueryBreakdownGeneratorTests
{
private QueryBreakdownGenerator _generator = null!;
[SetUp]
public void Setup()
{
_generator = new QueryBreakdownGenerator();
}
[Test]
public void GenerateMermaidDiagram_WithSimpleQuery_GeneratesFlowchart()
{
@@ -8,15 +8,12 @@ namespace Strata.SqlTools.Markdown.Tests.SqlServer;
[Category("MarkdownGeneration")]
public class QueryMarkdownGenerationTests
{
private QueryBreakdownGenerator _generator = null!;
private string _queriesSourcePath = null!;
private string _markdownOutputPath = null!;
[SetUp]
public void Setup()
{
_generator = new QueryBreakdownGenerator();
// Get the solution root directory
var testDirectory = TestContext.CurrentContext.TestDirectory;
var solutionRoot = Directory.GetParent(testDirectory)?.Parent?.Parent?.Parent?.Parent?.FullName;
@@ -6,14 +6,6 @@ namespace Strata.SqlTools.Markdown.Tests.SqlServer;
[TestFixture]
public class SqlStatementGeneratorTests
{
private SqlStatementGenerator _generator = null!;
[SetUp]
public void Setup()
{
_generator = new SqlStatementGenerator();
}
[Test]
public void GenerateSequenceDiagram_WithSimpleQuery_GeneratesSequence()
{