npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prisma-lint

v0.7.0

Published

A linter for Prisma schema files.

Downloads

78,826

Readme

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.