Skip to content

Prismalint Showcase #29

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Prismalint Showcase #29

wants to merge 2 commits into from

Conversation

nimratcoderabbit
Copy link

@nimratcoderabbit nimratcoderabbit commented Jul 15, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a Prisma schema defining user, tenant, and user role models with customized table and column mappings.
    • Added configuration for Prisma client generation and PostgreSQL datasource.
    • Implemented linting rules to enforce consistent naming conventions, field ordering, and indexing requirements in Prisma schema files.

Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

A new Prisma schema file and a Prisma linter configuration file have been added. The schema defines four models with various fields, relationships, and database mappings. The linter configuration enforces naming conventions, field ordering, and index requirements for Prisma models and fields.

Changes

File(s) Change Summary
.prismalintrc.json Added configuration file specifying Prisma linting rules for naming, field order, required/ignored fields, and indexes.
example.prisma Added Prisma schema with four models, generator and datasource blocks, field mappings, and model relationships.

Poem

In the garden of schemas, a new seed is sown,
With linter rules guiding how models are grown.
Snake_case and order, relations in line,
Four models now sparkle, their mappings divine.
With every new field, the database hops—
A rabbit’s delight as the project grows nonstop! 🐇

Impact Analysis

Introduction of new Prisma schema and client generation configuration

📢 Medium 🔗 Impacts API 🔄 Impacts behavior

A new Prisma schema is introduced, defining four database models and configuring Prisma Client generation for JavaScript. This enables users to interact with new database tables and fields, and to generate a Prisma Client for application development. The schema establishes model structures, field mappings, and relationships, directly impacting how developers define, query, and manage data in the application.

Test Prisma Client generation and validate that all defined models and relations are accessible and function as expected. Verify CRUD operations for each model, check field mappings, and ensure that ignored fields and relations behave correctly. Confirm that the database schema matches the intended design.

🔍 Related Files
  • example.prisma

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • 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 our support 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 to generate 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot 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)

3-8: Consider consolidating compoundWords exceptions across rules

"S3" is exempted for field names but not for model names, while "GraphQL" is exempted for model names but not for field names. Unless you have a strong reason for this asymmetry, keep the allow-list identical across the two snake-case rules to avoid surprising false positives.


28-34: forAllRelations already implies every field – redundant filter

When forAllRelations is true, the engine will run the rule for every relation field regardless of its name. Keeping forNames: ["tenantId"] is therefore redundant (and mildly confusing). Either drop forAllRelations or drop forNames to make the intent crystal-clear.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ef04b8d and 9f05031.

📒 Files selected for processing (2)
  • .prismalintrc.json (1 hunks)
  • example.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
example.py

1-1: SyntaxError: Simple statements must be separated by newlines or semicolons


1-1: SyntaxError: Simple statements must be separated by newlines or semicolons


2-2: SyntaxError: Expected an expression or a '}'


3-3: SyntaxError: Expected ',', found name


3-3: SyntaxError: Expected ',', found '='


6-6: SyntaxError: Simple statements must be separated by newlines or semicolons


6-6: SyntaxError: Simple statements must be separated by newlines or semicolons


7-7: SyntaxError: Expected an expression or a '}'


8-8: SyntaxError: Expected ',', found name


8-8: SyntaxError: Expected ',', found '='


11-11: SyntaxError: Simple statements must be separated by newlines or semicolons


11-11: SyntaxError: Simple statements must be separated by newlines or semicolons


12-12: SyntaxError: Expected ',', found name


13-13: SyntaxError: Expected ',', found name


13-13: SyntaxError: Expected ',', found name


14-14: SyntaxError: Expected ',', found name


14-14: SyntaxError: Expected ',', found name


15-15: SyntaxError: Expected ',', found name


15-15: SyntaxError: Expected ',', found name


16-16: SyntaxError: Expected ',', found name


16-16: SyntaxError: Expected ',', found name


16-16: SyntaxError: Expected ',', found ':'


16-16: SyntaxError: Expected ',', found ':'


17-17: SyntaxError: Expected an expression


17-17: SyntaxError: Expected ',', found ':'


20-20: SyntaxError: Simple statements must be separated by newlines or semicolons


20-20: SyntaxError: Simple statements must be separated by newlines or semicolons


21-21: SyntaxError: Expected ',', found name


22-22: SyntaxError: Expected ',', found name


22-22: SyntaxError: Expected ',', found name


23-23: SyntaxError: Expected an expression


23-23: SyntaxError: Expected ',', found ':'


26-26: SyntaxError: Simple statements must be separated by newlines or semicolons


26-26: SyntaxError: Simple statements must be separated by newlines or semicolons


27-27: SyntaxError: Expected ',', found name


28-28: SyntaxError: Expected an expression


28-28: SyntaxError: Expected ',', found ':'


