prisma-lint
Advanced tools
Comparing version 0.0.25 to 0.0.26
@@ -54,9 +54,14 @@ import { z } from 'zod'; | ||
Field: (model, field) => { | ||
if (allowedToHaveNoMapping(field)) { | ||
if (isAssociation(field.fieldType)) { | ||
return; | ||
} | ||
// A helper function to report a problem with the field. | ||
const report = (message) => context.report({ model, field, message }); | ||
const { attributes } = field; | ||
const { name, attributes } = field; | ||
const expectedSnakeCase = toSnakeCase(name, { compoundWords }); | ||
const isMappingRequired = !isAllLowerCase(name); | ||
if (!attributes) { | ||
report('Field name must be mapped to snake case.'); | ||
if (isMappingRequired) { | ||
report('Field name must be mapped to snake case.'); | ||
} | ||
return; | ||
@@ -66,3 +71,5 @@ } | ||
if (!mapAttribute || !mapAttribute.args) { | ||
report('Field name must be mapped to snake case.'); | ||
if (isMappingRequired) { | ||
report('Field name must be mapped to snake case.'); | ||
} | ||
return; | ||
@@ -72,9 +79,7 @@ } | ||
if (!mappedName) { | ||
report('Field name must be mapped to snake case.'); | ||
if (isMappingRequired) { | ||
report('Field name must be mapped to snake case.'); | ||
} | ||
return; | ||
} | ||
const fieldName = field.name; | ||
const expectedSnakeCase = toSnakeCase(fieldName, { | ||
compoundWords, | ||
}); | ||
if (mappedName !== expectedSnakeCase) { | ||
@@ -97,5 +102,2 @@ report(`Field name must be mapped to "${expectedSnakeCase}".`); | ||
} | ||
export function allowedToHaveNoMapping(field) { | ||
return isAllLowerCase(field.name) || isAssociation(field.fieldType); | ||
} | ||
function isAssociation(fieldType) { | ||
@@ -102,0 +104,0 @@ if (typeof fieldType != 'string') { |
import { z } from 'zod'; | ||
const RULE_NAME = 'forbid-required-ignored-field'; | ||
const Config = z.object({}).strict(); | ||
const Config = z.object({}).strict().optional(); | ||
/** | ||
@@ -21,9 +21,2 @@ * Forbids required ignored fields without default values. | ||
* | ||
* // bad | ||
* type Product { | ||
* uuid String | ||
* toBeRemoved String @ignore | ||
* } | ||
* | ||
* @example | ||
* // good | ||
@@ -38,3 +31,3 @@ * type Product { | ||
* uuid String | ||
* toBeRemoved Boolean @ignore | ||
* toBeRemoved String @ignore | ||
* } | ||
@@ -41,0 +34,0 @@ */ |
{ | ||
"name": "prisma-lint", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"description": "A linter for Prisma schema files.", | ||
@@ -61,3 +61,3 @@ "repository": { | ||
"lint-staged": "^15.0.1", | ||
"prettier": "3.1.0", | ||
"prettier": "3.1.1", | ||
"ts-jest": "^29.1.0", | ||
@@ -64,0 +64,0 @@ "typescript": "^5.0.4" |
58870
1618