Skip to content

fix(sql): select the loaded formatter automatically - #191

Merged
Sec-ant merged 1 commit into
mainfrom
fix/sql-plugin-auto-selection
Oct 22, 2026
Merged

Sec-ant merged 1 commit into
mainfrom
fix/sql-plugin-auto-selection

Conversation

@Sec-ant

@Sec-ant Sec-ant commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

SQL templates are left unformatted when only prettier-plugin-sql-cst is loaded and embeddedSqlPlugin is omitted. Select the loaded formatter by its parser capabilities, preferring prettier-plugin-sql when both are available.

Preserve explicit choices, per-tag overrides, the sqlite parser default, and existing embedded error handling. Add focused regression coverage, a README decision table, and a patch changeset.

Validation:

  • pnpm test:ci: 1179 tests passed; coverage thresholds passed.
  • pnpm check
  • pnpm type-check
  • git diff --check

Fixes #187.

Summary by CodeRabbit

  • New Features

    • Embedded SQL formatting now automatically selects an available SQL formatter when no formatter is explicitly chosen. If both supported formatters are loaded, prettier-plugin-sql is preferred; otherwise, the formatter that supports the configured SQL parser is selected.
    • An explicitly selected formatter continues to take precedence, with no fallback to another formatter.
  • Documentation

    • Updated the SQL formatter selection guide to explain selection rules and what happens when a parser is unavailable.

@changeset-bot

changeset-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7c03f55

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
prettier-plugin-embed Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6255c0bf-56ce-4502-8125-63ea54aff115
📥 Commits

Reviewing files that changed from the base of the PR and between 855308f and 7c03f55.

📒 Files selected for processing: 5
  • .changeset/tidy-sql-defaults.md
  • README.md
  • src/embedded/sql/embedder.ts
  • src/embedded/sql/options.ts
  • tests/embedded/sql.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The SQL embedder now selects a formatter based on loaded parsers when embeddedSqlPlugin is unset. An explicit formatter choice remains in effect. Tests, README documentation, and a patch changeset cover the selection behavior.

Changes: SQL formatter selection

Layer / File(s) Summary
Formatter resolution and validation
src/embedded/sql/options.ts, src/embedded/sql/embedder.ts, tests/embedded/sql.spec.ts
The option no longer defaults to prettier-plugin-sql. When no formatter is specified, the embedder selects prettier-plugin-sql-cst if no plugin provides the sql parser and a plugin provides the configured parser, which defaults to sqlite. Otherwise, it selects prettier-plugin-sql. Tests cover plugin selection, output, and idempotence.
Selection documentation and changeset
README.md, .changeset/tidy-sql-defaults.md
The README documents formatter selection, parser resolution, and missing-parser behavior. The changeset describes the formatter selection behavior.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 7c03f

The formatter-selection change is mergeable with normal checks; no blocking issue was established.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: automatic selection of a loaded SQL formatter when no formatter is specified.
Linked Issues check Passed For #187, src/embedded/sql/options.ts removes the fixed SQL plugin default. src/embedded/sql/embedder.ts preserves explicit embeddedSqlPlugin and embedded overrides, selects `prettier-plugin-sql…
Out of Scope Changes check Passed The changes stay within #187. The added tests verify formatter selection and preserved behavior. The README decision table documents the new selection rules. The patch changeset records the SQL format…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Full details: Linked Issues check

Explanation

For #187, src/embedded/sql/options.ts removes the fixed SQL plugin default. src/embedded/sql/embedder.ts preserves explicit embeddedSqlPlugin and embedded overrides, selects prettier-plugin-sql-cst when no loaded plugin provides sql and the configured CST parser is available, and otherwise prefers prettier-plugin-sql. The sqlite default remains unchanged. Tests cover plugin order, explicit selection, tag overrides, idempotence, SQLite selection, and existing parser error handling.

Full details: Out of Scope Changes check

Explanation

The changes stay within #187. The added tests verify formatter selection and preserved behavior. The README decision table documents the new selection rules. The patch changeset records the SQL formatter fix. No unrelated implementation change is shown.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3 files. (2 skipped: 2 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/prettier-plugin-embed@191

commit: 7c03f55

@Sec-ant
Sec-ant merged commit eaaadd6 into main Oct 22, 2026
8 checks passed
@Sec-ant
Sec-ant deleted the fix/sql-plugin-auto-selection branch October 22, 2026 10:38

This branch was successfully deployed

1 active deployment
github-pages — 7c03f55c Deployed Oct 22, 2026 by Sec-ant via deploy #27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL templates are silently left unformatted when only prettier-plugin-sql-cst is loaded

1 participant