Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Preview/prismalint#39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
alexcoderabbitai wants to merge3 commits intomain
base:main
Choose a base branch
Loading
frompreview/prismalint
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions.coderabbit.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
reviews:
path_filters: ["**/.prismalintrc.json",".prismalintrc.json", "**/example.prisma", "example.prisma"]
36 changes: 36 additions & 0 deletions.prismalintrc.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
{
"rules": {
"field-name-mapping-snake-case": [
"error",
{
"compoundWords": ["S3"]
}
],
"field-order": [
"error",
{
"order": ["tenantId", "..."]
}
],
"forbid-required-ignored-field": ["error"],
"model-name-grammatical-number": [
"error",
{
"style": "singular"
}
],
"model-name-mapping-snake-case": [
"error",
{
"compoundWords": ["GraphQL"]
}
],
"require-field-index": [
"error",
{
"forAllRelations": true,
"forNames": ["tenantId"]
}
]
}
}
35 changes: 35 additions & 0 deletionsexample.prisma
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
generator client {
provider = "prisma-client-js"
output = "../generated/prisma/client"
}

datasource db {
provider = "postgresql"
url = "fake-url"
}
Comment on lines +6 to +9

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

⚠️ Potential issue

Datasource URL should come from env var

Hard-coding"fake-url" prevents local overrides and breaksprisma generate in CI/CD.
Typical pattern:

-  url      = "fake-url"+  url      = env("DATABASE_URL")
📝 Committable suggestion

‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
datasourcedb {
provider = "postgresql"
url ="fake-url"
}
datasourcedb {
provider = "postgresql"
url =env("DATABASE_URL")
}
🤖 Prompt for AI Agents
In example.prisma around lines 6 to 9, the datasource URL is hard-coded as"fake-url", which prevents local environment overrides and causes issues inCI/CD pipelines. Replace the hard-coded URL with an environment variablereference using the syntax env("DATABASE_URL") to allow dynamic configurationbased on the deployment environment.


model Users {
id String @id
emailAddress String
tenantId String
removeMe String @ignore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

⚠️ Potential issue

Ignored field is required

removeMe isString (required by default). Either mark it optional (String?) or drop it; otherwise it blocks deployments despite@ignore.

🤖 Prompt for AI Agents
In example.prisma at line 15, the field `removeMe` is marked with `@ignore` butis defined as a required `String`, which causes deployment issues. To fix this,either make the field optional by changing its type to `String?` or remove thefield entirely from the model to avoid blocking deployments.

tenant Tenant @relation(fields: [tenantId], references: [id])
@@map(name: "users")
}
Comment on lines +11 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🛠️ Refactor suggestion

Users violates four freshly-added lint rules

  1. Model name is plural (Users) butmodel-name-grammatical-number demands singular.
  2. RequiredremoveMe field is marked@ignore, violatingforbid-required-ignored-field.
  3. tenantId must be the first field perfield-order.
  4. tenantId lacks the mandatory@@index([tenantId]).

A minimal conforming refactor:

-model Users {-  id           String @id-  emailAddress String-  tenantId     String-  removeMe     String @ignore-  tenant       Tenant @relation(fields: [tenantId], references: [id])-  @@map(name: "users")-}+model User {+  tenantId     String+  id           String @id+  emailAddress String+  // removeMe removed – ignored required fields not allowed+  tenant       Tenant @relation(fields: [tenantId], references: [id])++  @@index([tenantId])+  @@map(name: "users")+}
📝 Committable suggestion

‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
modelUsers {
id String@id
emailAddress String
tenantId String
removeMe String@ignore
tenant Tenant@relation(fields:[tenantId],references:[id])
@@map(name:"users")
}
modelUser {
tenantId String
id String@id
emailAddress String
// removeMe removed – ignored required fields not allowed
tenant Tenant@relation(fields:[tenantId],references:[id])
@@index([tenantId])
@@map(name:"users")
}
🤖 Prompt for AI Agents
In example.prisma around lines 11 to 18, fix the Users model by renaming it tosingular form (User), remove the required field 'removeMe' or make it optionalinstead of using @ignore, reorder fields so that 'tenantId' is the first field,and add an @@index([tenantId]) attribute to index the tenantId field as requiredby the lint rules.


model Tenant {
id String @id
name String
@@map(name: "tenant")
}

model UserRoleFoo {
id String @id
@@map(name: "unexpected_snake_case")
}
Comment on lines +26 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🛠️ Refactor suggestion

UserRoleFoo mapping should follow snake-case convention

Rulemodel-name-mapping-snake-case expects the map name to beuser_role_foo.

 model UserRoleFoo {   id         String @id-  @@map(name: "unexpected_snake_case")+  @@map(name: "user_role_foo") }
📝 Committable suggestion

‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
modelUserRoleFoo {
id String@id
@@map(name:"unexpected_snake_case")
}
modelUserRoleFoo {
id String@id
@@map(name:"user_role_foo")
}
🧰 Tools
🪛 PrismaLint (0.10.2)

26-26: Model name must be mapped to "user_role_foo". (model-name-mapping-snake-case)

🤖 Prompt for AI Agents
In example.prisma around lines 26 to 29, the model UserRoleFoo has a @@mapattribute with the name "unexpected_snake_case" which does not follow therequired snake-case convention. Update the @@map name to "user_role_foo" tocomply with the model-name-mapping-snake-case rule.


model UserRole {
id String @id
userId String @map(name: "userid")
// No mapping.
}
Comment on lines +31 to +35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🛠️ Refactor suggestion

UserRole lacks relation toUser

userId is declared but no@relation or@@index([userId]) is present.
Withrequire-field-index set toforAllRelations: true this will fail linting once a relation is added. Recommend:

 model UserRole {   id         String @id-  userId     String @map(name: "userid")+  userId     String @map(name: "userid")+  user       User   @relation(fields: [userId], references: [id])++  @@index([userId]) }
📝 Committable suggestion

‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
modelUserRole {
id String@id
userId String@map(name:"userid")
// No mapping.
}
modelUserRole {
id String@id
userId String@map(name:"userid")
user User@relation(fields:[userId],references:[id])
@@index([userId])
}
🤖 Prompt for AI Agents
In example.prisma around lines 31 to 35, the UserRole model defines a userIdfield without a relation or index. To fix this, add a proper @relation attributelinking userId to the User model's id field and include an @@index on userId tosatisfy the require-field-index linting rule. This ensures the relation isexplicit and indexed for performance and linting compliance.


[8]ページ先頭

©2009-2025 Movatter.jp