Skip to content

jeremy-code/eslint-plugin-z

Repository files navigation

eslint-plugin-z

GitHub Actions License NPM version GitHub release

An ESLint plugin for linting Zod schemas.

Installation

npm install eslint-plugin-z --save-dev

Configuration

// eslint.config.mjs
import pluginZ from "eslint-plugin-z";

export default [pluginZ.configs.recommended];
// .eslintrc.json
{
  "extends": ["plugin:z/recommendedLegacy"]
}

Rules

  • 💼 Configurations enabled in
  • ⚠️ Configurations set to warn in
  • ✅ ️Set in the recommended configuration
  • 🔧 Automatically fixable by the --fix CLI option
Name Description 💼 ⚠️ 🔧
no-duplicate-enum-values Disallow duplicate enum member values 🔧
no-throw-in-refine Ban throwing in refinement function
no-undefined-argument-in-custom Disallow undefined argument in z.custom() 🔧
prefer-enum Enforce usage of z.enum() instead of z.union([z.literal(""),...]) ⚠️ 🔧
prefer-nonempty Enforce usage of z.string().array().nonempty() instead of z.string().array().min(1) or z.array().nonempty() instead of z.array().min(1) ⚠️ 🔧
prefer-nullish Enforce usage of z.nullish() instead of z.null().optional() or z.optional().null() ⚠️ 🔧
prefer-tuple Enforce usage of z.tuple([z.schema()]) instead of z.schema().array().length(1) ⚠️ 🔧

License

This project is licensed under the MIT license.