Registry / testing / eslint-plugin-slonik

eslint-plugin-slonik

JSON →
library1.13.5jsnpmunverified

ESLint plugin for compile-time SQL query validation against your PostgreSQL database schema. Version 1.13.5 validates raw SQL strings within Slonik SQL tags (sql.array, sql.fragment, sql.identifier, etc.) at lint time, catching errors before runtime. A fork of @ts-safeql/eslint-plugin with native Slonik support. Requires libpg-query as peer dependency. Patches are released regularly, but the plugin is stable with full feature coverage for Slonik's tag builders.

npm install eslint-plugin-slonik
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-SLON
E
eslint-plugin-slonik
testingjavascriptv1.13.5
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.

default
import slonik from 'eslint-plugin-slonik';
const slonik = require('eslint-plugin-slonik');
ESM-only; does not support CommonJS require. Use flat config only.
rules['slonik/check-sql']
import slonik from 'eslint-plugin-slonik'; rules: { 'slonik/check-sql': ['error', {...}] }
rules: { 'check-sql': ['error', {...}] }
Rule names are prefixed with slonik/ in ESLint config. Do not omit the plugin prefix.
plugins.slonik
import slonik from 'eslint-plugin-slonik'; plugins: { slonik }
plugins: { 'eslint-plugin-slonik': slonik }
Use the shorthand 'slonik' for the plugin key in flat config.

Shows flat config setup with database URL from env and Slonik SQL tag validation example.

// Install: npm install eslint-plugin-slonik libpg-query --save-dev // eslint.config.js (flat config) import slonik from 'eslint-plugin-slonik'; export default [ { plugins: { slonik, }, rules: { 'slonik/check-sql': [ 'error', { connections: { databaseUrl: process.env.DATABASE_URL ?? '', targets: [ { tag: 'sql.+(type\\\(*\\)|typeAlias\\\(*\\)|unsafe)' }, ], }, }, ], }, }, ]; // Example usage in code: import { sql } from 'slonik'; // This will be linted: sql.typeAlias('id')(sql`SELECT id FROM users WHERE name = ${name}`);
Debug
Known issues
breakingESM-only package — must use import syntax, not require().
fix
Use import slonik from 'eslint-plugin-slonik' in flat config; switch from .eslintrc to eslint.config.js.
affects: >=1.0.0
breakingRequires libpg-query >=13.2.5 as peer dependency — missing it causes runtime error.
fix
Run: npm install libpg-query --save-dev
affects: >=1.0.0
deprecatedLegacy .eslintrc format (JSON/YAML) is not supported; only flat config works.
fix
Migrate to eslint.config.js flat config as shown in quickstart.
affects: >=1.0.0
gotchadatabaseUrl can be undefined — validation silently disabled with warning log.
fix
Always set databaseUrl or use DATABASE_URL environment variable; check ESLint logs for warning.
affects: >=1.0.0
gotchaLegacy rule name 'check-sql' without plugin prefix will not work.
fix
Use 'slonik/check-sql' as rule key.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'libpg-query'
Missing peer dependency libpg-query.
fix
Run: npm install libpg-query --save-dev
Error: Invalid plugin object: ... Must be import of eslint-plugin-slonik
Using require() or wrong import for ESM-only plugin.
fix
Use import slonik from 'eslint-plugin-slonik' with flat config.
Error: "slonik/check-sql" rule not found
Rule name misspelled or missing plugin registration.
fix
Ensure plugins: { slonik } is set and rule key is 'slonik/check-sql'.
Warning: [eslint-plugin-slonik] databaseUrl is not configured. SQL validation is disabled.
No database URL provided.
fix
Set databaseUrl in config or export DATABASE_URL environment variable.
Upgrade
Version history
1.13.5latest on npm
Audit
Dependencies
libpg-queryrequiredRequired peer dependency for SQL parsing and validation
Agent activity
5 hits · last 30 days
node
4
Resources
eslint-plugin-slonik — npm install eslint-plugin-slonik · libregistry