@brutalway/oxlint-config-react-hook-form 0.1.0 → 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/dist/ReactHookFormConfig.d.ts +2 -2
- package/dist/ReactHookFormConfig.js +13 -8
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +71 -6
- package/package.json +28 -6
- package/dist/validationInSchema.d.ts +0 -1
- package/dist/validationInSchema.js +0 -43
- package/dist/zodResolver.d.ts +0 -1
- package/dist/zodResolver.js +0 -28
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const reactHookFormConfig: OxlintConfig;
|
|
1
|
+
import { OxlintConfig } from "oxlint";
|
|
2
|
+
export declare const reactHookFormConfig: OxlintConfig;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { fileURLToPath } from
|
|
2
|
-
import { defineConfig } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
}
|
|
9
13
|
});
|
|
14
|
+
export { reactHookFormConfig };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
declare const _default: import("@oxlint/plugins").Plugin;
|
|
2
|
-
export default
|
|
2
|
+
export { _default as default };
|
package/dist/plugin.js
CHANGED
|
@@ -1,7 +1,72 @@
|
|
|
1
|
-
import { definePlugin } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
}
|
|
7
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,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brutalway/oxlint-config-react-hook-form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Oxlint config for react-hook-form: every useForm validates through zodResolver, and no validation is passed to register or a Controller.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"oxlint",
|
|
@@ -20,13 +20,25 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"author": "elnop",
|
|
22
22
|
"type": "module",
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=26"
|
|
25
|
+
},
|
|
23
26
|
"files": [
|
|
24
|
-
"dist"
|
|
25
|
-
"!dist/tsconfig.tsbuildinfo"
|
|
27
|
+
"dist"
|
|
26
28
|
],
|
|
29
|
+
"imports": {
|
|
30
|
+
"#src/*": "./src/*"
|
|
31
|
+
},
|
|
27
32
|
"exports": "./dist/ReactHookFormConfig.js",
|
|
28
33
|
"scripts": {
|
|
29
|
-
"
|
|
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'"
|
|
30
42
|
},
|
|
31
43
|
"dependencies": {
|
|
32
44
|
"@oxlint/plugins": "^1.91.0"
|
|
@@ -35,7 +47,17 @@
|
|
|
35
47
|
"oxlint": "^1.91.0"
|
|
36
48
|
},
|
|
37
49
|
"devDependencies": {
|
|
38
|
-
"@brutalway/
|
|
39
|
-
"
|
|
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"
|
|
40
62
|
}
|
|
41
63
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const validationInSchema: import("@oxlint/plugins").Rule;
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
});
|
package/dist/zodResolver.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const zodResolver: import("@oxlint/plugins").Rule;
|
package/dist/zodResolver.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
});
|