@brutalway/oxlint-config-react-hook-form 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +28 -2
- package/dist/ReactHookFormConfig.d.ts +2 -0
- package/dist/ReactHookFormConfig.js +9 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +7 -0
- package/dist/validationInSchema.d.ts +1 -0
- package/dist/validationInSchema.js +43 -0
- package/dist/zodResolver.d.ts +1 -0
- package/dist/zodResolver.js +28 -0
- package/package.json +39 -4
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
|
-
#
|
|
1
|
+
# @brutalway/oxlint-config-react-hook-form
|
|
2
2
|
|
|
3
|
-
|
|
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,9 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { defineConfig } from 'oxlint';
|
|
3
|
+
export const reactHookFormConfig = defineConfig({
|
|
4
|
+
jsPlugins: [{ name: 'form-conventions', specifier: fileURLToPath(new URL('./plugin.js', import.meta.url)) }],
|
|
5
|
+
rules: {
|
|
6
|
+
'form-conventions/zod-resolver': 'error',
|
|
7
|
+
'form-conventions/validation-in-schema': 'error',
|
|
8
|
+
},
|
|
9
|
+
});
|
package/dist/plugin.d.ts
ADDED
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { definePlugin } from '@oxlint/plugins';
|
|
2
|
+
import { validationInSchema } from './validationInSchema.js';
|
|
3
|
+
import { zodResolver } from './zodResolver.js';
|
|
4
|
+
export default definePlugin({
|
|
5
|
+
meta: { name: 'form-conventions' },
|
|
6
|
+
rules: { 'zod-resolver': zodResolver, 'validation-in-schema': validationInSchema },
|
|
7
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validationInSchema: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { defineRule } from '@oxlint/plugins';
|
|
2
|
+
function calleeName(callee) {
|
|
3
|
+
if (callee.type === 'Identifier')
|
|
4
|
+
return callee.name;
|
|
5
|
+
if (callee.type === 'MemberExpression' && callee.property.type === 'Identifier')
|
|
6
|
+
return callee.property.name;
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const MESSAGE = '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.';
|
|
10
|
+
export const validationInSchema = defineRule({
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
docs: { description: 'No validation passed to register, useController or a Controller.' },
|
|
14
|
+
messages: { outsideSchema: MESSAGE },
|
|
15
|
+
schema: [],
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
return {
|
|
19
|
+
CallExpression(call) {
|
|
20
|
+
const name = calleeName(call.callee);
|
|
21
|
+
if (name === 'register' && call.arguments.length > 1)
|
|
22
|
+
context.report({ node: call.arguments[1] ?? call, messageId: 'outsideSchema' });
|
|
23
|
+
if (name !== 'useController')
|
|
24
|
+
return;
|
|
25
|
+
const [options] = call.arguments;
|
|
26
|
+
if (options?.type !== 'ObjectExpression')
|
|
27
|
+
return;
|
|
28
|
+
for (const property of options.properties) {
|
|
29
|
+
if (property.type === 'Property' && property.key.type === 'Identifier' && property.key.name === 'rules')
|
|
30
|
+
context.report({ node: property, messageId: 'outsideSchema' });
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
JSXAttribute(attribute) {
|
|
34
|
+
const element = attribute.parent;
|
|
35
|
+
if (attribute.name.type !== 'JSXIdentifier' || attribute.name.name !== 'rules')
|
|
36
|
+
return;
|
|
37
|
+
if (element.type !== 'JSXOpeningElement' || element.name.type !== 'JSXIdentifier' || element.name.name !== 'Controller')
|
|
38
|
+
return;
|
|
39
|
+
context.report({ node: attribute, messageId: 'outsideSchema' });
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const zodResolver: import("@oxlint/plugins").Rule;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineRule } from '@oxlint/plugins';
|
|
2
|
+
function resolvesWithZod(options) {
|
|
3
|
+
if (options?.type !== 'ObjectExpression')
|
|
4
|
+
return false;
|
|
5
|
+
return options.properties.some((property) => property.type === 'Property' &&
|
|
6
|
+
property.key.type === 'Identifier' &&
|
|
7
|
+
property.key.name === 'resolver' &&
|
|
8
|
+
property.value.type === 'CallExpression' &&
|
|
9
|
+
property.value.callee.type === 'Identifier' &&
|
|
10
|
+
property.value.callee.name === 'zodResolver');
|
|
11
|
+
}
|
|
12
|
+
export const zodResolver = defineRule({
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: { description: 'Every useForm validates through zodResolver.' },
|
|
16
|
+
messages: { noSchema: 'useForm takes resolver: zodResolver(XSchema), so the type of the form is the type its schema validates.' },
|
|
17
|
+
schema: [],
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
return {
|
|
21
|
+
CallExpression(call) {
|
|
22
|
+
if (call.callee.type !== 'Identifier' || call.callee.name !== 'useForm' || resolvesWithZod(call.arguments[0]))
|
|
23
|
+
return;
|
|
24
|
+
context.report({ node: call, messageId: 'noSchema' });
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brutalway/oxlint-config-react-hook-form",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.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
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"!dist/tsconfig.tsbuildinfo"
|
|
26
|
+
],
|
|
27
|
+
"exports": "./dist/ReactHookFormConfig.js",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "node --test '**/*.test.ts'"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@oxlint/plugins": "^1.91.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"oxlint": "^1.91.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@brutalway/lint-utils": "^0.1.0",
|
|
39
|
+
"oxlint": "^1.91.0"
|
|
40
|
+
}
|
|
41
|
+
}
|