prisma-lint
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -19,2 +19,3 @@ import pluralize from 'pluralize'; | ||
const snakeCaseWithCompoundWords = compountWordsAsSnakeCase.reduce((acc, compoundWord) => acc.replace(compoundWord, compoundWord.replace(/_/g, '')), snakeCase); | ||
let result = snakeCaseWithCompoundWords; | ||
if (options.pluralize) { | ||
@@ -26,5 +27,8 @@ if (options.irregularPlurals) { | ||
} | ||
return pluralize(snakeCaseWithCompoundWords); | ||
result = pluralize(snakeCaseWithCompoundWords); | ||
} | ||
return snakeCaseWithCompoundWords; | ||
if (options.requirePrefix) { | ||
result = `${options.requirePrefix}${snakeCaseWithCompoundWords}`; | ||
} | ||
return result; | ||
} |
@@ -8,2 +8,3 @@ import { z } from 'zod'; | ||
compoundWords: z.array(z.string()).optional(), | ||
requirePrefix: z.string().optional(), | ||
}) | ||
@@ -47,2 +48,13 @@ .strict() | ||
* | ||
* @example { requirePrefix: ["_"] } | ||
* // good | ||
* model PersistedQuery { | ||
* fooId String @map(name: "_foo_id") | ||
* } | ||
* | ||
* // bad | ||
* model PersistedQuery { | ||
* fooId String @map(name: "foo_id") | ||
* } | ||
* | ||
*/ | ||
@@ -53,3 +65,3 @@ export default { | ||
create: (config, context) => { | ||
const compoundWords = config?.compoundWords; | ||
const { compoundWords, requirePrefix } = config ?? {}; | ||
return { | ||
@@ -63,3 +75,6 @@ Field: (model, field) => { | ||
const { name, attributes } = field; | ||
const expectedSnakeCase = toSnakeCase(name, { compoundWords }); | ||
const expectedSnakeCase = toSnakeCase(name, { | ||
compoundWords, | ||
requirePrefix, | ||
}); | ||
const isMappingRequired = !isAllLowerCase(name); | ||
@@ -66,0 +81,0 @@ if (!attributes) { |
{ | ||
"name": "prisma-lint", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A linter for Prisma schema files.", | ||
@@ -5,0 +5,0 @@ "repository": { |
61600
1719