@longzai-intelligence-oxlint/schema-type-separation-plugin 0.1.18 → 0.1.19

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 CHANGED
@@ -1,17 +1,14 @@
1
1
  # @longzai-intelligence-oxlint/schema-type-separation-plugin
2
2
 
3
- ## 意图
3
+ Longzai Intelligence Oxlint 的职责分离插件,强制 Zod Schema 与 TypeScript Type 文件职责分离。
4
4
 
5
- 在静态检查阶段强制 Zod Schema 与 TypeScript Type 文件职责分离,避免在同一文件内混合两类定义造成维护负担。
5
+ ## 简介
6
6
 
7
- ## 定位
7
+ 治理 Schema/Type 混合定义的问题:Schema 文件内定义纯类型、类型文件内定义 Zod Schema 在静态检查阶段拦截,防止同一文件混合两类定义造成维护负担。
8
8
 
9
- Oxlint 生态的 Schema/Type 职责分离插件,通过 `eslintCompatPlugin` 包装以同时兼容 Oxlint 与 ESLint 运行时。
9
+ ## 能力
10
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 分离维度,处于稳定可用形态。
11
+ - `no-type-in-schema` — 禁止在 Schema 文件内定义纯类型
12
+ - `no-schema-in-types` — 禁止在类型文件内定义 Zod Schema
13
+ - `isSchemaFile`、`isTypesFile` 判断工具与 Zod Schema 方法常量导出
14
+ - 同时兼容 Oxlint 与 ESLint 运行时
package/dist/index.js CHANGED
@@ -1 +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};
1
+ import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";const n=/* @__PURE__ */ new Set(/* @__PURE__ */ `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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-oxlint/schema-type-separation-plugin",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "dist"
@@ -35,7 +35,7 @@
35
35
  "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json"
36
36
  },
37
37
  "dependencies": {
38
- "@longzai-intelligence-oxlint/core": "0.1.18",
38
+ "@longzai-intelligence-oxlint/core": "0.1.19",
39
39
  "@oxlint/plugins": "^1.74.0"
40
40
  },
41
41
  "devDependencies": {