This document is automatically generated from the source code. Do not edit it directly.
Configuration option schemas are written with Zod.
- ban-unbounded-string-type
- enum-name-pascal-case
- enum-value-snake-case
- field-name-camel-case
- field-name-mapping-snake-case
- field-order
- forbid-field
- forbid-required-ignored-field
- model-name-grammatical-number
- model-name-mapping-snake-case
- model-name-pascal-case
- model-name-prefix
- require-default-empty-arrays
- require-field-index
- require-field-type
- require-field
Checks that String fields are defined with a database native type to
limit the length, e.g. @db.VarChar(x)
.
Motivation inspired by https://brandur.org/text - to avoid unintentionally
building public APIs that support unlimited-length strings.
z.object({
allowNativeTextType: z.boolean().optional(),
}).strict();
// good
model User {
id String @db.VarChar(36)
}
// bad
model User {
id String
}
// bad
model User {
id String @db.Text
}
// good
model User {
id String @db.Text
}
Checks that enum names are in PascalCase.
z.object({
allowList: z.array(z.union([z.string(), z.instanceof(RegExp)])).optional(),
trimPrefix: z
.union([
z.string(),
z.instanceof(RegExp),
z.array(z.union([z.string(), z.instanceof(RegExp)])),
])
.optional(),
}).strict();
// good
enum ExampleOptions {
value1
}
// bad
enum exampleOptions {
value1
}
// bad
enum example_options {
value1
}
Checks that enum values are in snake_case.
This rule supports selectively ignoring enum values via the
prisma-lint-ignore-enum
comment, like so:
/// prisma-lint-ignore-enum enum-value-snake-case SCREAMING_SNAKE
That will permit an enum value of SCREAMING_SNAKE
. Other
values for the enum must still be in snake_case. A comma-separated list of values
can be provided to ignore multiple enum values.
z.object({
allowList: z.array(z.union([z.string(), z.instanceof(RegExp)])).optional(),
trimPrefix: z
.union([
z.string(),
z.instanceof(RegExp),
z.array(z.union([z.string(), z.instanceof(RegExp)])),
])
.optional(),
}).strict();
// good
enum Example {
value
}
// good
enum Example {
value_1
}
// bad
enum Example {
Value
}
// bad
enum Example {
VALUE
}
// bad
enum Example {
camelCase
}
Checks that field names are in camelCase.
z.object({
allowList: z.array(z.union([z.string(), z.instanceof(RegExp)])).optional(),
trimPrefix: z
.union([
z.string(),
z.instanceof(RegExp),
z.array(z.union([z.string(), z.instanceof(RegExp)])),
])
.optional(),
}).strict();
// good
model User {
rowId String @id
}
// bad
model User {
RowId String @id
}
// bad
model User {
row_id String @id
}
Checks that the mapped name of a field is the expected snake case.
This rule support selectively ignoring fields with parameterized comments.
That will ignore only tenantId
field violations for the model. Other
fields will still be enforced. A comma-separated list of fields can be
provided to ignore multiple fields.
z.object({
compoundWords: z.array(z.string()).optional(),
requireUnderscorePrefixForIds: z.boolean().optional(),
})
.strict()
.optional();
// good
model UserRole {
userId String @map(name: "user_id")
}
model UserRole {
// No mapping needed for single-word field name.
id String
// No mapping needed for association field.
grantedByUser User
}
// bad
model UserRole {
userId String
}
model UserRole {
userId String @map(name: "user_i_d")
}
// good
model PersistedQuery {
graphQLId String @map(name: "graphql_id")
}
// bad
model PersistedQuery {
graphQLId String @map(name: "graph_q_l_id")
}
// good
model PersistedQuery {
id String @id @map(name: "_id")
otherField String @map(name: "other_field")
}
// bad
model PersistedQuery {
id String @id @map(name: "id")
otherField String @map(name: "other_field")
}
// good
enum RoleType {
ADMIN
MEMBER
}
model UserRole {
roleType RoleType @map(name: "role_type")
}
// bad
model UserRole {
roleType RoleType
}
// good
type UserInfo {
institution String
}
model User {
userInfo UserInfo @map(name: "user_info")
}
// bad
model User {
userInfo UserInfo
}
// good
type Post {
/// prisma-lint-ignore-model field-name-mapping-snake-case tenantId
tenantId String
userId String @map(name: "user_id")
}
// bad
type Post {
/// prisma-lint-ignore-model field-name-mapping-snake-case tenantId
tenantId String
userId String
}
Checks that fields within a model are in the correct order.
Fields in the order
list that are not present in the model are ignored.
(To require fields, use the require-field
rule.)
The first field in the order
is interpreted to be required as
the first field in the model. The last field in the order
is
interpreted to be required as the last field in the model.
The special field name ...
can be used to indicate that any
number of fields can appear in the model at that point. This can
be used at the end of the order
list to indicate that remaining
fields can appear in any order at the end of the model.
z.object({
order: z.array(z.string()),
}).strict();
// good
model User {
tenantId String
id String @id
email String
}
model User {
tenantId String
id String @id
createdAt DateTime
email String
}
// bad
model User {
id String @id
email String
tenantId String
}
// good
model User {
tenantId String
id String
email String
createdAt DateTime
updatedAt DateTime
}
model User {
tenantId String
id String
email String
createdAt DateTime
}
// bad
model User {
id String @id
createdAt DateTime
email String
}
Forbids fields with certain names.
z.object({
forbid: z.array(z.union([z.string(), z.instanceof(RegExp)])),
}).strict();
// good
type Product {
uuid String
}
// bad
type Product {
id String
}
// good
type Product {
id String
priceAmountD6 Int
}
// bad
type Product {
id Int
priceD6 Int
}
Forbids required ignored fields without default values.
This prevents a client from being generated without a field while the database still expects the corresponding column to be non-nullable.
For more protection against breaking changes, consider using:
https://github.com/loop-payments/prisma-safety
// good
type Product {
uuid String
toBeRemoved String? @ignore
}
// good
type Product {
uuid String
toBeRemoved Boolean @default(false) @ignore
}
// bad
type Product {
uuid String
toBeRemoved String @ignore
}
Checks that each model name matches the plural or singlar enforced style.
https://en.wikipedia.org/wiki/Grammatical_number
z.object({
style: z.enum(['singular', 'plural']),
allowlist: z.array(z.union([z.string(), z.instanceof(RegExp)])).optional(),
}).strict();
// good
model User {
id String @id
}
// bad
model Users {
id String @id
}
// good
model Users {
id String @id
}
// bad
model User {
id String @id
}
// good
model UserData {
id String @id
}
model User {
id String @id
}
model Tenant {
id String @id
}
// bad ("data" is considered plural by default)
model TenantData {
id String @id
}
model Users {
id String @id
}
// good
model UserData {
id String @id
}
model TenantData {
id String @id
}
// bad
model DataRecords {
id String @id
}
model Users {
id String @id
}
Checks that the mapped name of a model is the expected snake case.
z.object({
compoundWords: z.array(z.string()).optional(),
irregularPlurals: z.record(z.string()).optional(),
pluralize: z.boolean().optional(),
trimPrefix: z.string().optional(),
})
.strict()
.optional();
// good
model UserRole {
id String @id
@@map(name: "user_role")
}
// bad
model UserRole {
id String @id
}
model UserRole {
id String @id
@@map(name: "user_roles")
}
// good
model DbUserRole {
id String @id
@@map(name: "user_role")
}
// bad
model DbUserRole {
id String @id
@@map(name: "db_user_role")
}
// good
model GraphQLPersistedQuery {
id String @id
@@map(name: "graphql_persisted_query")
}
// bad
model GraphQLPersistedQuery {
id String @id
@@map(name: "graph_q_l_persisted_query")
}
// good
model UserRole {
id String @id
@@map(name: "user_roles")
}
// bad
model UserRole {
id String @id
}
model UserRole {
id String @id
@@map(name: "user_role")
}
Checks that model names are in PascalCase.
z.object({
allowList: z.array(z.union([z.string(), z.instanceof(RegExp)])).optional(),
trimPrefix: z
.union([
z.string(),
z.instanceof(RegExp),
z.array(z.union([z.string(), z.instanceof(RegExp)])),
])
.optional(),
}).strict();
// good
model DbUser {
id String @id
}
// bad
model dbUser {
id String @id
}
// bad
model db_user {
id String @id
}
Checks that model names include a required prefix.
This is useful for avoiding name collisions with application-level types in cases where a single domain object is persisted in multiple tables, and the application type differs from the table structure.
z.object({
prefix: z.string(),
}).strict();
// good
model DbUser {
id String @id
}
// bad
model Users {
id String @id
}
Requires default empty arrays for array fields.
Motivation: #275
// good
model Post {
tags String[] @default([])
}
// bad
model Post {
tags String[]
}
Checks that certain fields have indices.
This rule supports selectively ignoring fields via the
prisma-lint-ignore-model
comment, like so:
/// prisma-lint-ignore-model require-field-index tenantId
That will ignore only tenantId
violations for the model. Other
required indices will still be enforced. A comma-separated list of fields
can be provided to ignore multiple fields.
z.object({
forAllRelations: z.boolean().optional(),
forNames: z
.union([z.string(), z.array(z.union([z.string(), z.instanceof(RegExp)]))])
.optional(),
}).strict();
// good
model User {
createdAt DateTime @unique
}
model User {
createdAt DateTime
@@index([createdAt])
}
model User {
createdAt DateTime
id String
@@index([createdAt, id])
}
// bad
model User {
createdAt string
}
model User {
createdAt DateTime
id String
@@index([id, createdAt])
}
// good
model User {
tenantId String
@@index([tenantId])
}
// bad
model User {
tenantId String
}
// good
type Bar {
fooId String
foo Foo @relation(fields: [fooId], references: [id])
@@index([fooId])
}
// bad
type Bar {
fooId String
foo Foo @relation(fields: [fooId], references: [id])
}
Checks that certain fields have a specific type.
z.object({
require: z.array(
z.object({
ifName: z.union([z.string(), z.instanceof(RegExp)]),
type: z.string(),
}),
),
}).strict();
// good
model User {
id String
}
// bad
model User {
id Int
}
// good
model User {
createdAt DateTime
updatedAt DateTime
}
// bad
model User {
createdAt String
updatedAt String
}
Checks that a model has certain fields.
This rule supports selectively ignoring fields via the
prisma-lint-ignore-model
comment, like so:
/// prisma-lint-ignore-model require-field tenantId
That will ignore only tenantId
field violations for the model. Other
required fields will still be enforced. A comma-separated list of fields
can be provided to ignore multiple required fields.
z.object({
require: z.array(
z.union([
z.string(),
z.object({
name: z.string(),
ifSibling: z.union([z.string(), z.instanceof(RegExp)]),
}),
]),
),
}).strict();
// good
model User {
id Int @id
}
// bad
model User {
name String
}
// good
model Product {
currencyCode String
priceAmountD6 Int
}
// bad
model Product {
priceAmountD6 Int
}