Registry / testing / eslint-plugin-format-sql

eslint-plugin-format-sql

JSON →
library1.1.1jsnpmunverified

An ESLint plugin that automatically formats SQL queries inside template literals tagged with configurable identifiers (e.g., SQL, sql). Current version 1.1.1, updated semi-regularly. It leverages the sql-formatter library to support 15+ SQL dialects (PostgreSQL, MySQL, BigQuery, etc.) and adds post-formatting improvements. Unlike generic formatters, it integrates directly into the ESLint workflow with --fix support, allowing codebases to enforce consistent SQL formatting without manual effort. Ships TypeScript type definitions.

npm install eslint-plugin-format-sql
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-FORM
E
eslint-plugin-format-sql
testingjavascriptv1.1.1
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.

plugin
// In .eslintrc.{js,json}: "plugins": ["format-sql"]
import plugin from 'eslint-plugin-format-sql'
This is an ESLint plugin, not a regular library. It is loaded via ESLint's configuration, not imported in source code.
config (flat)
// eslint.config.js: export default [ ...require('eslint-plugin-format-sql').configs['flat/recommended'], ];
import { configs } from 'eslint-plugin-format-sql'
Flat config is available since v1.1.0; use 'flat/recommended' or 'flat/format'.
rule
// .eslintrc: "format-sql/format": "warn"
import { format } from 'eslint-plugin-format-sql'
Rules are referenced by name in ESLint configuration, not imported.

Install the plugin and configure it in ESLint to format SQL template literals with --fix.

npm install --save-dev eslint eslint-plugin-format-sql
Debug
Known issues
gotchaThe plugin only formats template literals tagged with the names specified in the 'tags' option; untagged strings are ignored.
fix
Ensure your SQL template literal has a tag (e.g., SQL`...`) and include that tag name in the 'tags' array.
affects: >=1.0.0
gotchaThe 'startSpaces' option adds extra indentation to the entire query; setting it too high can produce excessive whitespace.
fix
Adjust 'startSpaces' to match your coding style; typically 0 or 2.
affects: >=1.0.0
gotchaThe plugin may not correctly handle nested template expressions or dynamic SQL parts that are not string literals.
fix
Use only simple ${variable} placeholders; avoid complex expressions inside the template literal.
affects: >=1.0.0
gotchaIf the SQL template library (e.g., pg-sql-template) modifies the tag behavior, the plugin might not recognize the tag correctly.
fix
Test with your specific library; if issues, configure 'tags' to match the exact tag name used.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'eslint-plugin-format-sql'
The plugin is not installed or ESLint cannot resolve it.
fix
Run `npm install --save-dev eslint-plugin-format-sql` and verify node_modules.
Definition for rule 'format-sql/format' was not found
The plugin is not listed in 'plugins' section of ESLint config.
fix
Add 'format-sql' to the 'plugins' array in your ESLint configuration.
Invalid option 'language': 'mysql2' is not supported
The 'language' option must be one of the supported dialect strings.
fix
Use 'mysql' instead of 'mysql2' or check the documentation for supported dialects.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
eslintrequiredpeer dependency; plugin requires ESLint to function
sql-formatterrequiredcore formatting engine; provides SQL parsing and formatting for multiple dialects
Agent activity
9 hits · last 30 days
node
8
Resources
eslint-plugin-format-sql — npm install eslint-plugin-format-sql · libregistry