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

Conversation

alexcoderabbitai
Copy link

@alexcoderabbitaialexcoderabbitai commentedJul 15, 2025
edited
Loading

image

Summary by CodeRabbit

  • New Features
    • Introduced linting rules for Prisma schema files to enforce consistent naming, field ordering, and indexing conventions.
    • Added a sample Prisma schema with models for users, tenants, and user roles, demonstrating various naming and mapping scenarios.

@coderabbitaicoderabbitai
Copy link

coderabbitaibot commentedJul 15, 2025
edited
Loading

Walkthrough

A new Prisma schema file and a Prisma linter configuration file are introduced. The schema defines four models with specific fields, relations, and database mappings, while the linter configuration enforces naming, ordering, and indexing conventions for Prisma models and fields. No existing code entities are modified.

Changes

File(s)Change Summary
.prismalintrc.jsonAdded Prisma linter configuration enforcing naming, ordering, and indexing rules for schema files.
example.prismaAdded Prisma schema defining four models, a PostgreSQL datasource, and a client generator with field and table mappings.

Poem

In fields and models, rules now reign,
With snake_case names and order plain.
Tenants come first, as linting decrees,
Indices on fields, all done with ease.
Prisma’s garden grows neat and bright—
A bunny’s delight in schema’s light! 🐇

Impact Analysis

Introduction of strict Prisma schema linting rules

📢 Medium 🔄 Impacts behavior

A new.prismalintrc.json file enforces strict linting rules for Prisma schema files, including naming conventions, field ordering, required indexing, and grammatical number for model names. Developers working with Prisma schemas will now encounter errors or warnings if their schema files do not comply with these conventions, potentially requiring changes to existing or future schema files to pass linting.

Test schema files with both compliant and non-compliant patterns to verify that linting errors are triggered as expected. Validate that exceptions (e.g., "S3" and "GraphQL") are handled correctly and that the developer experience remains smooth.

🔍 Related Files
  • .prismalintrc.json

Addition of new Prisma schema models and database mappings

📢 Medium 🔄 Impacts behavior

A new Prisma schema introduces four models (Users,Tenant,UserRoleFoo, andUserRole) with specific field definitions, relations, and database table mappings. This enables new data structures and relationships for applications using this schema, allowing developers to generate a Prisma client for interacting with these models in a PostgreSQL database.

Generate the Prisma client and test CRUD operations for each model. Verify that relations, field mappings, and ignored fields behave as expected, and that the generated client interacts correctly with the underlying database.

🔍 Related Files
  • example.prisma

🪧 Tips

Chat

There are 3 ways to chat withCodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag@coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag@coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on oursupport page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings togenerate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add@coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add@coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add@coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit ourDocumentation for detailed information on how to use CodeRabbit.
  • Join ourDiscord Community to get help, request features, and share feedback.
  • Follow us onX/Twitter for updates and announcements.

Copy link

@coderabbitaicoderabbitaibot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (2)
.prismalintrc.json (2)

28-34:Consider extending the index rule to cover composite tenant scopes

require-field-index currently safeguards one-columntenantId look-ups.
If your multi-tenant tables frequently use composite PKs/UKs that also includetenantId, add
"coverComposite": true (supported since prismalint 0.8) so the rule also flags@@id([id, tenantId]) without a matching secondary index.


35-36:Missing terminal newline

Posix tools expect a trailing newline; most editors warn when it’s absent.
Add one to avoid diff churn.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and betweenef04b8d and561dc6c.

📒 Files selected for processing (2)
  • .prismalintrc.json (1 hunks)
  • example.prisma (1 hunks)
🔇 Additional comments (2)
.prismalintrc.json (1)

3-8:Confirm rule key spelling matches prismalint’s spec

If the project is using@prisma/lint-pkg v0.6+ the option key iscompoundWords, but earlier releases expectcompoundWord. A typo silently disables the whitelist. Double-check the linter version so"compoundWords" is actually respected.

example.prisma (1)

