avocadowastaken / prettier-plugin-prisma Goto Github PK
View Code? Open in Web Editor NEWPrettier plugin for Prisma
License: MIT License
Prettier plugin for Prisma
License: MIT License
Describe the bug
Auto formatting is working but auto completion(like relation) is not working
Expected behavior
Tools (please provide the output of the following commands):
macOS, vscode, prettier-plugin-prisma v3.10, prisma v3.10
When working on a group project, adding another field to your Prisma schema, which is longer than all the other fields, will cause a significant merge conflict on the Prisma schema and make it hard to see exactly which fields have been changed and how to merge it properly.
Example:
model User {
id String @id @default(uuid()) @db.Uuid
email String? @db.Citext
name String? @db.Text
}
Following a new field 'address'
model User {
id String @id @default(uuid()) @db.Uuid
email String? @db.Citext
name String? @db.Text
address String? @db.Text
}
You can see that all of the field types have been shifted to the right, making the file resolve a significant merge conflict.
By enabling a flag in the config, perhaps a flatFormat
flag in the config, we can format it to a single space between field options.
Example:
Before format
model User {
id String @id @default(uuid()) @db.Uuid
email String? @db.Citext
name String? @db.Text
}
After format
model User {
id String @id @default(uuid()) @db.Uuid
email String? @db.Citext
name String? @db.Text
}
This helps with commits and changes to large models. This could also work in injunction with tabWidth to use the specified spacing but still not align them along the y-axis.
Is there a way to use this for code blocks inside larger documents like documentation?
For example:
```prisma
model Foo {
id Int @id
}
```
We would be pretty interested for https://www.prisma.io/docs/ honestly 😄
With the following .prettierrc.json configuration, I get proper tabs on all ts files, but not prisma, where I get 4 spaces instead.
{
"useTabs": true,
"tabWidth": 4,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120
}
Am I missing something?
Steps to reproduce the behavior:
prettier ./file.prisma
Expected behavior
Formatting would end up as tabs
Tools (please provide the output of the following commands):
When running npx prisma format schema.prisma
everything works great but running npx prettier schema.prisma
traps with the following messages, some referring to the wasm engine. I'm running this code in a MacBook Pro M1 with Big Sur 11.2.1.
#
# Fatal error in , line 0
# Check failed: allocator->SetPermissions(reinterpret_cast<void*>(region.begin()), region.size(), PageAllocator::kNoAccess).
#
#
#
#FailureMessage Object: 0x16f752918
1: 0x1007a5104 node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() [/opt/homebrew/bin/node]
2: 0x101130054 V8_Fatal(char const*, ...) [/opt/homebrew/bin/node]
3: 0x100d19358 v8::internal::wasm::WasmCodeAllocator::GetNumCodeSpaces() const [/opt/homebrew/bin/node]
4: 0x100d191f8 v8::internal::wasm::WasmCodeAllocator::FreeCode(v8::internal::Vector<v8::internal::wasm::WasmCode* const>) [/opt/homebrew/bin/node]
5: 0x100d1c048 v8::internal::wasm::NativeModule::FreeCode(v8::internal::Vector<v8::internal::wasm::WasmCode* const>) [/opt/homebrew/bin/node]
6: 0x100d29bcc v8::internal::wasm::WasmEngine::FreeDeadCodeLocked(std::__1::unordered_map<v8::internal::wasm::NativeModule*, std::__1::vector<v8::internal::wasm::WasmCode*, std::__1::allocator<v8::internal::wasm::WasmCode*> >, std::__1::hash<v8::internal::wasm::NativeModule*>, std::__1::equal_to<v8::internal::wasm::NativeModule*>, std::__1::allocator<std::__1::pair<v8::internal::wasm::NativeModule* const, std::__1::vector<v8::internal::wasm::WasmCode*, std::__1::allocator<v8::internal::wasm::WasmCode*> > > > > const&) [/opt/homebrew/bin/node]
7: 0x100d27bec v8::internal::wasm::WasmEngine::PotentiallyFinishCurrentGC() [/opt/homebrew/bin/node]
8: 0x100d28e28 v8::internal::wasm::WasmEngine::ReportLiveCodeForGC(v8::internal::Isolate*, v8::internal::Vector<v8::internal::wasm::WasmCode*>) [/opt/homebrew/bin/node]
9: 0x100d2b548 v8::internal::wasm::(anonymous namespace)::WasmGCForegroundTask::RunInternal() [/opt/homebrew/bin/node]
10: 0x1007a3bc0 node::PerIsolatePlatformData::RunForegroundTask(std::__1::unique_ptr<v8::Task, std::__1::default_delete<v8::Task> >) [/opt/homebrew/bin/node]
11: 0x1007a2cb4 node::PerIsolatePlatformData::FlushForegroundTasksInternal() [/opt/homebrew/bin/node]
12: 0x1007a3d7c node::NodePlatform::DrainTasks(v8::Isolate*) [/opt/homebrew/bin/node]
13: 0x1006b0aa4 node::SpinEventLoop(node::Environment*) [/opt/homebrew/bin/node]
14: 0x100781224 node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [/opt/homebrew/bin/node]
15: 0x100724ce4 node::Start(int, char**) [/opt/homebrew/bin/node]
16: 0x198afdf34 start [/usr/lib/system/libdyld.dylib]
[1] 2979 trace trap npx prettier schema.prisma
In Prisma v5 prisma-fmt
was renamed to prisma-schema
prisma/prisma#20045, so we need to update dependencies
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
@types/jest
, jest
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/main.yml
umidbekk/actions v2
umidbekk/actions v2
package.json
@prisma/prisma-schema-wasm 4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584
@types/jest 29.5.3
@umidbekk/configs 0.3.0
cross-env 7.0.3
husky 8.0.3
jest 29.6.1
lint-staged 13.2.3
prettier 3.0.0
prettier-plugin-packagejson 2.4.5
typescript 5.1.6
vscode-languageserver-protocol 3.17.3
prettier >=2 || >=3
node >=14
npm >=8
node 14.21.3
npm 8.19.4
Describe the bug
Prettier 3.0 has been released: https://prettier.io/blog/2023/07/05/3.0.0.html. It looks like that this plugin is no longer working with the new 3.0 version:
Checking formatting...
prisma/schema.prisma
[error] No parser could be inferred for file "/prisma/schema.prisma".
To Reproduce
Steps to reproduce the behavior:
Expected behavior
No error and schema is formatted
Describe the bug
This prettier plugin modifies our schema to add new reverse relationships.
To Reproduce
Table A adds a relationship on table B.
Expected behavior
Nothing.
Experienced behavior
Table B gets a relationship added back to Table A.
Additional context
I get that this is useful in some cases, but a prettier plugin shouldn't be making those decisions for us. Furthermore, the reverse relationship that gets added isn't consistent in terms of casing/style with our other ones.
In our case, we don't want that reverse relationship adding because we don't have indexes on it so it would be an inefficient query.
When I save the file in my editor (Vim & VS Code) prettier doesn't auto-format .prisma
files. It does auto-format .js
and .json
files though.
When I run npx prettier --write ./
manually - it formats .prisma
files correctly.
Can prettier-plugin-prisma
auto-format on save?
$ node --version
v16.13.2
$ npx os-name-cli
macOS Big Sur
$ npx npm-why prettier
Who required prettier:
serverless-functions > eslint-plugin-prettier > [email protected]
serverless-functions > [email protected]
serverless-functions > prettier-plugin-prisma > [email protected]
$ npx npm-why prettier-plugin-prisma
Who required prettier-plugin-prisma:
serverless-functions > [email protected]
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.
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?
const prettier = require("prettier");
let result = prettier.format(code, {
parser: "babel", plugins: ["prettier-plugin-prisma"]
});
also posted at prisma repo prisma/prisma#1761
Thank you for this plugin.
Is there a chance that you could support the @map
and @@map
instructions, as defined here in the Prisma documentation? Where my Prisma file contains @map
, the plugin reformats the file like this:
model users {
id Int @id @default(autoincrement()) @map("ID")
username String @unique(map: "username") @db.VarChar(25)
password String @db.VarChar(40)
allowSharing Boolean @default(true) @map("AccepterPartage")
}
where I would expect something like:
model users {
id Int @id @default(autoincrement()) @map("ID")
username String @unique(map: "username") @db.VarChar(25)
password String @db.VarChar(40)
allowSharing Boolean @default(true) @map("AccepterPartage")
}
Describe the bug
When using pnpm as the package manager, this message is shown:
npx prettier prisma\schema.prisma
Checking formatting...
prisma\schema.prisma[error] No parser could be inferred for file: prisma\schema.prisma
All matched files use Prettier code style!
Is this a problem with any prettier plugin with pnpm or is it specific to this plugin?
To Reproduce
use pnpm to add prettier and prettier-plugin-prisma to dependencies and run prettier on a prisma file
pnpm add -D prettier prettier-plugin-prisma
pnpx prettier -c prisma\schema.prisma
Expected behavior
Prettier should be able to automatically find this plugin and format a .prisma
file
Tools (please provide the output of the following commands):
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: Cannot find preset's package (:assignees(umidbekk)). Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.