{"library":"postgresql-eslint-parser","title":"PostgreSQL SQL Parser for ESLint","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install postgresql-eslint-parser"],"cli":null},"imports":["import parser from 'postgresql-eslint-parser';","import parser from 'postgresql-eslint-parser'; const ast = parser.parse('SELECT 1');","import parser from 'postgresql-eslint-parser'; const { ast, visitorKeys } = parser.parseForESLint('SELECT 1');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import postgresqlParser from 'postgresql-eslint-parser';\n\nexport default [\n  {\n    files: ['**/*.sql'],\n    languageOptions: {\n      parser: postgresqlParser,\n      parserOptions: {\n        // No specific options documented yet, but this is where they would go\n      }\n    },\n    rules: {\n      // Example: A hypothetical rule to disallow 'SELECT *'\n      // 'postgresql-eslint-parser/no-select-star': 'error'\n      // (Note: No actual rules are shipped with the parser itself)\n    },\n  },\n  // Add other ESLint configs here (e.g., for JavaScript/TypeScript files)\n];\n\n// Example of programmatic parsing (for custom tools or testing)\nconst sqlCode = \"SELECT user_name, email FROM users WHERE active = TRUE;\";\nconst ast = postgresqlParser.parse(sqlCode);\nconsole.log(JSON.stringify(ast, null, 2));","lang":"javascript","description":"Demonstrates configuring the parser in an ESLint flat config file to lint SQL files and basic programmatic usage of the parse function.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}