@longzai-intelligence-oxlint/architecture-core-plugin 0.2.16 → 0.2.18

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.
@@ -1 +1 @@
1
- const e={"@longzai-intelligence-oxlint/architecture-core-plugin/business-leak":`off`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-cross-package-relative-import":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/implementation-export-control":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-implementation-import-in-apps":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/domain-export-compliance":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/dependency-direction":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-raw-network-call-in-ui":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-port-probing":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-vite-port-fallback":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-reuseport-default":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-template-error-log":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-text-only-error-log":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-exit-after-error-log":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-inline-error-normalization":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-error-type-assertion":`warn`};export{e as recommended};
1
+ const e={"@longzai-intelligence-oxlint/architecture-core-plugin/business-leak":`off`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-cross-package-relative-import":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/implementation-export-control":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-implementation-import-in-apps":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/domain-export-compliance":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/dependency-direction":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-port-probing":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-vite-port-fallback":`error`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-reuseport-default":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-template-error-log":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-text-only-error-log":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-exit-after-error-log":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-inline-error-normalization":`warn`,"@longzai-intelligence-oxlint/architecture-core-plugin/no-error-type-assertion":`warn`};export{e as recommended};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";import*as n from"zod/mini";const r=[`/packages/platform/`,`/packages/ui/`,`/packages/ui-kit/`,`/packages/engine/`,`/packages/utils/`,`/packages/types/`],i=[],a=[`^validate`,`^calculate`,`^compute`,`^determine`,`^check`,`^can`,`^should`,`^isAllowed`,`^isPermitted`,`^hasPermission`,`^applyRule`,`^enforce`,`^execute`];function o(e){return typeof e==`object`&&!!e}function s(e){let t=Array.isArray(e)?e[0]:e;return o(t)?{techLayerPatterns:t.techLayerPatterns??r,businessKeywords:t.businessKeywords??i,businessRuleMethods:t.businessRuleMethods??a}:{techLayerPatterns:r,businessKeywords:i,businessRuleMethods:a}}function c(e){return e.map(e=>new RegExp(e))}function ee(e,t){let n=e.replace(/\\/g,`/`);return t.some(e=>e.test(n))}function l(e,t){let n=e.charAt(0).toUpperCase()+e.slice(1);return t.some(e=>n.includes(e))}function te(e,t){return t.some(t=>t.test(e))}const u=e({meta:{type:`suggestion`,docs:{description:`检测技术层中可能存在的业务逻辑`}},createOnce(e){let t=[],n=[],r=[];return{before(){let i=s(e.options);return t=c(i.techLayerPatterns),n=i.businessKeywords,r=c(i.businessRuleMethods),ee(e.filename,t)?void 0:!1},ClassDeclaration(t){t.id&&l(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关类 '${t.id.name}'。业务逻辑应该放在 domains/ 层。`})},MethodDefinition(t){t.key.type===`Identifier`&&te(t.key.name,r)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务规则方法 '${t.key.name}'。业务规则应该放在 domains/ 层。`})},TSInterfaceDeclaration(t){l(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关接口 '${t.id.name}'。业务接口应该放在 domains/ 层。`})},TSTypeAliasDeclaration(t){l(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关类型 '${t.id.name}'。业务类型应该放在 domains/ 层。`})}}}}),d={types:0,utils:1,"shared-kernel":2,contract:3,engine:4,platform:5,infrastructure:6,implementation:6,domain:6,capability:7,ui:7,"electron-shared":7,"electron-main":8,"electron-preload":8,"electron-renderer":9},ne={types:`类型层 (Types)`,utils:`工具层 (Utils)`,"shared-kernel":`共享内核层 (Shared Kernel)`,contract:`契约层 (Contract)`,engine:`引擎层 (Engine)`,platform:`平台层 (Platform)`,infrastructure:`基础设施层 (Infrastructure)`,implementation:`实现层 (Implementation)`,domain:`门面层 (Domain Facade)`,capability:`能力装配层 (Capability)`,ui:`UI 表现层`,"electron-shared":`Electron 共享层 (Shared)`,"electron-main":`Electron 主进程 (Main)`,"electron-preload":`Electron 预加载层 (Preload)`,"electron-renderer":`Electron 渲染进程 (Renderer)`},re=new Set(Object.keys(d)),f={pathPatterns:[{pattern:/\/apps\/capabilities\//,layer:`capability`},{pattern:/\/domains\/[^/]+\/implementation\//,layer:`implementation`},{pattern:/\/domains\/[^/]+\/contract\//,layer:`contract`},{pattern:/\/domains\/[^/]+\/ui\//,layer:`ui`},{pattern:/\/domains\/shared-kernel\//,layer:`shared-kernel`},{pattern:/\/infrastructure\//,layer:`infrastructure`}],packagePrefix:``,specialPackageMappings:{},packageSuffixMappings:[{suffix:`-contract`,layer:`contract`},{suffix:`-implementation`,layer:`implementation`},{suffix:`-infrastructure`,layer:`infrastructure`},{suffix:`-domain`,layer:`domain`},{suffix:`-ui`,layer:`ui`},{suffix:`-engine`,layer:`engine`},{suffix:`-runtime`,layer:`engine`}]},p=[{from:`capability`,to:`implementation`},{from:`capability`,to:`infrastructure`},{from:`ui`,to:`domain`,hint:`UI 面禁止经门面包取件,域外依赖唯一指向生成式 sdk 客户端,ADR 0127。`},{from:`ui`,to:`contract`,hint:`contract 为 DDD 主体对 UI 全封闭,类型正源为 sdk 生成契约推断类型,ADR 0127。`},{from:`ui`,to:`implementation`,hint:`UI 面禁止直连实现层,域外依赖唯一指向生成式 sdk 客户端,ADR 0127。`},{from:`ui`,to:`infrastructure`,hint:`UI 面禁止直连基础设施层,域外依赖唯一指向生成式 sdk 客户端,ADR 0127。`}],m=[`-main`],h=[{pattern:/\/src\/domain\//,layer:`contract`},{pattern:/\/src\/engine\//,layer:`engine`},{pattern:/\/src\/platform\//,layer:`platform`},{pattern:/\/src\/infrastructure\//,layer:`infrastructure`},{pattern:/\/src\/shared\//,layer:`shared-kernel`}];function g(e){return re.has(e)}function ie(e,t){return d[e]>=d[t]}function _(e){return ne[e]}function ae(e,t){let n=e.replace(/\\/g,`/`),r=t??f.pathPatterns;if(r){for(let{pattern:e,layer:t}of r)if(e.test(n))return{layer:t,priority:d[t]}}if(n.includes(`/apps/`)){for(let{pattern:e,layer:t}of h)if(e.test(n))return{layer:t,priority:d[t]}}if(n.includes(`/packages/`)){for(let{pattern:e,layer:t}of h)if(e.test(n))return{layer:t,priority:d[t]}}return null}function v(e,t){if(!e.startsWith(t))return null;let n=e.split(`/`),r=n[0]===``?n.slice(1):n;return(r[0]?.startsWith(`@`)?r[1]:r[0])??null}function oe(e,t){for(let n of t)if(e.endsWith(n))return n;return null}function se(e,t){let n=t.packagePrefix??``,r=v(e,n);if(!r)return null;let i=(t.specialPackageMappings??{})[`${n}${r}`];if(i)return{layer:i,priority:d[i]};let a=t.packageSuffixMappings??[];for(let{suffix:e,layer:t}of a)if(r.endsWith(e))return{layer:t,priority:d[t]};return null}function ce(e,t,n){return e.find(e=>e.from===t&&e.to===n)??null}function le(e){let t=e.match(/^\/(.+)\/([gimsuvy]*)$/);return t?.[1]?new RegExp(t[1],t[2]??``):new RegExp(e)}function ue(e){let t={};if(e.pathPatterns&&(t.pathPatterns=e.pathPatterns.reduce((e,{pattern:t,layer:n})=>(g(n)&&e.push({pattern:le(t),layer:n}),e),[])),e.packagePrefix&&(t.packagePrefix=e.packagePrefix),e.specialPackageMappings){let n={};for(let[t,r]of Object.entries(e.specialPackageMappings))g(r)&&(n[t]=r);t.specialPackageMappings=Object.keys(n).length>0?n:void 0}if(e.packageSuffixMappings){let n=[];for(let{suffix:t,layer:r}of e.packageSuffixMappings)g(r)&&n.push({suffix:t,layer:r});t.packageSuffixMappings=n.length>0?n:void 0}if(e.forbiddenLayerPairs){let n=[];for(let{from:t,to:r}of e.forbiddenLayerPairs)g(t)&&g(r)&&n.push({from:t,to:r});t.forbiddenLayerPairs=n.length>0?n:void 0}if(e.forbiddenPackageSuffixes){let n=e.forbiddenPackageSuffixes.filter(e=>e.length>0);t.forbiddenPackageSuffixes=n.length>0?n:void 0}return t}function de(e){return typeof e==`object`&&!!e}function fe(e){let t=ue(de(e)?e:{});return{pathPatterns:t.pathPatterns??f.pathPatterns,packagePrefix:t.packagePrefix??f.packagePrefix,specialPackageMappings:t.specialPackageMappings??f.specialPackageMappings,packageSuffixMappings:t.packageSuffixMappings??f.packageSuffixMappings,forbiddenLayerPairs:[...p,...t.forbiddenLayerPairs??[]],forbiddenPackageSuffixes:[...m,...t.forbiddenPackageSuffixes??[]]}}const pe=e({meta:{type:`problem`,docs:{description:`强制执行 Clean Architecture 的依赖方向规则`},schema:[{type:`object`,properties:{pathPatterns:{type:`array`,items:{type:`object`,properties:{pattern:{type:`string`},layer:{type:`string`}},required:[`pattern`,`layer`],additionalProperties:!1}},packagePrefix:{type:`string`},specialPackageMappings:{type:`object`,additionalProperties:{type:`string`}},packageSuffixMappings:{type:`array`,items:{type:`object`,properties:{suffix:{type:`string`},layer:{type:`string`}},required:[`suffix`,`layer`],additionalProperties:!1}},forbiddenLayerPairs:{type:`array`,items:{type:`object`,properties:{from:{type:`string`},to:{type:`string`}},required:[`from`,`to`],additionalProperties:!1}},forbiddenPackageSuffixes:{type:`array`,items:{type:`string`}}},additionalProperties:!1}]},createOnce(e){let t=null,n=null;return{before(){return t===null&&(t=fe(e.options?.[0])),n=ae(e.filename,t.pathPatterns),n!==null},ImportDeclaration(r){if(!n||!t)return;let i=r.source.type===`Literal`&&typeof r.source.value==`string`?r.source.value:null;if(!i)return;let a=v(i,t.packagePrefix??``);if(a){let n=oe(a,t.forbiddenPackageSuffixes??[]);if(n){e.report({node:r,message:`禁止导入已禁用的 ${n} 门面包,门面包统一使用 -domain 后缀。`});return}}let o=se(i,t);if(!o)return;let s=ce(t.forbiddenLayerPairs??[],n.layer,o.layer);s?e.report({node:r,message:`依赖方向违规: ${n.layer} (${_(n.layer)}) 不能导入 ${o.layer} (${_(o.layer)})。${s.hint??`域内取件必须经 -domain 门面包。`}`}):ie(n.layer,o.layer)||e.report({node:r,message:`依赖方向违规: ${n.layer} (${_(n.layer)}) 不能导入 ${o.layer} (${_(o.layer)})。依赖应该从外层指向内层。`})}}}});function me(e){let t=e.replace(/\\/g,`/`);return t.includes(`/domains/`)&&t.includes(`/implementation/src/index.ts`)}function y(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function b(e){return y(e)&&e.endsWith(`Entity`)}function x(e){return y(e)&&e.endsWith(`Repository`)&&!e.startsWith(`I`)}function S(e){return y(e)&&e.endsWith(`OrmEntity`)}function C(e){return e.endsWith(`_ORM_ENTITIES`)}function w(e){return y(e)&&e.endsWith(`OrmMapper`)}function T(e){return y(e)&&e.endsWith(`Schema`)}function E(e){return`exportKind`in e&&typeof e.exportKind==`string`?e.exportKind===`value`:!0}function D(e){return e.exported.type===`Identifier`?e.exported.name:e.exported.type===`Literal`&&typeof e.exported.value==`string`?e.exported.value:null}function O(e,t,n){b(e)&&E(t)?n.report({node:t,message:`禁止从主入口值导出 Entity 类 "${e}"。请改为类型导出或移除导出。`}):x(e)?n.report({node:t,message:`禁止导出 Repository 类型 "${e}"。Repository 是内部实现,不应暴露给外部。`}):S(e)?n.report({node:t,message:`禁止从主入口导出 ORM 实体 "${e}"。请创建 src/typeorm.ts 入口文件,从该入口导出。`}):C(e)?n.report({node:t,message:`禁止从主入口导出 ORM 实体集合 "${e}"。请创建 src/typeorm.ts 入口文件,从该入口导出。`}):w(e)?n.report({node:t,message:`禁止导出 ORM Mapper "${e}"。ORM Mapper 是基础设施实现细节,不应暴露给外部。`}):T(e)&&n.report({node:t,message:`禁止导出 Schema 定义 "${e}"。Schema 是实现细节,应仅导出推断类型。`})}const k=e({meta:{type:`problem`,docs:{description:`检查 Domain Implementation 包的导出是否符合规范`}},createOnce(e){return{before(){let t=e.filename;if(!me(t))return!1},ExportNamedDeclaration(t){if(t.source&&t.source.type===`Literal`&&typeof t.source.value==`string`)for(let n of t.specifiers){if(n.type!==`ExportSpecifier`)continue;let t=D(n);t&&O(t,n,e)}}}}});function A(e){let t=e.replace(/\\/g,`/`);return t.includes(`/domains/`)&&t.includes(`/implementation/src/index.ts`)}const j=[/\.\/typeorm/,/\.\/typeorm'/,/\.\/typeorm"/],M=[{pattern:/^[A-Z][a-zA-Z0-9]*OrmEntity$/,message:`禁止从主入口导出 ORM 实体。应使用 typeorm 入口导出。`},{pattern:/^[A-Z][a-zA-Z0-9]*Entity$/,message:`禁止从主入口导出 Entity 类。Entity 是内部实现,应使用 contract 包的 DTO。`},{pattern:/^[A-Z][a-zA-Z0-9]*UseCase$/,message:`禁止导出 UseCase 类。UseCase 是内部实现,应通过 Port 接口访问。`},{pattern:/^I[A-Z].*Repository$/,message:`禁止导出 Repository 接口。Repository 是内部接口,外部应通过 Port 访问。`},{pattern:/^create[A-Za-z]+Repository$/,message:`禁止导出 Repository 工厂函数。外部应使用 PortAdapter 工厂函数。`},{pattern:/^[A-Z][a-zA-Z0-9]*Repository[a-zA-Z0-9]*$/,message:`禁止导出 Repository 实现类。应使用工厂函数或 Port 接口。`},{pattern:/^[A-Z][a-zA-Z0-9]*Schema$/,message:`禁止导出 Schema 定义。Schema 是实现细节,应导出推断类型。`},{pattern:/_ORM_ENTITIES$/,message:`禁止从主入口导出实体集合。应使用 typeorm 入口导出。`},{pattern:/^[A-Z][a-zA-Z0-9]*OrmMapper$/,message:`禁止导出 ORM Mapper。这是基础设施实现细节。`},{pattern:/^[A-Z][a-zA-Z0-9]*Table$/,message:`禁止导出数据库表定义。这是数据存储细节。`}];function N(e){return j.some(t=>t.test(e))}function P(e){for(let{pattern:t,message:n}of M)if(t.test(e))return n;return null}function F(e,t){if(e.source){let n=e.source.type===`Literal`&&typeof e.source.value==`string`?e.source.value:null;if(n&&N(n)){t.report({node:e,message:`禁止从主入口重新导出 typeorm.ts 的内容。typeorm.ts 是专门的持久化入口。`});return}}if(e.specifiers){for(let n of e.specifiers)if(n.type===`ExportSpecifier`){let e=n.exported.type===`Identifier`?n.exported.name:n.exported.type===`Literal`&&typeof n.exported.value==`string`?n.exported.value:null;if(e){let r=P(e);r&&t.report({node:n,message:`${e}: ${r}`})}}}e.declaration&&R(e.declaration,t.report)}function I(e,t){if(e.source){let n=e.source.type===`Literal`&&typeof e.source.value==`string`?e.source.value:null;if(n&&N(n)){t.report({node:e,message:`禁止从主入口重新导出 typeorm.ts 的内容。typeorm.ts 是专门的持久化入口。`});return}}t.report({node:e,message:`禁止使用 export *。请使用显式导出,明确导出内容。`})}function L(e,t){z(e.declaration)&&R(e.declaration,t.report)}function R(e,t){if(e.type===`ClassDeclaration`&&e.id){let n=e.id.name,r=P(n);r&&t({node:e,message:`${n}: ${r}`})}else if(e.type===`VariableDeclaration`){for(let n of e.declarations)if(n.id.type===`Identifier`){let e=n.id.name,r=P(e);r&&t({node:n,message:`${e}: ${r}`})}}else if(e.type===`FunctionDeclaration`&&e.id){let n=e.id.name,r=P(n);r&&t({node:e,message:`${n}: ${r}`})}}function z(e){return e.type===`ClassDeclaration`||e.type===`FunctionDeclaration`||e.type===`VariableDeclaration`}const he=e({meta:{type:`problem`,docs:{description:`Implementation 包导出控制:禁止从主入口导出内部实现`}},createOnce(e){return{before(){let t=e.filename;if(!A(t))return!1},ExportNamedDeclaration(t){F(t,e)},ExportAllDeclaration(t){I(t,e)},ExportDefaultDeclaration(t){L(t,e)}}}}),ge=[{alias:`@main`,pathPattern:`src/main`},{alias:`@preload`,pathPattern:`src/preload`},{alias:`@renderer`,pathPattern:`src/renderer/src`},{alias:`@shared`,pathPattern:`src/shared`}];function _e(e){return typeof e==`object`&&!!e&&`packageBoundaries`in e}function B(e,t){let n=e.replace(/\\/g,`/`);for(let e of t){let t=e.pathPattern.replace(/\\/g,`/`);if(n.includes(`/${t}/`)||n.endsWith(`/${t}`)||n.includes(`/${t}\\`))return e.alias}return null}function ve(e,t,n){if(!t.startsWith(`.`))return null;let r=e.replace(/\\/g,`/`),i=r.lastIndexOf(`/`);return B(ye(i>0?r.substring(0,i):``,t),n)}function ye(e,t){let n=(e+`/`+t).split(`/`),r=[];for(let e of n)e===`..`?r.pop():e!==`.`&&e!==``&&r.push(e);return`/`+r.join(`/`)}function be(e){return e.startsWith(`./`)||e.startsWith(`../`)}const xe=e({meta:{type:`problem`,docs:{description:`禁止使用相对路径穿越不同包范围,强制使用别名导入`}},createOnce(e){let t=null;function n(){if(t===null){let n=e.options?.[0],r=n&&typeof n==`object`?n:{};t=_e(r)&&Array.isArray(r.packageBoundaries)?r.packageBoundaries:ge}return t}return{before(){n()},ImportDeclaration(t){let r=e.filename,i=t.source.type===`Literal`&&typeof t.source.value==`string`?t.source.value:null;if(!i||!be(i))return;let a=B(r,n());if(!a)return;let o=ve(r,i,n());o&&a!==o&&e.report({node:t,message:`禁止使用相对路径跨包导入。当前文件位于 "${a}" 包,目标位于 "${o}" 包。请使用别名导入:${o}/...`})}}}}),Se=[`get-port`,`get-port-plus`,`portfinder`,`detect-port`,`find-free-port`,`tcp-port-used`],Ce=[`getPort`,`getFreePort`,`detectPort`],we=[`findAvailablePort`,`findFreePort`,`getFreePort`,`getAvailablePort`,`isPortAvailable`,`isPortFree`,`checkPort`,`checkPortAvailable`,`detectPort`,`ensurePort`,`portCounter`],Te=[`__tests__/`,`.test.`,`.spec.`,`__mocks__/`],Ee=n.object({extraBannedModules:n.optional(n.array(n.string())),extraBannedImportNames:n.optional(n.array(n.string())),allowIdentifiers:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function V(e){let t=e.replace(/\\/g,`/`);return Te.some(e=>t.includes(e))}function De(e){let t=Ee.safeParse(e),n=t.success?t.data:{},r=new Set(n.allowIdentifiers??[]);return{bannedModules:/* @__PURE__ */ new Set([...Se,...n.extraBannedModules??[]]),bannedImportNames:/* @__PURE__ */ new Set([...Ce,...n.extraBannedImportNames??[]]),probingIdentifiers:new Set([...we].filter(e=>!r.has(e))),ignoreTests:n.ignoreTests??!0}}function H(e){return e.type===`Identifier`?e.name:null}function U(e,t){return`${e===`module`?`禁止引入端口探测库 "${t}"`:e===`importName`?`禁止引入端口探测函数 "${t}"`:`禁止声明端口探测标识符 "${t}"`}。端口获取统一走监听零口回读真实端口并经端口注册表注册,确需向子进程预派端口时以绑零口保留端口惯用法取系统分配口,正线见 ADR 0161。`}const Oe=e({meta:{type:`problem`,docs:{description:`禁止端口探测与避让处理,端口获取统一走端口注册表正线`}},createOnce(e){let t=null,n=!1;return{before(){if(t=De(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},ImportDeclaration(r){if(t&&n){if(t.bannedModules.has(r.source.value))e.report({node:r,message:U(`module`,r.source.value)});else for(let n of r.specifiers){if(n.type!==`ImportSpecifier`)continue;let r=n.imported.type===`Identifier`?n.imported.name:n.local.name;t.bannedImportNames.has(r)&&e.report({node:n,message:U(`importName`,r)})}}},FunctionDeclaration(r){t&&n&&r.id&&t.probingIdentifiers.has(r.id.name)&&e.report({node:r,message:U(`identifier`,r.id.name)})},MethodDefinition(r){if(!t||!n||r.computed)return;let i=H(r.key);i&&t.probingIdentifiers.has(i)&&e.report({node:r,message:U(`identifier`,i)})},PropertyDefinition(r){if(!t||!n||r.computed)return;let i=H(r.key);i&&t.probingIdentifiers.has(i)&&e.report({node:r,message:U(`identifier`,i)})},VariableDeclarator(r){t&&n&&r.id.type===`Identifier`&&t.probingIdentifiers.has(r.id.name)&&e.report({node:r,message:U(`identifier`,r.id.name)})}}}}),W=[`error`],G=[`logger`,`log`],K=e=>e.type!==`MemberExpression`||e.computed?null:e.property.type===`Identifier`?e.property.name:null,ke=e=>e.type!==`MemberExpression`||e.object.type!==`Identifier`?null:e.object.name,q=(e,t,n)=>{let r=K(e.callee);if(r===null||!t.has(r))return!1;let i=ke(e.callee);return i!==null&&n.has(i)},Ae=e=>{let t=K(e.callee);return t!==null&&t.toLowerCase().includes(`flush`)?!0:e.callee.type===`Identifier`&&e.callee.name.toLowerCase().includes(`flush`)},je=e=>e.callee.type!==`MemberExpression`||e.callee.object.type!==`Identifier`||e.callee.object.name!==`process`?!1:K(e.callee)===`exit`,Me=[`Error`],Ne=n.object({errorTypeNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function Pe(e){let t=Ne.safeParse(e),n=t.success?t.data:{};return{errorTypeNames:/* @__PURE__ */ new Set([...Me,...n.errorTypeNames??[]]),ignoreTests:n.ignoreTests??!0}}function Fe(e){return typeof e==`object`&&!!e&&`typeAnnotation`in e&&e.typeAnnotation!==null&&typeof e.typeAnnotation==`object`}function Ie(e,t){if(typeof e!=`object`||!e)return!1;let n=`type`in e&&e.type===`TSTypeReference`&&`typeName`in e&&e.typeName!==null?e.typeName:e;return typeof n!=`object`||!n?!1:`name`in n&&typeof n.name==`string`&&t.has(n.name)}const Le=e({meta:{type:`problem`,docs:{description:`禁止 as Error 类型断言,catch 的 unknown 经标准件 ensureError 取错误对象`}},createOnce(e){let t=null,n=!1;return{before(){if(t=Pe(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},TSAsExpression(r){t&&n&&Fe(r)&&Ie(r.typeAnnotation,t.errorTypeNames)&&e.report({node:r,message:`禁止 as Error 类型断言。catch 的 unknown 经标准件 ensureError 取错误对象或消息,正线见 error-handling 台账工作流 001 判据 1 与 ADR 0166。`})}}}}),Re=n.object({methodNames:n.optional(n.array(n.string())),objectNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function ze(e){let t=Re.safeParse(e),n=t.success?t.data:{};return{methodNames:/* @__PURE__ */ new Set([...W,...n.methodNames??[]]),loggerObjects:/* @__PURE__ */ new Set([...G,...n.objectNames??[]]),ignoreTests:n.ignoreTests??!0}}const Be=e({meta:{type:`problem`,docs:{description:`禁止 error 日志后裸 process exit,退出前一律经 flushAndExit 刷缓冲`}},createOnce(e){let t=null,n=!1;return{before(){if(t=ze(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},BlockStatement(r){if(!t||!n)return;let i=!1;for(let n of r.body){if(n.type!==`ExpressionStatement`)continue;let r=n.expression;r.type===`CallExpression`&&(Ae(r)?i=!1:q(r,t.methodNames,t.loggerObjects)?i=!0:je(r)&&i&&e.report({node:n,message:`error 日志后裸调用 process.exit 会吞掉缓冲中的致命日志。退出前一律经 flushAndExit 刷缓冲后退出,正线见 error-handling 台账工作流 002 判据 4。`}))}}}}});function Ve(e){return e.replace(/\\/g,`/`).includes(`/apps/`)}function He(e){return/-implementation(\/|$)/.test(e)}function Ue(e){return e.endsWith(`Entity`)}function We(e){return e.endsWith(`UseCase`)}function Ge(e){return[/PortAdapter$/,/_TOKEN$/,/^create\w+Repository$/,/^create\w+Adapter$/].some(t=>t.test(e))}const Ke=e({meta:{type:`problem`,docs:{description:`禁止在 apps 层导入 implementation 包的 Entity 和 UseCase`}},createOnce(e){return{before(){let t=e.filename;if(!Ve(t))return!1},ImportDeclaration(t){let n=t.source.type===`Literal`&&typeof t.source.value==`string`?t.source.value:null;if(n&&He(n))for(let n of t.specifiers){if(n.type!==`ImportSpecifier`)continue;let t=n.imported.type===`Identifier`?n.imported.name:null;t&&(Ue(t)?e.report({node:n,message:`禁止在 apps 层导入 Entity 类 "${t}"。请使用 contract 包的 Port 接口进行操作。`}):We(t)?e.report({node:n,message:`禁止在 apps 层导入 UseCase 类 "${t}"。请使用 contract 包的 Port 接口进行操作。`}):Ge(t)||e.report({node:n,message:`禁止在 apps 层从 implementation 包导入 "${t}"。请使用 contract 包的 Port 接口。`}))}}}}}),qe=[`Error`],Je=n.object({errorTypeNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function Ye(e){let t=Je.safeParse(e),n=t.success?t.data:{};return{errorTypeNames:/* @__PURE__ */ new Set([...qe,...n.errorTypeNames??[]]),ignoreTests:n.ignoreTests??!0}}const Xe=e({meta:{type:`problem`,docs:{description:`禁止内联三元归一化副本,unknown 转 Error 一律经标准件 ensureError`}},createOnce(e){let t=null,n=!1;return{before(){if(t=Ye(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},ConditionalExpression(r){if(!t||!n)return;let i=r.test;i.type===`BinaryExpression`&&i.operator===`instanceof`&&i.right.type===`Identifier`&&t.errorTypeNames.has(i.right.name)&&e.report({node:r,message:`禁止内联三元归一化副本。unknown 转 Error 一律经标准件 ensureError,纯日志位直传 logger 吸收汇,正线见 error-handling 台账工作流 001 判据 1 与判据 2 及 ADR 0166。`})}}}}),Ze=n.object({functionName:n.string(),forbiddenPaths:n.array(n.string()),message:n.optional(n.string())}),Qe=n.object({restrictions:n.array(Ze)});function J(e,t){let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`);if(!r.includes(`*`))return n.includes(r);let i=r.split(`*`).map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`[^/]+`);return new RegExp(i).test(n)}function $e(e,t){return t.some(t=>J(e,t))}function et(e){let t=Qe.safeParse(e);return t.success?t.data.restrictions:[]}function tt(e){return e.type===`Identifier`?e.name:e.type===`MemberExpression`&&e.property&&!e.computed&&e.property.type===`Identifier`?e.property.name:null}const nt=e({meta:{type:`problem`,docs:{description:`禁止在指定路径中调用特定函数,强制架构约束`}},createOnce(e){let t=[],n=/* @__PURE__ */ new Set;return{before(){let r=e.options?.[0];if(t=et(r),t.length===0)return!1;n=/* @__PURE__ */ new Set;for(let r=0;r<t.length;r++){let i=t[r];i&&$e(e.filename,i.forbiddenPaths)&&n.add(r)}if(n.size===0)return!1},CallExpression(r){let i=tt(r.callee);if(i)for(let a of n){let n=t[a];if(!n||i!==n.functionName)continue;let o=n.message??`禁止在当前路径中调用 "${n.functionName}"`;e.report({node:r,message:o})}}}}}),rt=[`fetch`,`axios`],it=[`XMLHttpRequest`,`EventSource`,`WebSocket`],at=[`domains/*/ui/`,`packages/ui/`,`packages/*-ui/`],ot=new Set(it),st=[`__tests__/`,`.test.`,`.spec.`,`__mocks__/`],ct=n.object({uiPathPatterns:n.optional(n.array(n.string())),extraFunctionNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function lt(e,t){return t.some(t=>J(e,t))}function ut(e){let t=e.replace(/\\/g,`/`);return st.some(e=>t.includes(e))}function dt(e){let t=ct.safeParse(e),n=t.success?t.data:{};return{uiPathPatterns:n.uiPathPatterns??[...at],rawCallNames:/* @__PURE__ */ new Set([...rt,...n.extraFunctionNames??[]]),ignoreTests:n.ignoreTests??!0}}function ft(e,t){return e.type===`Identifier`?t.has(e.name)?e.name:null:e.type===`MemberExpression`&&!e.computed&&e.object.type===`Identifier`&&t.has(e.object.name)?e.property.type===`Identifier`?`${e.object.name}.${e.property.name}`:e.object.name:null}function pt(e){return e.type===`Identifier`&&ot.has(e.name)?e.name:null}function Y(e){return`UI 层禁止手写网络调用 "${e}"。网络消费统一经生成式 sdk 客户端端点加 transport 通道注入,正线见 ADR 0127 与 sdk 治理台账工作流 002。`}const mt=e({meta:{type:`problem`,docs:{description:`禁止 UI 层手写网络调用,消费面统一经生成式 sdk 客户端`}},createOnce(e){let t=null,n=!1;return{before(){if(t=dt(e.options?.[0]),n=!(t.ignoreTests&&ut(e.filename))&&lt(e.filename,t.uiPathPatterns),!n)return!1},CallExpression(r){if(!t||!n)return;let i=ft(r.callee,t.rawCallNames);i&&e.report({node:r,message:Y(i)})},NewExpression(r){if(!t||!n)return;let i=pt(r.callee);i&&e.report({node:r,message:Y(i)})}}}}),ht=n.object({importSource:n.string(),importNames:n.optional(n.array(n.string())),forbiddenPaths:n.array(n.string()),message:n.optional(n.string())}),gt=n.object({restrictions:n.array(ht)});function _t(e,t,n){return e===n.importSource?!n.importNames||n.importNames.length===0?t.length>0:t.some(e=>n.importNames?.includes(e)??!1):!1}function vt(e){let t=[];for(let n of e)n.type===`ImportSpecifier`&&n.imported.type===`Identifier`?t.push(n.imported.name):n.type===`ImportDefaultSpecifier`&&t.push(n.local.name);return t}function yt(e){let t=gt.safeParse(e);return t.success?t.data.restrictions:[]}function bt(e,t){return t.some(t=>J(e,t))}const xt=e({meta:{type:`problem`,docs:{description:`禁止在指定路径中导入特定模块,强制架构约束`},schema:[{type:`object`,properties:{restrictions:{type:`array`,items:{type:`object`,properties:{importSource:{type:`string`},importNames:{type:`array`,items:{type:`string`}},forbiddenPaths:{type:`array`,items:{type:`string`}},message:{type:`string`}},required:[`importSource`,`forbiddenPaths`],additionalProperties:!1}}},additionalProperties:!1}]},createOnce(e){let t=[],n=/* @__PURE__ */ new Set;return{before(){let r=e.options?.[0];if(t=yt(r),t.length===0)return!1;n=/* @__PURE__ */ new Set;for(let r=0;r<t.length;r++){let i=t[r];i&&bt(e.filename,i.forbiddenPaths)&&n.add(r)}if(n.size===0)return!1},ImportDeclaration(r){let i=r.source.value;if(typeof i!=`string`)return;let a=vt(r.specifiers??[]);for(let o of n){let n=t[o];if(!n||!_t(i,a,n))continue;let s=n.importNames?a.filter(e=>n.importNames?.includes(e)??!1):a;for(let t of s){let i=n.message??`禁止在当前路径中导入 "${t}"(来源:${n.importSource})`;e.report({node:r,message:i})}}}}}}),St=/* @__PURE__ */ new Set([`port`,`hostname`]),Ct=n.object({ignoreTests:n.optional(n.boolean())});function wt(e){let t=Ct.safeParse(e);return{ignoreTests:(t.success?t.data:{}).ignoreTests??!0}}function Tt(e){return e.type===`Identifier`?e.name:null}function Et(e){return e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`&&e.property.name===`listen`}function Dt(e){return e.type===`MemberExpression`&&!e.computed&&e.object.type===`Identifier`&&e.object.name===`Bun`&&e.property.type===`Identifier`&&e.property.name===`serve`}function Ot(e){let t=!1;for(let n of e.properties){if(n.type!==`Property`||n.computed)continue;let e=Tt(n.key);if(e!==null&&(St.has(e)&&(t=!0),e===`reusePort`))return n.value.type===`Literal`&&n.value.value===!1}return!t&&null}function kt(e){return`${e===`listen`?`监听选项禁止依赖 reusePort 默认值`:`Bun.serve 选项禁止依赖 reusePort 默认值`}。Elysia 适配器默认开启端口共存绑定使冲突静默共享,显式置 reusePort 为 false 使端口冲突即崩溃快速失败,正线见 ADR 0195。`}const X=e({meta:{type:`problem`,docs:{description:`禁止监听选项依赖 reusePort 默认值,端口冲突统一显性快速失败`}},createOnce(e){let t=null,n=!1;return{before(){if(t=wt(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},CallExpression(r){if(!t||!n)return;let i=Dt(r.callee)?`bunServe`:Et(r.callee)?`listen`:null;if(i===null)return;let a=r.arguments[0];a!==void 0&&a.type===`ObjectExpression`&&Ot(a)===!1&&e.report({node:r,message:kt(i)})}}}}),At=n.object({methodNames:n.optional(n.array(n.string())),objectNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function jt(e){let t=At.safeParse(e),n=t.success?t.data:{};return{methodNames:/* @__PURE__ */ new Set([...W,...n.methodNames??[]]),loggerObjects:/* @__PURE__ */ new Set([...G,...n.objectNames??[]]),ignoreTests:n.ignoreTests??!0}}const Mt=e({meta:{type:`problem`,docs:{description:`禁止错误日志模板拼接 message,改为结构化第二参直传错误值`}},createOnce(e){let t=null,n=!1;return{before(){if(t=jt(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},CallExpression(r){if(!t||!n||!q(r,t.methodNames,t.loggerObjects))return;let i=r.arguments[0];if(!i||i.type===`SpreadElement`)return;let a=i.type===`TemplateLiteral`&&i.expressions.length>0,o=i.type===`BinaryExpression`&&i.operator===`+`;(a||o)&&e.report({node:r,message:`错误日志禁止模板拼接 message。模板拼接吞掉错误对象的 cause 与 stack 与 code,消息写固定文案并以第二参直传错误值由 logger 吸收汇归一化,正线见 error-handling 台账工作流 002 判据 1 与 ADR 0166。`})}}}}),Nt=n.object({methodNames:n.optional(n.array(n.string())),objectNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function Pt(e){let t=Nt.safeParse(e),n=t.success?t.data:{};return{methodNames:/* @__PURE__ */ new Set([...W,...n.methodNames??[]]),loggerObjects:/* @__PURE__ */ new Set([...G,...n.objectNames??[]]),ignoreTests:n.ignoreTests??!0}}const Ft=e({meta:{type:`problem`,docs:{description:`禁止纯文案错误日志,无底层错误时错误参数位显式传 undefined 并附业务上下文`}},createOnce(e){let t=null,n=!1;return{before(){if(t=Pt(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},CallExpression(r){t&&n&&q(r,t.methodNames,t.loggerObjects)&&r.arguments.length<2&&e.report({node:r,message:`错误日志禁止纯文案形态。无底层错误对象的业务校验场景在错误参数位显式传 undefined 并附业务上下文,正线见 error-handling 台账工作流 002 判据 2 与 ADR 0166。`})}}}}),It=[`vite.config.`],Lt=[`portDiscovery`],Rt=n.object({viteConfigPatterns:n.optional(n.array(n.string())),registerMarkers:n.optional(n.array(n.string()))});function zt(e){let t=Rt.safeParse(e),n=t.success?t.data:{};return{viteConfigPatterns:n.viteConfigPatterns??[...It],registerMarkers:/* @__PURE__ */ new Set([...Lt,...n.registerMarkers??[]])}}function Bt(e,t){let n=e.replace(/\\/g,`/`).split(`/`).pop()??``;return t.some(e=>n.includes(e))}function Z(e){return e.computed||e.key.type!==`Identifier`||e.value.type!==`Literal`?null:{key:e.key.name,value:e.value.value}}function Vt(){return`vite 配置禁止置 strictPort 为 false 依赖占用自动加一。端口面统一置 strictPort 为 true 快速失败,或 port 置 0 配合 portDiscovery 注册,正线见 ADR 0161。`}function Ht(e){return`vite 配置写死端口 ${e} 且未置 strictPort 为 true,占用时将静默改用相邻端口。端口面统一置 strictPort 为 true 快速失败,或 port 置 0 配合 portDiscovery 注册,正线见 ADR 0161。`}const Q={"dependency-direction":pe,"business-leak":u,"no-cross-package-relative-import":xe,"domain-export-compliance":k,"implementation-export-control":he,"no-implementation-import-in-apps":Ke,"no-restricted-call-in-paths":nt,"no-restricted-import-in-paths":xt,"no-raw-network-call-in-ui":mt,"no-port-probing":Oe,"no-vite-port-fallback":e({meta:{type:`problem`,docs:{description:`禁止 vite 配置依赖端口占用自动加一,端口面统一快速失败或注册表注册`}},createOnce(e){let t=null,n=!1,r={hasRegisterMarker:!1,hasStrictPortTrue:!1,strictPortFalseNodes:[],positivePortNodes:[]};return{before(){if(t=zt(e.options?.[0]),n=Bt(e.filename,t.viteConfigPatterns),r.hasRegisterMarker=!1,r.hasStrictPortTrue=!1,r.strictPortFalseNodes=[],r.positivePortNodes=[],!n)return!1},ImportDeclaration(e){if(t&&n)for(let n of e.specifiers)n.type===`ImportSpecifier`&&n.local.name&&t.registerMarkers.has(n.local.name)&&(r.hasRegisterMarker=!0)},CallExpression(e){t&&n&&e.callee.type===`Identifier`&&t.registerMarkers.has(e.callee.name)&&(r.hasRegisterMarker=!0)},Property(e){if(!t||!n)return;let i=Z(e);i&&(i.key===`strictPort`?i.value===!0?r.hasStrictPortTrue=!0:i.value===!1&&r.strictPortFalseNodes.push(e):i.key===`port`&&typeof i.value==`number`&&i.value>0&&r.positivePortNodes.push(e))},"Program:exit"(){if(t&&n&&!r.hasRegisterMarker){for(let t of r.strictPortFalseNodes)e.report({node:t,message:Vt()});if(!r.hasStrictPortTrue)for(let t of r.positivePortNodes){let n=Z(t);e.report({node:t,message:Ht(typeof n?.value==`number`?n.value:0)})}}}}}}),"no-reuseport-default":X,"no-template-error-log":Mt,"no-text-only-error-log":Ft,"no-exit-after-error-log":Be,"no-inline-error-normalization":Xe,"no-error-type-assertion":Le},$=t({meta:{name:`@longzai-intelligence-oxlint/architecture-core-plugin`},rules:Q});export{$ as architectureCorePlugin,$ as default,Q as coreRules};
1
+ import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";import*as n from"zod/mini";const r=[`/packages/platform/`,`/packages/ui/`,`/packages/ui-kit/`,`/packages/engine/`,`/packages/utils/`,`/packages/types/`],i=[],a=[`^validate`,`^calculate`,`^compute`,`^determine`,`^check`,`^can`,`^should`,`^isAllowed`,`^isPermitted`,`^hasPermission`,`^applyRule`,`^enforce`,`^execute`];function o(e){return typeof e==`object`&&!!e}function s(e){let t=Array.isArray(e)?e[0]:e;return o(t)?{techLayerPatterns:t.techLayerPatterns??r,businessKeywords:t.businessKeywords??i,businessRuleMethods:t.businessRuleMethods??a}:{techLayerPatterns:r,businessKeywords:i,businessRuleMethods:a}}function c(e){return e.map(e=>new RegExp(e))}function ee(e,t){let n=e.replace(/\\/g,`/`);return t.some(e=>e.test(n))}function l(e,t){let n=e.charAt(0).toUpperCase()+e.slice(1);return t.some(e=>n.includes(e))}function te(e,t){return t.some(t=>t.test(e))}const u=e({meta:{type:`suggestion`,docs:{description:`检测技术层中可能存在的业务逻辑`}},createOnce(e){let t=[],n=[],r=[];return{before(){let i=s(e.options);return t=c(i.techLayerPatterns),n=i.businessKeywords,r=c(i.businessRuleMethods),ee(e.filename,t)?void 0:!1},ClassDeclaration(t){t.id&&l(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关类 '${t.id.name}'。业务逻辑应该放在 domains/ 层。`})},MethodDefinition(t){t.key.type===`Identifier`&&te(t.key.name,r)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务规则方法 '${t.key.name}'。业务规则应该放在 domains/ 层。`})},TSInterfaceDeclaration(t){l(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关接口 '${t.id.name}'。业务接口应该放在 domains/ 层。`})},TSTypeAliasDeclaration(t){l(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关类型 '${t.id.name}'。业务类型应该放在 domains/ 层。`})}}}}),d={types:0,utils:1,"shared-kernel":2,contract:3,engine:4,platform:5,infrastructure:6,implementation:6,domain:6,capability:7,ui:7,"electron-shared":7,"electron-main":8,"electron-preload":8,"electron-renderer":9},ne={types:`类型层 (Types)`,utils:`工具层 (Utils)`,"shared-kernel":`共享内核层 (Shared Kernel)`,contract:`契约层 (Contract)`,engine:`引擎层 (Engine)`,platform:`平台层 (Platform)`,infrastructure:`基础设施层 (Infrastructure)`,implementation:`实现层 (Implementation)`,domain:`门面层 (Domain Facade)`,capability:`能力装配层 (Capability)`,ui:`UI 表现层`,"electron-shared":`Electron 共享层 (Shared)`,"electron-main":`Electron 主进程 (Main)`,"electron-preload":`Electron 预加载层 (Preload)`,"electron-renderer":`Electron 渲染进程 (Renderer)`},re=new Set(Object.keys(d)),f={pathPatterns:[{pattern:/\/apps\/capabilities\//,layer:`capability`},{pattern:/\/domains\/[^/]+\/implementation\//,layer:`implementation`},{pattern:/\/domains\/[^/]+\/contract\//,layer:`contract`},{pattern:/\/domains\/[^/]+\/ui\//,layer:`ui`},{pattern:/\/domains\/shared-kernel\//,layer:`shared-kernel`},{pattern:/\/infrastructure\//,layer:`infrastructure`}],packagePrefix:``,specialPackageMappings:{},packageSuffixMappings:[{suffix:`-contract`,layer:`contract`},{suffix:`-implementation`,layer:`implementation`},{suffix:`-infrastructure`,layer:`infrastructure`},{suffix:`-domain`,layer:`domain`},{suffix:`-ui`,layer:`ui`},{suffix:`-engine`,layer:`engine`},{suffix:`-runtime`,layer:`engine`}]},p=[{from:`capability`,to:`implementation`},{from:`capability`,to:`infrastructure`},{from:`ui`,to:`domain`,hint:`UI 面禁止经门面包取件,域外依赖唯一指向生成式 sdk 客户端,ADR 0127。`},{from:`ui`,to:`contract`,hint:`contract 为 DDD 主体对 UI 全封闭,类型正源为 sdk 生成契约推断类型,ADR 0127。`},{from:`ui`,to:`implementation`,hint:`UI 面禁止直连实现层,域外依赖唯一指向生成式 sdk 客户端,ADR 0127。`},{from:`ui`,to:`infrastructure`,hint:`UI 面禁止直连基础设施层,域外依赖唯一指向生成式 sdk 客户端,ADR 0127。`}],m=[`-main`],h=[{pattern:/\/src\/domain\//,layer:`contract`},{pattern:/\/src\/engine\//,layer:`engine`},{pattern:/\/src\/platform\//,layer:`platform`},{pattern:/\/src\/infrastructure\//,layer:`infrastructure`},{pattern:/\/src\/shared\//,layer:`shared-kernel`}];function g(e){return re.has(e)}function ie(e,t){return d[e]>=d[t]}function _(e){return ne[e]}function ae(e,t){let n=e.replace(/\\/g,`/`),r=t??f.pathPatterns;if(r){for(let{pattern:e,layer:t}of r)if(e.test(n))return{layer:t,priority:d[t]}}if(n.includes(`/apps/`)){for(let{pattern:e,layer:t}of h)if(e.test(n))return{layer:t,priority:d[t]}}if(n.includes(`/packages/`)){for(let{pattern:e,layer:t}of h)if(e.test(n))return{layer:t,priority:d[t]}}return null}function v(e,t){if(!e.startsWith(t))return null;let n=e.split(`/`),r=n[0]===``?n.slice(1):n;return(r[0]?.startsWith(`@`)?r[1]:r[0])??null}function oe(e,t){for(let n of t)if(e.endsWith(n))return n;return null}function se(e,t){let n=t.packagePrefix??``,r=v(e,n);if(!r)return null;let i=(t.specialPackageMappings??{})[`${n}${r}`];if(i)return{layer:i,priority:d[i]};let a=t.packageSuffixMappings??[];for(let{suffix:e,layer:t}of a)if(r.endsWith(e))return{layer:t,priority:d[t]};return null}function ce(e,t,n){return e.find(e=>e.from===t&&e.to===n)??null}function le(e){let t=e.match(/^\/(.+)\/([gimsuvy]*)$/);return t?.[1]?new RegExp(t[1],t[2]??``):new RegExp(e)}function ue(e){let t={};if(e.pathPatterns&&(t.pathPatterns=e.pathPatterns.reduce((e,{pattern:t,layer:n})=>(g(n)&&e.push({pattern:le(t),layer:n}),e),[])),e.packagePrefix&&(t.packagePrefix=e.packagePrefix),e.specialPackageMappings){let n={};for(let[t,r]of Object.entries(e.specialPackageMappings))g(r)&&(n[t]=r);t.specialPackageMappings=Object.keys(n).length>0?n:void 0}if(e.packageSuffixMappings){let n=[];for(let{suffix:t,layer:r}of e.packageSuffixMappings)g(r)&&n.push({suffix:t,layer:r});t.packageSuffixMappings=n.length>0?n:void 0}if(e.forbiddenLayerPairs){let n=[];for(let{from:t,to:r}of e.forbiddenLayerPairs)g(t)&&g(r)&&n.push({from:t,to:r});t.forbiddenLayerPairs=n.length>0?n:void 0}if(e.forbiddenPackageSuffixes){let n=e.forbiddenPackageSuffixes.filter(e=>e.length>0);t.forbiddenPackageSuffixes=n.length>0?n:void 0}return t}function de(e){return typeof e==`object`&&!!e}function fe(e){let t=ue(de(e)?e:{});return{pathPatterns:t.pathPatterns??f.pathPatterns,packagePrefix:t.packagePrefix??f.packagePrefix,specialPackageMappings:t.specialPackageMappings??f.specialPackageMappings,packageSuffixMappings:t.packageSuffixMappings??f.packageSuffixMappings,forbiddenLayerPairs:[...p,...t.forbiddenLayerPairs??[]],forbiddenPackageSuffixes:[...m,...t.forbiddenPackageSuffixes??[]]}}const pe=e({meta:{type:`problem`,docs:{description:`强制执行 Clean Architecture 的依赖方向规则`},schema:[{type:`object`,properties:{pathPatterns:{type:`array`,items:{type:`object`,properties:{pattern:{type:`string`},layer:{type:`string`}},required:[`pattern`,`layer`],additionalProperties:!1}},packagePrefix:{type:`string`},specialPackageMappings:{type:`object`,additionalProperties:{type:`string`}},packageSuffixMappings:{type:`array`,items:{type:`object`,properties:{suffix:{type:`string`},layer:{type:`string`}},required:[`suffix`,`layer`],additionalProperties:!1}},forbiddenLayerPairs:{type:`array`,items:{type:`object`,properties:{from:{type:`string`},to:{type:`string`}},required:[`from`,`to`],additionalProperties:!1}},forbiddenPackageSuffixes:{type:`array`,items:{type:`string`}}},additionalProperties:!1}]},createOnce(e){let t=null,n=null;return{before(){return t===null&&(t=fe(e.options?.[0])),n=ae(e.filename,t.pathPatterns),n!==null},ImportDeclaration(r){if(!n||!t)return;let i=r.source.type===`Literal`&&typeof r.source.value==`string`?r.source.value:null;if(!i)return;let a=v(i,t.packagePrefix??``);if(a){let n=oe(a,t.forbiddenPackageSuffixes??[]);if(n){e.report({node:r,message:`禁止导入已禁用的 ${n} 门面包,门面包统一使用 -domain 后缀。`});return}}let o=se(i,t);if(!o)return;let s=ce(t.forbiddenLayerPairs??[],n.layer,o.layer);s?e.report({node:r,message:`依赖方向违规: ${n.layer} (${_(n.layer)}) 不能导入 ${o.layer} (${_(o.layer)})。${s.hint??`域内取件必须经 -domain 门面包。`}`}):ie(n.layer,o.layer)||e.report({node:r,message:`依赖方向违规: ${n.layer} (${_(n.layer)}) 不能导入 ${o.layer} (${_(o.layer)})。依赖应该从外层指向内层。`})}}}});function me(e){let t=e.replace(/\\/g,`/`);return t.includes(`/domains/`)&&t.includes(`/implementation/src/index.ts`)}function y(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function b(e){return y(e)&&e.endsWith(`Entity`)}function x(e){return y(e)&&e.endsWith(`Repository`)&&!e.startsWith(`I`)}function S(e){return y(e)&&e.endsWith(`OrmEntity`)}function C(e){return e.endsWith(`_ORM_ENTITIES`)}function w(e){return y(e)&&e.endsWith(`OrmMapper`)}function T(e){return y(e)&&e.endsWith(`Schema`)}function E(e){return`exportKind`in e&&typeof e.exportKind==`string`?e.exportKind===`value`:!0}function D(e){return e.exported.type===`Identifier`?e.exported.name:e.exported.type===`Literal`&&typeof e.exported.value==`string`?e.exported.value:null}function O(e,t,n){b(e)&&E(t)?n.report({node:t,message:`禁止从主入口值导出 Entity 类 "${e}"。请改为类型导出或移除导出。`}):x(e)?n.report({node:t,message:`禁止导出 Repository 类型 "${e}"。Repository 是内部实现,不应暴露给外部。`}):S(e)?n.report({node:t,message:`禁止从主入口导出 ORM 实体 "${e}"。请创建 src/typeorm.ts 入口文件,从该入口导出。`}):C(e)?n.report({node:t,message:`禁止从主入口导出 ORM 实体集合 "${e}"。请创建 src/typeorm.ts 入口文件,从该入口导出。`}):w(e)?n.report({node:t,message:`禁止导出 ORM Mapper "${e}"。ORM Mapper 是基础设施实现细节,不应暴露给外部。`}):T(e)&&n.report({node:t,message:`禁止导出 Schema 定义 "${e}"。Schema 是实现细节,应仅导出推断类型。`})}const k=e({meta:{type:`problem`,docs:{description:`检查 Domain Implementation 包的导出是否符合规范`}},createOnce(e){return{before(){let t=e.filename;if(!me(t))return!1},ExportNamedDeclaration(t){if(t.source&&t.source.type===`Literal`&&typeof t.source.value==`string`)for(let n of t.specifiers){if(n.type!==`ExportSpecifier`)continue;let t=D(n);t&&O(t,n,e)}}}}});function A(e){let t=e.replace(/\\/g,`/`);return t.includes(`/domains/`)&&t.includes(`/implementation/src/index.ts`)}const j=[/\.\/typeorm/,/\.\/typeorm'/,/\.\/typeorm"/],M=[{pattern:/^[A-Z][a-zA-Z0-9]*OrmEntity$/,message:`禁止从主入口导出 ORM 实体。应使用 typeorm 入口导出。`},{pattern:/^[A-Z][a-zA-Z0-9]*Entity$/,message:`禁止从主入口导出 Entity 类。Entity 是内部实现,应使用 contract 包的 DTO。`},{pattern:/^[A-Z][a-zA-Z0-9]*UseCase$/,message:`禁止导出 UseCase 类。UseCase 是内部实现,应通过 Port 接口访问。`},{pattern:/^I[A-Z].*Repository$/,message:`禁止导出 Repository 接口。Repository 是内部接口,外部应通过 Port 访问。`},{pattern:/^create[A-Za-z]+Repository$/,message:`禁止导出 Repository 工厂函数。外部应使用 PortAdapter 工厂函数。`},{pattern:/^[A-Z][a-zA-Z0-9]*Repository[a-zA-Z0-9]*$/,message:`禁止导出 Repository 实现类。应使用工厂函数或 Port 接口。`},{pattern:/^[A-Z][a-zA-Z0-9]*Schema$/,message:`禁止导出 Schema 定义。Schema 是实现细节,应导出推断类型。`},{pattern:/_ORM_ENTITIES$/,message:`禁止从主入口导出实体集合。应使用 typeorm 入口导出。`},{pattern:/^[A-Z][a-zA-Z0-9]*OrmMapper$/,message:`禁止导出 ORM Mapper。这是基础设施实现细节。`},{pattern:/^[A-Z][a-zA-Z0-9]*Table$/,message:`禁止导出数据库表定义。这是数据存储细节。`}];function N(e){return j.some(t=>t.test(e))}function P(e){for(let{pattern:t,message:n}of M)if(t.test(e))return n;return null}function F(e,t){if(e.source){let n=e.source.type===`Literal`&&typeof e.source.value==`string`?e.source.value:null;if(n&&N(n)){t.report({node:e,message:`禁止从主入口重新导出 typeorm.ts 的内容。typeorm.ts 是专门的持久化入口。`});return}}if(e.specifiers){for(let n of e.specifiers)if(n.type===`ExportSpecifier`){let e=n.exported.type===`Identifier`?n.exported.name:n.exported.type===`Literal`&&typeof n.exported.value==`string`?n.exported.value:null;if(e){let r=P(e);r&&t.report({node:n,message:`${e}: ${r}`})}}}e.declaration&&R(e.declaration,t.report)}function I(e,t){if(e.source){let n=e.source.type===`Literal`&&typeof e.source.value==`string`?e.source.value:null;if(n&&N(n)){t.report({node:e,message:`禁止从主入口重新导出 typeorm.ts 的内容。typeorm.ts 是专门的持久化入口。`});return}}t.report({node:e,message:`禁止使用 export *。请使用显式导出,明确导出内容。`})}function L(e,t){z(e.declaration)&&R(e.declaration,t.report)}function R(e,t){if(e.type===`ClassDeclaration`&&e.id){let n=e.id.name,r=P(n);r&&t({node:e,message:`${n}: ${r}`})}else if(e.type===`VariableDeclaration`){for(let n of e.declarations)if(n.id.type===`Identifier`){let e=n.id.name,r=P(e);r&&t({node:n,message:`${e}: ${r}`})}}else if(e.type===`FunctionDeclaration`&&e.id){let n=e.id.name,r=P(n);r&&t({node:e,message:`${n}: ${r}`})}}function z(e){return e.type===`ClassDeclaration`||e.type===`FunctionDeclaration`||e.type===`VariableDeclaration`}const he=e({meta:{type:`problem`,docs:{description:`Implementation 包导出控制:禁止从主入口导出内部实现`}},createOnce(e){return{before(){let t=e.filename;if(!A(t))return!1},ExportNamedDeclaration(t){F(t,e)},ExportAllDeclaration(t){I(t,e)},ExportDefaultDeclaration(t){L(t,e)}}}}),ge=[{alias:`@main`,pathPattern:`src/main`},{alias:`@preload`,pathPattern:`src/preload`},{alias:`@renderer`,pathPattern:`src/renderer/src`},{alias:`@shared`,pathPattern:`src/shared`}];function _e(e){return typeof e==`object`&&!!e&&`packageBoundaries`in e}function B(e,t){let n=e.replace(/\\/g,`/`);for(let e of t){let t=e.pathPattern.replace(/\\/g,`/`);if(n.includes(`/${t}/`)||n.endsWith(`/${t}`)||n.includes(`/${t}\\`))return e.alias}return null}function ve(e,t,n){if(!t.startsWith(`.`))return null;let r=e.replace(/\\/g,`/`),i=r.lastIndexOf(`/`);return B(ye(i>0?r.substring(0,i):``,t),n)}function ye(e,t){let n=(e+`/`+t).split(`/`),r=[];for(let e of n)e===`..`?r.pop():e!==`.`&&e!==``&&r.push(e);return`/`+r.join(`/`)}function be(e){return e.startsWith(`./`)||e.startsWith(`../`)}const xe=e({meta:{type:`problem`,docs:{description:`禁止使用相对路径穿越不同包范围,强制使用别名导入`}},createOnce(e){let t=null;function n(){if(t===null){let n=e.options?.[0],r=n&&typeof n==`object`?n:{};t=_e(r)&&Array.isArray(r.packageBoundaries)?r.packageBoundaries:ge}return t}return{before(){n()},ImportDeclaration(t){let r=e.filename,i=t.source.type===`Literal`&&typeof t.source.value==`string`?t.source.value:null;if(!i||!be(i))return;let a=B(r,n());if(!a)return;let o=ve(r,i,n());o&&a!==o&&e.report({node:t,message:`禁止使用相对路径跨包导入。当前文件位于 "${a}" 包,目标位于 "${o}" 包。请使用别名导入:${o}/...`})}}}}),Se=[`get-port`,`get-port-plus`,`portfinder`,`detect-port`,`find-free-port`,`tcp-port-used`],Ce=[`getPort`,`getFreePort`,`detectPort`],we=[`findAvailablePort`,`findFreePort`,`getFreePort`,`getAvailablePort`,`isPortAvailable`,`isPortFree`,`checkPort`,`checkPortAvailable`,`detectPort`,`ensurePort`,`portCounter`],Te=[`__tests__/`,`.test.`,`.spec.`,`__mocks__/`],Ee=n.object({extraBannedModules:n.optional(n.array(n.string())),extraBannedImportNames:n.optional(n.array(n.string())),allowIdentifiers:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function V(e){let t=e.replace(/\\/g,`/`);return Te.some(e=>t.includes(e))}function De(e){let t=Ee.safeParse(e),n=t.success?t.data:{},r=new Set(n.allowIdentifiers??[]);return{bannedModules:/* @__PURE__ */ new Set([...Se,...n.extraBannedModules??[]]),bannedImportNames:/* @__PURE__ */ new Set([...Ce,...n.extraBannedImportNames??[]]),probingIdentifiers:new Set([...we].filter(e=>!r.has(e))),ignoreTests:n.ignoreTests??!0}}function H(e){return e.type===`Identifier`?e.name:null}function U(e,t){return`${e===`module`?`禁止引入端口探测库 "${t}"`:e===`importName`?`禁止引入端口探测函数 "${t}"`:`禁止声明端口探测标识符 "${t}"`}。端口获取统一走监听零口回读真实端口并经端口注册表注册,确需向子进程预派端口时以绑零口保留端口惯用法取系统分配口,正线见 ADR 0161。`}const Oe=e({meta:{type:`problem`,docs:{description:`禁止端口探测与避让处理,端口获取统一走端口注册表正线`}},createOnce(e){let t=null,n=!1;return{before(){if(t=De(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},ImportDeclaration(r){if(t&&n){if(t.bannedModules.has(r.source.value))e.report({node:r,message:U(`module`,r.source.value)});else for(let n of r.specifiers){if(n.type!==`ImportSpecifier`)continue;let r=n.imported.type===`Identifier`?n.imported.name:n.local.name;t.bannedImportNames.has(r)&&e.report({node:n,message:U(`importName`,r)})}}},FunctionDeclaration(r){t&&n&&r.id&&t.probingIdentifiers.has(r.id.name)&&e.report({node:r,message:U(`identifier`,r.id.name)})},MethodDefinition(r){if(!t||!n||r.computed)return;let i=H(r.key);i&&t.probingIdentifiers.has(i)&&e.report({node:r,message:U(`identifier`,i)})},PropertyDefinition(r){if(!t||!n||r.computed)return;let i=H(r.key);i&&t.probingIdentifiers.has(i)&&e.report({node:r,message:U(`identifier`,i)})},VariableDeclarator(r){t&&n&&r.id.type===`Identifier`&&t.probingIdentifiers.has(r.id.name)&&e.report({node:r,message:U(`identifier`,r.id.name)})}}}}),W=[`error`],G=[`logger`,`log`],K=e=>e.type!==`MemberExpression`||e.computed?null:e.property.type===`Identifier`?e.property.name:null,ke=e=>e.type!==`MemberExpression`||e.object.type!==`Identifier`?null:e.object.name,q=(e,t,n)=>{let r=K(e.callee);if(r===null||!t.has(r))return!1;let i=ke(e.callee);return i!==null&&n.has(i)},Ae=e=>{let t=K(e.callee);return t!==null&&t.toLowerCase().includes(`flush`)?!0:e.callee.type===`Identifier`&&e.callee.name.toLowerCase().includes(`flush`)},je=e=>e.callee.type!==`MemberExpression`||e.callee.object.type!==`Identifier`||e.callee.object.name!==`process`?!1:K(e.callee)===`exit`,Me=[`Error`],Ne=n.object({errorTypeNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function Pe(e){let t=Ne.safeParse(e),n=t.success?t.data:{};return{errorTypeNames:/* @__PURE__ */ new Set([...Me,...n.errorTypeNames??[]]),ignoreTests:n.ignoreTests??!0}}function Fe(e){return typeof e==`object`&&!!e&&`typeAnnotation`in e&&e.typeAnnotation!==null&&typeof e.typeAnnotation==`object`}function Ie(e,t){if(typeof e!=`object`||!e)return!1;let n=`type`in e&&e.type===`TSTypeReference`&&`typeName`in e&&e.typeName!==null?e.typeName:e;return typeof n!=`object`||!n?!1:`name`in n&&typeof n.name==`string`&&t.has(n.name)}const Le=e({meta:{type:`problem`,docs:{description:`禁止 as Error 类型断言,catch 的 unknown 经标准件 ensureError 取错误对象`}},createOnce(e){let t=null,n=!1;return{before(){if(t=Pe(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},TSAsExpression(r){t&&n&&Fe(r)&&Ie(r.typeAnnotation,t.errorTypeNames)&&e.report({node:r,message:`禁止 as Error 类型断言。catch 的 unknown 经标准件 ensureError 取错误对象或消息,正线见 error-handling 台账工作流 001 判据 1 与 ADR 0166。`})}}}}),Re=n.object({methodNames:n.optional(n.array(n.string())),objectNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function ze(e){let t=Re.safeParse(e),n=t.success?t.data:{};return{methodNames:/* @__PURE__ */ new Set([...W,...n.methodNames??[]]),loggerObjects:/* @__PURE__ */ new Set([...G,...n.objectNames??[]]),ignoreTests:n.ignoreTests??!0}}const Be=e({meta:{type:`problem`,docs:{description:`禁止 error 日志后裸 process exit,退出前一律经 flushAndExit 刷缓冲`}},createOnce(e){let t=null,n=!1;return{before(){if(t=ze(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},BlockStatement(r){if(!t||!n)return;let i=!1;for(let n of r.body){if(n.type!==`ExpressionStatement`)continue;let r=n.expression;r.type===`CallExpression`&&(Ae(r)?i=!1:q(r,t.methodNames,t.loggerObjects)?i=!0:je(r)&&i&&e.report({node:n,message:`error 日志后裸调用 process.exit 会吞掉缓冲中的致命日志。退出前一律经 flushAndExit 刷缓冲后退出,正线见 error-handling 台账工作流 002 判据 4。`}))}}}}});function Ve(e){return e.replace(/\\/g,`/`).includes(`/apps/`)}function He(e){return/-implementation(\/|$)/.test(e)}function Ue(e){return e.endsWith(`Entity`)}function We(e){return e.endsWith(`UseCase`)}function Ge(e){return[/PortAdapter$/,/_TOKEN$/,/^create\w+Repository$/,/^create\w+Adapter$/].some(t=>t.test(e))}const Ke=e({meta:{type:`problem`,docs:{description:`禁止在 apps 层导入 implementation 包的 Entity 和 UseCase`}},createOnce(e){return{before(){let t=e.filename;if(!Ve(t))return!1},ImportDeclaration(t){let n=t.source.type===`Literal`&&typeof t.source.value==`string`?t.source.value:null;if(n&&He(n))for(let n of t.specifiers){if(n.type!==`ImportSpecifier`)continue;let t=n.imported.type===`Identifier`?n.imported.name:null;t&&(Ue(t)?e.report({node:n,message:`禁止在 apps 层导入 Entity 类 "${t}"。请使用 contract 包的 Port 接口进行操作。`}):We(t)?e.report({node:n,message:`禁止在 apps 层导入 UseCase 类 "${t}"。请使用 contract 包的 Port 接口进行操作。`}):Ge(t)||e.report({node:n,message:`禁止在 apps 层从 implementation 包导入 "${t}"。请使用 contract 包的 Port 接口。`}))}}}}}),qe=[`Error`],Je=n.object({errorTypeNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function Ye(e){let t=Je.safeParse(e),n=t.success?t.data:{};return{errorTypeNames:/* @__PURE__ */ new Set([...qe,...n.errorTypeNames??[]]),ignoreTests:n.ignoreTests??!0}}const Xe=e({meta:{type:`problem`,docs:{description:`禁止内联三元归一化副本,unknown 转 Error 一律经标准件 ensureError`}},createOnce(e){let t=null,n=!1;return{before(){if(t=Ye(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},ConditionalExpression(r){if(!t||!n)return;let i=r.test;i.type===`BinaryExpression`&&i.operator===`instanceof`&&i.right.type===`Identifier`&&t.errorTypeNames.has(i.right.name)&&e.report({node:r,message:`禁止内联三元归一化副本。unknown 转 Error 一律经标准件 ensureError,纯日志位直传 logger 吸收汇,正线见 error-handling 台账工作流 001 判据 1 与判据 2 及 ADR 0166。`})}}}}),Ze=n.object({functionName:n.string(),forbiddenPaths:n.array(n.string()),message:n.optional(n.string())}),Qe=n.object({restrictions:n.array(Ze)});function J(e,t){let n=e.replace(/\\/g,`/`),r=t.replace(/\\/g,`/`);if(!r.includes(`*`))return n.includes(r);let i=r.split(`*`).map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`[^/]+`);return new RegExp(i).test(n)}function $e(e,t){return t.some(t=>J(e,t))}function et(e){let t=Qe.safeParse(e);return t.success?t.data.restrictions:[]}function tt(e){return e.type===`Identifier`?e.name:e.type===`MemberExpression`&&e.property&&!e.computed&&e.property.type===`Identifier`?e.property.name:null}const nt=e({meta:{type:`problem`,docs:{description:`禁止在指定路径中调用特定函数,强制架构约束`}},createOnce(e){let t=[],n=/* @__PURE__ */ new Set;return{before(){let r=e.options?.[0];if(t=et(r),t.length===0)return!1;n=/* @__PURE__ */ new Set;for(let r=0;r<t.length;r++){let i=t[r];i&&$e(e.filename,i.forbiddenPaths)&&n.add(r)}if(n.size===0)return!1},CallExpression(r){let i=tt(r.callee);if(i)for(let a of n){let n=t[a];if(!n||i!==n.functionName)continue;let o=n.message??`禁止在当前路径中调用 "${n.functionName}"`;e.report({node:r,message:o})}}}}}),rt=[`fetch`,`axios`],it=[`XMLHttpRequest`,`EventSource`,`WebSocket`],at=[`domains/*/ui/`,`packages/ui/`,`packages/*-ui/`,`apps/web/`],ot=new Set(it),st=[`__tests__/`,`.test.`,`.spec.`,`__mocks__/`],ct=n.object({uiPathPatterns:n.optional(n.array(n.string())),extraFunctionNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function lt(e,t){return t.some(t=>J(e,t))}function ut(e){let t=e.replace(/\\/g,`/`);return st.some(e=>t.includes(e))}function dt(e){let t=ct.safeParse(e),n=t.success?t.data:{};return{uiPathPatterns:n.uiPathPatterns??[...at],rawCallNames:/* @__PURE__ */ new Set([...rt,...n.extraFunctionNames??[]]),ignoreTests:n.ignoreTests??!0}}function ft(e,t){return e.type===`Identifier`?t.has(e.name)?e.name:null:e.type===`MemberExpression`&&!e.computed&&e.object.type===`Identifier`&&t.has(e.object.name)?e.property.type===`Identifier`?`${e.object.name}.${e.property.name}`:e.object.name:null}function pt(e){return e.type===`Identifier`&&ot.has(e.name)?e.name:null}function Y(e){return`UI 层禁止手写网络调用 "${e}"。网络消费统一经生成式 sdk 客户端端点加 transport 通道注入,正线见 ADR 0127 与 sdk 治理台账工作流 002。`}const mt=e({meta:{type:`problem`,docs:{description:`禁止 UI 层手写网络调用,消费面统一经生成式 sdk 客户端`}},createOnce(e){let t=null,n=!1;return{before(){if(t=dt(e.options?.[0]),n=!(t.ignoreTests&&ut(e.filename))&&lt(e.filename,t.uiPathPatterns),!n)return!1},CallExpression(r){if(!t||!n)return;let i=ft(r.callee,t.rawCallNames);i&&e.report({node:r,message:Y(i)})},NewExpression(r){if(!t||!n)return;let i=pt(r.callee);i&&e.report({node:r,message:Y(i)})}}}}),ht=n.object({importSource:n.string(),importNames:n.optional(n.array(n.string())),forbiddenPaths:n.array(n.string()),message:n.optional(n.string())}),gt=n.object({restrictions:n.array(ht)});function _t(e,t,n){return e===n.importSource?!n.importNames||n.importNames.length===0?t.length>0:t.some(e=>n.importNames?.includes(e)??!1):!1}function vt(e){let t=[];for(let n of e)n.type===`ImportSpecifier`&&n.imported.type===`Identifier`?t.push(n.imported.name):n.type===`ImportDefaultSpecifier`&&t.push(n.local.name);return t}function yt(e){let t=gt.safeParse(e);return t.success?t.data.restrictions:[]}function bt(e,t){return t.some(t=>J(e,t))}const xt=e({meta:{type:`problem`,docs:{description:`禁止在指定路径中导入特定模块,强制架构约束`},schema:[{type:`object`,properties:{restrictions:{type:`array`,items:{type:`object`,properties:{importSource:{type:`string`},importNames:{type:`array`,items:{type:`string`}},forbiddenPaths:{type:`array`,items:{type:`string`}},message:{type:`string`}},required:[`importSource`,`forbiddenPaths`],additionalProperties:!1}}},additionalProperties:!1}]},createOnce(e){let t=[],n=/* @__PURE__ */ new Set;return{before(){let r=e.options?.[0];if(t=yt(r),t.length===0)return!1;n=/* @__PURE__ */ new Set;for(let r=0;r<t.length;r++){let i=t[r];i&&bt(e.filename,i.forbiddenPaths)&&n.add(r)}if(n.size===0)return!1},ImportDeclaration(r){let i=r.source.value;if(typeof i!=`string`)return;let a=vt(r.specifiers??[]);for(let o of n){let n=t[o];if(!n||!_t(i,a,n))continue;let s=n.importNames?a.filter(e=>n.importNames?.includes(e)??!1):a;for(let t of s){let i=n.message??`禁止在当前路径中导入 "${t}"(来源:${n.importSource})`;e.report({node:r,message:i})}}}}}}),St=/* @__PURE__ */ new Set([`port`,`hostname`]),Ct=n.object({ignoreTests:n.optional(n.boolean())});function wt(e){let t=Ct.safeParse(e);return{ignoreTests:(t.success?t.data:{}).ignoreTests??!0}}function Tt(e){return e.type===`Identifier`?e.name:null}function Et(e){return e.type===`MemberExpression`&&!e.computed&&e.property.type===`Identifier`&&e.property.name===`listen`}function Dt(e){return e.type===`MemberExpression`&&!e.computed&&e.object.type===`Identifier`&&e.object.name===`Bun`&&e.property.type===`Identifier`&&e.property.name===`serve`}function Ot(e){let t=!1;for(let n of e.properties){if(n.type!==`Property`||n.computed)continue;let e=Tt(n.key);if(e!==null&&(St.has(e)&&(t=!0),e===`reusePort`))return n.value.type===`Literal`&&n.value.value===!1}return!t&&null}function kt(e){return`${e===`listen`?`监听选项禁止依赖 reusePort 默认值`:`Bun.serve 选项禁止依赖 reusePort 默认值`}。Elysia 适配器默认开启端口共存绑定使冲突静默共享,显式置 reusePort 为 false 使端口冲突即崩溃快速失败,正线见 ADR 0195。`}const X=e({meta:{type:`problem`,docs:{description:`禁止监听选项依赖 reusePort 默认值,端口冲突统一显性快速失败`}},createOnce(e){let t=null,n=!1;return{before(){if(t=wt(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},CallExpression(r){if(!t||!n)return;let i=Dt(r.callee)?`bunServe`:Et(r.callee)?`listen`:null;if(i===null)return;let a=r.arguments[0];a!==void 0&&a.type===`ObjectExpression`&&Ot(a)===!1&&e.report({node:r,message:kt(i)})}}}}),At=n.object({methodNames:n.optional(n.array(n.string())),objectNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function jt(e){let t=At.safeParse(e),n=t.success?t.data:{};return{methodNames:/* @__PURE__ */ new Set([...W,...n.methodNames??[]]),loggerObjects:/* @__PURE__ */ new Set([...G,...n.objectNames??[]]),ignoreTests:n.ignoreTests??!0}}const Mt=e({meta:{type:`problem`,docs:{description:`禁止错误日志模板拼接 message,改为结构化第二参直传错误值`}},createOnce(e){let t=null,n=!1;return{before(){if(t=jt(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},CallExpression(r){if(!t||!n||!q(r,t.methodNames,t.loggerObjects))return;let i=r.arguments[0];if(!i||i.type===`SpreadElement`)return;let a=i.type===`TemplateLiteral`&&i.expressions.length>0,o=i.type===`BinaryExpression`&&i.operator===`+`;(a||o)&&e.report({node:r,message:`错误日志禁止模板拼接 message。模板拼接吞掉错误对象的 cause 与 stack 与 code,消息写固定文案并以第二参直传错误值由 logger 吸收汇归一化,正线见 error-handling 台账工作流 002 判据 1 与 ADR 0166。`})}}}}),Nt=n.object({methodNames:n.optional(n.array(n.string())),objectNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function Pt(e){let t=Nt.safeParse(e),n=t.success?t.data:{};return{methodNames:/* @__PURE__ */ new Set([...W,...n.methodNames??[]]),loggerObjects:/* @__PURE__ */ new Set([...G,...n.objectNames??[]]),ignoreTests:n.ignoreTests??!0}}const Ft=e({meta:{type:`problem`,docs:{description:`禁止纯文案错误日志,无底层错误时错误参数位显式传 undefined 并附业务上下文`}},createOnce(e){let t=null,n=!1;return{before(){if(t=Pt(e.options?.[0]),n=!(t.ignoreTests&&V(e.filename)),!n)return!1},CallExpression(r){t&&n&&q(r,t.methodNames,t.loggerObjects)&&r.arguments.length<2&&e.report({node:r,message:`错误日志禁止纯文案形态。无底层错误对象的业务校验场景在错误参数位显式传 undefined 并附业务上下文,正线见 error-handling 台账工作流 002 判据 2 与 ADR 0166。`})}}}}),It=[`vite.config.`],Lt=[`portDiscovery`],Rt=n.object({viteConfigPatterns:n.optional(n.array(n.string())),registerMarkers:n.optional(n.array(n.string()))});function zt(e){let t=Rt.safeParse(e),n=t.success?t.data:{};return{viteConfigPatterns:n.viteConfigPatterns??[...It],registerMarkers:/* @__PURE__ */ new Set([...Lt,...n.registerMarkers??[]])}}function Bt(e,t){let n=e.replace(/\\/g,`/`).split(`/`).pop()??``;return t.some(e=>n.includes(e))}function Z(e){return e.computed||e.key.type!==`Identifier`||e.value.type!==`Literal`?null:{key:e.key.name,value:e.value.value}}function Vt(){return`vite 配置禁止置 strictPort 为 false 依赖占用自动加一。端口面统一置 strictPort 为 true 快速失败,或 port 置 0 配合 portDiscovery 注册,正线见 ADR 0161。`}function Ht(e){return`vite 配置写死端口 ${e} 且未置 strictPort 为 true,占用时将静默改用相邻端口。端口面统一置 strictPort 为 true 快速失败,或 port 置 0 配合 portDiscovery 注册,正线见 ADR 0161。`}const Q={"dependency-direction":pe,"business-leak":u,"no-cross-package-relative-import":xe,"domain-export-compliance":k,"implementation-export-control":he,"no-implementation-import-in-apps":Ke,"no-restricted-call-in-paths":nt,"no-restricted-import-in-paths":xt,"no-raw-network-call-in-ui":mt,"no-port-probing":Oe,"no-vite-port-fallback":e({meta:{type:`problem`,docs:{description:`禁止 vite 配置依赖端口占用自动加一,端口面统一快速失败或注册表注册`}},createOnce(e){let t=null,n=!1,r={hasRegisterMarker:!1,hasStrictPortTrue:!1,strictPortFalseNodes:[],positivePortNodes:[]};return{before(){if(t=zt(e.options?.[0]),n=Bt(e.filename,t.viteConfigPatterns),r.hasRegisterMarker=!1,r.hasStrictPortTrue=!1,r.strictPortFalseNodes=[],r.positivePortNodes=[],!n)return!1},ImportDeclaration(e){if(t&&n)for(let n of e.specifiers)n.type===`ImportSpecifier`&&n.local.name&&t.registerMarkers.has(n.local.name)&&(r.hasRegisterMarker=!0)},CallExpression(e){t&&n&&e.callee.type===`Identifier`&&t.registerMarkers.has(e.callee.name)&&(r.hasRegisterMarker=!0)},Property(e){if(!t||!n)return;let i=Z(e);i&&(i.key===`strictPort`?i.value===!0?r.hasStrictPortTrue=!0:i.value===!1&&r.strictPortFalseNodes.push(e):i.key===`port`&&typeof i.value==`number`&&i.value>0&&r.positivePortNodes.push(e))},"Program:exit"(){if(t&&n&&!r.hasRegisterMarker){for(let t of r.strictPortFalseNodes)e.report({node:t,message:Vt()});if(!r.hasStrictPortTrue)for(let t of r.positivePortNodes){let n=Z(t);e.report({node:t,message:Ht(typeof n?.value==`number`?n.value:0)})}}}}}}),"no-reuseport-default":X,"no-template-error-log":Mt,"no-text-only-error-log":Ft,"no-exit-after-error-log":Be,"no-inline-error-normalization":Xe,"no-error-type-assertion":Le},$=t({meta:{name:`@longzai-intelligence-oxlint/architecture-core-plugin`},rules:Q});export{$ as architectureCorePlugin,$ as default,Q as coreRules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-oxlint/architecture-core-plugin",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "Longzai Intelligence oxlint 核心架构规则插件",
5
5
  "keywords": [
6
6
  "architecture",
@@ -43,12 +43,11 @@
43
43
  "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json"
44
44
  },
45
45
  "dependencies": {
46
- "@longzai-intelligence-oxlint/core": "0.2.16",
46
+ "@longzai-intelligence-oxlint/core": "0.2.18",
47
47
  "@oxlint/plugins": "^1.74.0",
48
48
  "zod": "^4.4.3"
49
49
  },
50
50
  "devDependencies": {
51
- "@longzai-intelligence-oxlint/testing": "0.2.16",
52
51
  "@vitest/coverage-v8": "^4.1.10",
53
52
  "typescript": "^6.0.3"
54
53
  },