@longzai-intelligence-oxlint/presets 0.2.2 → 0.2.4
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
|
-
import"../rolldown-runtime-BqT_7tdF.js";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 l(e,t){let n=e.replace(/\\/g,`/`);return t.some(e=>e.test(n))}function u(e,t){let n=e.charAt(0).toUpperCase()+e.slice(1);return t.some(e=>n.includes(e))}function d(e,t){return t.some(t=>t.test(e))}const ee=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),l(e.filename,t)?void 0:!1},ClassDeclaration(t){t.id&&u(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关类 '${t.id.name}'。业务逻辑应该放在 domains/ 层。`})},MethodDefinition(t){t.key.type===`Identifier`&&d(t.key.name,r)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务规则方法 '${t.key.name}'。业务规则应该放在 domains/ 层。`})},TSInterfaceDeclaration(t){u(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关接口 '${t.id.name}'。业务接口应该放在 domains/ 层。`})},TSTypeAliasDeclaration(t){u(t.id.name,n)&&e.report({node:t,message:`业务逻辑泄漏嫌疑: 技术层发现业务相关类型 '${t.id.name}'。业务类型应该放在 domains/ 层。`})}}}}),f={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},p={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)`},te=new Set(Object.keys(f)),m={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`}]},ne=[{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。`}],re=[`-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 te.has(e)}function ie(e,t){return f[e]>=f[t]}function _(e){return p[e]}function ae(e,t){let n=e.replace(/\\/g,`/`),r=t??m.pathPatterns;if(r){for(let{pattern:e,layer:t}of r)if(e.test(n))return{layer:t,priority:f[t]}}if(n.includes(`/apps/`)){for(let{pattern:e,layer:t}of h)if(e.test(n))return{layer:t,priority:f[t]}}if(n.includes(`/packages/`)){for(let{pattern:e,layer:t}of h)if(e.test(n))return{layer:t,priority:f[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 y(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:f[i]};let a=t.packageSuffixMappings??[];for(let{suffix:e,layer:t}of a)if(r.endsWith(e))return{layer:t,priority:f[t]};return null}function b(e,t,n){return e.find(e=>e.from===t&&e.to===n)??null}function x(e){let t=e.match(/^\/(.+)\/([gimsuvy]*)$/);return t?.[1]?new RegExp(t[1],t[2]??``):new RegExp(e)}function S(e){let t={};if(e.pathPatterns&&(t.pathPatterns=e.pathPatterns.reduce((e,{pattern:t,layer:n})=>(g(n)&&e.push({pattern:x(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 C(e){return typeof e==`object`&&!!e}function w(e){let t=S(C(e)?e:{});return{pathPatterns:t.pathPatterns??m.pathPatterns,packagePrefix:t.packagePrefix??m.packagePrefix,specialPackageMappings:t.specialPackageMappings??m.specialPackageMappings,packageSuffixMappings:t.packageSuffixMappings??m.packageSuffixMappings,forbiddenLayerPairs:[...ne,...t.forbiddenLayerPairs??[]],forbiddenPackageSuffixes:[...re,...t.forbiddenPackageSuffixes??[]]}}const T=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=w(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=y(i,t);if(!o)return;let s=b(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 E(e){let t=e.replace(/\\/g,`/`);return t.includes(`/domains/`)&&t.includes(`/implementation/src/index.ts`)}function D(e){return e.endsWith(`Entity`)}function O(e){return e.endsWith(`Repository`)&&!e.startsWith(`I`)}function k(e){return e.endsWith(`OrmEntity`)}function A(e){return e.endsWith(`_ORM_ENTITIES`)}function j(e){return e.endsWith(`OrmMapper`)}function M(e){return e.endsWith(`Schema`)}function N(e){return`exportKind`in e&&typeof e.exportKind==`string`?e.exportKind===`value`:!0}function P(e){return e.exported.type===`Identifier`?e.exported.name:e.exported.type===`Literal`&&typeof e.exported.value==`string`?e.exported.value:null}function F(e,t,n){D(e)&&N(t)?n.report({node:t,message:`禁止从主入口值导出 Entity 类 "${e}"。请改为类型导出或移除导出。`}):O(e)?n.report({node:t,message:`禁止导出 Repository 类型 "${e}"。Repository 是内部实现,不应暴露给外部。`}):k(e)?n.report({node:t,message:`禁止从主入口导出 ORM 实体 "${e}"。请创建 src/typeorm.ts 入口文件,从该入口导出。`}):A(e)?n.report({node:t,message:`禁止从主入口导出 ORM 实体集合 "${e}"。请创建 src/typeorm.ts 入口文件,从该入口导出。`}):j(e)?n.report({node:t,message:`禁止导出 ORM Mapper "${e}"。ORM Mapper 是基础设施实现细节,不应暴露给外部。`}):M(e)&&n.report({node:t,message:`禁止导出 Schema 定义 "${e}"。Schema 是实现细节,应仅导出推断类型。`})}const I=e({meta:{type:`problem`,docs:{description:`检查 Domain Implementation 包的导出是否符合规范`}},createOnce(e){return{before(){let t=e.filename;if(!E(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=P(n);t&&F(t,n,e)}}}}});function L(e){let t=e.replace(/\\/g,`/`);return t.includes(`/domains/`)&&t.includes(`/implementation/src/index.ts`)}const R=[/\.\/typeorm/,/\.\/typeorm'/,/\.\/typeorm"/],z=[{pattern:/OrmEntity$/,message:`禁止从主入口导出 ORM 实体。应使用 typeorm 入口导出。`},{pattern:/Entity$/,message:`禁止从主入口导出 Entity 类。Entity 是内部实现,应使用 contract 包的 DTO。`},{pattern:/UseCase$/,message:`禁止导出 UseCase 类。UseCase 是内部实现,应通过 Port 接口访问。`},{pattern:/^I[A-Z].*Repository$/,message:`禁止导出 Repository 接口。Repository 是内部接口,外部应通过 Port 访问。`},{pattern:/^create[A-Za-z]+Repository$/,message:`禁止导出 Repository 工厂函数。外部应使用 PortAdapter 工厂函数。`},{pattern:/Repository/,message:`禁止导出 Repository 实现类。应使用工厂函数或 Port 接口。`},{pattern:/Schema$/,message:`禁止导出 Schema 定义。Schema 是实现细节,应导出推断类型。`},{pattern:/_ORM_ENTITIES$/,message:`禁止从主入口导出实体集合。应使用 typeorm 入口导出。`},{pattern:/OrmMapper$/,message:`禁止导出 ORM Mapper。这是基础设施实现细节。`},{pattern:/Table$/,message:`禁止导出数据库表定义。这是数据存储细节。`}];function B(e){return R.some(t=>t.test(e))}function V(e){for(let{pattern:t,message:n}of z)if(t.test(e))return n;return null}function H(e,t){if(e.source){let n=e.source.type===`Literal`&&typeof e.source.value==`string`?e.source.value:null;if(n&&B(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=V(e);r&&t.report({node:n,message:`${e}: ${r}`})}}}e.declaration&&G(e.declaration,t.report)}function U(e,t){if(e.source){let n=e.source.type===`Literal`&&typeof e.source.value==`string`?e.source.value:null;if(n&&B(n)){t.report({node:e,message:`禁止从主入口重新导出 typeorm.ts 的内容。typeorm.ts 是专门的持久化入口。`});return}}t.report({node:e,message:`禁止使用 export *。请使用显式导出,明确导出内容。`})}function W(e,t){K(e.declaration)&&G(e.declaration,t.report)}function G(e,t){if(e.type===`ClassDeclaration`&&e.id){let n=e.id.name,r=V(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=V(e);r&&t({node:n,message:`${e}: ${r}`})}}else if(e.type===`FunctionDeclaration`&&e.id){let n=e.id.name,r=V(n);r&&t({node:e,message:`${n}: ${r}`})}}function K(e){return e.type===`ClassDeclaration`||e.type===`FunctionDeclaration`||e.type===`VariableDeclaration`}const q=e({meta:{type:`problem`,docs:{description:`Implementation 包导出控制:禁止从主入口导出内部实现`}},createOnce(e){return{before(){let t=e.filename;if(!L(t))return!1},ExportNamedDeclaration(t){H(t,e)},ExportAllDeclaration(t){U(t,e)},ExportDefaultDeclaration(t){W(t,e)}}}}),se=[{alias:`@main`,pathPattern:`src/main`},{alias:`@preload`,pathPattern:`src/preload`},{alias:`@renderer`,pathPattern:`src/renderer/src`},{alias:`@shared`,pathPattern:`src/shared`}];function ce(e){return typeof e==`object`&&!!e&&`packageBoundaries`in e}function J(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 le(e,t,n){if(!t.startsWith(`.`))return null;let r=e.replace(/\\/g,`/`),i=r.lastIndexOf(`/`);return J(ue(i>0?r.substring(0,i):``,t),n)}function ue(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 Y(e){return e.startsWith(`./`)||e.startsWith(`../`)}const de=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=ce(r)&&Array.isArray(r.packageBoundaries)?r.packageBoundaries:se}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||!Y(i))return;let a=J(r,n());if(!a)return;let o=le(r,i,n());o&&a!==o&&e.report({node:t,message:`禁止使用相对路径跨包导入。当前文件位于 "${a}" 包,目标位于 "${o}" 包。请使用别名导入:${o}/...`})}}}});function fe(e){return e.replace(/\\/g,`/`).includes(`/apps/`)}function pe(e){return/-implementation(\/|$)/.test(e)}function me(e){return e.endsWith(`Entity`)}function he(e){return e.endsWith(`UseCase`)}function ge(e){return[/PortAdapter$/,/_TOKEN$/,/^create\w+Repository$/,/^create\w+Adapter$/].some(t=>t.test(e))}const _e=e({meta:{type:`problem`,docs:{description:`禁止在 apps 层导入 implementation 包的 Entity 和 UseCase`}},createOnce(e){return{before(){let t=e.filename;if(!fe(t))return!1},ImportDeclaration(t){let n=t.source.type===`Literal`&&typeof t.source.value==`string`?t.source.value:null;if(n&&pe(n))for(let n of t.specifiers){if(n.type!==`ImportSpecifier`)continue;let t=n.imported.type===`Identifier`?n.imported.name:null;t&&(me(t)?e.report({node:n,message:`禁止在 apps 层导入 Entity 类 "${t}"。请使用 contract 包的 Port 接口进行操作。`}):he(t)?e.report({node:n,message:`禁止在 apps 层导入 UseCase 类 "${t}"。请使用 contract 包的 Port 接口进行操作。`}):ge(t)||e.report({node:n,message:`禁止在 apps 层从 implementation 包导入 "${t}"。请使用 contract 包的 Port 接口。`}))}}}}}),ve=n.object({functionName:n.string(),forbiddenPaths:n.array(n.string()),message:n.optional(n.string())}),ye=n.object({restrictions:n.array(ve)});function X(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 be(e,t){return t.some(t=>X(e,t))}function xe(e){let t=ye.safeParse(e);return t.success?t.data.restrictions:[]}function Se(e){return e.type===`Identifier`?e.name:e.type===`MemberExpression`&&e.property&&!e.computed&&e.property.type===`Identifier`?e.property.name:null}const Ce=e({meta:{type:`problem`,docs:{description:`禁止在指定路径中调用特定函数,强制架构约束`}},createOnce(e){let t=[],n=/* @__PURE__ */ new Set;return{before(){let r=e.options?.[0];if(t=xe(r),t.length===0)return!1;n=/* @__PURE__ */ new Set;for(let r=0;r<t.length;r++){let i=t[r];i&&be(e.filename,i.forbiddenPaths)&&n.add(r)}if(n.size===0)return!1},CallExpression(r){let i=Se(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})}}}}}),we=[`fetch`,`axios`],Te=[`XMLHttpRequest`,`EventSource`,`WebSocket`],Ee=[`domains/*/ui/`,`packages/ui/`,`packages/*-ui/`],De=new Set(Te),Oe=[`__tests__/`,`.test.`,`.spec.`,`__mocks__/`],ke=n.object({uiPathPatterns:n.optional(n.array(n.string())),extraFunctionNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function Ae(e,t){return t.some(t=>X(e,t))}function je(e){let t=e.replace(/\\/g,`/`);return Oe.some(e=>t.includes(e))}function Me(e){let t=ke.safeParse(e),n=t.success?t.data:{};return{uiPathPatterns:n.uiPathPatterns??[...Ee],rawCallNames:/* @__PURE__ */ new Set([...we,...n.extraFunctionNames??[]]),ignoreTests:n.ignoreTests??!0}}function Ne(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 Pe(e){return e.type===`Identifier`&&De.has(e.name)?e.name:null}function Z(e){return`UI 层禁止手写网络调用 "${e}"。网络消费统一经生成式 sdk 客户端端点加 transport 通道注入,正线见 ADR 0127 与 sdk 治理台账工作流 002。`}const Fe=e({meta:{type:`problem`,docs:{description:`禁止 UI 层手写网络调用,消费面统一经生成式 sdk 客户端`}},createOnce(e){let t=null,n=!1;return{before(){if(t=Me(e.options?.[0]),n=!(t.ignoreTests&&je(e.filename))&&Ae(e.filename,t.uiPathPatterns),!n)return!1},CallExpression(r){if(!t||!n)return;let i=Ne(r.callee,t.rawCallNames);i&&e.report({node:r,message:Z(i)})},NewExpression(r){if(!t||!n)return;let i=Pe(r.callee);i&&e.report({node:r,message:Z(i)})}}}}),Ie=n.object({importSource:n.string(),importNames:n.optional(n.array(n.string())),forbiddenPaths:n.array(n.string()),message:n.optional(n.string())}),Le=n.object({restrictions:n.array(Ie)});function Re(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 ze(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 Be(e){let t=Le.safeParse(e);return t.success?t.data.restrictions:[]}function Ve(e,t){return t.some(t=>X(e,t))}const Q={"dependency-direction":T,"business-leak":ee,"no-cross-package-relative-import":de,"domain-export-compliance":I,"implementation-export-control":q,"no-implementation-import-in-apps":_e,"no-restricted-call-in-paths":Ce,"no-restricted-import-in-paths":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=Be(r),t.length===0)return!1;n=/* @__PURE__ */ new Set;for(let r=0;r<t.length;r++){let i=t[r];i&&Ve(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=ze(r.specifiers??[]);for(let o of n){let n=t[o];if(!n||!Re(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})}}}}}}),"no-raw-network-call-in-ui":Fe},$=t({meta:{name:`@longzai-intelligence-oxlint/architecture-core-plugin`},rules:Q});export{$ as architectureCorePlugin,$ as default,Q as coreRules};
|
|
1
|
+
import"../rolldown-runtime-BqT_7tdF.js";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 u(e,t){return t.some(t=>t.test(e))}const d=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`&&u(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/ 层。`})}}}}),f={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},te={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)`},ne=new Set(Object.keys(f)),p={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`}]},m=[{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。`}],h=[`-main`],g=[{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 _(e){return ne.has(e)}function re(e,t){return f[e]>=f[t]}function v(e){return te[e]}function ie(e,t){let n=e.replace(/\\/g,`/`),r=t??p.pathPatterns;if(r){for(let{pattern:e,layer:t}of r)if(e.test(n))return{layer:t,priority:f[t]}}if(n.includes(`/apps/`)){for(let{pattern:e,layer:t}of g)if(e.test(n))return{layer:t,priority:f[t]}}if(n.includes(`/packages/`)){for(let{pattern:e,layer:t}of g)if(e.test(n))return{layer:t,priority:f[t]}}return null}function y(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 ae(e,t){for(let n of t)if(e.endsWith(n))return n;return null}function oe(e,t){let n=t.packagePrefix??``,r=y(e,n);if(!r)return null;let i=(t.specialPackageMappings??{})[`${n}${r}`];if(i)return{layer:i,priority:f[i]};let a=t.packageSuffixMappings??[];for(let{suffix:e,layer:t}of a)if(r.endsWith(e))return{layer:t,priority:f[t]};return null}function b(e,t,n){return e.find(e=>e.from===t&&e.to===n)??null}function x(e){let t=e.match(/^\/(.+)\/([gimsuvy]*)$/);return t?.[1]?new RegExp(t[1],t[2]??``):new RegExp(e)}function S(e){let t={};if(e.pathPatterns&&(t.pathPatterns=e.pathPatterns.reduce((e,{pattern:t,layer:n})=>(_(n)&&e.push({pattern:x(t),layer:n}),e),[])),e.packagePrefix&&(t.packagePrefix=e.packagePrefix),e.specialPackageMappings){let n={};for(let[t,r]of Object.entries(e.specialPackageMappings))_(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)_(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)_(t)&&_(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 C(e){return typeof e==`object`&&!!e}function w(e){let t=S(C(e)?e:{});return{pathPatterns:t.pathPatterns??p.pathPatterns,packagePrefix:t.packagePrefix??p.packagePrefix,specialPackageMappings:t.specialPackageMappings??p.specialPackageMappings,packageSuffixMappings:t.packageSuffixMappings??p.packageSuffixMappings,forbiddenLayerPairs:[...m,...t.forbiddenLayerPairs??[]],forbiddenPackageSuffixes:[...h,...t.forbiddenPackageSuffixes??[]]}}const T=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=w(e.options?.[0])),n=ie(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=y(i,t.packagePrefix??``);if(a){let n=ae(a,t.forbiddenPackageSuffixes??[]);if(n){e.report({node:r,message:`禁止导入已禁用的 ${n} 门面包,门面包统一使用 -domain 后缀。`});return}}let o=oe(i,t);if(!o)return;let s=b(t.forbiddenLayerPairs??[],n.layer,o.layer);s?e.report({node:r,message:`依赖方向违规: ${n.layer} (${v(n.layer)}) 不能导入 ${o.layer} (${v(o.layer)})。${s.hint??`域内取件必须经 -domain 门面包。`}`}):re(n.layer,o.layer)||e.report({node:r,message:`依赖方向违规: ${n.layer} (${v(n.layer)}) 不能导入 ${o.layer} (${v(o.layer)})。依赖应该从外层指向内层。`})}}}});function E(e){let t=e.replace(/\\/g,`/`);return t.includes(`/domains/`)&&t.includes(`/implementation/src/index.ts`)}function D(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function O(e){return D(e)&&e.endsWith(`Entity`)}function k(e){return D(e)&&e.endsWith(`Repository`)&&!e.startsWith(`I`)}function A(e){return D(e)&&e.endsWith(`OrmEntity`)}function j(e){return e.endsWith(`_ORM_ENTITIES`)}function M(e){return D(e)&&e.endsWith(`OrmMapper`)}function N(e){return D(e)&&e.endsWith(`Schema`)}function P(e){return`exportKind`in e&&typeof e.exportKind==`string`?e.exportKind===`value`:!0}function F(e){return e.exported.type===`Identifier`?e.exported.name:e.exported.type===`Literal`&&typeof e.exported.value==`string`?e.exported.value:null}function I(e,t,n){O(e)&&P(t)?n.report({node:t,message:`禁止从主入口值导出 Entity 类 "${e}"。请改为类型导出或移除导出。`}):k(e)?n.report({node:t,message:`禁止导出 Repository 类型 "${e}"。Repository 是内部实现,不应暴露给外部。`}):A(e)?n.report({node:t,message:`禁止从主入口导出 ORM 实体 "${e}"。请创建 src/typeorm.ts 入口文件,从该入口导出。`}):j(e)?n.report({node:t,message:`禁止从主入口导出 ORM 实体集合 "${e}"。请创建 src/typeorm.ts 入口文件,从该入口导出。`}):M(e)?n.report({node:t,message:`禁止导出 ORM Mapper "${e}"。ORM Mapper 是基础设施实现细节,不应暴露给外部。`}):N(e)&&n.report({node:t,message:`禁止导出 Schema 定义 "${e}"。Schema 是实现细节,应仅导出推断类型。`})}const L=e({meta:{type:`problem`,docs:{description:`检查 Domain Implementation 包的导出是否符合规范`}},createOnce(e){return{before(){let t=e.filename;if(!E(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=F(n);t&&I(t,n,e)}}}}});function R(e){let t=e.replace(/\\/g,`/`);return t.includes(`/domains/`)&&t.includes(`/implementation/src/index.ts`)}const z=[/\.\/typeorm/,/\.\/typeorm'/,/\.\/typeorm"/],B=[{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 V(e){return z.some(t=>t.test(e))}function H(e){for(let{pattern:t,message:n}of B)if(t.test(e))return n;return null}function U(e,t){if(e.source){let n=e.source.type===`Literal`&&typeof e.source.value==`string`?e.source.value:null;if(n&&V(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=H(e);r&&t.report({node:n,message:`${e}: ${r}`})}}}e.declaration&&K(e.declaration,t.report)}function W(e,t){if(e.source){let n=e.source.type===`Literal`&&typeof e.source.value==`string`?e.source.value:null;if(n&&V(n)){t.report({node:e,message:`禁止从主入口重新导出 typeorm.ts 的内容。typeorm.ts 是专门的持久化入口。`});return}}t.report({node:e,message:`禁止使用 export *。请使用显式导出,明确导出内容。`})}function G(e,t){q(e.declaration)&&K(e.declaration,t.report)}function K(e,t){if(e.type===`ClassDeclaration`&&e.id){let n=e.id.name,r=H(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=H(e);r&&t({node:n,message:`${e}: ${r}`})}}else if(e.type===`FunctionDeclaration`&&e.id){let n=e.id.name,r=H(n);r&&t({node:e,message:`${n}: ${r}`})}}function q(e){return e.type===`ClassDeclaration`||e.type===`FunctionDeclaration`||e.type===`VariableDeclaration`}const se=e({meta:{type:`problem`,docs:{description:`Implementation 包导出控制:禁止从主入口导出内部实现`}},createOnce(e){return{before(){let t=e.filename;if(!R(t))return!1},ExportNamedDeclaration(t){U(t,e)},ExportAllDeclaration(t){W(t,e)},ExportDefaultDeclaration(t){G(t,e)}}}}),ce=[{alias:`@main`,pathPattern:`src/main`},{alias:`@preload`,pathPattern:`src/preload`},{alias:`@renderer`,pathPattern:`src/renderer/src`},{alias:`@shared`,pathPattern:`src/shared`}];function le(e){return typeof e==`object`&&!!e&&`packageBoundaries`in e}function J(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 ue(e,t,n){if(!t.startsWith(`.`))return null;let r=e.replace(/\\/g,`/`),i=r.lastIndexOf(`/`);return J(de(i>0?r.substring(0,i):``,t),n)}function de(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 fe(e){return e.startsWith(`./`)||e.startsWith(`../`)}const pe=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=le(r)&&Array.isArray(r.packageBoundaries)?r.packageBoundaries:ce}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||!fe(i))return;let a=J(r,n());if(!a)return;let o=ue(r,i,n());o&&a!==o&&e.report({node:t,message:`禁止使用相对路径跨包导入。当前文件位于 "${a}" 包,目标位于 "${o}" 包。请使用别名导入:${o}/...`})}}}});function me(e){return e.replace(/\\/g,`/`).includes(`/apps/`)}function he(e){return/-implementation(\/|$)/.test(e)}function ge(e){return e.endsWith(`Entity`)}function _e(e){return e.endsWith(`UseCase`)}function ve(e){return[/PortAdapter$/,/_TOKEN$/,/^create\w+Repository$/,/^create\w+Adapter$/].some(t=>t.test(e))}const ye=e({meta:{type:`problem`,docs:{description:`禁止在 apps 层导入 implementation 包的 Entity 和 UseCase`}},createOnce(e){return{before(){let t=e.filename;if(!me(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&&(ge(t)?e.report({node:n,message:`禁止在 apps 层导入 Entity 类 "${t}"。请使用 contract 包的 Port 接口进行操作。`}):_e(t)?e.report({node:n,message:`禁止在 apps 层导入 UseCase 类 "${t}"。请使用 contract 包的 Port 接口进行操作。`}):ve(t)||e.report({node:n,message:`禁止在 apps 层从 implementation 包导入 "${t}"。请使用 contract 包的 Port 接口。`}))}}}}}),be=n.object({functionName:n.string(),forbiddenPaths:n.array(n.string()),message:n.optional(n.string())}),xe=n.object({restrictions:n.array(be)});function Y(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 Se(e,t){return t.some(t=>Y(e,t))}function Ce(e){let t=xe.safeParse(e);return t.success?t.data.restrictions:[]}function we(e){return e.type===`Identifier`?e.name:e.type===`MemberExpression`&&e.property&&!e.computed&&e.property.type===`Identifier`?e.property.name:null}const Te=e({meta:{type:`problem`,docs:{description:`禁止在指定路径中调用特定函数,强制架构约束`}},createOnce(e){let t=[],n=/* @__PURE__ */ new Set;return{before(){let r=e.options?.[0];if(t=Ce(r),t.length===0)return!1;n=/* @__PURE__ */ new Set;for(let r=0;r<t.length;r++){let i=t[r];i&&Se(e.filename,i.forbiddenPaths)&&n.add(r)}if(n.size===0)return!1},CallExpression(r){let i=we(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})}}}}}),Ee=[`fetch`,`axios`],De=[`XMLHttpRequest`,`EventSource`,`WebSocket`],Oe=[`domains/*/ui/`,`packages/ui/`,`packages/*-ui/`],ke=new Set(De),Ae=[`__tests__/`,`.test.`,`.spec.`,`__mocks__/`],je=n.object({uiPathPatterns:n.optional(n.array(n.string())),extraFunctionNames:n.optional(n.array(n.string())),ignoreTests:n.optional(n.boolean())});function Me(e,t){return t.some(t=>Y(e,t))}function Ne(e){let t=e.replace(/\\/g,`/`);return Ae.some(e=>t.includes(e))}function Pe(e){let t=je.safeParse(e),n=t.success?t.data:{};return{uiPathPatterns:n.uiPathPatterns??[...Oe],rawCallNames:/* @__PURE__ */ new Set([...Ee,...n.extraFunctionNames??[]]),ignoreTests:n.ignoreTests??!0}}function Fe(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 Ie(e){return e.type===`Identifier`&&ke.has(e.name)?e.name:null}function X(e){return`UI 层禁止手写网络调用 "${e}"。网络消费统一经生成式 sdk 客户端端点加 transport 通道注入,正线见 ADR 0127 与 sdk 治理台账工作流 002。`}const Z=e({meta:{type:`problem`,docs:{description:`禁止 UI 层手写网络调用,消费面统一经生成式 sdk 客户端`}},createOnce(e){let t=null,n=!1;return{before(){if(t=Pe(e.options?.[0]),n=!(t.ignoreTests&&Ne(e.filename))&&Me(e.filename,t.uiPathPatterns),!n)return!1},CallExpression(r){if(!t||!n)return;let i=Fe(r.callee,t.rawCallNames);i&&e.report({node:r,message:X(i)})},NewExpression(r){if(!t||!n)return;let i=Ie(r.callee);i&&e.report({node:r,message:X(i)})}}}}),Le=n.object({importSource:n.string(),importNames:n.optional(n.array(n.string())),forbiddenPaths:n.array(n.string()),message:n.optional(n.string())}),Re=n.object({restrictions:n.array(Le)});function ze(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 Be(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 Ve(e){let t=Re.safeParse(e);return t.success?t.data.restrictions:[]}function He(e,t){return t.some(t=>Y(e,t))}const Q={"dependency-direction":T,"business-leak":d,"no-cross-package-relative-import":pe,"domain-export-compliance":L,"implementation-export-control":se,"no-implementation-import-in-apps":ye,"no-restricted-call-in-paths":Te,"no-restricted-import-in-paths":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=Ve(r),t.length===0)return!1;n=/* @__PURE__ */ new Set;for(let r=0;r<t.length;r++){let i=t[r];i&&He(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=Be(r.specifiers??[]);for(let o of n){let n=t[o];if(!n||!ze(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})}}}}}}),"no-raw-network-call-in-ui":Z},$=t({meta:{name:`@longzai-intelligence-oxlint/architecture-core-plugin`},rules:Q});export{$ as architectureCorePlugin,$ as default,Q as coreRules};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../rolldown-runtime-BqT_7tdF.js";import"../rolldown-runtime-BqT_7tdF-BqT_7tdF.js";import{n as e,r as t,t as n}from"../dist-CskvMq7J.js";import{defineRule as r,eslintCompatPlugin as i}from"@oxlint/plugins";import{existsSync as a,readFileSync as ee}from"node:fs";import{dirname as o,join as te}from"node:path";import*as s from"zod/mini";function c(e){return e.endsWith(`Class`)}const l=r({meta:{type:`problem`,docs:{description:`禁止在 import 别名中使用 "Class" 后缀`}},createOnce(e){return{ImportSpecifier(t){let n=t.local.name,r=t.imported.type===`Identifier`?t.imported.name:n;n!==r&&c(n)&&e.report({node:t,message:`导入别名 "${n}" 使用了 "Class" 后缀,这是不允许的命名方式。请使用更具描述性的名称,或直接使用原始名称 "${r}"`})}}}}),u=/* @__PURE__ */ new Set([`console.log`,`console.warn`,`console.error`,`console.info`,`console.debug`,`console.trace`,`console.dir`,`console.table`]);function d(e){let t=e.callee;return t.type===`Identifier`?t.name:t.type===`MemberExpression`&&t.property.type===`Identifier`&&t.object.type===`Identifier`?`${t.object.name}.${t.property.name}`:null}const f=r({meta:{type:`problem`,docs:{description:`禁止使用 console 方法,必须使用 @longzai-intelligence/logger-preset-* 或 react-devtools(ADR 0038)`}},createOnce(e){return{CallExpression(t){if(t.type!==`CallExpression`)return;let n=d(t);n&&u.has(n)&&e.report({node:t,message:`检测到 '${n}' — 必须使用 @longzai-intelligence/logger-preset-* 代替(ADR 0038)`})}}}}),p=/\/src\/(index|main|cli)\.(ts|mts|cts)$/,m=/(^|\/)dist\//;function ne(e){return e.replace(/\\/g,`/`)}function h(e){return typeof e==`object`&&!!e}function re(e){return e.startsWith(`#!`)}function g(e){return p.test(ne(e))}function ie(e){let t=e;for(let e=0;e<4;e+=1){let e=te(t,`package.json`);if(a(e))try{let t=JSON.parse(ee(e,`utf8`));return h(t)?t:null}catch{return null}let n=o(t);if(n===t)break;t=n}return null}function ae(e){let t=e.bin;return(typeof t==`string`?[t]:h(t)?Object.values(t).filter(e=>typeof e==`string`):[]).some(e=>m.test(e.replace(/^\.\//,``)))}const _={noHandwrittenShebang:`入口源码手写 shebang 属被裁定的错误方式,bin 产物首行 shebang 应由 "lzi-builder.config.ts" 的 banner 在构建期注入。请删除源码首行的 "#!" 行并补 banner 配置。`},v=r({meta:{type:`problem`,docs:{description:`禁止所属包 bin 指向 dist 产物的入口源码手写 shebang`}},createOnce(e){return{before(){let t=e.filename;if(!g(t))return!1},Program(t){let n=e.sourceCode.text;if(!re(n))return;let r=ie(o(o(e.filename)));r!==null&&ae(r)&&e.report({node:t,message:_.noHandwrittenShebang})}}}}),y=s.object({type:s.literal(`TSTypeLiteral`)}),b=s.object({type:s.literal(`TSFunctionType`)}),x=s.object({type:s.literal(`TSUnionType`),types:s.array(s.unknown())}),oe=s.object({type:s.literal(`TSIntersectionType`),types:s.array(s.unknown())}),se=s.object({type:s.literal(`Identifier`),name:s.string()}),ce=s.object({type:s.literal(`RestElement`),argument:s.object({name:s.string()})}),le=s.union([se,ce]),S=s.object({typeAnnotation:s.unknown()}),ue=s.object({type:s.literal(`MethodDefinition`),key:s.object({type:s.string(),name:s.optional(s.string())}),value:s.object({params:s.optional(s.array(s.unknown())),returnType:s.optional(s.union([S,s.null()]))}),kind:s.enum([`method`,`constructor`,`get`,`set`])}),de=s.object({returnType:S}),fe=s.object({id:s.optional(s.object({name:s.optional(s.string())})),params:s.optional(s.array(s.unknown())),returnType:s.optional(s.unknown())}),pe=s.object({params:s.optional(s.array(s.unknown()))});function C(e){return y.safeParse(e).success}function w(e){return b.safeParse(e).success}function T(e){return x.safeParse(e).success}function E(e){return oe.safeParse(e).success}function D(e){return le.safeParse(e).success}function O(e){if(typeof e!=`object`||!e||!(`type`in e))return!1;let t=[`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`,`MethodDefinition`],n=e.type;return typeof n==`string`&&t.includes(n)}function k(e){return ue.safeParse(e).success}function A(e){return de.safeParse(e).success}function j(e){return fe.safeParse(e).success}function M(e){return pe.safeParse(e).success}function N(e){return C(e)||w(e)?!0:T(e)||E(e)?e.types.some(N):!1}function P(e){return C(e)?`对象类型`:w(e)?`函数类型`:`内联类型`}function F(e){return D(e)?e.type===`Identifier`?e.name:e.type===`RestElement`?e.argument.name:null:null}function I(e,t,n,r,i,a){i?e.report({node:t,message:`参数 "${n}" 使用了内联${r}定义。请将其提取为具名的 type。`}):a?e.report({node:t,message:`方法 "${a}" 的参数 "${n}" 使用了内联${r}定义。请将其提取为具名的 type。`}):e.report({node:t,message:`参数 "${n}" 使用了内联${r}定义。请将其提取为具名的 type。`})}function L(e,t,n,r,i){i?e.report({node:t,message:`方法 "${i}" 的返回值使用了内联${n}定义。请将其提取为具名的 type。`}):r?e.report({node:t,message:`函数 "${r}" 的返回值使用了内联${n}定义。请将其提取为具名的 type。`}):e.report({node:t,message:`匿名函数的返回值使用了内联${n}定义。请将其提取为具名的 type。`})}function R(e,t,n,r,i){if(typeof e!=`object`||!e||!(`typeAnnotation`in e)||e.typeAnnotation===null||typeof e.typeAnnotation!=`object`||!(`typeAnnotation`in e.typeAnnotation))return;let a=e.typeAnnotation.typeAnnotation;N(a)&&I(t,n,F(e)??`未知参数`,P(a),r,i)}function z(e,t,n,r,i){for(let a of e)R(a,t,n,i??!1,r)}function B(e,t,n,r,i){if(typeof e!=`object`||!e||!(`typeAnnotation`in e))return;let a=e.typeAnnotation;N(a)&&L(t,n,P(a),r,i)}function V(e,t){if(!O(e)||!j(e))return;let n=null;`id`in e&&e.id!==null&&typeof e.id==`object`&&`name`in e.id&&typeof e.id.name==`string`&&(n=e.id.name),M(e)&&z(e.params??[],t,e),A(e)&&B(e.returnType,t,e,n??void 0)}function me(e,t){O(e)&&M(e)&&(M(e)&&z(e.params??[],t,e),A(e)&&B(e.returnType,t,e))}function he(e,t){if(!k(e))return;let n=e.key,r=n&&`name`in n&&typeof n.name==`string`?n.name:`未知方法`,i=e.value;if(i&&`params`in i&&Array.isArray(i.params)&&z(i.params,t,e,r,e.kind===`constructor`),i&&`returnType`in i&&i.returnType&&typeof i.returnType==`object`&&`typeAnnotation`in i.returnType){let n=i.returnType;B(n,t,e,void 0,r)}}const H=r({meta:{type:`suggestion`,docs:{description:`禁止在函数参数和返回值中使用内联类型定义,强制使用具名类型`}},createOnce(e){return{FunctionDeclaration(t){V(t,e)},FunctionExpression(t){V(t,e)},ArrowFunctionExpression(t){me(t,e)},MethodDefinition(t){he(t,e)}}}});function ge(e){let t=[];if(e.type===`Identifier`&&t.push(e.name),e.type===`ObjectPattern`)for(let n of e.properties)n.type===`Property`&&`value`in n?n.value.type===`Identifier`&&t.push(n.value.name):n.type===`RestElement`&&n.argument.type===`Identifier`&&t.push(n.argument.name);if(e.type===`ArrayPattern`)for(let n of e.elements)n&&n.type===`Identifier`&&t.push(n.name);return t}const U=r({meta:{type:`suggestion`,docs:{description:`将 export const/let/var 拆分为独立的声明和导出语句`}},createOnce(e){return{ExportNamedDeclaration(t){if(!t.declaration||t.declaration.type!==`VariableDeclaration`)return;let n=t.declaration;if(n.kind!==`const`&&n.kind!==`let`&&n.kind!==`var`||n.declarations.length===0)return;let r=[];for(let e of n.declarations)r.push(...ge(e.id));r.length!==0&&e.report({node:t,message:`应将 \`export ${n.kind} ${r.join(`, `)}\` 拆分为独立的声明和导出语句`})}}}}),W=[{suffix:`.service.drizzle.ts`,classSuffix:`Service`,isInterface:!1,isPrefix:!1},{suffix:`.service.memory.ts`,classSuffix:`Service`,isInterface:!1,isPrefix:!1},{suffix:`.service.ts`,classSuffix:`Service`,isInterface:!1,isPrefix:!1},{suffix:`.controller.ts`,classSuffix:`Controller`,isInterface:!1,isPrefix:!1},{suffix:`.module.ts`,classSuffix:`Module`,isInterface:!1,isPrefix:!1},{suffix:`.repository.drizzle.ts`,classSuffix:`Repository`,isInterface:!1,isPrefix:!1},{suffix:`.repository.memory.ts`,classSuffix:`Repository`,isInterface:!1,isPrefix:!1},{suffix:`.repository.interface.ts`,classSuffix:`Repository`,isInterface:!0,isPrefix:!0},{suffix:`.repository.ts`,classSuffix:`Repository`,isInterface:!1,isPrefix:!1},{suffix:`.entity.ts`,classSuffix:`Entity`,isInterface:!1,isPrefix:!1},{suffix:`.orm-entity.ts`,classSuffix:`OrmEntity`,isInterface:!1,isPrefix:!1},{suffix:`.dto.ts`,classSuffix:`DTO`,isInterface:!1,isPrefix:!1},{suffix:`.port.interface.ts`,classSuffix:`Port`,isInterface:!0,isPrefix:!0},{suffix:`.interface.ts`,classSuffix:``,isInterface:!0,isPrefix:!0},{suffix:`.port.ts`,classSuffix:`Port`,isInterface:!0,isPrefix:!1},{suffix:`.port.adapter.ts`,classSuffix:`PortAdapter`,isInterface:!1,isPrefix:!1},{suffix:`.adapter.ts`,classSuffix:`Adapter`,isInterface:!1,isPrefix:!1},{suffix:`.events.ts`,classSuffix:`Event`,isInterface:!1,isPrefix:!1},{suffix:`.mapper.ts`,classSuffix:`Mapper`,isInterface:!1,isPrefix:!1},{suffix:`.vo.ts`,classSuffix:`VO`,isInterface:!1,isPrefix:!1},{suffix:`.usecase.ts`,classSuffix:`UseCase`,isInterface:!1,isPrefix:!1},{suffix:`.errors.ts`,classSuffix:`Error`,isInterface:!1,isPrefix:!1}];function G(e){for(let t of W)if(e.endsWith(t.suffix))return t;return null}function K(e,t){if(t.isPrefix&&t.isInterface){if(t.classSuffix){let n=t.classSuffix;return e.startsWith(`I`)&&e.endsWith(n)&&e.length>1+n.length}return e.startsWith(`I`)&&e.length>1}return t.isPrefix?e.startsWith(`I`)&&e.length>1:e.endsWith(t.classSuffix)&&e.length>t.classSuffix.length}function q(e){return e.isPrefix&&e.isInterface?e.classSuffix?`I${e.classSuffix}(如 IUser${e.classSuffix})`:`I 前缀(如 IUser)`:e.isPrefix?`I 前缀(如 IUser)`:`${e.classSuffix} 后缀`}const J=r({meta:{type:`problem`,docs:{description:`强制执行类名与文件类型后缀的一致性`}},createOnce(e){return{before(){let t=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``;if(t.endsWith(`.test.ts`)||t.endsWith(`.spec.ts`)||!G(t))return!1},ClassDeclaration(t){let n=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``,r=G(n);if(!r||r.isInterface||!t.id)return;let i=t.id.name;K(i,r)||e.report({node:t,message:`类名 "${i}" 不符合命名规范。文件 "${n}" 中的类应使用 ${q(r)}`})},TSInterfaceDeclaration(t){let n=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``,r=G(n);if(!r||!r.isInterface)return;let i=t.id.name;K(i,r)||e.report({node:t,message:`接口名 "${i}" 不符合命名规范。文件 "${n}" 中的接口应使用 ${q(r)}`})}}}});function Y(e){return e.endsWith(`.dto.ts`)}function X(e){return e.endsWith(`DTO`)}const Z=r({meta:{type:`problem`,docs:{description:`强制执行 DTO 文件中的接口命名规范(Dto 后缀,驼峰式)`}},createOnce(e){return{before(){let t=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``;if(t.endsWith(`.test.ts`)||t.endsWith(`.spec.ts`)||!Y(t))return!1},TSInterfaceDeclaration(n){let r=n.id.name;X(r)?e.report({node:n,message:`接口名 "${r}" 后缀应使用 Dto(驼峰式)而非 DTO(全大写)`}):t(r)||e.report({node:n,message:`DTO 文件中的接口名 "${r}" 应以 Dto 结尾(如 UserResponseDto)`})}}}}),_e=[`types.ts`,`types.d.ts`],ve=[`.port.interface.ts`,`.repository.interface.ts`,`.types.ts`,`.types.d.ts`,`.events.ts`,`.d.ts`];function ye(t,r){return e(t)?!1:!r.endsWith(`.dto.ts`)||n(t)}function be(e){return e.endsWith(`.dto.ts`)?`DTO 后缀(如 UserDTO),禁止 I 前缀`:`PascalCase(如 User、UserRepository),禁止 I 前缀`}function xe(e){if(_e.includes(e))return!0;for(let t of ve)if(e.endsWith(t))return!0;return!1}function Se(e){return e.endsWith(`.port.ts`)?e.replace(`.port.ts`,`.port.interface.ts`):e.endsWith(`.repository.ts`)?e.replace(`.repository.ts`,`.repository.interface.ts`):e.replace(`.ts`,`.interface.ts`)}const Q=r({meta:{type:`problem`,docs:{description:`强制执行接口命名规范(禁止 I 前缀,使用 PascalCase)和文件命名规范`}},createOnce(t){return{before(){let e=t.filename.replace(/\\/g,`/`).split(`/`).pop()??``;if(e.endsWith(`.test.ts`)||e.endsWith(`.spec.ts`)||xe(e))return!1},TSInterfaceDeclaration(n){let r=t.filename.replace(/\\/g,`/`).split(`/`).pop()??``,i=r.endsWith(`.interface.ts`)||r.endsWith(`.interface.tsx`),a=n.id.name;ye(a,r)||(e(a)?t.report({node:n,message:`接口名 "${a}" 使用了 I 前缀。现代 TypeScript 不推荐使用匈牙利命名法,建议使用 "${a.substring(1)}"`}):r.endsWith(`.dto.ts`)&&a.endsWith(`Dto`)?t.report({node:n,message:`接口名 "${a}" 后缀应使用 DTO(全大写)而非 Dto(驼峰式)`}):t.report({node:n,message:`接口名 "${a}" 不符合命名规范。接口名应使用 ${be(r)}`})),!i&&!r.endsWith(`.dto.ts`)&&!r.endsWith(`.tsx`)&&t.report({node:n,message:`包含接口 "${a}" 的文件 "${r}" 应命名为 "${Se(r)}"`})}}}}),$=i({meta:{name:`@longzai-intelligence-oxlint/code-style-plugin`},rules:{"no-console":f,"no-inline-type-definition":H,"prefer-split-export-const":U,"require-interface-naming":Q,"require-dto-naming":Z,"require-class-suffix":J,"no-class-suffix-alias":l,"no-handwritten-shebang":v}});export{W as SUFFIX_MAPPINGS,$ as codeStylePlugin,$ as default,P as getInlineTypeDescription,F as getParamName,e as hasIPrefix,N as hasInlineType,Y as isDtoFile,O as isFunctionNode,k as isMethodDefinition,w as isTSFunctionType,E as isTSIntersectionType,C as isTSTypeLiteral,T as isTSUnionType,l as noClassSuffixAliasRule,f as noConsoleRule,v as noHandwrittenShebangRule,H as noInlineTypeDefinitionRule,U as preferSplitExportConstRule,J as requireClassSuffixRule,Z as requireDtoNamingRule,Q as requireInterfaceNamingRule};
|
|
1
|
+
import"../rolldown-runtime-BqT_7tdF.js";import"../rolldown-runtime-BqT_7tdF-BqT_7tdF.js";import{n as e,r as t,t as n}from"../dist-CskvMq7J.js";import{defineRule as r,eslintCompatPlugin as i}from"@oxlint/plugins";import{existsSync as a,readFileSync as ee}from"node:fs";import{dirname as o,join as te}from"node:path";import*as s from"zod/mini";function c(e){return e.endsWith(`Class`)}const l=r({meta:{type:`problem`,docs:{description:`禁止在 import 别名中使用 "Class" 后缀`}},createOnce(e){return{ImportSpecifier(t){let n=t.local.name,r=t.imported.type===`Identifier`?t.imported.name:n;n!==r&&c(n)&&e.report({node:t,message:`导入别名 "${n}" 使用了 "Class" 后缀,这是不允许的命名方式。请使用更具描述性的名称,或直接使用原始名称 "${r}"`})}}}}),u=/* @__PURE__ */ new Set([`console.log`,`console.warn`,`console.error`,`console.info`,`console.debug`,`console.trace`,`console.dir`,`console.table`]);function d(e){let t=e.callee;return t.type===`Identifier`?t.name:t.type===`MemberExpression`&&t.property.type===`Identifier`&&t.object.type===`Identifier`?`${t.object.name}.${t.property.name}`:null}const f=r({meta:{type:`problem`,docs:{description:`禁止使用 console 方法,必须使用 @longzai-intelligence/logger-preset-* 或 react-devtools(ADR 0038)`}},createOnce(e){return{CallExpression(t){if(t.type!==`CallExpression`)return;let n=d(t);n&&u.has(n)&&e.report({node:t,message:`检测到 '${n}' — 必须使用 @longzai-intelligence/logger-preset-* 代替(ADR 0038)`})}}}}),p=/\/src\/(index|main|cli)\.(ts|mts|cts)$/,m=/(^|\/)dist\//;function ne(e){return e.replace(/\\/g,`/`)}function h(e){return typeof e==`object`&&!!e}function re(e){return e.startsWith(`#!`)}function g(e){return p.test(ne(e))}function ie(e){let t=e;for(let e=0;e<4;e+=1){let e=te(t,`package.json`);if(a(e))try{let t=JSON.parse(ee(e,`utf8`));return h(t)?t:null}catch{return null}let n=o(t);if(n===t)break;t=n}return null}function ae(e){let t=e.bin;return(typeof t==`string`?[t]:h(t)?Object.values(t).filter(e=>typeof e==`string`):[]).some(e=>m.test(e.replace(/^\.\//,``)))}const oe={noHandwrittenShebang:`入口源码手写 shebang 属被裁定的错误方式,bin 产物首行 shebang 应由 "lzi-builder.config.ts" 的 banner 在构建期注入。请删除源码首行的 "#!" 行并补 banner 配置。`},_=r({meta:{type:`problem`,docs:{description:`禁止所属包 bin 指向 dist 产物的入口源码手写 shebang`}},createOnce(e){return{before(){let t=e.filename;if(!g(t))return!1},Program(t){let n=e.sourceCode.text;if(!re(n))return;let r=ie(o(o(e.filename)));r!==null&&ae(r)&&e.report({node:t,message:oe.noHandwrittenShebang})}}}}),v=s.object({type:s.literal(`TSTypeLiteral`)}),y=s.object({type:s.literal(`TSFunctionType`)}),b=s.object({type:s.literal(`TSUnionType`),types:s.array(s.unknown())}),se=s.object({type:s.literal(`TSIntersectionType`),types:s.array(s.unknown())}),ce=s.object({type:s.literal(`Identifier`),name:s.string()}),le=s.object({type:s.literal(`RestElement`),argument:s.object({name:s.string()})}),ue=s.union([ce,le]),x=s.object({typeAnnotation:s.unknown()}),de=s.object({type:s.literal(`MethodDefinition`),key:s.object({type:s.string(),name:s.optional(s.string())}),value:s.object({params:s.optional(s.array(s.unknown())),returnType:s.optional(s.union([x,s.null()]))}),kind:s.enum([`method`,`constructor`,`get`,`set`])}),fe=s.object({returnType:x}),pe=s.object({id:s.optional(s.object({name:s.optional(s.string())})),params:s.optional(s.array(s.unknown())),returnType:s.optional(s.unknown())}),me=s.object({params:s.optional(s.array(s.unknown()))});function S(e){return v.safeParse(e).success}function C(e){return y.safeParse(e).success}function w(e){return b.safeParse(e).success}function T(e){return se.safeParse(e).success}function E(e){return ue.safeParse(e).success}function D(e){if(typeof e!=`object`||!e||!(`type`in e))return!1;let t=[`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`,`MethodDefinition`],n=e.type;return typeof n==`string`&&t.includes(n)}function O(e){return de.safeParse(e).success}function k(e){return fe.safeParse(e).success}function A(e){return pe.safeParse(e).success}function j(e){return me.safeParse(e).success}function M(e){return S(e)||C(e)?!0:w(e)||T(e)?e.types.some(M):!1}function N(e){return S(e)?`对象类型`:C(e)?`函数类型`:`内联类型`}function P(e){return E(e)?e.type===`Identifier`?e.name:e.type===`RestElement`?e.argument.name:null:null}function F(e,t,n,r,i,a){i?e.report({node:t,message:`参数 "${n}" 使用了内联${r}定义。请将其提取为具名的 type。`}):a?e.report({node:t,message:`方法 "${a}" 的参数 "${n}" 使用了内联${r}定义。请将其提取为具名的 type。`}):e.report({node:t,message:`参数 "${n}" 使用了内联${r}定义。请将其提取为具名的 type。`})}function I(e,t,n,r,i){i?e.report({node:t,message:`方法 "${i}" 的返回值使用了内联${n}定义。请将其提取为具名的 type。`}):r?e.report({node:t,message:`函数 "${r}" 的返回值使用了内联${n}定义。请将其提取为具名的 type。`}):e.report({node:t,message:`匿名函数的返回值使用了内联${n}定义。请将其提取为具名的 type。`})}function L(e,t,n,r,i){if(typeof e!=`object`||!e||!(`typeAnnotation`in e)||e.typeAnnotation===null||typeof e.typeAnnotation!=`object`||!(`typeAnnotation`in e.typeAnnotation))return;let a=e.typeAnnotation.typeAnnotation;M(a)&&F(t,n,P(e)??`未知参数`,N(a),r,i)}function R(e,t,n,r,i){for(let a of e)L(a,t,n,i??!1,r)}function z(e,t,n,r,i){if(typeof e!=`object`||!e||!(`typeAnnotation`in e))return;let a=e.typeAnnotation;M(a)&&I(t,n,N(a),r,i)}function B(e,t){if(!D(e)||!A(e))return;let n=null;`id`in e&&e.id!==null&&typeof e.id==`object`&&`name`in e.id&&typeof e.id.name==`string`&&(n=e.id.name),j(e)&&R(e.params??[],t,e),k(e)&&z(e.returnType,t,e,n??void 0)}function he(e,t){D(e)&&j(e)&&(j(e)&&R(e.params??[],t,e),k(e)&&z(e.returnType,t,e))}function ge(e,t){if(!O(e))return;let n=e.key,r=n&&`name`in n&&typeof n.name==`string`?n.name:`未知方法`,i=e.value;if(i&&`params`in i&&Array.isArray(i.params)&&R(i.params,t,e,r,e.kind===`constructor`),i&&`returnType`in i&&i.returnType&&typeof i.returnType==`object`&&`typeAnnotation`in i.returnType){let n=i.returnType;z(n,t,e,void 0,r)}}const V=r({meta:{type:`suggestion`,docs:{description:`禁止在函数参数和返回值中使用内联类型定义,强制使用具名类型`}},createOnce(e){return{FunctionDeclaration(t){B(t,e)},FunctionExpression(t){B(t,e)},ArrowFunctionExpression(t){he(t,e)},MethodDefinition(t){ge(t,e)}}}}),H=/^(?:eslint-disable(?:-next-line|-line)?|eslint-enable|oxlint-disable(?:-next-line|-line)?|oxlint-enable|biome-ignore|stylelint-disable(?:-next-line|-line)?|stylelint-enable|@ts-ignore|@ts-nocheck)(?=[\s,]|$)/;function _e(e){let t=e.trimStart();return H.exec(t)?.[0]??null}const U=r({meta:{type:`problem`,docs:{description:`禁止 eslint-disable、oxlint-disable、biome-ignore、stylelint-disable、@ts-ignore、@ts-nocheck 等抑制注释`}},createOnce(e){return{Program(){let t=e.sourceCode.getAllComments();for(let n of t){if(n.type===`Shebang`)continue;let t=_e(n.value);t!==null&&e.report({node:n,message:`检测到抑制指令 ${t},抑制注释不是合法豁免手段,请从源头消除违例或在包级 oxlint.config.ts 的 ignorePatterns 登记路径豁免`})}}}}});function ve(e){let t=[];if(e.type===`Identifier`&&t.push(e.name),e.type===`ObjectPattern`)for(let n of e.properties)n.type===`Property`&&`value`in n?n.value.type===`Identifier`&&t.push(n.value.name):n.type===`RestElement`&&n.argument.type===`Identifier`&&t.push(n.argument.name);if(e.type===`ArrayPattern`)for(let n of e.elements)n&&n.type===`Identifier`&&t.push(n.name);return t}const W=r({meta:{type:`suggestion`,docs:{description:`将 export const/let/var 拆分为独立的声明和导出语句`}},createOnce(e){return{ExportNamedDeclaration(t){if(!t.declaration||t.declaration.type!==`VariableDeclaration`)return;let n=t.declaration;if(n.kind!==`const`&&n.kind!==`let`&&n.kind!==`var`||n.declarations.length===0)return;let r=[];for(let e of n.declarations)r.push(...ve(e.id));r.length!==0&&e.report({node:t,message:`应将 \`export ${n.kind} ${r.join(`, `)}\` 拆分为独立的声明和导出语句`})}}}}),G=[{suffix:`.service.drizzle.ts`,classSuffix:`Service`,isInterface:!1,isPrefix:!1},{suffix:`.service.memory.ts`,classSuffix:`Service`,isInterface:!1,isPrefix:!1},{suffix:`.service.ts`,classSuffix:`Service`,isInterface:!1,isPrefix:!1},{suffix:`.controller.ts`,classSuffix:`Controller`,isInterface:!1,isPrefix:!1},{suffix:`.module.ts`,classSuffix:`Module`,isInterface:!1,isPrefix:!1},{suffix:`.repository.drizzle.ts`,classSuffix:`Repository`,isInterface:!1,isPrefix:!1},{suffix:`.repository.memory.ts`,classSuffix:`Repository`,isInterface:!1,isPrefix:!1},{suffix:`.repository.interface.ts`,classSuffix:`Repository`,isInterface:!0,isPrefix:!0},{suffix:`.repository.ts`,classSuffix:`Repository`,isInterface:!1,isPrefix:!1},{suffix:`.entity.ts`,classSuffix:`Entity`,isInterface:!1,isPrefix:!1},{suffix:`.orm-entity.ts`,classSuffix:`OrmEntity`,isInterface:!1,isPrefix:!1},{suffix:`.dto.ts`,classSuffix:`DTO`,isInterface:!1,isPrefix:!1},{suffix:`.port.interface.ts`,classSuffix:`Port`,isInterface:!0,isPrefix:!0},{suffix:`.interface.ts`,classSuffix:``,isInterface:!0,isPrefix:!0},{suffix:`.port.ts`,classSuffix:`Port`,isInterface:!0,isPrefix:!1},{suffix:`.port.adapter.ts`,classSuffix:`PortAdapter`,isInterface:!1,isPrefix:!1},{suffix:`.adapter.ts`,classSuffix:`Adapter`,isInterface:!1,isPrefix:!1},{suffix:`.events.ts`,classSuffix:`Event`,isInterface:!1,isPrefix:!1},{suffix:`.mapper.ts`,classSuffix:`Mapper`,isInterface:!1,isPrefix:!1},{suffix:`.vo.ts`,classSuffix:`VO`,isInterface:!1,isPrefix:!1},{suffix:`.usecase.ts`,classSuffix:`UseCase`,isInterface:!1,isPrefix:!1},{suffix:`.errors.ts`,classSuffix:`Error`,isInterface:!1,isPrefix:!1}];function K(e){for(let t of G)if(e.endsWith(t.suffix))return t;return null}function q(e,t){if(t.isPrefix&&t.isInterface){if(t.classSuffix){let n=t.classSuffix;return e.startsWith(`I`)&&e.endsWith(n)&&e.length>1+n.length}return e.startsWith(`I`)&&e.length>1}return t.isPrefix?e.startsWith(`I`)&&e.length>1:e.endsWith(t.classSuffix)&&e.length>t.classSuffix.length}function J(e){return e.isPrefix&&e.isInterface?e.classSuffix?`I${e.classSuffix}(如 IUser${e.classSuffix})`:`I 前缀(如 IUser)`:e.isPrefix?`I 前缀(如 IUser)`:`${e.classSuffix} 后缀`}const Y=r({meta:{type:`problem`,docs:{description:`强制执行类名与文件类型后缀的一致性`}},createOnce(e){return{before(){let t=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``;if(t.endsWith(`.test.ts`)||t.endsWith(`.spec.ts`)||!K(t))return!1},ClassDeclaration(t){let n=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``,r=K(n);if(!r||r.isInterface||!t.id)return;let i=t.id.name;q(i,r)||e.report({node:t,message:`类名 "${i}" 不符合命名规范。文件 "${n}" 中的类应使用 ${J(r)}`})},TSInterfaceDeclaration(t){let n=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``,r=K(n);if(!r||!r.isInterface)return;let i=t.id.name;q(i,r)||e.report({node:t,message:`接口名 "${i}" 不符合命名规范。文件 "${n}" 中的接口应使用 ${J(r)}`})}}}});function X(e){return e.endsWith(`.dto.ts`)}function ye(e){return e.endsWith(`DTO`)}const Z=r({meta:{type:`problem`,docs:{description:`强制执行 DTO 文件中的接口命名规范(Dto 后缀,驼峰式)`}},createOnce(e){return{before(){let t=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``;if(t.endsWith(`.test.ts`)||t.endsWith(`.spec.ts`)||!X(t))return!1},TSInterfaceDeclaration(n){let r=n.id.name;ye(r)?e.report({node:n,message:`接口名 "${r}" 后缀应使用 Dto(驼峰式)而非 DTO(全大写)`}):t(r)||e.report({node:n,message:`DTO 文件中的接口名 "${r}" 应以 Dto 结尾(如 UserResponseDto)`})}}}}),be=[`types.ts`,`types.d.ts`],xe=[`.port.interface.ts`,`.repository.interface.ts`,`.types.ts`,`.types.d.ts`,`.events.ts`,`.d.ts`];function Se(t,r){return e(t)?!1:!r.endsWith(`.dto.ts`)||n(t)}function Ce(e){return e.endsWith(`.dto.ts`)?`DTO 后缀(如 UserDTO),禁止 I 前缀`:`PascalCase(如 User、UserRepository),禁止 I 前缀`}function we(e){if(be.includes(e))return!0;for(let t of xe)if(e.endsWith(t))return!0;return!1}function Te(e){return e.endsWith(`.port.ts`)?e.replace(`.port.ts`,`.port.interface.ts`):e.endsWith(`.repository.ts`)?e.replace(`.repository.ts`,`.repository.interface.ts`):e.replace(`.ts`,`.interface.ts`)}const Q=r({meta:{type:`problem`,docs:{description:`强制执行接口命名规范(禁止 I 前缀,使用 PascalCase)和文件命名规范`}},createOnce(t){return{before(){let e=t.filename.replace(/\\/g,`/`).split(`/`).pop()??``;if(e.endsWith(`.test.ts`)||e.endsWith(`.spec.ts`)||we(e))return!1},TSInterfaceDeclaration(n){let r=t.filename.replace(/\\/g,`/`).split(`/`).pop()??``,i=r.endsWith(`.interface.ts`)||r.endsWith(`.interface.tsx`),a=n.id.name;Se(a,r)||(e(a)?t.report({node:n,message:`接口名 "${a}" 使用了 I 前缀。现代 TypeScript 不推荐使用匈牙利命名法,建议使用 "${a.substring(1)}"`}):r.endsWith(`.dto.ts`)&&a.endsWith(`Dto`)?t.report({node:n,message:`接口名 "${a}" 后缀应使用 DTO(全大写)而非 Dto(驼峰式)`}):t.report({node:n,message:`接口名 "${a}" 不符合命名规范。接口名应使用 ${Ce(r)}`})),!i&&!r.endsWith(`.dto.ts`)&&!r.endsWith(`.tsx`)&&t.report({node:n,message:`包含接口 "${a}" 的文件 "${r}" 应命名为 "${Te(r)}"`})}}}}),$=i({meta:{name:`@longzai-intelligence-oxlint/code-style-plugin`},rules:{"no-console":f,"no-inline-type-definition":V,"prefer-split-export-const":W,"require-interface-naming":Q,"require-dto-naming":Z,"require-class-suffix":Y,"no-class-suffix-alias":l,"no-handwritten-shebang":_,"no-lint-suppression":U}});export{G as SUFFIX_MAPPINGS,$ as codeStylePlugin,$ as default,N as getInlineTypeDescription,P as getParamName,e as hasIPrefix,M as hasInlineType,X as isDtoFile,D as isFunctionNode,O as isMethodDefinition,C as isTSFunctionType,T as isTSIntersectionType,S as isTSTypeLiteral,w as isTSUnionType,l as noClassSuffixAliasRule,f as noConsoleRule,_ as noHandwrittenShebangRule,V as noInlineTypeDefinitionRule,U as noLintSuppressionRule,W as preferSplitExportConstRule,Y as requireClassSuffixRule,Z as requireDtoNamingRule,Q as requireInterfaceNamingRule};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-oxlint/presets",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Longzai Intelligence oxlint 配置预设",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -100,33 +100,33 @@
|
|
|
100
100
|
"zod": "^4.4.3"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
|
-
"@longzai-intelligence-oxlint/architecture-core-plugin": "0.2.
|
|
104
|
-
"@longzai-intelligence-oxlint/architecture-electron-plugin": "0.2.
|
|
105
|
-
"@longzai-intelligence-oxlint/architecture-library-plugin": "0.2.
|
|
106
|
-
"@longzai-intelligence-oxlint/code-style-plugin": "0.2.
|
|
107
|
-
"@longzai-intelligence-oxlint/composer-plugin": "0.2.
|
|
108
|
-
"@longzai-intelligence-oxlint/core": "0.2.
|
|
109
|
-
"@longzai-intelligence-oxlint/design-rules-plugin": "0.2.
|
|
110
|
-
"@longzai-intelligence-oxlint/elysia-route-plugin": "0.2.
|
|
111
|
-
"@longzai-intelligence-oxlint/eslint-config-plugin": "0.2.
|
|
112
|
-
"@longzai-intelligence-oxlint/file-naming-plugin": "0.2.
|
|
113
|
-
"@longzai-intelligence-oxlint/lzi-builder-config-plugin": "0.2.
|
|
114
|
-
"@longzai-intelligence-oxlint/lzi-config-plugin": "0.2.
|
|
115
|
-
"@longzai-intelligence-oxlint/nestjs-route-plugin": "0.2.
|
|
116
|
-
"@longzai-intelligence-oxlint/package-json-plugin": "0.2.
|
|
117
|
-
"@longzai-intelligence-oxlint/perfectionist-plugin": "0.2.
|
|
118
|
-
"@longzai-intelligence-oxlint/react-plugin": "0.2.
|
|
119
|
-
"@longzai-intelligence-oxlint/schema-type-separation-plugin": "0.2.
|
|
120
|
-
"@longzai-intelligence-oxlint/stylistic-plugin": "0.2.
|
|
121
|
-
"@longzai-intelligence-oxlint/tsconfig-plugin": "0.2.
|
|
122
|
-
"@longzai-intelligence-oxlint/tsdoc-plugin": "0.2.
|
|
123
|
-
"@longzai-intelligence-oxlint/tsdown-config-plugin": "0.2.
|
|
124
|
-
"@longzai-intelligence-oxlint/tsup-config-plugin": "0.2.
|
|
125
|
-
"@longzai-intelligence-oxlint/typeorm-plugin": "0.2.
|
|
126
|
-
"@longzai-intelligence-oxlint/typescript-eslint-plugin": "0.2.
|
|
127
|
-
"@longzai-intelligence-oxlint/utils": "0.2.
|
|
128
|
-
"@longzai-intelligence-oxlint/vitest-config-plugin": "0.2.
|
|
129
|
-
"@longzai-intelligence-oxlint/zod-plugin": "0.2.
|
|
103
|
+
"@longzai-intelligence-oxlint/architecture-core-plugin": "0.2.4",
|
|
104
|
+
"@longzai-intelligence-oxlint/architecture-electron-plugin": "0.2.4",
|
|
105
|
+
"@longzai-intelligence-oxlint/architecture-library-plugin": "0.2.4",
|
|
106
|
+
"@longzai-intelligence-oxlint/code-style-plugin": "0.2.4",
|
|
107
|
+
"@longzai-intelligence-oxlint/composer-plugin": "0.2.4",
|
|
108
|
+
"@longzai-intelligence-oxlint/core": "0.2.4",
|
|
109
|
+
"@longzai-intelligence-oxlint/design-rules-plugin": "0.2.4",
|
|
110
|
+
"@longzai-intelligence-oxlint/elysia-route-plugin": "0.2.4",
|
|
111
|
+
"@longzai-intelligence-oxlint/eslint-config-plugin": "0.2.4",
|
|
112
|
+
"@longzai-intelligence-oxlint/file-naming-plugin": "0.2.4",
|
|
113
|
+
"@longzai-intelligence-oxlint/lzi-builder-config-plugin": "0.2.4",
|
|
114
|
+
"@longzai-intelligence-oxlint/lzi-config-plugin": "0.2.4",
|
|
115
|
+
"@longzai-intelligence-oxlint/nestjs-route-plugin": "0.2.4",
|
|
116
|
+
"@longzai-intelligence-oxlint/package-json-plugin": "0.2.4",
|
|
117
|
+
"@longzai-intelligence-oxlint/perfectionist-plugin": "0.2.4",
|
|
118
|
+
"@longzai-intelligence-oxlint/react-plugin": "0.2.4",
|
|
119
|
+
"@longzai-intelligence-oxlint/schema-type-separation-plugin": "0.2.4",
|
|
120
|
+
"@longzai-intelligence-oxlint/stylistic-plugin": "0.2.4",
|
|
121
|
+
"@longzai-intelligence-oxlint/tsconfig-plugin": "0.2.4",
|
|
122
|
+
"@longzai-intelligence-oxlint/tsdoc-plugin": "0.2.4",
|
|
123
|
+
"@longzai-intelligence-oxlint/tsdown-config-plugin": "0.2.4",
|
|
124
|
+
"@longzai-intelligence-oxlint/tsup-config-plugin": "0.2.4",
|
|
125
|
+
"@longzai-intelligence-oxlint/typeorm-plugin": "0.2.4",
|
|
126
|
+
"@longzai-intelligence-oxlint/typescript-eslint-plugin": "0.2.4",
|
|
127
|
+
"@longzai-intelligence-oxlint/utils": "0.2.4",
|
|
128
|
+
"@longzai-intelligence-oxlint/vitest-config-plugin": "0.2.4",
|
|
129
|
+
"@longzai-intelligence-oxlint/zod-plugin": "0.2.4",
|
|
130
130
|
"@vitest/coverage-v8": "^4.1.10"
|
|
131
131
|
},
|
|
132
132
|
"peerDependencies": {
|