31-31: SyntaxError: Simple statements must be separated by newlines or semicolons


31-31: SyntaxError: Simple statements must be separated by newlines or semicolons


32-32: SyntaxError: Expected ',', found name


33-33: SyntaxError: Expected ',', found name


33-33: SyntaxError: Expected ',', found name


33-33: SyntaxError: Expected ',', found ':'


34-34: SyntaxError: Expected ',', found name


35-35: SyntaxError: Expected an identifier

example.py Outdated
Comment on lines 1 to 4
generator client {
provider = "prisma-client-js"
output = "../generated/prisma/client"
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Wrong file extension – Prisma schema should use .prisma

The file is a Prisma schema but is saved with a .py extension.
Tools (formatter, IDE plugins, CI linters) will fail to recognise it and the Ruff errors shown in the pipeline stem from this mismatch.

Rename the file to example.prisma (or any *.prisma) so that Prisma-aware tooling kicks in.

🧰 Tools
🪛 Ruff (0.12.2)

1-1: SyntaxError: Simple statements must be separated by newlines or semicolons


1-1: SyntaxError: Simple statements must be separated by newlines or semicolons


2-2: SyntaxError: Expected an expression or a '}'


3-3: SyntaxError: Expected ',', found name


3-3: SyntaxError: Expected ',', found '='

🤖 Prompt for AI Agents
In example.py lines 1 to 4, the file contains a Prisma schema but has a .py
extension, causing tooling and linters to fail. Rename the file from example.py
to example.prisma to ensure Prisma-aware tools and formatters recognize and
process it correctly.

example.py Outdated
Comment on lines 26 to 29
model UserRoleFoo {
id String @id
@@map(name: "unexpected_snake_case")
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

UserRoleFoo looks like a placeholder

The trailing Foo suggests this model is temporary or experimental.
If it is intentional, document its purpose; if not, drop or rename it before the linter forces a rename anyway (singular, meaningful name + snake-case mapping).

🧰 Tools
🪛 Ruff (0.12.2)

26-26: SyntaxError: Simple statements must be separated by newlines or semicolons


26-26: SyntaxError: Simple statements must be separated by newlines or semicolons


27-27: SyntaxError: Expected ',', found name


28-28: SyntaxError: Expected an expression


28-28: SyntaxError: Expected ',', found ':'

🤖 Prompt for AI Agents
In example.py around lines 26 to 29, the model name `UserRoleFoo` appears to be
a placeholder due to the trailing `Foo`. Rename the model to a meaningful,
singular name that reflects its purpose, and update the @@map attribute to use a
snake_case table name matching the new model name. If the model is intentional
but temporary, add a comment explaining its purpose to avoid confusion.

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

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

userId mapping is not snake_case

userId String @map(name: "userid") fails the field-name-mapping-snake-case rule.
Rename the column to user_id (or add "userid" to the compoundWords allow-list) to stay compliant:

-userId     String @map(name: "userid")
+userId     String @map(name: "user_id")
📝 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
model UserRole {
id String @id
userId String @map(name: "userid")
// No mapping.
}
model UserRole {
id String @id
userId String @map(name: "user_id")
// No mapping.
}
🧰 Tools
🪛 Ruff (0.12.2)

31-31: SyntaxError: Simple statements must be separated by newlines or semicolons


31-31: SyntaxError: Simple statements must be separated by newlines or semicolons


32-32: SyntaxError: Expected ',', found name


33-33: SyntaxError: Expected ',', found name


33-33: SyntaxError: Expected ',', found name


33-33: SyntaxError: Expected ',', found ':'


34-34: SyntaxError: Expected ',', found name


35-35: SyntaxError: Expected an identifier

🤖 Prompt for AI Agents
In example.py around lines 31 to 35, the userId field mapping uses "userid"
which is not in snake_case and violates the field-name-mapping-snake-case rule.
To fix this, rename the mapped column from "userid" to "user_id" to comply with
snake_case naming conventions, or alternatively add "userid" to the
compoundWords allow-list if that naming must be preserved.

example.py Outdated
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")
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Multiple lint violations in Users model

  1. Model name Users is plural – violates model-name-grammatical-number: singular.
  2. tenantId is not the first field – violates field-order.
  3. tenantId lacks an @index – violates require-field-index.
  4. removeMe is required and @ignored – violates forbid-required-ignored-field.

A minimal compliant refactor would look like:

-model Users {
+model User {
+  tenantId     String   @index
   id           String   @id
   emailAddress String
-  tenantId     String
-  removeMe     String @ignore
+  removeMe     String?  @ignore // optional or delete field
   tenant       Tenant   @relation(fields: [tenantId], references: [id])
   @@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
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 @index
id String @id
emailAddress String
removeMe String? @ignore // optional or delete field
tenant Tenant @relation(fields: [tenantId], references: [id])
@@map(name: "users")
}
🧰 Tools
🪛 Ruff (0.12.2)

11-11: SyntaxError: Simple statements must be separated by newlines or semicolons


11-11: SyntaxError: Simple statements must be separated by newlines or semicolons


12-12: SyntaxError: Expected ',', found name


13-13: SyntaxError: Expected ',', found name


13-13: SyntaxError: Expected ',', found name


14-14: SyntaxError: Expected ',', found name


14-14: SyntaxError: Expected ',', found name


15-15: SyntaxError: Expected ',', found name


15-15: SyntaxError: Expected ',', found name


16-16: SyntaxError: Expected ',', found name


16-16: SyntaxError: Expected ',', found name


16-16: SyntaxError: Expected ',', found ':'


16-16: SyntaxError: Expected ',', found ':'


17-17: SyntaxError: Expected an expression


17-17: SyntaxError: Expected ',', found ':'

🤖 Prompt for AI Agents
In example.py around lines 11 to 18, the Users model has multiple lint issues:
the model name should be singular, tenantId must be the first field, tenantId
needs an @index attribute, and removeMe cannot be both required and ignored.
Rename the model to User, move tenantId to be the first field, add @index to
tenantId, and either remove the removeMe field or make it optional if it must be
ignored.

Copy link

@coderabbitai coderabbitai bot 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: 3

🧹 Nitpick comments (2)
example.prisma (2)

20-24: Minor: add defaults & uniqueness on Tenant

Consider @default(uuid()) for id and @unique on name to prevent duplicates.

-model Tenant {
-  id         String @id
-  name       String
-  @@map(name: "tenant")
-}
+model Tenant {
+  id   String @id @default(uuid())
+  name String @unique
+
+  @@map(name: "tenant")
+}

26-29: Demo model UserRoleFoo breaks naming rules

The mixed-case model mapped to unexpected_snake_case looks intentional for a lint showcase, but in production code this would be rejected by the configured rules. Either delete it or rename to a compliant model name.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9f05031 and 561dc6c.

📒 Files selected for processing (1)
  • example.prisma (1 hunks)

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

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Database URL must come from environment variable

Hard-coding a placeholder string will break migrations & deployments. Prisma recommends env("DATABASE_URL") to pick up per-environment credentials.

-datasource db {
-  provider = "postgresql"
-  url      = "fake-url"
-}
+datasource db {
+  provider = "postgresql"
+  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
datasource db {
provider = "postgresql"
url = "fake-url"
}
datasource db {
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 a
placeholder string, which will cause issues with migrations and deployments.
Replace the hard-coded URL with an environment variable reference by using
env("DATABASE_URL") to ensure the database URL is dynamically loaded from the
environment configuration.

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")
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Users model violates several lint & modelling best-practices

• Model name is plural – linter rule expects singular.
id lacks a default; every insert must supply it manually.
emailAddress probably needs @unique.
tenantId should be indexed for FK look-ups.
removeMe is both required and @ignore, which the linter flags; simply remove it.

-model Users {
-  id           String @id
-  emailAddress String
-  tenantId     String
-  removeMe     String @ignore
-  tenant       Tenant @relation(fields: [tenantId], references: [id])
-  @@map(name: "users")
-}
+model User {
+  id           String @id @default(uuid())
+  emailAddress String @unique
+  tenantId     String
+  tenant       Tenant @relation(fields: [tenantId], references: [id])
+
+  @@map(name: "users")
+  @@index([tenantId])
+}

Note: Renaming the model is a breaking change; plan a migration accordingly.

🤖 Prompt for AI Agents
In example.prisma around lines 11 to 18, the Users model should be renamed to
singular form to follow naming conventions, add a default value to the id field
(e.g., use @default(uuid()) for automatic ID generation), add @unique to
emailAddress to enforce uniqueness, add an index to tenantId for efficient
foreign key lookups, and remove the removeMe field entirely since it is both
required and ignored, which is invalid. Plan a migration to handle the model
renaming as it is a breaking change.

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

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

UserRole missing relation & table mapping

userId is scalar-only; without a relation you lose referential integrity. Also, table name is implicit – add @@map for consistency.

 model UserRole {
   id         String @id
-  userId     String @map(name: "userid")
-  // No mapping.
+  userId     String @map(name: "userid")
+  user       User  @relation(fields: [userId], references: [id])
+
+  @@map(name: "user_role")
+  @@index([userId])
 }
🤖 Prompt for AI Agents
In example.prisma around lines 31 to 35, the UserRole model's userId field lacks
a relation definition, which means referential integrity is not enforced. Add a
relation attribute to userId linking it to the User model's id field. Also, add
an @@map attribute at the model level to explicitly specify the database table
name for consistency and clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants