ESLint plugin ensuring best practices and code quality for Prisma with TypeScript
npm install @v2nic/eslint-plugin-prismaESLint plugin ensuring best practices and code quality for Prisma with TypeScript

This ESLint plugin is designed to help developers maintain best practices and enforce code quality when using Prisma in TypeScript projects. It includes a set of custom rules tailored to the specific requirements and idioms of Prisma, aiming to prevent common pitfalls and encourage efficient, clean, and secure database interactions.
You'll first need to install ESLint:
``sh`
npm install eslint --save-dev
Next, install @v2nic/eslint-plugin-prisma:
`sh`
npm install @v2nic/eslint-plugin-prisma --save-dev
If you want to use a local checkout instead of the registry, build the package and install it via a file path.
`sh`
npm install
npm run build
From the consuming project:
`sh`
npm install /absolute/path/to/eslint-plugin-prisma --save-dev
If you update the plugin source, re-run npm run build in the plugin repo and reinstall. For local development, you can use npm link to create a global symlink to the package and then link it into your consuming project:
`shin the plugin repo
npm link
This makes Node resolve the plugin to your local checkout. The global link lives under your npm prefix (from
npm prefix -g) at lib/node_modules/@v2nic/eslint-plugin-prisma (macOS/Linux) or node_modules\@v2nic\eslint-plugin-prisma (Windows). You still need to rebuild after changes (npm run build) because consumers load the compiled output. To stop using the linked package, run npm unlink --no-save @v2nic/eslint-plugin-prisma in the consuming repo and npm unlink in the plugin repo.Usage
Example failure for schema field naming:
`prisma
model InvoiceItem {
id Int @id
customer_id String
}
``text
schema.prisma
3:3 error Schema field names must follow the camelCase style prisma/schema-field-name-style
`$3
The VS Code ESLint extension only validates language IDs listed in
eslint.validate. ESLint config does not control this. Add Prisma to your workspace or user settings to enable linting in .prisma files:`json
{
"eslint.validate": ["javascript", "typescript", "prisma"]
}
`$3
Use the processor object and plugin map. This complete example shows both overrides:
`js
import prisma from '@v2nic/eslint-plugin-prisma';export default [
{
files: ['*/.prisma'],
plugins: { prisma },
processor: prisma.processors['.prisma'],
},
{
files: ['*/.prisma.js'],
plugins: { prisma },
rules: {
'prisma/schema-field-name-style': 'error',
'prisma/schema-model-name-style': 'error',
'prisma/schema-enum-name-style': 'error',
'prisma/schema-enum-value-style': 'error',
'prisma/db-table-name-style': 'error',
'prisma/db-column-name-style': 'error',
'prisma/db-enum-name-style': 'error',
'prisma/db-enum-value-style': 'error',
},
},
];
`The processor rewrites
schema.prisma into schema.prisma.js, so rule overrides must target /.prisma.js for flat config. An override is the file-matching block in your config array that applies rules to a specific glob. The /.prisma override only enables the processor. If you prefer, prisma.configs['prisma-schema-flat'] provides the processor-only override.#### Rule selection
You must specify the rules you want to enable. If you want the naming rules with defaults, use the bundled preset:
`js
import prisma from '@v2nic/eslint-plugin-prisma';export default [...prisma.configs['prisma-schema-flat-recommended']];
`$3
To lint Prisma schema files, enable the processor configuration and set rules in an override:
`json
{
"extends": ["plugin:@v2nic/prisma/prisma-schema"],
"overrides": [
{
"files": ["*.prisma.js"],
"rules": {
"prisma/schema-field-name-style": "error",
"prisma/schema-model-name-style": "error",
"prisma/schema-enum-name-style": "error",
"prisma/schema-enum-value-style": "error",
"prisma/db-table-name-style": "error",
"prisma/db-column-name-style": "error",
"prisma/db-enum-name-style": "error",
"prisma/db-enum-value-style": "error"
}
}
]
}
`For classic config, you can also use the bundled
prisma-schema-recommended config for default naming rules on the processed *.prisma.js file.Add
@v2nic/prisma to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix.
Then configure the rules you want to use under the rules section:`json
{
"plugins": ["@v2nic/prisma"],
"rules": {
"prisma/no-unsafe": "error",
"prisma/require-select": "error"
}
}
`Load the
recommended configuration:`json
{
"extends": ["plugin:@v2nic/prisma/recommended"]
}
`Rule names are always under the
prisma/* namespace even when the plugin is scoped.Configurations
The table below is generated from the exported configs. The ✅ marker indicates the
recommended preset, which enables no-unsafe and require-select only.| | Name |
| :-- | :------------------------------- |
| |
prisma-schema |
| | prisma-schema-flat |
| | prisma-schema-flat-recommended |
| | prisma-schema-recommended |
| ✅ | recommended |Rules
The rules table is generated from each rule definition. The 💡 marker means the rule provides ESLint suggestions via
meta.hasSuggestions`.💡 Manually fixable by editor suggestions.
| Name | Description | 💡 |
| :--------------------------------------------------------------- | :------------------------------------------------------------------- | :-- |
| db-column-name-style | Enforce database column names to follow the configured style | 💡 |
| db-enum-name-style | Enforce database enum names to follow the configured style | 💡 |
| db-enum-value-style | Enforce database enum values to follow the configured style | 💡 |
| db-table-name-style | Enforce database table names to follow the configured style | 💡 |
| no-snake-case-in-ts | Disallow snake_case identifiers and keys in TypeScript | 💡 |
| no-unsafe | Disallow the use of potentially unsafe Prisma methods | |
| require-select | Forces explicit selection of all fields in Prisma queries | 💡 |
| schema-enum-name-style | Enforce schema enum names to follow the configured TypeScript style | 💡 |
| schema-enum-value-style | Enforce schema enum values to follow the configured TypeScript style | 💡 |
| schema-field-name-style | Enforce schema field names to follow the configured TypeScript style | 💡 |
| schema-model-name-style | Enforce schema model names to follow the configured TypeScript style | 💡 |