feat(oxlint-plugin): add prefer-schema-validation draft rule#488
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
feat(oxlint-plugin): add prefer-schema-validation draft rule#488devin-ai-integration[bot] wants to merge 1 commit into
prefer-schema-validation draft rule#488devin-ai-integration[bot] wants to merge 1 commit into
Conversation
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>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Adds a new
prefer-schema-validationrule (in thecorrectnessbucket) 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:
typeof x === "string"/"number"/"boolean"/"object"checks"key" in objproperty-existence checkshasOwnProperty()/Object.hasOwn()chainsWhat it skips (false-positive guards):
typeof x === "undefined"— null safety / existence checkstypeof x === "function"— callback presence guardstest-noisetagtypeofchecks (environment detection)Files changed:
packages/oxlint-plugin-react-doctor/src/plugin/rules/correctness/prefer-schema-validation.ts— rule implementationpackages/oxlint-plugin-react-doctor/src/plugin/rules/correctness/prefer-schema-validation.test.ts— 32 test casespackages/oxlint-plugin-react-doctor/src/plugin/constants/thresholds.ts—MANUAL_TYPE_CHECK_THRESHOLD = 3packages/oxlint-plugin-react-doctor/src/plugin/rule-registry.ts— auto-generated (286 rules)Review & Testing Checklist for Human
Array.isArray()chains orinstanceofchains as additional manual validation signals.npx react-doctoragainst a few real-world projects to see if the rule produces useful results without excessive noise.Notes
test-noiseso it auto-skips test/spec/story files.correctnessbucket (default category: "Correctness").typeof "undefined"andtypeof "function"exclusions are intentional — these are legitimate guard patterns that don't indicate shape validation plumbing.main(install-agent-hooks.test.ts) — unrelated to this change.Link to Devin session: https://app.devin.ai/sessions/f55e61c6625044009ba0fdd26656544b