Skip to content

feat: add no-zod-enum guardrail - #36

Merged
stevensacks merged 1 commit into
mainfrom
feat/no-zod-enum-rule
Jul 3, 2026
Merged

feat: add no-zod-enum guardrail#36
stevensacks merged 1 commit into
mainfrom
feat/no-zod-enum-rule

Conversation

@stevensacks

Copy link
Copy Markdown
Contributor

What

Adds the no-zod-enum custom guardrail: z.enum(...) is now an error in .ts/.tsx. Use z.literal([...]) for string unions (sort values alphanumerically).

Why

The typescript convention z.literal([...]) over z.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

  • New rule src/plugins/no-zod-enum.ts (esquery selector on z.enum call callee), report-only, type: 'problem'.
  • Registered in guardrails scoped to **/*.ts?(x), severity error.
  • RuleTester suite src/plugins/no-zod-enum.test.ts (5 valid + 2 invalid).
  • README bundle-shape row updated; minor changeset included.

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 union members.

Consumers with existing z.enum() will see a new lint error on upgrade.

🤖 Generated with Claude Code

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>
@stevensacks
stevensacks merged commit fe262a6 into main Jul 3, 2026
1 check passed
@stevensacks
stevensacks deleted the feat/no-zod-enum-rule branch July 3, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant