Rich T‑SQL formatter for .sql files with extensive options and sharable profiles.
- Document formatter for
.sqlfiles only. - Configurable rules: keyword casing, indent size, line breaks, JOIN alignment, operator spacing, and more.
- Profiles: save, load, export, and import formatting rule sets.
- VS Code 1.190+
Key settings under tsqlformatter.*:
tsqlformatter.profile: active profile name.tsqlformatter.keywordCasing: upper/lower/original.tsqlformatter.indentSize: spaces per indent.tsqlformatter.newlineAfterSelect,tsqlformatter.newlineAfterFrom,tsqlformatter.joinAlignment, etc.tsqlformatter.columnsCommaPlacement:leading|trailing|ignoreto control comma placement in column lists (SELECT/ORDER BY/GROUP BY).tsqlformatter.aliasKeyword:enable|remove|ignoreto add/remove theASkeyword for aliased items (columns and table/subquery aliases).tsqlformatter.safeWrapDelimiters: array of delimiters (comma,AND,OR) considered safe for expression wrapping whenexpressionWidthis set.tsqlformatter.indentStyle:standard|centralwithtsqlformatter.indentStyleMode:ignore|enableandtsqlformatter.indentAlignColumnfor target column.tsqlformatter.indentCentralClauses: array of clauses to centrally align (e.g.,["ON", "SET", "SELECT"]).
tsqlformatter.columnsCommaPlacement: leading | trailing | ignore — comma placement for column lists (SELECT/ORDER BY/GROUP BY).tsqlformatter.aliasKeyword: enable | remove | ignore — add/remove/ignoreASfor aliased columns and table/subquery aliases.tsqlformatter.safeWrapDelimiters: [comma, AND, OR] — delimiters considered safe for wrapping withexpressionWidth.tsqlformatter.expressionWidth: number (0 disables) — wrap long expressions at safe delimiters.tsqlformatter.indentStyle: standard | central — indent strategy.tsqlformatter.indentStyleMode: ignore | enable — enable central alignment when usingcentral.tsqlformatter.indentAlignColumn: number — target column for central alignment.tsqlformatter.indentCentralClauses: [SELECT, WHERE, ON, SET] — clauses to align centrally.
- Initial formatter is minimal and will expand over time.
Initial scaffold: formatter provider, settings, profiles, samples, tests.
- Open a
.sqlfile and run Format Document. - Configure
tsqlformatter.*settings in VS Code. - Save/export/import profiles via commands.
See CONFIG.md for detailed options and PROFILES.md for sharing.
-
Columns comma placement
-
Trailing commas:
-- settings: columnsCommaPlacement=trailing, newlineAfterSelect=true SELECT a, b, c FROM t
-
Leading commas:
-- settings: columnsCommaPlacement=leading, newlineAfterSelect=true SELECT a , b , c FROM t
-
Ignore (preserve):
-- settings: columnsCommaPlacement=ignore SELECT a,b , c FROM t
-
-
Alias keyword handling
-
Enable
ASfor column and table aliases:-- settings: aliasKeyword=enable SELECT a AS colA, SUM(b) AS total FROM dbo.Table AS t
-
Remove
AS:-- settings: aliasKeyword=remove SELECT a colA, SUM(b) total FROM dbo.Table t
-
-
Safe wrap delimiters
-- settings: expressionWidth=20, safeWrapDelimiters=["AND"] WHERE a = 1 AND b = 2
-
Central alignment
-- settings: indentStyle=central, indentStyleMode=enable, indentAlignColumn=40, indentCentralClauses=["ON", "SET"] SELECT a, b FROM t LEFT JOIN x ON t.id = x.id SET @x = 1
Follow these quick steps to see the formatter in action. (GIF placeholders below — replace with recordings when ready.)
-
Open sample:
- Use
samples/sample.sqland open the file in VS Code.
- Use
-
Configure settings:
- Open VS Code Settings and search for
tsqlformatter. - Toggle
columnsCommaPlacement(e.g.,leading) andaliasKeyword(e.g.,enable).
- Open VS Code Settings and search for
-
Run the formatter:
- Execute
Format Document(right-click orShift+Alt+F). - Observe updated comma placement and alias keyword behavior.
- Execute
-
Profiles:
- Run
T-SQL Formatter: Save Active Profileto capture current settings. - Run
T-SQL Formatter: Export Active Profileand share the JSON. - Run
T-SQL Formatter: Import Profileto apply a profile.
Settings prefix note: all settings moved from
sqlFormatter.*totsqlformatter.*to avoid collisions and better reflect the extension’s purpose. VS Code will treat them as new settings; update your profiles accordingly. - Run
- Comma placement demo:
docs/media/commas.gif - Alias keyword demo:
docs/media/alias.gif - Central alignment demo:
docs/media/central.gif
-
Unit tests (Vitest):
-
Run all:
npm run test:unit
-
Watch mode:
npm run test:watch
-
Coverage:
npm run coverage
-
VS Code Testing view:
- Install the “Vitest” VS Code extension to auto-discover and run tests inline.
- Tests are under
src/test/**/*.vitest.ts.
-
-
Extension E2E tests:
npm testruns the existing integration tests via@vscode/test-electron.- This spins up a VS Code instance and validates provider registration and formatter behavior.
- CI status badge uses the workflow at
.github/workflows/ci.yml. - Coverage badge reflects Codecov-hosted results; set
CODECOV_TOKENin repository secrets for private repos (not needed for public). Alternative providers like Coveralls can be used if preferred.
-
PRs will fail if overall coverage or patch coverage drops below 80% (configured in
codecov.yml). Adjust thresholds as needed.-
Shields with GitHub Workflow Status:

-