A PostgreSQL SQL parser for ESLint.
npm install postgresql-eslint-parserA PostgreSQL SQL parser for ESLint.
``bash`
npm install postgresql-eslint-parser
`javascript
import parser from "postgresql-eslint-parser";
// Parse SQL code
const ast = parser.parse("SELECT * FROM users WHERE id = 1");
// Parse for ESLint (includes visitor keys and scope manager)
const { ast, visitorKeys, scopeManager } = parser.parseForESLint(
"SELECT * FROM users WHERE id = 1",
);
`
Configure the parser in your ESLint configuration file:
#### ESLint Flat Config (eslint.config.js)
`javascript
import postgresqlParser from "postgresql-eslint-parser";
export default [
{
files: ["*/.sql"],
languageOptions: {
parser: postgresqlParser,
},
rules: {
// Your SQL-specific rules here
},
},
];
`
- 🔍 PostgreSQL SQL parsing - Powered by libpg-query (parseForESLint
- 🌳 ESTree-compatible AST - Works seamlessly with ESLint
- 🎯 ESLint integration - Provides function with visitor keys
- 📍 Source location tracking - Includes line/column information for all nodes
- 🏷️ Token support - Generates tokens for syntax highlighting and analysis
Parses SQL code and returns an ESTree Program node.
Parses SQL code for ESLint usage, returning an object with:
- ast: The ESTree Program nodevisitorKeys
- : Visitor key mappings for AST traversalscopeManager
- : Scope manager (currently null`)