|
| 1 | +--- |
| 2 | +title: Prisma Lint |
| 3 | +sidebar_label: Prisma Lint |
| 4 | +description: CodeRabbit's guide to Prisma Lint. |
| 5 | +--- |
| 6 | + |
| 7 | +```mdx-code-block |
| 8 | +import ProPlanNotice from '@site/src/components/ProPlanNotice.mdx'; |
| 9 | +
|
| 10 | +<ProPlanNotice /> |
| 11 | +``` |
| 12 | + |
| 13 | +[Prisma Lint](https://github.com/loop-payments/prisma-lint) is a linter for Prisma schema files that helps enforce consistent conventions and best practices in your Prisma schemas. |
| 14 | + |
| 15 | +## Files |
| 16 | + |
| 17 | +Prisma Lint will run on files with the following extensions: |
| 18 | + |
| 19 | +- `.prisma` |
| 20 | + |
| 21 | +## Configuration |
| 22 | + |
| 23 | +Prisma Lint supports the following config files: |
| 24 | + |
| 25 | +- `.prismalintrc.json` |
| 26 | +- User-defined config file set at `reviews.tools.prismalint.config_file` in your project's `.coderabbit.yaml` file or setting the "Review → Tools → Prisma Lint → Config File" field in CodeRabbit's settings page. |
| 27 | + |
| 28 | +:::note |
| 29 | + |
| 30 | +By default, Prisma Lint looks for schema files at `prisma/schema.prisma`. If you have a custom schema path specified in the `prisma.schema` field within `package.json`, that will be used instead. |
| 31 | + |
| 32 | +::: |
| 33 | + |
| 34 | +## Rule Configuration |
| 35 | + |
| 36 | +Rules can be configured in your `.prismalintrc.json` file. Here's an example configuration: |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "rules": { |
| 41 | + "field-name-mapping-snake-case": [ |
| 42 | + "error", |
| 43 | + { |
| 44 | + "compoundWords": ["S3"] |
| 45 | + } |
| 46 | + ], |
| 47 | + "model-name-grammatical-number": [ |
| 48 | + "error", |
| 49 | + { |
| 50 | + "style": "singular" |
| 51 | + } |
| 52 | + ], |
| 53 | + "require-field-index": [ |
| 54 | + "error", |
| 55 | + { |
| 56 | + "forAllRelations": true, |
| 57 | + "forNames": ["tenantId"] |
| 58 | + } |
| 59 | + ] |
| 60 | + } |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +## Ignoring Rules |
| 65 | + |
| 66 | +You can ignore rules using three-slash (`///`) comments inside your Prisma models: |
| 67 | + |
| 68 | +```prisma |
| 69 | +model User { |
| 70 | + /// prisma-lint-ignore-model |
| 71 | + // Ignores all lint rules for this model |
| 72 | +} |
| 73 | +
|
| 74 | +model Post { |
| 75 | + /// prisma-lint-ignore-model require-field |
| 76 | + // Ignores specific rules for this model |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Links |
| 81 | + |
| 82 | +- [Prisma Lint GitHub Repository](https://github.com/loop-payments/prisma-lint) |
| 83 | +- [Prisma Lint Rules Documentation](https://github.com/loop-payments/prisma-lint/blob/main/RULES.md) |
0 commit comments