ESLint custom parser · PostgreSQL 17

Lint SQL the same way you lint everything else.

postgresql-eslint-parser turns PostgreSQL source into an ESTree-compatible AST so ESLint can parse, traverse and report on .sql files — directives, scope walks, rule authoring and all.

Install npm install --save-dev postgresql-eslint-parser

Features

  • Real PostgreSQL 17 grammar

    Backed by libpg-query — the actual Postgres server parser compiled to WebAssembly. CTEs, window functions, LATERAL joins, partial indexes are all parsed the way Postgres parses them.

  • ESTree-compatible AST

    Every statement is a normal AST node with `type`, `range`, `loc`, `parent`. ESLint, plugin authors, codemods and AST inspectors already speak this language.

  • Synchronous parser API

    The WASM is loaded eagerly through `new WebAssembly.Module`, so `parseForESLint` stays synchronous — exactly what ESLint expects from a custom parser.

  • ESLint directives in SQL comments

    `-- eslint-disable-next-line` and `/* eslint-disable */` work in `.sql` files because tokens and comments are emitted in the shape ESLint's directive scanner expects.

  • Graceful syntax errors

    Broken SQL doesn't crash the lint run. The parser returns a `SQLParseError` node inside `program.body`, so downstream rules and IDEs can still inspect the source.

  • Typed AST

    All node types are shipped under the `Ast` namespace export. Write custom ESLint rules in TypeScript with full inference — no `any` casts needed.

  • Lint plv8, plpgsql, plpython3u, …

    PL function bodies are exposed as `EmbeddedCode` nodes, and the bundled processor emits one virtual file per body — bring your own ESLint parser for any language.

Drop it into your ESLint config

Add the parser to ESLint's flat config and point it at .sql files. Your editor and CI will lint SQL the same way they lint TypeScript and JavaScript.

See the documentation for the full API, or try the playground to inspect the AST a rule would receive.

Looking for ready-made rules? Check out eslint-plugin-postgresql, the companion plugin that ships lint rules built on this parser.

// eslint.config.js
import postgresqlParser from "postgresql-eslint-parser";

export default [
  {
    files: ["**/*.sql"],
    languageOptions: {
      parser: postgresqlParser,
    },
    rules: {
      // your SQL-specific rules
    },
  },
];