@eslint-zod/utils
v7.0.0
Published
Shared utilities for eslint-zod plugins
Maintainers
Readme
@eslint-zod/utils
Shared AST utilities for
eslint-plugin-zodeslint-plugin-zod-minieslint-plugin-zod-core
[!NOTE] This package is a dependency of all previously listed packages, so you do not need to install it directly.
API
Every export carries JSDoc with usage notes — refer to the linked source files (or hover in your editor) for the full description and examples. This README only lists what's available.
Root exports — @eslint-zod/utils
Only what the plugins import; every other helper is internal to this package.
createPluginMeta(packageJSONURL)— a plugin'sname,version,getRuleURLandcreateRule, read from itspackage.json; rule docs are expected atdocs/rules/<rule-name>.mdunderrepository.directory; typeRuleCreatorzodImportScope,zodMiniImportScope,zodCoreImportScope— each plugin's import scope;scope.createTracker({ kind, sourceCode? })gives a rule its per-file tracker (typeZodSchemaImportTracker), whose members are documented in its source- type
ZodSchemaMeta— what schema detection returns getZodSchemaBaseType(schemaType)— map a schema factory name to its base type category,nullfor factories rules should not reason aboutgetZodSchemaFactoryName(meta)— the factory a detected chain builds its schema with:meta.schemaType, except thatcoerce.<name>()gives<name>buildZodChainRemoveMethodFix(opts)— remove one method from a chainhasCommentInRange(sourceCode, range)— whether a comment sits inside a range a fixer is about to remove or rewritehasParenthesizedReceiver(member)— whether a member expression's object is wrapped in parentheses ((z.string()).min(1))ZOD_MUTATING_CHECK_NAMES— Zod check names that mutate the validated valueZOD_NON_SCHEMA_PRODUCING_METHODS— Zod method names that do not return a schemaZOD_STRING_FORMAT_METHODS— deprecatedz.string().<format>()methods and the top-level factory replacing each; typeZodStringFormatMethodNameZOD_TYPE_CHANGING_METHODS— chained methods that rebuild the schema around another type (array,or,pipe, …)
Rule types — @eslint-zod/utils/rule-types
The slice of the linter's rule API the helpers read. The types are structural, so ESLint's and typescript-eslint's own objects are assignable to them and no linter has to be installed: the package's only typescript-eslint dependency is @typescript-eslint/types, for the AST.
RuleContext,RuleListener,RuleModule,RuleMeta— the rule itselfJSONSchema4— the type ofmeta.schema, vendored from typescript-eslint so itsRuleTesteraccepts the rule modulesRuleFix,RuleFixer,ReportDescriptor,ReportFixFunction,ReportSuggestionArray,SuggestionReportDescriptor— reports and fixesSourceCode,TokenSearchOptions,Scope,ScopeVariable,ScopeDefinition,ScopeReference— source and scope access
Shared rule builders — @eslint-zod/utils/rule-builders/<rule-name>
Each rule shared between eslint-plugin-zod and eslint-plugin-zod-mini (some also eslint-plugin-zod-core) exposes its create(...) factory from a dedicated subpath. Plugins keep rule metadata local and reuse the runtime logic.
buildConsistentImportCreate(scope)— also exportsConsistentImportOptions; its optional type argument narrowssyntaxto the choices a plugin offersbuildConsistentImportSourceCreate(scope)— also exportsConsistentImportSourceOptionsbuildConsistentObjectPropertyKeyStyleCreate(scope)— also exportsConsistentObjectPropertyKeyStyleOptionsandZOD_OBJECT_PROPERTY_KEY_STYLESbuildConsistentObjectSchemaTypeCreate(scope)— also exportsConsistentObjectSchemaTypeOptionsandZOD_OBJECT_METHODSbuildConsistentSchemaOutputTypeStyleCreate(scope)— also exportsConsistentSchemaOutputTypeStyleOptionsandZOD_SCHEMA_TYPE_STYLESbuildConsistentSchemaVarNameCreate(scope)— also exportsConsistentSchemaVarNameOptionsbuildNoAnySchemaCreate(scope)buildNoCoerceBooleanCreate(scope)buildNoConflictingChecksCreate(scope)— also exports theNoConflictingChecksOptionsandNoConflictingChecksMessageIdscontractsbuildNoDuplicateSchemaMethodsCreate(scope, excludedMethods)— anas constlist naming a type-changing method is a type error, since the rule never reaches it; also exportsNoDuplicateSchemaMethodsExclusionsbuildNoDynamicSchemaValueCreate(scope)buildNoEmptyCustomSchemaCreate(scope)buildNoFunctionScopedSchemaCreate(scope)buildNoNativeEnumCreate(scope)buildNoPromiseSchemaCreate(scope)buildNoReshapeOnRefinedObjectCreate(scope)buildNoThrowInRefineCreate(scope)buildNoTransformInRecordKeyCreate(scope, transformNames)—transformNamesare matched against the key schema's factory and its constraints, so one list covers both API stylesbuildNoUnknownSchemaCreate(scope)buildNoUnnecessaryReadonlyCreate(scope)buildPreferEnumOverLiteralUnionCreate(scope)buildPreferNullishCreate(scope)buildPreferTupleOverArrayLengthCreate(scope)buildPreferValidateCreate(scope, api)— success-only parsing suggestions;apiis aZodValidateApiStyle(schema-methodorstandalone)buildRequireBrandTypeParameterCreate(scope)buildRequireErrorMessageCreate(scope)buildSchemaErrorPropertyStyleCreate(scope)— also exportsSchemaErrorPropertyStyleOptions
The consistent-import builder additionally re-exports IMPORT_SYNTAXES and ImportSyntax: every syntax the builder can enforce.
Each plugin declares the subset it offers in its own rule schema.
Rule patterns — @eslint-zod/utils/rule-patterns/<pattern-name>
Rule shapes that recur across several rules, parameterized by the names they differ in. Unlike rule builders these are not tied to one rule name, and a single plugin may use one several times.
buildDeprecatedSchemaPropertyCreate(options)— flag a deprecated property access on a schema of a givenschemaType, one factory or a list (z.number().isInt); also exportsDeprecatedSchemaPropertyOptionsbuildDeprecatedSchemaMethodCreate(options)— flag a deprecated method anywhere in a schema chain (.isOptional()); also exportsDeprecatedSchemaMethodOptionsbuildCollapseEqualBoundsCreate(options)— collapse an equal lower/upper bound pair into the exact-form check of the same domain (z.string().min(3).max(3)→z.string().length(3)); also exportsCollapseEqualBoundsOptionsandCollapsibleBoundDomainbuildPreferDedicatedFactoryCreate(options)— prefer a dedicated factory over a general one plus a chained modifier (z.looseObject()overz.object().passthrough()); also exportsPreferDedicatedFactoryOptionsbuildPreferTopLevelFactoryCreate(options)— prefer a top-level factory over a deprecated method chained on a general one (z.uuid()overz.string().uuid()), or remove the method on aredundantfactory that already implies it (z.int32().int()); also exportsPreferTopLevelFactoryOptionsandTopLevelFactoryReplacement
