@longzai-intelligence-oxlint/schema-type-separation-plugin 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/README.md +17 -0
- package/dist/configs/recommended.d.ts +11 -0
- package/dist/configs/recommended.js +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @longzai-intelligence-oxlint/schema-type-separation-plugin
|
|
2
|
+
|
|
3
|
+
## 意图
|
|
4
|
+
|
|
5
|
+
在静态检查阶段强制 Zod Schema 与 TypeScript Type 文件职责分离,避免在同一文件内混合两类定义造成维护负担。
|
|
6
|
+
|
|
7
|
+
## 定位
|
|
8
|
+
|
|
9
|
+
Oxlint 生态的 Schema/Type 职责分离插件,通过 `eslintCompatPlugin` 包装以同时兼容 Oxlint 与 ESLint 运行时。
|
|
10
|
+
|
|
11
|
+
## 职能
|
|
12
|
+
|
|
13
|
+
提供 `no-type-in-schema` 规则禁止在 Schema 文件内定义纯类型、`no-schema-in-types` 规则禁止在类型文件内定义 Zod Schema;同时导出 `isSchemaFile`、`isTypesFile` 与 Zod Schema 方法常量供外部复用。
|
|
14
|
+
|
|
15
|
+
## 实现情况
|
|
16
|
+
|
|
17
|
+
两条规则及配套判断工具均已实现并按规则目录组织,规则、工具与插件对象一并导出;当前规则集合聚焦 Schema/Type 分离维度,处于稳定可用形态。
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { OxlintRules } from "@longzai-intelligence-oxlint/core";
|
|
2
|
+
//#region src/configs/recommended.config.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* 推荐规则配置对象
|
|
5
|
+
*
|
|
6
|
+
* 包含 schema-type-separation 插件的推荐规则设置,
|
|
7
|
+
* 两条规则默认关闭,推荐将 type 定义合并在 schema 文件中
|
|
8
|
+
*/
|
|
9
|
+
declare const recommended: OxlintRules;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { recommended };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={"@longzai-intelligence-oxlint/schema-type-separation-plugin/no-type-in-schema":`off`,"@longzai-intelligence-oxlint/schema-type-separation-plugin/no-schema-in-types":`off`};export{e as recommended};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/rules/no-schema-in-types/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Zod Schema 运行时方法名列表
|
|
4
|
+
*
|
|
5
|
+
* 覆盖所有可能创建 Zod Schema 的方法调用
|
|
6
|
+
*/
|
|
7
|
+
declare const ZOD_SCHEMA_METHODS: Set<string>;
|
|
8
|
+
/**
|
|
9
|
+
* 判断文件是否为 types 文件
|
|
10
|
+
*
|
|
11
|
+
* @param filename - 文件名
|
|
12
|
+
* @returns 是否为 types 文件
|
|
13
|
+
*/
|
|
14
|
+
declare function isTypesFile(filename: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* no-schema-in-types 规则定义
|
|
17
|
+
*
|
|
18
|
+
* 在 *.types.ts 文件中禁止 Zod Schema 运行时定义,允许 z.infer 类型推导。
|
|
19
|
+
* 使用 createOnce 替代 create 以获得 Oxlint 最佳性能。
|
|
20
|
+
*/
|
|
21
|
+
declare const noSchemaInTypesRule: import("@oxlint/plugins").Rule;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/rules/no-type-in-schema/index.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* 判断文件是否为 schema 文件
|
|
26
|
+
*
|
|
27
|
+
* @param filename - 文件名
|
|
28
|
+
* @returns 是否为 schema 文件
|
|
29
|
+
*/
|
|
30
|
+
declare function isSchemaFile(filename: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* no-type-in-schema 规则定义
|
|
33
|
+
*
|
|
34
|
+
* 在 *.schema.ts 文件中禁止任何 type 声明,零容忍。
|
|
35
|
+
* 使用 createOnce 替代 create 以获得 Oxlint 最佳性能。
|
|
36
|
+
*/
|
|
37
|
+
declare const noTypeInSchemaRule: import("@oxlint/plugins").Rule;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/index.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* schema-type-separation 插件
|
|
42
|
+
*
|
|
43
|
+
* 提供 Schema/Type 职责分离相关的 Oxlint 规则,
|
|
44
|
+
* 通过 eslintCompatPlugin 包装以同时支持 Oxlint 和 ESLint 运行时
|
|
45
|
+
*/
|
|
46
|
+
declare const schemaTypeSeparationPlugin: import("@oxlint/plugins").Plugin;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { ZOD_SCHEMA_METHODS, schemaTypeSeparationPlugin as default, schemaTypeSeparationPlugin, isSchemaFile, isTypesFile, noSchemaInTypesRule, noTypeInSchemaRule };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";const n=new Set(`object.enum.string.number.boolean.array.record.tuple.union.intersection.literal.nativeEnum.any.unknown.void.never.date.bigint.map.set.nan.null.undefined.symbol.coerce.lazy.promise.function.branded.catch.default.describe.nullable.optional.transform.pipe.refine.superRefine.preprocess`.split(`.`));function r(e){return e.endsWith(`.types.ts`)}const i=e({meta:{type:`problem`,docs:{description:`禁止在 *.types.ts 文件中包含 Zod Schema 运行时定义,允许 z.infer 类型推导`}},createOnce(e){return{before(){let t=e.filename;if(!r(t))return!1},CallExpression(t){if(t.callee.type!==`MemberExpression`||t.callee.object.type!==`Identifier`||t.callee.object.name!==`z`||t.callee.property.type!==`Identifier`)return;let r=t.callee.property.name;n.has(r)&&e.report({node:t,message:`*.types.ts 文件不允许包含 Zod Schema 定义。"z.${r}()" 是运行时验证逻辑,应放在 *.schema.ts 文件中。`})},ImportDeclaration(t){if(t.source.value===`zod`&&!(`importKind`in t&&t.importKind===`type`))for(let n of t.specifiers){if(n.type===`ImportNamespaceSpecifier`){e.report({node:t,message:`*.types.ts 文件不允许从 zod 进行值导入。如需引用 Zod 类型,请使用 import type 语法。`});return}if(!(`importKind`in n&&n.importKind===`type`)){e.report({node:t,message:`*.types.ts 文件不允许从 zod 进行值导入。如需引用 Zod 类型,请使用 import type 语法。`});return}}}}}});function a(e){return e.endsWith(`.schema.ts`)}function o(e){if(`id`in e&&e.id!==null&&typeof e.id==`object`&&`name`in e.id&&typeof e.id.name==`string`)return e.id.name}const s=e({meta:{type:`problem`,docs:{description:`禁止在 *.schema.ts 文件中包含任何 type 定义,强制拆分到 *.types.ts 文件`}},createOnce(e){return{before(){let t=e.filename;if(!a(t))return!1},TSTypeAliasDeclaration(t){let n=o(t);e.report({node:t,message:`*.schema.ts 文件不允许包含 type 定义。类型 "${n??`未知类型`}" 应拆分到对应的 *.types.ts 文件中。`})}}}}),c=t({meta:{name:`@longzai-intelligence-oxlint/schema-type-separation-plugin`},rules:{"no-type-in-schema":s,"no-schema-in-types":i}});export{n as ZOD_SCHEMA_METHODS,c as default,c as schemaTypeSeparationPlugin,a as isSchemaFile,r as isTypesFile,i as noSchemaInTypesRule,s as noTypeInSchemaRule};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-oxlint/schema-type-separation-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./configs/recommended": {
|
|
17
|
+
"types": "./dist/configs/recommended.d.ts",
|
|
18
|
+
"import": "./dist/configs/recommended.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "lzi-builder",
|
|
23
|
+
"build:prod": "NODE_ENV=production lzi-builder",
|
|
24
|
+
"prepublishOnly": "bun run build:prod",
|
|
25
|
+
"dev": "lzi-builder --watch",
|
|
26
|
+
"clean": "rimraf dist",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"test:coverage": "vitest run --coverage",
|
|
30
|
+
"lint": "oxlint && oxfmt --check",
|
|
31
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
32
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
33
|
+
"typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
|
|
34
|
+
"typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
|
|
35
|
+
"typecheck:test": "tsgo --noEmit -p tsconfig/test.json"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@longzai-intelligence-oxlint/core": "0.1.0",
|
|
39
|
+
"@oxlint/plugins": "^1.74.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
43
|
+
"typescript": "^6.0.3"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"oxlint": ">=1.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|