refactor(dedup): second pass at src/ duplication — clear 10 of 13 remaining blocks #21

Merged
bermudalamb merged 4 commits from chore/sonarqube-src-dedup-pass2 into main 2026-05-27 17:14:01 -05:00
4 Commits
Author SHA1 Message Date
Thom LambandClaude Opus 4.7 a84fe9768f refactor(dedup): remove redundant local TruncateText forwarders
SonarQube Analysis / sonarqube (pull_request) Successful in 3m58s
`QueryBreakdownGenerator`, `SqlStatementGenerator`, and
`ExpressionGenerator` each had a 1-line `private static string
TruncateText(...)` forwarder to `Internal.MarkdownTextHelpers.TruncateText`.
The forwarders existed only to keep existing call sites short
(`TruncateText(x, 50)` instead of the fully-qualified form).

Each file now imports `using static MarkdownTextHelpers;` once at the
top, so call sites continue to read identically and the local
forwarders are deleted. Removes the structural duplication Sonar was
flagging (two private static helpers — `EscapeMermaidText` + the
TruncateText forwarder — appearing in both `QueryBreakdownGenerator`
and `SqlStatementGenerator` with the same shape).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 17:11:39 -05:00
Thom LambandClaude Opus 4.7 4b6b3edc87 refactor(dedup): TryMatchTwoCharOperator helper in PG StatementReader
The PostgreSql-specific operator dispatch in
`StatementReader.TryHandleAdditionalCharacter` had four similar 4-7
line blocks (each handling a single-char operator with one or more
two-char variants — \<, \>, \|, \=). Sonar flagged it as a
self-duplication.

Extract a small `TryMatchTwoCharOperator(char, string)` helper that
encapsulates the "if next char matches, advance and emit two-char
operator" pattern. Each operator handler now reads as a small list:

    if (CurrentCharacter == '<')
    {
        MovePosition();
        if (TryMatchTwoCharOperator('=', "<=")) return true;
        if (TryMatchTwoCharOperator('>', "<>")) return true;
        if (TryMatchTwoCharOperator('<', "<<")) return true;
        _currentToken = new Token(TokenType.Operator, "<");
        return true;
    }

Reverses my earlier "extracting would obscure intent" call after
re-reading — the helper-based form actually surfaces the intent
("two-char operator dispatch") more clearly than the original.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 17:08:26 -05:00
Thom LambandClaude Opus 4.7 85cc79d5a1 refactor(dedup): share clause-with-comments ingestion (PG/Snowflake QueryBreakdown ctors)
The `QueryBreakdown(string select, string from, ...)` constructors on
PostgreSql.QueryBreakdown and Snowflake.QueryBreakdown each ran the
same six-line pattern twice (once per clause): call
`parser.ExtractSqlComments`, set the clause to the trimmed result,
join the comment list into the Comment property.

New `StatementParser.PopulateClauseWithComments(rawText, target)`
instance method does both halves. Each ctor now reads:

    parser.PopulateClauseWithComments(selectClause, SelectClause);
    parser.PopulateClauseWithComments(fromClause, FromClause);

Same behavior; the helper is a pure refactor of existing semantics.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 17:06:51 -05:00
Thom LambandClaude Opus 4.7 507620cc04 refactor(dedup): redundant Snowflake override + shared Insert regex helper
Two follow-ups to the prior dedup pass:

- **Delete `Snowflake.UpdateBreakdown.GetSqlBreakdown`**: it was a
  byte-for-byte copy of the SqlServer base's `GetSqlBreakdown` (modulo
  one explanatory comment). Snowflake's UPDATE syntax — including the
  FROM clause — is identical at the formatter level, so the override
  was pure inheritance noise. Now inherits.

- **Extract `ParsePreparation.TryMatchInsertSql`**: the regex match +
  group extraction + failure message at the end of
  `SqlServer.InsertBreakdown.TryParse` and
  `Snowflake.InsertBreakdown.TryParse` was duplicated. Hoist the
  shared piece next to `TryRunPrelude` on `ParsePreparation`. Both
  callers continue to construct their own `InsertBreakdown` instance
  (the constructor signatures differ slightly between dialects).

All 1180 tests stay green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 17:05:00 -05:00