loop-payments/prisma-lint

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

Closed this issue · 5 comments

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

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:

function isAssociation(fieldType: any) {
if (typeof fieldType != 'string') {
return false;
}
if (PRISMA_SCALAR_TYPES.has(fieldType)) {
return false;
}
return true;
}

maxh commented

Started: #365

maxh commented

#365 is code complete

maxh commented

@daeteck please try 0.4.0

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