sql-lint
raw JSON → 1.0.2 verified Fri May 01 auth: no javascript
An intelligent SQL linter that performs sanity checks (e.g., missing WHERE, unmatched parentheses) and surfaces database errors with more informative messages. The current stable version is 1.0.2. Since v1.0.0, it has been considered stable. Compared to other SQL linters, sql-lint focuses on catching common mistakes like missing WHERE clauses and invalid DROP/CREATE options, and supports multiple databases (MySQL, PostgreSQL). It can be used as a CLI tool or programmatically in JavaScript/TypeScript, and ships TypeScript type definitions. Release cadence is irregular.
Common errors
error TypeError: sqlLint is not a function ↓
cause Using require('sql-lint') which returns an object with a .default property.
fix
Use
const sqlLint = require('sql-lint').default; or switch to ESM imports. error Error: Cannot find module 'sql-lint' ↓
cause Package not installed globally or locally.
fix
Run
npm install -g sql-lint for CLI use or npm install sql-lint for programmatic use. error sql-lint: unable to connect to database ↓
cause Database connection parameters are missing or incorrect.
fix
Provide correct host, user, password, and database options in the config or programmatic call.
error SyntaxError: Unexpected token: name, (something) (line: 1, col: 1) ↓
cause The SQL string contains non-SQL content or is not a valid query.
fix
Ensure the input is a valid SQL statement. Use the programmatic API with
sql option. Warnings
gotcha The default export is a function. CommonJS require() may need .default to access the default export. ↓
fix Use require('sql-lint').default or use ESM imports.
breaking In v0.0.14, the --file and -f flags were removed. Files are now passed as positional arguments. ↓
fix Use `sql-lint my-file.sql` instead of `sql-lint -f my-file.sql`.
deprecated The --query and -q flags are deprecated in v0.0.14 and may be removed. Use `sql-lint --sql 'SELECT 1'` or pass via stdin. ↓
fix Use `echo 'SELECT 1' | sql-lint` or programmatic API.
gotcha When used programmatically, unresolved promises could cause the process to hang in versions before v0.0.20. ↓
fix Update to v0.0.20 or later.
gotcha Config file `ignore-errors` option was not respected until v0.0.20. ↓
fix Update to v0.0.20 or later.
Install
npm install sql-lint yarn add sql-lint pnpm add sql-lint Imports
- sqlLint wrong
const sqlLint = require('sql-lint')correctimport sqlLint from 'sql-lint' - sqlLint wrong
const sqlLint = require('sql-lint')correctconst sqlLint = require('sql-lint').default || require('sql-lint') - SqlLintOptions wrong
import { SqlLintOptions } from 'sql-lint'correctimport type { SqlLintOptions } from 'sql-lint'
Quickstart
import sqlLint from 'sql-lint';
const errors = await sqlLint({
sql: 'DELETE FROM users WHERE id = 1;',
// optionally connect to a database to get server errors
// host: 'localhost',
// user: 'root',
// password: process.env.DB_PASS ?? ''
});
if (errors.length === 0) {
console.log('No errors found.');
} else {
for (const error of errors) {
console.log(`${error.file}:${error.line}: ${error.message}`);
}
}