A T-SQL / SQL Server formatter for Visual Studio Code. It formats complete documents or the current selection while preserving string literals, comments, quoted identifiers, and T-SQL-specific syntax.
Features
- Formats T-SQL statements, clauses, joins, CTEs, subqueries, and set operations.
- Supports
SELECT, INSERT, UPDATE, DELETE, MERGE, DDL, stored procedures, triggers, TRY/CATCH, CASE, window functions, OFFSET/FETCH, and GO batches.
- Preserves
'single-quoted' strings, N'Unicode' strings, "quoted" identifiers, [bracketed] identifiers, comments, and SQLCMD lines.
- Formats the current selection when one exists; otherwise formats the whole document.
- Uses the editor's tab size for indentation.
- Preserves CRLF/LF line endings, BOMs, money literals, and multi-line literal contents.
- Avoids changing the case of ambiguous identifiers while still uppercasing keywords.
- Returns the original text unchanged if formatting fails.
Usage
- Install the extension from a
.vsix file:
- Open the Extensions view.
- Select
... > Install from VSIX...
- Choose the packaged
sql-formatter-plus-3.1.1.vsix file.
- Open a
.sql file.
- Optionally select the SQL you want to format.
- Run sql-formatter-plus: Format SQL from the Command Palette.
Selections that start or end inside a string literal, comment, or delimited identifier are skipped to avoid corrupting the document.
Development
npm install
npm test
npm run vsix
npm test compiles the extension and runs the unit and integration tests in a VS Code extension host. npm run vsix creates a packaged extension in the repository root.
Notes
- Formatting is syntax-aware but does not validate SQL semantics.
- The extension does not change object names, column names, or string contents.
- Keyword casing is configurable through the formatter API; the VS Code command uses uppercase keywords.
License
MIT
| |