-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Prettier plugin for .prisma files #1761
Comments
This should definitely be part of the support for prettier. It's hard to follow the format if not using VSCode. |
Current possible alternatives:
import { formatSchema } from '@prisma/sdk'
const output = await formatSchema({ schemaPath: 'myschema.prisma' })
// or
const output = await formatSchema({ schema: 'schema file content as string' }) |
Those are round about ways of getting the job done, but I specifically want prettier support. Especially for CI and git hook integrations. Also for those of us that don't use VS Code. Basically the expectation of JS devs is that every file in a JS project should be formatted by prettier. |
Agreed, +1 for prettier plugins |
My current setup are these VS Code settings Default formatter set on null: The Prisma extension installed: Set Prettier for JavaScript / TypeScript {
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
} Alternative solution by @LeonardSSH {
"editor.formatOnSave": true,
"[prisma]": {
"editor.defaultFormatter": "Prisma.prisma"
},
} This makes Prettier and Prisma extension formatting work together nicely in VS Code |
I was surprised when found that no one built it, so I did it myself: https://github.com/umidbekkarimov/prettier-plugin-prisma
EDIT: Now uses |
@umidbekk thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
Currently looking for a way to use that in a |
I have schema code built by other tools i build and in this use case i want to have a function where i can provide generated code and get nice formatted schema to write to schema file. This worked fine, yet npm package is deprecated https://www.npmjs.com/package/@prisma/sdk
I tried @umidbekk plugin but it failed to do the job with error which seem like prettier is looking like prettier thinks it's javascript, while it's not. And i don't see any way to tell prettier that it's prisma schema. Any hints?
|
Use this in your settings.json "[prisma]": {
"editor.defaultFormatter": "Prisma.prisma"
}, |
Can you further explain the rationale behind using prettier here @flybayer? My understanding is that prisma format does linting and formatting while prettier only does formatting. So in CI/hooks, to get linting and formatting you would need to run What benefit does that get you over just running |
For those who would want to stay with
|
Since the prisma schema has defined file formatting guidelines, a prettier plugin should exist so we can format .prisma files using our CI system along with all our other files.
Currently there's a VS Code extension to do this, but tons of people including myself don't use VS Code. Additional, this extension can't be used with CI and git hooks.
From #1557
The text was updated successfully, but these errors were encountered: