eslint-plugin-sql

raw JSON →
3.4.1 verified Sat Apr 25 auth: no javascript

ESLint plugin providing SQL linting rules, including formatting via sql-formatter and unsafe query detection. Version 3.4.1 is current, with active development. It supports Postgres and uses template literal tags (default `` sql `` ) to identify SQL. Requires ESLint >=8.1.0 and Node >=18. Differentiated by its focus on safety (no-unsafe-query) and auto-fix formatting. Ships TypeScript types.

error Definition for rule 'sql/format' was not found.
cause Plugin not installed or not added to plugins array.
fix
Run 'npm install eslint-plugin-sql --save-dev' and add 'plugins: ["sql"]' to ESLint config.
error Expected a plain object but got 'undefined'.
cause Rule options passed as second argument but not wrapped in an array.
fix
Use array format: 'sql/format': [2, {}] instead of 'sql/format': {}
error Cannot find module 'eslint-plugin-sql'
cause Plugin not installed or ESLint cannot resolve it.
fix
Ensure 'eslint-plugin-sql' is in node_modules and ESLint dependencies are correct.
breaking Minimum Node version changed to 18 in v3.0.0
fix Upgrade Node to >=18
breaking Peer dependency eslint changed to >=8.1.0 in v3.0.0
fix Upgrade ESLint to >=8.1.0
deprecated The 'sql/format' rule option 'ignoreStartWithNewLine' is deprecated and will be removed in a future version
fix Remove 'ignoreStartWithNewLine' from rule options
gotcha The plugin only detects SQL in template literals tagged with 'sql' by default; set 'ignoreTagless: false' to detect all template literals
fix Add { ignoreTagless: false } to rule options
gotcha Placeholders like '?' make the SQL invalid; you must set 'placeholderRule' in settings to match them
fix Add settings: { sql: { placeholderRule: '\\?' } } to ESLint config
breaking Rule 'sql/no-unsafe-query' option 'allowLiteral' changed default from true to false in v3.0.0
fix Set 'allowLiteral: true' explicitly if you want to allow literal strings
npm install eslint-plugin-sql
yarn add eslint-plugin-sql
pnpm add eslint-plugin-sql

Configures ESLint with sql plugin, enabling format and no-unsafe-query rules.

// .eslintrc.cjs
module.exports = {
  plugins: ['sql'],
  rules: {
    'sql/format': [2, { ignoreExpressions: false, ignoreInline: true, ignoreTagless: true }],
    'sql/no-unsafe-query': [2, { allowLiteral: false }],
  },
};