Getting Started
Prerequisites
Set up ESLint following the typescript-eslint Getting Started docs, to enable TypeScript language support in ESLint.
Installation
bash
npm install --save-dev @ts-safeql/eslint-plugin libpg-queryIntegrate with ESLint
In order for SafeQL to be able to lint your queries, you need to specify either a databaseUrl or a migrationsDir in your ESLint configuration:
js
// eslint.config.js
import safeql from "@ts-safeql/eslint-plugin/config";
import { defineConfig } from "eslint/config";
export default defineConfig(
{
languageOptions: {
parserOptions: {
projectService: true,
},
},
},
safeql.configs.connections({
// read more about configuration in the next section
databaseUrl: "postgres://postgres:postgres@localhost:5432/my_database",
targets: [{ tag: "sql" }],
})
);
defineConfigcomes with ESLint 9.22 and later. On an older ESLint 9, remove theeslint/configimport and export a plain array of the same config objects instead:export default [{ ... }, safeql.configs.connections({ ... })];
In the next section, you'll learn how to configure your connection(s).