avocadowastaken/prettier-plugin-prisma

Feat: Flat Formatting

Closed this issue · 1 comments

How it currently works

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.

Proposed Solution

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.

Hey @moishinetzer 👋

Thanks for sharing your idea, but this library is built on top of official prisma-fmt-wasm, and all new features are developed there: https://github.com/prisma/prisma-engines/issues?page=2&q=fmt