{"id":26426,"library":"sql-lint","title":"sql-lint","description":"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.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/joereynolds/sql-lint","tags":["javascript","sql","linter","checker","sql-linter","sql-lint","typescript"],"install":[{"cmd":"npm install sql-lint","lang":"bash","label":"npm"},{"cmd":"yarn add sql-lint","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-lint","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for connecting to MySQL databases to fetch server errors.","package":"mysql","optional":true},{"reason":"Used for connecting to PostgreSQL databases to fetch server errors.","package":"pg","optional":true}],"imports":[{"note":"ESM default import. Default export is a function. TypeScript type definitions are included.","wrong":"const sqlLint = require('sql-lint')","symbol":"sqlLint","correct":"import sqlLint from 'sql-lint'"},{"note":"In CommonJS, the default export is under .default if the package uses ESM. Use the dual approach to be safe.","wrong":"const sqlLint = require('sql-lint')","symbol":"sqlLint","correct":"const sqlLint = require('sql-lint').default || require('sql-lint')"},{"note":"Use type import for TypeScript to avoid runtime overhead.","wrong":"import { SqlLintOptions } from 'sql-lint'","symbol":"SqlLintOptions","correct":"import type { SqlLintOptions } from 'sql-lint'"}],"quickstart":{"code":"import sqlLint from 'sql-lint';\n\nconst errors = await sqlLint({\n  sql: 'DELETE FROM users WHERE id = 1;',\n  // optionally connect to a database to get server errors\n  // host: 'localhost',\n  // user: 'root',\n  // password: process.env.DB_PASS ?? ''\n});\n\nif (errors.length === 0) {\n  console.log('No errors found.');\n} else {\n  for (const error of errors) {\n    console.log(`${error.file}:${error.line}: ${error.message}`);\n  }\n}","lang":"typescript","description":"Shows programmatic usage to lint SQL string and handle lint errors."},"warnings":[{"fix":"Use require('sql-lint').default or use ESM imports.","message":"The default export is a function. CommonJS require() may need .default to access the default export.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `sql-lint my-file.sql` instead of `sql-lint -f my-file.sql`.","message":"In v0.0.14, the --file and -f flags were removed. Files are now passed as positional arguments.","severity":"breaking","affected_versions":">=0.0.14"},{"fix":"Use `echo 'SELECT 1' | sql-lint` or programmatic API.","message":"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.","severity":"deprecated","affected_versions":">=0.0.14 <1.0.0"},{"fix":"Update to v0.0.20 or later.","message":"When used programmatically, unresolved promises could cause the process to hang in versions before v0.0.20.","severity":"gotcha","affected_versions":"<0.0.20"},{"fix":"Update to v0.0.20 or later.","message":"Config file `ignore-errors` option was not respected until v0.0.20.","severity":"gotcha","affected_versions":"<0.0.20"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `const sqlLint = require('sql-lint').default;` or switch to ESM imports.","cause":"Using require('sql-lint') which returns an object with a .default property.","error":"TypeError: sqlLint is not a function"},{"fix":"Run `npm install -g sql-lint` for CLI use or `npm install sql-lint` for programmatic use.","cause":"Package not installed globally or locally.","error":"Error: Cannot find module 'sql-lint'"},{"fix":"Provide correct host, user, password, and database options in the config or programmatic call.","cause":"Database connection parameters are missing or incorrect.","error":"sql-lint: unable to connect to database"},{"fix":"Ensure the input is a valid SQL statement. Use the programmatic API with `sql` option.","cause":"The SQL string contains non-SQL content or is not a valid query.","error":"SyntaxError: Unexpected token: name, (something) (line: 1, col: 1)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}