Registry / devops / dbt-formatter

dbt-formatter

JSON →
library1.3.0jsnpmunverified

A SQL and Jinja formatter for dbt (data build tool) projects. Current stable version is 1.3.0, released in 2020 with low maintenance activity. It formats dbt SQL files containing Jinja expressions (e.g., {{ ref('model') }}) with configurable indentation, uppercase keywords, and newline options. Unlike general SQL formatters (sql-formatter, pgFormatter), it preserves Jinja template syntax without breaking. It is a single-purpose tool, but may lack support for dbt-specific constructs like macros and blocks. Supports only a default SQL dialect; no active support for Redshift, BigQuery, or other databases as of v1.3.0. Minimal dependencies.

npm install dbt-formatter
INSTALL
IMPORT
SIG · DBT-FORMATTER
D
dbt-formatter
devopsjavascriptv1.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatter
import formatter from 'dbt-formatter';
const formatter = require('dbt-formatter');
Default export; ESM import works as shown. CJS require() also works but is not the recommended pattern for modern Node.
format
import { format } from 'dbt-formatter';
Named export 'format' is available as an alternative to default import. Both export the same function.
FormatOptions
import type { FormatOptions } from 'dbt-formatter';
TypeScript type for options object. Not exported as a value, only as a type.

Formats a dbt SQL string with uppercase reserved words, 2-space indentation, and a trailing newline.

import formatter from 'dbt-formatter'; const sql = `SELECT * FROM {{ ref('myTableRef') }} WHERE id = 1`; const formatted = formatter.format(sql, { sql: 'default', indent: 2, upper: true, newline: true }); console.log(formatted); // Output: // SELECT // * // FROM // {{ ref('myTableRef') }} // WHERE // id = 1
Debug
Known issues
gotchaOnly 'default' SQL dialect is supported; specifying other dialects silently falls back to default.
fix
Use `opts.sql = 'default'` or omit the option. Do not expect Snowflake, BigQuery, etc. to be supported.
affects: <=1.3.0
deprecatedPackage has not been updated since 2020; no new features or bug fixes.
fix
Consider alternatives like sql-formatter (with Jinja plugin) or write custom formatting.
affects: >=1.0.0
gotchaJinja block syntax ({% ... %}) is not handled; will cause formatting errors or unformatted output.
fix
Avoid using dbt-formatter on models with Jinja blocks (e.g., {% set %}, {% if %}). Strip blocks first or use a different formatter.
affects: <=1.3.0
gotchaThe 'lowerWords' option lowercases all words, including column aliases and table references, which may break case-sensitive databases.
fix
Set `lowerWords: false` if you need to preserve original casing for identifiers.
affects: <=1.3.0
Errors
Common errors & fixes
TypeError: formatter.format is not a function
Using default import incorrectly (e.g., import { formatter } from 'dbt-formatter').
fix
Use `import formatter from 'dbt-formatter'` (default import) or `import { format } from 'dbt-formatter'` (named export).
Cannot find module 'dbt-formatter'
Package not installed or missing from node_modules.
fix
Run `npm install dbt-formatter` (or `yarn add dbt-formatter`).
Unsupported sql dialect 'snowflake'. Falling back to default.
Only 'default' dialect is implemented; other values produce a warning and fallback.
fix
Use `opts.sql = 'default'` or omit the option. No Snowflake-specific formatting will occur.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
dbt-formatter — npm install dbt-formatter · libregistry