Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/prefer-schema-validation-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"oxlint-plugin-react-doctor": patch
---

Add the `react-doctor/prefer-schema-validation` rule.

Flags hand-rolled runtime type/shape validation — a TypeScript type-predicate or assertion function (`value is User`, `asserts input is Config`), or a validator-named function (`isUser`, `validateConfig`, `assertX`, …) that checks an object's shape with two or more distinct `typeof` member checks — and recommends parsing the value once with a schema validator (Zod, Valibot, Yup) so the type and the runtime check stay in sync. Only `typeof param.member === "<tag>"` checks count, so polymorphic dispatch on the parameter itself, serializers without a validator name, checks inside nested functions, and dynamic computed members stay quiet.
12 changes: 12 additions & 0 deletions packages/oxlint-plugin-react-doctor/src/plugin/rule-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ import { preferFunctionComponent } from "./rules/react-builtins/prefer-function-
import { preferHtmlDialog } from "./rules/a11y/prefer-html-dialog.js";
import { preferModuleScopePureFunction } from "./rules/architecture/prefer-module-scope-pure-function.js";
import { preferModuleScopeStaticValue } from "./rules/architecture/prefer-module-scope-static-value.js";
import { preferSchemaValidation } from "./rules/architecture/prefer-schema-validation.js";
import { preferStableEmptyFallback } from "./rules/performance/prefer-stable-empty-fallback.js";
import { preferTagOverRole } from "./rules/a11y/prefer-tag-over-role.js";
import { preferUseEffectEvent } from "./rules/state-and-effects/prefer-use-effect-event.js";
Expand Down Expand Up @@ -2900,6 +2901,17 @@ export const reactDoctorRules = [
category: "Maintainability",
},
},
{
key: "react-doctor/prefer-schema-validation",
id: "prefer-schema-validation",
source: "react-doctor",
originallyExternal: false,
rule: {
...preferSchemaValidation,
framework: "global",
category: "Maintainability",
},
},
{
key: "react-doctor/prefer-stable-empty-fallback",
id: "prefer-stable-empty-fallback",
Expand Down
Loading
Loading