@longzai-intelligence-oxlint/presets 0.2.3 → 0.2.5

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{n as e}from"../dist-CskvMq7J.js";import{defineRule as t,eslintCompatPlugin as n}from"@oxlint/plugins";import{existsSync as r,readdirSync as i}from"node:fs";import a from"node:path";const o=[`index.ts`,`index.tsx`,`main.ts`,`main.tsx`,`App.tsx`],s=[`types.ts`,`errors.ts`,`constants.ts`],c=[`persistence.ts`,`typeorm.ts`,`hono.ts`,`react.ts`,`vue.ts`,`next.ts`,`electron.ts`,`browser.ts`,`node.ts`],l=[...o,...s,...c],u=[`impl`,`functions`,`methods`,`handlers`,`classes`,`class`,`manager`,`object`,`processor`,`process`,`common`,`logic`,`hooks`,`component`],d=[{pattern:/^use[A-Z][a-zA-Z]*\.spec\.tsx?$/,caseStyle:`camelCase`,description:`Hook 测试文件应使用 camelCase 并以 use 前缀开头(如 useChat.spec.ts)`},{pattern:/^use[A-Z][a-zA-Z]*\.test\.tsx?$/,caseStyle:`camelCase`,description:`Hook 测试文件应使用 camelCase 并以 use 前缀开头(如 useChat.test.ts)`},{pattern:/^use[A-Z][a-zA-Z]*\.types\.ts$/,caseStyle:`camelCase`,description:`Hook 类型文件应使用 camelCase 并以 use 前缀开头(如 useChat.types.ts)`},{pattern:/\.spec\.ts$/,caseStyle:`kebab-case-test`,description:`测试文件应使用 xxx.spec.ts 格式(kebab-case)`},{pattern:/\.test\.ts$/,caseStyle:`kebab-case-test`,description:`测试文件应使用 xxx.test.ts 格式(kebab-case)`},{pattern:/\.spec\.tsx$/,caseStyle:`kebab-case-test`,description:`测试文件应使用 xxx.spec.tsx 格式(kebab-case)`},{pattern:/\.test\.tsx$/,caseStyle:`kebab-case-test`,description:`测试文件应使用 xxx.test.tsx 格式(kebab-case)`},{pattern:/^use[A-Z][a-zA-Z]*\.tsx?$/,caseStyle:`camelCase`,description:`Hook 文件应使用 camelCase 并以 use 前缀开头(如 useChat.ts)`}],f=[{pattern:/\.service\.drizzle\.ts$/,caseStyle:`kebab-case`,description:`Drizzle Service 文件应使用 xxx.service.drizzle.ts 格式(kebab-case)`},{pattern:/\.service\.memory\.ts$/,caseStyle:`kebab-case`,description:`Memory Service 文件应使用 xxx.service.memory.ts 格式(kebab-case)`},{pattern:/\.service\.ts$/,caseStyle:`kebab-case`,description:`服务文件应使用 xxx.service.ts 格式(kebab-case)`},{pattern:/\.controller\.ts$/,caseStyle:`kebab-case`,description:`控制器文件应使用 xxx.controller.ts 格式(kebab-case)`},{pattern:/\.module\.ts$/,caseStyle:`kebab-case`,description:`模块文件应使用 xxx.module.ts 格式(kebab-case)`},{pattern:/\.repository\.drizzle\.ts$/,caseStyle:`kebab-case`,description:`Drizzle Repository 文件应使用 xxx.repository.drizzle.ts 格式(kebab-case)`},{pattern:/\.repository\.memory\.ts$/,caseStyle:`kebab-case`,description:`Memory Repository 文件应使用 xxx.repository.memory.ts 格式(kebab-case)`},{pattern:/\.repository\.interface\.ts$/,caseStyle:`kebab-case`,description:`Repository 接口文件应使用 xxx.repository.interface.ts 格式(kebab-case)`},{pattern:/\.repository\.types\.ts$/,caseStyle:`kebab-case`,description:`Repository 类型文件应使用 xxx.repository.types.ts 格式(kebab-case)`},{pattern:/\.repository\.ts$/,caseStyle:`kebab-case`,description:`Repository 文件应使用 xxx.repository.ts 格式(kebab-case)`},{pattern:/\.entity\.types\.ts$/,caseStyle:`kebab-case`,description:`Entity 类型文件应使用 xxx.entity.types.ts 格式(kebab-case)`},{pattern:/\.entity\.interface\.ts$/,caseStyle:`kebab-case`,description:`Entity 接口文件应使用 xxx.entity.interface.ts 格式(kebab-case)`},{pattern:/\.entity\.ts$/,caseStyle:`kebab-case`,description:`Entity 文件应使用 xxx.entity.ts 格式(kebab-case)`},{pattern:/\.dto\.ts$/,caseStyle:`kebab-case`,description:`DTO 文件应使用 xxx.dto.ts 格式(kebab-case)`},{pattern:/\.port\.interface\.ts$/,caseStyle:`kebab-case`,description:`Port 接口文件应使用 xxx.port.interface.ts 格式(kebab-case)`},{pattern:/\.interface\.ts$/,caseStyle:`kebab-case`,description:`接口文件应使用 xxx.interface.ts 格式(kebab-case)`},{pattern:/\.interface\.tsx$/,caseStyle:`kebab-case`,description:`接口文件应使用 xxx.interface.tsx 格式(kebab-case)`},{pattern:/\.types\.ts$/,caseStyle:`kebab-case`,description:`类型文件应使用 xxx.types.ts 格式(kebab-case)`},{pattern:/\.schema\.ts$/,caseStyle:`kebab-case`,description:`Schema 文件应使用 xxx.schema.ts 格式(kebab-case)`},{pattern:/\.port\.ts$/,caseStyle:`kebab-case`,description:`Port 文件应使用 xxx.port.ts 格式(kebab-case)`},{pattern:/\.port-adapter\.factory\.ts$/,caseStyle:`kebab-case`,description:`Port Adapter Factory 文件应使用 xxx.port-adapter.factory.ts 格式(kebab-case)`},{pattern:/\.port-adapter\.ts$/,caseStyle:`kebab-case`,description:`Port Adapter 文件应使用 xxx.port-adapter.ts 格式(kebab-case)`},{pattern:/\.adapter\.ts$/,caseStyle:`kebab-case`,description:`Adapter 文件应使用 xxx.adapter.ts 格式(kebab-case)`},{pattern:/\.client\.ts$/,caseStyle:`kebab-case`,description:`客户端文件应使用 xxx.client.ts 格式(kebab-case)`},{pattern:/\.events\.ts$/,caseStyle:`kebab-case`,description:`Events 文件应使用 xxx.events.ts 格式(kebab-case)`},{pattern:/\.mapper\.ts$/,caseStyle:`kebab-case`,description:`Mapper 文件应使用 xxx.mapper.ts 格式(kebab-case)`},{pattern:/\.ipc\.ts$/,caseStyle:`kebab-case`,description:`IPC 文件应使用 xxx.ipc.ts 格式(kebab-case)`},{pattern:/\.config\.ts$/,caseStyle:`kebab-case`,description:`配置文件应使用 xxx.config.ts 格式(kebab-case)`},{pattern:/\.errors\.ts$/,caseStyle:`kebab-case`,description:`错误文件应使用 xxx.errors.ts 格式(kebab-case)`},{pattern:/\.utils\.ts$/,caseStyle:`kebab-case`,description:`工具函数文件应使用 xxx.utils.ts 格式(kebab-case)`},{pattern:/\.constants\.ts$/,caseStyle:`kebab-case`,description:`常量文件应使用 xxx.constants.ts 格式(kebab-case)`},{pattern:/\.atom\.ts$/,caseStyle:`kebab-case`,description:`Atom 文件应使用 xxx.atom.ts 格式(kebab-case)`},{pattern:/\.vo\.ts$/,caseStyle:`kebab-case`,description:`值对象文件应使用 xxx.vo.ts 格式(kebab-case)`},{pattern:/\.usecase\.ts$/,caseStyle:`kebab-case`,description:`UseCase 文件应使用 xxx.usecase.ts 格式(kebab-case)`},{pattern:/\.styles\.css$/,caseStyle:`kebab-case`,description:`样式文件应使用 xxx.styles.css 格式(kebab-case)`},{pattern:/\.extension\.tsx?$/,caseStyle:`kebab-case`,description:`扩展文件应使用 xxx.extension.ts(x) 格式(kebab-case)`}],p=[{pattern:/^[A-Z][a-zA-Z0-9]*\.types\.ts$/,caseStyle:`PascalCase`,description:`类型文件可使用 PascalCase(如 DataExtractor.types.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.utils\.ts$/,caseStyle:`PascalCase`,description:`工具函数文件可使用 PascalCase(如 DataExtractor.utils.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.constants\.ts$/,caseStyle:`PascalCase`,description:`常量文件可使用 PascalCase(如 ByteVisualizer.constants.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.guards\.ts$/,caseStyle:`PascalCase`,description:`守卫文件可使用 PascalCase(如 DataExtractor.guards.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.helpers\.ts$/,caseStyle:`PascalCase`,description:`辅助函数文件可使用 PascalCase(如 TableVisualizer.helpers.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.groups\.ts$/,caseStyle:`PascalCase`,description:`分组文件可使用 PascalCase(如 TableVisualizer.groups.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.type-guards\.ts$/,caseStyle:`PascalCase`,description:`类型守卫文件可使用 PascalCase(如 TableVisualizer.type-guards.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.test\.ts$/,caseStyle:`PascalCase`,description:`测试文件可使用 PascalCase(如 DataExtractor.test.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.[a-z][-a-z]*\.test\.ts$/,caseStyle:`PascalCase`,description:`伴生测试文件可使用 PascalCase(如 DataExtractor.guards.test.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.[a-z][-a-z]*\.test\.tsx$/,caseStyle:`PascalCase`,description:`伴生测试文件可使用 PascalCase(如 PacketCompare.test.tsx)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.test\.tsx$/,caseStyle:`PascalCase`,description:`测试文件可使用 PascalCase(如 ByteVisualizer.test.tsx)`}],m={pattern:/^[a-z][a-zA-Z0-9_-]*\.tsx$/,caseStyle:`PascalCase`,description:`组件文件应使用 PascalCase(如 ChatPage.tsx),小写开头不允许`},h={pattern:/^[A-Z][a-zA-Z0-9]*\.tsx$/,caseStyle:`PascalCase`,description:`React 组件文件可使用 PascalCase(如 ChatPage.tsx)`},g=[...d,...p,...f,m,h];function _(e){return/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(e)}function v(e){return e.split(`.`).every(e=>_(e)&&e.length>0)}function y(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function b(e){return/^[a-z][a-zA-Z0-9]*$/.test(e)}function x(e){let t=e.split(`.`)[0];return t!==void 0&&t.length>0&&y(t)}function S(e){return e.split(`.`).every(e=>_(e)&&e.length>0)}function ee(e,t){switch(t){case`kebab-case`:return v(e);case`PascalCase`:return y(e);case`camelCase`:return b(e);case`kebab-case-test`:return S(e);default:return!0}}function te(e){return/^v\d+(-[a-z0-9-]+)?\.ts$/.test(e)}function C(e){let t=e.replace(/\.tsx?$/,``);for(let e of u){if(t.endsWith(`.${e}`))return e;let n=t.split(`.`);if(n.length>=2&&n[n.length-1]===e)return e}return null}function w(e){return!!(l.includes(e)||e.endsWith(`.d.ts`)||te(e)||e.startsWith(`[`)||e.startsWith(`_`))}function T(e,t){let n=e.replace(/\\/g,`/`);for(let e of t){let t=e.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*\*\//g,`<<DOUBLE_STAR_SLASH>>`).replace(/\*\*/g,`<<DOUBLE_STAR>>`).replace(/\*/g,`[^/]*`).replace(/<<DOUBLE_STAR_SLASH>>/g,`(.*\\/)?`).replace(/<<DOUBLE_STAR>>/g,`.*`);if(RegExp(`.*${t}`).test(n))return!0}return!1}function E(e,t){if(t===h)return e.replace(/\.tsx$/,``);let n=t.pattern.source;if(n.startsWith(`^`)&&n.endsWith(`$`)){if(n.includes(`\\.test\\.`)||n.includes(`\\.spec\\.`))return e.replace(/\.(test|spec)\.(tsx?|jsx?)$/,``);let t=e.match(/^([A-Z][a-zA-Z0-9]*)\.[a-z][-a-z]*\.tsx?$/);return t&&t[1]?t[1]:n.includes(`\\.types\\.`)?e.replace(/\.types\.ts$/,``):e.replace(/\.[^.]+$/,``)}return e.replace(t.pattern,``)}[...l];const D=/* @__PURE__ */ new Map;function O(e){let t=D.get(e);if(t!==void 0)return t;let n;try{n=r(e)}catch{n=!1}return D.set(e,n),n}const k=/^([A-Z][a-zA-Z0-9]*)\.[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*\.ts$/;function A(e){return e.match(k)?.[1]??null}function j(e,t){let n=A(t);if(!n)return!1;let r=`${n}.tsx`,i=e.substring(0,e.lastIndexOf(`/`));return O(a.join(i,r))}function M(e){let t=e.replace(/\.(test|spec)\.(tsx|ts)$/,``);return y(t)||x(t)}function N(e,t){if(!(t.endsWith(`.test.tsx`)||t.endsWith(`.spec.tsx`)||t.endsWith(`.test.ts`)||t.endsWith(`.spec.ts`))||!M(t))return{status:`not-component-test`};let n=t.replace(/\.(test|spec)\.(tsx|ts)$/,`.tsx`),r=t.replace(/\.(test|spec)\.(tsx|ts)$/,`.ts`);if(e.includes(`/__tests__/`))return F(e,n)||F(e,r)?{status:`component-test-found`}:{status:`not-component-test`};if(e.includes(`/components/`)){let t=e.substring(0,e.lastIndexOf(`/`)),i=e.indexOf(`/components/`),o=e.substring(0,i+11),s=t;for(;;){if(P(s,n)||P(s,r))return{status:`component-test-found`};if(s===o)break;let e=a.dirname(s);if(e===s)break;s=e}}return{status:`not-component-test`}}function P(e,t){if(O(a.join(e,t)))return!0;try{let n=i(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()&&O(a.join(e,r.name,t)))return!0}catch{}return!1}function F(e,t){let n=e.indexOf(`/__tests__/`),r=e.substring(0,n),i=e.substring(n+11),o=a.dirname(i),s=o===`.`?r:a.join(r,o);for(;;){if(P(s,t))return!0;if(s===r)break;let e=a.dirname(s);if(e===s)break;s=e}return!1}function I(e){return typeof e==`object`&&!!e}function L(e,t){let n=I(t)?t:void 0;return!!(n?.skipPatterns?.length&&T(e,n.skipPatterns))}const R=t({meta:{type:`problem`,docs:{description:`强制执行文件命名规范`},schema:[{type:`object`,properties:{skipPatterns:{type:`array`,items:{type:`string`}}},additionalProperties:!1}]},createOnce(e){return{before(){if(L(e.filename,e.options?.[0])||w(e.filename.replace(/\\/g,`/`).split(`/`).pop()??``))return!1},Program(t){if(L(e.filename,e.options?.[0]))return;let n=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``,r=e.filename.replace(/\\/g,`/`),i=C(n);if(i!==`hooks`&&j(r,n))return;if(N(r,n).status===`component-test-found`){let e=n.replace(/\.(test|spec)\.(tsx|ts)$/,``);if(y(e)||x(e))return}if(i!==null){let r=i===`hooks`?`hook 文件应使用 use 前缀小驼峰且不带后缀,如 useRepos.ts`:i===`component`?`组件文件应使用大驼峰且不带后缀,如 RepoList.tsx`:`.${i} 后缀语义过于泛化,请改用具体语义后缀`;e.report({node:t,message:`文件命名违规: ${n}。禁用 .${i} 后缀,${r}`});return}let a=g.find(e=>e.pattern.test(n));a&&(ee(E(n,a),a.caseStyle)||e.report({node:t,message:`文件命名违规: ${n}。${a.description}`}))}}}}),ne=[`.types.ts`,`.types.d.ts`];function z(e){return ne.some(t=>e.endsWith(t))}const B=t({meta:{type:`problem`,docs:{description:`强制执行 types 文件中的接口命名规范(禁止 I 前缀)`}},createOnce(t){return{before(){let e=t.filename.replace(/\\/g,`/`).split(`/`).pop()??``;if(e.endsWith(`.test.ts`)||e.endsWith(`.spec.ts`)||!z(e))return!1},TSInterfaceDeclaration(n){let r=n.id.name;e(r)&&t.report({node:n,message:`类型文件中的接口名 "${r}" 使用了 I 前缀。现代 TypeScript 不推荐使用匈牙利命名法,建议使用 "${r.substring(1)}"`})}}}}),V=[`impl`,`functions`,`methods`,`handlers`,`classes`,`class`,`manager`,`object`,`processor`,`process`,`common`,`logic`],H=/* @__PURE__ */ new Set([`index.ts`,`index.tsx`,`main.ts`,`main.tsx`,`App.tsx`,`bootstrap.ts`,`types.ts`,`errors.ts`,`constants.ts`,`types.d.ts`,`persistence.ts`,`typeorm.ts`,`migrate.ts`,`seed.ts`,`hono.ts`,`react.ts`,`vue.ts`,`next.ts`,`electron.ts`,`browser.ts`,`node.ts`]);function U(e){if(!e.endsWith(`.ts`)&&!e.endsWith(`.tsx`))return!1;let t=e.replace(/\.tsx?$/,``);return/^use[A-Z][a-zA-Z0-9]*$/.test(t)}function W(e){if(!e.endsWith(`.tsx`))return!1;let t=e.replace(`.tsx`,``);return/^[A-Z][a-zA-Z0-9]*$/.test(t)}function G(e){return/^v\d+(-[a-z0-9-]+)?\.ts$/.test(e)}function K(e){let t=e.replace(/\.tsx?$/,``);return[/s$/,/es$/,/ies$/].some(e=>e.test(t))}function q(e){return e.endsWith(`.types.ts`)?!0:/^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*\.tsx?$/.test(e)||/^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*\.tsx?$/.test(e)}function J(e){let t=e.replace(/\.tsx?$/,``);for(let e of V){if(t.endsWith(`.${e}`))return e;let n=t.split(`.`);if(n.length>=2&&n[n.length-1]===e)return e}return null}function Y(e){let t=[],n=e.replace(/\.tsx?$/,``);return(n.includes(`service`)||n.includes(`Service`))&&t.push(`.service.ts`),(n.includes(`controller`)||n.includes(`Controller`))&&t.push(`.controller.ts`),(n.includes(`utils`)||n.includes(`helper`))&&t.push(`.utils.ts`),(n.includes(`constant`)||n.includes(`Constant`))&&t.push(`.constants.ts`),(n.includes(`config`)||n.includes(`Config`))&&t.push(`.config.ts`),t.length===0&&t.push(`.utils.ts`,`.config.ts`,`.constants.ts`),t}function X(e){for(let t of[`.test.ts`,`.test.tsx`,`.spec.ts`,`.spec.tsx`])if(e.endsWith(t)){let n=t.endsWith(`.tsx`)?`.tsx`:`.ts`;return e.replace(t,n)}return e}function Z(e){return typeof e==`object`&&!!e}function re(e,t,n,r){return!!(n?.skipPatterns&&T(r,n.skipPatterns)||H.has(t)||t.endsWith(`.d.ts`)||e.startsWith(`[`)||e.startsWith(`_`)||t.endsWith(`.tsx`)||e.endsWith(`.test.ts`)||e.endsWith(`.test.tsx`)||e.endsWith(`.spec.ts`)||e.endsWith(`.spec.tsx`)||G(t)||W(t)||U(t)||!J(t)&&K(t))}const Q=t({meta:{type:`problem`,docs:{description:`强制执行文件类型后缀规范,确保文件名明确表达其用途`},schema:[{type:`object`,properties:{skipPatterns:{type:`array`,items:{type:`string`}}},additionalProperties:!1}]},createOnce(e){return{Program(t){let n=e.options?.[0],r=Z(n)?n:void 0,i=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``,a=X(i);if(re(i,a,r,e.filename))return;let o=J(a);if(o){e.report({node:t,message:`文件 "${i}" 使用了禁止的后缀 ".${o}"。该后缀语义过于泛化,无法表达文件用途。请使用更具体的后缀,如 ".utils"、".service" 等。`});return}if(q(a))return;let s=Y(a);e.report({node:t,message:`文件 "${i}" 缺少类型后缀。除特殊文件外,所有文件应使用 xxx.yyy.ts 格式明确表达用途。建议: ${s.join(`, `)}`})}}}}),$=n({meta:{name:`@longzai-intelligence-oxlint/file-naming-plugin`},rules:{"file-naming":R,"require-type-naming":B,"require-type-suffix":Q}});export{$ as default,$ as fileNamingPlugin,R as fileNamingRule,B as requireTypeNamingRule,Q as requireTypeSuffixRule};
1
+ import"../rolldown-runtime-BqT_7tdF.js";import{n as e}from"../dist-CskvMq7J.js";import{defineRule as t,eslintCompatPlugin as n}from"@oxlint/plugins";import{existsSync as r,readdirSync as i}from"node:fs";import a from"node:path";const o=[`index.ts`,`index.tsx`,`main.ts`,`main.tsx`,`App.tsx`],s=[`types.ts`,`errors.ts`,`constants.ts`],c=[`persistence.ts`,`typeorm.ts`,`hono.ts`,`react.ts`,`vue.ts`,`next.ts`,`electron.ts`,`browser.ts`,`node.ts`],l=[...o,...s,...c],u=[`impl`,`functions`,`methods`,`handlers`,`classes`,`class`,`manager`,`object`,`processor`,`process`,`common`,`logic`,`hooks`,`component`,`scripts`,`script`],d=[{pattern:/^use[A-Z][a-zA-Z]*\.spec\.tsx?$/,caseStyle:`camelCase`,description:`Hook 测试文件应使用 camelCase 并以 use 前缀开头(如 useChat.spec.ts)`},{pattern:/^use[A-Z][a-zA-Z]*\.test\.tsx?$/,caseStyle:`camelCase`,description:`Hook 测试文件应使用 camelCase 并以 use 前缀开头(如 useChat.test.ts)`},{pattern:/^use[A-Z][a-zA-Z]*\.types\.ts$/,caseStyle:`camelCase`,description:`Hook 类型文件应使用 camelCase 并以 use 前缀开头(如 useChat.types.ts)`},{pattern:/\.spec\.ts$/,caseStyle:`kebab-case-test`,description:`测试文件应使用 xxx.spec.ts 格式(kebab-case)`},{pattern:/\.test\.ts$/,caseStyle:`kebab-case-test`,description:`测试文件应使用 xxx.test.ts 格式(kebab-case)`},{pattern:/\.spec\.tsx$/,caseStyle:`kebab-case-test`,description:`测试文件应使用 xxx.spec.tsx 格式(kebab-case)`},{pattern:/\.test\.tsx$/,caseStyle:`kebab-case-test`,description:`测试文件应使用 xxx.test.tsx 格式(kebab-case)`},{pattern:/^use[A-Z][a-zA-Z]*\.tsx?$/,caseStyle:`camelCase`,description:`Hook 文件应使用 camelCase 并以 use 前缀开头(如 useChat.ts)`}],f=[{pattern:/\.service\.drizzle\.ts$/,caseStyle:`kebab-case`,description:`Drizzle Service 文件应使用 xxx.service.drizzle.ts 格式(kebab-case)`},{pattern:/\.service\.memory\.ts$/,caseStyle:`kebab-case`,description:`Memory Service 文件应使用 xxx.service.memory.ts 格式(kebab-case)`},{pattern:/\.service\.ts$/,caseStyle:`kebab-case`,description:`服务文件应使用 xxx.service.ts 格式(kebab-case)`},{pattern:/\.controller\.ts$/,caseStyle:`kebab-case`,description:`控制器文件应使用 xxx.controller.ts 格式(kebab-case)`},{pattern:/\.module\.ts$/,caseStyle:`kebab-case`,description:`模块文件应使用 xxx.module.ts 格式(kebab-case)`},{pattern:/\.repository\.drizzle\.ts$/,caseStyle:`kebab-case`,description:`Drizzle Repository 文件应使用 xxx.repository.drizzle.ts 格式(kebab-case)`},{pattern:/\.repository\.memory\.ts$/,caseStyle:`kebab-case`,description:`Memory Repository 文件应使用 xxx.repository.memory.ts 格式(kebab-case)`},{pattern:/\.repository\.interface\.ts$/,caseStyle:`kebab-case`,description:`Repository 接口文件应使用 xxx.repository.interface.ts 格式(kebab-case)`},{pattern:/\.repository\.types\.ts$/,caseStyle:`kebab-case`,description:`Repository 类型文件应使用 xxx.repository.types.ts 格式(kebab-case)`},{pattern:/\.repository\.ts$/,caseStyle:`kebab-case`,description:`Repository 文件应使用 xxx.repository.ts 格式(kebab-case)`},{pattern:/\.entity\.types\.ts$/,caseStyle:`kebab-case`,description:`Entity 类型文件应使用 xxx.entity.types.ts 格式(kebab-case)`},{pattern:/\.entity\.interface\.ts$/,caseStyle:`kebab-case`,description:`Entity 接口文件应使用 xxx.entity.interface.ts 格式(kebab-case)`},{pattern:/\.entity\.ts$/,caseStyle:`kebab-case`,description:`Entity 文件应使用 xxx.entity.ts 格式(kebab-case)`},{pattern:/\.dto\.ts$/,caseStyle:`kebab-case`,description:`DTO 文件应使用 xxx.dto.ts 格式(kebab-case)`},{pattern:/\.port\.interface\.ts$/,caseStyle:`kebab-case`,description:`Port 接口文件应使用 xxx.port.interface.ts 格式(kebab-case)`},{pattern:/\.interface\.ts$/,caseStyle:`kebab-case`,description:`接口文件应使用 xxx.interface.ts 格式(kebab-case)`},{pattern:/\.interface\.tsx$/,caseStyle:`kebab-case`,description:`接口文件应使用 xxx.interface.tsx 格式(kebab-case)`},{pattern:/\.types\.ts$/,caseStyle:`kebab-case`,description:`类型文件应使用 xxx.types.ts 格式(kebab-case)`},{pattern:/\.schema\.ts$/,caseStyle:`kebab-case`,description:`Schema 文件应使用 xxx.schema.ts 格式(kebab-case)`},{pattern:/\.port\.ts$/,caseStyle:`kebab-case`,description:`Port 文件应使用 xxx.port.ts 格式(kebab-case)`},{pattern:/\.port-adapter\.factory\.ts$/,caseStyle:`kebab-case`,description:`Port Adapter Factory 文件应使用 xxx.port-adapter.factory.ts 格式(kebab-case)`},{pattern:/\.port-adapter\.ts$/,caseStyle:`kebab-case`,description:`Port Adapter 文件应使用 xxx.port-adapter.ts 格式(kebab-case)`},{pattern:/\.adapter\.ts$/,caseStyle:`kebab-case`,description:`Adapter 文件应使用 xxx.adapter.ts 格式(kebab-case)`},{pattern:/\.client\.ts$/,caseStyle:`kebab-case`,description:`客户端文件应使用 xxx.client.ts 格式(kebab-case)`},{pattern:/\.events\.ts$/,caseStyle:`kebab-case`,description:`Events 文件应使用 xxx.events.ts 格式(kebab-case)`},{pattern:/\.mapper\.ts$/,caseStyle:`kebab-case`,description:`Mapper 文件应使用 xxx.mapper.ts 格式(kebab-case)`},{pattern:/\.ipc\.ts$/,caseStyle:`kebab-case`,description:`IPC 文件应使用 xxx.ipc.ts 格式(kebab-case)`},{pattern:/\.config\.ts$/,caseStyle:`kebab-case`,description:`配置文件应使用 xxx.config.ts 格式(kebab-case)`},{pattern:/\.errors\.ts$/,caseStyle:`kebab-case`,description:`错误文件应使用 xxx.errors.ts 格式(kebab-case)`},{pattern:/\.utils\.ts$/,caseStyle:`kebab-case`,description:`工具函数文件应使用 xxx.utils.ts 格式(kebab-case)`},{pattern:/\.constants\.ts$/,caseStyle:`kebab-case`,description:`常量文件应使用 xxx.constants.ts 格式(kebab-case)`},{pattern:/\.atom\.ts$/,caseStyle:`kebab-case`,description:`Atom 文件应使用 xxx.atom.ts 格式(kebab-case)`},{pattern:/\.vo\.ts$/,caseStyle:`kebab-case`,description:`值对象文件应使用 xxx.vo.ts 格式(kebab-case)`},{pattern:/\.usecase\.ts$/,caseStyle:`kebab-case`,description:`UseCase 文件应使用 xxx.usecase.ts 格式(kebab-case)`},{pattern:/\.styles\.css$/,caseStyle:`kebab-case`,description:`样式文件应使用 xxx.styles.css 格式(kebab-case)`},{pattern:/\.extension\.tsx?$/,caseStyle:`kebab-case`,description:`扩展文件应使用 xxx.extension.ts(x) 格式(kebab-case)`}],p=[{pattern:/^[A-Z][a-zA-Z0-9]*\.types\.ts$/,caseStyle:`PascalCase`,description:`类型文件可使用 PascalCase(如 DataExtractor.types.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.utils\.ts$/,caseStyle:`PascalCase`,description:`工具函数文件可使用 PascalCase(如 DataExtractor.utils.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.constants\.ts$/,caseStyle:`PascalCase`,description:`常量文件可使用 PascalCase(如 ByteVisualizer.constants.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.guards\.ts$/,caseStyle:`PascalCase`,description:`守卫文件可使用 PascalCase(如 DataExtractor.guards.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.helpers\.ts$/,caseStyle:`PascalCase`,description:`辅助函数文件可使用 PascalCase(如 TableVisualizer.helpers.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.groups\.ts$/,caseStyle:`PascalCase`,description:`分组文件可使用 PascalCase(如 TableVisualizer.groups.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.type-guards\.ts$/,caseStyle:`PascalCase`,description:`类型守卫文件可使用 PascalCase(如 TableVisualizer.type-guards.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.test\.ts$/,caseStyle:`PascalCase`,description:`测试文件可使用 PascalCase(如 DataExtractor.test.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.[a-z][-a-z]*\.test\.ts$/,caseStyle:`PascalCase`,description:`伴生测试文件可使用 PascalCase(如 DataExtractor.guards.test.ts)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.[a-z][-a-z]*\.test\.tsx$/,caseStyle:`PascalCase`,description:`伴生测试文件可使用 PascalCase(如 PacketCompare.test.tsx)`},{pattern:/^[A-Z][a-zA-Z0-9]*\.test\.tsx$/,caseStyle:`PascalCase`,description:`测试文件可使用 PascalCase(如 ByteVisualizer.test.tsx)`}],m={pattern:/^[a-z][a-zA-Z0-9_-]*\.tsx$/,caseStyle:`PascalCase`,description:`组件文件应使用 PascalCase(如 ChatPage.tsx),小写开头不允许`},h={pattern:/^[A-Z][a-zA-Z0-9]*\.tsx$/,caseStyle:`PascalCase`,description:`React 组件文件可使用 PascalCase(如 ChatPage.tsx)`},g=[...d,...p,...f,m,h];function _(e){return/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(e)}function v(e){return e.split(`.`).every(e=>_(e)&&e.length>0)}function y(e){return/^[A-Z][a-zA-Z0-9]*$/.test(e)}function b(e){return/^[a-z][a-zA-Z0-9]*$/.test(e)}function x(e){let t=e.split(`.`)[0];return t!==void 0&&t.length>0&&y(t)}function S(e){return e.split(`.`).every(e=>_(e)&&e.length>0)}function ee(e,t){switch(t){case`kebab-case`:return v(e);case`PascalCase`:return y(e);case`camelCase`:return b(e);case`kebab-case-test`:return S(e);default:return!0}}function te(e){return/^v\d+(-[a-z0-9-]+)?\.ts$/.test(e)}function C(e){let t=e.replace(/\.tsx?$/,``);for(let e of u){if(t.endsWith(`.${e}`))return e;let n=t.split(`.`);if(n.length>=2&&n[n.length-1]===e)return e}return null}function w(e){return!!(l.includes(e)||e.endsWith(`.d.ts`)||te(e)||e.startsWith(`[`)||e.startsWith(`_`))}function T(e,t){let n=e.replace(/\\/g,`/`);for(let e of t){let t=e.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*\*\//g,`<<DOUBLE_STAR_SLASH>>`).replace(/\*\*/g,`<<DOUBLE_STAR>>`).replace(/\*/g,`[^/]*`).replace(/<<DOUBLE_STAR_SLASH>>/g,`(.*\\/)?`).replace(/<<DOUBLE_STAR>>/g,`.*`);if(RegExp(`.*${t}`).test(n))return!0}return!1}function E(e,t){if(t===h)return e.replace(/\.tsx$/,``);let n=t.pattern.source;if(n.startsWith(`^`)&&n.endsWith(`$`)){if(n.includes(`\\.test\\.`)||n.includes(`\\.spec\\.`))return e.replace(/\.(test|spec)\.(tsx?|jsx?)$/,``);let t=e.match(/^([A-Z][a-zA-Z0-9]*)\.[a-z][-a-z]*\.tsx?$/);return t&&t[1]?t[1]:n.includes(`\\.types\\.`)?e.replace(/\.types\.ts$/,``):e.replace(/\.[^.]+$/,``)}return e.replace(t.pattern,``)}[...l];const D=/* @__PURE__ */ new Map;function O(e){let t=D.get(e);if(t!==void 0)return t;let n;try{n=r(e)}catch{n=!1}return D.set(e,n),n}const k=/^([A-Z][a-zA-Z0-9]*)\.[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*\.ts$/;function A(e){return e.match(k)?.[1]??null}function j(e,t){let n=A(t);if(!n)return!1;let r=`${n}.tsx`,i=e.substring(0,e.lastIndexOf(`/`));return O(a.join(i,r))}function M(e){let t=e.replace(/\.(test|spec)\.(tsx|ts)$/,``);return y(t)||x(t)}function N(e,t){if(!(t.endsWith(`.test.tsx`)||t.endsWith(`.spec.tsx`)||t.endsWith(`.test.ts`)||t.endsWith(`.spec.ts`))||!M(t))return{status:`not-component-test`};let n=t.replace(/\.(test|spec)\.(tsx|ts)$/,`.tsx`),r=t.replace(/\.(test|spec)\.(tsx|ts)$/,`.ts`);if(e.includes(`/__tests__/`))return F(e,n)||F(e,r)?{status:`component-test-found`}:{status:`not-component-test`};if(e.includes(`/components/`)){let t=e.substring(0,e.lastIndexOf(`/`)),i=e.indexOf(`/components/`),o=e.substring(0,i+11),s=t;for(;;){if(P(s,n)||P(s,r))return{status:`component-test-found`};if(s===o)break;let e=a.dirname(s);if(e===s)break;s=e}}return{status:`not-component-test`}}function P(e,t){if(O(a.join(e,t)))return!0;try{let n=i(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()&&O(a.join(e,r.name,t)))return!0}catch{}return!1}function F(e,t){let n=e.indexOf(`/__tests__/`),r=e.substring(0,n),i=e.substring(n+11),o=a.dirname(i),s=o===`.`?r:a.join(r,o);for(;;){if(P(s,t))return!0;if(s===r)break;let e=a.dirname(s);if(e===s)break;s=e}return!1}function I(e){return typeof e==`object`&&!!e}function L(e,t){let n=I(t)?t:void 0;return!!(n?.skipPatterns?.length&&T(e,n.skipPatterns))}const R=t({meta:{type:`problem`,docs:{description:`强制执行文件命名规范`},schema:[{type:`object`,properties:{skipPatterns:{type:`array`,items:{type:`string`}}},additionalProperties:!1}]},createOnce(e){return{before(){if(L(e.filename,e.options?.[0])||w(e.filename.replace(/\\/g,`/`).split(`/`).pop()??``))return!1},Program(t){if(L(e.filename,e.options?.[0]))return;let n=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``,r=e.filename.replace(/\\/g,`/`),i=C(n);if(i!==`hooks`&&j(r,n))return;if(N(r,n).status===`component-test-found`){let e=n.replace(/\.(test|spec)\.(tsx|ts)$/,``);if(y(e)||x(e))return}if(i!==null){let r=i===`hooks`?`hook 文件应使用 use 前缀小驼峰且不带后缀,如 useRepos.ts`:i===`component`?`组件文件应使用大驼峰且不带后缀,如 RepoList.tsx`:i===`scripts`||i===`script`?`脚本文件应以动词直接命名且不带后缀,如 migrate.ts、seed.ts`:`.${i} 后缀语义过于泛化,请改用具体语义后缀`;e.report({node:t,message:`文件命名违规: ${n}。禁用 .${i} 后缀,${r}`});return}let a=g.find(e=>e.pattern.test(n));a&&(ee(E(n,a),a.caseStyle)||e.report({node:t,message:`文件命名违规: ${n}。${a.description}`}))}}}}),ne=[`.types.ts`,`.types.d.ts`];function z(e){return ne.some(t=>e.endsWith(t))}const B=t({meta:{type:`problem`,docs:{description:`强制执行 types 文件中的接口命名规范(禁止 I 前缀)`}},createOnce(t){return{before(){let e=t.filename.replace(/\\/g,`/`).split(`/`).pop()??``;if(e.endsWith(`.test.ts`)||e.endsWith(`.spec.ts`)||!z(e))return!1},TSInterfaceDeclaration(n){let r=n.id.name;e(r)&&t.report({node:n,message:`类型文件中的接口名 "${r}" 使用了 I 前缀。现代 TypeScript 不推荐使用匈牙利命名法,建议使用 "${r.substring(1)}"`})}}}}),V=[`impl`,`functions`,`methods`,`handlers`,`classes`,`class`,`manager`,`object`,`processor`,`process`,`common`,`logic`,`scripts`,`script`],H=/* @__PURE__ */ new Set([`index.ts`,`index.tsx`,`main.ts`,`main.tsx`,`App.tsx`,`bootstrap.ts`,`types.ts`,`errors.ts`,`constants.ts`,`types.d.ts`,`persistence.ts`,`typeorm.ts`,`migrate.ts`,`seed.ts`,`hono.ts`,`react.ts`,`vue.ts`,`next.ts`,`electron.ts`,`browser.ts`,`node.ts`]);function U(e){if(!e.endsWith(`.ts`)&&!e.endsWith(`.tsx`))return!1;let t=e.replace(/\.tsx?$/,``);return/^use[A-Z][a-zA-Z0-9]*$/.test(t)}function W(e){if(!e.endsWith(`.tsx`))return!1;let t=e.replace(`.tsx`,``);return/^[A-Z][a-zA-Z0-9]*$/.test(t)}function G(e){return/^v\d+(-[a-z0-9-]+)?\.ts$/.test(e)}function K(e){let t=e.replace(/\.tsx?$/,``);return[/s$/,/es$/,/ies$/].some(e=>e.test(t))}function q(e){return e.endsWith(`.types.ts`)?!0:/^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*\.tsx?$/.test(e)||/^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*\.tsx?$/.test(e)}function J(e){let t=e.replace(/\.tsx?$/,``);for(let e of V){if(t.endsWith(`.${e}`))return e;let n=t.split(`.`);if(n.length>=2&&n[n.length-1]===e)return e}return null}function Y(e){let t=[],n=e.replace(/\.tsx?$/,``);return(n.includes(`service`)||n.includes(`Service`))&&t.push(`.service.ts`),(n.includes(`controller`)||n.includes(`Controller`))&&t.push(`.controller.ts`),(n.includes(`utils`)||n.includes(`helper`))&&t.push(`.utils.ts`),(n.includes(`constant`)||n.includes(`Constant`))&&t.push(`.constants.ts`),(n.includes(`config`)||n.includes(`Config`))&&t.push(`.config.ts`),t.length===0&&t.push(`.utils.ts`,`.config.ts`,`.constants.ts`),t}function X(e){for(let t of[`.test.ts`,`.test.tsx`,`.spec.ts`,`.spec.tsx`])if(e.endsWith(t)){let n=t.endsWith(`.tsx`)?`.tsx`:`.ts`;return e.replace(t,n)}return e}function Z(e){return typeof e==`object`&&!!e}function re(e,t,n,r){return!!(n?.skipPatterns&&T(r,n.skipPatterns)||H.has(t)||t.endsWith(`.d.ts`)||e.startsWith(`[`)||e.startsWith(`_`)||t.endsWith(`.tsx`)||e.endsWith(`.test.ts`)||e.endsWith(`.test.tsx`)||e.endsWith(`.spec.ts`)||e.endsWith(`.spec.tsx`)||G(t)||W(t)||U(t)||!J(t)&&K(t))}const Q=t({meta:{type:`problem`,docs:{description:`强制执行文件类型后缀规范,确保文件名明确表达其用途`},schema:[{type:`object`,properties:{skipPatterns:{type:`array`,items:{type:`string`}}},additionalProperties:!1}]},createOnce(e){return{Program(t){let n=e.options?.[0],r=Z(n)?n:void 0,i=e.filename.replace(/\\/g,`/`).split(`/`).pop()??``,a=X(i);if(re(i,a,r,e.filename))return;let o=J(a);if(o){e.report({node:t,message:`文件 "${i}" 使用了禁止的后缀 ".${o}"。该后缀语义过于泛化,无法表达文件用途。请使用更具体的后缀,如 ".utils"、".service" 等。`});return}if(q(a))return;let s=Y(a);e.report({node:t,message:`文件 "${i}" 缺少类型后缀。除特殊文件外,所有文件应使用 xxx.yyy.ts 格式明确表达用途。建议: ${s.join(`, `)}`})}}}}),$=n({meta:{name:`@longzai-intelligence-oxlint/file-naming-plugin`},rules:{"file-naming":R,"require-type-naming":B,"require-type-suffix":Q}});export{$ as default,$ as fileNamingPlugin,R as fileNamingRule,B as requireTypeNamingRule,Q as requireTypeSuffixRule};
@@ -2,8 +2,8 @@ import"../rolldown-runtime-BqT_7tdF.js";import{parseSeparatorComment as e}from".
2
2
  `)}})}}function P(e,t,n,r,i){let a=e.type===`Block`;if(a&&n.afterBlockComment||!a&&n.afterLineComment){if(M(i,n))return;let o=e.loc.end.line;A(o,t)||r.report({loc:{start:e.loc.end,end:e.loc.end},message:a?`块注释后需要空行`:`行注释后需要空行`,fix:t=>t.insertTextAfterRange([e.range[1],e.range[1]],`
3
3
  `)})}}function F(e,t,n,r,i=[],a=!1,o=!1){if(b(e,t)||C(e,n))return;let s=x(e,i),c=m(e,t),l=ee(e,t)||te(e,t),u=re(e,t);!a&&!s&&!l&&!u&&N(e,t,n,r,c),o||P(e,t,n,r,c)}const ie=t({meta:{type:`layout`,fixable:`whitespace`,docs:{description:`要求在注释前后有空行`},schema:[{type:`object`,properties:{beforeBlockComment:{type:`boolean`},afterBlockComment:{type:`boolean`},beforeLineComment:{type:`boolean`},afterLineComment:{type:`boolean`},allowBlockStart:{type:`boolean`},allowBlockEnd:{type:`boolean`},allowObjectStart:{type:`boolean`},allowObjectEnd:{type:`boolean`},allowArrayStart:{type:`boolean`},allowArrayEnd:{type:`boolean`},allowClassStart:{type:`boolean`},allowClassEnd:{type:`boolean`},allowInterfaceStart:{type:`boolean`},allowInterfaceEnd:{type:`boolean`},allowTypeStart:{type:`boolean`},allowTypeEnd:{type:`boolean`},allowEnumStart:{type:`boolean`},allowEnumEnd:{type:`boolean`},allowModuleStart:{type:`boolean`},allowModuleEnd:{type:`boolean`},allowFunctionStart:{type:`boolean`},allowFunctionEnd:{type:`boolean`},ignorePattern:{type:`string`},applyDefaultIgnorePatterns:{type:`boolean`}},additionalProperties:!1}]},createOnce(e){let t=[],n=[];return{Program(){let r=O(e.options?.[0]);t=e.sourceCode.text.split(`
4
4
  `),n=[];let i=e.sourceCode.getAllComments();for(let a=0;a<i.length;a++){let o=i[a];if(!o)continue;let s=i[a+1],c=s!==void 0&&s.loc.start.line<=o.loc.end.line+1;F(o,t,r,e,n,!1,c),n.push(o)}}}}}),I=[`eslint`,`oxlint`,`jshint`,`jslint`,`tslint`,`istanbul`,`global`,`exported`,`jscs`],L=[`<reference`,`<amd-module`,`<amd-dependency`,`@ts-`],R=/^\*?\s*$/u,z=/^\s*$/u,B=`禁止双斜杠注释,只允许多行块注释`;function V(e){let t=e.value.trim(),n=t.replace(/^\/+/u,``).trim();return I.some(e=>t.startsWith(e))||L.some(e=>n.startsWith(e))}function H(t){return t.type===`Line`&&e(t.value)!==null}function U(e,t){let n=t[e.loc.start.line-1];if(!n)return` `.repeat(e.loc.start.column);let r=n.slice(0,e.loc.start.column);return r.trim().length>0?` `.repeat(e.loc.start.column):r}function W(e){let t=[];for(let n of e){let e=t[t.length-1];if(e){let t=e[e.length-1];if(t&&t.loc.end.line===n.loc.start.line-1){e.push(n);continue}}t.push([n])}return t}function G(e){return e.map(e=>e.value)}function K(e,t){return`/*\n${e.map(e=>{let n=e.trim();return n?`${t} * ${n}`:`${t} *`}).join(`
5
- `)}\n${t} */`}function q(e,t){let n=e.trim();return n?`/*\n${t} * ${n}\n${t} */`:`/*\n${t} */`}function J(e,t){let n=e.value.split(`
5
+ `)}\n${t} */`}function q(e,t){let n=e.trim(),r=n.startsWith(`*`),i=r?n.slice(1).trim():n,a=r?`/**`:`/*`;return i?`${a}\n${t} * ${i}\n${t} */`:`${a}\n${t} */`}function J(e,t){let n=e.value.split(`
6
6
  `),r=0;for(let e=0;e<t;e++)r+=(n[e]?.length??0)+1;return e.range[0]+2+r}function Y(e,t){let n=[],r=[];for(let i of e)b(i,t)?n.push({message:B,loc:{start:{...i.loc.start},end:{...i.loc.end}}}):r.push(i);for(let e of W(r)){let r=e[0],i=e[e.length-1];if(!r||!i)continue;let a=U(r,t),o=G(e),s=o.some(e=>e.trim().startsWith(`/`));n.push({message:B,loc:{start:{...r.loc.start},end:{...i.loc.end}},fix:s?void 0:{range:[r.range[0],i.range[1]],text:K(o,a)}})}return n}function ae(e,t){let n=[],r=e.value.split(`
7
- `),i=U(e,t);if(e.loc.start.line===e.loc.end.line)return n.push({message:`禁止单行块注释,注释须为多行星号块形态`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[0],e.range[1]],text:q(e.value,i)}}),n;let a=r[0]??``;if(!R.test(a)){let t=+!!a.startsWith(`*`);n.push({message:`多行块注释的首行应在 "/*" 后换行`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[0]+2,e.range[0]+2+t],text:`\n${i} *`}})}for(let t=1;t<r.length-1;t++){let a=r[t]??``,o=a.trim();if(!o||o.startsWith(`*`))continue;let s=J(e,t),c=a.length-a.trimStart().length;n.push({message:`多行注释的中间行应以 "*" 开头`,loc:{start:{line:e.loc.start.line+t,column:0},end:{line:e.loc.start.line+t,column:a.length}},fix:{range:[s,s+c],text:`${i} * `}})}let o=r[r.length-1]??``;return z.test(o)||n.push({message:`多行块注释的末行应在 "*/" 前换行`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[1]-2,e.range[1]-2],text:`\n${i} `}}),n}function oe(e,t){let n=[],r=[];for(let i of e)i.type!==`Shebang`&&(V(i)||H(i)||(i.type===`Line`?r.push(i):n.push(...ae(i,t))));return n.push(...Y(r,t)),n}const se=t({meta:{type:`layout`,fixable:`code`,docs:{description:`强制多行注释使用星号块样式`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments(),r=e.sourceCode.text,i=oe(n,r==null?[]:r.split(`
7
+ `),i=U(e,t);if(e.loc.start.line===e.loc.end.line)return n.push({message:`禁止单行块注释,注释须为多行星号块形态`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[0],e.range[1]],text:q(e.value,i)}}),n;let a=r[0]??``;if(!R.test(a)){let t=+!!a.startsWith(`*`),r=e.range[0]+2+t;n.push({message:`多行块注释的首行应在 "/*" 后换行`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[r,r],text:`\n${i} *`}})}for(let t=1;t<r.length-1;t++){let a=r[t]??``,o=a.trim();if(!o||o.startsWith(`*`))continue;let s=J(e,t),c=a.length-a.trimStart().length;n.push({message:`多行注释的中间行应以 "*" 开头`,loc:{start:{line:e.loc.start.line+t,column:0},end:{line:e.loc.start.line+t,column:a.length}},fix:{range:[s,s+c],text:`${i} * `}})}let o=r[r.length-1]??``;return z.test(o)||n.push({message:`多行块注释的末行应在 "*/" 前换行`,loc:{start:{...e.loc.start},end:{...e.loc.end}},fix:{range:[e.range[1]-2,e.range[1]-2],text:`\n${i} `}}),n}function oe(e,t){let n=[],r=[];for(let i of e)i.type!==`Shebang`&&(V(i)||H(i)||(i.type===`Line`?r.push(i):n.push(...ae(i,t))));return n.push(...Y(r,t)),n}const se=t({meta:{type:`layout`,fixable:`code`,docs:{description:`强制多行注释使用星号块样式`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments(),r=e.sourceCode.text,i=oe(n,r==null?[]:r.split(`
8
8
  `));for(let t of i){let{fix:n}=t;e.report({loc:t.loc,message:t.message,fix:n?e=>e.replaceTextRange(n.range,n.text):void 0})}}}}});function X(e){return e.type===`ExportNamedDeclaration`||e.type===`ExportDefaultDeclaration`||e.type===`ExportAllDeclaration`}function ce(e,t,n){if(n-t<=1)return!1;for(let r=t+1;r<n;r++)if(e[r-1]?.trim()===``)return!0;return!1}function Z(e){return e.type===`Program`}function le(e,t,n){for(let r=1;r<e.length;r++){let i=e[r-1],a=e[r];if(i!==void 0&&a!==void 0&&X(i)&&X(a)){let e=i.loc.end.line,r=a.loc.start.line;ce(t,e,r)||n.report({loc:a.loc.start,message:`export 语句之间需要空行`})}}}const Q={"multiline-comment-style":se,"lines-around-comment":ie,"padding-line-between-statements":t({meta:{type:`layout`,docs:{description:`要求在 export 语句之间有空行`}},createOnce(e){return{Program(t){let n=e.sourceCode.text.split(`
9
9
  `),r=Z(t)?t:null;r&&le(r.body,n,e)}}}})},$=n({meta:{name:`@longzai-intelligence-oxlint/stylistic-plugin`},rules:Q});export{$ as default,$ as stylisticPlugin,Q as stylisticRules};
@@ -3,11 +3,17 @@ import"../rolldown-runtime-BqT_7tdF.js";import{defineRule as e,eslintCompatPlugi
3
3
  `),r=[],i=[],a=null,o=!0,s=!1;for(let e=0;e<n.length;e++){let t=n[e];if(t){if(t=t.trim(),t.startsWith(`*`)&&(t=t.slice(1).trim()),f(t)&&(s=!s),s||f(t))o?(t||r.length>0)&&r.push(t):a&&(a.description+=(a.description?`
4
4
  `:``)+t);else if(t.startsWith(`@`)){o=!1,a&&i.push(a);let e=t.match(/^@(\w+)\s*(.*)/);if(e){let t=e[1];if(!t)continue;a=ne(t,e[2]??``)}}else o?(t||r.length>0)&&r.push(t):a&&(a.description+=(a.description?`
5
5
  `:``)+t)}}return a&&i.push(a),{description:r.join(`
6
- `).trim(),tags:i}}function p(e){return e.tags.filter(e=>e.tag===`param`)}function m(e){return e.tags.find(e=>e.tag===`returns`||e.tag===`return`)}function h(e){return e.description.trim().length>0}function g(e){let t=e.description.trim();return t.length!==0&&t!==`-`&&t!==`--`}function _(e){return p(e).map(e=>e.name.split(`.`)[0]).filter(e=>typeof e==`string`)}const ae=e({meta:{type:`suggestion`,docs:{description:`禁止使用 description 标签`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);i&&i.tags.some(e=>e.tag===`description`)&&e.report({node:t,message:`请勿使用 description 标签,直接书写描述文本即可`})}}}}});n.object({type:n.string(),range:n.tuple([n.number(),n.number()])});const oe=n.object({init:n.unknown()}),se=n.object({type:n.string()});n.object({name:n.unknown()}),n.object({left:n.unknown(),right:n.unknown()}),n.object({id:n.object({name:n.string()})}),n.object({key:n.object({name:n.string()})}),n.object({declarations:n.array(n.object({id:n.optional(n.object({name:n.optional(n.string())}))}))}),n.object({type:n.literal(`ThrowStatement`),argument:n.unknown()}),n.object({type:n.literal(`NewExpression`),callee:n.unknown()}),n.object({type:n.literal(`Identifier`),name:n.unknown()}),n.object({consequent:n.array(n.unknown())}),n.object({consequent:n.unknown(),alternate:n.unknown()}),n.object({block:n.unknown(),handler:n.unknown()}),n.object({cases:n.unknown()}),n.object({body:n.array(n.unknown())});const ce=n.record(n.string(),n.unknown()),le=n.object({type:n.enum([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`])});n.object({type:n.string(),params:n.array(n.unknown())});const ue=n.object({range:n.tuple([n.number(),n.number()])}),de=n.object({range:n.tuple([n.number(),n.number()])}),fe=n.object({range:n.tuple([n.number(),n.number()])}),pe=n.object({id:n.object({name:n.string()})}),me=n.object({key:n.object({name:n.string()})}),he=n.object({declarations:n.array(n.unknown())}),ge=n.object({typeParameters:n.object({params:n.array(n.record(n.string(),n.unknown()))})}),_e=n.object({params:n.array(n.unknown())}),ve=n.object({value:n.unknown()}),ye=n.object({declarations:n.array(n.unknown())});function v(e){return ue.safeParse(e).success}function be(e){return de.safeParse(e).success}function y(e){return fe.safeParse(e).success}function xe(e){if(!v(e))return-1;if(`decorators`in e&&Array.isArray(e.decorators)&&e.decorators.length>0){let t=e.decorators[0];if(y(t))return t.range[0]}if(`parent`in e&&e.parent&&typeof e.parent==`object`){let t=e.parent;if(v(t)&&`type`in t&&typeof t.type==`string`){if(t.type===`MethodDefinition`){if(`decorators`in t&&Array.isArray(t.decorators)&&t.decorators.length>0){let e=t.decorators[0];if(y(e))return e.range[0]}return t.range[0]}if(t.type===`Property`)return t.range[0];if(t.type===`VariableDeclarator`){let e=`parent`in t?t.parent:void 0;if(v(e)&&`type`in e&&typeof e.type==`string`&&e.type===`VariableDeclaration`){if(`parent`in e&&e.parent){let t=e.parent;if(v(t)&&`type`in t&&typeof t.type==`string`&&[`ExportNamedDeclaration`,`ExportDefaultDeclaration`].includes(t.type))return t.range[0]}return e.range[0]}}if([`ExportNamedDeclaration`,`ExportDefaultDeclaration`].includes(t.type))return t.range[0]}}return e.range[0]}function Se(e,t,n,r){let i=e.range[1],a=xe(t);if(a<0)return!1;let o=n.filter(e=>e.range[0]>=i&&e.range[1]<=a),s=[];if(v(t)&&`decorators`in t){let e=t.decorators;if(Array.isArray(e))for(let t of e)y(t)&&s.push(t.range)}let c=[...o.map(e=>e.range),...s].sort((e,t)=>e[0]-t[0]),l=[],u=i;for(let e of c)e[0]>u&&l.push(r.slice(u,e[0])),u=Math.max(u,e[1]);u<a&&l.push(r.slice(u,a));for(let e of l)if(e.trim().length>0)return!1;return!0}function b(e,t,n){if(!be(t))return null;let r=xe(t),i=r>=0?r:t.range[0],a=null;for(let t of e)t.type===`Block`&&t.value.startsWith(`*`)&&t.range[1]<=i&&(a===null||t.range[1]>a.range[1])&&(a={value:t.value,range:t.range});return a&&n&&!Se(a,t,e,n)?null:a}const x={description:`[待填写描述]`,functionDescription:`[待填写函数描述]`,methodDescription:`[待填写方法描述]`,classDescription:`[待填写类描述]`,variableDescription:`[待填写变量描述]`,paramDescription:`[待填写参数描述]`,returnsDescription:`[待填写返回值描述]`,typeParamDescription:`[待填写类型参数描述]`},Ce=[/^\s*\*\s*描述\s*$/m,/^\s*\*\s*函数描述\s*$/m,/^\s*\*\s*方法描述\s*$/m,/^\s*\*\s*类描述\s*$/m,/^\s*\*\s*变量描述\s*$/m,/@param\s+\w+\s*-\s*参数描述/,/@returns\s+返回值描述/,/@typeParam\s+\w+\s*-\s*类型参数描述/];function we(e){return Object.values(x).some(t=>e.includes(t))?!0:Ce.some(t=>t.test(e))}function S(e,t){let n=t[0];for(;n>0&&e[n-1]!==`
7
- `;)n--;return e.slice(n,t[0])}function C(e,t,n,r){let i=t.range[1]-2,a=t.range[0]+2+t.value.replace(/\s+$/,``).length,o=`${n}\n${r} `;return e.replaceTextRange([a,i],o)}function w(e,t,n,r,i){let a=t.range[0]+2,o=t.range[1]-2,s=n[0].replace(/\s+$/,``).length,c=a+(n.index??0)+s,l=`${r}\n${i} `;return e.replaceTextRange([c,o],l)}function Te(e,t,n,r){let i=`\n${r} * @param ${n} - ${x.paramDescription}`,a=t.value.match(/@param[^@]*$/);return a&&a.index!==void 0?w(e,t,a,i,r):C(e,t,i,r)}function Ee(e,t,n){let r=`\n${n} * @returns ${x.returnsDescription}`,i=t.value.match(/@\w+[^@]*$/);return i&&i.index!==void 0?w(e,t,i,r,n):C(e,t,r,n)}function De(e,t,n,r){let i=`\n${r} * @typeParam ${n} - ${x.typeParamDescription}`,a=t.value,o=a.match(/@typeParam[^@]*$/);if(o&&o.index!==void 0)return w(e,t,o,i,r);let s=a.match(/@param[^@]*$/);return s&&s.index!==void 0?w(e,t,s,i,r):C(e,t,i,r)}function Oe(e,t,n){let r=t.value;return r.trim()===`*`?e.replaceTextRange(t.range,`/**\n${n} * ${x.description}\n${n} */`):e.replaceTextRange(t.range,`/*${r}*/`)}function T(e,t,n){return e.slice(t).includes(`
8
- `)?``:`\n${n} `}function ke(e,t,n,r){let i=t.value,a=RegExp(`@param\\s+${E(n)}\\s*$`,`m`),o=a.exec(i);if(o){let s=T(i,o.index+o[0].length,r),c=i.replace(a,`@param ${n} - ${x.paramDescription}${s}`);return e.replaceTextRange(t.range,`/*${c}*/`)}return e.replaceTextRange(t.range,`/*${i}*/`)}function Ae(e,t,n){let r=t.value,i=/@returns\s*$/m,a=i.exec(r);if(a){let o=T(r,a.index+a[0].length,n),s=r.replace(i,`@returns ${x.returnsDescription}${o}`);return e.replaceTextRange(t.range,`/*${s}*/`)}return e.replaceTextRange(t.range,`/*${r}*/`)}function E(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}const D=n.object({type:n.optional(n.string()),name:n.optional(n.string()),left:n.optional(n.object({name:n.optional(n.string())}))}),je=n.object({type:n.string(),name:n.optional(n.string()),left:n.optional(D),argument:n.optional(D),parameter:n.optional(D)});function Me(e){return _e.safeParse(e).success}function O(e){return Me(e)?e.params.map(e=>{let t=je.safeParse(e);if(!t.success)return``;let n=t.data;switch(n.type){case`Identifier`:return n.name??``;case`AssignmentPattern`:return n.left?.name??``;case`RestElement`:return n.argument?.name??``;case`ObjectPattern`:return Ne(n)??`options`;case`ArrayPattern`:return`args`;case`TSParameterProperty`:return n.parameter?.name??n.parameter?.left?.name??``;default:return``}}).filter(e=>!!e):[]}function Ne(e){return null}const Pe=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`禁止多余的 @param 标签`}},createOnce(e){let t=[];function n(n){let r=b(t,n,e.sourceCode.text);if(!r)return;let i=d(r.value);if(!i)return;let a=O(n),o=_(i).filter(e=>!a.includes(e));for(let t of o)e.report({node:n,message:`@param "${t}" 在函数签名中不存在`,fix:e=>{let n=r.value,i=RegExp(`\\n\\s*\\*\\s*@param\\s+${E(t)}\\b[^\\n]*`),a=n.replace(i,``);return e.replaceTextRange(r.range,`/*${a}*/`)}})}return{Program(){t=e.sourceCode.getAllComments()},FunctionDeclaration(e){n(e)},FunctionExpression(e){n(e)},ArrowFunctionExpression(e){if(`parent`in e&&e.parent){let t=e.parent.type;if(t===`CallExpression`||t===`Property`)return}n(e)}}}}),Fe=[`file`,`module`,`author`,`since`];function Ie(e){return Fe.includes(e)}function Le(e,t,n,r){let i=e.split(`
6
+ `).trim(),tags:i}}function p(e){return e.tags.filter(e=>e.tag===`param`)}function m(e){return e.tags.find(e=>e.tag===`returns`||e.tag===`return`)}function h(e){return e.description.trim().length>0}function ae(e){let t=e.description.trim();return t.length!==0&&t!==`-`&&t!==`--`}function oe(e){return p(e).map(e=>e.name.split(`.`)[0]).filter(e=>typeof e==`string`)}const se=e({meta:{type:`suggestion`,docs:{description:`禁止使用 description 标签`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);i&&i.tags.some(e=>e.tag===`description`)&&e.report({node:t,message:`请勿使用 description 标签,直接书写描述文本即可`})}}}}});n.object({type:n.string(),range:n.tuple([n.number(),n.number()])});const ce=n.object({init:n.unknown()}),le=n.object({type:n.string()});n.object({name:n.unknown()}),n.object({left:n.unknown(),right:n.unknown()}),n.object({id:n.object({name:n.string()})}),n.object({key:n.object({name:n.string()})}),n.object({declarations:n.array(n.object({id:n.optional(n.object({name:n.optional(n.string())}))}))}),n.object({type:n.literal(`ThrowStatement`),argument:n.unknown()}),n.object({type:n.literal(`NewExpression`),callee:n.unknown()}),n.object({type:n.literal(`Identifier`),name:n.unknown()}),n.object({consequent:n.array(n.unknown())}),n.object({consequent:n.unknown(),alternate:n.unknown()}),n.object({block:n.unknown(),handler:n.unknown()}),n.object({cases:n.unknown()}),n.object({body:n.array(n.unknown())});const ue=n.record(n.string(),n.unknown()),de=n.object({type:n.enum([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`])});n.object({type:n.string(),params:n.array(n.unknown())});const fe=n.object({range:n.tuple([n.number(),n.number()])}),pe=n.object({range:n.tuple([n.number(),n.number()])}),me=n.object({range:n.tuple([n.number(),n.number()])}),he=n.object({id:n.object({name:n.string()})}),ge=n.object({key:n.object({name:n.string()})}),_e=n.object({declarations:n.array(n.unknown())}),ve=n.object({typeParameters:n.object({params:n.array(n.record(n.string(),n.unknown()))})}),ye=n.object({params:n.array(n.unknown())}),be=n.object({value:n.unknown()}),xe=n.object({declarations:n.array(n.unknown())});function g(e){return fe.safeParse(e).success}function _(e){return pe.safeParse(e).success}function v(e){return me.safeParse(e).success}function y(e){if(!g(e))return-1;if(`decorators`in e&&Array.isArray(e.decorators)&&e.decorators.length>0){let t=e.decorators[0];if(v(t))return t.range[0]}if(`parent`in e&&e.parent&&typeof e.parent==`object`){let t=e.parent;if(g(t)&&`type`in t&&typeof t.type==`string`){if(t.type===`MethodDefinition`){if(`decorators`in t&&Array.isArray(t.decorators)&&t.decorators.length>0){let e=t.decorators[0];if(v(e))return e.range[0]}return t.range[0]}if(t.type===`Property`)return t.range[0];if(t.type===`VariableDeclarator`){let e=`parent`in t?t.parent:void 0;if(g(e)&&`type`in e&&typeof e.type==`string`&&e.type===`VariableDeclaration`){if(`parent`in e&&e.parent){let t=e.parent;if(g(t)&&`type`in t&&typeof t.type==`string`&&[`ExportNamedDeclaration`,`ExportDefaultDeclaration`].includes(t.type))return t.range[0]}return e.range[0]}}if([`ExportNamedDeclaration`,`ExportDefaultDeclaration`].includes(t.type))return t.range[0]}}return e.range[0]}function b(e,t,n,r){let i=e.range[1],a=y(t);if(a<0)return!1;let o=n.filter(e=>e.range[0]>=i&&e.range[1]<=a),s=[];if(g(t)&&`decorators`in t){let e=t.decorators;if(Array.isArray(e))for(let t of e)v(t)&&s.push(t.range)}let c=[...o.map(e=>e.range),...s].sort((e,t)=>e[0]-t[0]),l=[],u=i;for(let e of c)e[0]>u&&l.push(r.slice(u,e[0])),u=Math.max(u,e[1]);u<a&&l.push(r.slice(u,a));for(let e of l)if(e.trim().length>0)return!1;return!0}function x(e,t,n){if(!_(t))return null;let r=y(t),i=r>=0?r:t.range[0],a=null;for(let t of e)t.type===`Block`&&t.value.startsWith(`*`)&&t.range[1]<=i&&(a===null||t.range[1]>a.range[1])&&(a={value:t.value,range:t.range});return a&&n&&!b(a,t,e,n)?null:a}function Se(e,t,n){if(!_(t))return null;let r=y(t),i=r>=0?r:t.range[0],a=null;for(let t of e)t.type!==`Shebang`&&t.range[1]<=i&&(a===null||t.range[1]>a.range[1])&&(a=t);if(a===null)return null;if(n===void 0)return{comments:[a]};let o=a.range[0];for(;o>0&&n[o-1]!==`
7
+ `;)o--;if(n.slice(o,a.range[0]).trim().length>0||!b(a,t,e,n))return null;if(a.type===`Block`)return{comments:[a]};let s=[a],c=!0;for(;c;){c=!1;let t=s[0];if(!t)break;let r=null;for(let n of e)n.type===`Line`&&n.range[1]<t.range[0]&&(r===null||n.range[1]>r.range[1])&&(r=n);if(r===null)break;let i=n.slice(r.range[1],t.range[0]);if(i.split(`
8
+ `).length!==2||i.trim().length>0)break;let a=r.range[0];for(;a>0&&n[a-1]!==`
9
+ `;)a--;if(n.slice(a,r.range[0]).trim().length>0)break;s.unshift(r),c=!0}return{comments:s}}const S={description:`[待填写描述]`,functionDescription:`[待填写函数描述]`,methodDescription:`[待填写方法描述]`,classDescription:`[待填写类描述]`,variableDescription:`[待填写变量描述]`,paramDescription:`[待填写参数描述]`,returnsDescription:`[待填写返回值描述]`,typeParamDescription:`[待填写类型参数描述]`},Ce=[/^\s*\*\s*描述\s*$/m,/^\s*\*\s*函数描述\s*$/m,/^\s*\*\s*方法描述\s*$/m,/^\s*\*\s*类描述\s*$/m,/^\s*\*\s*变量描述\s*$/m,/@param\s+\w+\s*-\s*参数描述/,/@returns\s+返回值描述/,/@typeParam\s+\w+\s*-\s*类型参数描述/];function we(e){return Object.values(S).some(t=>e.includes(t))?!0:Ce.some(t=>t.test(e))}function C(e,t){let n=t[0];for(;n>0&&e[n-1]!==`
10
+ `;)n--;return e.slice(n,t[0])}function w(e,t,n,r){let i=t.range[1]-2,a=t.range[0]+2+t.value.replace(/\s+$/,``).length,o=`${n}\n${r} `;return e.replaceTextRange([a,i],o)}function T(e,t,n,r,i){let a=t.range[0]+2,o=t.range[1]-2,s=n[0].replace(/\s+$/,``).length,c=a+(n.index??0)+s,l=`${r}\n${i} `;return e.replaceTextRange([c,o],l)}function Te(e,t,n,r){let i=`\n${r} * @param ${n} - ${S.paramDescription}`,a=t.value.match(/@param[^@]*$/);return a&&a.index!==void 0?T(e,t,a,i,r):w(e,t,i,r)}function Ee(e,t,n){let r=`\n${n} * @returns ${S.returnsDescription}`,i=t.value.match(/@\w+[^@]*$/);return i&&i.index!==void 0?T(e,t,i,r,n):w(e,t,r,n)}function De(e,t,n,r){let i=`\n${r} * @typeParam ${n} - ${S.typeParamDescription}`,a=t.value,o=a.match(/@typeParam[^@]*$/);if(o&&o.index!==void 0)return T(e,t,o,i,r);let s=a.match(/@param[^@]*$/);return s&&s.index!==void 0?T(e,t,s,i,r):w(e,t,i,r)}function Oe(e,t,n){let r=t.value;return r.trim()===`*`?e.replaceTextRange(t.range,`/**\n${n} * ${S.description}\n${n} */`):e.replaceTextRange(t.range,`/*${r}*/`)}function ke(e,t,n){return e.slice(t).includes(`
11
+ `)?``:`\n${n} `}function Ae(e,t,n,r){let i=t.value,a=RegExp(`@param\\s+${E(n)}\\s*$`,`m`),o=a.exec(i);if(o){let s=ke(i,o.index+o[0].length,r),c=i.replace(a,`@param ${n} - ${S.paramDescription}${s}`);return e.replaceTextRange(t.range,`/*${c}*/`)}return e.replaceTextRange(t.range,`/*${i}*/`)}function je(e,t,n){let r=t.value,i=/@returns\s*$/m,a=i.exec(r);if(a){let o=ke(r,a.index+a[0].length,n),s=r.replace(i,`@returns ${S.returnsDescription}${o}`);return e.replaceTextRange(t.range,`/*${s}*/`)}return e.replaceTextRange(t.range,`/*${r}*/`)}function E(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}const D=n.object({type:n.optional(n.string()),name:n.optional(n.string()),left:n.optional(n.object({name:n.optional(n.string())}))}),Me=n.object({type:n.string(),name:n.optional(n.string()),left:n.optional(D),argument:n.optional(D),parameter:n.optional(D)});function Ne(e){return ye.safeParse(e).success}function O(e){return Ne(e)?e.params.map(e=>{let t=Me.safeParse(e);if(!t.success)return``;let n=t.data;switch(n.type){case`Identifier`:return n.name??``;case`AssignmentPattern`:return n.left?.name??``;case`RestElement`:return n.argument?.name??``;case`ObjectPattern`:return Pe(n)??`options`;case`ArrayPattern`:return`args`;case`TSParameterProperty`:return n.parameter?.name??n.parameter?.left?.name??``;default:return``}}).filter(e=>!!e):[]}function Pe(e){return null}const Fe=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`禁止多余的 @param 标签`}},createOnce(e){let t=[];function n(n){let r=x(t,n,e.sourceCode.text);if(!r)return;let i=d(r.value);if(!i)return;let a=O(n),o=oe(i).filter(e=>!a.includes(e));for(let t of o)e.report({node:n,message:`@param "${t}" 在函数签名中不存在`,fix:e=>{let n=r.value,i=RegExp(`\\n\\s*\\*\\s*@param\\s+${E(t)}\\b[^\\n]*`),a=n.replace(i,``);return e.replaceTextRange(r.range,`/*${a}*/`)}})}return{Program(){t=e.sourceCode.getAllComments()},FunctionDeclaration(e){n(e)},FunctionExpression(e){n(e)},ArrowFunctionExpression(e){if(`parent`in e&&e.parent){let t=e.parent.type;if(t===`CallExpression`||t===`Property`)return}n(e)}}}}),Ie=[`file`,`module`,`author`,`since`];function Le(e){return Ie.includes(e)}function Re(e,t,n,r){let i=e.split(`
9
12
  `),a=-1;for(let e=0;e<i.length;e++){let n=i[e];if(n&&n.trim().startsWith(`* @${t}`)){a=e;break}}if(a===-1)return n.replaceTextRange(r,`/*${e}*/`);let o=i.filter((e,t)=>t!==a).join(`
10
- `);return n.replaceTextRange(r,`/*${o}*/`)}const Re=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`禁止使用旧版 JSDoc 标签`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(i)for(let a of i.tags)Ie(a.tag)&&e.report({node:t,message:`禁止使用旧版 JSDoc 标签 @${a.tag},该标签在 TSDoc 中已不推荐使用`,fix:e=>Le(n,a.tag,e,r.range)})}}}}}),ze=[...Object.values(x),`参数描述`,`返回值描述`,`函数描述`,`方法描述`,`类描述`,`变量描述`,`类型参数描述`,`描述`];function k(e){let t=e.trim();t.startsWith(`-`)&&(t=t.slice(1).trim());for(let e of ze)if(t===e)return e;return null}function Be(e){let t=k(e);return t?`禁止使用占位描述 "${t}",请提供有意义的描述`:null}function Ve(e){let t=[],n=p(e);for(let e of n){let n=k(e.description);n&&t.push(`@param 标签禁止使用占位描述 "${n}",请提供有意义的描述`)}let r=m(e);if(r){let e=k(r.description);e&&t.push(`@returns 标签禁止使用占位描述 "${e}",请提供有意义的描述`)}let i=e.tags.filter(e=>e.tag===`typeParam`||e.tag===`template`);for(let e of i){let n=k(e.description);n&&t.push(`@typeParam 标签禁止使用占位描述 "${n}",请提供有意义的描述`)}return t}const He=e({meta:{type:`suggestion`,docs:{description:`禁止使用占位描述文本`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=Be(i.description);a&&e.report({node:t,message:a});let o=Ve(i);for(let n of o)e.report({node:t,message:n})}}}}});function Ue(e){return e?e.trim().startsWith(`-`):!1}const We=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:"要求参数描述使用 `-` 分隔"}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=p(i);for(let i of a)Ue(i.description)||e.report({node:t,message:`参数 "${i.name}" 的描述应该使用 \`-\` 分隔,格式:@param ${i.name} - 描述`,fix:e=>{let t=RegExp(`(@param\\s+${E(i.name)}\\s+)([^\\-\\s].*?)(\\n|$)`,`g`),a=n.replace(t,`$1- $2$3`);return e.replaceTextRange(r.range,`/*${a}*/`)}})}}}}});function Ge(e){let t=e.split(`
11
- `),n=-1,r=!1;for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;let a=i.trim();if(f(a.startsWith(`*`)?a.slice(1).trim():a))r=!r;else if(!r&&a.startsWith(`*`)&&a.slice(1).trim().startsWith(`@`)){n=e;break}}if(n===-1||n===0)return!0;let i=t[n-1];if(!i)return!0;let a=i.trim();return a===`*`||a===``}const Ke=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求标签前有空行`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);i&&i.tags.length>0&&h(i)&&(Ge(n)||e.report({node:t,message:`标签前应有一个空行`,fix:e=>{let t=n.replace(/([ \t]*)(\* [^\n@]+)\n([ \t]*)(\* @)/g,(e,t,n,r,i)=>`${t}${n}\n${t||r}*\n${r}${i}`);return e.replaceTextRange(r.range,`/*${t}*/`)}}))}}}}}),qe=[/使用\s+\S+\s+代替/,/请使用\s+\S+/,/use\s+\S+\s+instead/i,/replaced\s+by\s+\S+/i];function Je(e){if(!e)return!1;let t=e.trim();if(t.length===0)return!1;for(let e of qe)if(e.test(t))return!0;return t.length>10}const Ye=e({meta:{type:`suggestion`,docs:{description:`要求 @deprecated 标签有替代方案说明`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=i.tags.find(e=>e.tag===`deprecated`);a&&(Je(a.description)||e.report({node:t,message:`@deprecated 标签应该包含替代方案说明,例如:@deprecated 使用 newMethod 代替`}))}}}}}),Xe=[`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`,`ClassDeclaration`,`VariableDeclaration`,`MethodDefinition`,`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSEnumDeclaration`,`PropertyDefinition`,`TSPropertySignature`,`TSEnumMember`],Ze=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求 TSDoc 注释有描述文本`}},createOnce(e){let t=[];function n(n){let r=b(t,n,e.sourceCode.text);if(!r)return;let i=d(r.value);i&&(h(i)||e.report({node:n,message:`TSDoc 注释缺少描述`,fix:t=>{let n=S(e.sourceCode.text,r.range);return Oe(t,r,n)}}))}let r={Program(){t=e.sourceCode.getAllComments()}};for(let e of Xe)r[e]=e=>n(e);return r}});function A(e){return pe.safeParse(e).success}function j(e){return me.safeParse(e).success}function M(e){return he.safeParse(e).success}function Qe(e){if(!Array.isArray(e)||e.length===0)return null;let t=e[0];if(!t||typeof t!=`object`)return null;let n=t;if(`type`in n&&n.type===`Property`&&`key`in n){let e=n.key;if(e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`)return e.name}if(`type`in n&&n.type===`RestElement`&&`argument`in n){let e=n.argument;if(e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`)return e.name}return null}function $e(e){if(!Array.isArray(e)||e.length===0)return null;let t=e[0];return t&&typeof t==`object`&&`name`in t&&typeof t.name==`string`?t.name:null}function et(e){if(!e||typeof e!=`object`)return null;let t=e;return`type`in t&&t.type===`ObjectPattern`&&`properties`in t?Qe(t.properties):`type`in t&&t.type===`ArrayPattern`&&`elements`in t?$e(t.elements):null}function tt(e){if(!M(e)||e.declarations.length===0)return null;let t=e.declarations[0];if(!t||typeof t!=`object`||!t||!(`id`in t)||!t.id)return null;let n=t.id;if(typeof n==`object`&&`type`in n){let e=n;if(e.type===`Identifier`&&`name`in e)return typeof e.name==`string`?e.name:null;if(e.type===`ObjectPattern`||e.type===`ArrayPattern`)return et(n)}return A(t)?t.id?.name??null:null}function N(e){if(!e||typeof e!=`object`||!(`type`in e))return null;let t=e.type;if(typeof t!=`string`)return null;switch(t){case`FunctionDeclaration`:case`ClassDeclaration`:case`TSInterfaceDeclaration`:case`TSTypeAliasDeclaration`:case`TSEnumDeclaration`:case`TSEnumMember`:return A(e)?e.id?.name??null:null;case`MethodDefinition`:case`PropertyDefinition`:case`TSPropertySignature`:return j(e)?e.key?.name??null:null;case`VariableDeclaration`:return tt(e);default:return null}}const nt={FunctionDeclaration:`函数`,MethodDefinition:`方法`,ClassDeclaration:`类`,VariableDeclaration:`变量`,TSInterfaceDeclaration:`接口`,TSTypeAliasDeclaration:`类型别名`,TSEnumDeclaration:`枚举`,PropertyDefinition:`类属性`,TSPropertySignature:`接口属性`,TSEnumMember:`枚举成员`};function P(e){return nt[e]||e}function F(e){return ge.safeParse(e).success}function rt(e){return F(e)?e.typeParameters.params.map(e=>e.name&&typeof e.name==`object`&&`name`in e.name?String(e.name.name):``).filter(Boolean):[]}function it(e){return!e.trim().includes(`
12
- `)}function at(e){return j(e)?e.key.name:A(e)?e.id.name:`(匿名)`}const ot=e({meta:{type:`suggestion`,docs:{description:`要求接口属性、类属性、枚举成员使用多行 TSDoc 注释格式`}},createOnce(e){return{TSPropertySignature(t){I(t,e)},PropertyDefinition(t){I(t,e)},TSEnumMember(t){I(t,e)}}}});function I(e,t){let n=b(t.sourceCode.getAllComments(),e,t.sourceCode.text);if(!n)return;let r=n.value;if(it(r)){let n=at(e);t.report({node:e,message:`"${n}"的注释应使用多行 TSDoc 格式,当前为单行格式`})}}const st=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求 @param 标签有描述`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=p(i);for(let n of a)g(n)||e.report({node:t,message:`参数 "${n.name}" 缺少描述`,fix:t=>ke(t,r,n.name,S(e.sourceCode.text,r.range))})}}}}}),ct=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求函数参数有 @param 标签`}},createOnce(e){let t=[];function n(n){let r=b(t,n,e.sourceCode.text);if(!r)return;let i=O(n);if(i.length===0)return;let a=d(r.value);if(!a)return;let o=_(a),s=i.filter(e=>!o.includes(e));for(let t of s)e.report({node:n,message:`参数 "${t}" 缺少 @param 标签`,fix:n=>{let i=S(e.sourceCode.text,r.range);return Te(n,r,t,i)}})}return{Program(){t=e.sourceCode.getAllComments()},FunctionDeclaration(e){n(e)},FunctionExpression(e){n(e)},ArrowFunctionExpression(e){if(`parent`in e&&e.parent){let t=e.parent.type;if(t===`CallExpression`||t===`Property`)return}n(e)}}}}),lt=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求 @returns 标签有描述`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=m(i);a&&!g(a)&&e.report({node:t,message:`@returns 标签缺少描述`,fix:t=>Ae(t,r,S(e.sourceCode.text,r.range))})}}}}});function L(e){return typeof e!=`object`||!e||!(`type`in e)?!1:typeof e.type==`string`}function ut(e){return L(e)&&e.type===`ReturnStatement`&&`argument`in e}function dt(e){return typeof e==`object`&&!!e&&`body`in e}function ft(e){return typeof e==`object`&&!!e&&`returnType`in e}function pt(e){return L(e)?[`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`].includes(e.type):!1}function R(e,t){if(!e||typeof e!=`object`)return!1;let n=e;if(t.has(n))return!1;if(t.add(n),ut(n))return!0;if(pt(n))return!1;for(let e of Object.keys(n)){let r=Object.getOwnPropertyDescriptor(n,e);if(!r||!(`value`in r))continue;let i=r.value;if(i&&typeof i==`object`){if(Array.isArray(i)){for(let e of i)if(R(e,t))return!0}else if(`type`in i&&R(i,t))return!0}}return!1}function z(e){if(typeof e!=`object`||!e||!dt(e)||!e.body)return!1;let t=e.body;return typeof t!=`object`||!t?!1:!(`type`in t)||t.type!==`BlockStatement`||R(t,/* @__PURE__ */ new WeakSet)}function B(e){if(typeof e!=`object`||!e||!ft(e)||!e.returnType)return!1;let t=e.returnType;if(!t||typeof t!=`object`||!(`typeAnnotation`in t)||!t.typeAnnotation)return!1;let n=t.typeAnnotation;if(typeof n!=`object`||!(`type`in n))return!1;if(n.type===`TSVoidKeyword`)return!0;if(n.type===`TSTypeReference`){let e=`typeName`in n?n.typeName:null;if(e&&typeof e==`object`&&`name`in e&&e.name===`Promise`){let e=`typeArguments`in n?n.typeArguments:null;if(e&&typeof e==`object`&&`params`in e&&Array.isArray(e.params)&&e.params.length>0){let t=e.params[0];if(L(t))return t.type===`TSVoidKeyword`}}}return!1}function mt(e){return z(e)?!B(e):!1}const ht=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求有返回值的函数有 @returns 标签`}},createOnce(e){return{FunctionDeclaration(t){V(t,e)},FunctionExpression(t){V(t,e)},ArrowFunctionExpression(t){if(`parent`in t&&t.parent){let e=t.parent.type;if(e===`CallExpression`||e===`Property`)return}V(t,e)}}}});function V(e,t){if(!mt(e))return;let n=b(t.sourceCode.getAllComments(),e,t.sourceCode.text);if(!n)return;let r=d(n.value);r&&(m(r)||t.report({node:e,message:`缺少 @returns 文档`,fix:e=>{let r=S(t.sourceCode.text,n.range);return Ee(e,n,r)}}))}function gt(e){if(typeof e!=`object`||!e)return!1;let t=e;return`type`in t&&`range`in t&&Array.isArray(t.range)}const _t=e({meta:{type:`suggestion`,docs:{description:`要求 @throws 标签有异常类型`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let t of n){if(t.type!==`Block`)continue;let n=t.value;if(!n.startsWith(`*`))continue;let r=d(n);if(!r)continue;let i=r.tags.filter(e=>e.tag===`throws`||e.tag===`throw`);for(let n of i)!n.type&&gt(t)&&e.report({node:t,message:`@throws 标签应使用 {@link Type} 格式声明异常类型,例如:@throws {@link Error} 描述`})}}}}});function H(e){if(typeof e!=`object`||!e)return!1;let t=e;return`body`in t&&Array.isArray(t.body)}function vt(e){if(typeof e!=`object`||!e)return!1;let t=e;return`type`in t&&t.type===`ThrowStatement`&&`argument`in t}function yt(e){if(typeof e!=`object`||!e)return!1;let t=e;return`type`in t&&t.type===`NewExpression`&&`callee`in t}function U(e){if(typeof e!=`object`||!e)return!1;let t=e;return`type`in t&&t.type===`Identifier`&&`name`in t}function bt(e){if(typeof e!=`object`||!e)return!1;let t=e;return`consequent`in t&&`alternate`in t}function xt(e){if(typeof e!=`object`||!e)return!1;let t=e;return`block`in t&&`handler`in t}function St(e){return typeof e!=`object`||!e?!1:`cases`in e}function Ct(e){if(typeof e!=`object`||!e||!(`consequent`in e))return!1;let t=e;return Array.isArray(t.consequent)}function wt(e){let t=e.argument;if(yt(t)){let e=t.callee;if(U(e))return e.name}return U(t)?t.name:`Error`}function W(e,t){if(!H(e))return;let n=e;if(Array.isArray(n.body))for(let e of n.body)G(e,t)}function G(e,t){if(!e||typeof e!=`object`)return;let n=e;if(`type`in n&&n.type===`ThrowStatement`&&vt(n)){let e=wt(n);t.push({typeName:e})}else`type`in n&&n.type===`IfStatement`&&bt(n)?(G(n.consequent,t),n.alternate&&G(n.alternate,t)):`type`in n&&n.type===`TryStatement`&&xt(n)?Tt(n,t):`type`in n&&n.type===`SwitchStatement`&&St(n)?Et(n,t):`type`in n&&n.type===`BlockStatement`&&H(n)&&W(n,t)}function Tt(e,t){H(e.block)&&W(e.block,t),e.handler&&typeof e.handler==`object`&&`body`in e.handler&&e.handler.body&&H(e.handler.body)&&W(e.handler.body,t)}function Et(e,t){for(let n of e.cases)if(Ct(n))for(let e of n.consequent)G(e,t)}function Dt(e){if(!e||typeof e!=`object`||!(`body`in e)||!e.body)return[];let t=e.body;if(typeof t!=`object`||!t||!(`type`in t)||t.type!==`BlockStatement`)return[];let n=[];return W(t,n),n}const Ot=e({meta:{type:`suggestion`,docs:{description:`要求抛出异常的函数有 @throws 标签`}},createOnce(e){return{FunctionDeclaration(t){K(t,e)},FunctionExpression(t){K(t,e)},ArrowFunctionExpression(t){if(`parent`in t&&t.parent){let e=t.parent.type;if(e===`CallExpression`||e===`Property`)return}K(t,e)}}}});function K(e,t){let n=Dt(e);if(n.length===0)return;let r=b(t.sourceCode.getAllComments(),e,t.sourceCode.text);if(!r){q(e,t,n);return}let i=d(r.value);i?i.tags.filter(e=>e.tag===`throws`||e.tag===`throw`).length===0&&q(e,t,n):q(e,t,n)}function q(e,t,n){let r=[...new Set(n.map(e=>e.typeName))],i=r[0]||`Error`;t.report({node:e,message:`函数抛出异常但没有 @throws 标签。抛出的异常类型: ${r.join(`, `)}。正确用法: @throws {@link ${i}} 异常描述`})}function kt(e){return le.safeParse(e).success}function At(e){return ce.safeParse(e).success}function jt(e){return oe.safeParse(e).success}function Mt(e){return se.safeParse(e).success}function Nt(e){return ve.safeParse(e).success}function Pt(e){return ye.safeParse(e).success}function Ft(e,t){return e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`?It(e,t):e.type===`MethodDefinition`&&Nt(e)&&e.value?Lt(e.value,t):e.type===`ClassDeclaration`?Rt(t):e.type===`VariableDeclaration`&&Pt(e)?zt(e.declarations,t):J(t)}function It(e,t){let n=O(e),r=z(e),i=B(e),a=[];a.push(`/**`),a.push(` * ${x.functionDescription}`);for(let e of n)a.push(` * @param ${e} - ${x.paramDescription}`);return r&&!i&&a.push(` * @returns ${x.returnsDescription}`),a.push(` */`),`\n${t}`+a.join(`\n${t}`)+`\n${t}`}function Lt(e,t){if(!e||typeof e!=`object`||!kt(e))return J(t);let n=e,r=O(n),i=z(n),a=B(n),o=[];o.push(`/**`),o.push(` * ${x.methodDescription}`);for(let e of r)o.push(` * @param ${e} - ${x.paramDescription}`);return i&&!a&&o.push(` * @returns ${x.returnsDescription}`),o.push(` */`),`\n${t}`+o.join(`\n${t}`)+`\n${t}`}function Rt(e){let t=[];return t.push(`/**`),t.push(` * ${x.classDescription}`),t.push(` */`),`\n${e}`+t.join(`\n${e}`)+`\n${e}`}function zt(e,t){let n=e[0];if(!n||!At(n))return J(t);let r=jt(n)?n.init:void 0;if(r&&typeof r==`object`&&Mt(r)){let e=r.type;if(e===`ArrowFunctionExpression`||e===`FunctionExpression`)return J(t)}let i=[];return i.push(`/**`),i.push(` * ${x.variableDescription}`),i.push(` */`),`\n${t}`+i.join(`\n${t}`)+`\n${t}`}function J(e){let t=[];return t.push(`/**`),t.push(` * ${x.description}`),t.push(` */`),`\n${e}`+t.join(`\n${e}`)+`\n${e}`}function Y(e){return typeof e==`object`&&!!e&&`type`in e&&typeof e.type==`string`}function X(e){return typeof e==`object`&&!!e&&`parent`in e}function Bt(e){return typeof e==`object`&&!!e&&`init`in e}function Z(e){return typeof e==`object`&&!!e}const Vt=[`FunctionDeclaration`,`MethodDefinition`,`ClassDeclaration`,`VariableDeclaration`,`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSEnumDeclaration`,`PropertyDefinition`,`TSEnumMember`];function Ht(e){if(!Z(e)||e.type!==`TSPropertySignature`)return!1;let t=e.key;return Z(t)&&t.type===`Identifier`&&`name`in t&&typeof t.name==`string`?t.name===`null`||t.name===`undefined`:!1}function Ut(e,t){if(X(e)&&e.parent&&typeof e.parent==`object`&&Y(e.parent)&&[`ForStatement`,`ForInStatement`,`ForOfStatement`].includes(e.parent.type))return!0;if(e.type===`VariableDeclaration`){if(t)return!1;if(M(e)&&e.declarations.length>0){let t=e.declarations[0];if(!t)return!0;if(Bt(t)&&t.init&&typeof t.init==`object`&&Y(t.init)&&(t.init.type===`ArrowFunctionExpression`||t.init.type===`FunctionExpression`))return!1}return!0}return!!Ht(e)}function Wt(e){return e.includes(`/**`)}function Gt(e){if(`decorators`in e&&Array.isArray(e.decorators)&&e.decorators.length>0){let t=e.decorators[0];if(Z(t)){let e=t.range;if(Array.isArray(e)&&e.length>=1&&typeof e[0]==`number`)return[e[0],e[0]]}}if(X(e)&&e.parent&&typeof e.parent==`object`){let t=e.parent;if(Y(t)&&Z(t)&&[`ExportNamedDeclaration`,`ExportDefaultDeclaration`].includes(t.type)){let e=t.range;if(Array.isArray(e)&&e.length>=1&&typeof e[0]==`number`)return[e[0],e[0]]}}return[e.range[0],e.range[0]]}function Kt(e,t){if(!e)return``;let n=t;for(;n>0&&e[n-1]!==`
13
- `;)n--;return e.slice(n,t)}function qt(e,t,n){if(t.skipFile||Ut(e,t.checkAllVariables))return;let r=b(t.commentsCache,e,n.sourceCode.text);if(!r){let t=P(e.type),r=N(e);n.report({node:e,message:`${t}"${r}"缺少 TSDoc 注释`,fix:t=>{let r=Gt(e),i=Ft(e,Kt(n.sourceCode.text,r[0]));return t.insertTextBeforeRange(r,i)}});return}let i=r.value;if(we(i)){let t=P(e.type),r=N(e);n.report({node:e,message:`${t}"${r}"的 TSDoc 注释包含占位描述,请填写实际描述`})}}function Jt(e,t){let n=e.getAllComments(),r=e.text;if(r!=null){if(!Wt(r))return t.skipFile=!0,n}else if(!n.some(e=>e.type===`Block`&&e.value.startsWith(`*`)))return t.skipFile=!0,n;return n}function Yt(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t=e;if(`checkAllVariables`in t&&typeof t.checkAllVariables==`boolean`)return t.checkAllVariables}return!1}const Xt=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求 TSDoc 注释存在`},schema:[{type:`object`,properties:{contexts:{type:`array`,items:{type:`string`}},checkAllVariables:{type:`boolean`}},additionalProperties:!1}]},createOnce(e){let t={commentsCache:[],checkAllVariables:!1,skipFile:!1},n={Program(n){t.skipFile=!1,t.checkAllVariables=!1,t.commentsCache=Jt(e.sourceCode,t);let r=e.options?.[0];t.checkAllVariables=Yt(r)}};for(let r of Vt)n[r]=n=>qt(n,t,e);return n}});function Zt(e){return e.tags.filter(e=>e.tag===`typeParam`||e.tag===`template`).map(e=>e.name)}const Qt=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求泛型有 @typeParam 标签`}},createOnce(e){return{FunctionDeclaration(t){Q(t,e)},FunctionExpression(t){Q(t,e)},ArrowFunctionExpression(t){if(`parent`in t&&t.parent){let e=t.parent.type;if(e===`CallExpression`||e===`Property`)return}Q(t,e)},ClassDeclaration(t){Q(t,e)},TSInterfaceDeclaration(t){Q(t,e)},TSTypeAliasDeclaration(t){Q(t,e)}}}});function Q(e,t){if(!F(e))return;let n=rt(e);if(n.length===0)return;let r=b(t.sourceCode.getAllComments(),e,t.sourceCode.text);if(!r)return;let i=d(r.value);if(!i)return;let a=Zt(i),o=n.filter(e=>!a.includes(e));for(let n of o)t.report({node:e,message:`缺少类型参数 "${n}" 的 @typeParam 文档`,fix:e=>{let i=S(t.sourceCode.text,r.range);return De(e,r,n,i)}})}const $t=/^(=+)\s+(.+?)\s+(=+)$/;function en(e){let t=e.trim().match($t);return t?{leadingEquals:t[1]??``,text:t[2]??``,trailingEquals:t[3]??``}:null}const tn=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求代码块分隔符使用规范格式`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Line`)continue;let n=en(r.value.trim());if(n&&(n.leadingEquals.length!==20||n.trailingEquals.length!==20)){let i=`=`.repeat(20);e.report({node:t,message:`代码块分隔符格式不正确,应为:// ${i} ${n.text} ${i}`,fix:e=>{let t=`// ${i} ${n.text} ${i}`;return e.replaceTextRange(r.range,t)}})}}}}}}),nn=/\bTODO(?:\(([^)]+)\))?:?\s*(.*)/i;function rn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const an={requireAuthor:!1,requireDescription:!0};function on(e){return/\bTODO\b/i.test(e)}function sn(e){let t={...an};if(rn(e)){let n=e;typeof n.requireAuthor==`boolean`&&(t.requireAuthor=n.requireAuthor),typeof n.requireDescription==`boolean`&&(t.requireDescription=n.requireDescription)}return t}function cn(e){let t=e.match(nn);return t?{author:t[1]??``,description:(t[2]??``).trim()}:null}const ln={"no-commented-code":s,"no-description-tag":ae,"no-extra-param":Pe,"no-legacy-jsdoc-tags":Re,"no-placeholder-description":He,"param-hyphen-format":We,"require-blank-line-before-tags":Ke,"require-deprecated-alternative":Ye,"require-description":Ze,"require-multiline-property-comment":ot,"require-param":ct,"require-param-description":st,"require-returns":ht,"require-returns-description":lt,"require-throws":Ot,"require-throws-type":_t,"require-tsdoc":Xt,"require-type-param":Qt,"separator-format":tn,"todo-format":e({meta:{type:`suggestion`,docs:{description:`要求 TODO 注释有描述和作者`}},createOnce(e){let t=sn(e.options?.[0]);return{Program(n){let r=e.sourceCode.getAllComments();for(let i of r){let r=i.value;if(!on(r))continue;let a=cn(r);a&&(t.requireAuthor&&!a.author&&e.report({node:n,message:`TODO 注释缺少作者信息,格式:TODO(author): 描述`}),t.requireDescription&&!a.description&&e.report({node:n,message:`TODO 注释缺少描述说明`}))}}}}})},$=t({meta:{name:`@longzai-intelligence-oxlint/tsdoc-plugin`},rules:ln});export{$t as SEPARATOR_PATTERN,$ as default,$ as tsdocPlugin,en as parseSeparatorComment,ln as tsdocRules};
13
+ `);return n.replaceTextRange(r,`/*${o}*/`)}const ze=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`禁止使用旧版 JSDoc 标签`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(i)for(let a of i.tags)Le(a.tag)&&e.report({node:t,message:`禁止使用旧版 JSDoc 标签 @${a.tag},该标签在 TSDoc 中已不推荐使用`,fix:e=>Re(n,a.tag,e,r.range)})}}}}}),Be=[...Object.values(S),`参数描述`,`返回值描述`,`函数描述`,`方法描述`,`类描述`,`变量描述`,`类型参数描述`,`描述`];function k(e){let t=e.trim();t.startsWith(`-`)&&(t=t.slice(1).trim());for(let e of Be)if(t===e)return e;return null}function Ve(e){let t=k(e);return t?`禁止使用占位描述 "${t}",请提供有意义的描述`:null}function He(e){let t=[],n=p(e);for(let e of n){let n=k(e.description);n&&t.push(`@param 标签禁止使用占位描述 "${n}",请提供有意义的描述`)}let r=m(e);if(r){let e=k(r.description);e&&t.push(`@returns 标签禁止使用占位描述 "${e}",请提供有意义的描述`)}let i=e.tags.filter(e=>e.tag===`typeParam`||e.tag===`template`);for(let e of i){let n=k(e.description);n&&t.push(`@typeParam 标签禁止使用占位描述 "${n}",请提供有意义的描述`)}return t}const Ue=e({meta:{type:`suggestion`,docs:{description:`禁止使用占位描述文本`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=Ve(i.description);a&&e.report({node:t,message:a});let o=He(i);for(let n of o)e.report({node:t,message:n})}}}}});function We(e){return e?e.trim().startsWith(`-`):!1}const Ge=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:"要求参数描述使用 `-` 分隔"}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=p(i);for(let i of a)We(i.description)||e.report({node:t,message:`参数 "${i.name}" 的描述应该使用 \`-\` 分隔,格式:@param ${i.name} - 描述`,fix:e=>{let t=RegExp(`(@param\\s+${E(i.name)}\\s+)([^\\-\\s].*?)(\\n|$)`,`g`),a=n.replace(t,`$1- $2$3`);return e.replaceTextRange(r.range,`/*${a}*/`)}})}}}}});function Ke(e){let t=e.split(`
14
+ `),n=-1,r=!1;for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;let a=i.trim();if(f(a.startsWith(`*`)?a.slice(1).trim():a))r=!r;else if(!r&&a.startsWith(`*`)&&a.slice(1).trim().startsWith(`@`)){n=e;break}}if(n===-1||n===0)return!0;let i=t[n-1];if(!i)return!0;let a=i.trim();return a===`*`||a===``}const qe=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求标签前有空行`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);i&&i.tags.length>0&&h(i)&&(Ke(n)||e.report({node:t,message:`标签前应有一个空行`,fix:e=>{let t=n.replace(/([ \t]*)(\* [^\n@]+)\n([ \t]*)(\* @)/g,(e,t,n,r,i)=>`${t}${n}\n${t||r}*\n${r}${i}`);return e.replaceTextRange(r.range,`/*${t}*/`)}}))}}}}}),Je=[/使用\s+\S+\s+代替/,/请使用\s+\S+/,/use\s+\S+\s+instead/i,/replaced\s+by\s+\S+/i];function Ye(e){if(!e)return!1;let t=e.trim();if(t.length===0)return!1;for(let e of Je)if(e.test(t))return!0;return t.length>10}const Xe=e({meta:{type:`suggestion`,docs:{description:`要求 @deprecated 标签有替代方案说明`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=i.tags.find(e=>e.tag===`deprecated`);a&&(Ye(a.description)||e.report({node:t,message:`@deprecated 标签应该包含替代方案说明,例如:@deprecated 使用 newMethod 代替`}))}}}}}),Ze=[`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`,`ClassDeclaration`,`VariableDeclaration`,`MethodDefinition`,`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSEnumDeclaration`,`PropertyDefinition`,`TSPropertySignature`,`TSEnumMember`],Qe=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求 TSDoc 注释有描述文本`}},createOnce(e){let t=[];function n(n){let r=x(t,n,e.sourceCode.text);if(!r)return;let i=d(r.value);i&&(h(i)||e.report({node:n,message:`TSDoc 注释缺少描述`,fix:t=>{let n=C(e.sourceCode.text,r.range);return Oe(t,r,n)}}))}let r={Program(){t=e.sourceCode.getAllComments()}};for(let e of Ze)r[e]=e=>n(e);return r}});function A(e){return he.safeParse(e).success}function j(e){return ge.safeParse(e).success}function M(e){return _e.safeParse(e).success}function $e(e){if(!Array.isArray(e)||e.length===0)return null;let t=e[0];if(!t||typeof t!=`object`)return null;let n=t;if(`type`in n&&n.type===`Property`&&`key`in n){let e=n.key;if(e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`)return e.name}if(`type`in n&&n.type===`RestElement`&&`argument`in n){let e=n.argument;if(e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`)return e.name}return null}function et(e){if(!Array.isArray(e)||e.length===0)return null;let t=e[0];return t&&typeof t==`object`&&`name`in t&&typeof t.name==`string`?t.name:null}function tt(e){if(!e||typeof e!=`object`)return null;let t=e;return`type`in t&&t.type===`ObjectPattern`&&`properties`in t?$e(t.properties):`type`in t&&t.type===`ArrayPattern`&&`elements`in t?et(t.elements):null}function nt(e){if(!M(e)||e.declarations.length===0)return null;let t=e.declarations[0];if(!t||typeof t!=`object`||!t||!(`id`in t)||!t.id)return null;let n=t.id;if(typeof n==`object`&&`type`in n){let e=n;if(e.type===`Identifier`&&`name`in e)return typeof e.name==`string`?e.name:null;if(e.type===`ObjectPattern`||e.type===`ArrayPattern`)return tt(n)}return A(t)?t.id?.name??null:null}function N(e){if(!e||typeof e!=`object`||!(`type`in e))return null;let t=e.type;if(typeof t!=`string`)return null;switch(t){case`FunctionDeclaration`:case`ClassDeclaration`:case`TSInterfaceDeclaration`:case`TSTypeAliasDeclaration`:case`TSEnumDeclaration`:case`TSEnumMember`:return A(e)?e.id?.name??null:null;case`MethodDefinition`:case`PropertyDefinition`:case`TSPropertySignature`:return j(e)?e.key?.name??null:null;case`VariableDeclaration`:return nt(e);default:return null}}const rt={FunctionDeclaration:`函数`,MethodDefinition:`方法`,ClassDeclaration:`类`,VariableDeclaration:`变量`,TSInterfaceDeclaration:`接口`,TSTypeAliasDeclaration:`类型别名`,TSEnumDeclaration:`枚举`,PropertyDefinition:`类属性`,TSPropertySignature:`接口属性`,TSEnumMember:`枚举成员`};function P(e){return rt[e]||e}function it(e){return ve.safeParse(e).success}function at(e){return it(e)?e.typeParameters.params.map(e=>e.name&&typeof e.name==`object`&&`name`in e.name?String(e.name.name):``).filter(Boolean):[]}function ot(e){return!e.trim().includes(`
15
+ `)}function st(e){return j(e)?e.key.name:A(e)?e.id.name:`(匿名)`}const ct=e({meta:{type:`suggestion`,docs:{description:`要求接口属性、类属性、枚举成员使用多行 TSDoc 注释格式`}},createOnce(e){return{TSPropertySignature(t){F(t,e)},PropertyDefinition(t){F(t,e)},TSEnumMember(t){F(t,e)}}}});function F(e,t){let n=x(t.sourceCode.getAllComments(),e,t.sourceCode.text);if(!n)return;let r=n.value;if(ot(r)){let n=st(e);t.report({node:e,message:`"${n}"的注释应使用多行 TSDoc 格式,当前为单行格式`})}}const lt=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求 @param 标签有描述`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=p(i);for(let n of a)ae(n)||e.report({node:t,message:`参数 "${n.name}" 缺少描述`,fix:t=>Ae(t,r,n.name,C(e.sourceCode.text,r.range))})}}}}}),ut=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求函数参数有 @param 标签`}},createOnce(e){let t=[];function n(n){let r=x(t,n,e.sourceCode.text);if(!r)return;let i=O(n);if(i.length===0)return;let a=d(r.value);if(!a)return;let o=oe(a),s=i.filter(e=>!o.includes(e));for(let t of s)e.report({node:n,message:`参数 "${t}" 缺少 @param 标签`,fix:n=>{let i=C(e.sourceCode.text,r.range);return Te(n,r,t,i)}})}return{Program(){t=e.sourceCode.getAllComments()},FunctionDeclaration(e){n(e)},FunctionExpression(e){n(e)},ArrowFunctionExpression(e){if(`parent`in e&&e.parent){let t=e.parent.type;if(t===`CallExpression`||t===`Property`)return}n(e)}}}}),dt=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求 @returns 标签有描述`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Block`)continue;let n=r.value;if(!n.startsWith(`*`))continue;let i=d(n);if(!i)continue;let a=m(i);a&&!ae(a)&&e.report({node:t,message:`@returns 标签缺少描述`,fix:t=>je(t,r,C(e.sourceCode.text,r.range))})}}}}});function I(e){return typeof e!=`object`||!e||!(`type`in e)?!1:typeof e.type==`string`}function ft(e){return I(e)&&e.type===`ReturnStatement`&&`argument`in e}function pt(e){return typeof e==`object`&&!!e&&`body`in e}function mt(e){return typeof e==`object`&&!!e&&`returnType`in e}function ht(e){return I(e)?[`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`].includes(e.type):!1}function L(e,t){if(!e||typeof e!=`object`)return!1;let n=e;if(t.has(n))return!1;if(t.add(n),ft(n))return!0;if(ht(n))return!1;for(let e of Object.keys(n)){let r=Object.getOwnPropertyDescriptor(n,e);if(!r||!(`value`in r))continue;let i=r.value;if(i&&typeof i==`object`){if(Array.isArray(i)){for(let e of i)if(L(e,t))return!0}else if(`type`in i&&L(i,t))return!0}}return!1}function R(e){if(typeof e!=`object`||!e||!pt(e)||!e.body)return!1;let t=e.body;return typeof t!=`object`||!t?!1:!(`type`in t)||t.type!==`BlockStatement`||L(t,/* @__PURE__ */ new WeakSet)}function z(e){if(typeof e!=`object`||!e||!mt(e)||!e.returnType)return!1;let t=e.returnType;if(!t||typeof t!=`object`||!(`typeAnnotation`in t)||!t.typeAnnotation)return!1;let n=t.typeAnnotation;if(typeof n!=`object`||!(`type`in n))return!1;if(n.type===`TSVoidKeyword`)return!0;if(n.type===`TSTypeReference`){let e=`typeName`in n?n.typeName:null;if(e&&typeof e==`object`&&`name`in e&&e.name===`Promise`){let e=`typeArguments`in n?n.typeArguments:null;if(e&&typeof e==`object`&&`params`in e&&Array.isArray(e.params)&&e.params.length>0){let t=e.params[0];if(I(t))return t.type===`TSVoidKeyword`}}}return!1}function gt(e){return R(e)?!z(e):!1}const _t=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求有返回值的函数有 @returns 标签`}},createOnce(e){return{FunctionDeclaration(t){B(t,e)},FunctionExpression(t){B(t,e)},ArrowFunctionExpression(t){if(`parent`in t&&t.parent){let e=t.parent.type;if(e===`CallExpression`||e===`Property`)return}B(t,e)}}}});function B(e,t){if(!gt(e))return;let n=x(t.sourceCode.getAllComments(),e,t.sourceCode.text);if(!n)return;let r=d(n.value);r&&(m(r)||t.report({node:e,message:`缺少 @returns 文档`,fix:e=>{let r=C(t.sourceCode.text,n.range);return Ee(e,n,r)}}))}function vt(e){if(typeof e!=`object`||!e)return!1;let t=e;return`type`in t&&`range`in t&&Array.isArray(t.range)}const yt=e({meta:{type:`suggestion`,docs:{description:`要求 @throws 标签有异常类型`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let t of n){if(t.type!==`Block`)continue;let n=t.value;if(!n.startsWith(`*`))continue;let r=d(n);if(!r)continue;let i=r.tags.filter(e=>e.tag===`throws`||e.tag===`throw`);for(let n of i)!n.type&&vt(t)&&e.report({node:t,message:`@throws 标签应使用 {@link Type} 格式声明异常类型,例如:@throws {@link Error} 描述`})}}}}});function V(e){if(typeof e!=`object`||!e)return!1;let t=e;return`body`in t&&Array.isArray(t.body)}function bt(e){if(typeof e!=`object`||!e)return!1;let t=e;return`type`in t&&t.type===`ThrowStatement`&&`argument`in t}function xt(e){if(typeof e!=`object`||!e)return!1;let t=e;return`type`in t&&t.type===`NewExpression`&&`callee`in t}function H(e){if(typeof e!=`object`||!e)return!1;let t=e;return`type`in t&&t.type===`Identifier`&&`name`in t}function St(e){if(typeof e!=`object`||!e)return!1;let t=e;return`consequent`in t&&`alternate`in t}function Ct(e){if(typeof e!=`object`||!e)return!1;let t=e;return`block`in t&&`handler`in t}function wt(e){return typeof e!=`object`||!e?!1:`cases`in e}function Tt(e){if(typeof e!=`object`||!e||!(`consequent`in e))return!1;let t=e;return Array.isArray(t.consequent)}function Et(e){let t=e.argument;if(xt(t)){let e=t.callee;if(H(e))return e.name}return H(t)?t.name:`Error`}function U(e,t){if(!V(e))return;let n=e;if(Array.isArray(n.body))for(let e of n.body)W(e,t)}function W(e,t){if(!e||typeof e!=`object`)return;let n=e;if(`type`in n&&n.type===`ThrowStatement`&&bt(n)){let e=Et(n);t.push({typeName:e})}else`type`in n&&n.type===`IfStatement`&&St(n)?(W(n.consequent,t),n.alternate&&W(n.alternate,t)):`type`in n&&n.type===`TryStatement`&&Ct(n)?Dt(n,t):`type`in n&&n.type===`SwitchStatement`&&wt(n)?Ot(n,t):`type`in n&&n.type===`BlockStatement`&&V(n)&&U(n,t)}function Dt(e,t){V(e.block)&&U(e.block,t),e.handler&&typeof e.handler==`object`&&`body`in e.handler&&e.handler.body&&V(e.handler.body)&&U(e.handler.body,t)}function Ot(e,t){for(let n of e.cases)if(Tt(n))for(let e of n.consequent)W(e,t)}function kt(e){if(!e||typeof e!=`object`||!(`body`in e)||!e.body)return[];let t=e.body;if(typeof t!=`object`||!t||!(`type`in t)||t.type!==`BlockStatement`)return[];let n=[];return U(t,n),n}const At=e({meta:{type:`suggestion`,docs:{description:`要求抛出异常的函数有 @throws 标签`}},createOnce(e){return{FunctionDeclaration(t){G(t,e)},FunctionExpression(t){G(t,e)},ArrowFunctionExpression(t){if(`parent`in t&&t.parent){let e=t.parent.type;if(e===`CallExpression`||e===`Property`)return}G(t,e)}}}});function G(e,t){let n=kt(e);if(n.length===0)return;let r=x(t.sourceCode.getAllComments(),e,t.sourceCode.text);if(!r){K(e,t,n);return}let i=d(r.value);i?i.tags.filter(e=>e.tag===`throws`||e.tag===`throw`).length===0&&K(e,t,n):K(e,t,n)}function K(e,t,n){let r=[...new Set(n.map(e=>e.typeName))],i=r[0]||`Error`;t.report({node:e,message:`函数抛出异常但没有 @throws 标签。抛出的异常类型: ${r.join(`, `)}。正确用法: @throws {@link ${i}} 异常描述`})}function jt(e){return de.safeParse(e).success}function Mt(e){return ue.safeParse(e).success}function Nt(e){return ce.safeParse(e).success}function Pt(e){return le.safeParse(e).success}function Ft(e){return be.safeParse(e).success}function It(e){return xe.safeParse(e).success}function q(e){return e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`?zt(e):e.type===`MethodDefinition`&&Ft(e)&&e.value?Bt(e.value):e.type===`ClassDeclaration`?Vt():e.type===`VariableDeclaration`&&It(e)?Ht(e.declarations):J()}function Lt(e,t){return`\n${t}`+e.join(`\n${t}`)+`\n${t}`}function Rt(e,t){return Lt(q(e),t)}function zt(e){let t=O(e),n=R(e),r=z(e),i=[];i.push(`/**`),i.push(` * ${S.functionDescription}`);for(let e of t)i.push(` * @param ${e} - ${S.paramDescription}`);return n&&!r&&i.push(` * @returns ${S.returnsDescription}`),i.push(` */`),i}function Bt(e){if(!e||typeof e!=`object`||!jt(e))return J();let t=e,n=O(t),r=R(t),i=z(t),a=[];a.push(`/**`),a.push(` * ${S.methodDescription}`);for(let e of n)a.push(` * @param ${e} - ${S.paramDescription}`);return r&&!i&&a.push(` * @returns ${S.returnsDescription}`),a.push(` */`),a}function Vt(){let e=[];return e.push(`/**`),e.push(` * ${S.classDescription}`),e.push(` */`),e}function Ht(e){let t=e[0];if(!t||!Mt(t))return J();let n=Nt(t)?t.init:void 0;if(n&&typeof n==`object`&&Pt(n)){let e=n.type;if(e===`ArrowFunctionExpression`||e===`FunctionExpression`)return J()}let r=[];return r.push(`/**`),r.push(` * ${S.variableDescription}`),r.push(` */`),r}function J(){let e=[];return e.push(`/**`),e.push(` * ${S.description}`),e.push(` */`),e}function Ut(e,t){let n=e.map(e=>{let t=e.trim();return t.startsWith(`*`)?t.slice(1).trim():t});for(;n.length>0&&!n[0];)n.shift();for(;n.length>0&&!n[n.length-1];)n.pop();return n.length===0?`/**\n${t} */`:`/**\n${n.map(e=>e?`${t} * ${e}`:`${t} *`).join(`
16
+ `)}\n${t} */`}function Y(e){return typeof e==`object`&&!!e&&`type`in e&&typeof e.type==`string`}function X(e){return typeof e==`object`&&!!e&&`parent`in e}function Wt(e){return typeof e==`object`&&!!e&&`init`in e}function Z(e){return typeof e==`object`&&!!e}const Gt=[`FunctionDeclaration`,`MethodDefinition`,`ClassDeclaration`,`VariableDeclaration`,`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSEnumDeclaration`,`PropertyDefinition`,`TSEnumMember`];function Kt(e){if(!Z(e)||e.type!==`TSPropertySignature`)return!1;let t=e.key;return Z(t)&&t.type===`Identifier`&&`name`in t&&typeof t.name==`string`?t.name===`null`||t.name===`undefined`:!1}function qt(e,t){if(X(e)&&e.parent&&typeof e.parent==`object`&&Y(e.parent)&&[`ForStatement`,`ForInStatement`,`ForOfStatement`].includes(e.parent.type))return!0;if(e.type===`VariableDeclaration`){if(t)return!1;if(M(e)&&e.declarations.length>0){let t=e.declarations[0];if(!t)return!0;if(Wt(t)&&t.init&&typeof t.init==`object`&&Y(t.init)&&(t.init.type===`ArrowFunctionExpression`||t.init.type===`FunctionExpression`))return!1}return!0}return!!Kt(e)}function Jt(e){return e.includes(`/**`)}function Yt(e){if(`decorators`in e&&Array.isArray(e.decorators)&&e.decorators.length>0){let t=e.decorators[0];if(Z(t)){let e=t.range;if(Array.isArray(e)&&e.length>=1&&typeof e[0]==`number`)return[e[0],e[0]]}}if(X(e)&&e.parent&&typeof e.parent==`object`){let t=e.parent;if(Y(t)&&Z(t)&&[`ExportNamedDeclaration`,`ExportDefaultDeclaration`].includes(t.type)){let e=t.range;if(Array.isArray(e)&&e.length>=1&&typeof e[0]==`number`)return[e[0],e[0]]}}return[e.range[0],e.range[0]]}function Q(e,t){if(!e)return``;let n=t;for(;n>0&&e[n-1]!==`
17
+ `;)n--;return e.slice(n,t)}function Xt(e,t,n){let r=Yt(t),i=Rt(t,Q(n.sourceCode.text,r[0]));return e.insertTextBeforeRange(r,i)}function Zt(e,t,n){if(t.skipFile||qt(e,t.checkAllVariables))return;let r=x(t.commentsCache,e,n.sourceCode.text);if(!r){let r=P(e.type),i=N(e),a=Se(t.commentsCache,e,n.sourceCode.text);n.report({node:e,message:`${r}"${i}"缺少 TSDoc 注释`,fix:t=>{let r=a?.comments[0],i=a?.comments[a.comments.length-1];if(!r||!i)return Xt(t,e,n);let o=[r.range[0],i.range[1]],s=Q(n.sourceCode.text,o[0]),c=a.comments.flatMap(e=>e.type===`Block`?e.value.split(`
18
+ `):[e.value]),l=c.map(e=>{let t=e.trim();return t.startsWith(`*`)?t.slice(1).trim():t}).every(e=>!e)?q(e).join(`
19
+ `):Ut(c,s);return t.replaceTextRange(o,l)}});return}let i=r.value;if(we(i)){let t=P(e.type),r=N(e);n.report({node:e,message:`${t}"${r}"的 TSDoc 注释包含占位描述,请填写实际描述`})}}function Qt(e,t){let n=e.getAllComments(),r=e.text;if(r!=null){if(!Jt(r))return t.skipFile=!0,n}else if(!n.some(e=>e.type===`Block`&&e.value.startsWith(`*`)))return t.skipFile=!0,n;return n}function $t(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t=e;if(`checkAllVariables`in t&&typeof t.checkAllVariables==`boolean`)return t.checkAllVariables}return!1}const en=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求 TSDoc 注释存在`},schema:[{type:`object`,properties:{contexts:{type:`array`,items:{type:`string`}},checkAllVariables:{type:`boolean`}},additionalProperties:!1}]},createOnce(e){let t={commentsCache:[],checkAllVariables:!1,skipFile:!1},n={Program(n){t.skipFile=!1,t.checkAllVariables=!1,t.commentsCache=Qt(e.sourceCode,t);let r=e.options?.[0];t.checkAllVariables=$t(r)}};for(let r of Gt)n[r]=n=>Zt(n,t,e);return n}});function tn(e){return e.tags.filter(e=>e.tag===`typeParam`||e.tag===`template`).map(e=>e.name)}const nn=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求泛型有 @typeParam 标签`}},createOnce(e){return{FunctionDeclaration(t){$(t,e)},FunctionExpression(t){$(t,e)},ArrowFunctionExpression(t){if(`parent`in t&&t.parent){let e=t.parent.type;if(e===`CallExpression`||e===`Property`)return}$(t,e)},ClassDeclaration(t){$(t,e)},TSInterfaceDeclaration(t){$(t,e)},TSTypeAliasDeclaration(t){$(t,e)}}}});function $(e,t){if(!it(e))return;let n=at(e);if(n.length===0)return;let r=x(t.sourceCode.getAllComments(),e,t.sourceCode.text);if(!r)return;let i=d(r.value);if(!i)return;let a=tn(i),o=n.filter(e=>!a.includes(e));for(let n of o)t.report({node:e,message:`缺少类型参数 "${n}" 的 @typeParam 文档`,fix:e=>{let i=C(t.sourceCode.text,r.range);return De(e,r,n,i)}})}const rn=/^(=+)\s+(.+?)\s+(=+)$/;function an(e){let t=e.trim().match(rn);return t?{leadingEquals:t[1]??``,text:t[2]??``,trailingEquals:t[3]??``}:null}const on=e({meta:{type:`suggestion`,fixable:`code`,docs:{description:`要求代码块分隔符使用规范格式`}},createOnce(e){return{Program(t){let n=e.sourceCode.getAllComments();for(let r of n){if(r.type!==`Line`)continue;let n=an(r.value.trim());if(n&&(n.leadingEquals.length!==20||n.trailingEquals.length!==20)){let i=`=`.repeat(20);e.report({node:t,message:`代码块分隔符格式不正确,应为:// ${i} ${n.text} ${i}`,fix:e=>{let t=`// ${i} ${n.text} ${i}`;return e.replaceTextRange(r.range,t)}})}}}}}}),sn=/\bTODO(?:\(([^)]+)\))?:?\s*(.*)/i;function cn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const ln={requireAuthor:!1,requireDescription:!0};function un(e){return/\bTODO\b/i.test(e)}function dn(e){let t={...ln};if(cn(e)){let n=e;typeof n.requireAuthor==`boolean`&&(t.requireAuthor=n.requireAuthor),typeof n.requireDescription==`boolean`&&(t.requireDescription=n.requireDescription)}return t}function fn(e){let t=e.match(sn);return t?{author:t[1]??``,description:(t[2]??``).trim()}:null}const pn={"no-commented-code":s,"no-description-tag":se,"no-extra-param":Fe,"no-legacy-jsdoc-tags":ze,"no-placeholder-description":Ue,"param-hyphen-format":Ge,"require-blank-line-before-tags":qe,"require-deprecated-alternative":Xe,"require-description":Qe,"require-multiline-property-comment":ct,"require-param":ut,"require-param-description":lt,"require-returns":_t,"require-returns-description":dt,"require-throws":At,"require-throws-type":yt,"require-tsdoc":en,"require-type-param":nn,"separator-format":on,"todo-format":e({meta:{type:`suggestion`,docs:{description:`要求 TODO 注释有描述和作者`}},createOnce(e){let t=dn(e.options?.[0]);return{Program(n){let r=e.sourceCode.getAllComments();for(let i of r){let r=i.value;if(!un(r))continue;let a=fn(r);a&&(t.requireAuthor&&!a.author&&e.report({node:n,message:`TODO 注释缺少作者信息,格式:TODO(author): 描述`}),t.requireDescription&&!a.description&&e.report({node:n,message:`TODO 注释缺少描述说明`}))}}}}})},mn=t({meta:{name:`@longzai-intelligence-oxlint/tsdoc-plugin`},rules:pn});export{rn as SEPARATOR_PATTERN,mn as default,mn as tsdocPlugin,an as parseSeparatorComment,pn as tsdocRules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-oxlint/presets",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
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.3",
104
- "@longzai-intelligence-oxlint/architecture-electron-plugin": "0.2.3",
105
- "@longzai-intelligence-oxlint/architecture-library-plugin": "0.2.3",
106
- "@longzai-intelligence-oxlint/code-style-plugin": "0.2.3",
107
- "@longzai-intelligence-oxlint/composer-plugin": "0.2.3",
108
- "@longzai-intelligence-oxlint/core": "0.2.3",
109
- "@longzai-intelligence-oxlint/design-rules-plugin": "0.2.3",
110
- "@longzai-intelligence-oxlint/elysia-route-plugin": "0.2.3",
111
- "@longzai-intelligence-oxlint/eslint-config-plugin": "0.2.3",
112
- "@longzai-intelligence-oxlint/file-naming-plugin": "0.2.3",
113
- "@longzai-intelligence-oxlint/lzi-builder-config-plugin": "0.2.3",
114
- "@longzai-intelligence-oxlint/lzi-config-plugin": "0.2.3",
115
- "@longzai-intelligence-oxlint/nestjs-route-plugin": "0.2.3",
116
- "@longzai-intelligence-oxlint/package-json-plugin": "0.2.3",
117
- "@longzai-intelligence-oxlint/perfectionist-plugin": "0.2.3",
118
- "@longzai-intelligence-oxlint/react-plugin": "0.2.3",
119
- "@longzai-intelligence-oxlint/schema-type-separation-plugin": "0.2.3",
120
- "@longzai-intelligence-oxlint/stylistic-plugin": "0.2.3",
121
- "@longzai-intelligence-oxlint/tsconfig-plugin": "0.2.3",
122
- "@longzai-intelligence-oxlint/tsdoc-plugin": "0.2.3",
123
- "@longzai-intelligence-oxlint/tsdown-config-plugin": "0.2.3",
124
- "@longzai-intelligence-oxlint/tsup-config-plugin": "0.2.3",
125
- "@longzai-intelligence-oxlint/typeorm-plugin": "0.2.3",
126
- "@longzai-intelligence-oxlint/typescript-eslint-plugin": "0.2.3",
127
- "@longzai-intelligence-oxlint/utils": "0.2.3",
128
- "@longzai-intelligence-oxlint/vitest-config-plugin": "0.2.3",
129
- "@longzai-intelligence-oxlint/zod-plugin": "0.2.3",
103
+ "@longzai-intelligence-oxlint/architecture-core-plugin": "0.2.5",
104
+ "@longzai-intelligence-oxlint/architecture-electron-plugin": "0.2.5",
105
+ "@longzai-intelligence-oxlint/architecture-library-plugin": "0.2.5",
106
+ "@longzai-intelligence-oxlint/code-style-plugin": "0.2.5",
107
+ "@longzai-intelligence-oxlint/composer-plugin": "0.2.5",
108
+ "@longzai-intelligence-oxlint/core": "0.2.5",
109
+ "@longzai-intelligence-oxlint/design-rules-plugin": "0.2.5",
110
+ "@longzai-intelligence-oxlint/elysia-route-plugin": "0.2.5",
111
+ "@longzai-intelligence-oxlint/eslint-config-plugin": "0.2.5",
112
+ "@longzai-intelligence-oxlint/file-naming-plugin": "0.2.5",
113
+ "@longzai-intelligence-oxlint/lzi-builder-config-plugin": "0.2.5",
114
+ "@longzai-intelligence-oxlint/lzi-config-plugin": "0.2.5",
115
+ "@longzai-intelligence-oxlint/nestjs-route-plugin": "0.2.5",
116
+ "@longzai-intelligence-oxlint/package-json-plugin": "0.2.5",
117
+ "@longzai-intelligence-oxlint/perfectionist-plugin": "0.2.5",
118
+ "@longzai-intelligence-oxlint/react-plugin": "0.2.5",
119
+ "@longzai-intelligence-oxlint/schema-type-separation-plugin": "0.2.5",
120
+ "@longzai-intelligence-oxlint/stylistic-plugin": "0.2.5",
121
+ "@longzai-intelligence-oxlint/tsconfig-plugin": "0.2.5",
122
+ "@longzai-intelligence-oxlint/tsdoc-plugin": "0.2.5",
123
+ "@longzai-intelligence-oxlint/tsdown-config-plugin": "0.2.5",
124
+ "@longzai-intelligence-oxlint/tsup-config-plugin": "0.2.5",
125
+ "@longzai-intelligence-oxlint/typeorm-plugin": "0.2.5",
126
+ "@longzai-intelligence-oxlint/typescript-eslint-plugin": "0.2.5",
127
+ "@longzai-intelligence-oxlint/utils": "0.2.5",
128
+ "@longzai-intelligence-oxlint/vitest-config-plugin": "0.2.5",
129
+ "@longzai-intelligence-oxlint/zod-plugin": "0.2.5",
130
130
  "@vitest/coverage-v8": "^4.1.10"
131
131
  },
132
132
  "peerDependencies": {