feat: add no-zod-enum guardrail - #36
Merged
Merged
Conversation
Disallow z.enum() in .ts/.tsx and require z.literal([...]) for string unions (sort values alphanumerically). Report-only, error severity, to match the existing no-switch / no-enum / no-jsx-iife guardrails. Not autofixable on purpose: z.enum()'s .enum/.options/.extract/.exclude accessors have no z.literal array-form equivalent, so a blind rename could break downstream code, and a rename cannot sort the union members. This makes the typescript SKILL's z.literal-over-z.enum convention a deterministic lint failure instead of a discretionary review suggestion. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the
no-zod-enumcustom guardrail:z.enum(...)is now an error in.ts/.tsx. Usez.literal([...])for string unions (sort values alphanumerically).Why
The typescript convention
z.literal([...])overz.enum()was previously only enforced by discretionary code review, which downgraded violations to a non-blocking Suggestion. This makes it a deterministic lint failure.Details
src/plugins/no-zod-enum.ts(esquery selector onz.enumcall callee), report-only,type: 'problem'.guardrailsscoped to**/*.ts?(x), severityerror.src/plugins/no-zod-enum.test.ts(5 valid + 2 invalid).Not autofixable on purpose:
z.enum()'s.enum/.options/.extract/.excludeaccessors have noz.literalarray-form equivalent, so a blind rename could break downstream code, and a rename cannot sort union members.Consumers with existing
z.enum()will see a new lint error on upgrade.🤖 Generated with Claude Code