@brutalway/oxlint-config-react-hook-form 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 elnop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @brutalway/oxlint-config-react-hook-form
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Oxlint config for react-hook-form with Zod. A form validates in one place, its schema, so the type of the values it hands over is the type the schema checked.
4
+
5
+ ```sh
6
+ npm install --save-dev oxlint @brutalway/oxlint-config-react-hook-form
7
+ ```
8
+
9
+ ```ts
10
+ import { reactConfig } from '@brutalway/oxlint-config-react';
11
+ import { reactHookFormConfig } from '@brutalway/oxlint-config-react-hook-form';
12
+ import { defineConfig } from 'oxlint';
13
+
14
+ export default defineConfig({
15
+ extends: [reactConfig, reactHookFormConfig],
16
+ });
17
+ ```
18
+
19
+ ## `form-conventions/zod-resolver`
20
+
21
+ `useForm` takes `resolver: zodResolver(XSchema)`. A `useForm()` without options, or with another resolver, is reported:
22
+
23
+ ```ts
24
+ useForm({ resolver: zodResolver(TodoDraftSchema), defaultValues: { title: '' } });
25
+ ```
26
+
27
+ ## `form-conventions/validation-in-schema`
28
+
29
+ No validation outside the schema: `register('title', { required: true })`, `useController({ rules })` and `<Controller rules={...} />` are reported. Move the rule into the Zod schema, where `.min(1, 'The title is blank')` also carries the message shown to the user.
@@ -0,0 +1,2 @@
1
+ import { OxlintConfig } from "oxlint";
2
+ export declare const reactHookFormConfig: OxlintConfig;
@@ -0,0 +1,14 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { defineConfig } from "oxlint";
3
+ // src/ReactHookFormConfig.ts
4
+ const reactHookFormConfig = defineConfig({
5
+ jsPlugins: [{
6
+ name: "form-conventions",
7
+ specifier: fileURLToPath(new URL("./plugin.js", import.meta.url))
8
+ }],
9
+ rules: {
10
+ "form-conventions/zod-resolver": "error",
11
+ "form-conventions/validation-in-schema": "error"
12
+ }
13
+ });
14
+ export { reactHookFormConfig };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@oxlint/plugins").Plugin;
2
+ export { _default as default };
package/dist/plugin.js ADDED
@@ -0,0 +1,72 @@
1
+ import { definePlugin, defineRule } from "@oxlint/plugins";
2
+ // src/features/validation-in-schema/validationInSchema.ts
3
+ function calleeName(callee) {
4
+ if (callee.type === "Identifier") return callee.name;
5
+ if (callee.type === "MemberExpression" && callee.property.type === "Identifier") return callee.property.name;
6
+ }
7
+ const validationInSchema = defineRule({
8
+ meta: {
9
+ type: "problem",
10
+ docs: { description: "No validation passed to register, useController or a Controller." },
11
+ messages: { outsideSchema: "Validation lives in the Zod schema of the form: move this rule into it, so there is one place to read what a field accepts." },
12
+ schema: []
13
+ },
14
+ create(context) {
15
+ return {
16
+ CallExpression(call) {
17
+ const name = calleeName(call.callee);
18
+ if (name === "register" && call.arguments.length > 1) context.report({
19
+ node: call.arguments[1] ?? call,
20
+ messageId: "outsideSchema"
21
+ });
22
+ if (name !== "useController") return;
23
+ const [options] = call.arguments;
24
+ if (options?.type !== "ObjectExpression") return;
25
+ for (const property of options.properties) if (property.type === "Property" && property.key.type === "Identifier" && property.key.name === "rules") context.report({
26
+ node: property,
27
+ messageId: "outsideSchema"
28
+ });
29
+ },
30
+ JSXAttribute(attribute) {
31
+ const element = attribute.parent;
32
+ if (attribute.name.type !== "JSXIdentifier" || attribute.name.name !== "rules") return;
33
+ if (element.type !== "JSXOpeningElement" || element.name.type !== "JSXIdentifier" || element.name.name !== "Controller") return;
34
+ context.report({
35
+ node: attribute,
36
+ messageId: "outsideSchema"
37
+ });
38
+ }
39
+ };
40
+ }
41
+ });
42
+ // src/features/zod-resolver/zodResolver.ts
43
+ function resolvesWithZod(options) {
44
+ if (options?.type !== "ObjectExpression") return false;
45
+ return options.properties.some((property) => property.type === "Property" && property.key.type === "Identifier" && property.key.name === "resolver" && property.value.type === "CallExpression" && property.value.callee.type === "Identifier" && property.value.callee.name === "zodResolver");
46
+ }
47
+ const zodResolver = defineRule({
48
+ meta: {
49
+ type: "problem",
50
+ docs: { description: "Every useForm validates through zodResolver." },
51
+ messages: { noSchema: "useForm takes resolver: zodResolver(XSchema), so the type of the form is the type its schema validates." },
52
+ schema: []
53
+ },
54
+ create(context) {
55
+ return { CallExpression(call) {
56
+ if (call.callee.type !== "Identifier" || call.callee.name !== "useForm" || resolvesWithZod(call.arguments[0])) return;
57
+ context.report({
58
+ node: call,
59
+ messageId: "noSchema"
60
+ });
61
+ } };
62
+ }
63
+ });
64
+ // src/plugin.ts
65
+ var plugin_default = definePlugin({
66
+ meta: { name: "form-conventions" },
67
+ rules: {
68
+ "zod-resolver": zodResolver,
69
+ "validation-in-schema": validationInSchema
70
+ }
71
+ });
72
+ export { plugin_default as default };
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@brutalway/oxlint-config-react-hook-form",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Oxlint config for react-hook-form: every useForm validates through zodResolver, and no validation is passed to register or a Controller.",
5
+ "keywords": [
6
+ "oxlint",
7
+ "oxlint-config",
8
+ "oxlint-plugin",
9
+ "react-hook-form",
10
+ "zod",
11
+ "lint"
12
+ ],
13
+ "homepage": "https://github.com/Elnop/brutalway/tree/main/packages/configs/oxlint-config-react-hook-form#readme",
14
+ "bugs": "https://github.com/Elnop/brutalway/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/Elnop/brutalway.git",
18
+ "directory": "packages/configs/oxlint-config-react-hook-form"
19
+ },
20
+ "license": "MIT",
21
+ "author": "elnop",
22
+ "type": "module",
23
+ "engines": {
24
+ "node": ">=26"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "imports": {
30
+ "#src/*": "./src/*"
31
+ },
32
+ "exports": "./dist/ReactHookFormConfig.js",
33
+ "scripts": {
34
+ "build": "tsdown",
35
+ "typecheck": "tsc -p .",
36
+ "lint": "oxlint --type-aware src oxlint.config.ts tsdown.config.ts",
37
+ "deps": "depcruise src",
38
+ "tree": "check-tree src --root-entries",
39
+ "duplicates": "jscpd src",
40
+ "check": "npm run typecheck && npm run lint && npm run deps && npm run tree && npm run duplicates",
41
+ "test": "node --test 'src/**/*.test.ts'"
42
+ },
43
+ "dependencies": {
44
+ "@oxlint/plugins": "^1.91.0"
45
+ },
46
+ "peerDependencies": {
47
+ "oxlint": "^1.91.0"
48
+ },
49
+ "devDependencies": {
50
+ "@brutalway/check-tree": "0.5.0",
51
+ "@brutalway/dependency-cruiser-config": "0.5.0",
52
+ "@brutalway/lint-utils": "0.1.0",
53
+ "@brutalway/oxlint-config-node": "0.2.0",
54
+ "@brutalway/oxlint-config-node-test": "0.1.0",
55
+ "@brutalway/tsconfig": "0.3.0",
56
+ "dependency-cruiser": "18.7.2",
57
+ "jscpd": "5.4.2",
58
+ "oxlint": "1.91.0",
59
+ "oxlint-tsgolint": "7.0.2005",
60
+ "tsdown": "0.23.5",
61
+ "typescript": "7.0.2"
62
+ }
63
+ }