包详细信息

prisma-lint

loop-payments73.2kMIT0.10.2

A linter for Prisma schema files.

自述文件

prisma-lint

A linter for Prisma schema files.

Installation

> npm install --save-dev prisma-lint
# or
> yarn add --dev prisma-lint

Usage

> npx prisma-lint
# or
> yarn prisma-lint

The default schema path is prisma/schema.prisma. If a custom schema path is specified in the field prisma.schema within package.json, that is used instead.

Alternatively, you can provide one or more explicit paths as CLI arguments. These can be globs, directories, or file paths.

Run yarn prisma-lint --help for all options.

Rules

The file RULES.md contains documentation for each rule. All rules are disabled by default. Create a configuration file to enable the rules you'd like to enforce.

Configuration

The configuration file format is loosely based on eslint's conventions. Here's an example .prismalintrc.json:

{
  "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"]
      }
    ]
  }
}

See Loop's configuration for a more thorough example. Configuration files are loaded with cosmiconfig.

Ignore comments

Rules can be ignored with three-slash (///) comments inside models.

To ignore all lint rules for a model and its fields:

model User {
  /// prisma-lint-ignore-model
}

To ignore specific lint rules for a model and its fields:

model User {
  /// prisma-lint-ignore-model require-field
  /// prisma-lint-ignore-model require-field-type
}

Some rules support parameterized ignore comments like this:

model User {
  /// prisma-lint-ignore-model require-field revisionNumber,revisionCreatedAt
}

Omitting revisionNumber and revisionCreatedAt fields from this model will not result in a violation. Other required fields remain required.

Output

There are a few output options.

Simple (default)

> yarn prisma-lint -o simple
example/invalid.prisma ✖
  Users 11:1
    error Expected singular model name. model-name-grammatical-number
    error Missing required fields: "createdAt". require-field
  Users.emailAddress 13:3
    error Field name must be mapped to snake case. field-name-mapping-snake-case
example/valid.prisma ✔

Contextual

> yarn prisma-lint -o contextual
example/invalid.prisma:11:1 Users
model Users {
^^^^^^^^^^^
  error Expected singular model name. model-name-grammatical-number
  error Missing required fields: "createdAt". require-field

example/invalid.prisma:13:3 Users.emailAddress
  emailAddress String
  ^^^^^^^^^^^^
  error Field name must be mapped to snake case. field-name-mapping-snake-case

Filepath

> yarn prisma-lint -o filepath
example/invalid.prisma ✖
example/valid.prisma ✔

None

> yarn prisma-lint -o none

No output, for when you just want to use the status code.

JSON

> yarn prisma-lint -o json

Outputs a serialized JSON object with list of violations. Useful for editor plugins.

Contributing

Pull requests are welcome. Please see DEVELOPMENT.md.

更新日志

Changelog

Unreleased

0.10.2 (2025-05-24)

  • #683 Stop requiring defaults for @ignored relation fields.

0.10.1 (2025-04-30)

  • #622 Require case-sensitive compound word match for snake case conversion. Fixes bug introduced in 0.10.0.

0.10.0 (2025-03-25)

  • Add support for case: 'upper' option in enum-value-snake-case rule.
  • Improve handling of compoundWords for snake case rules.

0.9.0 (2025-03-19)

  • #611 Add nativeType option to require-field-type rule to additionally enforce native DB types if needed.
  • Update dependencies, including commander to 13.1.0.

0.8.0 (2025-01-17)

  • Add new rule field-name-grammatical-number.

0.7.0 (2024-10-17)

  • Add support for parsing Prisma schema directory names and globs specified in package.json.

0.6.0 (2024-08-16)

  • Add new rules enum-name-pascal-case and enum-value-snake-case.
  • Add new rule ban-unbounded-string-type.
  • Add new rules model-name-pascal-case and field-name-camel-case.

Thanks to @andyjy for these new rules!

0.5.0 (2024-05-01)

  • #388 Teach field-name-mapping-snake-case ignore comments about individual fields.

0.4.0 (2024-04-23)

  • #363 Require enum and custom type fields to use snake case in field-name-mapping-snake-case.

0.3.0 (2024-04-03)

  • #330 Remove requirePrefix option and add requireUnderscorePrefixForIds to field-name-mapping-snake-case to actually support MongoDB naming conventions.

0.2.0 (2024-03-29)

  • #354 Add allowlist to model-name-grammatical-number.

0.1.3 (2024-03-23)

  • Upgrade @mrleebo/prisma-ast to get new version that supports mapped enums.

0.1.2 (2024-03-13)

  • Add require-prefix option to field-name-mapping-snake-case to support MongoDB naming conventions.

0.1.1 (2024-03-09)

  • Upgrade dependencies.

0.1.0 (2024-01-06)

  • #275 Add new rule require-default-empty-arrays.

0.0.26 (2023-12-30)

  • Show violation for incorrect mapping of single-word field name.

0.0.25 (2023-11-25)

  • Avoid empty line in simple output format.

0.0.24 (2023-11-24)

  • Add new -o, --output option which accepts simple (the default), none, contextual, filepath, and json.

0.0.23 (2023-11-15)

  • Allow ignoring required fields with default values in forbid-required-ignored-field.

0.0.22 (2023-11-10)

  • Add option to pluralize snake case model names.

0.0.20 (2023-08-22)

  • Add support for reading prisma schema configuration from package.json.

0.0.19 (2023-08-04)

0.0.18 (2023-06-06)

  • #59 Add support for @map and @@map without keys.
  • #56 Clearer error message when configuration not found.

0.0.17 (2023-06-01)

  • Show clearer error if "rules" is missing from config.
  • Allow ignore parameters for the forbid-field rule.

0.0.16 (2023-05-31)

  • Minor tweaks to rules documentation.

0.0.15 (2023-05-30)

  • Add Loop example configuration.
  • Add comment to README about rules being disabled by default.
  • Improve error output for invalid and missing configuration files.

0.0.12 (2023-05-30)

  • Fix behavior when no CLI arg is provided.

0.0.11 (2023-05-30)

  • Add support for terminal colors and --no-color CLI option.

0.0.10 (2023-05-30)

  • Support automatic releases on version changes.

0.0.4 (2023-05-30)

  • Add CHANGELOG.

0.0.3 (2023-05-29)

  • Add full implementation of first version.

0.0.2 (2023-05-23)

  • Fix release contents.

0.0.1 (2023-05-23)

  • Add initial skeleton code.