Registry / testing / postgresql-eslint-parser

postgresql-eslint-parser

JSON →
library0.1.8jsnpmunverified

postgresql-eslint-parser provides a specialized parser for PostgreSQL SQL syntax, enabling ESLint to perform static analysis on `.sql` files or SQL embedded within other codebases. It leverages the `libpg-query` library to convert PostgreSQL SQL into an ESTree-compatible Abstract Syntax Tree (AST), which is the standard format for ESLint. The current stable version is 0.1.8, indicating it's still in its early development stages with minor patch releases for bug fixes and improvements. Its primary differentiation lies in its tight integration with the ESLint ecosystem, offering functions like `parseForESLint` that provide not only the AST but also visitor keys essential for traversing the tree and a scope manager (currently `null`). This allows developers to write custom ESLint rules specifically for PostgreSQL, ensuring SQL code adheres to project-specific style guides and best practices, enhancing code quality and maintainability in projects that utilize PostgreSQL.

npm install postgresql-eslint-parser
INSTALL
IMPORT
SIG · POSTGRESQL-ESLINT-
P
postgresql-eslint-parser
testingjavascriptv0.1.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export (parser module object)
import parser from 'postgresql-eslint-parser';
import { parse } from 'postgresql-eslint-parser';
The default export is the parser module object itself, containing methods like `parse` and `parseForESLint`. When configuring ESLint flat config, this entire object is assigned to `languageOptions.parser`.
parser.parse(code: string)
import parser from 'postgresql-eslint-parser'; const ast = parser.parse('SELECT 1');
import { parse } from 'postgresql-eslint-parser';
The `parse` function is a method on the default-exported parser object, not a direct named export. It returns an ESTree `Program` node.
parser.parseForESLint(code: string)
import parser from 'postgresql-eslint-parser'; const { ast, visitorKeys } = parser.parseForESLint('SELECT 1');
import { parseForESLint } from 'postgresql-eslint-parser';
The `parseForESLint` function is a method on the default-exported parser object, providing the AST, visitor keys for traversal, and a scope manager (currently `null`), as required by ESLint.

Demonstrates configuring the parser in an ESLint flat config file to lint SQL files and basic programmatic usage of the parse function.

import postgresqlParser from 'postgresql-eslint-parser'; export default [ { files: ['**/*.sql'], languageOptions: { parser: postgresqlParser, parserOptions: { // No specific options documented yet, but this is where they would go } }, rules: { // Example: A hypothetical rule to disallow 'SELECT *' // 'postgresql-eslint-parser/no-select-star': 'error' // (Note: No actual rules are shipped with the parser itself) }, }, // Add other ESLint configs here (e.g., for JavaScript/TypeScript files) ]; // Example of programmatic parsing (for custom tools or testing) const sqlCode = "SELECT user_name, email FROM users WHERE active = TRUE;"; const ast = postgresqlParser.parse(sqlCode); console.log(JSON.stringify(ast, null, 2));
Debug
Known issues
breakingThis package requires Node.js version 22.0.0 or higher. Earlier Node.js versions are not supported and will result in runtime errors.
fix
Upgrade your Node.js environment to version 22.0.0 or newer. Check the `engines` field in `package.json` for precise requirements.
affects: <0.1.0
gotchaAs of v0.1.8, ESLint disable directives (e.g., `/* eslint-disable */`) placed in SQL comments are now respected. In prior versions, these directives were ignored, potentially leading to unexpected linting results.
fix
No fix required, but be aware of the change in behavior if upgrading from earlier versions. Ensure your SQL comment directives are correctly formatted if you relied on them being ignored previously.
affects: <0.1.8
gotchaThis package is pre-1.0.0, indicating that its API may not be stable and could introduce breaking changes in minor versions. Always review release notes carefully when upgrading.
fix
Monitor release notes (`CHANGELOG.md` or GitHub releases) for each update. Pin exact versions for production use or use a dependency manager like Dependabot to alert you to updates.
affects: >=0.1.0
Errors
Common errors & fixes
ESLint: The 'parser' option to ESLint's 'Linter' class must be a function.
Attempted to use the parser by providing its package name as a string (e.g., `parser: "postgresql-eslint-parser"`) instead of importing the parser module object.
fix
In your `eslint.config.js` (flat config), import the parser object and assign it directly: `import postgresqlParser from 'postgresql-eslint-parser'; languageOptions: { parser: postgresqlParser, }`.
Error: Cannot find module 'postgresql-eslint-parser'
The package was not installed or is not resolvable in the current project context.
fix
Ensure the package is installed: `npm install postgresql-eslint-parser` or `yarn add postgresql-eslint-parser`. Verify that the module resolution paths are correct if using a monorepo or custom setup.
SQL syntax error at or near "..."
The provided SQL code contains a syntax error that `libpg-query` (the underlying parser) cannot parse according to PostgreSQL's grammar.
fix
Review the SQL statement for correctness against PostgreSQL syntax. The error message usually indicates the approximate location of the syntax issue. This parser is strict about PostgreSQL SQL.
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
postgresql-eslint-parser — npm install postgresql-eslint-parser · libregistry