26-29:Model name mapping suggests accidental snake_case in DB

UserRoleFoo maps tounexpected_snake_case, which is already snake_case.
If the intention is to diverge from the default mapping to satisfy an existing table, that’s fine.
If not, you can delete@@map and let Prisma generateuser_role_foo.

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.

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

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.

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

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.

Comment on lines +11 to +18
model Users {
id String @id
emailAddress String
tenantId String
removeMe String @ignore
tenant Tenant @relation(fields: [tenantId], references: [id])
@@map(name: "users")
}

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.

@alexcoderabbitai
Copy link
Author

@coderabbitai full review

coderabbitai[bot] reacted with eyes emoji

@coderabbitaicoderabbitai
Copy link

✅ Actions performed

Full review triggered.

@alexcoderabbitai
Copy link
Author

@coderabbitai full review

coderabbitai[bot] reacted with eyes emoji

@coderabbitaicoderabbitai
Copy link

✅ Actions performed

Full review triggered.

@alexcoderabbitai
Copy link
Author

@coderabbitai full review

coderabbitai[bot] reacted with eyes emoji

@coderabbitaicoderabbitai
Copy link

✅ Actions performed

Full review triggered.

Copy link

@coderabbitaicoderabbitaibot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (3)
example.prisma (3)

11-18:Users model violates four enabled lint rules
Duplicate of an existing bot comment – still unresolved.

  1. Model name should be singular.
  2. tenantId must be the first field.
  3. Required +@ignore fieldremoveMe is forbidden.
  4. Missing@@index([tenantId]).

Minimal compliant 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 @map(name: "email_address")+  tenant       Tenant @relation(fields: [tenantId], references: [id])++  @@index([tenantId])+  @@map(name: "users")+}

31-35:Add relation, index, and snake-case mapping forUserRole
Earlier bot hint still applies.

 model UserRole {   id         String @id-  userId     String @map(name: "userid")-  // No mapping.+  userId     String @map(name: "user_id")+  user       User   @relation(fields: [userId], references: [id])++  @@index([userId])+  @@map(name: "user_role") }

6-9:Datasource URL must be externalised

Hard-coding"fake-url" breaks local overrides and CI/CD secrets injection. Switch to an env var to stay 12-factor compliant.

 datasource db {   provider = "postgresql"-  url      = "fake-url"+  url      = env("DATABASE_URL") }
🧹 Nitpick comments (1)
.prismalintrc.json (1)

1-35:Consider documenting the rationale behind rule exceptions

compoundWords arrays (["S3"],["GraphQL"]) are self-explanatory to us today, but future contributors won’t know why just those tokens are exempt from snake-case. Because JSON doesn’t allow comments, add a short section inCONTRIBUTING.md (or aPRISMA_LINT_RULES.md) that explains each exception and how to request new ones.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and betweenef04b8d andba7b209.

⛔ Files ignored due to path filters (1)
  • .coderabbit.yaml is excluded by none and included by none
📒 Files selected for processing (2)
  • .prismalintrc.json (1 hunks)
  • example.prisma (1 hunks)
🧰 Additional context used
🪛 PrismaLint (0.10.2)
example.prisma

31-31: Model name must be mapped to snake case. (model-name-mapping-snake-case)


33-33: Field name must be mapped to "user_id". (field-name-mapping-snake-case)


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


11-11: Fields are not in the expected order: "tenantId", "...". (field-order)


11-11: Expected singular model name. (model-name-grammatical-number)


13-13: Field name must be mapped to snake case. (field-name-mapping-snake-case)


15-15: Field name must be mapped to snake case. (field-name-mapping-snake-case)


15-15: Do not ignore a required field without a default value. (forbid-required-ignored-field)


14-14: Field name must be mapped to snake case. (field-name-mapping-snake-case)


14-14: Field "tenantId" must have an index. (require-field-index)

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

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@alexcoderabbitai@nimratcoderabbit

[8]ページ先頭

©2009-2025 Movatter.jp