prisma-lint
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -8,3 +8,3 @@ import { z } from 'zod'; | ||
compoundWords: z.array(z.string()).optional(), | ||
requirePrefix: z.string().optional(), | ||
requireUnderscorePrefixForIds: z.boolean().optional(), | ||
}) | ||
@@ -48,6 +48,7 @@ .strict() | ||
* | ||
* @example { requirePrefix: ["_"] } | ||
* @example { requireUnderscorePrefixForIds: true } | ||
* // good | ||
* model PersistedQuery { | ||
* fooId String @map(name: "_foo_id") | ||
* id String @id @map(name: "_id") | ||
* otherField String @map(name: "other_field") | ||
* } | ||
@@ -57,3 +58,4 @@ * | ||
* model PersistedQuery { | ||
* fooId String @map(name: "foo_id") | ||
* id String @id @map(name: "id") | ||
* otherField String @map(name: "other_field") | ||
* } | ||
@@ -66,3 +68,3 @@ * | ||
create: (config, context) => { | ||
const { compoundWords, requirePrefix } = config ?? {}; | ||
const { compoundWords, requireUnderscorePrefixForIds } = config ?? {}; | ||
return { | ||
@@ -75,8 +77,6 @@ Field: (model, field) => { | ||
const report = (message) => context.report({ model, field, message }); | ||
const { name, attributes } = field; | ||
const expectedSnakeCase = toSnakeCase(name, { | ||
compoundWords, | ||
requirePrefix, | ||
}); | ||
const isMappingRequired = !isAllLowerCase(name); | ||
const { attributes, name: fieldName } = field; | ||
const isIdWithRequiredPrefix = requireUnderscorePrefixForIds && | ||
attributes?.find((a) => a.name === 'id'); | ||
const isMappingRequired = !isAllLowerCase(fieldName) || isIdWithRequiredPrefix; | ||
if (!attributes) { | ||
@@ -102,2 +102,6 @@ if (isMappingRequired) { | ||
} | ||
let expectedSnakeCase = toSnakeCase(fieldName, { compoundWords }); | ||
if (isIdWithRequiredPrefix) { | ||
expectedSnakeCase = `_${expectedSnakeCase}`; | ||
} | ||
if (mappedName !== expectedSnakeCase) { | ||
@@ -104,0 +108,0 @@ report(`Field name must be mapped to "${expectedSnakeCase}".`); |
{ | ||
"name": "prisma-lint", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A linter for Prisma schema files.", | ||
@@ -5,0 +5,0 @@ "repository": { |
63326
1778