Skip to content

feat(oxlint-plugin): add prefer-schema-validation draft rule#488

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1779748211-prefer-schema-validation
Open

feat(oxlint-plugin): add prefer-schema-validation draft rule#488
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1779748211-prefer-schema-validation

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Adds a new prefer-schema-validation rule (in the correctness bucket) that detects functions with 3+ manual type-checking operations (typeof, in, hasOwnProperty/hasOwn) that collectively validate an object shape, and suggests using a schema validation library instead (zod, valibot, superstruct, etc.).

What it flags:

  • Functions with 3+ typeof x === "string" / "number" / "boolean" / "object" checks
  • Chains of "key" in obj property-existence checks
  • hasOwnProperty() / Object.hasOwn() chains
  • Mixed combinations of the above

What it skips (false-positive guards):

  • typeof x === "undefined" — null safety / existence checks
  • typeof x === "function" — callback presence guards
  • Files that already import one of 18 recognized schema libraries (zod, yup, joi, valibot, superstruct, io-ts, runtypes, arktype, effect/Schema, typebox, ow, etc.)
  • Nested functions counted independently (inner arrow/function bodies don't inflate the parent count)
  • Test files via test-noise tag
  • Module-scope typeof checks (environment detection)

Files changed:

  • packages/oxlint-plugin-react-doctor/src/plugin/rules/correctness/prefer-schema-validation.ts — rule implementation
  • packages/oxlint-plugin-react-doctor/src/plugin/rules/correctness/prefer-schema-validation.test.ts — 32 test cases
  • packages/oxlint-plugin-react-doctor/src/plugin/constants/thresholds.tsMANUAL_TYPE_CHECK_THRESHOLD = 3
  • packages/oxlint-plugin-react-doctor/src/plugin/rule-registry.ts — auto-generated (286 rules)

Review & Testing Checklist for Human

  • Verify the threshold of 3 feels right — should it be 2 or 4 instead? The current value flags 3+ manual checks per function body.
  • Review the schema library list — are there any missing libraries your users commonly use?
  • Consider whether the rule should also detect Array.isArray() chains or instanceof chains as additional manual validation signals.
  • Run npx react-doctor against a few real-world projects to see if the rule produces useful results without excessive noise.

Notes

  • The rule is tagged test-noise so it auto-skips test/spec/story files.
  • It's placed in the correctness bucket (default category: "Correctness").
  • The typeof "undefined" and typeof "function" exclusions are intentional — these are legitimate guard patterns that don't indicate shape validation plumbing.
  • One pre-existing test failure exists on main (install-agent-hooks.test.ts) — unrelated to this change.

Link to Devin session: https://app.devin.ai/sessions/f55e61c6625044009ba0fdd26656544b

Detects functions with 3+ manual type-checking operations (typeof,
in, hasOwnProperty/hasOwn) that collectively validate an object shape,
and suggests using a schema validation library instead (zod, valibot,
superstruct, etc.).

Smart exclusions to minimize false positives:
- typeof undefined / function checks (null safety & callback guards)
- Files already importing a schema library (18 recognized)
- Nested functions counted independently (not aggregated)
- Test files skipped via test-noise tag

32 test cases covering flagged patterns, false-positive guards,
and real-world open-source scenarios.

Co-Authored-By: nisarg@million.dev <awesomenisarg@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration Bot requested a review from aidenybai May 25, 2026 22:42
@NisargIO NisargIO marked this pull request as ready for review May 25, 2026 22:42
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.

0 participants