loop-payments / prisma-lint

A linter for Prisma schema files.
https://www.npmjs.com/package/prisma-lint
MIT License
120 stars 4 forks source link

field-name-mapping-snake-case rule not working for field with custom types or enums #363

Closed daeteck closed 2 months ago

daeteck commented 3 months ago

When the field is a custom type in MongoDB or the field is a enum in for example Postgres the rule field-name-mapping-snake-case do not thrown any warning / error.

Example for enum (Postgres):

model Sale {
  id                    Int                                @id @default(autoincrement())
  saleChannel           SaleChannel                        

  @@map("sale")
}

enum SaleChannel {
  TERMINAL
  WEB
  MOBILE
}

In the example above, the field saleChannel should be mapped to @map("sale_channel") when the field-name-mapping-snake-case it's on, but the lint do not throws a warning or an error.

Example for custom types (MongoDB):

model Location {
  id                           String                            @id @default(uuid()) @map("_id")
  additionalInformation        LocationAdditionalInformation 

  @@map("location")
}

type LocationAdditionalInformation {
  institution       String? 
  printExtraBarCode Boolean? @map("print_extra_bar_code")
  taxMessage        String?  @map("tax_message")
}

In the example above, the field LocationAdditionalInformation should be mapped to @map("additional_information") when the field-name-mapping-snake-case it's on, but the lint do not throws a warning or an error.

maxh commented 3 months ago

Interesting. We don't use DB enums so haven't run into this. I'll try to take a look this weekend.

We need to update this function: https://github.com/loop-payments/prisma-lint/blob/4da8cb674be2a87080ba684bf8cbd3a092473a54/src/rules/field-name-mapping-snake-case.ts#L135-L143

maxh commented 3 months ago

Started: https://github.com/loop-payments/prisma-lint/pull/365

maxh commented 2 months ago

https://github.com/loop-payments/prisma-lint/pull/365 is code complete

maxh commented 2 months ago

@daeteck please try 0.4.0

daeteck commented 2 months ago

@maxh it works perfect! Thanks a lot for this fix and sorry for my late response.