@2digits/oxlint-plugin 0.7.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,7 +1,9 @@
1
- import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";import*as n from"effect/Record";import*as r from"effect/Array";import*as i from"effect/Predicate";import*as a from"effect/String";import*as o from"effect/Effect";import*as s from"effect/Function";import*as c from"effect/Match";import*as l from"effect/Option";import*as u from"effect/Schema";import*as d from"effect/Struct";import*as f from"effect/Result";import*as p from"effect/Tuple";import*as m from"effect/Duration";import*as h from"effect/Number";import{Rule as ee,RuleContext as te,Visitor as ne}from"effect-oxlint";import*as g from"effect/Ref";var _=class extends u.Class(`FileState`)({bindings:u.ReadonlyMap(u.String,u.Array(u.String)).pipe(u.withConstructorDefault(o.succeed(/* @__PURE__ */ new Map))),hasEffectImport:u.Boolean.pipe(u.withConstructorDefault(o.succeed(!1)))}){};const re=_.make(),v=c.type().pipe(c.discriminatorsExhaustive(`type`)({Identifier:({name:e})=>e,Literal:({value:e})=>e}));function ie(e){let t=r.lastNonEmpty(a.split(e,`/`));return/^\p{Ll}/u.test(t)?[]:[t]}const ae=c.type().pipe(c.withReturnType(),c.when(`alchemy`,s.constant([`Alchemy`])),c.when(`@alchemy.run/domain`,s.constant([`Domain`])),c.when(c.is(`effect`,`@effect/platform`),s.constant([])),c.whenOr(a.startsWith(`effect/`),a.startsWith(`alchemy/`),a.startsWith(`@effect/`),ie),c.orElse(s.constUndefined));function oe(e){let t=/* @__PURE__ */ new Map,n=!1;for(let r of e.body){if(r.type!==`ImportDeclaration`)continue;let e=r.source.value;(e===`effect`||a.startsWith(`effect/`)(e)||a.startsWith(`@effect/`)(e))&&(n=!0);let o=ae(e);if(!i.isUndefined(o))for(let e of r.specifiers)e.type===`ImportNamespaceSpecifier`||e.type===`ImportDefaultSpecifier`?t.set(e.local.name,o):t.set(e.local.name,[...o,v(e.imported)])}return _.make({bindings:t,hasEffectImport:n})}function y(t,n){return e({meta:t,createOnce:n})}function b(t,n){return e({meta:t,createOnce(e){let t=re,{before:r,Program:i,...a}=n(e,()=>t);return{before(){t=re,r?.()},Program(e){t=oe(e),i?.(e)},...a}}})}function x(e,t,n,r){return{type:e,docs:{description:t,recommended:!0,...i.isUndefined(r)?{}:{url:r}},schema:[],messages:n}}const S=c.type().pipe(c.when({computed:!1,property:{type:`Identifier`}},({property:e})=>e.name),c.when({computed:!0,property:{type:`Literal`,value:a.isString}},({property:e})=>e.value),c.orElse(s.constUndefined));function C(e){let t=[],n=e;for(;n.type===`ChainExpression`||n.type===`MemberExpression`;){if(n.type===`ChainExpression`){n=n.expression;continue}let e=S(n);if(i.isUndefined(e))return;t.unshift(e),n=n.object}return n.type===`Identifier`?[n.name,...t]:void 0}function w(e,t,n){for(let r=e.sourceCode.getScope(t);i.isNotNull(r);r=r.upper){let e=r.set.get(n);if(i.isNotUndefined(e))return e}}function T(e){return e?.defs.length===1?l.getOrUndefined(r.head(e.defs)):void 0}function E(e,t,n){return e.type===`Identifier`&&e.name===n&&(w(t,e,n)?.defs.length??0)===0}function D(e,t){let n=C(e),r=n?.[0];if(i.isUndefined(n)||i.isUndefined(r))return;let a=t.bindings.get(r);return i.isUndefined(a)?void 0:[...a,...n.slice(1)]}function O(e,t,n,r){let i=D(e,t);return i?.length===2&&i[0]===n&&i[1]===r}function k(e,t,n,i){let a=D(e,t);return a?.length===2&&a[0]===n&&r.contains(i,a[1])}function A(e,t,n){let i=D(e,t);return i?.length===n.length&&r.every(i,(e,t)=>e===n[t])}const se=c.type().pipe(c.when({type:c.is(`ArrowFunctionExpression`,`FunctionExpression`)},s.constTrue),c.orElse(s.constFalse));function j(e){return se(e)}const ce=c.type().pipe(c.when({type:`VariableDeclaration`,kind:`const`},s.constTrue),c.orElse(s.constFalse)),le=c.type().pipe(c.when({type:`Property`,computed:!1,method:!1,kind:`init`},e=>e),c.orElse(s.constUndefined));function M(e,t){let n=e.arguments[t];return i.isUndefined(n)||n.type===`SpreadElement`?void 0:n}const N=c.type().pipe(c.when({computed:!1,key:{type:`Identifier`}},({key:e})=>e.name),c.when({key:{type:`Literal`,value:a.isString}},({key:e})=>e.value),c.orElse(s.constUndefined));function P(e,t){return l.getOrUndefined(r.findFirst(e.properties,e=>e.type===`Property`&&N(e)===t))}const ue=/* @__PURE__ */ new Set([`ParenthesizedExpression`,`TSAsExpression`,`TSNonNullExpression`,`TSSatisfiesExpression`,`TSTypeAssertion`]);function de(e){return ue.has(e.type)}const fe=/* @__PURE__ */ new Set([`loc`,`parent`,`range`]);function F(e){let t=e;for(;de(t);)t=t.expression;return t}function pe(e,t){if(r.isArray(e))for(let n of e)t.push(n);else for(let[r,i]of n.toEntries(e))fe.has(r)||t.push(i)}function I(e,t){let n=[e],a=/* @__PURE__ */ new WeakSet;for(;r.isReadonlyArrayNonEmpty(n);){let e=n.pop();if(i.isObjectOrArray(e)&&!a.has(e)){if(a.add(e),i.hasProperty(e,`type`)&&i.isString(e.type)&&t(e)===!0)return!0;pe(e,n)}}return!1}function me(e,t){return I(e,e=>e.type===`Identifier`&&e.name===t)}function L(e){return l.getOrUndefined(l.filter(r.head(e.params),e=>e.type===`Identifier`))}function he(e){let t=L(e);return i.isUndefined(t)||!e.body||a.startsWith(`_`)(t.name)?!1:me(e.body,t.name)}function ge(e,t){for(let n=e.parent;n;n=n.parent)if(t(n))return n}function R(e){return ge(e,j)}function z(e){let t=e.parent;if(t.type===`CallExpression`&&t.arguments.includes(e))return t}function _e(e,t){return e.range[0]<=t.range[0]&&t.range[1]<=e.range[1]}function B(e){return e.type===`Literal`&&a.isString(e.value)}const ve=/* @__PURE__ */ new Set([`==`,`===`,`!=`,`!==`]);function ye(e){return ve.has(e)}function V(e,t){return e.type===`Literal`&&e.value===t}function be(e){let t=e.parent;return t?t.type===`ExpressionStatement`||t.type===`UnaryExpression`&&t.operator===`void`||t.type===`SequenceExpression`&&t.expressions.at(-1)!==e:!1}const xe=i.mapInput(i.compose(i.isString,a.endsWith(`Error`)),e=>C(e.callee)?.at(-1)),Se=[`Aggregate`,`Api`,`Command`,`Event`,`ExternalSystem`,`Model`,`Policy`,`Projection`,`Rejection`,`RequestContext`,`Saga`,`Stream`,`View`];function Ce(e){return r.contains(Se,e)}function we(e,t,n){let r=Ee(e.callee,t,n),i=r?.[1];return r?.length===2&&r[0]===`Domain`&&Ce(i)?i:void 0}function Te(e,t){let n=e.parent;return n.type===`MemberExpression`&&n.property===e&&!n.computed||n.type===`Property`&&n.key===e&&n.value!==e?!1:T(w(t,n,e.name))?.type===`ImportBinding`}function Ee(e,t,n){return l.exists(r.head(C(e)??[]),t=>T(w(n,e,t))?.type===`ImportBinding`)?D(e,t):void 0}function De(e,t,n){for(let r=e,a=e.parent;a;r=a,a=a.parent){if(a.type!==`Property`||a.value!==r)continue;let e=a.parent,o=e.parent;for(;i.isNotNull(o)&&ue.has(o.type);)o=o.parent;let s=o?.type===`CallExpression`?M(o,1):void 0;if(i.isUndefined(s)||e.type!==`ObjectExpression`||o?.type!==`CallExpression`||F(s)!==e)continue;let c=we(o,t,n);if(i.isUndefined(c))continue;let l=N(a);return i.isUndefined(l)?void 0:{block:c,section:l}}}const Oe={Aggregate:`aggregate`,Api:`api`,Command:`command`,ExternalSystem:`external`,Model:`model`,Policy:`policy`,Projection:`projection`,RequestContext:`context`,Saga:`saga`,Stream:`stream`,View:`view`},ke={Event:`event`,Rejection:`rejection`},Ae=/* @__PURE__ */ new Set([`command`,`external`,`stream`]),je=/\.(?:test|spec|stories?)\.[cm]?[jt]sx?$/u,Me=b(x(`suggestion`,"Require one Alchemy Domain block per file, named `<Noun>.<kind>.ts`.",{fileName:"Declare this {{block}} in its own `<Noun>.{{kind}}.ts` file.",oneBlock:"Move this {{block}} to its own `<Noun>.{{kind}}.ts` file. Each file declares one Domain block."},`https://alchemy.run/domain`),(e,t)=>{let n=!1,o=[],s=!1;return{before(){n=!1,o=[],s=!1},"Program:exit":function(){if(!s)for(let{node:t,block:n,kind:r}of o)e.report({node:t,messageId:`fileName`,data:{block:n,kind:r}})},CallExpression(c){let l=we(c,t(),e),u=r.lastNonEmpty(a.split(e.filename,/[/\\]/u)),d=a.split(u,`.`),f=d.length>=3&&a.isNonEmpty(r.headNonEmpty(d))?d.at(-2):void 0,p=i.isUndefined(l)?void 0:Oe[l]??ke[l];i.isUndefined(l)||i.isUndefined(p)||je.test(u)||(Ae.has(f)&&i.isNotUndefined(ke[l])?o.push({node:c.callee,block:l,kind:p}):(f===p&&Ae.has(f)&&(s=!0),n?e.report({node:c.callee,messageId:`oneBlock`,data:{block:l,kind:p}}):f!==p&&e.report({node:c.callee,messageId:`fileName`,data:{block:l,kind:p}}),n=!0))}}}),Ne=/* @__PURE__ */ new Map([[`Date.now`,`time`],[`performance.now`,`time`],[`performance.timeOrigin`,`time`],[`Math.random`,`random`],[`crypto.randomUUID`,`random`],[`crypto.getRandomValues`,`random`]]),Pe=/* @__PURE__ */ new Map([[`Clock`,`time`],[`Random`,`random`],[`SecureRandom`,`random`]]),Fe=/* @__PURE__ */ new Map([[`DateTime.now`,`time`],[`DateTime.nowAsDate`,`time`],[`DateTime.nowInCurrentZone`,`time`],[`DateTime.nowUnsafe`,`time`],[`DateTime.isFuture`,`time`],[`DateTime.isFutureUnsafe`,`time`],[`DateTime.isPast`,`time`],[`DateTime.isPastUnsafe`,`time`],[`Aead.Aead`,`random`],[`Cipher.Cipher`,`random`],[`Signature.Signature`,`random`],[`KeyAgreement.KeyAgreement`,`random`],[`KeyWrap.KeyWrap`,`random`],[`Jwk.generateKeyPair`,`random`],[`Jwk.generateSecret`,`random`],[`Jwe.encrypt`,`random`],[`Jws.sign`,`random`],[`Jws.verifyWithKeySet`,`io`],[`Jwt.sign`,`random`],[`Jwt.encrypt`,`random`],[`Jwt.verify`,`time`],[`Jwt.verifyWithKeySet`,`time`],[`Jwt.decrypt`,`time`],[`Jwks.Jwks`,`io`],[`Jwks.makeRemote`,`io`],[`Jwks.layerRemote`,`io`]]),Ie=[`promise`,`tryPromise`],Le=b(x(`problem`,`Require Alchemy Domain aggregate decide handlers to be pure.`,{time:"`decide` reads time from its `now` argument, not {{api}}. Replays must decide the same way.",random:"`decide` must be deterministic, so it cannot use {{api}}. Take the value from the command input instead.",io:"`decide` never performs I/O such as {{api}}. Call external systems from a policy or saga and send the result as a command."},`https://alchemy.run/domain/aggregate`),(e,t)=>{function n(n,r,a){i.isNotUndefined(r)&&De(n,t(),e)?.section===`decide`&&e.report({node:n,messageId:r,data:{api:a}})}function a(i){let a=Ee(i,t(),e)??[];if(!r.isReadonlyArrayNonEmpty(a)||a.length!==2)return;let o=r.join(a,`.`);n(i,Fe.get(o)??Pe.get(r.headNonEmpty(a)),o)}function o(t){if(t.type===`Identifier`)return E(t,e,t.name)?t.name:void 0;let n=C(t);return t.type===`MemberExpression`&&n?.length===2&&E(t.object,e,`globalThis`)?n[1]:void 0}return{MemberExpression(t){let i=C(t)??[],o=r.head(i),s=t;for(;s.type===`MemberExpression`||s.type===`ChainExpression`;)s=s.type===`ChainExpression`?s.expression:s.object;let c=l.contains(o,`globalThis`)?i.slice(1):i;if(c.length===2&&l.exists(o,t=>E(s,e,t))){let e=r.join(c,`.`),i=t.parent.type===`CallExpression`&&t.parent.callee===t;n(t,Ne.get(e),i?`${e}()`:e)}else a(t)},Identifier(t){Te(t,e)&&a(t)},NewExpression(e){r.isReadonlyArrayEmpty(e.arguments)&&o(e.callee)===`Date`&&n(e,`time`,`new Date()`)},CallExpression(i){c.value(o(i.callee)).pipe(c.when(`Date`,()=>n(i,`time`,`Date()`)),c.when(`fetch`,()=>n(i,`io`,`fetch()`)),c.orElse(()=>{let a=Ee(i.callee,t(),e);a?.length===2&&a[0]===`Effect`&&Ie.includes(a[1]??``)&&n(i,`io`,r.join(a,`.`))}))}}}),Re=/\.(?:aggregate|api|command|context|event|external|id|middleware|model|policy|projection|rejection|saga|stream|view)\.[cm]?tsx?$/u,ze=`@alchemy.run/domain`;function Be(e){return a.startsWith(`.`)(e)||e===`effect`||a.startsWith(`effect/`)(e)||e===ze||a.startsWith(`${ze}/`)(e)}function Ve(e){return r.some(e.body,e=>e.type===`ImportDeclaration`&&e.source.value===ze)}const He=y(x(`problem`,"Restrict Alchemy Domain block files to imports from `@alchemy.run/domain`, `effect` and the domain package itself.",{import:"A domain block imports only `@alchemy.run/domain`, `effect` and relative files, not `{{source}}`. Put code that touches infrastructure in the server package.",dynamic:"A domain block imports only `@alchemy.run/domain`, `effect` and relative files, so its import sources must be string literals."},`https://alchemy.run/domain`),e=>{let t=!1;function n(n){t&&i.isNotNull(n.source)&&!Be(n.source.value)&&e.report({node:n.source,messageId:`import`,data:{source:n.source.value}})}function r(n){t&&(n.type!==`Literal`||!i.isString(n.value)?e.report({node:n,messageId:`dynamic`}):Be(n.value)||e.report({node:n,messageId:`import`,data:{source:n.value}}))}return{Program(n){t=Re.test(e.filename)&&Ve(n)},ImportDeclaration:n,ExportAllDeclaration:n,ExportNamedDeclaration:n,ImportExpression(e){r(e.source)},TSImportEqualsDeclaration(e){e.moduleReference.type===`TSExternalModuleReference`&&r(e.moduleReference.expression)},CallExpression(t){let n=M(t,0);i.isNotUndefined(n)&&E(t.callee,e,`require`)&&r(n)}}}),Ue=b(x(`suggestion`,`Require Alchemy Domain views to declare their version.`,{missing:"Declare `version` on this view (`version: 0` keeps the current default). Bump it whenever `evolve`, `emit`, `keyOf`, `state` or `from` changes, so the deploy rebuilds the view from its events.",overridden:"Move `version` after the spread, so the spread cannot override the version this view declares."},`https://alchemy.run/domain/model#change-a-view-bump-its-version`),(e,t)=>({CallExpression(n){let a=M(n,1),o=i.isUndefined(a)?void 0:F(a);if(we(n,t(),e)!==`View`||o?.type!==`ObjectExpression`)return;let s=P(o,`version`);i.isUndefined(s)?e.report({node:n.callee,messageId:`missing`}):r.some(o.properties.slice(o.properties.indexOf(s)+1),e=>e.type===`SpreadElement`)&&e.report({node:s,messageId:`overridden`})}})),We=/* @__PURE__ */ new Map([[`Aggregate`,/* @__PURE__ */ new Set([`evolve`,`reply`])],[`View`,/* @__PURE__ */ new Set([`evolve`])]]),Ge=/* @__PURE__ */ new Set([`Option`,`Result`]),Ke=/* @__PURE__ */ new Set([`getOrThrow`,`getOrThrowWith`]),qe=b(x(`problem`,`Require Alchemy Domain evolve and reply handlers to be total, and decide handlers to reject instead of throwing.`,{partial:'`{{section}}` must be total and never fail: {{api}} throws when the state is not what it expects. Keep any state the event cannot follow, such as `s._tag === "Open" ? { ...s, ... } : s`.',reject:"`decide` never throws: {{api}} becomes a defect the caller cannot handle. Return a rejection the command lists in `rejects` instead, or `return yield* rejection` in an `Effect.fn`."},`https://alchemy.run/domain/aggregate`),(e,t)=>{function n(n,r){let a=De(n,t(),e);i.isUndefined(a)||(a.block===`Aggregate`&&a.section===`decide`?e.report({node:n,messageId:`reject`,data:{api:r}}):We.get(a.block)?.has(a.section)===!0&&e.report({node:n,messageId:`partial`,data:{section:a.section,api:r}}))}function a(i){let a=Ee(i,t(),e);a?.length===2&&Ge.has(a[0]??``)&&Ke.has(a[1]??``)&&n(i,`\`${r.join(a,`.`)}\``)}return{ThrowStatement(e){n(e,"`throw`")},MemberExpression:a,Identifier(t){Te(t,e)&&a(t)}}}),Je=/* @__PURE__ */ new Set([`alarm`,`fetch`,`queue`,`rpc`,`scheduled`,`tail`,`trace`,`webSocketClose`,`webSocketError`,`webSocketMessage`]),Ye=[[`Cloudflare`,`Worker`],[`Cloudflare`,`Workers`,`Worker`]];function Xe(e,t){return r.some(Ye,n=>A(e,t,n))}function Ze(e,t){return ge(e,e=>e.type===`CallExpression`&&Xe(e.callee,t))}function Qe(e,t){let n=R(e),r=i.isUndefined(n)?void 0:z(n);return i.isNotUndefined(r)&&O(r.callee,t,`Effect`,`gen`)?r:void 0}function $e(e){let t=e.parent;for(;t;){if(j(t))return;if(t.type===`Property`){let e=N(t);if(i.isNotUndefined(e)&&Je.has(e))return e}t=t.parent}}const et=b(x(`problem`,`Disallow finalizers in Cloudflare Worker initialization, where workerd never runs them.`,{finalizer:`A Cloudflare Worker init finalizer never runs because workerd has no isolate teardown hook. Acquire disposable resources inside an event handler.`},`https://alchemy.run/cloudflare/compute/workers`),(e,t)=>({CallExpression(n){let r=t();if(!O(n.callee,r,`Effect`,`addFinalizer`))return;let a=Qe(n,r);i.isNotUndefined(a)&&Ze(a,r)?.arguments.includes(a)&&e.report({node:n,messageId:`finalizer`})}}));function H(e,t){let n=l.flatMapNullishOr(r.head(C(t)??[]),n=>w(e,t,n));return l.exists(n,({defs:e})=>r.some(e,e=>{let t=e.node;return e.type===`ImportBinding`&&t.parent?.type===`ImportDeclaration`&&t.parent.importKind!==`type`&&(t.type!==`ImportSpecifier`||t.importKind!==`type`)}))}function tt(e,t,n,a,o){let s=e.sourceCode.ast,c=r.findFirst(r.flatMap(s.body,e=>e.type===`ImportDeclaration`&&e.source.value===n&&e.importKind!==`type`?e.specifiers:[]),n=>n.type===`ImportNamespaceSpecifier`&&r.some(w(e,t,n.local.name)?.defs??[],e=>e.node===n));if(l.isSome(c))return{name:c.value.local.name,fixes:[]};let u=new Set(r.flatMap(e.sourceCode.scopeManager.scopes,e=>[...r.map(e.variables,d.get(`name`)),...r.map(e.references,e=>e.identifier.name)])),f=a,p=2;for(;u.has(f);)f=`${a}${p++}`;let m=`import * as ${f} from '${n}';\n`,h=l.getOrUndefined(r.findFirst(s.body,e=>e.type!==`ExpressionStatement`||!B(e.expression)));return{name:f,fixes:[i.isUndefined(h)?o.insertTextAfter(s,`\n${m}`):o.insertTextBefore(h,m)]}}function nt(e,t){let n=/* @__PURE__ */ new Set;return r.every(e.properties,e=>{let r=le(e);if(i.isUndefined(r)||r.key.type!==`Identifier`&&r.key.type!==`Literal`)return!1;let a=r.key.type===`Identifier`?r.key.name:String(r.key.value);return a===t||n.has(a)?!1:(n.add(a),!0)})}const rt=b({...x(`problem`,`Disallow the deprecated top-level Docker Service constraints property.`,{constraints:`Docker.Service constraints is deprecated. Move it to placement: { constraints: ... }.`},`https://alchemy.run/providers/docker/service`),fixable:`code`},(e,t)=>({CallExpression(n){if(!O(n.callee,t(),`Docker`,`Service`))return;let r=M(n,1),i=r?.type===`ObjectExpression`?P(r,`constraints`):void 0;i!==void 0&&e.report({node:i,messageId:`constraints`,fix(t){if(H(e,n.callee)&&r?.type===`ObjectExpression`&&nt(r,`placement`))return t.replaceText(i,`placement: { ${e.sourceCode.getText(i)} }`)}})}})),it=/* @__PURE__ */ new Map([[`Cloudflare.Access.Bookmark`,`Cloudflare.Access.Application with type: "bookmark"`],[`AWS.RDSData.ExecuteSql`,`AWS.RDSData.ExecuteStatement`],[`AWS.EKS.Deployment`,`Kubernetes.Deployment from alchemy/Kubernetes`],[`AWS.EKS.HelmChart`,`Kubernetes.HelmChart from alchemy/Kubernetes`],[`AWS.EKS.Job`,`Kubernetes.Job from alchemy/Kubernetes`],[`AWS.EKS.Manifest`,`Kubernetes.Manifest from alchemy/Kubernetes`]]),at=b(x(`problem`,`Disallow deprecated Alchemy resource APIs that have supported replacements.`,{deprecated:`{{api}} is deprecated. Use {{replacement}}.`},`https://alchemy.run/llms-full.txt`),(e,t)=>({CallExpression(n){let a=D(n.callee,t());if(i.isUndefined(a))return;let o=r.join(a,`.`),s=it.get(o);i.isNotUndefined(s)&&e.report({node:n.callee,messageId:`deprecated`,data:{api:o,replacement:s}})}}));function ot(e,t){let n=F(e);if(B(n)||n.type===`TemplateLiteral`)return!0;let r=C(n);return r?.[0]===`process`&&r[1]===`env`||n.type===`CallExpression`&&O(n.callee,t,`Config`,`string`)}const st=b(x(`problem`,`Require singular GitHub Secret values to use Redacted.`,{plaintext:`GitHub.Secret value must be Redacted so it stays out of logs and state. Use Redacted.make(...) or Config.redacted(...).`},`https://alchemy.run/providers/github/secret`),(e,t)=>({CallExpression(n){let r=t();if(!O(n.callee,r,`GitHub`,`Secret`))return;let i=M(n,1),a=i?.type===`ObjectExpression`?P(i,`value`):void 0;a!==void 0&&ot(a.value,r)&&e.report({node:a.value,messageId:`plaintext`})}})),ct=b(x(`problem`,`Disallow removed Alchemy Secret and Variable APIs.`,{removed:`Alchemy.{{api}} was removed. Use effect/Config (Config.redacted for secrets, Config.string for variables).`},`https://alchemy.run/blog/2026-05-29-beta-45`),(e,t)=>({CallExpression(n){let r=D(n.callee,t());r?.[0]===`Alchemy`&&(r[1]===`Secret`||r[1]===`Variable`)&&e.report({node:n.callee,messageId:`removed`,data:{api:r[1]}})}})),lt=b(x(`problem`,`Disallow creating an EventBridge bus with the reserved default name.`,{reserved:`EventBridge reserves the name "default". Omit the bus argument to use the account default, or choose another name.`},`https://alchemy.run/aws/messaging/eventbridge`),(e,t)=>({CallExpression(n){if(!A(n.callee,t(),[`AWS`,`EventBridge`,`EventBus`]))return;let r=M(n,1),i=r?.type===`ObjectExpression`?P(r,`name`):void 0;i!==void 0&&V(i.value,`default`)&&e.report({node:i.value,messageId:`reserved`})}})),ut=b(x(`problem`,`Require Effect Config values to be resolved during Alchemy Worker initialization.`,{runtime:`Config resolved inside the {{handler}} handler is invisible to Alchemy deployment. Resolve it in Worker init and close over the value, or put it in env.`},`https://alchemy.run/environments/secrets`),(e,t)=>({YieldExpression(n){let r=t(),i=n.argument;if(i?.type!==`CallExpression`||D(i.callee,r)?.[0]!==`Config`)return;let a=Qe(n,r);if(a===void 0)return;let o=$e(a);o!==void 0&&Ze(a,r)!==void 0&&e.report({node:i,messageId:`runtime`,data:{handler:o}})}})),dt=/* @__PURE__ */ new Map([[`alchemy/aws`,`alchemy/AWS`],[`alchemy/cloudflare`,`alchemy/Cloudflare`]]),ft=y(x(`problem`,`Disallow Alchemy v1 imports that bypass the Effect-based Stack API.`,{defaultImport:`The default alchemy() API is from v1. Use import * as Alchemy and Alchemy.Stack.`,providerImport:`Use the v2 provider entrypoint {{replacement}} (capitalization is significant).`},`https://alchemy.run/migrating-from-v1`),e=>({ImportDeclaration(t){let n=t.source.value;if(n===`alchemy`){let n=l.getOrUndefined(r.findFirst(t.specifiers,e=>e.type===`ImportDefaultSpecifier`));i.isNotUndefined(n)&&e.report({node:n,messageId:`defaultImport`});return}let a=dt.get(n);i.isUndefined(a)||e.report({node:t.source,messageId:`providerImport`,data:{replacement:a}})}})),pt=[[`entrypoint`,`main`],[`bindings`,`env`]],mt=b({...x(`problem`,`Disallow Alchemy v1 Cloudflare Worker property names.`,{property:`Cloudflare.Worker {{old}} was replaced in v2. Use {{replacement}}.`},`https://alchemy.run/migrating-from-v1`),fixable:`code`},(e,t)=>({CallExpression(n){if(!Xe(n.callee,t()))return;let r=M(n,1);if(r?.type===`ObjectExpression`)for(let[t,i]of pt){let a=P(r,t);a!==void 0&&e.report({node:a,messageId:`property`,data:{old:t,replacement:i},fix(o){if(H(e,n.callee)&&nt(r,i))return o.replaceText(a.key,a.shorthand?`${i}: ${t}`:i)}})}}})),ht=b(x(`suggestion`,`Prefer schema-based tagged errors so errors have a serializable contract.`,{taggedError:`Prefer Schema.TaggedError over Data.TaggedError.`}),(e,t)=>({CallExpression(n){O(n.callee,t(),`Data`,`TaggedError`)&&e.report({node:n.callee,messageId:`taggedError`})}})),gt=/* @__PURE__ */ new Set([`error`,`err`,`e`,`cause`,`exception`,`ex`]);function _t(e){return e?.type===`Identifier`&&gt.has(e.name)?e.name:void 0}function vt(e){if(e.type!==`CallExpression`||e.arguments.length!==1)return!1;let t=C(e.callee);return t?.at(-1)===`String`&&t.length<=2}const yt=y({...x(`problem`,`Disallow string coercion that discards an error value’s stack, type, and cause chain.`,{errorString:`Do not stringify {{name}}. Preserve the original error as an Error cause instead.`,useCause:`Replace {{pattern}} with {{replacement}} to preserve the original error.`}),hasSuggestions:!0},e=>({NewExpression(t){let n=M(t,0);if(n===void 0||!vt(n)||!xe(t))return;let r=M(n,0);if(r===void 0)return;let i=e.sourceCode.getText(r),a=`'Error occurred', { cause: ${i} }`;e.report({node:n,messageId:`errorString`,data:{name:i},suggest:[{messageId:`useCause`,data:{pattern:e.sourceCode.getText(n),replacement:a},fix:e=>e.replaceText(n,a)}]})},CallExpression(t){if(vt(t)){if(t.parent.type===`NewExpression`&&t.parent.arguments[0]===t&&xe(t.parent))return;let n=_t(t.arguments[0]);n!==void 0&&e.report({node:t,messageId:`errorString`,data:{name:n}});return}if(t.callee.type!==`MemberExpression`||C(t.callee)?.at(-1)!==`toString`||t.arguments.length>0)return;let n=_t(t.callee.object);n!==void 0&&e.report({node:t,messageId:`errorString`,data:{name:n}})},TemplateLiteral(t){let[n,r]=t.quasis,i=_t(t.expressions[0]);i!==void 0&&t.quasis.length===2&&n?.value.raw===``&&r?.value.raw===``&&e.report({node:t,messageId:`errorString`,data:{name:i}})}})),bt=/* @__PURE__ */ new Set(/* @__PURE__ */ `flip.fromFormData.fromJsonString.fromURLSearchParams.mutable.mutableKey.NullishOr.NullOr.optional.optionalKey.OptionFromNullishOr.OptionFromNullOr.OptionFromOptional.OptionFromOptionalKey.OptionFromOptionalNullOr.OptionFromUndefinedOr.readonlyKey.RedactedFromValue.required.requiredKey.toCodecArrayFromSingle.toCodecGoJson.toCodecIso.toCodecJson.toCodecStringTree.toEncoded.toType.UndefinedOr`.split(`.`)),xt=/* @__PURE__ */ new Set([`Array`,`ArrayEnsure`,`Chunk`,`HashSet`,`NonEmptyArray`,`Option`,`ReadonlySet`,`Redacted`,`Tree`,`UniqueArray`]),St=/* @__PURE__ */ new Set(/* @__PURE__ */ `annotate.annotateEncoded.annotateKey.brand.catchDecoding.catchDecodingWithContext.catchEncoding.catchEncodingWithContext.check.decode.decodeTo.encode.encodeKeys.encodeTo.extendTo.fieldsAssign.fromBrand.middlewareDecoding.middlewareEncoding.overrideToCodecIso.overrideToEquivalence.overrideToFormatter.refine.toTaggedUnion.withConstructorDefault.withDecodingDefault.withDecodingDefaultKey.withDecodingDefaultType.withDecodingDefaultTypeKey`.split(`.`)),Ct=/* @__PURE__ */ new Set([`annotate`,`annotateKey`,`check`,`mapFields`]),wt=/* @__PURE__ */ new Set([`CallExpression`,`Identifier`,`MemberExpression`,`ThisExpression`]),Tt=/^\p{Lu}/u;function U(e,t,n){let r=D(e,n);return C(e)?.length===2&&r?.length===2&&r[0]===`Schema`&&H(t,e)?r[1]:void 0}function Et(e){return e!==void 0&&xt.has(e)}function Dt(e){return e!==void 0&&(bt.has(e)||xt.has(e))}const Ot=/* @__PURE__ */ new Set([`ArrowFunctionExpression`,`FunctionExpression`,`Identifier`,`Literal`,`ThisExpression`]);function kt(e,t,n){return r.every(e,e=>i.isNull(e)||W(e,t,n))}function W(e,t,n){if(Ot.has(e.type))return!0;if(e.type===`MemberExpression`)return W(e.object,t,n)&&(!e.computed||W(e.property,t,n));if(e.type===`TemplateLiteral`)return kt(e.expressions,t,n);if(e.type===`ArrayExpression`)return kt(e.elements,t,n);if(e.type===`ObjectExpression`)return r.every(e.properties,e=>e.type===`SpreadElement`?W(e.argument,t,n):(!e.computed||W(e.key,t,n))&&W(e.value,t,n));if(e.type!==`CallExpression`)return!1;let a=e.callee.type===`CallExpression`?e.callee.callee:e.callee;return i.isNotUndefined(U(a,t,n))&&(e.callee===a||W(e.callee,t,n))&&kt(e.arguments,t,n)}function At(e,t){if(e.type===`Identifier`)return t.bindings.get(e.name);if(e.type!==`TSQualifiedName`)return;let n=At(e.left,t);return i.isUndefined(n)?void 0:[...n,e.right.name]}function jt(e,t){for(let n=t.parent;i.isNotNull(n);n=n.parent){let t=`typeParameters`in n&&n.typeParameters?.type===`TSTypeParameterDeclaration`?s.pipe(n.typeParameters.params,r.findFirst(t=>t.name.name===e),l.getOrUndefined):void 0;if(i.isNotUndefined(t))return t}}function Mt(e,t,n){let r=/* @__PURE__ */ new Set,o=e,s=t;for(;o?.type===`TSTypeReference`;){let e=At(o.typeName,n),t=e?.length===2&&e[0]===`Schema`?e[1]:void 0;if(i.isNotUndefined(t))return!a.startsWith(`Constraint`)(t);let c=o.typeName.type===`Identifier`?jt(o.typeName.name,s):void 0;if(i.isUndefined(c)||r.has(c))return r.size===0&&void 0;r.add(c),o=c.constraint,s=c}return r.size===0&&void 0}function Nt(e,t){return r.head(w(t,e,e.name)?.defs??[]).pipe(l.flatMapNullishOr(({name:e})=>`typeAnnotation`in e?e.typeAnnotation:void 0),l.getOrUndefined)}function Pt(e,t,n){let r=e;for(;r.type===`TSSatisfiesExpression`||r.type===`TSNonNullExpression`;)r=r.expression;if(r.type===`TSAsExpression`)return Mt(r.typeAnnotation,r,n)===!1;let a=r.type===`Identifier`?Nt(r,t):void 0;return i.isNotUndefined(a)&&Mt(a.typeAnnotation,a,n)===!1}function Ft(e){return r.some(e.arguments,e=>e.type===`SpreadElement`)}function It(e){let[t]=e.arguments;return e.arguments.length===1&&t?.type!==`SpreadElement`&&!e.typeArguments?t:void 0}function Lt(e){return e.callee.type===`MemberExpression`&&!e.callee.optional&&S(e.callee)===`pipe`&&!e.typeArguments&&!Ft(e)}function Rt(e,t,n){return(A(e.callee,n,[`pipe`])||A(e.callee,n,[`Function`,`pipe`]))&&H(t,e.callee)}function zt(e,t,n){return Dt(U(e,t,n))?!0:e.type===`CallExpression`&&St.has(U(e.callee,t,n)??``)}function Bt(e,t,n){if(Tt.test(U(e,t,n)??``)||i.isNotUndefined(Kt(e,t,n)))return!0;if(e.type!==`CallExpression`)return!1;let r=U(e.callee,t,n);return i.isNotUndefined(r)?Tt.test(r)||Dt(r):e.callee.type===`MemberExpression`&&Ct.has(S(e.callee)??``)&&Bt(e.callee.object,t,n)}function Vt(e,t,n){let[r,a]=e.arguments;if(!(i.isUndefined(r)||i.isUndefined(a)||r.type===`SpreadElement`||e.typeArguments||Ft(e)||!Bt(r,t,n)&&!zt(a,t,n)))return[r,e.arguments.slice(1)]}function Ht(e,t,n,r,i,a){let o=qt(e,i,a);return{head:o.head,steps:[...o.steps,t],violation:o.violation??n,reordersEffects:o.reordersEffects||r}}function Ut(e,t,n){let r=It(e);if(i.isUndefined(r))return;let a=U(e.callee,t,n);if(Dt(a)){let i=Et(a);return Ht(r,{text:t.sourceCode.getText(e.callee),wrapper:i},i?void 0:{kind:`modifierCall`,name:a},!1,t,n)}let o=e.callee.type===`CallExpression`?U(e.callee.callee,t,n):void 0;if(!i.isUndefined(o)&&St.has(o))return Ht(r,{text:t.sourceCode.getText(e.callee),wrapper:!1},{kind:`dataLastCall`,name:o},!W(e.callee,t,n)&&!W(r,t,n),t,n)}function Wt(e,t,n){let a=Rt(e,t,n),o=a?Vt(e,t,n):Lt(e)?[e.callee.object,e.arguments]:void 0;if(i.isUndefined(o))return;let[c,u]=o,d=r.map(u,e=>U(e,t,n)),f=s.pipe(d,r.findFirst(Et),l.getOrUndefined),p=i.isNotUndefined(f)&&r.some(u.slice(d.indexOf(f)+1),e=>!W(e,t,n));return Gt(c,r.map(u,(e,n)=>({text:t.sourceCode.getText(e),wrapper:Et(d[n])})),a?{kind:`functionPipe`}:i.isUndefined(f)?void 0:{kind:`wrapperPipe`,name:f},p,t,n)}function Gt(e,t,n,r,i,a){let o=qt(e,i,a);return{head:o.head,steps:[...o.steps,...t],violation:o.violation??n,reordersEffects:o.reordersEffects||r}}function Kt(e,t,n){return e.type===`CallExpression`?Ut(e,t,n)??Wt(e,t,n):void 0}function qt(e,t,n){return Kt(e,t,n)??{head:e,steps:[],violation:void 0,reordersEffects:!1}}function Jt(e,t,n){let r=e.parent;return r.type===`MemberExpression`&&r.object===e&&r.parent.type===`CallExpression`?r.parent.callee===r&&Lt(r.parent):r.type===`CallExpression`&&M(r,0)===e&&(Rt(r,t,n)||!Lt(r))&&i.isNotUndefined(Kt(r,t,n))}function Yt(e,t,n){return r.isReadonlyArrayNonEmpty(t)?`${e===`\0`&&!wt.has(n.type)?`(\0)`:e}.pipe(${r.join(t,`, `)})`:e}function Xt(e,t){let n=`\0`,r=[];for(let i of t)if(i.wrapper){let t=Yt(n,r,e),a=t===`\0`&&e.type===`SequenceExpression`?`(${t})`:t;n=`${i.text}(${a})`,r=[]}else r.push(i.text);return Yt(n,r,e)}const Zt=b({...x(`suggestion`,"Apply Schema modifiers with `.pipe(...)` and call Schema wrappers directly.",{modifierCall:"Apply Schema.{{name}} with `.pipe(...)` instead of calling it.",dataLastCall:"Apply Schema.{{name}}(...) with `.pipe(...)` instead of calling it on the schema.",functionPipe:"Call `.pipe(...)` on the schema instead of passing it to `pipe(...)`.",wrapperPipe:`Call Schema.{{name}}(...) directly instead of piping into it.`},`https://github.com/2digits-agency/configs/blob/main/docs/adr/0001-schema-modifiers-pipe-wrappers-call.md`),fixable:`code`},(e,t)=>({CallExpression(n){let o=t();if(!o.hasEffectImport)return;let s=Kt(n,e,o);if(i.isUndefined(s?.violation)||Jt(n,e,o))return;let{head:c}=s;if(l.exists(r.head(s.steps),({wrapper:e})=>!e)&&Pt(c,e,o))return;let u=r.some(e.sourceCode.getCommentsInside(n),e=>!_e(c,e)),[d,f=``]=a.split(Xt(c,s.steps),`\0`);e.report({node:n,messageId:s.violation.kind,data:{name:s.violation.name??``},fix:u||s.reordersEffects?void 0:e=>[e.replaceTextRange([n.range[0],c.range[0]],d),e.replaceTextRange([c.range[1],n.range[1]],f)]})}}));function Qt(e){return l.getOrUndefined(r.findFirst(e.arguments,e=>e.type===`ObjectExpression`))}function $t(e,t){let n=e.parent;if(n.type!==`Property`||N(n)!==t)return;let r=n.parent,i=r.parent;return r.type===`ObjectExpression`&&i?.type===`CallExpression`?i:void 0}function en(e,t){let n=z(e);return i.isUndefined(n)?void 0:D(n.callee,t)}function tn(e){let t=e.parent,n=t.type===`Property`&&t.value===e?t.parent:e,r=n.parent;return(r?.type===`CallExpression`||r?.type===`NewExpression`)&&r.arguments.includes(n)?r:void 0}function nn(e,t){let n=tn(e);if(i.isUndefined(n))return!1;let r=n.callee;for(;r.type===`CallExpression`;)r=r.callee;return i.isUndefined(D(r,t))}const rn=/* @__PURE__ */ new Set([`catch`,`finally`,`then`]);function an(e){let t=C(e.callee);return i.isNotUndefined(t)&&r.join(t,`.`)===`Promise`}function on(e){let t=C(e.callee);return i.isNotUndefined(t)&&r.join(t,`.`)===`fetch`||t?.[0]===`Promise`&&t[1]!==`withResolvers`||rn.has(t?.at(-1)??``)||j(e.callee)&&e.callee.async}const sn=c.type().pipe(c.discriminators(`type`)({CallExpression:on,NewExpression:an}),c.orElse(s.constFalse));function cn(e){return sn(F(e))}function G(e){if(e.body)return e.body.type===`BlockStatement`?(e.body.body.length===1?r.head(e.body.body):l.none()).pipe(l.flatMapNullishOr(e=>e.type===`ReturnStatement`?e.argument:void 0),l.map(F),l.getOrUndefined):F(e.body)}function ln(e){let t=e?.type===`ObjectExpression`?P(e,`try`)?.value:e;return j(t)?t:void 0}function un(e){let t=F(e);return V(t,`*`)?!0:t.type===`ArrayExpression`&&(r.isReadonlyArrayEmpty(t.elements)||r.some(t.elements,e=>i.isNotNull(e)&&V(e,`*`)))}const dn=b(x(`problem`,`Disallow credentialed CORS with wildcard origins because browsers reject that combination.`,{wildcard:`Credentialed CORS cannot use a wildcard origin. Set allowedOrigins to explicit trusted origins or disable credentials.`},`https://github.com/Effect-TS/tsgo/issues/400`),(e,t)=>({CallExpression(n){let r=t();if(!O(n.callee,r,`HttpMiddleware`,`cors`)&&!O(n.callee,r,`HttpRouter`,`cors`)&&!O(n.callee,r,`HttpApiBuilder`,`middlewareCors`))return;let a=Qt(n);if(i.isUndefined(a)||!V(P(a,`credentials`)?.value??a,!0))return;let o=P(a,`allowedOrigins`);(i.isUndefined(o)||un(o.value))&&e.report({node:n,messageId:`wildcard`})}}));function fn(e){return e.type===`AssignmentPattern`||e.type===`RestElement`||e.optional===!0}const pn=b(x(`problem`,`Disallow numeric dual arity with optional or rest parameters because dispatch becomes ambiguous.`,{unsafeArity:`Function.dual with numeric arity misdispatches an implementation with optional/default/rest parameters. Use predicate dispatch.`},`https://github.com/Effect-TS/tsgo/issues/401`),(e,t)=>({CallExpression(n){let a=M(n,0),o=M(n,1);!i.isUndefined(o)&&O(n.callee,t(),`Function`,`dual`)&&a?.type===`Literal`&&i.isNumber(a.value)&&j(o)&&r.some(o.params,fn)&&e.report({node:a,messageId:`unsafeArity`})}})),mn=b(x(`problem`,`Require Effect.tryPromise so Promise rejections enter the typed error channel.`,{tryPromise:`Use Effect.tryPromise instead of Effect.promise so rejections are typed failures.`}),(e,t)=>({CallExpression(n){O(n.callee,t(),`Effect`,`promise`)&&e.report({node:n.callee,messageId:`tryPromise`})}}));function hn(e,t){if(k(e.callee,t,`Effect`,[`promise`,`tryPromise`]))return ln(M(e,0))}const gn=b(x(`problem`,`Ensure Effect Promise thunks start fresh asynchronous work rather than reusing an already-started Promise.`,{prestarted:`This thunk returns an already-started Promise. Start the asynchronous work inside the thunk so retries and repeats run it again.`},`https://github.com/Effect-TS/tsgo/issues/475`),(e,t)=>{let n=/* @__PURE__ */ new Set;return{before(){n=/* @__PURE__ */ new Set},VariableDeclarator(e){e.id.type===`Identifier`&&e.init&&cn(e.init)&&n.add(e.id.name)},CallExpression(r){let a=hn(r,t()),o=i.isUndefined(a)?void 0:G(a);o?.type===`Identifier`&&n.has(o.name)&&e.report({node:o,messageId:`prestarted`})}}}),_n=b(x(`problem`,`Disallow async thunks in Effect.try because rejected Promises bypass its catch mapper.`,{asyncTry:`Effect.try does not await Promises. Use Effect.tryPromise so rejection enters the typed error channel.`},`https://github.com/Effect-TS/tsgo/issues/657`),(e,t)=>({CallExpression(n){if(!O(n.callee,t(),`Effect`,`try`))return;let r=M(n,0),a=i.isNotUndefined(r)&&j(r)?r:void 0;if(i.isUndefined(a)&&r?.type===`ObjectExpression`){let e=P(r,`try`)?.value;i.isNotUndefined(e)&&j(e)&&(a=e)}let o=i.isUndefined(a)?void 0:G(a);i.isNotUndefined(a)&&(a.async||i.isNotUndefined(o)&&cn(o))&&e.report({node:a,messageId:`asyncTry`})}})),vn=b(x(`problem`,`Disallow discarded Effect.runPromise results that can become unhandled rejections.`,{discarded:`The Promise returned by Effect.runPromise is discarded. Await/return/handle it, or use Effect.runFork for fire-and-forget work.`},`https://github.com/Effect-TS/tsgo/issues/643`),(e,t)=>({CallExpression(n){let r=t(),i=O(n.callee,r,`Effect`,`runPromise`),a=n.callee.type===`CallExpression`&&O(n.callee.callee,r,`Effect`,`runPromiseWith`);(i||a)&&be(n)&&e.report({node:n,messageId:`discarded`})}})),yn=/* @__PURE__ */ new Set([`mapElements`,`mapFields`,`mapMembers`]);function bn(e,t){let n=F(e);if(n.type===`CallExpression`&&n.callee.type===`MemberExpression`&&S(n.callee)===t)return n}const xn=b(x(`problem`,`Disallow schema mapping that silently drops checks attached to the receiver.`,{discarded:`{{method}} creates a new schema and drops the preceding check. Re-attach the check after mapping or explicitly preserve it.`},`https://github.com/Effect-TS/tsgo/issues/435`),(e,t)=>({CallExpression(n){if(!t().hasEffectImport||n.callee.type!==`MemberExpression`)return;let a=S(n.callee);i.isUndefined(a)||!yn.has(a)||i.isUndefined(bn(n.callee.object,`check`))||r.findFirst(n.arguments,e=>e.type===`ObjectExpression`).pipe(l.flatMapNullishOr(e=>P(e,`unsafePreserveChecks`)),l.exists(e=>V(e.value,!0)))||e.report({node:n,messageId:`discarded`,data:{method:a}})}})),Sn={Array:`Arr`,Boolean:`Bool`,Equal:`Eq`,Function:`Fn`,Number:`Num`,Option:`Opt`,Predicate:`P`,Record:`R`,String:`Str`},Cn=/^\p{Lu}[^_]*$/u;function wn(e){return Cn.test(e)}function Tn(e){return e===`@effect/vitest`||a.startsWith(`@effect/vitest/`)(e)}function K(e,t){return e.importKind===`type`||t?.importKind===`type`}function En(e){return l.getOrElse(n.get(Sn,e),()=>e)}function Dn(e,t){if(e===`effect`||e===`alchemy`||/^@effect\/[^/]+$/u.test(e)&&!Tn(e))return`${e}/${t}`}function On(e){if(Tn(e)||!(a.startsWith(`effect/`)(e)||a.startsWith(`alchemy/`)(e)||/^@effect\/[^/]+\//u.test(e)))return;let t=r.lastNonEmpty(a.split(e,`/`));return wn(t)?t:void 0}function kn(e,t,n){let a=t.specifiers;if(r.isReadonlyArrayNonEmpty(e.sourceCode.getCommentsInside(t))||r.isReadonlyArrayNonEmpty(t.attributes)||!r.every(a,e=>e.type===`ImportSpecifier`))return;let[o,s]=r.partition(a,n=>{let r=v(n.imported),a=wn(r)&&!K(t,n)?Dn(t.source.value,r):void 0;return i.isUndefined(a)?f.fail(e.sourceCode.getText(n)):f.succeed(`import * as ${n.local.name} from '${a}';`)}),c=r.isReadonlyArrayNonEmpty(s)?r.prepend(o,`import { ${r.join(s,`, `)} } from ${e.sourceCode.getText(t.source)};`):o;return[n.replaceText(t,r.join(c,`
2
- `))]}function An(e,t,n){let a=On(t.source.value);if(i.isUndefined(a)||r.isReadonlyArrayNonEmpty(t.attributes)||r.isReadonlyArrayNonEmpty(e.sourceCode.getCommentsInside(t)))return;let o=En(a),s=e.sourceCode.getDeclaredVariables(t),c=l.getOrUndefined(r.findFirst(s,e=>e.name===o));if(r.some(e.sourceCode.scopeManager.scopes,e=>r.some(e.variables,e=>e.name===o&&e!==c)||r.some(e.references,e=>e.identifier.name===o&&e.resolved!==c)))return;let u=[],d=[];for(let r of t.specifiers){if(r.type===`ImportDefaultSpecifier`)return;if(r.type===`ImportSpecifier`&&K(t,r)){if(r.local.name===o)return;d.push(e.sourceCode.getText(r));continue}let a=jn(r,s,o,n);if(i.isUndefined(a))return;u.push(...a)}let f=e.sourceCode.getText(t.source),p=`import * as ${o} from ${f};${r.isReadonlyArrayEmpty(d)?``:`\nimport { ${r.join(d,`, `)} } from ${f};`}`;return[n.replaceText(t,p),...u]}function jn(e,t,n,a){let o=l.getOrUndefined(r.findFirst(t,t=>t.name===e.local.name));if(!i.isUndefined(o)){if(e.type===`ImportNamespaceSpecifier`)return Mn(o,n,!1,a);if(e.imported.type===`Identifier`)return Mn(o,`${n}.${e.imported.name}`,!0,a)}}function Mn(e,t,n,r){let i=[],o=/* @__PURE__ */ new Set;for(let s of e.references){let e=s.identifier,c=p.get(e.range,0);if(o.has(c))continue;o.add(c);let l=e.parent;if(s.isWrite()||l.type===`ExportSpecifier`||a.startsWith(`JSX`)(l.type))return;let u=l.type===`Property`&&l.shorthand?`${e.name}: ${t}`:t;n&&(l.type===`CallExpression`&&l.callee===e||l.type===`TaggedTemplateExpression`&&l.tag===e)&&(u=`(0, ${t})`),i.push(r.replaceText(e,u))}return i}const Nn=y({...x(`suggestion`,`Import Effect and Alchemy module namespaces from their submodule entrypoints instead of root barrels.`,{barrelImport:'Import this module as `import * as {{alias}} from "{{source}}"` instead of from the root barrel.'},`https://github.com/Effect-TS/language-service/blob/main/packages/language-service/src/diagnostics/importFromBarrel.ts`),fixable:`code`},e=>({ImportDeclaration(t){for(let n of t.specifiers){if(n.type!==`ImportSpecifier`||K(t,n))continue;let r=v(n.imported),i=wn(r)?Dn(t.source.value,r):void 0;i!==void 0&&e.report({node:n,messageId:`barrelImport`,data:{alias:En(r),source:i},fix:n=>kn(e,t,n)})}}})),Pn=[`log`,`logDebug`,`logError`,`logFatal`,`logInfo`,`logTrace`,`logWarning`],Fn=[`debug`,`error`,`info`,`log`,`trace`,`warn`],In=[`as`,`asSome`,`asVoid`];function Ln(e,t){let n=F(e);if(n.type!==`CallExpression`)return;let i=F(n.callee);if(i.type===`CallExpression`&&A(i.callee,t,[`Effect`,`logWithLevel`]))return`Effect.logWithLevel`;if(k(i,t,`Effect`,Pn)||k(i,t,`Console`,Fn))return r.join(D(i,t)??[],`.`)}function Rn(e,t){if(i.isUndefined(e))return;let n=F(e);return n.type===`CallExpression`&&n.arguments.length===1&&A(n.callee,t,[`Effect`,`as`])?`as`:k(n,t,`Effect`,[`asSome`,`asVoid`])?D(n,t)?.[1]:void 0}function zn(e,t){return A(e,t,[`pipe`])||A(e,t,[`Function`,`pipe`])}function Bn(e,t){let n=F(e.callee);if(n.type===`MemberExpression`&&S(n)===`pipe`){let r=M(e,0),a=Ln(n.object,t),o=Rn(r,t);return i.isUndefined(r)||i.isUndefined(a)||i.isUndefined(o)?void 0:{logger:a,method:o,node:r}}if(zn(n,t)){let n=M(e,0),r=i.isUndefined(n)?void 0:Ln(n,t),a=M(e,1),o=Rn(a,t);return i.isUndefined(a)||i.isUndefined(r)||i.isUndefined(o)?void 0:{logger:r,method:o,node:a}}let r=k(n,t,`Effect`,In)?D(n,t)?.[1]:void 0,a=M(e,0);if(i.isUndefined(r)||i.isUndefined(a)||r===`as`&&e.arguments.length!==2)return;let o=Ln(a,t);return i.isUndefined(o)?void 0:{logger:o,method:r,node:e}}const Vn=b(x(`suggestion`,`Disallow Effect.as, Effect.asSome and Effect.asVoid on log effects.`,{asOnLog:"Do not swap the result of {{logger}} with Effect.{{method}}. Use Effect.gen: `yield*` the log, then return the value.",asVoidOnLog:`{{logger}} already succeeds with void; remove Effect.asVoid.`}),(e,t)=>({CallExpression(n){let r=Bn(n,t());i.isUndefined(r)||e.report({node:r.node,messageId:r.method===`asVoid`?`asVoidOnLog`:`asOnLog`,data:{logger:r.logger,method:r.method}})}})),Hn=b({...x(`suggestion`,`Prefer Effect.never to an empty Effect.callback registration.`,{emptyCallback:`An empty Effect.callback registration is Effect.never. Use the explicit primitive.`},`https://github.com/Effect-TS/tsgo/issues/636`),fixable:`code`},(e,t)=>({CallExpression(n){if(!O(n.callee,t(),`Effect`,`callback`)&&!O(n.callee,t(),`Effect`,`async`))return;let a=M(n,0);i.isNotUndefined(a)&&j(a)&&a.body?.type===`BlockStatement`&&r.isReadonlyArrayEmpty(a.body.body)&&e.report({node:n,messageId:`emptyCallback`,fix(t){if(!H(e,n.callee)||n.arguments.length!==1||a.async||a.generator||r.some(a.params,e=>e.type!==`Identifier`)||r.isReadonlyArrayNonEmpty(e.sourceCode.getCommentsInside(n)))return;let i=tt(e,n,`effect/Effect`,`Effect`,t);return[...i.fixes,t.replaceText(n,`${i.name}.never`)]}})}})),Un=b(x(`problem`,`Disallow Schema.Struct({}), which accepts every non-null object-like value.`,{emptyStruct:`Schema.Struct({}) does not validate an exact empty object. Define the intended fields explicitly.`},`https://github.com/Effect-TS/tsgo/issues/403`),(e,t)=>({CallExpression(n){let i=M(n,0);O(n.callee,t(),`Schema`,`Struct`)&&i?.type===`ObjectExpression`&&r.isReadonlyArrayEmpty(i.properties)&&e.report({node:n,messageId:`emptyStruct`})}}));function Wn(e,t){let n=F(e),a=/* @__PURE__ */ new Set;for(;n.type===`Identifier`;){let e=w(t,n,n.name),o=T(e),s=o?.node;if(i.isUndefined(e)||a.has(e)||s?.type!==`VariableDeclarator`||s.id.type!==`Identifier`||!ce(o?.parent)||!s.init||r.some(e.references,e=>e.isWrite()&&!e.init))return;a.add(e),n=F(s.init)}return n}function Gn(e){if(e.arguments.length===2)return M(e,0);let t=e.parent;if(e.arguments.length===1&&t.type===`CallExpression`&&M(t,0)===e&&t.callee.type===`MemberExpression`&&S(t.callee)===`pipe`)return t.callee.object}const Kn=b(x(`problem`,`Disallow obsolete lazy callbacks passed to the now-eager Config.withDefault API.`,{functionDefault:`Config.withDefault takes an eager value. This callback becomes the configured value; pass the returned value directly.`},`https://github.com/Effect-TS/tsgo/issues/408`),(e,t)=>({CallExpression(n){if(!O(n.callee,t(),`Config`,`withDefault`)||!H(e,n.callee))return;let a=M(n,n.arguments.length-1),o=Gn(n),s=i.isUndefined(o)?void 0:Wn(o,e);s?.type===`CallExpression`&&O(s.callee,t(),`Config`,`succeed`)&&H(e,s.callee)&&j(M(s,0))||j(a)&&r.isReadonlyArrayEmpty(a.params)&&e.report({node:a,messageId:`functionDefault`})}})),qn=/* @__PURE__ */ new Set([`delete`,`get`,`has`,`set`]);function Jn(e,t){return e.type===`CallExpression`&&O(e.callee,t,`Hash`,`hash`)}const Yn=b(x(`problem`,`Disallow using Hash.hash output as collision-free identity.`,{hashIdentity:`Hash.hash is a bucketing hint, not a unique identity. Use HashMap/Equal.equals or a real identifier instead.`},`https://github.com/Effect-TS/tsgo/issues/482`),(e,t)=>{let n=/* @__PURE__ */ new Set;function r(e){return Jn(e,t())||e.type===`Identifier`&&n.has(e.name)}return{before(){n=/* @__PURE__ */ new Set},VariableDeclarator(e){e.id.type===`Identifier`&&e.init&&Jn(e.init,t())&&n.add(e.id.name)},CallExpression(t){if(t.callee.type!==`MemberExpression`||!qn.has(C(t.callee)?.at(-1)??``))return;let n=M(t,0);i.isNotUndefined(n)&&r(n)&&e.report({node:n,messageId:`hashIdentity`})},BinaryExpression(t){ye(t.operator)&&r(t.left)&&r(t.right)&&e.report({node:t,messageId:`hashIdentity`})},MemberExpression(t){t.computed&&r(t.property)&&e.report({node:t.property,messageId:`hashIdentity`})}}}),Xn=/* @__PURE__ */ new Set(/* @__PURE__ */ `asserts.decodeEffect.decodeExit.decodeOption.decodePromise.decodeResult.decodeSync.decodeUnknownEffect.decodeUnknownExit.decodeUnknownOption.decodeUnknownPromise.decodeUnknownResult.decodeUnknownSync.encodeEffect.encodeExit.encodeOption.encodePromise.encodeResult.encodeSync.encodeUnknownEffect.encodeUnknownExit.encodeUnknownOption.encodeUnknownPromise.encodeUnknownResult.encodeUnknownSync.is`.split(`.`)),Zn=/* @__PURE__ */ new Set([`global`,`module`]),Qn=/* @__PURE__ */ new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`]),$n=/* @__PURE__ */ new Set([`AssignmentExpression`,`AwaitExpression`,`ImportExpression`,`TaggedTemplateExpression`,`UpdateExpression`,`YieldExpression`]),er=/* @__PURE__ */ new Set([`ParenthesizedExpression`,`TSAsExpression`,`TSNonNullExpression`]);function tr(e,t,n){let a=D(e,t),o=a?.length===2&&a[0]===`Schema`?a[1]:void 0;if(i.isUndefined(o)||!Xn.has(o))return;let s=l.flatMapNullishOr(r.head(C(e)??[]),t=>w(n,e,t));return l.exists(s,({defs:e})=>r.every(e,e=>e.type===`ImportBinding`))?o:void 0}function nr(e){let t=e.parent;for(;t;){if(Qn.has(t.type))return!0;t=t.parent}return!1}function rr(e){let t=e,n=e.parent;for(;er.has(n.type)&&i.isNotNull(n.parent);)t=n,n=n.parent;return n.type===`CallExpression`&&n.callee===t}function ir(e){let t=e,n=e.parent;for(;n?.type===`MemberExpression`&&n.object===t;)t=n,n=n.parent;return t!==e&&(n?.type===`AssignmentExpression`&&n.left===t||n?.type===`UpdateExpression`&&n.argument===t||n?.type===`UnaryExpression`&&n.operator===`delete`&&n.argument===t)}function ar(e){return r.every(e.references,e=>(!e.isWrite()||e.init)&&!ir(e.identifier))}function or(e,t,n,r){let a=w(r,e,t);return i.isUndefined(a)||_e(n,a.scope.block)?!0:Zn.has(a.scope.type)&&ar(a)}function sr(e){let t=e.parent;return t?.type===`MemberExpression`&&t.property===e&&!t.computed||t?.type===`Property`&&t.key===e&&!t.computed&&!t.shorthand}function cr(e,t){if(e===t)return!1;let n=e.parent;for(;n!==t&&i.isNotNull(n);){if(Qn.has(n.type))return!0;n=n.parent}return!1}function lr(e,t,n){return cr(e,t)?!1:e.type===`CallExpression`||e.type===`NewExpression`?i.isUndefined(D(e.callee,n)):$n.has(e.type)}function ur(e,t,n){return!I(e,r=>r.type===`ThisExpression`||r.type===`Super`||r.type===`MetaProperty`&&r.meta.name===`new`||lr(r,e,t)||r.type===`Identifier`&&!sr(r)&&!or(r,r.name,e,n))}const dr=b(x(`problem`,`Disallow compiling Schema decoders, encoders, and guards inside function bodies.`,{inlineSchema:`Hoist Schema.{{method}}(...) to module scope: both the inline schema and the compiled function are rebuilt on every call. Move the compiled function to a module-level const.`,inlineCompile:`Hoist Schema.{{method}}(...) to module scope: the compiled function is rebuilt on every call. Move it to a module-level const.`},`https://github.com/pingdotgg/t3code/blob/main/oxlint-plugin-t3code/rules/no-inline-schema-compile.ts`),(e,t)=>({CallExpression(n){let a=t();if(!a.hasEffectImport)return;let o=tr(n.callee,a,e),[s]=n.arguments;if(i.isUndefined(o)||i.isUndefined(s)||s.type===`SpreadElement`||r.some(n.arguments,e=>e.type===`SpreadElement`)||!rr(n)||!nr(n))return;let c=F(s),u=c.type===`CallExpression`&&l.contains(r.head(D(c.callee,a)??[]),`Schema`);(u||c.type===`Identifier`||c.type===`MemberExpression`)&&r.every(n.arguments,t=>ur(t,a,e))&&e.report({node:n.callee,messageId:u?`inlineSchema`:`inlineCompile`,data:{method:o}})}})),fr=/* @__PURE__ */ new Set([`catch`,`catchIf`,`catchTag`,`orElseSucceed`,`catchAll`,`catchAllCause`,`catchSome`,`catchSomeCause`,`orElse`,`orElseFail`]),pr=/* @__PURE__ */ new Set([`log`,`logDebug`,`logError`,`logInfo`,`logTrace`,`logWarning`]);function mr(e,t){let n=e.parent;for(;n;){if(j(n)){let e=z(n);if(e?.arguments.at(-1)===n){let n=D(e.callee,t),r=n?.[1];if(i.isNotUndefined(r)&&n?.[0]===`Effect`&&fr.has(r))return{method:r}}}n=n.parent}}const hr=b(x(`suggestion`,`Keep logging separate from Effect recovery handlers.`,{logging:`Move {{logger}} out of Effect.{{catchMethod}} and use Effect.tapError before recovery.`}),(e,t)=>({CallExpression(n){let a=t(),o=D(n.callee,a),s=i.isNotUndefined(o?.[1])&&o[0]===`Effect`&&pr.has(o[1])?r.join(o,`.`):void 0;if(i.isUndefined(s))return;let c=mr(n,a);i.isNotUndefined(c)&&e.report({node:n,messageId:`logging`,data:{logger:s,catchMethod:c.method}})}})),gr=c.type().pipe(c.when({type:`MemberExpression`,computed:!1,object:{type:`Identifier`,name:`Effect`},property:{type:`Identifier`,name:c.is(`catch`,`catchAll`,`catchIf`)}},s.constTrue),c.orElse(s.constFalse)),_r=c.type().pipe(c.when({type:`MemberExpression`,computed:!1,object:{type:`Identifier`,name:`Match`},property:{type:`Identifier`,name:c.is(`when`,`not`)}},s.constTrue),c.orElse(s.constFalse)),vr=/* @__PURE__ */ new Set([`_tag`]);function q(e,t=vr){if(e.type!==`MemberExpression`)return!1;let n=S(e);return n!==void 0&&t.has(n)}function yr(e,t=vr){if(ye(e.operator)){if(q(e.left,t)&&B(e.right))return e.left;if(q(e.right,t)&&B(e.left))return e.right}}function br(e){let t=R(e),n=i.isUndefined(t)?void 0:z(t);return i.isNotUndefined(n)&&gr(n.callee)}function xr(e){return e.object.type===`MemberExpression`&&S(e.object)===`reason`}function Sr(e){let t=e.parent;return t.type===`CallExpression`&&t.arguments.includes(e)&&_r(t.callee)}const Cr=y(x(`problem`,"Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler.",{tag:`Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.`,reason:"Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler."},`https://github.com/dmmulroy/anti-slop/blob/main/src/effect/rules/no-manual-effect-error-tag.ts`),e=>({BinaryExpression(t){let n=yr(t);n!==void 0&&br(t)&&e.report({node:t,messageId:xr(n)?`reason`:`tag`})},SwitchStatement(t){q(t.discriminant)&&br(t)&&e.report({node:t,messageId:xr(t.discriminant)?`reason`:`tag`})}})),wr=u.is(u.Struct({discriminants:u.Array(u.String).pipe(u.optionalKey)})),Tr=y({...x(`problem`,"Use Effect Match or Predicate helpers instead of manually branching on `_tag` or another configured discriminant.",{manualComparison:`Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.`,manualSwitch:"Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`.",manualDiscriminantComparison:"Use Match.discriminator('{{discriminant}}')/Match.discriminators('{{discriminant}}') or a Match.when pattern instead of comparing `{{discriminant}}` manually.",manualDiscriminantSwitch:"Use Match.type or Match.value with Match.discriminatorsExhaustive('{{discriminant}}') instead of switching on `{{discriminant}}`."},`https://github.com/dmmulroy/anti-slop/blob/main/src/effect/rules/no-manual-tag-comparison.ts`),schema:[{type:`object`,properties:{discriminants:{type:`array`,items:{type:`string`,minLength:1},uniqueItems:!0,description:"Discriminant properties to check in addition to `_tag`. Replaces the default list."}},additionalProperties:!1}],defaultOptions:[{discriminants:[`kind`,`status`]}]},e=>{let t=/* @__PURE__ */ new Set;function n(t,n,r){let i=q(n);i&&br(t)||e.report({node:t,messageId:i?`manual${r}`:`manualDiscriminant${r}`,data:{discriminant:S(n)??``}})}return{before(){let[n]=e.options;t=/* @__PURE__ */ new Set([`_tag`,...wr(n)?n.discriminants??[]:[]])},BinaryExpression(e){let r=yr(e,t);i.isNotUndefined(r)&&n(e,r,`Comparison`)},SwitchStatement(e){q(e.discriminant,t)&&n(e,e.discriminant,`Switch`)}}}),Er=y(x(`problem`,"Construct tagged values with their existing Effect constructor instead of writing `_tag` manually.",{manualConstruction:"Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object."},`https://github.com/dmmulroy/anti-slop/blob/main/src/effect/rules/no-manual-tagged-construction.ts`),e=>({ObjectExpression(t){if(Sr(t))return;let n=l.getOrUndefined(r.findFirst(t.properties,e=>e.type===`Property`&&N(e)===`_tag`&&B(e.value)));i.isNotUndefined(n)&&e.report({node:n,messageId:`manualConstruction`})}})),Dr=/* @__PURE__ */ new Map([[`Effect.cachedInvalidateWithTTL`,`last`],[`Effect.cachedWithTTL`,`last`],[`Effect.delay`,`last`],[`Effect.sleep`,`last`],[`Effect.timeout`,`last`],[`Effect.timeoutOption`,`last`],[`Effect.timeoutOrElse`,`options.duration`],[`Schedule.duration`,`last`],[`Schedule.during`,`last`],[`Schedule.exponential`,`first`],[`Schedule.fibonacci`,`last`],[`Schedule.fixed`,`last`],[`Schedule.spaced`,`last`],[`Schedule.windowed`,`last`],[`Stream.debounce`,`last`],[`Stream.groupedWithin`,`last`],[`Stream.throttle`,`options.duration`],[`Stream.timeout`,`last`],[`TestClock.adjust`,`last`]]),Or={first:e=>M(e,0),last:e=>M(e,e.arguments.length-1),"options.duration":e=>{let t=M(e,e.arguments.length-1);return t?.type===`ObjectExpression`?P(t,`duration`)?.value:void 0}};function kr(e,t,n){let a=D(e.callee,n),o=i.isUndefined(a)?void 0:Dr.get(r.join(a,`.`));return i.isNotUndefined(o)&&H(t,e.callee)?Or[o](e):void 0}const Ar=c.type().pipe(c.withReturnType(),c.when(`*`,()=>h.multiply),c.when(`+`,()=>h.sum),c.when(`-`,()=>h.subtract),c.when(`/`,()=>h.divideUnsafe),c.when(`%`,()=>h.remainder),c.when(`**`,()=>(e,t)=>e**t),c.orElse(s.constUndefined));function J(e){let t=F(e);if(t.type===`Literal`)return i.isNumber(t.value)?t.value:void 0;if(t.type===`UnaryExpression`&&(t.operator===`-`||t.operator===`+`)){let e=J(t.argument);return i.isUndefined(e)||t.operator===`+`?e:-e}if(t.type!==`BinaryExpression`||t.left.type===`PrivateIdentifier`)return;let n=J(t.left),r=J(t.right);if(!(i.isUndefined(n)||i.isUndefined(r)))return Ar(t.operator)?.(n,r)}function jr(e){let t=F(e);if(t.type===`Literal`)return i.isNumber(t.value)?[t.value]:void 0;if(t.type!==`BinaryExpression`||t.operator!==`*`)return;let n=jr(t.left),a=jr(t.right);return i.isUndefined(n)||i.isUndefined(a)?void 0:r.appendAll(n,a)}const Mr=/* @__PURE__ */ new Set([6e4,36e5,864e5]),Nr=/* @__PURE__ */ new Set([60,3600,86400]),Pr=/* @__PURE__ */ new Set([7,24,60,1e3,3600,86400]);function Fr(e){let t=jr(e);if(!(i.isUndefined(t)||t.length<2)&&(r.some(t,e=>Mr.has(e))||r.some(t,e=>Nr.has(e))&&r.filter(t,e=>Pr.has(e)).length>=2))return{millis:r.contains(t,1e3)||r.some(t,e=>e%6e4==0)}}const Ir=s.flow(a.split(/[_$]+|(?<=[\da-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/u),r.filter(a.isNonEmpty),r.map(a.toLowerCase)),Lr=/* @__PURE__ */ new Set([`millis`,`milliseconds`,`ms`]),Rr=/* @__PURE__ */ new Set([`at`,`created`,`deadline`,`end`,`ended`,`epoch`,`last`,`now`,`since`,`start`,`started`,`timestamp`,`until`,`updated`]);function zr(e){let t=Ir(e);if(Lr.has(t.at(-1)??``))return r.some(t,e=>Rr.has(e))?`instant`:`duration`}const Br={weeks:m.weeks,days:m.days,hours:m.hours,minutes:m.minutes,seconds:m.seconds,millis:m.millis},Vr=[[`weeks`,m.toWeeks],[`days`,m.toDays],[`hours`,m.toHours],[`minutes`,m.toMinutes],[`seconds`,m.toSeconds],[`millis`,m.toMillis]];function Hr(e){return!Number.isSafeInteger(e)||Math.abs(e)<1e4?String(e):a.replaceAll(/\B(?=(?:\d{3})+$)/gu,`_`)(String(e))}function Ur(e,t){let n=Br[t](e);return m.isZero(n)?`Duration.zero`:r.findFirst(Vr,([,e])=>Number.isSafeInteger(e(n))).pipe(l.match({onNone:()=>`Duration.millis(${n.pipe(m.toMillis,Hr)})`,onSome:([e,t])=>`Duration.${e}(${Hr(t(n))})`}))}const Wr=/* @__PURE__ */ new Set([`*`,`+`,`-`,`/`]),Gr={"!==":`Duration.equals`,"*":`Duration.times`,"+":`Duration.sum`,"-":`Duration.subtract`,"/":`Duration.divide`,"<":`Duration.isLessThan`,"<=":`Duration.isLessThanOrEqualTo`,"===":`Duration.equals`,">":`Duration.isGreaterThan`,">=":`Duration.isGreaterThanOrEqualTo`},Kr={"!==":`DateTime.Equivalence`,"+":`DateTime.addDuration`,"-":`DateTime.subtractDuration`,"<":`DateTime.isLessThan`,"<=":`DateTime.isLessThanOrEqualTo`,"===":`DateTime.Equivalence`,">":`DateTime.isGreaterThan`,">=":`DateTime.isGreaterThanOrEqualTo`},qr=`Duration.isPositive, Duration.isNegative or Duration.isZero`,Jr={"!==":`Duration.isZero`,"<":qr,"<=":qr,"===":`Duration.isZero`,">":qr,">=":qr},Yr=new Set(n.keys(Gr));function Xr(e){let t=F(e);return t.type===`TemplateLiteral`||t.type===`Literal`&&i.isString(t.value)?!0:t.type===`BinaryExpression`&&t.operator===`+`&&(Xr(t.left)||Xr(t.right))}function Zr(e){let t=F(e);return t.type===`Identifier`&&t.name===`undefined`||t.type===`Literal`&&!i.isNumber(t.value)}function Qr(e,t){let n=e.name.parent;if((n.type===`AssignmentPattern`?n.parent:n).type===`Property`)return!0;if(e.type!==`Parameter`)return!1;let r=R(e.name);return i.isNotUndefined(r)&&nn(r,t)}function $r(e,t){let n=t.left===`instant`,r=t.right===`instant`;return e===`+`?n===r?`duration`:`instant`:n&&!r&&e===`-`?`instant`:`duration`}function ei(e,t){let n=t.left===`instant`||t.right===`instant`;return t.right===`instant`&&e.operator===`-`?`DateTime.distance`:V(e.right,1e3)&&e.operator===`/`?n?`DateTime.toEpochSeconds`:`Duration.toSeconds`:(!n&&(V(e.left,0)||V(e.right,0))?Jr[e.operator]:void 0)??(n?Kr[e.operator]:void 0)??Gr[e.operator]??`Duration`}function ti(e){return e?.type===`BinaryExpression`&&e.left.type!==`PrivateIdentifier`}function ni(e){let t=e.parent;for(;t&&ue.has(t.type);)t=t.parent;return ti(t)?t:void 0}const ri=b(x(`suggestion`,`Disallow arithmetic and comparisons on millisecond numbers where Effect Duration or DateTime can do the math.`,{millisArithmetic:`{{operand}} is {{what}} in milliseconds. Keep it as a {{module}} and use {{suggestion}}; convert to milliseconds only where a non-Effect API needs them.`},`https://www.effect.website/docs/v4/api/effect/Duration`),(e,t)=>{function n(n){let r=D(n,t());if(r?.length!==2||!H(e,n))return;let i=`${r[0]}.${r[1]}`;return i===`Duration.toMillis`?`duration`:i===`DateTime.toEpochMillis`?`instant`:void 0}function r(n,r){let o=T(w(e,n,n.name));if(i.isNotUndefined(o)&&Qr(o,t()))return;let s=zr(n.name);if(i.isNotUndefined(s))return s;let c=o?.node;return c?.type===`VariableDeclarator`&&ce(c.parent)&&c.id===o?.name&&i.isNotNull(c.init)?a(c.init,r+1):void 0}function a(a,s=0){if(s>4)return;let c=F(a);if(c.type===`Identifier`)return r(c,s);if(c.type===`MemberExpression`){let e=c.object.type===`ThisExpression`?S(c):void 0;return i.isUndefined(e)?void 0:zr(e)}if(c.type===`CallExpression`)return n(c.callee);if(c.type===`YieldExpression`){let n=c.argument;return i.isNotNull(n)&&c.delegate&&A(n,t(),[`Clock`,`currentTimeMillis`])&&H(e,n)?`instant`:void 0}if(!ti(c)||!Wr.has(c.operator))return;let l=o(c,s);return i.isUndefined(l)?void 0:$r(c.operator,l)}function o(e,t){if(!Yr.has(e.operator)||e.operator===`+`&&(Xr(e.left)||Xr(e.right))||(e.operator===`===`||e.operator===`!==`)&&(Zr(e.left)||Zr(e.right)))return;let n=a(e.left,t),r=a(e.right,t);return i.isUndefined(n)&&i.isUndefined(r)?void 0:{left:n,right:r}}return{BinaryExpression(n){if(!t().hasEffectImport)return;let r=o(n,0),a=ni(n);if(i.isUndefined(r)||i.isNotUndefined(a)&&i.isNotUndefined(o(a,0)))return;let s=r.left===`instant`||r.right===`instant`;e.report({node:n,messageId:`millisArithmetic`,data:{operand:e.sourceCode.getText(i.isUndefined(r.left)?n.right:n.left),what:s?`a timestamp`:`a duration`,module:s?`DateTime`:`Duration`,suggestion:ei(n,r)}})}}}),ii=/* @__PURE__ */ new Map([[`addEventListener`,1],[`on`,1],[`setInterval`,0]]);function ai(e,t){let n=C(e.callee)?.at(-1),r=i.isUndefined(n)?void 0:ii.get(n);if(i.isUndefined(r))return!1;if(n===`addEventListener`){let t=M(e,2);if(t?.type===`ObjectExpression`){let e=P(t,`once`);if(i.isNotUndefined(e)&&V(e.value,!0))return!1}}let a=M(e,r);return i.isNotUndefined(a)&&me(a,t)}const oi=b(x(`problem`,`Disallow attaching Effect.callback resume to repeating event sources.`,{multiShot:`Effect.callback is single-shot, but this source emits repeatedly. Use a once-style subscription or Stream.callback.`},`https://github.com/Effect-TS/tsgo/issues/484`),(e,t)=>({CallExpression(n){if(!O(n.callee,t(),`Effect`,`callback`))return;let r=M(n,0);if(i.isUndefined(r)||!j(r))return;let a=L(r)?.name,o=r.body;o&&i.isNotUndefined(a)&&I(o,e=>e.type===`CallExpression`&&ai(e,a))&&e.report({node:n,messageId:`multiShot`})}})),si=/* @__PURE__ */ new Set([`NaN`,`Infinity`,`undefined`]),ci=/* @__PURE__ */ new Set([`annotate`,`annotateEncoded`,`annotateKey`]),li=[`default`,`examples`];function ui(e){return e.type===`Literal`&&i.isBigInt(e.value)||e.type===`Identifier`&&si.has(e.name)||j(e)||e.type===`CallExpression`&&C(e.callee)?.at(-1)===`Symbol`}function di(e,t){if(e.type===`ArrayExpression`)for(let n of e.elements)n&&n.type!==`SpreadElement`&&t.push(n);else if(e.type===`ObjectExpression`)for(let n of e.properties)n.type===`Property`&&t.push(n.value)}function fi(e){let t=[e];for(;r.isReadonlyArrayNonEmpty(t);){let e=t.pop();if(i.isUndefined(e))continue;let n=F(e);if(ui(n))return n;di(n,t)}}const pi=b(x(`problem`,`Disallow schema examples and defaults that cannot be represented in JSON Schema.`,{nonJson:`This schema annotation value is not JSON-serializable and will be omitted from or corrupt generated JSON Schema.`},`https://github.com/Effect-TS/tsgo/issues/440`),(e,t)=>({CallExpression(n){let r=t();if(!r.hasEffectImport)return;let a=D(n.callee,r),o=n.callee.type===`MemberExpression`?S(n.callee):a?.[0]===`Schema`?a[1]:void 0;if(i.isUndefined(o)||!ci.has(o))return;let s=Qt(n);if(!(i.isUndefined(s)||i.isNotUndefined(P(s,`jsonSchema`))))for(let t of li){let n=P(s,t);if(i.isUndefined(n))continue;let r=fi(n.value);i.isNotUndefined(r)&&e.report({node:r,messageId:`nonJson`})}}})),mi=[`option`,`either`],hi=b(x(`problem`,`Disallow wrapping infallible Effect.service access in Option or Either.`,{mandatory:`Effect.service never fails, so this wrapper is always present and keeps the service requirement. Use Effect.serviceOption.`},`https://github.com/Effect-TS/tsgo/issues/648`),(e,t)=>({CallExpression(n){let r=t(),a=k(n.callee,r,`Effect`,mi),o=M(n,0);if(a&&o?.type===`CallExpression`&&O(o.callee,r,`Effect`,`service`)){e.report({node:n,messageId:`mandatory`});return}if(n.callee.type!==`MemberExpression`||C(n.callee)?.at(-1)!==`pipe`)return;let s=F(n.callee.object),c=M(n,0);i.isNotUndefined(c)&&s.type===`CallExpression`&&O(s.callee,r,`Effect`,`service`)&&k(c,r,`Effect`,mi)&&e.report({node:n,messageId:`mandatory`})}})),gi=b(x(`problem`,`Ensure a later object spread cannot overwrite an explicitly assigned _tag.`,{overwritten:`A later spread can overwrite _tag at runtime. Move _tag after all spreads.`},`https://github.com/Effect-TS/tsgo/issues/426`),e=>({ObjectExpression(t){let n=r.findFirstWithIndex(t.properties,e=>e.type===`Property`&&N(e)===`_tag`);if(l.isNone(n))return;let[i,a]=n.value;r.some(r.drop(t.properties,a+1),e=>e.type===`SpreadElement`)&&e.report({node:i,messageId:`overwritten`})}})),_i=/^make[A-Z]/u,vi=/\.(?:test|spec)\.[cm]?[jt]sx?$/u,yi=y(x(`problem`,`Disallow project-local make<CapabilityName> imports outside test and spec files.`,{serviceConstructorImport:`Do not import Effect service constructor "{{name}}" into runtime code. Import the owning Layer, yield the contextual service, and allow its requirements to propagate to the composition root.`},`https://github.com/dmmulroy/anti-slop/blob/main/src/effect/rules/no-service-constructor-imports.ts`),e=>({ImportDeclaration(t){if(!vi.test(a.replaceAll(`\\`,`/`)(e.filename))&&(a.startsWith(`./`)(t.source.value)||a.startsWith(`../`)(t.source.value)))for(let n of t.specifiers){if(n.type!==`ImportSpecifier`)continue;let t=v(n.imported);_i.test(t)&&e.report({node:n,messageId:`serviceConstructorImport`,data:{name:t}})}}})),bi=[`getOrThrow`,`getOrThrowWith`],xi=b(x(`problem`,`Disallow turning missing Effect services into untyped Option defects.`,{getOrThrow:`Option.getOrThrow after Effect.serviceOption hides a mandatory service until runtime. Use Effect.service so it remains a typed requirement.`},`https://github.com/Effect-TS/tsgo/issues/650`),(e,t)=>({CallExpression(n){let r=t();if(k(n.callee,r,`Option`,bi)){let t=M(n,0),i=t?.type===`YieldExpression`?t.argument:t;i?.type===`CallExpression`&&O(i.callee,r,`Effect`,`serviceOption`)&&e.report({node:n,messageId:`getOrThrow`});return}if(n.callee.type!==`MemberExpression`||C(n.callee)?.at(-1)!==`pipe`)return;let a=F(n.callee.object),o=M(n,0);if(a.type!==`CallExpression`||!O(a.callee,r,`Effect`,`serviceOption`)||o?.type!==`CallExpression`||!O(o.callee,r,`Effect`,`map`))return;let s=M(o,0);i.isNotUndefined(s)&&k(s,r,`Option`,bi)&&e.report({node:n,messageId:`getOrThrow`})}})),Si=/* @__PURE__ */ new Set([`andThen`,`map`,`mapError`,`tap`,`tapError`,`tapErrorCause`]),Ci=b(x(`problem`,`Disallow throw in Effect callbacks that cannot add the thrown value to the typed error channel.`,{callbackThrow:`Throwing in this Effect callback creates an untyped defect. Return Effect.fail(...) or return the mapped error value instead.`},`https://github.com/Effect-TS/tsgo/issues/406`),(e,t)=>({ThrowStatement(n){let r=R(n);if(i.isUndefined(r))return;let a=t(),o=en(r,a),s=$t(r,`catch`);(o?.[0]===`Effect`&&i.isNotUndefined(o[1])&&Si.has(o[1])||i.isNotUndefined(s)&&k(s.callee,a,`Effect`,[`try`,`tryPromise`]))&&e.report({node:n,messageId:`callbackThrow`})}})),wi=/* @__PURE__ */ new Set([`get`,`post`,`put`,`patch`,`delete`,`head`,`options`]);function Ti(e,t){let n=e.parent,r=e.node;if(e.type!==`ImportBinding`||n?.type!==`ImportDeclaration`||K(n,r.type===`ImportSpecifier`?r:void 0))return!1;let i=n.source.value;return r.type===`ImportNamespaceSpecifier`?i===`effect/unstable/httpapi/HttpApiEndpoint`&&t.length===2||i===`effect/unstable/httpapi`&&t.length===3&&t[1]===`HttpApiEndpoint`:r.type===`ImportSpecifier`&&r.imported.type===`Identifier`&&r.imported.name===`HttpApiEndpoint`&&i===`effect/unstable/httpapi`&&t.length===2}function Ei(e,t){let n=C(e.callee),r=n?.[0],a=n?.at(-1);if(i.isUndefined(n)||i.isUndefined(r)||i.isUndefined(a)||!wi.has(a))return!1;let o=T(w(t,e,r));return i.isNotUndefined(o)&&Ti(o,n)}function Di(e){if(e?.type!==`ObjectExpression`)return;let t=/* @__PURE__ */ new Set,n=[];for(let r of e.properties){let e=le(r);if(i.isUndefined(e))return;let a=N(e)??(e.key.type===`Literal`&&i.isNumber(e.key.value)?String(e.key.value):void 0);if(i.isUndefined(a)||t.has(a))return;t.add(a),n.push(e)}return n}const Oi=y(x(`problem`,`Require lowercase static keys in Effect v4 endpoint header field schemas.`,{uppercase:`Header schema key "{{name}}" contains ASCII uppercase letters. Incoming headers use exact lowercase runtime lookup; review the schema and its consumers before renaming this key.`},`https://github.com/Effect-TS/tsgo/issues/413`),e=>({CallExpression(t){if(r.some(t.arguments,e=>e.type===`SpreadElement`)||!Ei(t,e))return;let n=Di(M(t,2)),a=Di(l.getOrUndefined(r.findFirst(n??[],e=>N(e)===`headers`))?.value);if(!i.isUndefined(a))for(let t of a){let n=N(t);i.isNotUndefined(n)&&/[A-Z]/u.test(n)&&e.report({node:t.key,messageId:`uppercase`,data:{name:n}})}}})),ki=b(x(`problem`,`Disallow no-op retry and repeat wrappers with times: 0.`,{zeroTimes:`times: 0 performs no retries or repeats. Remove the wrapper or use a positive count.`},`https://github.com/Effect-TS/tsgo/issues/412`),(e,t)=>({CallExpression(n){let r=t();if(!k(n.callee,r,`Effect`,[`retry`,`repeat`]))return;let a=Qt(n);if(i.isUndefined(a))return;let o=P(a,`times`);i.isNotUndefined(o)&&V(o.value,0)&&e.report({node:o,messageId:`zeroTimes`})}})),Ai=/* @__PURE__ */ new Map([[`Exit`,[`isSuccess`,`isFailure`]],[`Result`,[`isSuccess`,`isFailure`]],[`Option`,[`isSome`,`isNone`]]]);function ji(e,t){let n=F(e.type===`UnaryExpression`&&e.operator===`!`?e.argument:e);if(n.type!==`CallExpression`||n.arguments.length!==1)return;let i=D(n.callee,t);return i?.length===2&&r.contains(Ai.get(i[0]??``)??[],i[1])?i:void 0}function Mi(e){return I(e,e=>e.type===`YieldExpression`||e.type===`AwaitExpression`)}function Ni(e){if(!e)return!1;let t=e.type===`BlockStatement`?e.body.at(-1):e;return t?.type===`ReturnStatement`&&i.isNotNull(t.argument)&&!Mi(e)}function Pi(e){let t=e.parent;if(t.type!==`BlockStatement`&&t.type!==`Program`)return;let n=t.body,r=n[n.indexOf(e)+1];return r?.type===`ReturnStatement`?r:void 0}const Fi=b(x(`suggestion`,`Use Exit.match, Result.match or Option.match instead of branching on their guards to produce a value.`,{preferMatch:"Use `{{module}}.match` instead of branching on `{{module}}.{{guard}}` and producing a value in both branches."},`https://www.effect.website/docs/v4/api/effect/Option`),(e,t)=>{function n(t,n){e.report({node:t,messageId:`preferMatch`,data:{module:n[0]??``,guard:n[1]??``}})}return{ConditionalExpression(e){let r=ji(e.test,t());i.isNotUndefined(r)&&!Mi(e.consequent)&&!Mi(e.alternate)&&n(e,r)},IfStatement(e){let r=ji(e.test,t());i.isNotUndefined(r)&&Ni(e.consequent)&&Ni(e.alternate??Pi(e))&&n(e,r)}}}),Ii=y({...x(`suggestion`,`Use consistently aliased namespace imports for Effect and Alchemy submodule entrypoints.`,{alias:"Import {{source}} as the canonical namespace alias `{{alias}}`.",namespace:'Use `import * as {{alias}} from "{{source}}"` instead of importing values directly.'},`https://github.com/Effect-TS/language-service/blob/main/packages/language-service/src/core/AutoImport.ts`),fixable:`code`},e=>({ImportDeclaration(t){let n=On(t.source.value);if(n===void 0||t.importKind===`type`)return;let r=En(n);for(let n of t.specifiers)n.type===`ImportSpecifier`&&K(t,n)||(n.type===`ImportNamespaceSpecifier`?n.local.name!==r&&e.report({node:n.local,messageId:`alias`,data:{alias:r,source:t.source.value},fix:n=>An(e,t,n)}):e.report({node:n,messageId:`namespace`,data:{alias:r,source:t.source.value},fix:n=>An(e,t,n)}))}}));function Li(e,t){return e?.type===`NewExpression`&&e.arguments.length===1&&E(e.callee,t,`Set`)}function Ri(e,t){if(e.type===`ArrayExpression`){let[n]=e.elements;return e.elements.length===1&&n?.type===`SpreadElement`&&Li(n.argument,t)}return e.callee.type===`MemberExpression`&&S(e.callee)===`from`&&E(e.callee.object,t,`Array`)&&e.arguments.length===1&&Li(M(e,0),t)}function zi(e){let t=e.parent;return t.type===`AssignmentExpression`&&t.left===e||t.type===`UpdateExpression`||t.type===`UnaryExpression`&&t.operator===`delete`}function Bi(e,t){let n=t.sourceCode.getText(e.object);return I(R(e)??t.sourceCode.ast,e=>e.type===`MemberExpression`&&e.computed&&e.property.type===`Literal`&&i.isNumber(e.property.value)&&e.property.value!==0&&t.sourceCode.getText(e.object)===n)}function Vi(e){return e.type===`MemberExpression`&&S(e)===`length`}const Hi={"!=":`nonEmpty`,"!==":`nonEmpty`,"==":`empty`,"===":`empty`};function Ui(e){let t=F(e.left),n=F(e.right);if(Vi(t)&&V(n,0))return e.operator===`>`?`nonEmpty`:Hi[e.operator];if(V(t,0)&&Vi(n))return e.operator===`<`?`nonEmpty`:Hi[e.operator]}function Wi(e){let t=e.callee;return t.type===`MemberExpression`?S(t):t.type===`Identifier`?t.name:void 0}function Gi(e){if(e.type!==`ArrowFunctionExpression`||e.async||!e.expression||e.params.length!==1)return;let[t]=e.params,n=F(e.body);if(t?.type===`Identifier`&&n.type===`MemberExpression`&&n.object.type===`Identifier`&&n.object.name===t.name)return S(n)}const Ki=b(x(`suggestion`,`Prefer Effect Array and Struct helpers over hand-written array idioms in Effect files.`,{dedupe:`Use Arr.dedupe instead of deduplicating through a Set.`,head:`Use Arr.head, which returns an Option, instead of indexing the first element (Tuple.get for tuples).`,empty:"Use Arr.isReadonlyArrayEmpty (Str.isEmpty for strings) instead of comparing `.length` with 0.",nonEmpty:"Use Arr.isReadonlyArrayNonEmpty (Str.isNonEmpty for strings), which narrows to a non-empty array, instead of comparing `.length` with 0.",structGet:`Use Struct.get('{{key}}') instead of a property accessor lambda.`},`https://www.effect.website/docs/v4/api/effect/Array`),(e,t)=>({ArrayExpression(n){t().hasEffectImport&&Ri(n,e)&&e.report({node:n,messageId:`dedupe`})},CallExpression(n){if(t().hasEffectImport){if(Ri(n,e))e.report({node:n,messageId:`dedupe`});else if(Wi(n)===`map`)for(let t of n.arguments){let n=Gi(t);i.isNotUndefined(n)&&e.report({node:t,messageId:`structGet`,data:{key:n}})}}},MemberExpression(n){t().hasEffectImport&&n.computed&&V(n.property,0)&&!zi(n)&&!Bi(n,e)&&e.report({node:n,messageId:`head`})},BinaryExpression(n){if(!t().hasEffectImport)return;let r=Ui(n);i.isNotUndefined(r)&&e.report({node:n,messageId:r})}})),qi=b(x(`suggestion`,`Prefer immutable, Order-based Effect Array sorting in Effect projects.`,{effectArraySort:`Use Arr.sort with an Order instead of the mutable native Array.sort method.`},`https://www.effect.website/docs/v4/api/effect/Array#sort`),(e,t)=>({CallExpression(n){let r=t();r.hasEffectImport&&n.callee.type===`MemberExpression`&&S(n.callee)===`sort`&&!O(n.callee,r,`Array`,`sort`)&&e.report({node:n,messageId:`effectArraySort`})}})),Ji=/* @__PURE__ */ new Set([`toISOString`,`toLocaleDateString`,`toLocaleTimeString`]),Yi=b(x(`suggestion`,`Prefer Effect DateTime formatting so time-zone behavior is explicit and composable.`,{effectDateTime:`Convert to DateTime and format it in an explicit zone: DateTime.setZone with DateTime.formatIsoDate, formatIsoOffset or formatIsoZoned, or DateTime.format with timeZone. DateTime.formatIso is UTC, like toISOString: use it only for UTC instants, never slice it for a local date.`},`https://www.effect.website/docs/v4/api/effect/DateTime`),(e,t)=>({CallExpression(n){t().hasEffectImport&&n.callee.type===`MemberExpression`&&Ji.has(S(n.callee)??``)&&e.report({node:n,messageId:`effectDateTime`})}})),Xi=b({...x(`suggestion`,`Prefer explicit Effect Duration constructors over ambiguous millisecond literals.`,{effectDuration:`Wrap this number with Duration.millis or use a more descriptive Duration constructor.`},`https://www.effect.website/docs/v4/api/effect/Duration`),fixable:`code`},(e,t)=>({CallExpression(n){let r=kr(n,e,t());i.isUndefined(r)||i.isUndefined(J(r))||e.report({node:r,messageId:`effectDuration`,fix(t){let i=tt(e,n,`effect/Duration`,`Duration`,t);return[...i.fixes,t.replaceText(r,`${i.name}.millis(${e.sourceCode.getText(r)})`)]}})}})),Zi=/* @__PURE__ */ new Map([[`ms`,`millis`],[`milli`,`millis`],[`millis`,`millis`],[`millisecond`,`millis`],[`milliseconds`,`millis`],[`sec`,`seconds`],[`secs`,`seconds`],[`seconds`,`seconds`],[`mins`,`minutes`],[`minutes`,`minutes`],[`hr`,`hours`],[`hrs`,`hours`],[`hours`,`hours`],[`days`,`days`],[`weeks`,`weeks`]]),Qi=/* @__PURE__ */ new Set([`day`,`hour`,`minute`,`second`,`week`]),$i=/* @__PURE__ */ new Set([`backoff`,`cooldown`,`day`,`debounce`,`delay`,`duration`,`expiration`,`expiry`,`hour`,`interval`,`lifetime`,`minute`,`second`,`throttle`,`timeout`,`ttl`,`week`]),ea=/* @__PURE__ */ new Set([`at`,`epoch`,`per`,`timestamp`]);function ta(e){return e!==void 0&&e!==`excluded`&&e!==`unknown`}function na(e){let t=Ir(e),n=t.indexOf(`in`),a=t[n-1]??``;if(n>0&&n<t.length-1&&(Zi.has(a)||Qi.has(a))||r.some(t,e=>ea.has(e)))return`excluded`;let o=t.at(-1),s=t.at(-2);if(i.isUndefined(o))return;let c=Zi.get(o);if(i.isNotUndefined(c))return c;if($i.has(o)||o===`age`&&s===`max`||o===`in`&&s===`expires`)return`unknown`}function ra(e,t,n){return r.some(w(n,e,t)?.defs??[],e=>e.type===`ImportBinding`)}const ia=c.type().pipe(c.withReturnType(),c.discriminators(`type`)({Identifier:s.flow(d.get(`name`),r.make),TSQualifiedName:({left:e,right:t})=>{let n=ia(e);return i.isUndefined(n)?void 0:r.append(n,t.name)}}),c.orElse(s.constUndefined));function aa(e,t,n){return I(e,e=>{if(e.type!==`TSTypeReference`)return!1;let[a,...o]=ia(e.typeName)??[],s=i.isUndefined(a)||!ra(e,a,t)?void 0:n.bindings.get(a);return i.isNotUndefined(s)&&l.contains(r.head(r.appendAll(s,o)),`Duration`)})}function oa(e){return ce(e.parent)&&e.id.type===`Identifier`&&e.init!==null&&J(e.init)!==void 0}function sa(e,t){let n=F(e);if(n.type!==`Identifier`)return;let r=T(w(t,n,n.name))?.node;return r?.type===`VariableDeclarator`&&oa(r)?r:void 0}const ca=b(x(`suggestion`,`Prefer Effect Duration values over plain-number duration constants.`,{durationConstant:`{{name}} holds a duration as a plain number. Declare it as {{replacement}} and convert at non-Effect boundaries with Duration.toMillis or Duration.toSeconds.`},`https://www.effect.website/docs/v4/api/effect/Duration`),(e,t)=>{let n=/* @__PURE__ */ new Map;function r(n,r){if(n.id.typeAnnotation&&aa(n.id.typeAnnotation,e,t()))return`none`;let a=na(n.id.name);if(r)return ta(a)?a:`millis`;if(a===`excluded`||(J(n.init)??0)<=0)return`none`;if(ta(a))return a;let o=Fr(n.init);return o?.millis===!0?`millis`:a===`unknown`||i.isNotUndefined(o)?void 0:`none`}return{before(){n.clear()},VariableDeclarator(e){t().hasEffectImport&&oa(e)&&!n.has(e)&&n.set(e,!1)},CallExpression(r){let a=kr(r,e,t()),o=i.isUndefined(a)?void 0:sa(a,e);i.isNotUndefined(o)&&n.set(o,!0)},"Program:exit":function(){for(let[t,a]of n){let n=r(t,a),o=J(t.init);n!==`none`&&e.report({node:t.id,messageId:`durationConstant`,data:{name:t.id.name,replacement:i.isUndefined(n)||i.isUndefined(o)?`a Duration constructor such as Duration.seconds`:Ur(o,n)}})}}}}),la=/* @__PURE__ */ new Set([`Finite`,`FiniteFromString`,`Int`,`Number`,`NumberFromString`]),ua=/* @__PURE__ */ new Set([`NullOr`,`NullishOr`,`UndefinedOr`,`optional`,`optionalKey`]),da=/* @__PURE__ */ new Set([`annotate`,`annotateKey`,`brand`,`check`,`withConstructorDefault`,`withDecodingDefault`,`withDecodingDefaultKey`]);function fa(e,t){let n=D(e,t);return n?.length===2&&n[0]===`Schema`?n[1]:void 0}function pa(e,t){if(e.type===`SpreadElement`)return!1;let n=F(e);return n.type===`CallExpression`?da.has(fa(n.callee,t)??``):ua.has(fa(n,t)??``)}function ma(e,t){let n=F(e);if(n.type!==`CallExpression`)return la.has(fa(n,t)??``);let a=n.callee,o=M(n,0);if(ua.has(fa(a,t)??``))return i.isNotUndefined(o)&&ma(o,t);if(a.type!==`MemberExpression`||a.object.type===`Super`||!ma(a.object,t))return!1;let s=S(a);return s===`pipe`?r.every(n.arguments,e=>pa(e,t)):s===`annotate`||s===`check`}function ha(e){let t=e?.typeAnnotation;return t?.type===`TSNumberKeyword`||t?.type===`TSUnionType`&&r.some(t.types,e=>e.type===`TSNumberKeyword`)&&r.every(t.types,e=>[`TSNullKeyword`,`TSNumberKeyword`,`TSUndefinedKeyword`].includes(e.type))}function ga(e){return e!==void 0&&zr(e)===`duration`}function _a(e){return e.computed?e.key.type===`Literal`&&i.isString(e.key.value)?e.key.value:void 0:e.key.type===`Identifier`?e.key.name:void 0}function va(e,t,n){if(/\.d\.[cm]?ts$/u.test(t.filename))return!0;let a=ge(e,e=>i.hasProperty(e,`declare`)&&e.declare);if(i.isNotUndefined(a))return!0;let o=R(e);return i.isNotUndefined(o)&&nn(o,n)&&r.some(o.params,t=>_e(t,e))}function ya(e){let t=e.type===`TSParameterProperty`?e.parameter:e;if(t.type===`Identifier`)return ha(t.typeAnnotation)?t:void 0;if(t.type!==`AssignmentPattern`||t.left.type!==`Identifier`)return;let n=F(t.right);return ha(t.left.typeAnnotation)||!t.left.typeAnnotation&&n.type===`Literal`&&i.isNumber(n.value)?t.left:void 0}const ba=b(x(`suggestion`,`Prefer Duration types over plain numbers for millisecond parameters and fields.`,{durationType:`{{name}} holds a duration as a number of milliseconds. Type it as Duration.Input (or Duration.Duration) and convert with Duration.toMillis only where a non-Effect API needs milliseconds.`,durationSchema:`{{name}} decodes a duration as a plain number. Use Schema.DurationFromMillis to keep milliseconds in the encoded data, or Schema.Duration.`},`https://www.effect.website/docs/v4/api/effect/Duration`),(e,t)=>{function n(t,n,r){e.report({node:t,messageId:r,data:{name:n}})}function r(r){if(t().hasEffectImport&&r.body&&!nn(r,t())&&!va(r,e,t()))for(let e of r.params){let t=ya(e);i.isNotUndefined(t)&&ga(t.name)&&n(t,t.name,`durationType`)}}function a(r){let i=_a(r);t().hasEffectImport&&ga(i)&&ha(r.typeAnnotation)&&!va(r,e,t())&&n(r.key,i,`durationType`)}return{ArrowFunctionExpression:r,FunctionDeclaration:r,FunctionExpression:r,PropertyDefinition:a,TSPropertySignature:a,Property(e){let r=N(e);t().hasEffectImport&&e.parent.type===`ObjectExpression`&&ga(r)&&ma(e.value,t())&&n(e.key,r,`durationSchema`)}}}),xa=/* @__PURE__ */ new Set([`base64`,`base64url`,`hex`]);function Sa(e){return i.isNotUndefined(e)&&B(e)&&xa.has(e.value)}const Ca=b(x(`suggestion`,`Prefer Effect Encoding for portable Base64, Base64Url, and hexadecimal encoding.`,{effectEncoding:`Use Encoding encode/decode helpers; decoders return Result instead of throwing.`},`https://www.effect.website/docs/v4/api/effect/Encoding`),(e,t)=>({CallExpression(n){if(!t().hasEffectImport)return;if((E(n.callee,e,`atob`)||E(n.callee,e,`btoa`))&&r.isReadonlyArrayNonEmpty(n.arguments)){e.report({node:n,messageId:`effectEncoding`});return}let a=C(n.callee),o=i.isNotUndefined(a)&&r.join(a,`.`)===`Buffer.from`&&Sa(M(n,1)),s=a?.at(-1)===`toString`&&Sa(M(n,0));(o||s)&&e.report({node:n,messageId:`effectEncoding`})}})),wa=/* @__PURE__ */ new Set([`fs`,`fs/promises`,`node:fs`,`node:fs/promises`]),Ta=b(x(`suggestion`,`Prefer the Effect FileSystem service over direct Node.js filesystem imports in Effect projects.`,{effectFileSystem:`Use the FileSystem service from effect/FileSystem instead of {{source}}.`},`https://www.effect.website/docs/v4/api/effect/FileSystem`),(e,t)=>({ImportDeclaration(n){t().hasEffectImport&&wa.has(n.source.value)&&e.report({node:n.source,messageId:`effectFileSystem`,data:{source:n.source.value}})}}));function Ea(e,t,n){return e.type===`CallExpression`&&O(e.callee,t,`Result`,n)?M(e,0):void 0}function Da(e,t,n){let r=L(t),i=G(t);if(r===void 0||i?.type!==`ConditionalExpression`)return;let a=Ea(i.consequent,n,`succeed`),o=Ea(i.alternate,n,`fail`);a?.type===`Identifier`&&a.name===r.name&&o?.type===`Identifier`&&o.name===r.name&&e.report({node:t,messageId:`effectFilter`})}const Oa=b(x(`suggestion`,`Prefer Effect Filter constructors for reusable Result-valued predicates.`,{effectFilter:`Use Filter.fromPredicate for this Result-valued predicate so it composes as a Filter.`},`https://www.effect.website/docs/v4/api/effect/Filter`),(e,t)=>({ArrowFunctionExpression(n){Da(e,n,t())},FunctionExpression(n){Da(e,n,t())}})),ka=b(x(`suggestion`,`Prefer immutable Effect Headers values in Effect projects.`,{effectHeaders:`Use Headers.fromInput to construct normalized, immutable Effect headers.`},`https://www.effect.website/docs/v4/api/effect/unstable/http/Headers`),(e,t)=>({NewExpression(n){t().hasEffectImport&&E(n.callee,e,`Headers`)&&e.report({node:n,messageId:`effectHeaders`})}}));function Aa(e){return e.type===`Literal`||e.type===`TemplateLiteral`&&e.expressions.length===0}function ja(e,t){if(e.type===`BinaryExpression`&&ye(e.operator)){if(Aa(e.left))return t.sourceCode.getText(e.right);if(Aa(e.right))return t.sourceCode.getText(e.left)}}function Ma(e,t){let n=ja(e.test,t);if(n===void 0)return!1;let r=e.alternate,i=1;for(;r?.type===`ConditionalExpression`||r?.type===`IfStatement`;){if(ja(r.test,t)!==n)return!1;i+=1,r=r.alternate}return i>1}const Na=b(x(`suggestion`,`Prefer Effect Match for composable and exhaustive branching in Effect projects.`,{effectMatch:`Use Match.type, Match.value, or Match.tags with Match.exhaustive instead of switch.`,preferMatch:`Use Match from Effect instead of a chained literal ternary.`,ifChain:"Use Match.type, Match.value, or Match.discriminators with Match.exhaustive instead of an `else if` chain comparing the same value against literals."},`https://www.effect.website/docs/v4/api/effect/Match`),(e,t)=>({SwitchStatement(n){t().hasEffectImport&&e.report({node:n,messageId:`effectMatch`})},IfStatement(n){(n.parent.type!==`IfStatement`||n.parent.alternate!==n)&&t().hasEffectImport&&Ma(n,e)&&e.report({node:n,messageId:`ifChain`})},ConditionalExpression(t){t.parent.type!==`ConditionalExpression`&&Ma(t,e)&&e.report({node:t,messageId:`preferMatch`})}})),Pa=/* @__PURE__ */ new Set([`node:path`,`path`]),Fa=b(x(`suggestion`,`Prefer the Effect Path service over direct Node.js path imports in Effect projects.`,{effectPath:`Use the Path service from effect/Path instead of {{source}}.`},`https://www.effect.website/docs/v4/api/effect/Path`),(e,t)=>({ImportDeclaration(n){t().hasEffectImport&&Pa.has(n.source.value)&&e.report({node:n.source,messageId:`effectPath`,data:{source:n.source.value}})}})),Ia={bigint:`P.isBigInt`,boolean:`P.isBoolean`,function:`P.isFunction`,number:`P.isNumber`,object:`P.isObjectOrArray`,string:`P.isString`,symbol:`P.isSymbol`,undefined:`P.isUndefined`},La={"!=":`P.isNotNullish`,"!==":`P.isNotNull`,"==":`P.isNullish`,"===":`P.isNull`},Ra={"!=":`P.isNotNullish`,"!==":`P.isNotUndefined`,"==":`P.isNullish`,"===":`P.isUndefined`},za={Array:`Arr.isArray`,BigInt:`P.isBigInt`,Boolean:`P.isBoolean`,Date:`P.isDate`,Error:`P.isError`,Function:`P.isFunction`,Map:`P.isMap`,Number:`P.isNumber`,Promise:`P.isPromise`,RegExp:`P.isRegExp`,Set:`P.isSet`,String:`P.isString`,Symbol:`P.isSymbol`,Uint8Array:`P.isUint8Array`},Ba=/* @__PURE__ */ new Set([`BigInt`,`Boolean`,`Number`,`String`,`Symbol`]);function Va(e){return e.type===`ArrowFunctionExpression`||e.type===`FunctionDeclaration`||e.type===`FunctionExpression`}function Ha(e){return e===`!==`||e===`!=`}function Ua(e,t,r){if(t.type===`Literal`&&i.isNull(t.value))return l.getOrUndefined(n.get(La,e.operator));if(E(t,r,`undefined`))return l.getOrUndefined(n.get(Ra,e.operator))}function Wa(e,t,r,a){if(t.type!==`UnaryExpression`||t.operator!==`typeof`||!B(r))return;let o=F(t.argument);if(o.type===`Identifier`&&E(o,a,o.name))return;let s=l.getOrUndefined(n.get(Ia,r.value));if(!i.isUndefined(s))return r.value===`undefined`?Ha(e.operator)?`P.isNotUndefined`:s:Ha(e.operator)?`P.not(${s})`:s}function Ga(e,t){if(!ye(e.operator))return;let n=F(e.left),r=F(e.right);return Wa(e,n,r,t)??Wa(e,r,n,t)??Ua(e,r,t)??Ua(e,n,t)}function Ka(e,t){let r=F(e.right);if(r.type===`Identifier`&&E(r,t,r.name))return l.getOrUndefined(n.get(za,r.name))}const qa=b(x(`suggestion`,`Prefer Effect Predicate guards over typeof, instanceof, and nullish comparisons in Effect files.`,{predicate:`Use {{predicate}} from Effect instead of this check. Decode unknown input with Schema.is or a Schema decoder instead of narrowing it by hand.`,objectPredicate:`Use {{predicate}} from Effect instead of this check. Unlike typeof x === 'object', it treats null as not an object.`,boxedInstance:"`instanceof {{constructor}}` only matches boxed objects such as `new {{constructor}}(…)`, never primitive values. To check for the primitive, use {{predicate}}."},`https://www.effect.website/docs/v4/api/effect/Predicate`),(e,t)=>({BinaryExpression(n){if(!t().hasEffectImport)return;let r=n.operator===`instanceof`?Ka(n,e):Ga(n,e);if(i.isUndefined(r)||ge(n,Va)?.returnType?.typeAnnotation.type===`TSTypePredicate`)return;let o=n.operator===`instanceof`?e.sourceCode.getText(n.right):``;Ba.has(o)?e.report({node:n,messageId:`boxedInstance`,data:{constructor:o,predicate:r}}):a.includes(`P.isObjectOrArray`)(r)?e.report({node:n,messageId:`objectPredicate`,data:{predicate:r}}):e.report({node:n,messageId:`predicate`,data:{predicate:r}})}})),Ja=/* @__PURE__ */ new Set([`canParse`,`parse`]),Ya=b(x(`suggestion`,`Prefer Effect Url helpers for safe URL parsing in Effect projects.`,{effectUrl:`Use Url.fromString or Url.make so invalid URLs are represented as Result failures.`},`https://www.effect.website/docs/v4/api/effect/unstable/http/Url`),(e,t)=>({NewExpression(n){t().hasEffectImport&&E(n.callee,e,`URL`)&&e.report({node:n,messageId:`effectUrl`})},CallExpression(n){let r=C(n.callee);t().hasEffectImport&&r?.[0]===`URL`&&Ja.has(r[1]??``)&&n.callee.type===`MemberExpression`&&E(n.callee.object,e,`URL`)&&e.report({node:n,messageId:`effectUrl`})}})),Xa={"&&":[`===`,`==`],"||":[`!==`,`!=`],"??":[]};function Za(e,t){let n=F(e);return n.type!==`LogicalExpression`||n.operator!==t?[n]:[...Za(n.left,t),...Za(n.right,t)]}function Qa(e,t,n){if(e.type!==`BinaryExpression`||!t.includes(e.operator)||e.left.type===`PrivateIdentifier`)return;let r=F(e.left),i=F(e.right);if(r.type!==`MemberExpression`||i.type!==`MemberExpression`)return;let a=S(r),o=n.sourceCode.getText(r.object),s=n.sourceCode.getText(i.object);if(a!==void 0&&o!==s&&a===S(i))return o<s?`${o} and ${s}`:`${s} and ${o}`}function $a(e,t){let n=R(e),r=n===void 0?void 0:en(n,t);return r?.length===2&&r[0]===`Equivalence`&&r[1]===`make`}const eo=b(x(`suggestion`,`Prefer Equal.equals or an Equivalence over field-by-field comparisons in Effect files.`,{preferEqual:`Compare {{pair}} with Equal.equals (Data and Schema classes implement Equal) or an Equivalence such as Equivalence.Struct instead of field by field.`},`https://www.effect.website/docs/v4/api/effect/Equal`),(e,t)=>({LogicalExpression(n){let r=t(),i=Xa[n.operator];if(!r.hasEffectImport||i.length===0)return;let a=n.parent;if(a.type===`LogicalExpression`&&a.operator===n.operator)return;let o=/* @__PURE__ */ new Map;for(let t of Za(n,n.operator)){let a=Qa(t,i,e);if(a===void 0)continue;let s=(o.get(a)??0)+1;if(o.set(a,s),s===2&&!$a(n,r)){e.report({node:n,messageId:`preferEqual`,data:{pair:a}});return}}}}));function to(e,t){let n=e===void 0?void 0:F(e);return n?.type===`Identifier`&&n.name===t}function no(e,t,n){return e?.type===`CallExpression`&&e.arguments.length===1&&O(e.callee,n,`Match`,`value`)&&to(M(e,0),t)}function ro(e,t,n){return e.callee.type===`MemberExpression`&&S(e.callee)===`pipe`?no(e.callee.object,t,n):(A(e.callee,n,[`pipe`])||A(e.callee,n,[`Function`,`pipe`]))&&no(e.arguments[0],t,n)}function io(e,t,n){if(O(e.callee,n,`Match`,`valueTags`))return e.arguments.length===2&&to(M(e,0),t)?e.arguments[1]:void 0;let r=e.callee;return r.type===`CallExpression`&&O(r.callee,n,`Match`,`valueTags`)&&r.arguments.length===1&&e.arguments.length===1&&to(M(e,0),t)?r.arguments[0]:void 0}function ao(e){return e.type!==`ArrowFunctionExpression`&&e.id!==null||e.parent.type===`VariableDeclarator`&&e.parent.init===e}const oo=b(x(`suggestion`,`Hoist Effect matchers with Match.type or Match.typeTags instead of wrapping Match.value or Match.valueTags in a function.`,{value:"Replace this function with a hoisted `Match.type<…>().pipe(…)` matcher instead of calling `Match.value({{parameter}})` on every call. Case handlers already receive the narrowed value.",valueTags:"Replace this function with a hoisted `Match.typeTags<…>()({…})` or `Match.type<…>().pipe(Match.tagsExhaustive({…}))` matcher instead of calling `Match.valueTags` with `{{parameter}}`. Case handlers already receive the narrowed value."},`https://www.effect.website/docs/v4/api/effect/Match`),(e,t)=>{function n(n){let r=n.params[0];if(n.params.length!==1||r?.type!==`Identifier`||n.typeParameters||n.async||n.generator)return;let i=G(n);if(i?.type!==`CallExpression`||I(i,e=>e.type===`ThisExpression`))return;let a=t();if(ro(i,r.name,a)){e.report({node:n,messageId:`value`,data:{parameter:r.name}});return}let o=io(i,r.name,a);o!==void 0&&(!ao(n)||me(o,r.name))&&e.report({node:n,messageId:`valueTags`,data:{parameter:r.name}})}return{ArrowFunctionExpression:n,FunctionDeclaration:n,FunctionExpression:n}});function so(e){return e.type===`SpreadElement`}function co(e){let t=F(e.argument);return t.type!==`ConditionalExpression`&&t.type!==`LogicalExpression`&&t.type!==`ObjectExpression`&&(t.type!==`MemberExpression`||S(t)!==`fields`)}function lo(e){return j(e)&&r.some(e.params,e=>e.type!==`AssignmentPattern`&&e.type!==`TSParameterProperty`&&!e.typeAnnotation)}function uo(e){if(i.isNull(e)||e.type===`SpreadElement`)return!1;let t=F(e);return c.value(t).pipe(c.when({type:`Literal`},({value:e})=>i.isString(e)||i.isNumber(e)||i.isBoolean(e)),c.when({type:`TemplateLiteral`},({expressions:e})=>r.isReadonlyArrayEmpty(e)),c.when({type:`UnaryExpression`,operator:`-`},({argument:e})=>uo(e)),c.when({type:`ArrayExpression`},({elements:e})=>r.some(e,uo)),c.when({type:`ObjectExpression`},({properties:e})=>r.some(e,e=>e.type===`Property`&&uo(e.value))),c.orElse(s.constFalse))}function fo(e){return lo(e)||e.type===`CallExpression`&&r.some(e.arguments,e=>lo(e))}const po=c.type().pipe(c.when({type:`Property`,kind:`init`,method:!1},e=>{let t=F(e.value);return!fo(t)&&!uo(t)}),c.orElse(s.constFalse)),mo=b(x(`suggestion`,`Prefer Struct.assign over object spread merges and copies in Effect files.`,{merge:`Use Struct.assign(a, b) instead of merging objects with spreads.`,copy:`Use Struct.assign(value, { … }) instead of copying an object with spread overrides. Spreading a class instance drops its prototype; rebuild Schema and Data class instances with their constructor.`},`https://www.effect.website/docs/v4/api/effect/Struct#assign`),(e,t)=>({ObjectExpression(n){if(!t().hasEffectImport)return;let[a,...o]=n.properties;!i.isUndefined(a)&&so(a)&&co(a)&&(r.isReadonlyArrayNonEmpty(o)&&r.every(o,e=>so(e)&&co(e))?e.report({node:n,messageId:`merge`}):r.isReadonlyArrayNonEmpty(o)&&r.every(o,po)&&e.report({node:n,messageId:`copy`}))}})),ho=/* @__PURE__ */ new Map([[`interruptibleMask`,`interruptible`],[`uninterruptibleMask`,`uninterruptible`]]),go=b(x(`suggestion`,`Prefer the non-mask interruptibility API when the restore callback is unused.`,{unusedRestore:`The mask callback never uses restore, so the mask is equivalent to {{replacement}} and misleadingly suggests a restored region.`},`https://github.com/Effect-TS/tsgo/issues/659`),(e,t)=>({CallExpression(n){let r=D(n.callee,t()),a=r?.length===2&&r[0]===`Effect`?ho.get(r[1]??``):void 0,o=M(n,0);i.isNotUndefined(a)&&i.isNotUndefined(o)&&j(o)&&!he(o)&&e.report({node:n,messageId:`unusedRestore`,data:{replacement:`Effect.${a}`}})}})),_o=b(x(`suggestion`,`Prefer Effect.withSpan when the callback does not use the span handle.`,{unusedSpan:`The useSpan callback ignores its span. Use Effect.withSpan so nested spans are parented beneath this span.`},`https://github.com/Effect-TS/tsgo/issues/663`),(e,t)=>({CallExpression(n){if(!O(n.callee,t(),`Effect`,`useSpan`))return;let r=M(n,n.arguments.length-1);i.isNotUndefined(r)&&j(r)&&!he(r)&&e.report({node:n,messageId:`unusedSpan`})}}));function vo(e,t){let n=F(e);if(V(n,0))return!0;if(B(n))return/^0\s*(?:nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/i.test(n.value);if(O(n,t,`Duration`,`zero`))return!0;if(n.type===`CallExpression`){let e=D(n.callee,t),a=M(n,0);return i.isNotUndefined(a)&&l.contains(r.head(e??[]),`Duration`)&&V(a,0)}return!1}const yo=b(x(`suggestion`,`Prefer scheduler yielding to a zero-duration Clock sleep.`,{zeroSleep:`Effect.sleep(0) uses Clock and interacts with TestClock. Use Effect.yieldNow for a cooperative scheduler yield.`},`https://github.com/Effect-TS/tsgo/issues/661`),(e,t)=>({CallExpression(n){let r=t(),a=M(n,0);i.isNotUndefined(a)&&O(n.callee,r,`Effect`,`sleep`)&&vo(a,r)&&e.report({node:n,messageId:`zeroSleep`})}})),bo=/* @__PURE__ */ new Set([`catch`,`mapError`,`catchAll`]);function xo(e,t){let n=en(e,t),r=$t(e,`catch`);if(!(n?.[0]===`Effect`&&i.isNotUndefined(n[1])&&bo.has(n[1])||i.isNotUndefined(r)&&k(r.callee,t,`Effect`,[`try`,`tryPromise`]))||!e.body)return!1;let a=L(e);return I(e.body,e=>e.type===`NewExpression`&&xe(e)&&(i.isUndefined(a)||!me(e,a.name)))}const So=b(x(`suggestion`,`Preserve the underlying cause when wrapping an Effect failure.`,{droppedCause:`This handler constructs a new error but drops the caught failure. Accept it as a parameter and attach it as cause.`},`https://github.com/Effect-TS/tsgo/issues/490`),(e,t)=>({ArrowFunctionExpression(n){xo(n,t())&&e.report({node:n,messageId:`droppedCause`})},FunctionExpression(n){xo(n,t())&&e.report({node:n,messageId:`droppedCause`})}})),Co=b(x(`problem`,`Require Schema.Class declarations to carry a nominal brand.`,{missingBrand:`Schema.Class without a second type parameter is structural. Add a unique brand so plain objects cannot masquerade as instances.`},`https://github.com/Effect-TS/tsgo/issues/468`),(e,t)=>({CallExpression(n){O(n.callee,t(),`Schema`,`Class`)&&(n.typeArguments?.params.length??0)<2&&e.report({node:n,messageId:`missingBrand`})}}));function wo(e,t){if(O(e.callee,t,`Effect`,`tryPromise`))return ln(M(e,0))}const To=b(x(`suggestion`,`Require Effect.tryPromise thunks to accept and use their AbortSignal for interruption.`,{missingSignal:"Accept the AbortSignal parameter and pass it to the Promise API. Name it `_signal` only when cancellation is unsupported.",unusedSignal:"Pass this AbortSignal to the Promise API, or rename it to `_signal` to explicitly acknowledge that cancellation is unsupported."},`https://www.effect.website/docs/v4/api/effect/Effect#tryPromise`),(e,t)=>({CallExpression(n){let r=wo(n,t());if(i.isUndefined(r))return;let o=L(r);i.isUndefined(o)?e.report({node:r,messageId:`missingSignal`}):!a.startsWith(`_`)(o.name)&&!he(r)&&e.report({node:o,messageId:`unusedSignal`})}})),Eo=[`fn`,`fnUntraced`,`gen`],Do=[`fn`,`fnUntraced`],Oo=[`try`,`tryPromise`];function ko(e,t){let n=e.parent;if(n.type===`CallExpression`&&M(n,0)===e)return k(n.callee,t,`Effect`,Oo);if(n.type!==`Property`||n.key.type!==`Identifier`||n.key.name!==`try`)return!1;let r=n.parent;return r.type===`ObjectExpression`&&r.parent.type===`CallExpression`&&k(r.parent.callee,t,`Effect`,Oo)}const Ao=b(x(`problem`,`Disallow throw in Effect generator APIs because it creates an untyped defect.`,{throwInGen:`Use yield* Effect.fail(...) instead of throw so the failure stays in the typed error channel.`}),(e,t)=>({ThrowStatement(n){let a=t(),o=R(n);if(i.isUndefined(o)||ko(o,a))return;let s=z(o),c=i.isNotUndefined(s)&&r.some(Eo,e=>O(s.callee,a,`Effect`,e)),l=s?.callee,u=l?.type===`CallExpression`&&r.some(Do,e=>O(l.callee,a,`Effect`,e));(c||u)&&e.report({node:n,messageId:`throwInGen`})}})),jo=/* @__PURE__ */ new Set([`BigDecimal`,`Config`,`Data`,`DateTime`,`Duration`,`Effect`,`Equivalence`,`Exit`,`Function`,`Layer`,`Match`,`Option`,`Order`,`Predicate`,`Result`,`Schedule`,`Schema`,`Stream`,`String`,`Struct`,`flow`,`pipe`]),Mo=/* @__PURE__ */ new Set([`BigDecimal`,`Data`,`DateTime`,`Duration`,`Exit`,`Option`,`Result`,`String`,`Struct`,`pipe`]),No=/* @__PURE__ */ new Set([`pipe`,`value`,`valueTags`]),Po=/^run|unsafe/iu;function Fo(e,t){let n=e.callee,i=D(n,t.state)??[],a=jo.has(i[0]??``)&&!r.some(i,e=>Po.test(e)),o=n.type===`MemberExpression`&&!n.computed&&n.property.type===`Identifier`&&n.property.name===`pipe`&&n.object.type===`CallExpression`&&Fo(n.object,t)||n.type===`CallExpression`&&Fo(n,t),s=Mo.has(i[0]??``)||No.has(i[1]??``);return!e.optional&&(a||o)&&r.every(e.arguments,e=>e.type!==`SpreadElement`&&Y(e,t)&&(!s||!Io(e,t)))}function Io(e,t){if(e.type!==`Identifier`)return j(e);let n=T(w(t.context,e,e.name));return n?.type===`FunctionName`||n?.type===`ImportBinding`||n?.type===`Variable`&&n.node.type===`VariableDeclarator`&&i.isNotNull(n.node.init)&&j(n.node.init)}function Lo(e,t){let n=T(w(t.context,e,e.name));return n?.type!==`Variable`||n.parent?.type!==`VariableDeclaration`||ce(n.parent)}function Ro(e,t){return e.type===`SpreadElement`?Y(e.argument,t):(!e.computed||Y(e.key,t))&&Y(e.value,t)}function Y(e,t){return c.value(e).pipe(c.discriminators(`type`)({Literal:e=>!(`regex`in e),ArrowFunctionExpression:s.constTrue,FunctionExpression:s.constTrue,Identifier:e=>Lo(e,t),TemplateLiteral:({expressions:e})=>r.every(e,e=>Y(e,t)),ParenthesizedExpression:({expression:e})=>Y(e,t),TSAsExpression:({expression:e})=>Y(e,t),TSSatisfiesExpression:({expression:e})=>Y(e,t),TSNonNullExpression:({expression:e})=>Y(e,t),MemberExpression:e=>i.isNotUndefined(D(e,t.state))||e.object.type===`CallExpression`&&Fo(e.object,t)&&(!e.computed||Y(e.property,t)),UnaryExpression:({argument:e,operator:n})=>n!==`delete`&&Y(e,t),BinaryExpression:({left:e,right:n})=>Y(e,t)&&Y(n,t),LogicalExpression:({left:e,right:n})=>Y(e,t)&&Y(n,t),ConditionalExpression:({alternate:e,consequent:n,test:r})=>Y(r,t)&&Y(n,t)&&Y(e,t),ArrayExpression:({elements:e})=>r.every(e,e=>i.isNull(e)||Y(e,t)),ObjectExpression:({properties:e})=>r.every(e,e=>Ro(e,t)),CallExpression:e=>Fo(e,t)}),c.orElse(s.constFalse))}function zo(e,t){return e.type===`ObjectExpression`||e.type===`ArrayExpression`||j(e)||e.type===`Identifier`&&T(w(t,e,e.name))?.type===`FunctionName`}function Bo(e,t,n){let i=r.findFirst(e.sourceCode.getDeclaredVariables(t),e=>e.name===n);return l.exists(i,({references:e})=>r.some(e,({identifier:e,init:t})=>{let n=e.parent;return!t&&(n.type!==`CallExpression`||n.callee!==e)}))}function Vo(e,t,{declaration:n,node:a,name:o}){let s=G(a);i.isUndefined(s)||r.isReadonlyArrayNonEmpty(a.params)||a.async||a.generator||a.typeParameters||zo(s,e)||!Y(s,{context:e,state:t})||Bo(e,n,o.name)||e.report({node:o,messageId:`constantThunk`,data:{name:o.name}})}function Ho(e){return(e.parent?.type===`ExportNamedDeclaration`?e.parent:e).parent?.type===`Program`}const Uo=b(x(`suggestion`,`Disallow top-level functions without parameters that always return the same value.`,{constantThunk:"`{{name}}` takes no parameters and always returns the same value. Make it a constant, or a static on its class."}),(e,t)=>({FunctionDeclaration(n){n.id&&n.body&&Ho(n)&&Vo(e,t(),{declaration:n,node:n,name:n.id})},VariableDeclarator(n){n.id.type===`Identifier`&&n.init&&j(n.init)&&Ho(n.parent)&&Vo(e,t(),{declaration:n,node:n.init,name:n.id})}}));function Wo(e){let t=[];for(let n of e.params)if(n.type===`Identifier`)t.push(n.name);else if(n.type===`RestElement`&&n.argument.type===`Identifier`)t.push(n.argument.name);else return;return t}function Go(e,t){return I(e,e=>e.type===`ThisExpression`||e.type===`Identifier`&&t.has(e.name))}function Ko(e,t){let n=t.params.at(-1);if(e.type===`SpreadElement`)return n?.type===`RestElement`&&n.argument.type===`Identifier`&&e.argument.type===`Identifier`&&e.argument.name===n.argument.name?n.argument.name:void 0;let r=n?.type===`RestElement`&&n.argument.type===`Identifier`?n.argument.name:void 0;return e.type===`Identifier`&&e.name!==r?e.name:void 0}function qo(e){let t=Wo(e),n=G(e);if(i.isUndefined(t)||e.async||e.generator||e.typeParameters||!r.isReadonlyArrayNonEmpty(t)||n?.type!==`CallExpression`||n.optional)return;let a=new Set(t);if(n.callee.type===`Super`||Go(n.callee,a))return;let o=[];for(let t of n.arguments){let n=Ko(t,e);if(i.isNotUndefined(n)&&a.has(n))o.push(n);else if(j(t)||Go(t,a))return}if(o.length===t.length&&r.every(o,(e,n)=>e===t[n]))return{call:n,exact:n.arguments.length===t.length}}function Jo(e){return e.returnType?.typeAnnotation.type===`TSTypePredicate`}function Yo(e,t){let n=D(e.type===`CallExpression`?e.callee:e,t);return n?.length===2&&(n[0]===`Schema`?n[1]===`is`:/^is\p{Lu}/u.test(n[1]??``))}function Xo(e,t){return e.type===`Identifier`?!0:e.type===`MemberExpression`?i.isNotUndefined(D(e,t)):e.type===`CallExpression`&&e.callee.type!==`Identifier`&&Xo(e.callee,t)}const Zo=/* @__PURE__ */ new Set([`Array`,`Chunk`,`HashMap`,`HashSet`,`Iterable`,`MutableHashMap`,`MutableHashSet`,`MutableList`,`Record`,`Trie`,`Tuple`,`TxChunk`,`TxHashMap`]),Qo=/* @__PURE__ */ new Set(/* @__PURE__ */ `Channel.acquireRelease,Channel.acquireUseRelease,Channel.catchCauseFilter,Channel.catchReason,Channel.combine,Channel.filterArrayEffect,Channel.fromTransform,Channel.fromTransformBracket,Channel.map,Channel.mapAccum,Channel.mapEffect,Channel.runFold,Channel.runFoldEffect,Channel.scan,Channel.scanEffect,Channel.transformPull,Combiner.make,Duration.matchPair,Effect.acquireRelease,Effect.acquireUseRelease,Effect.catchCauseFilter,Effect.catchReason,Effect.effectify,Effect.filter,Effect.findFirst,Effect.findFirstFilter,Effect.forEach,Effect.onErrorFilter,Effect.onExitFilter,Effect.partition,Effect.reduce,Effect.repeatOrElse,Effect.retryOrElse,Effect.tapCauseFilter,Effect.validate,Effect.zipWith,Equivalence.make,Filter.zipWith,Graph.complement,Graph.findEdge,Graph.findEdges,Graph.floydWarshall,Layer.fromBuild,Layer.fromBuildMemo,Metric.mapInput,Optic.fromChecks,Optic.makeLens,Optic.makeOptional,Option.containsWith,Option.lift2,Option.reduceCompact,Option.zipWith,Order.make,Reducer.make,RequestResolver.around,RequestResolver.make,RequestResolver.makeGrouped,RequestResolver.makeWith,Schema.makeFilter,Schema.makeIsMultipleOf,Schema.middlewareDecoding,Schema.middlewareEncoding,SchemaGetter.checkEffect,SchemaGetter.fail,SchemaGetter.transformEffect,SchemaGetter.transformOptionalEffect,SchemaTransformation.transformEffect,Sink.fold,Sink.foldArray,Sink.foldUntil,Sink.fromTransform,Sink.reduce,Sink.reduceArray,Sink.reduceEffect,Sink.reduceWhile,Sink.reduceWhileArray,Sink.reduceWhileArrayEffect,Sink.reduceWhileEffect,Sink.summarized,Stream.catchCauseFilter,Stream.catchReason,Stream.changesWith,Stream.changesWithEffect,Stream.combine,Stream.combineArray,Stream.crossWith,Stream.dropUntil,Stream.dropUntilEffect,Stream.dropWhile,Stream.dropWhileEffect,Stream.filterEffect,Stream.map,Stream.mapAccum,Stream.mapAccumArray,Stream.mapAccumArrayEffect,Stream.mapAccumEffect,Stream.mapArray,Stream.mapArrayEffect,Stream.mapEffect,Stream.runFold,Stream.runFoldEffect,Stream.scan,Stream.scanEffect,Stream.takeUntil,Stream.takeUntilEffect,Stream.takeWhile,Stream.takeWhileEffect,Stream.transformPull,Stream.transformPullBracket,Stream.zipLatestWith,Stream.zipWith,Stream.zipWithArray,TextDiff.diffWith,TxHashSet.reduce`.split(`,`)),$o=/* @__PURE__ */ new Set([`Match`]);function es(e,t){let n=D(e.callee,t);return i.isNotUndefined(n)&&r.isReadonlyArrayNonEmpty(n)&&n.length===2&&!Zo.has(r.headNonEmpty(n))&&!$o.has(r.headNonEmpty(n))&&!Qo.has(r.join(n,`.`))}function ts(e,t,n){let o=n.parent;if(o.type!==`CallExpression`||!r.contains(o.arguments,n)||!es(o,t))return;let s=qo(n);if(i.isUndefined(s)||!s.exact||!Xo(s.call.callee,t)||Jo(n)&&!Yo(s.call.callee,t))return;let c=e.sourceCode.getText(s.call.callee);e.report({node:n,messageId:`forwardingLambda`,data:{callee:a.includes(`
3
- `)(c)?`the callee`:`\`${c}\``}})}const ns=b(x(`suggestion`,`Disallow Effect callbacks that only forward their parameters to another function.`,{forwardingLambda:`This callback only passes its parameters to {{callee}}. Pass {{callee}} directly.`}),(e,t)=>({ArrowFunctionExpression(n){ts(e,t(),n)},FunctionExpression(n){ts(e,t(),n)}})),rs=[`Effect`,`fn`];function is(e,t){let n=F(e);return j(n)||n.type===`CallExpression`&&(A(n.callee,t,rs)||n.callee.type===`CallExpression`&&A(n.callee.callee,t,rs))}function as(e,t){if(e.type===`FunctionDeclaration`&&e.id&&e.body)return[{declaration:e,typed:Jo(e)||!!e.typeParameters,name:e.id}];if(e.type!==`VariableDeclaration`)return[];let n=[];for(let r of e.declarations){if(r.id.type!==`Identifier`||!r.init||!is(r.init,t))continue;let e=F(r.init);n.push({declaration:r,typed:j(e)&&(Jo(e)||!!e.typeParameters),name:r.id})}return n}function os(e){let t=/* @__PURE__ */ new Set;for(let n of e.body){if(n.type===`ExportNamedDeclaration`&&!n.source)for(let e of n.specifiers)t.add(v(e.local));n.type===`ExportDefaultDeclaration`&&n.declaration.type===`Identifier`&&t.add(n.declaration.name)}return t}function ss(e){let[t]=e.options;return t?.maxLines??3}const cs=b({...x(`suggestion`,`Disallow short non-exported top-level functions that are used only once.`,{singleUse:"`{{name}}` is only used once and not exported. Inline it where it is used instead of keeping a one-off helper."}),schema:[{type:`object`,properties:{maxLines:{type:`integer`,minimum:1}},additionalProperties:!1}]},(e,t)=>({Program(n){if(a.endsWith(`.d.ts`)(e.filename))return;let i=ss(e),o=os(n);for(let s of n.body)for(let{declaration:n,typed:c,name:u}of as(s,t())){let t=e.sourceCode.getText(n);if(c||o.has(u.name)||/^\p{Lu}|^use\p{Lu}/u.test(u.name)||a.split(t,`
4
- `).length>i||t.length>i*120)continue;let s=r.findFirst(e.sourceCode.getDeclaredVariables(n),e=>e.name===u.name).pipe(l.map(e=>r.filter(e.references,e=>!e.init)),l.getOrElse(r.empty));s.length===1&&!r.some(s,e=>_e(n,e.identifier))&&e.report({node:u,messageId:`singleUse`,data:{name:u.name}})}}}));function ls(e,t){let n=a.replaceAll(/\s+/gu,` `)(t.sourceCode.getText(e.callee));return n.length>60?`${a.slice(0,59)(n)}…`:n}function us(e,t,n,a){let o=qo(n),s=o?.call.callee;!i.isUndefined(o)&&!i.isUndefined(s)&&(!Jo(n)||Yo(s,t)&&!r.some(n.params,e=>e.type===`Identifier`&&i.isNotNullish(e.typeAnnotation)&&e.typeAnnotation.typeAnnotation.type!==`TSUnknownKeyword`))&&Xo(s,t)&&(o.exact||k(s,t,`Match`,[`valueTags`])||k(s,t,`Function`,[`pipe`])&&o.call.arguments.length===2)&&e.report({node:a,messageId:o.exact?`forwardsParameters`:`forwardsWithArguments`,data:{name:a.name,callee:ls(o.call,e)}})}const ds=b(x(`suggestion`,`Disallow named functions that only forward their parameters to another call.`,{forwardsParameters:"`{{name}}` only passes its parameters to `{{callee}}`. Call `{{callee}}` directly, or assign it to a constant instead of wrapping it.",forwardsWithArguments:"`{{name}}` only passes its parameters to `{{callee}}` with fixed arguments. Call it inline, or hoist a constant built from those arguments, such as `Match.typeTags` or `Schema.is(Schema)`."}),(e,t)=>({FunctionDeclaration(n){n.id&&n.body&&us(e,t(),n,n.id)},VariableDeclarator(n){n.id.type===`Identifier`&&n.init&&j(n.init)&&us(e,t(),n.init,n.id)}})),fs=/* @__PURE__ */ new Set([`replace`,`replaceAll`,`slice`,`split`,`substr`,`substring`]),ps=[`replace`,`replaceAll`,`slice`,`split`,`substring`,`takeLeft`,`takeRight`],ms=[`split`,`takeLeft`,`takeRight`],hs=[`flow`,`pipe`];function X(e){let t=F(e);return t.type===`ChainExpression`?t.expression:t}function gs(e,t){return O(X(e),t,`DateTime`,`formatIso`)}function _s(e,t){if(i.isUndefined(e))return!1;let n=X(e);if(n.type!==`CallExpression`)return!1;let a=X(n.callee);return a.type===`MemberExpression`&&S(a)===`toISOString`&&!r.isReadonlyArrayNonEmpty(n.arguments)||gs(a,t)}function vs(e,t){if(i.isUndefined(e))return!1;let n=X(e);return n.type===`CallExpression`&&k(n.callee,t,`String`,ps)}function ys(e,t){return k(e,t,`Function`,hs)||A(e,t,[`pipe`])||A(e,t,[`flow`])}function bs(e,t){let n=X(e.callee),i=r.filter(e.arguments,e=>e.type!==`SpreadElement`);if(i.length===e.arguments.length)return n.type===`MemberExpression`&&n.object.type!==`Super`&&S(n)===`pipe`?[n.object,...i]:ys(n,t)?i:void 0}function xs(e,t){let n=X(e.callee);if(n.type===`MemberExpression`&&fs.has(S(n)??``)&&_s(n.object,t)||e.arguments.length===2&&k(n,t,`String`,ms)&&_s(M(e,0),t)||e.arguments.length===1&&vs(n,t)&&_s(M(e,0),t))return e;let a=bs(e,t);if(!i.isUndefined(a))return s.pipe(r.zip(a,r.drop(a,1)),r.findFirst(([e,n])=>vs(n,t)&&(_s(e,t)||gs(e,t))),l.map(([,e])=>e),l.getOrUndefined)}const Ss=b(x(`problem`,`Disallow slicing or rewriting a UTC ISO string to get a local date or time.`,{utcIsoSlicing:`toISOString() and DateTime.formatIso give UTC, so slicing or rewriting them gives the UTC date and time: in Europe/Amsterdam the previous day between 00:00 and 02:00, and +00:00 instead of +01:00/+02:00. Format in an explicit zone instead: DateTime.setZone with DateTime.formatIsoDate, formatIsoOffset or formatIsoZoned, or Intl.DateTimeFormat with timeZone.`},`https://www.effect.website/docs/v4/api/effect/DateTime`),(e,t)=>({CallExpression(n){let r=xs(n,t());i.isNotUndefined(r)&&e.report({node:r,messageId:`utcIsoSlicing`})}})),Cs=String.raw`(?:\r\n|\r(?!\n)|[\n\u2028\u2029])`,ws=String.raw`[^\S\r\n\u2028\u2029]*`,Ts=RegExp(`^(${ws}${Cs})(?:${ws}${Cs})+(${ws};?)$`,`u`),Es=/^(?:module\s*\.\s*)?exports(?:\s*\.|\s*\[|$)/u,Ds=/* @__PURE__ */ new Set([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`]),Os=/* @__PURE__ */ new Set([`any`,`never`,`always`]),ks=/* @__PURE__ */ new Set([`any`,`singleline`,`multiline`]),As=/* @__PURE__ */ new Set([`blankLine`,`prev`,`next`]),js=/* @__PURE__ */ new Set([`selector`,`lineMode`]);function Ms(e){return e.type===`Punctuator`&&e.value===`;`}function Ns(e,t){return e.loc.end.line===t.loc.start.line}function Ps(e){return e.loc.start.line===e.loc.end.line}function Fs(e){return Ds.has(e.type)}function Is(e){return e.type===`ChainExpression`?e.expression:e}function Z(e,t){let n=new Set(r.ensure(e));return(e,r)=>r.getFirstToken(e)?.value===t&&n.has(e.type)}function Ls(e){return t=>t.type===e}function Q(e,t){return(n,r)=>e(n,r)&&Ps(n)===(t===`singleline`)}function Rs(e){if(e.type!==`ExpressionStatement`)return!1;let t=Is(e.expression);if(t.type===`UnaryExpression`&&(t=Is(t.argument)),t.type!==`CallExpression`)return!1;let n=t.callee;for(;n.type===`SequenceExpression`;)n=l.getOrThrowWith(r.last(n.expressions),()=>/* @__PURE__ */ Error(`Padding rule invariant: sequence expression is empty`));return Fs(n)}function zs(e){if(e.type!==`VariableDeclaration`)return!1;let t=l.getOrUndefined(r.head(e.declarations))?.init;if(i.isNullish(t))return!1;for(;t.type===`MemberExpression`;)t=t.object;return t.type===`CallExpression`&&t.callee.type===`Identifier`&&t.callee.name===`require`}function Bs(e,t){if(e.type===`DoWhileStatement`&&e.body.type===`BlockStatement`||Rs(e))return!0;let n=t.getLastToken(e,e=>!Ms(e)),r=n?.type===`Punctuator`&&n.value===`}`?t.getNodeByRangeIndex(p.get(n.range,0)):null;return r?.type===`BlockStatement`||r?.type===`SwitchStatement`}function Vs(e,t){return e.type===`ExpressionStatement`&&(e.parent.type===`Program`||e.parent.type===`BlockStatement`&&Fs(e.parent.parent))&&e.expression.type===`Literal`&&i.isString(e.expression.value)&&(t.getTokenBefore(e.expression)?.value!==`(`||t.getTokenAfter(e.expression)?.value!==`)`)}function Hs(e,t){if(!Vs(e,t)||!e.parent||!(`body`in e.parent)||!r.isArray(e.parent.body))return!1;let n=e.parent.body;return s.pipe(n,r.takeWhile(t=>t!==e),r.every(e=>Vs(e,t)))}function Us(e){if(e.type!==`ExpressionStatement`||e.expression.type!==`AssignmentExpression`)return!1;let t=e.expression.left;if(t.type!==`MemberExpression`)return!1;for(;t.object.type===`MemberExpression`;)t=t.object;return t.object.type===`Identifier`&&(t.object.name===`exports`||t.object.name===`module`&&t.property.type===`Identifier`&&t.property.name===`exports`)}function Ws(e,t){let n=l.getOrThrowWith(l.fromNullOr(t.getLastToken(e)),()=>/* @__PURE__ */ Error(`Padding rule invariant: statement has no token`)),r=t.getTokenBefore(n),i=t.getTokenAfter(n);return r&&i&&p.get(r.range,0)>=p.get(e.range,0)&&Ms(n)&&!Ns(r,n)&&Ns(n,i)?r:n}function Gs(e,t){if(Ps(e))return e.loc;let n=e.loc.start.line,i=l.getOrThrowWith(r.get(t.lines,n-1),()=>/* @__PURE__ */ Error(`Padding rule invariant: statement source line is missing`));return{start:e.loc.start,end:{line:n,column:i.length}}}const Ks=c.type().pipe(c.when({type:`VariableDeclaration`,kind:c.is(`using`,`await using`)},s.constTrue),c.orElse(s.constFalse)),$={"block-like":Bs,expression:(e,t)=>e.type===`ExpressionStatement`&&!Hs(e,t),return:Z(`ReturnStatement`,`return`),export:Z([`ExportAllDeclaration`,`ExportDefaultDeclaration`,`ExportNamedDeclaration`],`export`),var:Z(`VariableDeclaration`,`var`),let:Z(`VariableDeclaration`,`let`),const:Z(`VariableDeclaration`,`const`),using:Ks,type:Z(`TSTypeAliasDeclaration`,`type`)},qs={"*":()=>!0,exports:Us,require:zs,directive:Hs,iife:Rs,block:Ls(`BlockStatement`),empty:Ls(`EmptyStatement`),function:Ls(`FunctionDeclaration`),"ts-method":Ls(`TSMethodSignature`),break:Z(`BreakStatement`,`break`),case:Z(`SwitchCase`,`case`),class:Z(`ClassDeclaration`,`class`),continue:Z(`ContinueStatement`,`continue`),debugger:Z(`DebuggerStatement`,`debugger`),default:Z([`SwitchCase`,`ExportDefaultDeclaration`],`default`),do:Z(`DoWhileStatement`,`do`),for:Z([`ForStatement`,`ForInStatement`,`ForOfStatement`],`for`),if:Z(`IfStatement`,`if`),import:Z(`ImportDeclaration`,`import`),switch:Z(`SwitchStatement`,`switch`),throw:Z(`ThrowStatement`,`throw`),try:Z(`TryStatement`,`try`),while:Z([`WhileStatement`,`DoWhileStatement`],`while`),with:Z(`WithStatement`,`with`),"cjs-export":(e,t)=>e.type===`ExpressionStatement`&&e.expression.type===`AssignmentExpression`&&Es.test(t.getText(e.expression.left)),"cjs-import":(e,t)=>e.type===`VariableDeclaration`&&l.exists(r.head(e.declarations),({init:e})=>i.isNotNullish(e)&&a.startsWith(`require(`)(t.getText(e))),enum:Z(`TSEnumDeclaration`,`enum`),interface:Z(`TSInterfaceDeclaration`,`interface`),"function-overload":Ls(`TSDeclareFunction`),...$,"singleline-block-like":Q($[`block-like`],`singleline`),"multiline-block-like":Q($[`block-like`],`multiline`),"singleline-expression":Q($.expression,`singleline`),"multiline-expression":Q($.expression,`multiline`),"singleline-return":Q($.return,`singleline`),"multiline-return":Q($.return,`multiline`),"singleline-export":Q($.export,`singleline`),"multiline-export":Q($.export,`multiline`),"singleline-var":Q($.var,`singleline`),"multiline-var":Q($.var,`multiline`),"singleline-let":Q($.let,`singleline`),"multiline-let":Q($.let,`multiline`),"singleline-const":Q($.const,`singleline`),"multiline-const":Q($.const,`multiline`),"singleline-using":Q($.using,`singleline`),"multiline-using":Q($.using,`multiline`),"singleline-type":Q($.type,`singleline`),"multiline-type":Q($.type,`multiline`)};function Js(e){return ks.has(e)}function Ys(e){return Os.has(e)}function Xs(e){return i.isString(e)&&n.has(qs,e)}function Zs(e){return r.isArray(e)}function Qs(e){if(Xs(e))return e;if(i.isObject(e)&&i.isString(e.selector)&&r.every(n.keys(e),e=>js.has(e))){if(!(`lineMode`in e))return{selector:e.selector};if(Js(e.lineMode))return{selector:e.selector,lineMode:e.lineMode}}throw Error(`Invalid padding-line-between-statements statement matcher`)}function $s(e){if(!r.isArray(e))return Qs(e);let t=e;if(!r.isReadonlyArrayNonEmpty(t))throw Error(`Padding statement matcher arrays must not be empty`);return r.map(t,e=>Qs(e))}function ec(e){return r.map(e,e=>{if(!i.isObject(e)||!(`blankLine`in e)||!(`prev`in e)||!(`next`in e)||r.some(n.keys(e),e=>!As.has(e))||!Ys(e.blankLine))throw Error(`Invalid padding-line-between-statements configuration`);return{blankLine:e.blankLine,prev:$s(e.prev),next:$s(e.next)}})}function tc(e,t,n){let r=[],i=Ws(e,n);if(t.loc.start.line-i.loc.end.line>=2)do{let e=l.getOrThrowWith(l.fromNullOr(n.getTokenAfter(i,{includeComments:!0})),()=>/* @__PURE__ */ Error(`Padding rule invariant: next statement token is missing`));e.loc.start.line-i.loc.end.line>=2&&r.push([i,e]),i=e}while(p.get(i.range,0)<p.get(t.range,0));return r}function nc(e,t,n){return o.gen(function*(){if(n===`any`)return yield*o.void;let i=yield*te,c=i.sourceCode,l=tc(e,t,c);return n===`never`?r.isArrayNonEmpty(l)?yield*i.report({node:t,messageId:`unexpectedBlankLine`,loc:Gs(t,c),fix(e){if(l.length>=2)return null;let t=r.headNonEmpty(l),n=p.get(t[0].range,1),i=p.get(t[1].range,0);return e.replaceTextRange([n,i],s.pipe(c.text,a.slice(n,i),a.replace(Ts,`$1$2`)))}}):yield*o.void:r.isArrayNonEmpty(l)?yield*o.void:yield*i.report({node:t,messageId:`expectedBlankLine`,loc:Gs(t,c),fix(n){let r=Ws(e,c),i=c.getFirstTokenBetween(r,t,{includeComments:!0,filter(e){return!Ns(r,e)||(r=e,!1)}})??t;return n.insertTextAfter(r,Ns(r,i)?`
1
+ import{AST as e,Diagnostic as t,Plugin as n,Rule as r,RuleContext as i,Scope as a,SourceCode as o,Visitor as s}from"effect-oxlint";import*as c from"effect/Array";import*as l from"effect/Record";import*as u from"effect/Struct";import*as d from"effect/Effect";import*as f from"effect/Option";import*as p from"effect/Ref";import*as m from"effect/Schema";import*as h from"effect/String";import*as g from"effect/Function";import*as _ from"effect/Match";import*as v from"effect/Tuple";import*as y from"effect/Equivalence";import*as b from"effect/Predicate";import*as x from"effect/HashSet";import*as ee from"effect/Result";import*as S from"effect/Duration";import*as te from"effect/Number";import*as ne from"effect/HashMap";import*as re from"effect/Order";import*as ie from"effect/http/HttpMethod";import*as ae from"effect/http/HttpStatus";const oe=m.Literals([`ParenthesizedExpression`,`TSAsExpression`,`TSNonNullExpression`,`TSSatisfiesExpression`,`TSTypeAssertion`]),se=m.is(oe),ce=m.Literals([`==`,`===`,`!=`,`!==`]),le=m.is(ce),ue=m.Literals([`ArrowFunctionExpression`,`FunctionExpression`]),de=m.is(ue),fe=_.type().pipe(_.discriminatorsExhaustive(`type`)({Identifier:({name:e})=>e,Literal:({value:e})=>e})),C=_.type().pipe(_.when({computed:!1,property:{type:`Identifier`}},({property:e})=>f.some(e.name)),_.when({computed:!0,property:{type:`Literal`,value:h.isString}},({property:e})=>f.some(e.value)),_.orElse(()=>f.none()));function w(e){let t=e.type===`ChainExpression`?e.expression:e;return t.type===`Identifier`?f.some(c.of(t.name)):t.type===`MemberExpression`?f.zipWith(w(t.object),C(t),(e,t)=>c.append(e,t)):f.none()}const T=_.type().pipe(_.when({computed:!1,key:{type:`Identifier`}},({key:e})=>f.some(e.name)),_.when({key:{type:`Literal`,value:h.isString}},({key:e})=>f.some(e.value)),_.orElse(()=>f.none())),pe=_.type().pipe(_.when({type:`Property`,computed:!1,method:!1,kind:`init`},f.some),_.orElse(()=>f.none())),E=g.dual(2,(e,t)=>c.findFirst(e.properties,e=>e.type===`Property`&&f.contains(T(e),t)));function D(e,t){return f.filter(c.get(e.arguments,t),e=>e.type!==`SpreadElement`)}function me(e){return c.findFirst(e.arguments,e=>e.type===`ObjectExpression`)}function he(e){return se(e.type)}function O(e){return he(e)?O(e.expression):e}const ge=/* @__PURE__ */ new Set([`loc`,`parent`,`range`]);function _e(e){return c.isArray(e)?e:c.map(c.filter(l.toEntries(e),([e])=>!ge.has(e)),([,e])=>e)}function ve(e){return b.hasProperty(e,`type`)&&b.isString(e.type)}function k(e,t){let n=[e],r=/* @__PURE__ */ new WeakSet;for(;c.isArrayNonEmpty(n);){let e=n.pop();if(b.isObjectOrArray(e)&&!r.has(e)){if(r.add(e),ve(e)&&t(e))return!0;n.push(..._e(e))}}return!1}function ye(e,t){return k(e,e=>e.type===`Identifier`&&e.name===t)}function A(e){return b.isNotNullish(e)&&de(e.type)}const be=_.type().pipe(_.when({type:`VariableDeclaration`,kind:`const`},g.constTrue),_.orElse(g.constFalse));function xe(e){return f.filter(c.head(e.params),e=>e.type===`Identifier`)}function Se(e){return f.exists(xe(e),t=>b.isNotNullish(e.body)&&!h.startsWith(`_`)(t.name)&&ye(e.body,t.name))}function j(e){return f.fromNullishOr(e.parent)}function M(t,n){return f.filter(j(t),t=>f.isSome(e.narrow(t,n)))}function Ce(e,t){return f.flatMap(j(e),e=>t(e)?f.some(e):Ce(e,t))}function we(e){return Ce(e,A)}function Te(e){return f.filter(M(e,`CallExpression`),t=>F(t.arguments,e))}function Ee(e,t){return e.range[0]<=t.range[0]&&t.range[1]<=e.range[1]}function N(e){return e.type===`Literal`&&h.isString(e.value)}const P=g.dual(2,(e,t)=>e.type===`Literal`&&e.value===t);function De(e){return f.exists(j(e),t=>t.type===`ExpressionStatement`||t.type===`UnaryExpression`&&t.operator===`void`||t.type===`SequenceExpression`&&f.exists(c.last(t.expressions),t=>t!==e))}function Oe(e){return w(e.callee).pipe(f.map(c.lastNonEmpty),f.exists(h.endsWith(`Error`)))}function F(e,t){return c.containsWith(y.strictEqual())(e,t)}function I(e,t){return f.containsWith(y.strictEqual())(e,t)}function L(e,t,n){return a.findVariableUp(e.getScope(t),n)}function ke(e,t){return d.map(o.getScope(e),a.findVariableUp(t))}function R(e){return e.pipe(f.filter(({defs:e})=>e.length===1),f.flatMap(({defs:e})=>c.head(e)))}function z(e,t,n){return t.type===`Identifier`&&t.name===n&&!f.exists(a.findVariableUp(e,n),({defs:e})=>c.isArrayNonEmpty(e))}function B(e,t){return e.type===`Identifier`&&e.name===t?d.map(o.getScope(e),n=>z(n,e,t)):d.succeed(!1)}function Ae(e,t){return w(t).pipe(f.flatMap(n=>L(e,t,c.headNonEmpty(n))),f.exists(({defs:e})=>c.some(e,({type:e,node:t})=>e===`ImportBinding`&&t.parent?.type===`ImportDeclaration`&&t.parent.importKind!==`type`&&(t.type!==`ImportSpecifier`||t.importKind!==`type`))))}function je(e){return d.map(d.service(i),({sourceCode:t})=>Ae(t,e))}const Me=d.map(d.service(i),({sourceCode:e})=>new Set(c.flatMap(e.scopeManager.scopes,e=>[...c.map(e.variables,({name:e})=>e),...c.map(e.references,({identifier:e})=>e.name)]))),Ne=m.Array(m.String),Pe=g.dual(2,(e,t)=>e.length===2&&f.contains(c.head(e),t)?c.get(e,1):f.none());var Fe=class extends m.Class(`ImportBindings`)({bindings:m.ReadonlyMap(m.String,Ne),hasEffectImport:m.Boolean}){path(e){return f.flatMap(w(e),([e,...t])=>f.fromNullishOr(this.bindings.get(e)).pipe(f.map(e=>[...e,...t])))}isApi(e,t,n){let r=h.isString(n)?[n]:n;return f.exists(this.member(e,t),e=>c.contains(r,e))}member(e,t){return f.flatMap(this.path(e),Pe(t))}isApiPath(e,t){return f.exists(this.path(e),e=>c.makeEquivalence(h.Equivalence)(e,t))}};const Ie=m.String.check(m.isPattern(/^(?:effect(?:\/.*)?|@effect\/.*)$/u)),Le=m.is(Ie);function Re(e){let t=c.lastNonEmpty(h.split(e,`/`));return/^\p{Ll}/u.test(t)?[]:[t]}const ze=_.type().pipe(_.when(`alchemy`,()=>f.some([`Alchemy`])),_.when(`@alchemy.run/domain`,()=>f.some([`Domain`])),_.when(_.is(`effect`,`@effect/platform`),()=>f.some([])),_.whenOr(h.startsWith(`effect/`),h.startsWith(`alchemy/`),h.startsWith(`@effect/`),e=>f.some(Re(e))),_.orElse(()=>f.none()));function Be(e,t){return c.map(e.specifiers,e=>v.make(e.local.name,e.type===`ImportSpecifier`?[...t,fe(e.imported)]:t))}function Ve(e){let t=c.filter(e.body,e=>e.type===`ImportDeclaration`);return Fe.make({bindings:new Map(c.flatMap(t,e=>f.match(ze(e.source.value),{onNone:()=>[],onSome:t=>Be(e,t)}))),hasEffectImport:c.some(t,e=>Le(e.source.value))})}function He(e,t,n){let r=c.flatMap(e.ast.body,e=>e.type===`ImportDeclaration`&&c.contains(n,e.source.value)?e.specifiers:[]),i=f.flatMap(w(t),([e,...t])=>f.flatMap(c.findFirst(r,({local:t})=>t.name===e),e=>e.type===`ImportSpecifier`?c.isReadonlyArrayEmpty(t)?f.some(fe(e.imported)):f.none():t.length===1?c.head(t):f.none()));return f.filter(i,()=>Ae(e,t))}const V=d.map(d.service(i),e=>Ve(e.sourceCode.ast));function H(e){let{url:t,docs:n,...i}=e;return r.meta({schema:[],...i,docs:{recommended:!0,...t===void 0?{}:{url:t},...n}})}const Ue=m.Literals([`Aggregate`,`Api`,`Command`,`Event`,`ExternalSystem`,`Model`,`Policy`,`Projection`,`Rejection`,`RequestContext`,`Saga`,`Stream`,`View`]),We=m.is(Ue);function Ge(e,t,n){return f.exists(R(L(e,t,n)),({type:e})=>e===`ImportBinding`)}function Ke(e,t){return w(e).pipe(f.filter(n=>Ge(t.sourceCode,e,c.headNonEmpty(n))),f.flatMap(()=>t.imports.path(e)))}function qe(e,t){return Ke(e.callee,t).pipe(f.flatMap(Pe(`Domain`)),f.filter(We))}function Je(e,t){let{parent:n}=e;return n.type===`MemberExpression`&&n.property===e&&!n.computed||n.type===`Property`&&n.key===e&&n.value!==e?!1:Ge(t,n,e.name)}function Ye(e){return b.isNotNull(e)&&se(e.type)?Ye(e.parent):e}function Xe(e,t){if(e.type!==`ObjectExpression`)return f.none();let n=Ye(e.parent);return n?.type===`CallExpression`&&f.exists(D(n,1),t=>O(t)===e)?qe(n,t):f.none()}function Ze(e,t){return f.flatMap(j(e),n=>{let r=n.type===`Property`&&n.value===e?Xe(n.parent,t):f.none();return f.match(r,{onNone:()=>Ze(n,t),onSome:e=>f.map(T(n),t=>({block:e,section:t}))})})}const Qe={Aggregate:`aggregate`,Api:`api`,Command:`command`,ExternalSystem:`external`,Model:`model`,Policy:`policy`,Projection:`projection`,RequestContext:`context`,Saga:`saga`,Stream:`stream`,View:`view`},$e={Event:`event`,Rejection:`rejection`},et=m.is(m.Literals([`command`,`external`,`stream`])),tt=m.String.check(m.isPattern(/\.(?:test|spec|stories?)\.[cm]?[jt]sx?$/u)),nt=m.is(tt),rt=r.define({name:`alchemy-domain-block-file-name`,meta:H({type:`suggestion`,description:"Require one Alchemy Domain block per file, named `<Noun>.<kind>.ts`.",messages:{fileName:"Declare this {{block}} in its own `<Noun>.{{kind}}.ts` file.",oneBlock:"Move this {{block}} to its own `<Noun>.{{kind}}.ts` file. Each file declares one Domain block."},url:`https://alchemy.run/domain`}),*create(){let e=yield*i,n={sourceCode:e.sourceCode,imports:yield*V},r=c.lastNonEmpty(h.split(e.filename,/[/\\]/u));if(nt(r))return{};let a=h.split(r,`.`),o=a.length>=3&&h.isNonEmpty(c.headNonEmpty(a))?c.get(a,a.length-2):f.none(),u=f.exists(o,et),m=yield*p.make(!1),g=yield*p.make(!1);function _(e){return e.type===`CallExpression`?f.flatMap(qe(e,n),t=>l.get(Qe,t).pipe(f.orElse(()=>l.get($e,t)),f.map(n=>({node:e.callee,block:t,kind:n})))):f.none()}function v({block:e}){return u&&l.has($e,e)}function y(n,{node:r,block:i,kind:a}){return e.report(t.fromId({node:r,messageId:n,data:{block:i,kind:a}}))}let b=yield*s.accumulate(`CallExpression`,e=>f.filter(_(e),v),e=>d.flatMap(p.get(g),t=>t?d.void:d.forEach(e,e=>y(`fileName`,e),{discard:!0}))),x=d.fnUntraced(function*(e){let t=f.contains(o,e.kind);t&&u&&(yield*p.set(g,!0)),(yield*p.getAndSet(m,!0))?yield*y(`oneBlock`,e):t||(yield*y(`fileName`,e))});return s.merge(b,s.on(`CallExpression`,e=>_(e).pipe(f.filter(e=>!v(e)),f.match({onNone:()=>d.void,onSome:x}))))}}),it={"Date.now":`time`,"performance.now":`time`,"performance.timeOrigin":`time`,"Math.random":`random`,"crypto.randomUUID":`random`,"crypto.getRandomValues":`random`},at={Clock:`time`,Random:`random`,SecureRandom:`random`},ot={"DateTime.now":`time`,"DateTime.nowAsDate":`time`,"DateTime.nowInCurrentZone":`time`,"DateTime.nowUnsafe":`time`,"DateTime.isFuture":`time`,"DateTime.isFutureUnsafe":`time`,"DateTime.isPast":`time`,"DateTime.isPastUnsafe":`time`,"Aead.Aead":`random`,"Cipher.Cipher":`random`,"Signature.Signature":`random`,"KeyAgreement.KeyAgreement":`random`,"KeyWrap.KeyWrap":`random`,"Jwk.generateKeyPair":`random`,"Jwk.generateSecret":`random`,"Jwe.encrypt":`random`,"Jws.sign":`random`,"Jws.verifyWithKeySet":`io`,"Jwt.sign":`random`,"Jwt.encrypt":`random`,"Jwt.verify":`time`,"Jwt.verifyWithKeySet":`time`,"Jwt.decrypt":`time`,"Jwks.Jwks":`io`,"Jwks.makeRemote":`io`,"Jwks.layerRemote":`io`},st=m.is(m.Literals([`promise`,`tryPromise`]));function ct(e){let t=e;for(;t.type===`MemberExpression`||t.type===`ChainExpression`;)t=t.type===`ChainExpression`?t.expression:t.object;return t}const lt=r.define({name:`alchemy-domain-pure-decide`,meta:H({type:`problem`,description:`Require Alchemy Domain aggregate decide handlers to be pure.`,messages:{time:"`decide` reads time from its `now` argument, not {{api}}. Replays must decide the same way.",random:"`decide` must be deterministic, so it cannot use {{api}}. Take the value from the command input instead.",io:"`decide` never performs I/O such as {{api}}. Call external systems from a policy or saga and send the result as a command."},url:`https://alchemy.run/domain/aggregate`}),*create(){let e=yield*i,n={sourceCode:e.sourceCode,imports:yield*V};function r(t,n){return z(e.sourceCode.getScope(t),t,n)}function a(r,i,a){return i.pipe(f.filter(()=>f.exists(Ze(r,n),({section:e})=>e===`decide`)),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:r,messageId:n,data:{api:a}}))}))}function o(e){return Ke(e,n).pipe(f.filter(e=>e.length===2),f.match({onNone:()=>d.void,onSome:t=>{let n=c.join(t,`.`);return a(e,f.orElse(l.get(ot,n),()=>f.flatMap(c.head(t),e=>l.get(at,e))),n)}}))}function u(e){return e.type===`Identifier`?r(e,e.name)?f.some(e.name):f.none():e.type===`MemberExpression`&&r(e.object,`globalThis`)?w(e).pipe(f.filter(e=>e.length===2),f.flatMap(e=>c.get(e,1))):f.none()}return s.merge(s.on(`MemberExpression`,e=>{let t=f.getOrElse(w(e),()=>[]),n=c.head(t),i=f.contains(n,`globalThis`)?t.slice(1):t,s=ct(e);if(i.length!==2||!f.exists(n,e=>r(s,e)))return o(e);let u=c.join(i,`.`),d=e.parent.type===`CallExpression`&&e.parent.callee===e;return a(e,l.get(it,u),d?`${u}()`:u)}),s.on(`Identifier`,t=>Je(t,e.sourceCode)?o(t):d.void),s.on(`NewExpression`,e=>c.isReadonlyArrayEmpty(e.arguments)&&f.contains(u(e.callee),`Date`)?a(e,f.some(`time`),`new Date()`):d.void),s.on(`CallExpression`,e=>_.value(f.getOrElse(u(e.callee),()=>``)).pipe(_.when(`Date`,()=>a(e,f.some(`time`),`Date()`)),_.when(`fetch`,()=>a(e,f.some(`io`),`fetch()`)),_.orElse(()=>Ke(e.callee,n).pipe(f.flatMap(Pe(`Effect`)),f.filter(st),f.match({onNone:()=>d.void,onSome:t=>a(e,f.some(`io`),`Effect.${t}`)}))))))}}),ut=m.String.check(m.isPattern(/\.(?:aggregate|api|command|context|event|external|id|middleware|model|policy|projection|rejection|saga|stream|view)\.[cm]?tsx?$/u)),dt=m.is(ut),ft=`@alchemy.run/domain`;function pt(e){return h.startsWith(`.`)(e)||e===`effect`||h.startsWith(`effect/`)(e)||e===ft||h.startsWith(`${ft}/`)(e)}function mt(e){return c.some(e.body,e=>e.type===`ImportDeclaration`&&e.source.value===ft)}const ht=r.define({name:`alchemy-domain-pure-imports`,meta:H({type:`problem`,description:"Restrict Alchemy Domain block files to imports from `@alchemy.run/domain`, `effect` and the domain package itself.",messages:{import:"A domain block imports only `@alchemy.run/domain`, `effect` and relative files, not `{{source}}`. Put code that touches infrastructure in the server package.",dynamic:"A domain block imports only `@alchemy.run/domain`, `effect` and relative files, so its import sources must be string literals."},url:`https://alchemy.run/domain`}),*create(){let e=yield*i;if(!dt(e.filename)||!mt(e.sourceCode.ast))return{};function n(n,r){return pt(r)?d.void:e.report(t.fromId({node:n,messageId:`import`,data:{source:r}}))}function r(e){return b.isNull(e.source)?d.void:n(e.source,e.source.value)}function a(r){return N(r)?n(r,r.value):e.report(t.fromId({node:r,messageId:`dynamic`}))}return s.merge(s.on(`ImportDeclaration`,r),s.on(`ExportAllDeclaration`,r),s.on(`ExportNamedDeclaration`,r),s.on(`ImportExpression`,e=>a(e.source)),s.on(`TSImportEqualsDeclaration`,e=>e.moduleReference.type===`TSExternalModuleReference`?a(e.moduleReference.expression):d.void),s.on(`CallExpression`,e=>f.match(D(e,0),{onNone:()=>d.void,onSome:t=>d.flatMap(B(e.callee,`require`),e=>e?a(t):d.void)})))}});function gt(e,t){return c.some(e.properties.slice(e.properties.indexOf(t)+1),e=>e.type===`SpreadElement`)}const _t=r.define({name:`alchemy-domain-require-view-version`,meta:H({type:`suggestion`,description:`Require Alchemy Domain views to declare their version.`,messages:{missing:"Declare `version` on this view (`version: 0` keeps the current default). Bump it whenever `evolve`, `emit`, `keyOf`, `state` or `from` changes, so the deploy rebuilds the view from its events.",overridden:"Move `version` after the spread, so the spread cannot override the version this view declares."},url:`https://alchemy.run/domain/model#change-a-view-bump-its-version`}),*create(){let e=yield*i,n={sourceCode:e.sourceCode,imports:yield*V};function r(n,r){return f.match(E(r,`version`),{onNone:()=>e.report(t.fromId({node:n.callee,messageId:`missing`})),onSome:n=>gt(r,n)?e.report(t.fromId({node:n,messageId:`overridden`})):d.void})}return s.on(`CallExpression`,e=>D(e,1).pipe(f.map(O),f.filter(e=>e.type===`ObjectExpression`),f.filter(()=>f.contains(qe(e,n),`View`)),f.match({onNone:()=>d.void,onSome:t=>r(e,t)})))}}),vt={Aggregate:[`evolve`,`reply`],View:[`evolve`]},yt=m.is(m.Literals([`Option`,`Result`])),bt=m.is(m.Literals([`getOrThrow`,`getOrThrowWith`])),xt=r.define({name:`alchemy-domain-total-handlers`,meta:H({type:`problem`,description:`Require Alchemy Domain evolve and reply handlers to be total, and decide handlers to reject instead of throwing.`,messages:{partial:'`{{section}}` must be total and never fail: {{api}} throws when the state is not what it expects. Keep any state the event cannot follow, such as `s._tag === "Open" ? { ...s, ... } : s`.',reject:"`decide` never throws: {{api}} becomes a defect the caller cannot handle. Return a rejection the command lists in `rejects` instead, or `return yield* rejection` in an `Effect.fn`."},url:`https://alchemy.run/domain/aggregate`}),*create(){let e=yield*i,n={sourceCode:e.sourceCode,imports:yield*V};function r(r,i){return f.match(Ze(r,n),{onNone:()=>d.void,onSome:({block:n,section:a})=>n===`Aggregate`&&a===`decide`?e.report(t.fromId({node:r,messageId:`reject`,data:{api:i}})):f.exists(l.get(vt,n),c.contains(a))?e.report(t.fromId({node:r,messageId:`partial`,data:{section:a,api:i}})):d.void})}function a(e){return Ke(e,n).pipe(f.filter(e=>e.length===2&&f.exists(c.head(e),yt)&&f.exists(c.get(e,1),bt)),f.match({onNone:()=>d.void,onSome:t=>r(e,`\`${c.join(t,`.`)}\``)}))}return s.merge(s.on(`ThrowStatement`,e=>r(e,"`throw`")),s.on(`MemberExpression`,a),s.on(`Identifier`,t=>Je(t,e.sourceCode)?a(t):d.void))}}),St=m.Literals([`alarm`,`fetch`,`queue`,`rpc`,`scheduled`,`tail`,`trace`,`webSocketClose`,`webSocketError`,`webSocketMessage`]),Ct=m.is(St),wt=[[`Cloudflare`,`Worker`],[`Cloudflare`,`Workers`,`Worker`]];function Tt(e,t){return c.some(wt,n=>t.isApiPath(e,n))}function Et(e,t){return Ce(e,e=>e.type===`CallExpression`&&Tt(e.callee,t))}function Dt(e,t){return we(e).pipe(f.flatMap(Te),f.filter(e=>t.isApi(e.callee,`Effect`,`gen`)))}function Ot(e){return f.flatMap(j(e),e=>{if(A(e))return f.none();let t=e.type===`Property`?f.filter(T(e),Ct):f.none();return f.orElse(t,()=>Ot(e))})}const kt=r.define({name:`alchemy-no-cloudflare-init-finalizer`,meta:H({type:`problem`,description:`Disallow finalizers in Cloudflare Worker initialization, where workerd never runs them.`,messages:{finalizer:`A Cloudflare Worker init finalizer never runs because workerd has no isolate teardown hook. Acquire disposable resources inside an event handler.`},url:`https://alchemy.run/cloudflare/compute/workers`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Effect`,`addFinalizer`)&&f.exists(Dt(r,n),e=>f.exists(Et(e,n),t=>F(t.arguments,e)))?e.report(t.fromId({node:r,messageId:`finalizer`})):d.void)}});function At(e,t,n){let r=c.flatMap(t.body,e=>e.type===`ImportDeclaration`&&e.source.value===n&&e.importKind!==`type`?c.filter(e.specifiers,e=>e.type===`ImportNamespaceSpecifier`):[]);return d.map(d.filter(r,t=>d.map(ke(e,t.local.name),e=>f.exists(e,({defs:e})=>c.some(e,e=>e.node===t)))),e=>f.map(c.head(e),e=>e.local.name))}function jt(e,t,n=1){let r=n===1?e:`${e}${n}`;return t.has(r)?jt(e,t,n+1):r}function Mt(e,n){return f.match(c.findFirst(e.body,e=>e.type!==`ExpressionStatement`||!N(e.expression)),{onNone:()=>t.insertAfter(e,`\n${n}`),onSome:e=>t=>t.insertTextBefore(e,n)})}const Nt=d.fn(`namespaceImport`)(function*(e,t,n){let{sourceCode:r}=yield*i,a=r.ast,o=yield*At(e,a,t);if(f.isSome(o))return{name:o.value,fix:f.none()};let s=jt(n,yield*Me);return{name:s,fix:f.some(Mt(a,`import * as ${s} from '${t}';\n`))}}),Pt=d.fn(`replaceWithNamespace`)(function*(e,n,r,i){let a=yield*Nt(e,n,r);return t.composeFixes(...f.toArray(a.fix),t.replaceText(e,i(a.name)))});function U(e,t){let n=e.getText(t);return t.type===`SequenceExpression`?`(${n})`:n}function Ft(e,t){let n=c.map(e.properties,e=>pe(e).pipe(f.filter(e=>e.key.type===`Identifier`||e.key.type===`Literal`),f.flatMap(e=>e.key.type===`Literal`?f.some(String(e.key.value)):T(e)))),r=c.getSomes(n);return r.length===n.length&&!c.contains(r,t)&&c.dedupe(r).length===r.length}function It(e,n){return f.match(n,{onNone:()=>e,onSome:n=>t.withFix(e,n)})}const Lt=r.define({name:`alchemy-no-deprecated-docker-constraints`,meta:H({type:`problem`,description:`Disallow the deprecated top-level Docker Service constraints property.`,messages:{constraints:`Docker.Service constraints is deprecated. Move it to placement: { constraints: ... }.`},url:`https://alchemy.run/providers/docker/service`,fixable:`code`}),*create(){let e=yield*i,n=yield*V,r=d.fnUntraced(function*(n,r,i){let a=yield*je(n.callee),o=f.liftPredicate(t.replaceText(i,`placement: { ${e.sourceCode.getText(i)} }`),()=>a&&Ft(r,`placement`));yield*e.report(It(t.fromId({node:i,messageId:`constraints`}),o))});return s.on(`CallExpression`,e=>n.isApi(e.callee,`Docker`,`Service`)?f.filter(D(e,1),e=>e.type===`ObjectExpression`).pipe(f.flatMap(e=>f.map(E(e,`constraints`),t=>[e,t])),f.match({onNone:()=>d.void,onSome:([t,n])=>r(e,t,n)})):d.void)}}),Rt={"Cloudflare.Access.Bookmark":`Cloudflare.Access.Application with type: "bookmark"`,"AWS.RDSData.ExecuteSql":`AWS.RDSData.ExecuteStatement`,"AWS.EKS.Deployment":`Kubernetes.Deployment from alchemy/Kubernetes`,"AWS.EKS.HelmChart":`Kubernetes.HelmChart from alchemy/Kubernetes`,"AWS.EKS.Job":`Kubernetes.Job from alchemy/Kubernetes`,"AWS.EKS.Manifest":`Kubernetes.Manifest from alchemy/Kubernetes`},zt=r.define({name:`alchemy-no-deprecated-resource`,meta:H({type:`problem`,description:`Disallow deprecated Alchemy resource APIs that have supported replacements.`,messages:{deprecated:`{{api}} is deprecated. Use {{replacement}}.`},url:`https://alchemy.run/llms-full.txt`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.path(r.callee).pipe(f.flatMap(e=>{let t=c.join(e,`.`);return f.map(l.get(Rt,t),e=>({api:t,replacement:e}))}),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:r.callee,messageId:`deprecated`,data:n}))})))}});function Bt(e,t){let n=O(e);return N(n)||n.type===`TemplateLiteral`||f.exists(w(n),([e,t])=>e===`process`&&t===`env`)||n.type===`CallExpression`&&t.isApi(n.callee,`Config`,`string`)}const Vt=r.define({name:`alchemy-no-plaintext-github-secret`,meta:H({type:`problem`,description:`Require singular GitHub Secret values to use Redacted.`,messages:{plaintext:`GitHub.Secret value must be Redacted so it stays out of logs and state. Use Redacted.make(...) or Config.redacted(...).`},url:`https://alchemy.run/providers/github/secret`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>D(r,1).pipe(f.filter(()=>n.isApi(r.callee,`GitHub`,`Secret`)),f.filter(e=>e.type===`ObjectExpression`),f.flatMap(E(`value`)),f.map(({value:e})=>e),f.filter(e=>Bt(e,n)),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:n,messageId:`plaintext`}))})))}}),Ht=m.is(m.Literals([`Secret`,`Variable`])),Ut=r.define({name:`alchemy-no-removed-config-api`,meta:H({type:`problem`,description:`Disallow removed Alchemy Secret and Variable APIs.`,messages:{removed:`Alchemy.{{api}} was removed. Use effect/Config (Config.redacted for secrets, Config.string for variables).`},url:`https://alchemy.run/blog/2026-05-29-beta-45`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.path(r.callee).pipe(f.filter(e=>f.contains(c.head(e),`Alchemy`)),f.flatMap(e=>c.get(e,1)),f.filter(Ht),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:r.callee,messageId:`removed`,data:{api:n}}))})))}}),Wt=r.define({name:`alchemy-no-reserved-eventbridge-default-name`,meta:H({type:`problem`,description:`Disallow creating an EventBridge bus with the reserved default name.`,messages:{reserved:`EventBridge reserves the name "default". Omit the bus argument to use the account default, or choose another name.`},url:`https://alchemy.run/aws/messaging/eventbridge`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>D(r,1).pipe(f.filter(()=>n.isApiPath(r.callee,[`AWS`,`EventBridge`,`EventBus`])),f.filter(e=>e.type===`ObjectExpression`),f.flatMap(E(`name`)),f.map(({value:e})=>e),f.filter(P(`default`)),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:n,messageId:`reserved`}))})))}}),Gt=r.define({name:`alchemy-no-runtime-config`,meta:H({type:`problem`,description:`Require Effect Config values to be resolved during Alchemy Worker initialization.`,messages:{runtime:`Config resolved inside the {{handler}} handler is invisible to Alchemy deployment. Resolve it in Worker init and close over the value, or put it in env.`},url:`https://alchemy.run/environments/secrets`}),*create(){let e=yield*i,n=yield*V;return s.on(`YieldExpression`,r=>{let i=r.argument;if(i?.type!==`CallExpression`||!f.exists(n.path(i.callee),([e])=>e===`Config`))return d.void;let a=f.flatMap(Dt(r,n),e=>f.filter(Ot(e),()=>f.isSome(Et(e,n))));return f.match(a,{onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:i,messageId:`runtime`,data:{handler:n}}))})})}}),Kt={"alchemy/aws":`alchemy/AWS`,"alchemy/cloudflare":`alchemy/Cloudflare`},qt=r.define({name:`alchemy-no-v1-import`,meta:H({type:`problem`,description:`Disallow Alchemy v1 imports that bypass the Effect-based Stack API.`,messages:{defaultImport:`The default alchemy() API is from v1. Use import * as Alchemy and Alchemy.Stack.`,providerImport:`Use the v2 provider entrypoint {{replacement}} (capitalization is significant).`},url:`https://alchemy.run/migrating-from-v1`}),*create(){let e=yield*i;function n(n,r,i){return e.report(t.fromId({node:n,messageId:r,...b.isUndefined(i)?{}:{data:i}}))}return s.on(`ImportDeclaration`,e=>{let t=e.source.value,r=t===`alchemy`?f.map(c.findFirst(e.specifiers,e=>e.type===`ImportDefaultSpecifier`),e=>n(e,`defaultImport`)):f.map(l.get(Kt,t),t=>n(e.source,`providerImport`,{replacement:t}));return f.getOrElse(r,()=>d.void)})}}),Jt=[[`entrypoint`,`main`],[`bindings`,`env`]],Yt=r.define({name:`alchemy-no-v1-worker-properties`,meta:H({type:`problem`,description:`Disallow Alchemy v1 Cloudflare Worker property names.`,messages:{property:`Cloudflare.Worker {{old}} was replaced in v2. Use {{replacement}}.`},url:`https://alchemy.run/migrating-from-v1`,fixable:`code`}),*create(){let e=yield*i,n=yield*V,r=d.fnUntraced(function*(n,r){let i=yield*je(n.callee),a=c.flatMap(Jt,([e,t])=>E(r,e).pipe(f.map(n=>({old:e,replacement:t,property:n})),f.toArray));yield*d.forEach(a,({old:n,replacement:a,property:o})=>e.report(It(t.fromId({node:o,messageId:`property`,data:{old:n,replacement:a}}),f.liftPredicate(t.replaceText(o.key,o.shorthand?`${a}: ${n}`:a),()=>i&&Ft(r,a)))),{discard:!0})});return s.on(`CallExpression`,e=>D(e,1).pipe(f.filter(()=>Tt(e.callee,n)),f.filter(e=>e.type===`ObjectExpression`),f.match({onNone:()=>d.void,onSome:t=>r(e,t)})))}}),Xt=r.define({name:`avoid-data-tagged-error`,meta:H({type:`suggestion`,description:`Prefer schema-based tagged errors so errors have a serializable contract.`,messages:{taggedError:`Prefer Schema.TaggedError over Data.TaggedError.`}}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Data`,`TaggedError`)?e.report(t.fromId({node:r.callee,messageId:`taggedError`})):d.void)}}),Zt=m.Literals([`error`,`err`,`e`,`cause`,`exception`,`ex`]),Qt=m.is(Zt);function $t(e){return e?.type===`Identifier`&&Qt(e.name)?f.some(e.name):f.none()}function en(e){return e.arguments.length===1&&f.exists(w(e.callee),e=>c.lastNonEmpty(e)===`String`&&e.length<=2)}function tn(e){return f.exists(M(e,`NewExpression`),t=>I(c.head(t.arguments),e)&&Oe(t))}function nn(e){return en(e)?tn(e)?f.none():f.flatMap(c.head(e.arguments),$t):e.callee.type===`MemberExpression`&&c.isReadonlyArrayEmpty(e.arguments)&&f.exists(w(e.callee),e=>c.lastNonEmpty(e)===`toString`)?$t(e.callee.object):f.none()}function rn(e){let[t,n]=e.quasis;return e.quasis.length===2&&t?.value.raw===``&&n?.value.raw===``?f.flatMap(c.head(e.expressions),$t):f.none()}const an=r.define({name:`ban-error-string`,meta:H({type:`problem`,description:`Disallow string coercion that discards an error value’s stack, type, and cause chain.`,messages:{errorString:`Do not stringify {{name}}. Preserve the original error as an Error cause instead.`,useCause:`Replace {{pattern}} with {{replacement}} to preserve the original error.`},hasSuggestions:!0}),*create(){let e=yield*i;function n(n,r){return f.match(r,{onNone:()=>d.void,onSome:r=>e.report(t.fromId({node:n,messageId:`errorString`,data:{name:r}}))})}function r(n,r){let i=e.sourceCode.getText(r),a=`'Error occurred', { cause: ${i} }`;return e.report(t.withSuggestions(t.fromId({node:n,messageId:`errorString`,data:{name:i}}),[{messageId:`useCause`,data:{pattern:e.sourceCode.getText(n),replacement:a},fix:t.replaceText(n,a)}]))}return s.merge(s.on(`NewExpression`,e=>D(e,0).pipe(f.filter(t=>t.type===`CallExpression`&&en(t)&&Oe(e)),f.match({onNone:()=>d.void,onSome:e=>f.match(D(e,0),{onNone:()=>d.void,onSome:t=>r(e,t)})}))),s.on(`CallExpression`,e=>n(e,nn(e))),s.on(`TemplateLiteral`,e=>n(e,rn(e))))}}),on=m.is(m.Literals(/* @__PURE__ */ `flip.fromFormData.fromJsonString.fromURLSearchParams.mutable.mutableKey.NullishOr.NullOr.optional.optionalKey.OptionFromNullishOr.OptionFromNullOr.OptionFromOptional.OptionFromOptionalKey.OptionFromOptionalNullOr.OptionFromUndefinedOr.readonlyKey.RedactedFromValue.required.requiredKey.toCodecArrayFromSingle.toCodecGoJson.toCodecIso.toCodecJson.toCodecStringTree.toEncoded.toType.UndefinedOr`.split(`.`))),sn=m.is(m.Literals([`Array`,`ArrayEnsure`,`Chunk`,`HashSet`,`NonEmptyArray`,`Option`,`ReadonlySet`,`Redacted`,`Tree`,`UniqueArray`])),cn=m.is(m.Literals(/* @__PURE__ */ `annotate.annotateEncoded.annotateKey.brand.catchDecoding.catchDecodingWithContext.catchEncoding.catchEncodingWithContext.check.decode.decodeTo.encode.encodeKeys.encodeTo.extendTo.fieldsAssign.fromBrand.middlewareDecoding.middlewareEncoding.overrideToCodecIso.overrideToEquivalence.overrideToFormatter.refine.toTaggedUnion.withConstructorDefault.withDecodingDefault.withDecodingDefaultKey.withDecodingDefaultType.withDecodingDefaultTypeKey`.split(`.`))),ln=m.is(m.Literals([`annotate`,`annotateKey`,`check`,`mapFields`])),un=m.is(m.Literals([`CallExpression`,`Identifier`,`MemberExpression`,`ThisExpression`])),dn=m.is(m.Literals([`ArrowFunctionExpression`,`FunctionExpression`,`Identifier`,`Literal`,`ThisExpression`])),fn=m.String.check(m.isPattern(/^\p{Lu}/u)),pn=m.is(fn);function mn(e){return on(e)||sn(e)}function hn(e,t){return f.filter(t.imports.member(e,`Schema`),()=>f.exists(w(e),e=>e.length===2)&&Ae(t.sourceCode,e))}function gn(e,t){return c.every(e,e=>b.isNull(e)||W(e,t))}function W(e,t){return dn(e.type)||_.value(e).pipe(_.discriminators(`type`)({MemberExpression:({object:e,computed:n,property:r})=>W(e,t)&&(!n||W(r,t)),TemplateLiteral:({expressions:e})=>gn(e,t),ArrayExpression:({elements:e})=>gn(e,t),ObjectExpression:({properties:e})=>c.every(e,e=>e.type===`SpreadElement`?W(e.argument,t):(!e.computed||W(e.key,t))&&W(e.value,t)),CallExpression:e=>{let n=e.callee.type===`CallExpression`?e.callee.callee:e.callee;return f.isSome(hn(n,t))&&(e.callee===n||W(e.callee,t))&&gn(e.arguments,t)}}),_.orElse(g.constFalse))}function _n(e,t){return e.type===`Identifier`?f.fromNullishOr(t.bindings.get(e.name)):e.type===`TSQualifiedName`?f.map(_n(e.left,t),t=>[...t,e.right.name]):f.none()}function vn(e,t){return j(t).pipe(f.flatMap(t=>{let n=`typeParameters`in t&&t.typeParameters?.type===`TSTypeParameterDeclaration`?c.findFirst(t.typeParameters.params,t=>t.name.name===e):f.none();return f.orElse(n,()=>vn(e,t))}))}function yn(e,t,n,r=[]){let i=c.isReadonlyArrayEmpty(r)?f.none():f.some(!1);if(e?.type!==`TSTypeReference`)return i;let a=f.flatMap(_n(e.typeName,n),Pe(`Schema`));if(f.isSome(a))return f.some(!h.startsWith(`Constraint`)(a.value));let{typeName:o}=e,s=f.filter(o.type===`Identifier`?vn(o.name,t):f.none(),e=>!F(r,e));return f.match(s,{onNone:()=>i,onSome:e=>yn(e.constraint,e,n,[...r,e])})}function bn(e,t){return L(t.sourceCode,e,e.name).pipe(f.flatMap(({defs:e})=>c.head(e)),f.flatMapNullishOr(({name:e})=>`typeAnnotation`in e?e.typeAnnotation:void 0))}function xn(e){return e.type===`TSSatisfiesExpression`||e.type===`TSNonNullExpression`?xn(e.expression):e}function Sn(e,t){let n=xn(e);return n.type===`TSAsExpression`?f.contains(yn(n.typeAnnotation,n,t.imports),!1):f.exists(n.type===`Identifier`?bn(n,t):f.none(),e=>f.contains(yn(e.typeAnnotation,e,t.imports),!1))}function Cn(e){return c.some(e.arguments,e=>e.type===`SpreadElement`)}function wn(e){return e.callee.type===`MemberExpression`&&!e.callee.optional&&f.contains(C(e.callee),`pipe`)&&!e.typeArguments&&!Cn(e)}function Tn(e,t){return(t.imports.isApiPath(e.callee,[`pipe`])||t.imports.isApiPath(e.callee,[`Function`,`pipe`]))&&Ae(t.sourceCode,e.callee)}function En(e,t){return f.exists(hn(e,t),mn)||e.type===`CallExpression`&&f.exists(hn(e.callee,t),cn)}function Dn(e,t){return f.exists(hn(e,t),pn)||f.isSome(Mn(e,t))?!0:e.type===`CallExpression`&&f.match(hn(e.callee,t),{onSome:e=>pn(e)||mn(e),onNone:()=>e.callee.type===`MemberExpression`&&f.exists(C(e.callee),ln)&&Dn(e.callee.object,t)})}function On(e,t){let[n,r]=e.arguments;return b.isUndefined(n)||b.isUndefined(r)||n.type===`SpreadElement`||e.typeArguments||Cn(e)||!Dn(n,t)&&!En(r,t)?f.none():f.some([n,e.arguments.slice(1)])}function kn(e,t,n,r,i){let a=Nn(e,i);return{head:a.head,steps:[...a.steps,...t],violation:f.orElse(a.violation,()=>n),reordersEffects:a.reordersEffects||r}}function An(e,t){let n=e.arguments.length===1&&!e.typeArguments?D(e,0):f.none();return f.flatMap(n,n=>{let r={text:t.sourceCode.getText(e.callee),wrapper:!1};function i(){return(e.callee.type===`CallExpression`?hn(e.callee.callee,t):f.none()).pipe(f.filter(cn),f.map(i=>kn(n,[r],f.some({kind:`dataLastCall`,name:i}),!W(e.callee,t)&&!W(n,t),t)))}return hn(e.callee,t).pipe(f.filter(mn),f.match({onNone:i,onSome:e=>{let i=sn(e);return f.some(kn(n,[u.assign(r,{wrapper:i})],i?f.none():f.some({kind:`modifierCall`,name:e}),!1,t))}}))})}function jn(e,t){let n=Tn(e,t),r=n?On(e,t):wn(e)?f.some([e.callee.object,e.arguments]):f.none();return f.map(r,([e,r])=>{let i=c.map(r,e=>hn(e,t)),a=c.findFirstIndex(i,f.exists(sn)),o=f.exists(a,e=>c.some(r.slice(e+1),e=>!W(e,t))),s=n?f.some({kind:`functionPipe`}):a.pipe(f.flatMap(e=>f.flatten(c.get(i,e))),f.map(e=>({kind:`wrapperPipe`,name:e})));return kn(e,c.map(r,(e,n)=>({text:t.sourceCode.getText(e),wrapper:c.get(i,n).pipe(f.flatten,f.exists(sn))})),s,o,t)})}function Mn(e,t){return e.type===`CallExpression`?f.orElse(An(e,t),()=>jn(e,t)):f.none()}function Nn(e,t){return f.getOrElse(Mn(e,t),()=>({head:e,steps:[],violation:f.none(),reordersEffects:!1}))}function Pn(e,t){let n=e.parent;return n.type===`MemberExpression`&&n.object===e&&n.parent.type===`CallExpression`?n.parent.callee===n&&wn(n.parent):n.type===`CallExpression`&&I(D(n,0),e)&&(Tn(n,t)||!wn(n))&&f.isSome(Mn(n,t))}function Fn(e,t,n){return c.isReadonlyArrayNonEmpty(t)?`${e===`\0`&&!un(n.type)?`(\0)`:e}.pipe(${c.join(t,`, `)})`:e}function In(e,t){let{target:n,pending:r}=c.reduce(t,{target:`\0`,pending:[]},({target:t,pending:n},r)=>{if(!r.wrapper)return{target:t,pending:[...n,r.text]};let i=Fn(t,n,e),a=i===`\0`&&e.type===`SequenceExpression`?`(${i})`:i;return{target:`${r.text}(${a})`,pending:[]}});return Fn(n,r,e)}const Ln=r.define({name:`consistent-schema-pipe`,meta:H({type:`suggestion`,description:"Apply Schema modifiers with `.pipe(...)` and call Schema wrappers directly.",messages:{modifierCall:"Apply Schema.{{name}} with `.pipe(...)` instead of calling it.",dataLastCall:"Apply Schema.{{name}}(...) with `.pipe(...)` instead of calling it on the schema.",functionPipe:"Call `.pipe(...)` on the schema instead of passing it to `pipe(...)`.",wrapperPipe:`Call Schema.{{name}}(...) directly instead of piping into it.`},url:`https://github.com/2digits-agency/configs/blob/main/docs/adr/0001-schema-modifiers-pipe-wrappers-call.md`,fixable:`code`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};let r={sourceCode:e.sourceCode,imports:n};function a(n,r,i){let{head:a}=r,o=c.some(e.sourceCode.getCommentsInside(n),e=>!Ee(a,e)),[s,l=``]=h.split(In(a,r.steps),`\0`),u=t.fromId({node:n,messageId:i.kind,data:{name:i.name??``}});return e.report(o||r.reordersEffects?u:t.withFix(u,t.composeFixes(e=>e.replaceTextRange([v.get(n.range,0),v.get(a.range,0)],s),e=>e.replaceTextRange([v.get(a.range,1),v.get(n.range,1)],l))))}return s.on(`CallExpression`,e=>f.filter(Mn(e,r),({head:e,steps:t})=>!f.exists(c.head(t),({wrapper:e})=>!e)||!Sn(e,r)).pipe(f.flatMap(e=>f.map(e.violation,t=>[e,t])),f.filter(()=>!Pn(e,r)),f.match({onNone:()=>d.void,onSome:([t,n])=>a(e,t,n)})))}});function Rn(e){let t=O(e);return P(t,`*`)||t.type===`ArrayExpression`&&(c.isReadonlyArrayEmpty(t.elements)||c.some(t.elements,e=>b.isNotNull(e)&&P(e,`*`)))}function zn(e,t){return t.isApi(e,`HttpMiddleware`,`cors`)||t.isApi(e,`HttpRouter`,`cors`)||t.isApi(e,`HttpApiBuilder`,`middlewareCors`)}function Bn(e){let t=E(e,`credentials`).pipe(f.match({onSome:({value:e})=>e,onNone:()=>e}));return P(t,!0)&&f.match(E(e,`allowedOrigins`),{onNone:()=>!0,onSome:({value:e})=>Rn(e)})}const Vn=r.define({name:`cors-credentials-with-wildcard`,meta:H({type:`problem`,description:`Disallow credentialed CORS with wildcard origins because browsers reject that combination.`,messages:{wildcard:`Credentialed CORS cannot use a wildcard origin. Set allowedOrigins to explicit trusted origins or disable credentials.`},url:`https://github.com/Effect-TS/tsgo/issues/400`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>zn(r.callee,n)&&f.exists(me(r),Bn)?e.report(t.fromId({node:r,messageId:`wildcard`})):d.void)}});function Hn(e){return e.type===`AssignmentPattern`||e.type===`RestElement`||e.optional===!0}const Un=r.define({name:`dual-numeric-arity-with-optional-parameter`,meta:H({type:`problem`,description:`Disallow numeric dual arity with optional or rest parameters because dispatch becomes ambiguous.`,messages:{unsafeArity:`Function.dual with numeric arity misdispatches an implementation with optional/default/rest parameters. Use predicate dispatch.`},url:`https://github.com/Effect-TS/tsgo/issues/401`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Function`,`dual`)?D(r,0).pipe(f.filter(e=>e.type===`Literal`&&b.isNumber(e.value)&&f.exists(D(r,1),e=>A(e)&&c.some(e.params,Hn))),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:n,messageId:`unsafeArity`}))})):d.void)}}),Wn=r.define({name:`effect-promise-vs-trypromise`,meta:H({type:`problem`,description:`Require Effect.tryPromise so Promise rejections enter the typed error channel.`,messages:{tryPromise:`Use Effect.tryPromise instead of Effect.promise so rejections are typed failures.`}}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Effect`,`promise`)?e.report(t.fromId({node:r.callee,messageId:`tryPromise`})):d.void)}});function Gn(e,t){return _.value(e.parent).pipe(_.withReturnType(),_.when({type:`Property`,parent:{type:`ObjectExpression`,parent:{type:`CallExpression`}}},e=>f.contains(T(e),t)?f.some(e.parent.parent):f.none()),_.orElse(()=>f.none()))}function Kn(e,t){return f.flatMap(Te(e),e=>t.path(e.callee))}function qn(e){return e.type===`CallExpression`?qn(e.callee):e}function Jn(e,t){let n=e.parent.type===`Property`&&e.parent.value===e?e.parent.parent:e;return j(n).pipe(f.filter(e=>(e.type===`CallExpression`||e.type===`NewExpression`)&&F(e.arguments,n)),f.exists(e=>f.isNone(t.path(qn(e.callee)))))}const Yn=m.Literals([`catch`,`finally`,`then`]),Xn=m.is(Yn),Zn=_.type().pipe(_.discriminators(`type`)({CallExpression:({callee:e})=>f.exists(w(e),e=>c.join(e,`.`)===`fetch`||c.headNonEmpty(e)===`Promise`&&e[1]!==`withResolvers`||Xn(c.lastNonEmpty(e)))||A(e)&&e.async,NewExpression:({callee:e})=>f.exists(w(e),e=>c.join(e,`.`)===`Promise`)}),_.orElse(g.constFalse));function Qn(e){return Zn(O(e))}function G(e){return f.fromNullishOr(e.body).pipe(f.flatMap(e=>e.type===`BlockStatement`?c.head(e.body).pipe(f.filter(()=>e.body.length===1),f.flatMapNullishOr(e=>e.type===`ReturnStatement`?e.argument:void 0),f.map(O)):f.some(O(e))))}function $n(e){return e.pipe(f.flatMap(e=>e.type===`ObjectExpression`?f.map(E(e,`try`),({value:e})=>e):f.some(e)),f.filter(A))}const er=r.define({name:`no-already-started-promise`,meta:H({type:`problem`,description:`Ensure Effect Promise thunks start fresh asynchronous work rather than reusing an already-started Promise.`,messages:{prestarted:`This thunk returns an already-started Promise. Start the asynchronous work inside the thunk so retries and repeats run it again.`},url:`https://github.com/Effect-TS/tsgo/issues/475`}),*create(){let e=yield*i,n=yield*V,r=yield*p.make(x.empty());return s.merge(s.on(`VariableDeclarator`,e=>e.id.type===`Identifier`&&e.init&&Qn(e.init)?p.update(r,x.add(e.id.name)):d.void),s.on(`CallExpression`,i=>d.gen(function*(){if(!n.isApi(i.callee,`Effect`,[`promise`,`tryPromise`]))return;let a=f.flatMap($n(D(i,0)),G);if(f.isNone(a)||a.value.type!==`Identifier`)return;let o=yield*p.get(r);x.has(o,a.value.name)&&(yield*e.report(t.fromId({node:a.value,messageId:`prestarted`})))})))}}),tr=r.define({name:`no-async-effect-try`,meta:H({type:`problem`,description:`Disallow async thunks in Effect.try because rejected Promises bypass its catch mapper.`,messages:{asyncTry:`Effect.try does not await Promises. Use Effect.tryPromise so rejection enters the typed error channel.`},url:`https://github.com/Effect-TS/tsgo/issues/657`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Effect`,`try`)?D(r,0).pipe(f.flatMap(e=>A(e)?f.some(e):e.type===`ObjectExpression`?E(e,`try`).pipe(f.map(({value:e})=>e),f.filter(A)):f.none()),f.filter(e=>e.async||f.exists(G(e),Qn)),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:n,messageId:`asyncTry`}))})):d.void)}}),nr=r.define({name:`no-discarded-run-promise`,meta:H({type:`problem`,description:`Disallow discarded Effect.runPromise results that can become unhandled rejections.`,messages:{discarded:`The Promise returned by Effect.runPromise is discarded. Await/return/handle it, or use Effect.runFork for fire-and-forget work.`},url:`https://github.com/Effect-TS/tsgo/issues/643`}),*create(){let e=yield*i,n=yield*V;function r(e){return n.isApi(e,`Effect`,`runPromise`)||e.type===`CallExpression`&&n.isApi(e.callee,`Effect`,`runPromiseWith`)}return s.on(`CallExpression`,n=>r(n.callee)&&De(n)?e.report(t.fromId({node:n,messageId:`discarded`})):d.void)}}),rr=m.Literals([`mapElements`,`mapFields`,`mapMembers`]),ir=m.is(rr);function ar(e,t){let n=O(e);return n.type===`CallExpression`&&n.callee.type===`MemberExpression`&&f.contains(C(n.callee),t)}function or(e){return e.callee.type!==`MemberExpression`||!ar(e.callee.object,`check`)||me(e).pipe(f.flatMap(E(`unsafePreserveChecks`)),f.exists(e=>P(e.value,!0)))?f.none():f.filter(C(e.callee),ir)}const sr=r.define({name:`no-discarded-schema-checks`,meta:H({type:`problem`,description:`Disallow schema mapping that silently drops checks attached to the receiver.`,messages:{discarded:`{{method}} creates a new schema and drops the preceding check. Re-attach the check after mapping or explicitly preserve it.`},url:`https://github.com/Effect-TS/tsgo/issues/435`}),*create(){let e=yield*i;return(yield*V).hasEffectImport?s.on(`CallExpression`,n=>f.match(or(n),{onNone:()=>d.void,onSome:r=>e.report(t.fromId({node:n,messageId:`discarded`,data:{method:r}}))})):{}}}),cr={Array:`Arr`,Boolean:`Bool`,Equal:`Eq`,Function:`Fn`,Number:`Num`,Option:`Opt`,Predicate:`P`,Record:`R`,String:`Str`},lr=m.String.check(m.isPattern(/^\p{Lu}[^_]*$/u)),ur=m.is(lr),dr=m.String.check(m.isPattern(/^@effect\/vitest(?:\/.*)?$/u)),fr=m.is(dr),pr=m.String.check(m.isPattern(/^@effect\/[^/]+$/u)),mr=m.is(pr),hr=m.String.check(m.isPattern(/^@effect\/[^/]+\//u)),gr=m.is(hr);function _r(e,t){return e.importKind===`type`||t?.importKind===`type`}function vr(e){return f.getOrElse(l.get(cr,e),()=>e)}function yr(e,t){return _.value(e).pipe(_.when(_.is(`effect`,`alchemy`),()=>f.some(`${e}/${t}`)),_.when(e=>mr(e)&&!fr(e),()=>f.some(`${e}/${t}`)),_.orElse(()=>f.none()))}function br(e){return!fr(e)&&(h.startsWith(`effect/`)(e)||h.startsWith(`alchemy/`)(e)||gr(e))?f.liftPredicate(c.lastNonEmpty(h.split(e,`/`)),ur):f.none()}function xr(e,n){let r=n.specifiers;if(c.isReadonlyArrayNonEmpty(e.getCommentsInside(n))||c.isReadonlyArrayNonEmpty(n.attributes)||!c.every(r,e=>e.type===`ImportSpecifier`))return f.none();let[i,a]=c.partition(r,t=>{let r=fe(t.imported),i=ur(r)&&!_r(n,t)?yr(n.source.value,r):f.none();return f.match(i,{onNone:()=>ee.fail(e.getText(t)),onSome:e=>ee.succeed(`import * as ${t.local.name} from '${e}';`)})}),o=c.isReadonlyArrayNonEmpty(a)?c.prepend(i,`import { ${c.join(a,`, `)} } from ${e.getText(n.source)};`):i;return f.some(t.replaceText(n,c.join(o,`
2
+ `)))}function Sr(e,n,r){let i=c.dedupeWith(e.references,(e,t)=>v.get(e.identifier.range,0)===v.get(t.identifier.range,0));return f.all(c.map(i,e=>{let i=e.identifier,a=i.parent;if(e.isWrite()||a.type===`ExportSpecifier`||h.startsWith(`JSX`)(a.type))return f.none();let o=a.type===`CallExpression`&&a.callee===i||a.type===`TaggedTemplateExpression`&&a.tag===i,s=r&&o?`(0, ${n})`:a.type===`Property`&&a.shorthand?`${i.name}: ${n}`:n;return f.some(t.replaceText(i,s))}))}function Cr(e,t,n){return f.flatMap(c.findFirst(t,t=>t.name===e.local.name),t=>e.type===`ImportNamespaceSpecifier`?Sr(t,n,!1):e.imported.type===`Identifier`?Sr(t,`${n}.${e.imported.name}`,!0):f.none())}function wr(e,t,n){function r(e){return I(n,e)}return!c.some(e.scopeManager.scopes,e=>c.some(e.variables,e=>e.name===t&&!r(e))||c.some(e.references,e=>e.identifier.name===t&&!r(e.resolved)))}function Tr(e,n){return f.flatMap(br(n.source.value),r=>{if(c.isReadonlyArrayNonEmpty(n.attributes)||c.isReadonlyArrayNonEmpty(e.getCommentsInside(n)))return f.none();let i=vr(r),a=e.getDeclaredVariables(n);if(!wr(e,i,c.findFirst(a,e=>e.name===i)))return f.none();let o=c.filter(n.specifiers,e=>e.type===`ImportSpecifier`&&_r(n,e));if(c.some(n.specifiers,e=>e.type===`ImportDefaultSpecifier`)||c.some(o,e=>e.local.name===i))return f.none();let s=c.filter(n.specifiers,e=>e.type!==`ImportDefaultSpecifier`&&!F(o,e));return f.all(c.map(s,e=>Cr(e,a,i))).pipe(f.map(r=>{let a=e.getText(n.source),s=c.isReadonlyArrayEmpty(o)?``:`\nimport { ${c.join(c.map(o,t=>e.getText(t)),`, `)} } from ${a};`;return t.composeFixes(t.replaceText(n,`import * as ${i} from ${a};${s}`),...c.flatten(r))}))})}const Er=r.define({name:`no-effect-alchemy-barrel-imports`,meta:H({type:`suggestion`,description:`Import Effect and Alchemy module namespaces from their submodule entrypoints instead of root barrels.`,messages:{barrelImport:'Import this module as `import * as {{alias}} from "{{source}}"` instead of from the root barrel.'},url:`https://github.com/Effect-TS/language-service/blob/main/packages/language-service/src/diagnostics/importFromBarrel.ts`,fixable:`code`}),*create(){let e=yield*i;function n(n,r){let i=fe(r.imported);return f.match(ur(i)?yr(n.source.value,i):f.none(),{onNone:()=>d.void,onSome:a=>e.report(It(t.fromId({node:r,messageId:`barrelImport`,data:{alias:vr(i),source:a}}),xr(e.sourceCode,n)))})}return s.on(`ImportDeclaration`,e=>d.forEach(c.filter(e.specifiers,t=>t.type===`ImportSpecifier`&&!_r(e,t)),t=>n(e,t),{discard:!0}))}}),Dr=[`log`,`logDebug`,`logError`,`logFatal`,`logInfo`,`logTrace`,`logWarning`],Or=[`debug`,`error`,`info`,`log`,`trace`,`warn`],kr=[`as`,`asSome`,`asVoid`];function Ar(e,t){let n=O(e);if(n.type!==`CallExpression`)return f.none();let r=O(n.callee);return r.type===`CallExpression`&&t.isApiPath(r.callee,[`Effect`,`logWithLevel`])?f.some(`Effect.logWithLevel`):t.isApi(r,`Effect`,Dr)||t.isApi(r,`Console`,Or)?f.some(t.path(r).pipe(f.getOrElse(()=>[]),c.join(`.`))):f.none()}function jr(e,t){return f.flatMapNullishOr(t.path(e),([,e])=>e)}function Mr(e,t){let n=O(e);return n.type===`CallExpression`&&n.arguments.length===1&&t.isApiPath(n.callee,[`Effect`,`as`])?f.some(`as`):t.isApi(n,`Effect`,[`asSome`,`asVoid`])?jr(n,t):f.none()}function Nr(e,t){return t.isApiPath(e,[`pipe`])||t.isApiPath(e,[`Function`,`pipe`])}function Pr(e,t,n){return f.flatMap(t,t=>e.pipe(f.flatMap(e=>Ar(e,n)),f.zipWith(Mr(t,n),(e,n)=>({logger:e,method:n,node:t}))))}function Fr(e,t){let n=O(e.callee);return n.type===`MemberExpression`&&f.contains(C(n),`pipe`)?Pr(f.some(n.object),D(e,0),t):Nr(n,t)?Pr(D(e,0),D(e,1),t):(t.isApi(n,`Effect`,kr)?jr(n,t):f.none()).pipe(f.filter(t=>t!==`as`||e.arguments.length===2),f.flatMap(n=>D(e,0).pipe(f.flatMap(e=>Ar(e,t)),f.map(t=>({logger:t,method:n,node:e})))))}const Ir=r.define({name:`no-effect-as-on-log`,meta:H({type:`suggestion`,description:`Disallow Effect.as, Effect.asSome and Effect.asVoid on log effects.`,messages:{asOnLog:"Do not swap the result of {{logger}} with Effect.{{method}}. Use Effect.gen: `yield*` the log, then return the value.",asVoidOnLog:`{{logger}} already succeeds with void; remove Effect.asVoid.`}}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>f.match(Fr(r,n),{onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:n.node,messageId:n.method===`asVoid`?`asVoidOnLog`:`asOnLog`,data:{logger:n.logger,method:n.method}}))}))}}),Lr=r.define({name:`no-empty-effect-callback`,meta:H({type:`suggestion`,description:`Prefer Effect.never to an empty Effect.callback registration.`,messages:{emptyCallback:`An empty Effect.callback registration is Effect.never. Use the explicit primitive.`},url:`https://github.com/Effect-TS/tsgo/issues/636`,fixable:`code`}),*create(){let e=yield*i,n=yield*V,r=d.fnUntraced(function*(n,r){if(n.arguments.length!==1||r.async||r.generator||c.some(r.params,e=>e.type!==`Identifier`)||c.isReadonlyArrayNonEmpty(e.sourceCode.getCommentsInside(n))||!(yield*je(n.callee)))return f.none();let i=yield*Nt(n,`effect/Effect`,`Effect`);return f.some(t.composeFixes(...f.toArray(i.fix),t.replaceText(n,`${i.name}.never`)))});function a(e){return n.isApi(e,`Effect`,`callback`)||n.isApi(e,`Effect`,`async`)}return s.on(`CallExpression`,n=>a(n.callee)?D(n,0).pipe(f.filter(e=>A(e)&&e.body?.type===`BlockStatement`&&c.isReadonlyArrayEmpty(e.body.body)),f.match({onNone:()=>d.void,onSome:i=>d.flatMap(r(n,i),r=>e.report(It(t.fromId({node:n,messageId:`emptyCallback`}),r)))})):d.void)}}),Rr=r.define({name:`no-empty-schema-struct`,meta:H({type:`problem`,description:`Disallow Schema.Struct({}), which accepts every non-null object-like value.`,messages:{emptyStruct:`Schema.Struct({}) does not validate an exact empty object. Define the intended fields explicitly.`},url:`https://github.com/Effect-TS/tsgo/issues/403`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Schema`,`Struct`)&&f.exists(D(r,0),e=>e.type===`ObjectExpression`&&c.isReadonlyArrayEmpty(e.properties))?e.report(t.fromId({node:r,messageId:`emptyStruct`})):d.void)}}),zr=[`Base64`,`Base64Url`,`Hex`],Br=[`decode`,`decodeString`],Vr=[`getOrThrow`,`getOrThrowWith`];function Hr(e,t){let n=e.type===`ChainExpression`?e.expression:O(e);return n.type===`CallExpression`?t.path(n.callee).pipe(f.filter(e=>e.length===2&&c.contains(zr,e[0])&&c.contains(Br,e[1])),f.map(c.join(`.`))):f.none()}function Ur(e,t){let n=e.type===`CallExpression`?e.callee:e;return f.filter(t.member(n,`Result`),e=>c.contains(Vr,e))}function Wr(e,t){let n=f.filter(t.member(e.callee,`Result`),e=>c.contains(Vr,e));if(f.isSome(n))return D(e,0).pipe(f.flatMap(e=>Hr(e,t)),f.map(e=>({decoder:e,method:n.value})));let r=e.callee.type===`MemberExpression`&&f.contains(C(e.callee),`pipe`)?f.some({source:e.callee.object,steps:e.arguments}):t.isApi(e.callee,`Function`,`pipe`)||e.callee.type===`Identifier`&&e.callee.name===`pipe`?f.map(c.head(e.arguments),t=>({source:t,steps:c.drop(e.arguments,1)})):f.none();return f.flatMap(r,({source:e,steps:n})=>f.zipWith(Hr(e,t),f.flatMap(c.findFirst(n,e=>e.type!==`CallExpression`||!t.isApi(e.callee,`Result`,`map`)),e=>Ur(e,t)),(e,t)=>({decoder:e,method:t})))}const Gr=r.define({name:`no-encoding-get-or-throw`,meta:H({type:`problem`,description:`Disallow throwing away the typed EncodingError of Effect Base64, Base64Url, and Hex decoders.`,messages:{getOrThrow:`Result.{{method}} turns the EncodingError of {{decoder}} into an untyped exception. Keep it typed with yield* Effect.fromResult(…), or handle it with Result.match or Result.getOrElse.`},url:`https://effect.website/docs/v4/api/effect/encoding/EncodingError`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>f.match(Wr(r,n),{onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:r,messageId:`getOrThrow`,data:n}))}))}});function Kr(e,t=[]){let n=O(e);return n.type===`Identifier`?d.flatMap(ke(n,n.name),e=>{let n=f.flatMap(e,n=>f.flatMap(R(e),e=>{let r=e.node;return F(t,n)||r.type!==`VariableDeclarator`||r.id.type!==`Identifier`||!be(e.parent)||!r.init||c.some(n.references,e=>e.isWrite()&&!e.init)?f.none():f.some([n,r.init])}));return f.match(n,{onNone:()=>d.succeedNone,onSome:([e,n])=>Kr(n,[...t,e])})}):d.succeedSome(n)}function qr(e){return e.arguments.length===2?D(e,0):e.arguments.length===1?M(e,`CallExpression`).pipe(f.filter(t=>I(D(t,0),e)&&t.callee.type===`MemberExpression`&&f.contains(C(t.callee),`pipe`)),f.flatMap(e=>e.callee.type===`MemberExpression`?f.some(e.callee.object):f.none())):f.none()}const Jr=r.define({name:`no-function-config-default`,meta:H({type:`problem`,description:`Disallow obsolete lazy callbacks passed to the now-eager Config.withDefault API.`,messages:{functionDefault:`Config.withDefault takes an eager value. This callback becomes the configured value; pass the returned value directly.`},url:`https://github.com/Effect-TS/tsgo/issues/408`}),*create(){let e=yield*i,n=yield*V,r=d.fnUntraced(function*(e){let t=qr(e),r=f.isSome(t)?yield*Kr(t.value):f.none();if(f.isNone(r)||r.value.type!==`CallExpression`||!n.isApi(r.value.callee,`Config`,`succeed`))return!1;let i=r.value;return(yield*je(i.callee))&&f.exists(D(i,0),A)});return s.on(`CallExpression`,i=>d.gen(function*(){if(!n.isApi(i.callee,`Config`,`withDefault`)||!(yield*je(i.callee))||(yield*r(i)))return;let a=D(i,i.arguments.length-1);f.isSome(a)&&A(a.value)&&c.isReadonlyArrayEmpty(a.value.params)&&(yield*e.report(t.fromId({node:a.value,messageId:`functionDefault`})))}))}}),Yr=m.Literals([`delete`,`get`,`has`,`set`]),Xr=m.is(Yr);function Zr(e,t){return e.type===`CallExpression`&&t.isApi(e.callee,`Hash`,`hash`)}const Qr=r.define({name:`no-hash-as-identity`,meta:H({type:`problem`,description:`Disallow using Hash.hash output as collision-free identity.`,messages:{hashIdentity:`Hash.hash is a bucketing hint, not a unique identity. Use HashMap/Equal.equals or a real identifier instead.`},url:`https://github.com/Effect-TS/tsgo/issues/482`}),*create(){let e=yield*i,n=yield*V,r=yield*p.make(x.empty());function a(e){return Zr(e,n)?d.succeed(!0):e.type===`Identifier`?d.map(p.get(r),x.has(e.name)):d.succeed(!1)}function o(n,r){return d.when(e.report(t.fromId({node:n,messageId:`hashIdentity`})),r)}return s.merge(s.on(`VariableDeclarator`,e=>e.id.type===`Identifier`&&e.init&&Zr(e.init,n)?p.update(r,x.add(e.id.name)):d.void),s.on(`CallExpression`,e=>e.callee.type===`MemberExpression`&&f.exists(w(e.callee),e=>Xr(c.lastNonEmpty(e)))?f.match(D(e,0),{onNone:()=>d.void,onSome:e=>o(e,a(e))}):d.void),s.on(`BinaryExpression`,e=>le(e.operator)?o(e,d.map(d.all([a(e.left),a(e.right)]),c.every(Boolean))):d.void),s.on(`MemberExpression`,e=>e.computed?o(e.property,a(e.property)):d.void))}}),$r=m.Literals(/* @__PURE__ */ `asserts.decodeEffect.decodeExit.decodeOption.decodePromise.decodeResult.decodeSync.decodeUnknownEffect.decodeUnknownExit.decodeUnknownOption.decodeUnknownPromise.decodeUnknownResult.decodeUnknownSync.encodeEffect.encodeExit.encodeOption.encodePromise.encodeResult.encodeSync.encodeUnknownEffect.encodeUnknownExit.encodeUnknownOption.encodeUnknownPromise.encodeUnknownResult.encodeUnknownSync.is`.split(`.`)),ei=m.is($r),ti=m.is(m.Literals([`global`,`module`])),ni=m.is(m.Literals([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`])),ri=m.is(m.Literals([`AssignmentExpression`,`AwaitExpression`,`ImportExpression`,`TaggedTemplateExpression`,`UpdateExpression`,`YieldExpression`])),ii=m.is(m.Literals([`ParenthesizedExpression`,`TSAsExpression`,`TSNonNullExpression`]));function ai(e,t,n){let r=f.filter(t.member(e,`Schema`),ei);return w(e).pipe(f.flatMap(([t])=>L(n,e,t)),f.exists(({defs:e})=>c.every(e,e=>e.type===`ImportBinding`)))?r:f.none()}function oi(e,t=e){return f.exists(j(t),n=>ii(n.type)&&b.isNotNullish(n.parent)?oi(e,n):n.type===`CallExpression`&&n.callee===t)}function si(e){return j(e).pipe(f.filter(t=>t.type===`MemberExpression`&&t.object===e),f.match({onNone:()=>e,onSome:si}))}function ci(e){let t=si(e);return t!==e&&f.exists(j(t),e=>e.type===`AssignmentExpression`&&e.left===t||e.type===`UpdateExpression`&&e.argument===t||e.type===`UnaryExpression`&&e.operator===`delete`&&e.argument===t)}function li(e){return c.every(e.references,e=>(!e.isWrite()||e.init)&&!ci(e.identifier))}function ui(e,t,n,r){return f.match(L(r,e,t),{onNone:()=>!0,onSome:e=>Ee(n,e.scope.block)||ti(e.scope.type)&&li(e)})}function di(e){return f.exists(j(e),t=>t.type===`MemberExpression`&&t.property===e&&!t.computed||t.type===`Property`&&t.key===e&&!t.computed&&!t.shorthand)}function fi(e,t){return e!==t&&f.exists(j(e),e=>e!==t&&(ni(e.type)||fi(e,t)))}function pi(e,t,n){return fi(e,t)?!1:e.type===`CallExpression`||e.type===`NewExpression`?f.isNone(n.path(e.callee)):ri(e.type)}function mi(e,t,n){return!k(e,r=>r.type===`ThisExpression`||r.type===`Super`||r.type===`MetaProperty`&&r.meta.name===`new`||pi(r,e,t)||r.type===`Identifier`&&!di(r)&&!ui(r,r.name,e,n))}function hi(e,t,n){let[r]=e.arguments;if(b.isUndefined(r)||c.some(e.arguments,e=>e.type===`SpreadElement`)||!oi(e)||f.isNone(Ce(e,e=>ni(e.type))))return f.none();let i=O(r),a=i.type===`CallExpression`&&f.exists(t.path(i.callee),e=>f.contains(c.head(e),`Schema`));return!a&&i.type!==`Identifier`&&i.type!==`MemberExpression`||!c.every(e.arguments,e=>mi(e,t,n))?f.none():f.some(a?`inlineSchema`:`inlineCompile`)}const gi=r.define({name:`no-inline-schema-compile`,meta:H({type:`problem`,description:`Disallow compiling Schema decoders, encoders, and guards inside function bodies.`,messages:{inlineSchema:`Hoist Schema.{{method}}(...) to module scope: both the inline schema and the compiled function are rebuilt on every call. Move the compiled function to a module-level const.`,inlineCompile:`Hoist Schema.{{method}}(...) to module scope: the compiled function is rebuilt on every call. Move it to a module-level const.`},url:`https://github.com/pingdotgg/t3code/blob/main/oxlint-plugin-t3code/rules/no-inline-schema-compile.ts`}),*create(){let e=yield*i,n=yield*V;return n.hasEffectImport?s.on(`CallExpression`,r=>f.zipWith(ai(r.callee,n,e.sourceCode),hi(r,n,e.sourceCode),(e,t)=>({method:e,messageId:t})).pipe(f.match({onNone:()=>d.void,onSome:({method:n,messageId:i})=>e.report(t.fromId({node:r.callee,messageId:i,data:{method:n}}))}))):{}}}),_i=m.Literals([`catch`,`catchIf`,`catchTag`,`orElseSucceed`,`catchAll`,`catchAllCause`,`catchSome`,`catchSomeCause`,`orElse`,`orElseFail`]),vi=m.is(_i),yi=m.Literals([`log`,`logDebug`,`logError`,`logInfo`,`logTrace`,`logWarning`]),bi=m.is(yi);function xi(e,t){return e.pipe(f.filter(([e,n])=>e===`Effect`&&t(n)),f.flatMapNullishOr(([,e])=>e))}function Si(e,t){return f.flatMap(j(e),e=>{let n=A(e)?Te(e).pipe(f.filter(t=>I(c.last(t.arguments),e)),f.flatMap(e=>xi(t.path(e.callee),vi))):f.none();return f.orElse(n,()=>Si(e,t))})}const Ci=r.define({name:`no-logging-in-catch`,meta:H({type:`suggestion`,description:`Keep logging separate from Effect recovery handlers.`,messages:{logging:`Move {{logger}} out of Effect.{{catchMethod}} and use Effect.tapError before recovery.`}}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>{let i=n.path(r.callee);return f.zipWith(xi(i,bi),Si(r,n),(e,t)=>t).pipe(f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:r,messageId:`logging`,data:{logger:i.pipe(f.getOrElse(()=>[]),c.join(`.`)),catchMethod:n}}))}))})}}),wi=m.Literals([`catch`,`catchAll`,`catchIf`]),Ti=m.Literals([`when`,`not`]);function Ei(e,t){return _.type().pipe(_.when({type:`MemberExpression`,computed:!1,object:{type:`Identifier`,name:e},property:{type:`Identifier`,name:t}},g.constTrue),_.orElse(g.constFalse))}const Di=Ei(`Effect`,m.is(wi)),Oi=Ei(`Match`,m.is(Ti)),ki=/* @__PURE__ */ new Set([`_tag`]);function Ai(e,t=ki){return e.type===`MemberExpression`&&f.exists(C(e),e=>t.has(e))}function ji(e,t=ki){return le(e.operator)?c.findFirst([v.make(e.left,e.right),v.make(e.right,e.left)],([e,n])=>Ai(e,t)&&N(n)).pipe(f.map(([e])=>e)):f.none()}function Mi(e){return we(e).pipe(f.flatMap(Te),f.exists(e=>Di(e.callee)))}function Ni(e){return e.object.type===`MemberExpression`&&f.contains(C(e.object),`reason`)}function Pi(e){return f.exists(M(e,`CallExpression`),t=>F(t.arguments,e)&&Oi(t.callee))}const Fi=r.define({name:`no-manual-effect-error-tag`,meta:H({type:`problem`,description:"Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler.",messages:{tag:`Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.`,reason:"Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler."},url:`https://github.com/dmmulroy/anti-slop/blob/main/src/effect/rules/no-manual-effect-error-tag.ts`}),*create(){let e=yield*i;function n(n,r){return Mi(n)?e.report(t.fromId({node:n,messageId:Ni(r)?`reason`:`tag`})):d.void}return s.merge(s.on(`BinaryExpression`,e=>f.match(ji(e),{onNone:()=>d.void,onSome:t=>n(e,t)})),s.on(`SwitchStatement`,e=>Ai(e.discriminant)?n(e,e.discriminant):d.void))}}),Ii=m.Literals([`replace`,`replaceAll`]),Li=m.is(Ii);function Ri(e,t){return e.type===`CallExpression`&&e.callee.type===`MemberExpression`&&f.exists(C(e.callee),t)}function zi(e){return Ri(e,Li)}function Bi(e){if(N(e))return f.some(e.value);if(e.type!==`Literal`||!(`regex`in e))return f.none();let{pattern:t}=e.regex,n=/^\[(\\?.)\]$/u.exec(t)?.[1]??t;return f.some(n.length===2&&h.startsWith(`\\`)(n)?h.slice(1)(n):n)}function Vi(e){return f.all([f.flatMap(D(e,0),Bi),D(e,1)]).pipe(f.flatMap(([e,t])=>N(t)&&e.length===1&&t.value.length===1?f.some(`${e}${t.value}`):f.none()))}function Hi(e){return zi(e)?[...f.toArray(Vi(e)),...Hi(O(e.callee.object))]:[]}function Ui(e){let{parent:t}=e;return t.type!==`MemberExpression`||t.object!==e||!zi(t.parent)||t.parent.callee!==t}function Wi(e,t){let n=zi(e)?Ui(e)?Hi(e):[]:Gi(e,t);return(c.contains(n,`+-`)||c.contains(n,`-+`))&&(c.contains(n,`/_`)||c.contains(n,`_/`))}function Gi(e,t){return!(e.callee.type===`MemberExpression`&&f.contains(C(e.callee),`pipe`))&&!Ji(e.callee,t)?[]:c.flatMap(e.arguments,e=>e.type===`CallExpression`&&t.isApi(e.callee,`String`,[`replace`,`replaceAll`])?f.toArray(Vi(e)):[])}function Ki(e){return f.exists(D(e,0),P(2))&&f.exists(D(e,1),P(`0`))}function qi(e,t){return e.type===`CallExpression`&&t.isApi(e.callee,`String`,`padStart`)&&Ki(e)}function Ji(e,t){return t.isApi(e,`Function`,`pipe`)||e.type===`Identifier`&&e.name===`pipe`}function Yi(e,t){let{parent:n}=e;return n.type===`MemberExpression`?n.object===e&&f.contains(C(n),`padStart`)&&n.parent.type===`CallExpression`&&n.parent.callee===n&&Ki(n.parent):n.type!==`CallExpression`||!I(D(n,0),e)?!1:qi(n.callee,t)||Ji(n.callee,t)&&f.exists(D(n,1),e=>qi(e,t))}function Xi(e){return Ri(e,e=>e===`toString`)&&e.arguments.length===1&&f.exists(D(e,0),P(16))}const Zi=r.define({name:`no-manual-encoding`,meta:H({type:`suggestion`,description:`Disallow hand-written Base64Url and hexadecimal conversions in Effect projects.`,messages:{base64Url:`Swapping '+'/'-' and '/'/'_' by hand converts between Base64 and Base64Url. Use Base64Url.encode or Base64Url.decode from effect/encoding.`,hex:`Padding each byte's toString(16) to two digits hand-writes hexadecimal encoding. Use Hex.encode from effect/encoding.`},url:`https://effect.website/docs/v4/api/effect/encoding/Base64Url`}),*create(){let e=yield*i,n=yield*V;return n.hasEffectImport?s.on(`CallExpression`,r=>Wi(r,n)?e.report(t.fromId({node:r,messageId:`base64Url`})):Xi(r)&&Yi(r,n)?e.report(t.fromId({node:r,messageId:`hex`})):d.void):{}}}),Qi=m.String.check(m.isPattern(/(?:^|[\n\r])(?:data|event|id|retry):.*(?:\r?\n){2}$/su)),$i=m.is(Qi),ea=m.Literals([`data: `,`event: `,`id: `,`retry: `]),ta=m.is(ea);function na(e){if(e.type===`PrivateIdentifier`)return`\0`;let t=O(e);return N(t)?t.value:t.type===`TemplateLiteral`?c.join(c.map(t.quasis,({value:e})=>e.cooked??e.raw),`\0`):t.type===`BinaryExpression`&&t.operator===`+`?na(t.left)+na(t.right):`\0`}function ra(e){return e.type===`BinaryExpression`&&e.operator===`+`}const ia=r.define({name:`no-manual-sse`,meta:H({type:`suggestion`,description:`Disallow writing or parsing Server-Sent Events text by hand in Effect projects.`,messages:{frame:"Write events with Sse.encoder.write, Sse.encode or HttpApiSchema.StreamSse: a hand-written frame breaks on a line break in `data` and lets `id` or `event` inject fields.",parse:"Parse events with Sse.decode, Sse.decodeSchema or Sse.makeParser: matching `{{prefix}}` by hand misses fields without a space, multi-line data, comments and CR line endings."},url:`https://www.effect.website/docs/v4/api/effect/encoding/Sse`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};function r({callee:e}){return n.isApi(e,`String`,`startsWith`)||e.type===`MemberExpression`&&f.contains(C(e),`startsWith`)}function a(n){return!f.exists(j(n),ra)&&$i(na(n))?e.report(t.fromId({node:n,messageId:`frame`})):d.void}return s.merge(s.on(`Literal`,e=>N(e)?a(e):d.void),s.on(`TemplateLiteral`,a),s.on(`BinaryExpression`,e=>ra(e)?a(e):d.void),s.on(`CallExpression`,n=>D(n,0).pipe(f.filter(N),f.match({onNone:()=>d.void,onSome:({value:i})=>ta(i)&&r(n)?e.report(t.fromId({node:n,messageId:`parse`,data:{prefix:i}})):d.void}))))}}),aa=m.Struct({discriminants:m.Array(m.String).annotate({description:"Discriminant properties checked in addition to `_tag`. Replaces the default `['kind', 'status']`."}).pipe(m.optionalKey)}),oa=r.define({name:`no-manual-tag-comparison`,meta:H({type:`problem`,description:"Use Effect Match or Predicate helpers instead of manually branching on `_tag` or another configured discriminant.",messages:{manualComparison:`Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.`,manualSwitch:"Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`.",manualDiscriminantComparison:"Use Match.discriminator('{{discriminant}}')/Match.discriminators('{{discriminant}}') or a Match.when pattern instead of comparing `{{discriminant}}` manually.",manualDiscriminantSwitch:"Use Match.type or Match.value with Match.discriminatorsExhaustive('{{discriminant}}') instead of switching on `{{discriminant}}`.",isTagged:`Replace with {{replacement}}.`},hasSuggestions:!0,url:`https://github.com/dmmulroy/anti-slop/blob/main/src/effect/rules/no-manual-tag-comparison.ts`,schema:[{type:`object`,properties:{discriminants:{type:`array`,items:{type:`string`,minLength:1},uniqueItems:!0,description:"Discriminant properties to check in addition to `_tag`. Replaces the default list."}},additionalProperties:!1}],defaultOptions:[{discriminants:[`kind`,`status`]}]}),options:aa.pipe(m.UndefinedOr),*create(e){let n=yield*i,r=/* @__PURE__ */ new Set([`_tag`,...e?.discriminants??[]]);function a(e,n,r){return t.fromId({node:e,messageId:Ai(n)?`manual${r}`:`manualDiscriminant${r}`,data:{discriminant:f.getOrElse(C(n),()=>``)}})}function o(e,t){return Ai(t)&&Mi(e)}let l=d.fnUntraced(function*(e,r){let i=a(e,r,`Comparison`),o=r===e.left?e.right:e.left;if(!Ai(r)||!N(o)||c.isReadonlyArrayNonEmpty(n.sourceCode.getCommentsInside(e)))return yield*n.report(i);let s=e.operator===`!==`||e.operator===`!=`?`!`:``,l=`${U(n.sourceCode,r.object)}, ${n.sourceCode.getText(o)}`;function u(e){return`${s}${e}.isTagged(${l})`}let d=yield*Pt(e,`effect/Predicate`,`P`,u);return yield*n.report(t.withSuggestions(i,[{messageId:`isTagged`,data:{replacement:u(`P`)},fix:d}]))});return s.merge(s.on(`BinaryExpression`,e=>f.match(ji(e,r),{onNone:()=>d.void,onSome:t=>o(e,t)?d.void:l(e,t)})),s.on(`SwitchStatement`,e=>Ai(e.discriminant,r)?o(e,e.discriminant)?d.void:n.report(a(e,e.discriminant,`Switch`)):d.void))}}),sa=r.define({name:`no-manual-tagged-construction`,meta:H({type:`problem`,description:"Construct tagged values with their existing Effect constructor instead of writing `_tag` manually.",messages:{manualConstruction:"Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object."},url:`https://github.com/dmmulroy/anti-slop/blob/main/src/effect/rules/no-manual-tagged-construction.ts`}),*create(){let e=yield*i;return s.on(`ObjectExpression`,n=>Pi(n)?d.void:f.match(c.findFirst(n.properties,e=>e.type===`Property`&&f.contains(T(e),`_tag`)&&N(e.value)),{onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:n,messageId:`manualConstruction`}))}))}}),ca=/* @__PURE__ */ new Map([[`Effect.cachedInvalidateWithTTL`,`last`],[`Effect.cachedWithTTL`,`last`],[`Effect.delay`,`last`],[`Effect.sleep`,`last`],[`Effect.timeout`,`last`],[`Effect.timeoutOption`,`last`],[`Effect.timeoutOrElse`,`options.duration`],[`Schedule.duration`,`last`],[`Schedule.during`,`last`],[`Schedule.exponential`,`first`],[`Schedule.fibonacci`,`last`],[`Schedule.fixed`,`last`],[`Schedule.spaced`,`last`],[`Schedule.windowed`,`last`],[`Stream.debounce`,`last`],[`Stream.groupedWithin`,`last`],[`Stream.throttle`,`options.duration`],[`Stream.timeout`,`last`],[`TestClock.adjust`,`last`]]),la=_.type().pipe(_.withReturnType(),_.when(`first`,()=>e=>D(e,0)),_.when(`last`,()=>e=>D(e,e.arguments.length-1)),_.when(`options.duration`,()=>e=>D(e,e.arguments.length-1).pipe(f.filter(e=>e.type===`ObjectExpression`),f.flatMap(E(`duration`)),f.map(({value:e})=>e))),_.exhaustive);function ua(e,t){return f.match(t.path(e.callee).pipe(f.flatMapNullishOr(e=>ca.get(c.join(e,`.`)))),{onNone:()=>d.succeedNone,onSome:t=>d.map(je(e.callee),n=>n?la(t)(e):f.none())})}const da=_.type().pipe(_.withReturnType(),_.when(`*`,()=>f.some(te.multiply)),_.when(`+`,()=>f.some(te.sum)),_.when(`-`,()=>f.some(te.subtract)),_.when(`/`,()=>f.some(te.divideUnsafe)),_.when(`%`,()=>f.some(te.remainder)),_.when(`**`,()=>f.some((e,t)=>e**t)),_.orElse(()=>f.none()));function fa(e){return e.type===`Literal`&&b.isNumber(e.value)?f.some(e.value):f.none()}function pa(e){let t=O(e);if(t.type===`Literal`)return fa(t);if(t.type===`UnaryExpression`&&(t.operator===`-`||t.operator===`+`))return f.map(pa(t.argument),e=>t.operator===`+`?e:-e);if(t.type!==`BinaryExpression`||t.left.type===`PrivateIdentifier`)return f.none();let{left:n,right:r,operator:i}=t;return f.flatMap(da(i),e=>f.zipWith(pa(n),pa(r),(t,n)=>e(t,n)))}function ma(e){let t=O(e);return t.type===`Literal`?f.map(fa(t),c.of):t.type===`BinaryExpression`&&t.operator===`*`?f.zipWith(ma(t.left),ma(t.right),(e,t)=>[...e,...t]):f.none()}const ha=m.is(m.Literals([6e4,36e5,864e5])),ga=m.is(m.Literals([60,3600,86400])),_a=m.is(m.Literals([7,24,60,1e3,3600,86400]));function va(e){return ma(e).pipe(f.filter(e=>e.length>=2&&(c.some(e,ha)||c.some(e,ga)&&c.filter(e,_a).length>=2)),f.map(e=>({millis:c.contains(e,1e3)||c.some(e,e=>e%6e4==0)})))}const ya=g.flow(h.split(/[_$]+|(?<=[\da-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/u),c.filter(h.isNonEmpty),c.map(h.toLowerCase));m.Literals([`duration`,`instant`]);const ba=m.is(m.Literals([`millis`,`milliseconds`,`ms`])),xa=m.is(m.Literals([`at`,`created`,`deadline`,`end`,`ended`,`epoch`,`last`,`now`,`since`,`start`,`started`,`timestamp`,`until`,`updated`]));function Sa(e){let t=ya(e);return c.last(t).pipe(f.filter(ba),f.map(()=>c.some(t,xa)?`instant`:`duration`))}const Ca={weeks:S.weeks,days:S.days,hours:S.hours,minutes:S.minutes,seconds:S.seconds,millis:S.millis},wa=[[`weeks`,S.toWeeks],[`days`,S.toDays],[`hours`,S.toHours],[`minutes`,S.toMinutes],[`seconds`,S.toSeconds],[`millis`,S.toMillis]];function Ta(e){return!Number.isSafeInteger(e)||Math.abs(e)<1e4?String(e):h.replaceAll(/\B(?=(?:\d{3})+$)/gu,`_`)(String(e))}function Ea(e,t){let n=Ca[t](e);return S.isZero(n)?`Duration.zero`:c.findFirst(wa,([,e])=>Number.isSafeInteger(e(n))).pipe(f.match({onNone:()=>`Duration.millis(${n.pipe(S.toMillis,Ta)})`,onSome:([e,t])=>`Duration.${e}(${Ta(t(n))})`}))}const Da=m.is(m.Literals([`*`,`+`,`-`,`/`])),Oa={"!==":`Duration.equals`,"*":`Duration.times`,"+":`Duration.sum`,"-":`Duration.subtract`,"/":`Duration.divide`,"<":`Duration.isLessThan`,"<=":`Duration.isLessThanOrEqualTo`,"===":`Duration.equals`,">":`Duration.isGreaterThan`,">=":`Duration.isGreaterThanOrEqualTo`},ka={"!==":`DateTime.Equivalence`,"+":`DateTime.addDuration`,"-":`DateTime.subtractDuration`,"<":`DateTime.isLessThan`,"<=":`DateTime.isLessThanOrEqualTo`,"===":`DateTime.Equivalence`,">":`DateTime.isGreaterThan`,">=":`DateTime.isGreaterThanOrEqualTo`},Aa=`Duration.isPositive, Duration.isNegative or Duration.isZero`,ja={"!==":`Duration.isZero`,"<":Aa,"<=":Aa,"===":`Duration.isZero`,">":Aa,">=":Aa};function Ma(e){let t=O(e);return t.type===`TemplateLiteral`||t.type===`Literal`&&b.isString(t.value)?!0:t.type===`BinaryExpression`&&t.operator===`+`&&(Ma(t.left)||Ma(t.right))}function Na(e){let t=O(e);return t.type===`Identifier`&&t.name===`undefined`||t.type===`Literal`&&!b.isNumber(t.value)}function Pa(e,t){let n=e.name.parent;return(n.type===`AssignmentPattern`?n.parent:n).type===`Property`||e.type===`Parameter`&&f.exists(we(e.name),e=>Jn(e,t))}function K(e){return f.contains(e,`instant`)}function Fa(e,t){let{left:n,right:r}=t;return e===`+`?K(n)===K(r)?`duration`:`instant`:e===`-`&&K(n)&&!K(r)?`instant`:`duration`}function Ia(e,t){let n=K(t.left)||K(t.right);if(K(t.right)&&e.operator===`-`)return`DateTime.distance`;if(P(e.right,1e3)&&e.operator===`/`)return n?`DateTime.toEpochSeconds`:`Duration.toSeconds`;let r=!n&&(P(e.left,0)||P(e.right,0));return l.get(ja,e.operator).pipe(f.filter(()=>r),f.orElse(()=>f.filter(l.get(ka,e.operator),()=>n)),f.orElse(()=>l.get(Oa,e.operator)),f.getOrElse(()=>`Duration`))}function La(e){return e.type===`BinaryExpression`&&e.left.type!==`PrivateIdentifier`}function Ra(e){return f.flatMap(j(e),e=>se(e.type)?Ra(e):f.liftPredicate(e,La))}const za=r.define({name:`no-millis-arithmetic`,meta:H({type:`suggestion`,description:`Disallow arithmetic and comparisons on millisecond numbers where Effect Duration or DateTime can do the math.`,messages:{millisArithmetic:`{{operand}} is {{what}} in milliseconds. Keep it as a {{module}} and use {{suggestion}}; convert to milliseconds only where a non-Effect API needs them.`},url:`https://www.effect.website/docs/v4/api/effect/Duration`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};function r(e,t){return d.map(je(e),e=>e?f.some(t):f.none())}function a(e){return n.isApiPath(e,[`Duration`,`toMillis`])?r(e,`duration`):n.isApiPath(e,[`DateTime`,`toEpochMillis`])?r(e,`instant`):d.succeedNone}let o=d.fnUntraced(function*(e,t){let r=R(yield*ke(e,e.name));if(f.exists(r,e=>Pa(e,n)))return f.none();let i=Sa(e.name);if(f.isSome(i))return i;let a=f.flatMap(r,({node:e,name:t})=>e.type===`VariableDeclarator`&&be(e.parent)&&e.id===t&&b.isNotNull(e.init)?f.some(e.init):f.none());return f.isSome(a)?yield*c(a.value,t+1):f.none()});function c(e,t){if(t>4)return d.succeedNone;let i=O(e);if(i.type===`Identifier`)return o(i,t);if(i.type===`MemberExpression`)return d.succeed(i.object.type===`ThisExpression`?f.flatMap(C(i),Sa):f.none());if(i.type===`CallExpression`)return a(i.callee);if(i.type===`YieldExpression`){let e=i.argument;return b.isNotNull(e)&&i.delegate&&n.isApiPath(e,[`Clock`,`currentTimeMillis`])?r(e,`instant`):d.succeedNone}return!La(i)||!Da(i.operator)?d.succeedNone:d.map(u(i,t),f.map(e=>Fa(i.operator,e)))}function u(e,t){return!l.has(Oa,e.operator)||e.operator===`+`&&(Ma(e.left)||Ma(e.right))||(e.operator===`===`||e.operator===`!==`)&&(Na(e.left)||Na(e.right))?d.succeedNone:d.map(d.all({left:c(e.left,t),right:c(e.right,t)}),e=>f.isNone(e.left)&&f.isNone(e.right)?f.none():f.some(e))}function p(n,r){let i=K(r.left)||K(r.right);return e.report(t.fromId({node:n,messageId:`millisArithmetic`,data:{operand:e.sourceCode.getText(f.match(r.left,{onNone:()=>n.right,onSome:()=>n.left})),what:i?`a timestamp`:`a duration`,module:i?`DateTime`:`Duration`,suggestion:Ia(n,r)}}))}return s.on(`BinaryExpression`,d.fnUntraced(function*(e){if(!La(e))return;let t=yield*u(e,0);if(f.isNone(t))return;let n=Ra(e),r=f.isSome(n)?yield*u(n.value,0):f.none();f.isSome(r)||(yield*p(e,t.value))}))}}),Ba={addEventListener:1,on:1,setInterval:0};function Va(e){return f.exists(D(e,2),e=>e.type===`ObjectExpression`&&f.exists(E(e,`once`),e=>P(e.value,!0)))}function Ha(e,t){return w(e.callee).pipe(f.map(c.lastNonEmpty),f.exists(n=>f.exists(l.get(Ba,n),r=>(n!==`addEventListener`||!Va(e))&&f.exists(D(e,r),e=>ye(e,t)))))}function Ua(e){return f.exists(D(e,0),e=>{if(!A(e)||b.isNullish(e.body))return!1;let t=e.body;return f.exists(xe(e),({name:e})=>k(t,t=>t.type===`CallExpression`&&Ha(t,e)))})}const Wa=r.define({name:`no-multi-shot-effect-callback`,meta:H({type:`problem`,description:`Disallow attaching Effect.callback resume to repeating event sources.`,messages:{multiShot:`Effect.callback is single-shot, but this source emits repeatedly. Use a once-style subscription or Stream.callback.`},url:`https://github.com/Effect-TS/tsgo/issues/484`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Effect`,`callback`)&&Ua(r)?e.report(t.fromId({node:r,messageId:`multiShot`})):d.void)}}),Ga=m.Literals([`NaN`,`Infinity`,`undefined`]),Ka=m.is(Ga),qa=m.Literals([`annotate`,`annotateEncoded`,`annotateKey`]),Ja=m.is(qa),Ya=[`default`,`examples`];function Xa(e){return e.type===`Literal`&&b.isBigInt(e.value)||e.type===`Identifier`&&Ka(e.name)||A(e)||e.type===`CallExpression`&&f.exists(w(e.callee),e=>c.lastNonEmpty(e)===`Symbol`)}function Za(e){return e.type===`ArrayExpression`?c.filter(e.elements,e=>b.isNotNull(e)&&e.type!==`SpreadElement`):e.type===`ObjectExpression`?c.flatMap(e.properties,e=>e.type===`Property`?[e.value]:[]):[]}function Qa(e){let t=O(e);return Xa(t)?f.some(t):c.findFirst(c.reverse(Za(t)),Qa)}function $a(e,t){let n=e.callee.type===`MemberExpression`?C(e.callee):t.path(e.callee).pipe(f.filter(([e])=>e===`Schema`),f.flatMapNullishOr(([,e])=>e));return f.filter(n,Ja)}function eo(e){return me(e).pipe(f.filter(e=>f.isNone(E(e,`jsonSchema`))),f.match({onNone:()=>[],onSome:e=>c.getSomes(c.map(Ya,t=>f.flatMap(E(e,t),({value:e})=>Qa(e))))}))}const to=r.define({name:`no-non-json-schema-annotation`,meta:H({type:`problem`,description:`Disallow schema examples and defaults that cannot be represented in JSON Schema.`,messages:{nonJson:`This schema annotation value is not JSON-serializable and will be omitted from or corrupt generated JSON Schema.`},url:`https://github.com/Effect-TS/tsgo/issues/440`}),*create(){let e=yield*i,n=yield*V;return n.hasEffectImport?s.on(`CallExpression`,r=>f.match($a(r,n),{onNone:()=>d.void,onSome:()=>d.forEach(eo(r),n=>e.report(t.fromId({node:n,messageId:`nonJson`})),{discard:!0})})):{}}}),no=[`option`,`either`];function ro(e,t){return e.type===`CallExpression`&&t.isApi(e.callee,`Effect`,`service`)}function io(e,t){let n=D(e,0);return t.isApi(e.callee,`Effect`,no)?f.exists(n,e=>ro(e,t)):e.callee.type===`MemberExpression`&&f.exists(w(e.callee),e=>c.lastNonEmpty(e)===`pipe`)&&ro(O(e.callee.object),t)&&f.exists(n,e=>t.isApi(e,`Effect`,no))}const ao=r.define({name:`no-option-of-service`,meta:H({type:`problem`,description:`Disallow wrapping infallible Effect.service access in Option or Either.`,messages:{mandatory:`Effect.service never fails, so this wrapper is always present and keeps the service requirement. Use Effect.serviceOption.`},url:`https://github.com/Effect-TS/tsgo/issues/648`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>io(r,n)?e.report(t.fromId({node:r,messageId:`mandatory`})):d.void)}}),oo=r.define({name:`no-overwritten-discriminant`,meta:H({type:`problem`,description:`Ensure a later object spread cannot overwrite an explicitly assigned _tag.`,messages:{overwritten:`A later spread can overwrite _tag at runtime. Move _tag after all spreads.`},url:`https://github.com/Effect-TS/tsgo/issues/426`}),*create(){let e=yield*i;return s.on(`ObjectExpression`,n=>c.findFirstWithIndex(n.properties,e=>e.type===`Property`&&f.contains(T(e),`_tag`)).pipe(f.filter(([,e])=>c.some(c.drop(n.properties,e+1),e=>e.type===`SpreadElement`)),f.match({onNone:()=>d.void,onSome:([n])=>e.report(t.fromId({node:n,messageId:`overwritten`}))})))}}),so=m.is(m.String.check(m.isPattern(/\.(?:test|spec)\.[cm]?[jt]sx?$/u))),co=m.is(m.String.check(m.isPattern(/^make[A-Z]/u))),lo=m.is(m.String.check(m.isPattern(/^\.\.?\//u))),uo=r.define({name:`no-service-constructor-imports`,meta:H({type:`problem`,description:`Disallow project-local make<CapabilityName> imports outside test and spec files.`,messages:{serviceConstructorImport:`Do not import Effect service constructor "{{name}}" into runtime code. Import the owning Layer, yield the contextual service, and allow its requirements to propagate to the composition root.`},url:`https://github.com/dmmulroy/anti-slop/blob/main/src/effect/rules/no-service-constructor-imports.ts`}),*create(){let e=yield*i;return so(h.replaceAll(`\\`,`/`)(e.filename))?{}:s.on(`ImportDeclaration`,n=>lo(n.source.value)?d.forEach(c.filter(n.specifiers,e=>e.type===`ImportSpecifier`),n=>{let r=fe(n.imported);return co(r)?e.report(t.fromId({node:n,messageId:`serviceConstructorImport`,data:{name:r}})):d.void},{discard:!0}):d.void)}}),fo=[`getOrThrow`,`getOrThrowWith`];function po(e,t){return e.type===`CallExpression`&&t.isApi(e.callee,`Effect`,`serviceOption`)}function mo(e,t){return t.isApi(e.callee,`Option`,fo)?f.exists(D(e,0),e=>e.type===`YieldExpression`?b.isNotNullish(e.argument)&&po(e.argument,t):po(e,t)):e.callee.type===`MemberExpression`&&f.exists(w(e.callee),e=>c.lastNonEmpty(e)===`pipe`)&&po(O(e.callee.object),t)&&f.exists(D(e,0),e=>e.type===`CallExpression`&&t.isApi(e.callee,`Effect`,`map`)&&f.exists(D(e,0),e=>t.isApi(e,`Option`,fo)))}const ho=r.define({name:`no-service-option-get-or-throw`,meta:H({type:`problem`,description:`Disallow turning missing Effect services into untyped Option defects.`,messages:{getOrThrow:`Option.getOrThrow after Effect.serviceOption hides a mandatory service until runtime. Use Effect.service so it remains a typed requirement.`},url:`https://github.com/Effect-TS/tsgo/issues/650`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>mo(r,n)?e.report(t.fromId({node:r,messageId:`getOrThrow`})):d.void)}}),go=m.Literals([`andThen`,`map`,`mapError`,`tap`,`tapError`,`tapErrorCause`]),_o=m.is(go),vo=r.define({name:`no-throw-in-effect-callback`,meta:H({type:`problem`,description:`Disallow throw in Effect callbacks that cannot add the thrown value to the typed error channel.`,messages:{callbackThrow:`Throwing in this Effect callback creates an untyped defect. Return Effect.fail(...) or return the mapped error value instead.`},url:`https://github.com/Effect-TS/tsgo/issues/406`}),*create(){let e=yield*i,n=yield*V;return s.on(`ThrowStatement`,r=>f.exists(we(r),e=>f.exists(Kn(e,n),([e,t])=>e===`Effect`&&_o(t))||f.exists(Gn(e,`catch`),e=>n.isApi(e.callee,`Effect`,[`try`,`tryPromise`])))?e.report(t.fromId({node:r,messageId:`callbackThrow`})):d.void)}}),yo=m.Literals([`get`,`post`,`put`,`patch`,`delete`,`head`,`options`]),bo=m.is(yo),xo=m.is(m.String.check(m.isPattern(/[A-Z]/u)));function So(e,t){let n=e.parent,r=e.node;if(e.type!==`ImportBinding`||n?.type!==`ImportDeclaration`||_r(n,r.type===`ImportSpecifier`?r:void 0))return!1;let i=n.source.value;return r.type===`ImportNamespaceSpecifier`?i===`effect/unstable/httpapi/HttpApiEndpoint`&&t.length===2||i===`effect/unstable/httpapi`&&t.length===3&&t[1]===`HttpApiEndpoint`:r.type===`ImportSpecifier`&&r.imported.type===`Identifier`&&r.imported.name===`HttpApiEndpoint`&&i===`effect/unstable/httpapi`&&t.length===2}function Co(e){return w(e.callee).pipe(f.filter(e=>bo(c.lastNonEmpty(e))),f.match({onNone:()=>d.succeed(!1),onSome:t=>d.map(ke(e,c.headNonEmpty(t)),e=>f.exists(R(e),e=>So(e,t)))}))}function wo(e){return f.orElse(T(e),()=>e.key.type===`Literal`&&b.isNumber(e.key.value)?f.some(String(e.key.value)):f.none())}function To(e){return e.pipe(f.filter(e=>e.type===`ObjectExpression`),f.flatMap(e=>f.all(c.map(e.properties,pe))),f.filter(e=>f.all(c.map(e,wo)).pipe(f.exists(e=>c.dedupe(e).length===e.length))))}function Eo(e){return D(e,2).pipe(To,f.flatMap(e=>c.findFirst(e,e=>f.contains(T(e),`headers`))),f.map(({value:e})=>e),To)}const Do=r.define({name:`no-uppercase-http-api-header`,meta:H({type:`problem`,description:`Require lowercase static keys in Effect v4 endpoint header field schemas.`,messages:{uppercase:`Header schema key "{{name}}" contains ASCII uppercase letters. Incoming headers use exact lowercase runtime lookup; review the schema and its consumers before renaming this key.`},url:`https://github.com/Effect-TS/tsgo/issues/413`}),*create(){let e=yield*i;function n(n){return d.forEach(n,n=>T(n).pipe(f.filter(xo),f.match({onNone:()=>d.void,onSome:r=>e.report(t.fromId({node:n.key,messageId:`uppercase`,data:{name:r}}))})),{discard:!0})}return s.on(`CallExpression`,e=>c.some(e.arguments,e=>e.type===`SpreadElement`)?d.void:d.flatMap(Co(e),t=>t?f.match(Eo(e),{onNone:()=>d.void,onSome:n}):d.void))}}),Oo=r.define({name:`no-zero-retry-times`,meta:H({type:`problem`,description:`Disallow no-op retry and repeat wrappers with times: 0.`,messages:{zeroTimes:`times: 0 performs no retries or repeats. Remove the wrapper or use a positive count.`},url:`https://github.com/Effect-TS/tsgo/issues/412`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Effect`,[`retry`,`repeat`])?me(r).pipe(f.flatMap(E(`times`)),f.filter(e=>P(e.value,0)),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:n,messageId:`zeroTimes`}))})):d.void)}}),ko={Exit:[`isSuccess`,`isFailure`],Result:[`isSuccess`,`isFailure`],Option:[`isSome`,`isNone`]};function Ao(e,t){let n=O(e.type===`UnaryExpression`&&e.operator===`!`?e.argument:e);return n.type!==`CallExpression`||n.arguments.length!==1?f.none():f.flatMap(t.path(n.callee),e=>{let[t,n]=e;return e.length===2&&b.isNotUndefined(t)&&b.isNotUndefined(n)&&f.exists(l.get(ko,t),c.contains(n))?f.some([t,n]):f.none()})}function jo(e){return k(e,e=>e.type===`YieldExpression`||e.type===`AwaitExpression`)}function Mo(e){return f.exists(e,e=>f.exists(e.type===`BlockStatement`?c.last(e.body):f.some(e),t=>t.type===`ReturnStatement`&&b.isNotNull(t.argument)&&!jo(e)))}function No(e){return j(e).pipe(f.filter(e=>e.type===`BlockStatement`||e.type===`Program`),f.flatMap(t=>{let n=t.body;return f.filter(c.get(n,n.indexOf(e)+1),e=>e.type===`ReturnStatement`)}))}const Po=r.define({name:`prefer-data-match`,meta:H({type:`suggestion`,description:`Use Exit.match, Result.match or Option.match instead of branching on their guards to produce a value.`,messages:{preferMatch:"Use `{{module}}.match` instead of branching on `{{module}}.{{guard}}` and producing a value in both branches."},url:`https://www.effect.website/docs/v4/api/effect/Option`}),*create(){let e=yield*i,n=yield*V;function r(r,i,a){return Ao(i,n).pipe(f.filter(a),f.match({onNone:()=>d.void,onSome:([n,i])=>e.report(t.fromId({node:r,messageId:`preferMatch`,data:{module:n,guard:i}}))}))}return s.merge(s.on(`ConditionalExpression`,e=>r(e,e.test,()=>!jo(e.consequent)&&!jo(e.alternate))),s.on(`IfStatement`,e=>r(e,e.test,()=>Mo(f.some(e.consequent))&&Mo(f.fromNullishOr(e.alternate).pipe(f.orElse(()=>No(e)))))))}}),Fo=m.is(m.String.check(m.isPattern(/^is\p{Lu}/u)));function Io(e){return e.type===`Identifier`?f.some(e.name):e.type===`RestElement`&&e.argument.type===`Identifier`?f.some(e.argument.name):f.none()}function Lo(e,t){return k(e,e=>e.type===`ThisExpression`||e.type===`Identifier`&&c.contains(t,e.name))}function Ro(e,t){let n=c.last(t.params).pipe(f.filter(e=>e.type===`RestElement`),f.flatMap(Io));return e.type===`SpreadElement`?f.filter(n,t=>e.argument.type===`Identifier`&&e.argument.name===t):e.type===`Identifier`&&!f.contains(n,e.name)?f.some(e.name):f.none()}function zo(e,t,n){return f.all(c.flatMap(e.arguments,e=>Ro(e,t).pipe(f.filter(e=>c.contains(n,e)),f.match({onSome:e=>[f.some(e)],onNone:()=>A(e)||Lo(e,n)?[f.none()]:[]}))))}function Bo(e){return e.async||e.generator||e.typeParameters?f.none():f.zipWith(f.filter(f.all(c.map(e.params,Io)),c.isReadonlyArrayNonEmpty),f.filter(G(e),e=>e.type===`CallExpression`&&!e.optional),(e,t)=>({names:e,call:t})).pipe(f.flatMap(({names:t,call:n})=>n.callee.type===`Super`||Lo(n.callee,t)?f.none():zo(n,e,t).pipe(f.filter(e=>c.makeEquivalence(h.Equivalence)(e,t)),f.map(()=>({call:n,exact:n.arguments.length===t.length})))))}function Vo(e){return e.returnType?.typeAnnotation.type===`TSTypePredicate`}function Ho(e,t){let n=e.type===`CallExpression`?e.callee:e;return f.exists(t.path(n),e=>c.get(e,1).pipe(f.filter(()=>e.length===2),f.exists(t=>f.contains(c.head(e),`Schema`)?t===`is`:Fo(t))))}function Uo(e,t){return e.type===`Identifier`?!0:e.type===`MemberExpression`?f.isSome(t.path(e)):e.type===`CallExpression`&&e.callee.type!==`Identifier`&&Uo(e.callee,t)}function Wo(e,t){return Ee(t,e.name)?!1:e.type!==`Variable`&&e.type!==`ClassName`?!0:e.type===`Variable`&&!be(e.parent)?!1:v.get(e.node.range,1)<=v.get(t.range,0)&&!Go(t,e.node)}function Go(e,t){let n=e.parent;return!n||Ee(n,t)?!1:n.type===`FunctionDeclaration`||Go(n,t)}function Ko(e,t,n){return c.every(c.filter(e.getScope(t).references,({identifier:e})=>Ee(t,e)),({resolved:e})=>!e||!c.some(e.references,e=>e.isWrite()&&!e.init)&&c.every(e.defs,e=>Wo(e,n)))}const qo={"Array.filter":2,"Array.findFirst":2,"Array.findFirstIndex":2,"Array.flatMap":2,"Array.flatten":1,"Array.head":1,"Array.isArrayEmpty":1,"Array.isArrayNonEmpty":1,"Array.isReadonlyArrayEmpty":1,"Array.isReadonlyArrayNonEmpty":1,"Array.last":1,"Array.length":1,"Array.map":2,"Array.reverse":1,"Option.filter":2,"Option.flatMap":2,"Option.flatten":1,"Option.getFailure":1,"Option.getOrElse":2,"Option.getOrNull":1,"Option.getOrUndefined":1,"Option.getSuccess":1,"Option.isNone":1,"Option.isSome":1,"Option.map":2,"Option.match":2,"Option.orElse":2,"Option.some":1,"Result.flatMap":2,"Result.getFailure":1,"Result.getOrElse":2,"Result.getSuccess":1,"Result.isFailure":1,"Result.isSuccess":1,"Result.map":2,"Result.mapError":2};function Jo(e,t){return t.path(e).pipe(f.filter(e=>e.length===2),f.flatMap(e=>{let t=c.join(e,`.`);return f.map(l.get(qo,t),e=>v.make(t,e))}))}function Yo(e,t,n){return(e.type===`Identifier`||e.type===`MemberExpression`)&&f.exists(n.path(e),e=>c.join(e,`.`)===t)}function Xo(e){return e.optional||b.isNotNullish(e.typeArguments)||c.some(e.arguments,e=>e.type===`SpreadElement`)?f.none():f.some(e.arguments)}function Zo(e,t){return e.type===`CallExpression`?f.product(Jo(e.callee,t),Xo(e)).pipe(f.flatMap(([[t,n],r])=>r.length===n?f.map(c.head(r),n=>({self:n,step:{api:t,node:e,callee:e.callee,args:c.drop(r,1)}})):f.none())):f.none()}function Qo(e,t){return e.type===`CallExpression`?f.product(Jo(e.callee,t),Xo(e)).pipe(f.flatMap(([[t,n],r])=>r.length+1===n?f.some({api:t,node:e,callee:e.callee,args:r}):f.none())):e.type===`Identifier`||e.type===`MemberExpression`?f.flatMap(Jo(e,t),([t,n])=>n===1?f.some({api:t,node:e,callee:e,args:[]}):f.none()):f.none()}function $o(e,t){if(e.type!==`CallExpression`)return f.none();let n=e.callee;return f.flatMap(Xo(e),r=>n.type===`MemberExpression`&&n.object.type!==`Super`&&f.contains(C(n),`pipe`)?f.some({kind:`pipe`,call:e,subject:f.some(n.object),steps:r}):t.isApi(n,`Function`,`pipe`)||t.isApiPath(n,[`pipe`])?f.some({kind:`pipe`,call:e,subject:c.head(r),steps:c.drop(r,1)}):t.isApi(n,`Function`,`flow`)||t.isApiPath(n,[`flow`])?f.some({kind:`flow`,call:e,subject:f.none(),steps:r}):f.none())}function es(e,t){return c.map(t,t=>U(e.sourceCode,t))}function q(e,t={}){return(n,r)=>f.some({api:e,negate:t.negate??!1,safety:t.safety?.(n,r)??`fix`,args:t.args?.(n,r)??es(r,[...n.inner.args,...n.outer.args])})}function ts(e,t){return({inner:n,outer:r},i)=>{let[a=``,o=``]=es(i,[...n.args,...r.args]);return[`{ ${e}: ${a}, ${t}: ${o} }`]}}function J(e){return c.head(e.args)}function ns(e){return e.type===`ArrowFunctionExpression`&&!e.async&&c.isReadonlyArrayEmpty(e.params)}function rs(e){return ns(e)&&e.expression&&P(e.body,!1)}function is(e){return e.type===`CallExpression`?is(e.callee):e}const as=/* @__PURE__ */ new Set([`contains`,`endsWith`,`every`,`exists`,`has`,`includes`,`is`,`some`,`startsWith`]),os=/* @__PURE__ */ new Set([`!=`,`!==`,`<`,`<=`,`==`,`===`,`>`,`>=`,`in`,`instanceof`]);function ss(e,t){return _.value(e).pipe(_.discriminators(`type`)({BinaryExpression:({operator:e})=>os.has(e),UnaryExpression:({operator:e})=>e===`!`,Literal:({value:e})=>b.isBoolean(e),LogicalExpression:({operator:e,left:n,right:r})=>e!==`??`&&ss(n,t)&&ss(r,t),ConditionalExpression:({consequent:e,alternate:n})=>ss(e,t)&&ss(n,t),CallExpression:e=>t.path(is(e)).pipe(f.flatMap(e=>c.get(e,1)),f.exists(e=>as.has(e)||/^is\p{Lu}/u.test(e)))}),_.orElse(g.constFalse))}function cs(e,t){return e.type===`ConditionalExpression`?cs(e.consequent,t)||cs(e.alternate,t):e.type===`CallExpression`&&!ss(e,t)&&f.exists(t.path(is(e)),e=>f.contains(c.head(e),`Option`))}function ls(e){return A(e)&&!e.async&&!e.generator?G(e):f.none()}function us(e,t){return f.exists(J(e.inner),e=>ds(e,t.imports))?`fix`:`boolean`}function ds(e,t){return Ho(e,t)||f.exists(ls(e),e=>ss(e,t))}const fs=/* @__PURE__ */ new Set(/* @__PURE__ */ `append.appendAll.dedupe.drop.empty.filter.filterMap.flatMap.flatMapNullishOr.flatten.fromIterable.getFailures.getSomes.getSuccesses.make.map.of.prepend.prependAll.range.replicate.reverse.sort.sortBy.sortWith.take`.split(`.`));function ps(e,t){return e.type===`ArrayExpression`||t.isApi(e.type===`CallExpression`?e.callee:e,`Array`,[...fs])}function ms(e){return(t,n)=>f.map(e(t,n),e=>e.safety===`fix`&&!f.exists(t.input,e=>ps(e,n.imports))?u.assign(e,{safety:`array`}):e)}function hs(e){return A(e)&&e.params.length<=1&&c.every(e.params,e=>e.type!==`RestElement`)&&(e.type===`ArrowFunctionExpression`||!ye(e,`arguments`))}function gs(e){return A(e)||e.type===`Literal`||e.type===`TemplateLiteral`&&c.isReadonlyArrayEmpty(e.expressions)||f.isSome(w(e))}function _s(e){return(t,n)=>J(t.inner).pipe(f.flatMap(ls),f.exists(e=>cs(e,n.imports)))?f.none():e(t,n)}function vs(e,t){if(e.type!==`ArrowFunctionExpression`||e.async||!e.expression||e.params.length!==1)return!1;let[n]=e.params,r=e.body;return n?.type===`Identifier`&&r.type===`MemberExpression`&&!r.optional&&r.object.type===`Identifier`&&r.object.name===n.name&&f.contains(C(r),t)}const ys=[{guard:`Option.isSome`,field:`value`,getter:f.some(`Option.getOrThrow`),api:`Array.getSomes`},{guard:`Result.isSuccess`,field:`success`,getter:f.some(`Result.getOrThrow`),api:`Array.getSuccesses`},{guard:`Result.isFailure`,field:`failure`,getter:f.none(),api:`Array.getFailures`}];function bs(e,t){return f.product(J(e.inner),J(e.outer)).pipe(f.flatMap(([e,n])=>c.findFirst(ys,r=>Yo(e,r.guard,t.imports)&&(vs(n,r.field)||f.exists(r.getter,e=>Yo(n,e,t.imports))))),f.flatMap(({api:n})=>q(n,{args:()=>[]})(e,t)))}function xs(e,t){return f.exists(J(e.outer),e=>f.exists(t.imports.path(e),e=>c.join(e,`.`)===`Predicate.isNotNullish`))?q(`Array.flatMapNullishOr`,{args:({inner:e})=>es(t,e.args),safety:({inner:e})=>f.exists(J(e),hs)?`fix`:`none`})(e,t):f.none()}const Ss=[`Option.getSuccess`,`Result.getSuccess`],Cs=[`Option.getFailure`,`Result.getFailure`],ws=[{inner:[`Option.some`],outer:[`Option.filter`],rewrite:q(`Option.liftPredicate`)},{inner:[`Option.filter`],outer:[`Option.isSome`],rewrite:q(`Option.exists`)},{inner:[`Option.filter`],outer:[`Option.isNone`],rewrite:q(`Option.exists`,{negate:!0})},{inner:[`Option.map`],outer:[`Option.flatten`],rewrite:q(`Option.flatMap`)},{inner:[`Option.map`],outer:[`Option.getOrElse`],rewrite:(e,t)=>f.exists(J(e.outer),rs)&&f.exists(J(e.inner),e=>ds(e,t.imports))?q(`Option.exists`,{args:({inner:e})=>es(t,e.args)})(e,t):q(`Option.match`,{args:ts(`onSome`,`onNone`)})(e,t)},{inner:Ss,outer:[`Option.isSome`],rewrite:q(`Result.isSuccess`)},{inner:Ss,outer:[`Option.isNone`],rewrite:q(`Result.isFailure`)},{inner:Cs,outer:[`Option.isSome`],rewrite:q(`Result.isFailure`)},{inner:Cs,outer:[`Option.isNone`],rewrite:q(`Result.isSuccess`)},{inner:Ss,outer:[`Option.getOrNull`],rewrite:q(`Result.getOrNull`)},{inner:Ss,outer:[`Option.getOrUndefined`],rewrite:q(`Result.getOrUndefined`)},{inner:Ss,outer:[`Option.getOrElse`],rewrite:q(`Result.getOrElse`,{safety:({outer:e})=>f.exists(J(e),ns)?`fix`:`none`})},{inner:[`Array.findFirst`],outer:[`Option.isSome`],rewrite:_s(ms(q(`Array.some`,{safety:us})))},{inner:[`Array.findFirst`],outer:[`Option.isNone`],rewrite:_s(ms(q(`Array.some`,{negate:!0,safety:us})))},{inner:[`Array.findFirstIndex`],outer:[`Option.isSome`],rewrite:ms(q(`Array.some`))},{inner:[`Array.findFirstIndex`],outer:[`Option.isNone`],rewrite:ms(q(`Array.some`,{negate:!0}))},{inner:[`Array.filter`],outer:[`Array.head`],rewrite:q(`Array.findFirst`,{safety:()=>`pure`})},{inner:[`Array.filter`],outer:[`Array.isArrayNonEmpty`,`Array.isReadonlyArrayNonEmpty`],rewrite:q(`Array.some`,{safety:()=>`pure`})},{inner:[`Array.filter`],outer:[`Array.isArrayEmpty`,`Array.isReadonlyArrayEmpty`],rewrite:q(`Array.some`,{negate:!0,safety:()=>`pure`})},{inner:[`Array.filter`],outer:[`Array.length`],rewrite:q(`Array.countBy`)},{inner:[`Array.filter`],outer:[`Array.map`],rewrite:bs},{inner:[`Array.map`],outer:[`Array.filter`],rewrite:xs},{inner:[`Array.map`],outer:[`Array.flatten`],rewrite:q(`Array.flatMap`)},{inner:[`Array.head`,`Array.last`],outer:[`Option.isSome`],rewrite:q(`Array.isReadonlyArrayNonEmpty`)},{inner:[`Array.head`,`Array.last`],outer:[`Option.isNone`],rewrite:q(`Array.isReadonlyArrayEmpty`)},{inner:[`Array.reverse`],outer:[`Array.head`],rewrite:ms(q(`Array.last`))},{inner:[`Result.map`],outer:[`Result.getOrElse`],rewrite:q(`Result.match`,{args:ts(`onSuccess`,`onFailure`)})},{inner:[`Result.map`],outer:[`Result.mapError`],rewrite:q(`Result.mapBoth`,{args:ts(`onSuccess`,`onFailure`)})},{inner:[`Result.mapError`],outer:[`Result.map`],rewrite:q(`Result.mapBoth`,{args:ts(`onFailure`,`onSuccess`)})}];function Ts(e,t){let n=e.nested&&c.isReadonlyArrayNonEmpty(e.inner.args)&&!c.every(e.outer.args,gs);return c.findFirst(ws,n=>c.contains(n.inner,e.inner.api)&&c.contains(n.outer,e.outer.api)?n.rewrite(e,t):f.none()).pipe(f.map(e=>n?u.assign(e,{safety:`none`}):e))}function Es(e){if(!A(e)||e.async||e.generator||b.isNullish(e.body))return f.none();let t=e.body,n=t.type===`BlockStatement`?c.head(t.body).pipe(f.filter(e=>t.body.length===1&&e.type===`ReturnStatement`),f.flatMapNullishOr(e=>e.argument)):f.some(t);return f.filter(n,e=>e.type===`CallExpression`)}function Ds(e,t,n=!1){return(r,{imports:i,sourceCode:a})=>Es(r).pipe(f.filter(t=>A(r)&&b.isNullish(r.returnType)&&(!n||hs(r))&&Os(t,e,i)),f.flatMap(e=>Xo(e).pipe(f.filter(e=>e.length===1),f.flatMap(c.head),f.map(n=>{let i=U(a,n),o=n.type===`ObjectExpression`&&r.type===`ArrowFunctionExpression`&&r.body===e?`(${i})`:i;return{api:t,callback:`a callback that returns ${a.getText(e.callee)}(…)`,argument:f.some(ks(a,r,e.range,o))}}))))}function Os(e,t,n){return f.exists(n.path(e.callee),e=>c.join(e,`.`)===t)}function ks(e,t,n,r){let i=e.text,[a,o]=t.range;return`${h.slice(a,v.get(n,0))(i)}${r}${h.slice(v.get(n,1),o)(i)}`}function As(e){return(t,{imports:n,sourceCode:r})=>{let i=t.type===`ArrowFunctionExpression`&&!t.async&&t.expression?f.some(t.body):f.none(),a=f.exists(i,e=>e.type===`Literal`&&e.raw===`null`)||n.isApi(t,`Function`,`constNull`),o=f.exists(i,e=>z(r.getScope(e),e,`undefined`))||n.isApi(t,`Function`,`constUndefined`);if(!a&&!o)return f.none();let s=a?`null`:`undefined`;return f.some({api:a?`${e}.getOrNull`:`${e}.getOrUndefined`,callback:`a fallback of ${s}`,argument:f.none()})}}function js(e,{imports:t,sourceCode:n}){if(e.type!==`ObjectExpression`||e.properties.length!==2)return f.none();let r=c.getSomes(c.map(e.properties,pe));function i(e){return c.findFirst(r,t=>f.contains(T(t),e)&&!t.shorthand)}return i(`onNone`).pipe(f.filter(e=>r.length===2&&rs(e.value)),f.flatMap(()=>i(`onSome`)),f.filter(e=>ds(e.value,t)),f.map(e=>({api:`Option.exists`,callback:"`onNone: () => false`",argument:f.some(U(n,e.value))})))}function Ms(e,{imports:t,sourceCode:n}){return e.type===`CallExpression`&&Os(e,`Filter.toOption`,t)?Xo(e).pipe(f.filter(e=>e.length===1),f.flatMap(c.head),f.map(t=>({api:`Option.filterMap`,callback:`${n.getText(e.callee)}(…)`,argument:f.some(U(n,t))}))):f.none()}const Ns=[{apis:[`Option.flatMap`],rewrite:Ds(`Option.fromNullishOr`,`Option.flatMapNullishOr`)},{apis:[`Option.flatMap`],rewrite:Ds(`Option.some`,`Option.map`)},{apis:[`Option.flatMap`],rewrite:Ms},{apis:[`Option.orElse`],rewrite:Ds(`Option.some`,`Option.orElseSome`)},{apis:[`Option.getOrElse`],rewrite:As(`Option`)},{apis:[`Option.match`],rewrite:js},{apis:[`Result.flatMap`],rewrite:Ds(`Result.succeed`,`Result.map`)},{apis:[`Result.getOrElse`],rewrite:As(`Result`)},{apis:[`Array.flatMap`],rewrite:Ds(`Array.fromNullishOr`,`Array.flatMapNullishOr`,!0)}];function Ps(e,t){return f.flatMap(J(e),n=>c.findFirst(Ns,r=>c.contains(r.apis,e.api)?r.rewrite(n,t):f.none()))}const Fs={"Option.getSuccess":`Filter.toOption`,"Result.getSuccess":`Filter.toOption`,"Result.isSuccess":`Filter.toPredicate`};function Is(e,t){let[n]=e.params;if(e.async||e.generator||e.typeParameters||e.params.length!==1||n?.type!==`Identifier`)return f.none();let r=f.flatMap(G(e),e=>Zo(e,t).pipe(f.map(({step:e,self:t})=>v.make(e,t)),f.orElse(()=>$o(e,t).pipe(f.filter(({kind:e,steps:t})=>e===`pipe`&&t.length===1),f.flatMap(({subject:e,steps:n})=>c.head(n).pipe(f.flatMap(e=>Qo(e,t)),f.product(e)))))));return f.flatMap(r,([e,t])=>f.flatMap(l.get(Fs,e.api),r=>{let[i]=t.type===`CallExpression`?t.arguments:[];return t.type===`CallExpression`&&!t.optional&&t.callee.type!==`Super`&&t.arguments.length===1&&i?.type===`Identifier`&&i.name===n.name&&!k(t.callee,e=>e.type===`ThisExpression`||e.type===`Identifier`&&e.name===n.name)?f.some({check:e,filter:t,api:r}):f.none()}))}function Ls(e){return!!e.returnType||c.some(e.params,e=>e.type===`Identifier`&&!!e.typeAnnotation)}function Rs(e){let[t,n=``]=h.split(e,`.`);return[t,n]}function zs(e,t){return`${e}(${c.join(t,`, `)})`}function Bs(e,t){return c.isReadonlyArrayEmpty(t)?e:zs(e,t)}function Vs(e,t){let n=t.parent;return n?.type===`MemberExpression`&&n.object===t||(n?.type===`CallExpression`||n?.type===`NewExpression`)&&n.callee===t||n?.type===`TaggedTemplateExpression`||n?.type===`BinaryExpression`&&n.operator===`**`&&n.left===t?`(!${e})`:`!${e}`}const Hs={array:`pairIfArray`,boolean:`pairIfBoolean`,fix:`pair`,none:`pair`,pure:`pairIfPure`},Us=r.define({name:`prefer-direct-effect-combinators`,meta:H({type:`suggestion`,description:`Prefer the direct Effect Option, Array, Result and Filter API over an indirect chain of calls.`,messages:{pair:`Use {{direct}} instead of {{inner}} followed by {{outer}}.`,pairIfPure:`Use {{direct}} instead of {{inner}} followed by {{outer}}. It stops at the first match, so check that the callback has no side effects or exceptions that relied on running for every element.`,pairIfBoolean:`Use {{direct}} instead of {{inner}} followed by {{outer}} if the callback returns a boolean. {{inner}} also accepts a callback that returns an Option, which {{direct}} would treat as a match.`,pairIfArray:`Use {{direct}} instead of {{inner}} followed by {{outer}} if the input is an array. {{direct}} takes an array, while {{inner}} also takes other iterables, such as a Set.`,callback:`Use {{direct}} instead of {{outer}} with {{callback}}.`,filterCheck:`Use {{direct}}({{filter}}) instead of a function that applies {{check}} to the Result of {{filter}}.`,replace:`Replace with {{direct}}.`},url:`https://www.effect.website/docs/v4/api/effect/Option`,fixable:`code`,hasSuggestions:!0}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};let{sourceCode:r}=e,a={imports:n,sourceCode:r};function o(e){return U(r,e)}function l(e){return c.some(r.getAllComments(),t=>c.some(e,e=>Ee({range:e.range},t)))}let p=d.fnUntraced(function*(n){let[r,i]=Rs(n.api),a=yield*f.match(m(n.callees,r),{onNone:()=>Nt(n.node,`effect/${r}`,vr(r)),onSome:e=>d.succeed({name:e,fix:f.none()})}),o=`${a.name}.${i}`,s=n.negate?`!${o}`:o,p=t.fromId({node:n.node,messageId:n.messageId,data:u.assign(n.data,{direct:s})}),h=n.edits(o).pipe(f.filter(e=>!l(e)),f.filter(()=>n.safety!==`none`));if(f.isNone(h))return yield*e.report(p);let g=t.composeFixes(...f.toArray(a.fix),...c.map(h.value,e=>t.replaceText({range:e.range},e.text)));return yield*e.report(n.safety===`fix`?t.withFix(p,g):t.withSuggestions(p,[{messageId:`replace`,data:{direct:s},fix:g}]))});function m(e,t){return c.findFirst(e,e=>e.type===`MemberExpression`&&!e.computed&&f.exists(n.path(e.object),e=>e.length===1&&f.contains(c.head(e),t))?f.some(r.getText(e.object)):f.none())}function h(e,t,n){return f.match(Ts(t,a),{onNone:()=>d.void,onSome:i=>p({node:e,messageId:Hs[i.safety],data:{inner:r.getText(t.inner.callee),outer:r.getText(t.outer.callee)},api:i.api,negate:i.negate,safety:i.safety,edits:e=>n(i,e),callees:[t.inner.callee,t.outer.callee]})})}function g(e,t,n){return e.negate?Vs(t,n):t}function _(e){return Zo(e,n).pipe(f.flatMap(e=>f.map(Zo(e.self,n),t=>({outer:e.step,inner:t}))),f.match({onNone:()=>d.void,onSome:({outer:t,inner:n})=>h(e,{inner:n.step,outer:t,input:f.some(n.self),nested:!0},(t,r)=>f.some([{range:e.range,text:g(t,zs(r,[o(n.self),...t.args]),e)}]))}))}function y({call:e,subject:t,steps:r}){return t.pipe(f.flatMap(e=>Zo(e,n)),f.product(f.flatMap(c.head(r),e=>Qo(e,n))),f.match({onNone:()=>d.void,onSome:([n,i])=>h(i.node,{inner:n.step,outer:i,input:f.some(n.self),nested:!1},(a,s)=>{let l=zs(s,[o(n.self),...a.args]);return r.length===1?f.some([{range:e.range,text:g(a,l,e)}]):a.negate?f.none():f.product(t,c.get(r,1)).pipe(f.map(([e,t])=>[{range:e.range,text:l},{range:[v.get(i.node.range,0),v.get(t.range,0)],text:``}]))})}))}function x(e){let{kind:t,call:i,steps:a}=e,o=c.map(a,e=>Qo(e,n));return d.forEach(c.zip(c.dropRight(o,1),c.drop(o,1)),([n,o],s)=>f.product(n,o).pipe(f.match({onNone:()=>d.void,onSome:([n,o])=>h(o.node,{inner:n,outer:o,input:s===0?e.subject:c.get(a,s-1),nested:!1},(e,c)=>{let l=Bs(c,e.args),u=[v.get(n.node.range,0),v.get(o.node.range,1)];return e.negate?t===`pipe`&&s+2===a.length?f.some([{range:i.range,text:Vs(ks(r,i,u,l),i)}]):f.none():f.some([{range:u,text:l}])})})),{discard:!0})}function ee(e){return Zo(e,n).pipe(f.map(({step:e,self:t})=>v.make(e,f.some(t))),f.orElse(()=>f.map(Qo(e,n),e=>v.make(e,f.none()))),f.flatMap(([e,t])=>f.map(Ps(e,a),n=>({step:e,self:t,rewrite:n}))),f.match({onNone:()=>d.void,onSome:({step:t,self:n,rewrite:i})=>p({node:e,messageId:`callback`,data:{outer:r.getText(t.callee),callback:i.callback},api:i.api,negate:!1,safety:`fix`,edits:t=>{let r=[...n.pipe(f.map(o),f.toArray),...f.toArray(i.argument)];return f.some([{range:e.range,text:f.match(n,{onNone:()=>Bs(t,r),onSome:()=>zs(t,r)})}])},callees:[t.callee]})}))}function S(e){return f.match(Is(e,n),{onNone:()=>d.void,onSome:({check:t,filter:i,api:a})=>{let o=b.isNullish(i.typeArguments)&&Uo(i.callee,n)&&Ko(r,i.callee,e);return p({node:e,messageId:`filterCheck`,data:{check:r.getText(t.callee),filter:r.getText(i.callee)},api:a,negate:!1,safety:o?Ls(e)?`suggest`:`fix`:`none`,edits:t=>f.some([{range:e.range,text:zs(t,[U(r,i.callee)])}]),callees:[i.callee]})}})}return s.merge(s.on(`CallExpression`,e=>d.andThen(d.all([_(e),ee(e)],{discard:!0}),f.match($o(e,n),{onNone:()=>d.void,onSome:e=>d.all([y(e),x(e)],{discard:!0})}))),s.on(`ArrowFunctionExpression`,S),s.on(`FunctionExpression`,S))}}),Ws=r.define({name:`prefer-effect-alchemy-namespace-imports`,meta:H({type:`suggestion`,description:`Use consistently aliased namespace imports for Effect and Alchemy submodule entrypoints.`,messages:{alias:"Import {{source}} as the canonical namespace alias `{{alias}}`.",namespace:'Use `import * as {{alias}} from "{{source}}"` instead of importing values directly.'},url:`https://github.com/Effect-TS/language-service/blob/main/packages/language-service/src/core/AutoImport.ts`,fixable:`code`}),*create(){let e=yield*i;function n(n,r){let i={alias:r,source:n.source.value};function a(r,a){return e.report(It(t.fromId({node:r,messageId:a,data:i}),Tr(e.sourceCode,n)))}return d.forEach(c.filter(n.specifiers,e=>e.type!==`ImportSpecifier`||!_r(n,e)),e=>e.type===`ImportNamespaceSpecifier`?e.local.name===r?d.void:a(e.local,`alias`):a(e,`namespace`),{discard:!0})}return s.on(`ImportDeclaration`,e=>br(e.source.value).pipe(f.filter(()=>e.importKind!==`type`),f.match({onNone:()=>d.void,onSome:t=>n(e,vr(t))})))}});function Gs(e){let[t,n]=h.split(e,`/`);return b.isNotUndefined(n)&&h.startsWith(`@`)(t)?`${t}/${n}`:t}function Ks(e){return e.importKind===`type`||c.isReadonlyArrayNonEmpty(e.specifiers)&&c.every(e.specifiers,e=>e.type===`ImportSpecifier`&&e.importKind===`type`)}function qs(e){return s.merge(s.on(`ImportDeclaration`,t=>Ks(t)?d.void:e(t.source,f.some(t))),s.on(`ImportExpression`,({source:t})=>N(t)?e(t,f.none()):d.void))}const Js={"@zip.js/zip.js":`Zip`,"adm-zip":`Zip`,archiver:`Zip or Tar`,"client-zip":`Zip`,jszip:`Zip`,"js-untar":`Tar`,"modern-tar":`Tar`,nanotar:`Tar`,"node-stream-zip":`Zip`,"tar-js":`Tar`,"tar-stream":`Tar`,unzipper:`Zip`,yauzl:`Zip`,"yauzl-promise":`Zip`,yazl:`Zip`,"zip-stream":`Zip`},Ys=m.Literals([`AsyncUnzipInflate`,`AsyncZipDeflate`,`Unzip`,`UnzipInflate`,`UnzipPassThrough`,`Zip`,`ZipDeflate`,`ZipPassThrough`,`unzip`,`unzipSync`,`zip`,`zipSync`]),Xs=m.is(Ys);function Zs(e){return f.match(e,{onNone:()=>[],onSome:({specifiers:e})=>c.filter(e,e=>e.type===`ImportSpecifier`&&e.importKind!==`type`&&Xs(fe(e.imported)))})}const Qs=r.define({name:`prefer-effect-archive`,meta:H({type:`suggestion`,description:`Prefer Effect Tar and Zip over tar and zip libraries in Effect projects.`,messages:{archive:`Use {{module}} from effect/encoding instead of {{source}}: its decode and encode channels stream entries without buffering whole bodies.`},url:`https://www.effect.website/docs/v4/api/effect/encoding/Zip`}),*create(){let e=yield*i;if(!(yield*V).hasEffectImport)return{};function n(n,r,i){return e.report(t.fromId({node:n,messageId:`archive`,data:{module:i,source:r}}))}return qs((e,t)=>{let r=Gs(e.value);return r===`fflate`?d.forEach(Zs(t),e=>n(e,`fflate`,`Zip`),{discard:!0}):f.match(l.get(Js,r),{onNone:()=>d.void,onSome:t=>n(e,e.value,t)})})}});function $s(e,t){return e?.type===`NewExpression`&&e.arguments.length===1&&z(t,e.callee,`Set`)}function ec(e,t){if(e.type===`ArrayExpression`){let[n]=e.elements;return e.elements.length===1&&n?.type===`SpreadElement`&&$s(n.argument,t)}return e.callee.type===`MemberExpression`&&f.contains(C(e.callee),`from`)&&z(t,e.callee.object,`Array`)&&e.arguments.length===1&&f.exists(D(e,0),e=>$s(e,t))}function tc(e){let t=e.parent;return t.type===`AssignmentExpression`&&t.left===e||t.type===`UpdateExpression`||t.type===`UnaryExpression`&&t.operator===`delete`}function nc(e,t){let n=t.getText(e.object);return k(f.getOrElse(we(e),()=>t.ast),e=>e.type===`MemberExpression`&&e.computed&&e.property.type===`Literal`&&b.isNumber(e.property.value)&&e.property.value!==0&&t.getText(e.object)===n)}function rc(e){return e.type===`MemberExpression`&&f.contains(C(e),`length`)}const ic={"!=":`nonEmpty`,"!==":`nonEmpty`,"==":`empty`,"===":`empty`};function ac(e){let t=O(e.left),n=O(e.right);return rc(t)&&P(n,0)?e.operator===`>`?f.some(`nonEmpty`):l.get(ic,e.operator):P(t,0)&&rc(n)?e.operator===`<`?f.some(`nonEmpty`):l.get(ic,e.operator):f.none()}function oc(e){let t=e.callee;return t.type===`MemberExpression`?C(t):t.type===`Identifier`?f.some(t.name):f.none()}function sc(e){if(e.type!==`ArrowFunctionExpression`||e.async||!e.expression||e.params.length!==1)return f.none();let[t]=e.params,n=O(e.body);return t?.type===`Identifier`&&n.type===`MemberExpression`&&n.object.type===`Identifier`&&n.object.name===t.name?C(n):f.none()}const cc=r.define({name:`prefer-effect-array-ops`,meta:H({type:`suggestion`,description:`Prefer Effect Array and Struct helpers over hand-written array idioms in Effect files.`,messages:{dedupe:`Use Arr.dedupe instead of deduplicating through a Set.`,head:`Use Arr.head, which returns an Option, instead of indexing the first element (Tuple.get for tuples).`,empty:"Use Arr.isReadonlyArrayEmpty (Str.isEmpty for strings) instead of comparing `.length` with 0.",nonEmpty:"Use Arr.isReadonlyArrayNonEmpty (Str.isNonEmpty for strings), which narrows to a non-empty array, instead of comparing `.length` with 0.",structGet:`Use Struct.get('{{key}}') instead of a property accessor lambda.`},url:`https://www.effect.website/docs/v4/api/effect/Array`}),*create(){let e=yield*i;if(!(yield*V).hasEffectImport)return{};function n(n){return d.flatMap(o.getScope(n),r=>ec(n,r)?e.report(t.fromId({node:n,messageId:`dedupe`})):d.void)}function r(n){return f.contains(oc(n),`map`)?d.forEach(n.arguments,n=>f.match(sc(n),{onNone:()=>d.void,onSome:r=>e.report(t.fromId({node:n,messageId:`structGet`,data:{key:r}}))}),{discard:!0}):d.void}return s.merge(s.on(`ArrayExpression`,n),s.on(`CallExpression`,n=>d.flatMap(o.getScope(n),i=>ec(n,i)?e.report(t.fromId({node:n,messageId:`dedupe`})):r(n))),s.on(`MemberExpression`,n=>n.computed&&P(n.property,0)&&!tc(n)&&!nc(n,e.sourceCode)?e.report(t.fromId({node:n,messageId:`head`})):d.void),s.on(`BinaryExpression`,n=>f.match(ac(n),{onNone:()=>d.void,onSome:r=>e.report(t.fromId({node:n,messageId:r}))})))}}),lc=r.define({name:`prefer-effect-array-sort`,meta:H({type:`suggestion`,description:`Prefer immutable, Order-based Effect Array sorting in Effect projects.`,messages:{effectArraySort:`Use Arr.sort with an Order instead of the mutable native Array.sort method.`},url:`https://www.effect.website/docs/v4/api/effect/Array#sort`}),*create(){let e=yield*i,n=yield*V;return n.hasEffectImport?s.on(`CallExpression`,r=>r.callee.type===`MemberExpression`&&f.contains(C(r.callee),`sort`)&&!n.isApi(r.callee,`Array`,`sort`)?e.report(t.fromId({node:r,messageId:`effectArraySort`})):d.void):{}}}),uc=m.Literals([`cookie`,`set-cookie`]),dc=m.is(uc),fc=m.Literals([`split`,`match`,`matchAll`]),pc=m.is(fc),mc=m.Literals([`includes`,`startsWith`,`endsWith`]),hc=m.is(mc),gc=/;\s*(?:HttpOnly|Secure|Partitioned|(?:Path|Domain|Max-Age|Expires|SameSite)=)/iu,_c=/^(?:;\s*(?:HttpOnly|Secure|Partitioned|Path|Domain|Max-Age|Expires|SameSite)\b|HttpOnly$|Max-Age=|SameSite=)/iu;function vc(e){return h.includes(`cookie`)(h.toLowerCase(e))}function yc(e){let t=O(e),n=t.type===`ChainExpression`?f.some(t.expression):t.type===`LogicalExpression`?f.some(t.left):t.type===`CallExpression`&&t.callee.type===`Identifier`&&t.callee.name===`String`?D(t,0):f.none();return f.match(n,{onNone:()=>t,onSome:yc})}const bc=_.type().pipe(_.discriminators(`type`)({Identifier:({name:e})=>vc(e),MemberExpression:e=>f.exists(C(e),vc),CallExpression:e=>f.contains(Sc(e),`get`)&&c.some(e.arguments,e=>N(e)&&dc(h.toLowerCase(e.value)))}),_.orElse(g.constFalse));function xc(e){return bc(yc(e))}function Sc(e){return e.callee.type===`MemberExpression`?C(e.callee):f.none()}function Cc(e){return e.callee.type===`MemberExpression`&&e.callee.object.type!==`Super`?f.some(e.callee.object):f.none()}function wc(e){return f.exists(Sc(e),t=>pc(t)?f.exists(Cc(e),xc):t===`exec`&&f.exists(D(e,0),xc))}function Tc(e,t){let n=f.orElse(Sc(e),()=>t.member(e.callee,`String`));return f.exists(n,hc)&&f.exists(D(e,0),e=>N(e)&&_c.test(e.value))}function Ec(e){return c.isReadonlyArrayNonEmpty(e.expressions)&&c.some(e.quasis,e=>gc.test(e.value.cooked??e.value.raw))}function Dc(e){return N(e)&&gc.test(e.value)}const Oc=r.define({name:`prefer-effect-cookies`,meta:H({type:`suggestion`,description:`Prefer the Effect Cookies module over parsing, building and inspecting cookie strings by hand.`,messages:{documentCookie:`document.cookie is one unparsed string. Parse it with Cookies.parseHeader, and write cookies from the server with HttpServerResponse.setCookie.`,parseCookies:`Read request cookies with HttpServerRequest cookies or schemaCookies, or parse a header with Cookies.parseHeader or Cookies.fromSetCookie, instead of splitting or matching it by hand.`,serializeCookie:`Build cookies with Cookies.makeCookie and Cookies.serializeCookie, or HttpServerResponse.setCookie, which validate names, values and attributes.`,inspectCookie:`Parse Set-Cookie headers with Cookies.fromSetCookie and read the attributes from Cookies.get(…).options, instead of searching the string for them.`},url:`https://www.effect.website/docs/v4/api/effect/http/Cookies`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};function r(n,r){return e.report(t.fromId({node:n,messageId:r}))}function a(e){return!f.exists(M(e,`CallExpression`),t=>F(t.arguments,e)&&f.isSome(n.member(t.callee,`Cookies`)))&&f.contains(C(e),`cookie`)?B(e.object,`document`):d.succeed(!1)}return s.merge(s.on(`MemberExpression`,e=>d.when(r(e,`documentCookie`),a(e))),s.on(`CallExpression`,e=>wc(e)?r(e,`parseCookies`):Tc(e,n)?r(e,`inspectCookie`):d.void),s.on(`TemplateLiteral`,e=>Ec(e)&&e.parent.type!==`TaggedTemplateExpression`?r(e,`serializeCookie`):d.void),s.on(`BinaryExpression`,e=>e.operator===`+`&&(Dc(e.right)&&!N(e.left)||Dc(e.left)&&!N(e.right))?r(e,`serializeCookie`):d.void))}});function kc(e){return N(e)?f.some(e.value):e.type===`TemplateLiteral`&&c.isReadonlyArrayEmpty(e.expressions)?f.flatMapNullishOr(c.head(e.quasis),({value:e})=>e.cooked):f.none()}function Ac(e){return e.type===`Literal`&&`regex`in e&&b.isNotNullish(e.regex)?f.some(e.regex.pattern):f.none()}const jc=/^(?:\(\?:|[()|?*+[\]]|\\r|\\n)+$/u;function Mc(e){return f.exists(kc(e),e=>e===`
3
+ `||e===`\r
4
+ `)||f.exists(Ac(e),e=>h.includes(String.raw`\n`)(e)&&jc.test(e))}const Nc=/* @__PURE__ */ new Set([`,`,`;`,` `]);function Pc(e){return kc(e).pipe(f.orElse(()=>Ac(e)),f.exists(e=>Nc.has(e===String.raw`\t`?` `:e)))}function Fc(e,t,n,r){if(e.type!==`CallExpression`)return f.none();if(r.isApi(e.callee,n,t))return e.arguments.length===1?f.map(D(e,0),e=>({separator:e,subject:f.none()})):f.map(D(e,1),t=>({separator:t,subject:D(e,0)}));let i=e.callee;return i.type===`MemberExpression`&&f.isNone(r.path(i))&&f.contains(C(i),t)&&e.arguments.length===1?f.map(D(e,0),e=>({separator:e,subject:f.some(i.object)})):f.none()}function Ic(e,t,n){return Fc(e,`split`,`String`,n).pipe(f.filter(e=>t(e.separator)),f.map(({subject:e})=>e))}function Lc(e,t,n){return Fc(e,`join`,`Array`,n).pipe(f.filter(e=>t(e.separator)),f.map(({subject:e})=>e))}function Rc(e,t,n){return e.type===`MemberExpression`&&f.contains(C(e),t)&&z(n.getScope(e),e.object,`JSON`)}function zc(e){return e.type===`Identifier`&&!f.exists(j(e),t=>t.type===`MemberExpression`&&t.property===e&&!t.computed||t.type===`Property`&&t.key===e&&!t.computed&&!t.shorthand)}function Bc(e,t){let n=L(t.sourceCode,e,e.name);return R(n).pipe(f.filter(e=>e.type===`Variable`),f.flatMap(e=>e.node.type===`VariableDeclarator`&&e.node.id.type===`Identifier`&&b.isNotNullish(e.node.init)&&f.exists(n,({references:e})=>c.every(e,e=>!e.isWrite()||e.init))?f.some(e.node.init):f.none()))}const Vc=/* @__PURE__ */ new Set([`append`,`appendAll`,`concat`,`dedupe`,`drop`,`dropRight`,`filter`,`prepend`,`prependAll`,`reverse`,`slice`,`sort`,`sortWith`,`take`,`takeRight`,`toReversed`,`toSorted`]);function Hc(e,t){let n=e.type===`CallExpression`?e.callee:e;return f.orElse(t.member(n,`Array`),()=>n.type===`MemberExpression`&&f.isNone(t.path(n))?C(n):f.none())}function Uc(e,t){return f.exists(Hc(e,t),e=>Vc.has(e))}function Wc(e,t){let n=e.callee;return f.match(t.path(n),{onSome:()=>e.arguments.length>1||f.exists(Hc(e,t),e=>e===`dedupe`||e===`reverse`)?D(e,0):f.none(),onNone:()=>n.type===`MemberExpression`?f.some(n.object):f.none()})}function Gc(e,t,n,r){return f.exists(c.last(e),i=>{let a=c.dropRight(e,1);return c.isReadonlyArrayNonEmpty(a)&&!t.matches(i)?(i.type===`CallExpression`&&f.isNone(Wc(i,n.imports))||i.type===`MemberExpression`)&&(Uc(i,n.imports)||i.type===`CallExpression`&&t.preserves(i))&&Gc(a,t,n,r):Kc(i,t,n,r)})}function Kc(e,t,n,r=3){let i=e.type===`SpreadElement`?e.argument:O(e);return t.matches(i)?!0:zc(i)?r>0&&f.exists(Bc(i,n),e=>Kc(e,t,n,r-1)):i.type===`ArrayExpression`?c.some(i.elements,e=>e?.type===`SpreadElement`&&Kc(e,t,n,r)):i.type===`CallExpression`?Jc(i,n.imports)?Gc([...i.callee.type===`MemberExpression`?[i.callee.object]:[],...i.arguments],t,n,r):(Uc(i,n.imports)||t.preserves(i))&&f.exists(Wc(i,n.imports),e=>Kc(e,t,n,r)):!1}function qc(e){return{matches:t=>f.isSome(Ic(t,Mc,e.imports)),preserves:t=>el(t,{mapper:t=>e.imports.isApi(t,`String`,Zc),element:t=>Qc(t,e.imports)!==t})}}function Jc(e,t){return t.isApiPath(e.callee,[`pipe`])||t.isApiPath(e.callee,[`Function`,`pipe`])||e.callee.type===`MemberExpression`&&f.contains(C(e.callee),`pipe`)}function Yc(e,t,n){let r=c.findFirstIndex(e.arguments,e=>e===t),i=f.match(r,{onNone:()=>[],onSome:t=>c.take(e.arguments,t)}),a=e.callee.type===`MemberExpression`&&f.isNone(n.path(e.callee))?[e.callee.object]:[],o=M(e,`CallExpression`).pipe(f.match({onNone:()=>[],onSome:t=>c.isReadonlyArrayEmpty(i)&&c.isReadonlyArrayEmpty(a)&&F(t.arguments,e)&&Jc(t,n)?[...t.callee.type===`MemberExpression`?[t.callee.object]:[],...c.takeWhile(t.arguments,t=>t!==e)]:[]}));return[...a,...i,...o]}function Xc(e,t){return M(e,`CallExpression`).pipe(f.filter(t=>F(t.arguments,e)),f.exists(n=>Gc(Yc(n,e,t.imports),qc(t),t,3)))}const Zc=[`trim`,`trimEnd`,`trimStart`];function Qc(e,t){let n=O(e);return n.type===`CallExpression`?t.isApi(n.callee,`String`,Zc)?f.match(D(n,0),{onNone:()=>n,onSome:e=>Qc(e,t)}):n.callee.type===`MemberExpression`&&f.exists(C(n.callee),e=>c.contains(Zc,e))&&c.isReadonlyArrayEmpty(n.arguments)?Qc(n.callee.object,t):n:n}function $c(e,t){let n=Qc(e,t.imports);return n.type===`Identifier`&&f.exists(R(L(t.sourceCode,n,n.name)),e=>{if(e.type===`Parameter`){let n=e.node;return A(n)&&I(c.head(n.params),e.name)&&Xc(n,t)}let n=e.parent?.parent;return e.type===`Variable`&&n?.type===`ForOfStatement`&&n.left===e.parent&&Kc(n.right,qc(t),t)})}function el(e,t){return e.type===`CallExpression`&&c.some(e.arguments,e=>t.mapper(e)||A(e)&&f.exists(G(e),t.element))}function tl(e,t,n){return Gc(e,{matches:e=>el(e,t),preserves:()=>!1},n,3)}function nl(e,t,n){return f.match(t,{onSome:c.of,onNone:()=>Yc(e,e,n)})}const rl=r.define({name:`prefer-effect-csv`,meta:H({type:`suggestion`,description:`Prefer Effect Csv over splitting lines into cells or joining cells and rows by hand.`,messages:{decode:`Use Csv.decodeString or Csv.decodeSchemaString from effect/encoding instead of splitting each line on a delimiter: quoted cells may contain the delimiter, quotes and line breaks.`,encode:`Use Csv.encodeString or Csv.encodeSchemaString from effect/encoding instead of joining cells and rows: joined cells are not quoted when they contain the delimiter, quotes or line breaks.`},url:`https://www.effect.website/docs/v4/api/effect/encoding/Csv`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};let r={imports:n,sourceCode:e.sourceCode},a={mapper:e=>f.exists(Lc(e,Pc,n),f.isNone),element:e=>f.isSome(Lc(e,Pc,n))};function o(e){return f.exists(Ic(e,Pc,n),t=>f.match(t,{onNone:()=>Xc(e,r),onSome:e=>$c(e,r)}))}function c(e){return f.exists(Lc(e,Mc,n),t=>tl(nl(e,t,n),a,r))}return s.on(`CallExpression`,n=>o(n)?e.report(t.fromId({node:n,messageId:`decode`})):c(n)?e.report(t.fromId({node:n,messageId:`encode`})):d.void)}}),il=m.Literals([`toISOString`,`toLocaleDateString`,`toLocaleTimeString`]),al=m.is(il),ol=r.define({name:`prefer-effect-datetime`,meta:H({type:`suggestion`,description:`Prefer Effect DateTime formatting so time-zone behavior is explicit and composable.`,messages:{effectDateTime:`Convert to DateTime and format it in an explicit zone: DateTime.setZone with DateTime.formatIsoDate, formatIsoOffset or formatIsoZoned, or DateTime.format with timeZone. DateTime.formatIso is UTC, like toISOString: use it only for UTC instants, never slice it for a local date.`},url:`https://www.effect.website/docs/v4/api/effect/DateTime`}),*create(){let e=yield*i;return(yield*V).hasEffectImport?s.on(`CallExpression`,n=>n.callee.type===`MemberExpression`&&f.exists(C(n.callee),al)?e.report(t.fromId({node:n,messageId:`effectDateTime`})):d.void):{}}}),sl=r.define({name:`prefer-effect-duration`,meta:H({type:`suggestion`,description:`Prefer explicit Effect Duration constructors over ambiguous millisecond literals.`,messages:{effectDuration:`Wrap this number with Duration.millis or use a more descriptive Duration constructor.`},url:`https://www.effect.website/docs/v4/api/effect/Duration`,fixable:`code`}),*create(){let e=yield*i,n=yield*V,r=d.fnUntraced(function*(n,r){let i=yield*Nt(n,`effect/Duration`,`Duration`),a=t.replaceText(r,`${i.name}.millis(${e.sourceCode.getText(r)})`);yield*e.report(t.withFix(t.fromId({node:r,messageId:`effectDuration`}),t.composeFixes(...f.toArray(i.fix),a)))});return s.on(`CallExpression`,e=>d.flatMap(ua(e,n),t=>t.pipe(f.filter(e=>f.isSome(pa(e))),f.match({onNone:()=>d.void,onSome:t=>r(e,t)}))))}}),cl={ms:`millis`,milli:`millis`,millis:`millis`,millisecond:`millis`,milliseconds:`millis`,sec:`seconds`,secs:`seconds`,seconds:`seconds`,mins:`minutes`,minutes:`minutes`,hr:`hours`,hrs:`hours`,hours:`hours`,days:`days`,weeks:`weeks`},ll=m.is(m.Literals([`day`,`hour`,`minute`,`second`,`week`])),ul=m.is(m.Literals([`backoff`,`cooldown`,`day`,`debounce`,`delay`,`duration`,`expiration`,`expiry`,`hour`,`interval`,`lifetime`,`minute`,`second`,`throttle`,`timeout`,`ttl`,`week`])),dl=m.is(m.Literals([`at`,`epoch`,`per`,`timestamp`])),fl=m.is(m.Literals([`days`,`hours`,`millis`,`minutes`,`seconds`,`weeks`]));function pl(e){let t=ya(e),n=t.indexOf(`in`);if(n>0&&n<t.length-1&&f.exists(c.get(t,n-1),e=>l.has(cl,e)||ll(e))||c.some(t,dl))return`excluded`;let r=c.get(t,t.length-2);return f.match(c.last(t),{onNone:()=>`none`,onSome:e=>f.match(l.get(cl,e),{onSome:e=>e,onNone:()=>ul(e)||e===`age`&&f.contains(r,`max`)||e===`in`&&f.contains(r,`expires`)?`unknown`:`none`})})}function ml(e){return e.type===`Identifier`?f.some(c.of(e.name)):e.type===`TSQualifiedName`?f.map(ml(e.left),t=>c.append(t,e.right.name)):f.none()}function hl(e,t,n){return k(e,e=>e.type===`TSTypeReference`&&f.exists(ml(e.typeName),([r,...i])=>f.exists(L(t,e,r),({defs:e})=>c.some(e,e=>e.type===`ImportBinding`))&&f.fromNullishOr(n.bindings.get(r)).pipe(f.exists(e=>f.contains(c.head([...e,...i]),`Duration`)))))}function gl(e){return e.type===`VariableDeclarator`&&be(e.parent)&&e.id.type===`Identifier`&&e.init!==null&&f.isSome(pa(e.init))}function _l(e){let t=O(e);return t.type===`Identifier`?d.map(ke(t,t.name),e=>R(e).pipe(f.map(({node:e})=>e),f.filter(gl))):d.succeedNone}const vl=re.mapInput(re.Number,([e])=>e),yl=r.define({name:`prefer-effect-duration-constants`,meta:H({type:`suggestion`,description:`Prefer Effect Duration values over plain-number duration constants.`,messages:{durationConstant:`{{name}} holds a duration as a plain number. Declare it as {{replacement}} and convert at non-Effect boundaries with Duration.toMillis or Duration.toSeconds.`},url:`https://www.effect.website/docs/v4/api/effect/Duration`}),*create(){let e=yield*i,n=yield*V,r=yield*p.make(ne.empty());function a(t,r){if(t.id.typeAnnotation&&hl(t.id.typeAnnotation,e.sourceCode,n))return f.none();let i=pl(t.id.name),a=f.liftPredicate(i,fl);if(r)return f.some(f.orElseSome(a,()=>`millis`));if(i===`excluded`||f.getOrElse(pa(t.init),()=>0)<=0)return f.none();if(f.isSome(a))return f.some(a);let o=va(t.init);return f.exists(o,({millis:e})=>e)?f.some(f.some(`millis`)):i===`unknown`||f.isSome(o)?f.some(f.none()):f.none()}function o([,[n,r]]){return f.match(a(n,r),{onNone:()=>d.void,onSome:r=>e.report(t.fromId({node:n.id,messageId:`durationConstant`,data:{name:n.id.name,replacement:f.zipWith(pa(n.init),r,Ea).pipe(f.getOrElse(()=>`a Duration constructor such as Duration.seconds`))}}))})}return s.merge(s.on(`VariableDeclarator`,e=>n.hasEffectImport&&gl(e)?p.update(r,t=>ne.has(t,v.get(e.range,0))?t:ne.set(t,v.get(e.range,0),[e,!1])):d.void),s.on(`CallExpression`,e=>ua(e,n).pipe(d.flatMap(f.match({onNone:()=>d.succeedNone,onSome:_l})),d.flatMap(f.match({onNone:()=>d.void,onSome:e=>p.update(r,t=>ne.set(t,v.get(e.range,0),[e,!0]))})))),s.onExit(`Program`,()=>d.flatMap(p.get(r),e=>d.forEach(c.sort(ne.toEntries(e),vl),o,{discard:!0}))))}}),bl=m.is(m.Literals([`Finite`,`FiniteFromString`,`Int`,`Number`,`NumberFromString`])),xl=m.is(m.Literals([`NullOr`,`NullishOr`,`UndefinedOr`,`optional`,`optionalKey`])),Sl=m.is(m.Literals([`annotate`,`annotateKey`,`brand`,`check`,`withConstructorDefault`,`withDecodingDefault`,`withDecodingDefaultKey`])),Cl=m.is(m.Literals([`annotate`,`check`])),wl=m.is(m.Literals([`TSNullKeyword`,`TSNumberKeyword`,`TSUndefinedKeyword`]));function Tl(e,t){return t.member(e,`Schema`)}function El(e,t){if(e.type===`SpreadElement`)return!1;let n=O(e);return n.type===`CallExpression`?f.exists(Tl(n.callee,t),Sl):f.exists(Tl(n,t),xl)}function Dl(e,t){let n=O(e);if(n.type!==`CallExpression`)return f.exists(Tl(n,t),bl);let r=n.callee;return f.exists(Tl(r,t),xl)?f.exists(D(n,0),e=>Dl(e,t)):r.type!==`MemberExpression`||r.object.type===`Super`||!Dl(r.object,t)?!1:f.exists(C(r),e=>e===`pipe`?c.every(n.arguments,e=>El(e,t)):Cl(e))}function Ol(e){let t=e?.typeAnnotation;return t?.type===`TSNumberKeyword`||t?.type===`TSUnionType`&&c.some(t.types,e=>e.type===`TSNumberKeyword`)&&c.every(t.types,e=>wl(e.type))}function kl(e){return f.contains(Sa(e),`duration`)}function Al(e){return e.computed?e.key.type===`Literal`&&h.isString(e.key.value)?f.some(e.key.value):f.none():e.key.type===`Identifier`?f.some(e.key.name):f.none()}const jl=m.String.check(m.isPattern(/\.d\.[cm]?ts$/u)),Ml=m.is(jl);function Nl(e){return b.hasProperty(e,`declare`)&&e.declare}function Pl(e,t){return f.isSome(Ce(e,Nl))||f.exists(we(e),n=>Jn(n,t)&&c.some(n.params,t=>Ee(t,e)))}function Fl(e){let t=e.type===`TSParameterProperty`?e.parameter:e;if(t.type===`Identifier`)return Ol(t.typeAnnotation)?f.some(t):f.none();if(t.type!==`AssignmentPattern`||t.left.type!==`Identifier`)return f.none();let n=O(t.right);return Ol(t.left.typeAnnotation)||!t.left.typeAnnotation&&n.type===`Literal`&&b.isNumber(n.value)?f.some(t.left):f.none()}const Il=r.define({name:`prefer-effect-duration-types`,meta:H({type:`suggestion`,description:`Prefer Duration types over plain numbers for millisecond parameters and fields.`,messages:{durationType:`{{name}} holds a duration as a number of milliseconds. Type it as Duration.Input (or Duration.Duration) and convert with Duration.toMillis only where a non-Effect API needs milliseconds.`,durationSchema:`{{name}} decodes a duration as a plain number. Use Schema.DurationFromMillis to keep milliseconds in the encoded data, or Schema.Duration.`},url:`https://www.effect.website/docs/v4/api/effect/Duration`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};let r=Ml(e.filename);function a(n,r,i){return e.report(t.fromId({node:n,messageId:i,data:{name:r}}))}function o(e){return r||!e.body||Jn(e,n)||Pl(e,n)?d.void:d.forEach(c.filter(c.getSomes(c.map(e.params,Fl)),({name:e})=>kl(e)),e=>a(e,e.name,`durationType`),{discard:!0})}function l(e){return Al(e).pipe(f.filter(t=>kl(t)&&Ol(e.typeAnnotation)&&!r&&!Pl(e,n)),f.match({onNone:()=>d.void,onSome:t=>a(e.key,t,`durationType`)}))}return s.merge(s.on(`ArrowFunctionExpression`,o),s.on(`FunctionDeclaration`,o),s.on(`FunctionExpression`,o),s.on(`PropertyDefinition`,l),s.on(`TSPropertySignature`,l),s.on(`Property`,e=>e.parent.type===`ObjectExpression`?T(e).pipe(f.filter(t=>kl(t)&&Dl(e.value,n)),f.match({onNone:()=>d.void,onSome:t=>a(e.key,t,`durationSchema`)})):d.void))}}),Ll=m.Literals([`base64`,`base64url`,`hex`]),Rl=m.is(Ll),zl={base64:`Base64`,base64url:`Base64Url`,hex:`Hex`};function Bl(e,t){return f.flatMap(D(e,t),e=>N(e)&&Rl(e.value)?f.some(e.value):f.none())}function Vl(e){return D(e,1).pipe(f.filter(e=>e.type===`ObjectExpression`),f.flatMap(E(`alphabet`)),f.exists(({value:e})=>P(e,`base64url`)))}function Hl(e){return e.callee.type===`MemberExpression`&&f.contains(C(e.callee),`toString`)?f.map(Bl(e,0),e=>({messageId:`encode`,native:`toString('${e}')`,replacement:`${zl[e]}.encode`})):f.flatMap(w(e.callee),t=>{let n=c.join(t,`.`);return n===`Buffer.from`?f.map(Bl(e,1),e=>({messageId:`decode`,native:`Buffer.from(…, '${e}')`,replacement:`${zl[e]}.decode`})):n===`Uint8Array.fromHex`?f.some({messageId:`decode`,native:n,replacement:`Hex.decode`}):n===`Uint8Array.fromBase64`?f.some({messageId:`decode`,native:n,replacement:Vl(e)?`Base64Url.decode`:`Base64.decode`}):f.none()})}const Ul={atob:{messageId:`atob`,native:`atob`,replacement:`Base64.decode`},btoa:{messageId:`btoa`,native:`btoa`,replacement:`Base64.encode`}},Wl=m.Literals([`atob`,`btoa`]),Gl=m.is(Wl),Kl=r.define({name:`prefer-effect-encoding`,meta:H({type:`suggestion`,description:`Prefer the Effect v4 Base64, Base64Url, and Hex modules over native binary encoding APIs.`,messages:{atob:`Use Base64.decode from effect/encoding instead of atob: it returns the bytes as a Uint8Array in a Result with an EncodingError, where atob returns a binary string and throws on invalid input. Use Base64.decodeString only for UTF-8 text.`,btoa:`Use Base64.encode from effect/encoding instead of btoa, and pass it the bytes rather than a binary string: btoa throws on characters above U+00FF, and Base64.encode encodes strings as UTF-8.`,decode:`Use {{replacement}} from effect/encoding instead of {{native}}: it returns a Result with an EncodingError instead of throwing on invalid input.`,encode:`Use {{replacement}} from effect/encoding instead of {{native}}: it accepts bytes or UTF-8 text and runs the same in Node.js, browsers, and Workers.`},url:`https://effect.website/docs/v4/api/effect/encoding/Base64`}),*create(){let e=yield*i;if(!(yield*V).hasEffectImport)return{};function n(e){let t=e.callee.type===`MemberExpression`&&f.exists(w(e.callee),e=>e.length===2&&f.contains(c.head(e),`globalThis`))?e.callee.object:e.callee,n=w(e.callee).pipe(f.map(c.lastNonEmpty),f.filter(Gl));return f.match(n,{onNone:()=>d.succeedNone,onSome:n=>d.map(B(t,t===e.callee?n:`globalThis`),t=>t&&c.isReadonlyArrayNonEmpty(e.arguments)?f.some(Ul[n]):f.none())})}return s.on(`CallExpression`,r=>d.flatMap(n(r),n=>n.pipe(f.orElse(()=>Hl(r)),f.match({onNone:()=>d.void,onSome:({messageId:n,native:i,replacement:a})=>e.report(t.fromId({node:r,messageId:n,data:{native:i,replacement:a}}))}))))}}),ql=m.Literals([`fs`,`fs/promises`,`node:fs`,`node:fs/promises`]),Jl=m.is(ql),Yl=r.define({name:`prefer-effect-filesystem`,meta:H({type:`suggestion`,description:`Prefer the Effect FileSystem service over direct Node.js filesystem imports in Effect projects.`,messages:{effectFileSystem:`Use the FileSystem service from effect/FileSystem instead of {{source}}.`},url:`https://www.effect.website/docs/v4/api/effect/FileSystem`}),*create(){let e=yield*i;return(yield*V).hasEffectImport?s.on(`ImportDeclaration`,({source:n})=>Jl(n.value)?e.report(t.fromId({node:n,messageId:`effectFileSystem`,data:{source:n.value}})):d.void):{}}});function Xl(e,t,n,r){return e.type===`CallExpression`&&r.isApi(e.callee,`Result`,t)&&f.exists(D(e,0),e=>e.type===`Identifier`&&e.name===n)}const Zl=r.define({name:`prefer-effect-filter`,meta:H({type:`suggestion`,description:`Prefer Effect Filter constructors for reusable Result-valued predicates.`,messages:{effectFilter:`Use Filter.fromPredicate for this Result-valued predicate so it composes as a Filter.`},url:`https://www.effect.website/docs/v4/api/effect/Filter`}),*create(){let e=yield*i,n=yield*V;function r(r){return f.exists(xe(r),({name:e})=>f.exists(G(r),t=>t.type===`ConditionalExpression`&&Xl(t.consequent,`succeed`,e,n)&&Xl(t.alternate,`fail`,e,n)))?e.report(t.fromId({node:r,messageId:`effectFilter`})):d.void}return s.merge(s.on(`ArrowFunctionExpression`,r),s.on(`FunctionExpression`,r))}}),Ql={module:`Yaml`,members:[`load`,`parse`,`parseAllDocuments`,`parseDocument`]},$l={module:`Toml`,members:[`parse`]},Y={module:`Csv`,members:`all`},eu={"@fast-csv/format":Y,"@fast-csv/parse":Y,"@iarna/toml":$l,"@streamparser/json":{module:`JsonArray`,members:`all`},"@xmldom/xmldom":{module:`Xml`,members:[`DOMParser`]},"comment-json":{module:`Jsonc`,members:[`parse`]},"csv-parse":Y,"csv-parse/sync":Y,"csv-parser":Y,"csv-stringify":Y,"csv-stringify/sync":Y,"fast-csv":Y,"fast-xml-parser":{module:`Xml`,members:[`XMLParser`]},ini:{module:`Ini`,members:[`decode`,`parse`]},"js-yaml":Ql,json5:{module:`Json5`,members:[`parse`]},"jsonc-parser":{module:`Jsonc`,members:[`parse`]},ndjson:{module:`Ndjson`,members:`all`},papaparse:Y,sax:{module:`Xml`,members:`all`},"smol-toml":$l,"stream-json":{module:`JsonArray`,members:`all`},"strip-json-comments":{module:`Jsonc`,members:`all`},toml:$l,xml2js:{module:`Xml`,members:[`Parser`,`parseString`,`parseStringPromise`]},yaml:Ql};function tu(e,t){return e.members===`all`||c.contains(e.members,t)}const nu=r.define({name:`prefer-effect-format-parser`,meta:H({type:`suggestion`,description:`Prefer the effect/encoding modules over third-party YAML, TOML, INI, JSON5, JSONC, CSV, NDJSON, JSON array and XML parsers in Effect files.`,messages:{effectFormat:`Use {{module}} from effect/encoding instead of {{api}}.`},url:`https://www.effect.website/docs/v4/api/effect/encoding`}),*create(){let e=yield*i;if(!(yield*V).hasEffectImport)return{};function n(n,r,i){return e.report(t.fromId({node:n,messageId:`effectFormat`,data:{module:r.module,api:i}}))}function r(t,r,i){let a=c.flatMap(e.sourceCode.getDeclaredVariables(t),({references:e})=>c.getSomes(c.map(e,({identifier:e})=>j(e).pipe(f.filter(t=>t.type===`MemberExpression`&&t.object===e),f.flatMap(e=>C(e).pipe(f.filter(e=>tu(r,e)),f.map(t=>[e,`${i} ${t}`])))))));return d.forEach(a,([e,t])=>n(e,r,t),{discard:!0})}function a(e,t,i){let a=e.source.value;if(t.type===`ImportSpecifier`){let r=fe(t.imported);return!_r(e,t)&&tu(i,r)?n(t,i,`${a} ${r}`):d.void}return i.members===`all`?n(t,i,a):r(t,i,a)}return s.on(`ImportDeclaration`,e=>f.match(l.get(eu,e.source.value),{onNone:()=>d.void,onSome:t=>_r(e)?d.void:d.forEach(e.specifiers,n=>a(e,n,t),{discard:!0})}))}}),ru=r.define({name:`prefer-effect-headers`,meta:H({type:`suggestion`,description:`Prefer immutable Effect Headers values in Effect projects.`,messages:{effectHeaders:`Use Headers.fromInput to construct normalized, immutable Effect headers.`},url:`https://www.effect.website/docs/v4/api/effect/unstable/http/Headers`}),*create(){let e=yield*i;return(yield*V).hasEffectImport?s.on(`NewExpression`,n=>d.when(e.report(t.fromId({node:n,messageId:`effectHeaders`})),B(n.callee,`Headers`))):{}}});function iu(e){return f.exists(f.all(e),e=>c.every(e,ie.isHttpMethod)&&new Set(e).size>=6)}const au=r.define({name:`prefer-effect-http-method`,meta:H({type:`suggestion`,description:`Prefer the Effect HttpMethod type and guards over hand-written lists of HTTP methods.`,messages:{methodList:`Use HttpMethod.HttpMethod, HttpMethod.all or HttpMethod.isHttpMethod instead of listing HTTP methods by hand. HttpMethod also includes TRACE and QUERY.`},url:`https://www.effect.website/docs/v4/api/effect/http/HttpMethod`}),*create(){let e=yield*i;return(yield*V).hasEffectImport?s.merge(s.on(`ArrayExpression`,n=>iu(c.map(n.elements,e=>b.isNotNull(e)&&N(e)?f.some(e.value):f.none()))?e.report(t.fromId({node:n,messageId:`methodList`})):d.void),s.on(`TSUnionType`,n=>iu(c.map(n.types,e=>e.type===`TSLiteralType`&&N(e.literal)?f.some(e.literal.value):f.none()))?e.report(t.fromId({node:n,messageId:`methodList`})):d.void)):{}}}),ou=new Map(c.map(l.keys({Continue:!0,SwitchingProtocols:!0,Processing:!0,EarlyHints:!0,OK:!0,Created:!0,Accepted:!0,NonAuthoritativeInformation:!0,NoContent:!0,ResetContent:!0,PartialContent:!0,MultiStatus:!0,AlreadyReported:!0,ImUsed:!0,MultipleChoices:!0,MovedPermanently:!0,Found:!0,SeeOther:!0,NotModified:!0,TemporaryRedirect:!0,PermanentRedirect:!0,BadRequest:!0,Unauthorized:!0,PaymentRequired:!0,Forbidden:!0,NotFound:!0,MethodNotAllowed:!0,NotAcceptable:!0,ProxyAuthenticationRequired:!0,RequestTimeout:!0,Conflict:!0,Gone:!0,LengthRequired:!0,PreconditionFailed:!0,PayloadTooLarge:!0,UriTooLong:!0,UnsupportedMediaType:!0,RangeNotSatisfiable:!0,ExpectationFailed:!0,ImATeapot:!0,MisdirectedRequest:!0,UnprocessableEntity:!0,Locked:!0,FailedDependency:!0,TooEarly:!0,UpgradeRequired:!0,PreconditionRequired:!0,TooManyRequests:!0,RequestHeaderFieldsTooLarge:!0,UnavailableForLegalReasons:!0,InternalServerError:!0,NotImplemented:!0,BadGateway:!0,ServiceUnavailable:!0,GatewayTimeout:!0,HttpVersionNotSupported:!0,VariantAlsoNegotiates:!0,InsufficientStorage:!0,LoopDetected:!0,NotExtended:!0,NetworkAuthenticationRequired:!0}),e=>v.make(ae.fromLiteral(e),e)));function su(e,t){return t.isApi(e.callee,`HttpApiSchema`,`status`)?D(e,0).pipe(f.toArray,c.map(e=>v.make(e,`statusName`))):t.isApi(e.callee,`HttpApiSchema`,`Empty`)?D(e,0).pipe(f.toArray,c.map(e=>v.make(e,`httpStatus`))):t.isApi(e.callee,`HttpServerResponse`,`setStatus`)?c.map(c.getSomes([D(e,0),D(e,1)]),e=>v.make(e,`httpStatus`)):f.flatMap(t.member(e.callee,`HttpServerResponse`),t=>D(e,t===`empty`?0:1).pipe(f.filter(e=>e.type===`ObjectExpression`),f.flatMap(E(`status`)))).pipe(f.toArray,c.map(({value:e})=>v.make(e,`httpStatus`)))}const cu=r.define({name:`prefer-effect-http-status`,meta:H({type:`suggestion`,description:`Prefer named HttpStatus literals over status code numbers passed to Effect HTTP APIs.`,messages:{statusName:`Pass the status name: HttpApiSchema.status('{{literal}}') instead of {{code}}.`,httpStatus:`Name the status: use HttpStatus.fromLiteral('{{literal}}') instead of {{code}}.`},url:`https://www.effect.website/docs/v4/api/effect/http/HttpStatus`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};function r(n,r){let i=O(n),a=i.type===`Literal`&&b.isNumber(i.value)?f.fromNullishOr(ou.get(i.value)):f.none();return f.match(a,{onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:i,messageId:r,data:{code:e.sourceCode.getText(i),literal:n}}))})}return s.merge(s.on(`ObjectExpression`,e=>d.forEach(c.filter(c.getSomes(c.map(e.properties,pe)),e=>f.contains(T(e),`httpApiStatus`)),e=>r(e.value,`httpStatus`),{discard:!0})),s.on(`CallExpression`,e=>d.forEach(su(e,n),([e,t])=>r(e,t),{discard:!0})))}}),lu=m.Literals([`@tsndr/cloudflare-worker-jwt`,`fast-jwt`,`hono/jwt`,`jose`,`jsonwebtoken`,`jwt-decode`,`jwt-simple`]),uu=m.is(lu),du=m.Literals([`header`,`payload`,`signature`]),fu=m.is(du);function pu(e){return P(e,`.`)}function mu(e){return f.exists(M(e,`VariableDeclarator`),({id:e})=>e.type===`ArrayPattern`&&c.some(e.elements,e=>e?.type===`Identifier`&&fu(e.name)))}const hu=r.define({name:`prefer-effect-jwt`,meta:H({type:`suggestion`,description:`Prefer Effect Jwt over JWT libraries and tokens split and decoded by hand in Effect projects.`,messages:{jwtLibrary:`Use Jwt from effect/jose instead of {{source}}: it decodes the claims with a Schema and fails with a typed JwtError.`,manualJwt:`Do not split a JWT on '.' by hand. Use Jwt.verify or Jwt.verifyWithKeySet from effect/jose, which check the signature, exp and nbf before decoding the claims with a Schema, and Jwt.decodeUnverified only to choose a key.`},url:`https://effect.website/docs/v4/api/effect/jose/Jwt`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};function r(e){return n.isApi(e.callee,`String`,`split`)?f.exists(D(e,1),pu)?D(e,0):f.none():e.callee.type===`MemberExpression`&&f.contains(C(e.callee),`split`)&&f.exists(D(e,0),pu)?f.some(e.callee.object):f.none()}return s.merge(s.on(`ImportDeclaration`,({source:n})=>uu(n.value)?e.report(t.fromId({node:n,messageId:`jwtLibrary`,data:{source:n.value}})):d.void),s.on(`CallExpression`,n=>f.exists(r(n),e=>f.exists(w(e),e=>/jwt|token/iu.test(c.lastNonEmpty(e)))||mu(n))?e.report(t.fromId({node:n,messageId:`manualJwt`})):d.void))}});function gu(e){return e.type===`Literal`||e.type===`TemplateLiteral`&&c.isReadonlyArrayEmpty(e.expressions)}function _u(e,t){return e.type!==`BinaryExpression`||!le(e.operator)?f.none():gu(e.left)?f.some(t.getText(e.right)):gu(e.right)?f.some(t.getText(e.left)):f.none()}function vu(e){return e?.type===`ConditionalExpression`||e?.type===`IfStatement`}function yu(e,t,n){return f.contains(_u(e.test,n),t)?vu(e.alternate)?f.map(yu(e.alternate,t,n),e=>e+1):f.some(1):f.none()}function bu(e,t){return _u(e.test,t).pipe(f.flatMap(n=>yu(e,n,t)),f.exists(e=>e>1))}const xu=r.define({name:`prefer-effect-match`,meta:H({type:`suggestion`,description:`Prefer Effect Match for composable and exhaustive branching in Effect projects.`,messages:{effectMatch:`Use Match.type, Match.value, or Match.tags with Match.exhaustive instead of switch.`,preferMatch:`Use Match from Effect instead of a chained literal ternary.`,ifChain:"Use Match.type, Match.value, or Match.discriminators with Match.exhaustive instead of an `else if` chain comparing the same value against literals."},url:`https://www.effect.website/docs/v4/api/effect/Match`}),*create(){let e=yield*i,n=yield*V,r=s.on(`ConditionalExpression`,n=>n.parent.type!==`ConditionalExpression`&&bu(n,e.sourceCode)?e.report(t.fromId({node:n,messageId:`preferMatch`})):d.void);return n.hasEffectImport?s.merge(r,s.on(`SwitchStatement`,n=>e.report(t.fromId({node:n,messageId:`effectMatch`}))),s.on(`IfStatement`,n=>(n.parent.type!==`IfStatement`||n.parent.alternate!==n)&&bu(n,e.sourceCode)?e.report(t.fromId({node:n,messageId:`ifChain`})):d.void)):r}}),Su=m.Literals([`status`,`statusCode`]),Cu=m.is(Su),wu={"<":`>`,"<=":`>=`,">":`<`,">=":`<=`};function Tu(e){return e.type===`PrivateIdentifier`?e:O(e)}function Eu(e){let t=Tu(e);return t.type===`MemberExpression`&&f.exists(C(t),Cu)}function Du(e){let t=Tu(e);return t.type===`Literal`&&b.isNumber(t.value)?f.some(t.value):f.none()}function Ou(e,t){let n=Tu(e);if(n.type!==`BinaryExpression`||!(n.operator in wu))return f.none();let[r,i,a]=Eu(n.left)?[n.left,n.right,n.operator]:[n.right,n.left,wu[n.operator]??n.operator];return Eu(r)?f.flatMap(Du(i),e=>{let n=t(r);return e===200&&a===`>=`||e===199&&a===`>`?f.some({bound:`lower`,inRange:!0,status:n}):e===200&&a===`<`||e===199&&a===`<=`?f.some({bound:`lower`,inRange:!1,status:n}):e===300&&a===`<`||e===299&&a===`<=`?f.some({bound:`upper`,inRange:!0,status:n}):e===300&&a===`>=`||e===299&&a===`>`?f.some({bound:`upper`,inRange:!1,status:n}):f.none()}):f.none()}const ku=r.define({name:`prefer-effect-match-status`,meta:H({type:`suggestion`,description:`Prefer HttpClientResponse.filterStatusOk or matchStatus over hand-written 2xx status range checks.`,messages:{matchStatus:`Use HttpClientResponse.filterStatusOk, or HttpClientResponse.matchStatus with a '2xx' case, instead of checking the 2xx range by hand. On a native fetch Response, read response.ok.`},url:`https://www.effect.website/docs/v4/api/effect/http/HttpClientResponse`}),*create(){let e=yield*i;if(!(yield*V).hasEffectImport)return{};function n(t){return e.sourceCode.getText(t)}return s.on(`LogicalExpression`,r=>{let i=r.operator===`&&`;return r.operator!==`??`&&f.exists(f.all([Ou(r.left,n),Ou(r.right,n)]),([e,t])=>e.status===t.status&&e.bound!==t.bound&&e.inRange===i&&t.inRange===i)?e.report(t.fromId({node:r,messageId:`matchStatus`})):d.void})}}),Au=r.define({name:`prefer-effect-ndjson`,meta:H({type:`suggestion`,description:`Prefer Effect Ndjson over splitting lines and parsing or stringifying each one as JSON.`,messages:{decode:`Use Ndjson.decodeString or Ndjson.decodeSchemaString from effect/encoding instead of JSON.parse on each line: it handles CRLF, blank lines and lines split across chunks, and fails with an NdjsonError.`,encode:`Use Ndjson.encodeString or Ndjson.encodeSchemaString from effect/encoding instead of joining JSON.stringify results with line breaks.`},url:`https://www.effect.website/docs/v4/api/effect/encoding/Ndjson`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};let r={imports:n,sourceCode:e.sourceCode},a={mapper:t=>Rc(t,`stringify`,e.sourceCode),element:t=>t.type===`CallExpression`&&Rc(t.callee,`stringify`,e.sourceCode)};function o(t){return Rc(t.callee,`parse`,e.sourceCode)&&f.exists(D(t,0),e=>$c(e,r))}function c(e){return f.exists(Lc(e,Mc,n),t=>tl(nl(e,t,n),a,r))}return s.merge(s.on(`CallExpression`,n=>o(n)?e.report(t.fromId({node:n,messageId:`decode`})):c(n)?e.report(t.fromId({node:n,messageId:`encode`})):d.void),s.on(`MemberExpression`,n=>Rc(n,`parse`,e.sourceCode)&&Xc(n,r)?e.report(t.fromId({node:n,messageId:`decode`})):d.void))}}),ju=m.Literals([`ip`,`ip-address`,`ip-range-check`,`ip-regex`,`ipaddr.js`,`is-ip`,`is-localhost-ip`,`netmask`,`private-ip`]),Mu=m.is(ju),Nu=m.Literals([`isIP`,`isIPv4`,`isIPv6`]),Pu=m.is(Nu),Fu=[`net`,`node:net`],Iu=m.Literals([`0.0.0.0`,`127.0.0.1`,`255.255.255.255`,`::`,`::1`]),Lu=m.is(Iu),Ru=/^(?:(?:0|10|127|169\.254|192\.168|172\.(?:1[6-9]|2\d|3[01])|100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7]))\.|fe80:|::ffff:)$/iu,zu=[/(?:(?:\\d|\[0-9\])(?:\+|\{1,3\})\\\.){3}/u,/\((?:\?:)?(?:\\d|\[0-9\])(?:\+|\{1,3\})\\\.\)\{3\}/u,/^(?=[\s\S]*25\[0-5\])(?=[\s\S]*\\\.)/u,/^\^(?:\(\?:)?(?:0|10|100|127|169\\\.254|172|192\\\.168)(?:\|(?:0|10|100|127|169\\\.254|172|192\\\.168))*\)?\\\./u,/^\^\(?(?:\?:)?(?:fe80|fe\[89ab\]|f\[cd\]|fc\|fd|fd\|fc)/iu,/::ffff:/iu];function Bu(e){return f.match(j(e),{onNone:()=>e,onSome:t=>t.type===`Program`?e:Bu(t)})}const Vu=r.define({name:`prefer-effect-net-address`,meta:H({type:`suggestion`,description:`Prefer Effect NetAddress over IP addresses parsed and classified by hand in Effect projects.`,messages:{ipText:`Parse the address with NetAddress.ipFromString and classify it with NetAddress.isLoopback, isPrivate, isLinkLocal, isUniqueLocal, isUnspecified or isIpv4Mapped, or IpNetwork.contains, instead of matching IP text by hand.`,nodeIpCheck:`Use NetAddress.ipFromString, ipv4FromString or ipv6FromString from effect/net instead of net.{{name}}: they return a typed address to classify.`,library:`Use NetAddress and IpNetwork from effect/net instead of {{source}}.`},url:`https://effect.website/docs/v4/api/effect/net/NetAddress`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};let r=yield*p.make(x.empty());function a(n){let[i]=Bu(n).range;return d.gen(function*(){let a=yield*p.get(r);x.has(a,i)||(yield*p.update(r,x.add(i)),yield*e.report(t.fromId({node:n,messageId:`ipText`})))})}function o(e){return(e.callee.type===`MemberExpression`&&f.contains(C(e.callee),`startsWith`)||n.isApi(e.callee,`String`,`startsWith`))&&f.exists(D(e,0),e=>N(e)&&Ru.test(e.value))}return s.merge(s.on(`ImportDeclaration`,({source:n})=>Mu(n.value)?e.report(t.fromId({node:n,messageId:`library`,data:{source:n.value}})):d.void),s.on(`CallExpression`,n=>He(e.sourceCode,n.callee,Fu).pipe(f.filter(Pu),f.match({onNone:()=>o(n)?a(n):d.void,onSome:r=>e.report(t.fromId({node:n,messageId:`nodeIpCheck`,data:{name:r}}))}))),s.on(`Literal`,e=>`regex`in e&&c.some(zu,t=>t.test(e.regex.pattern))?a(e):d.void),s.on(`BinaryExpression`,e=>le(e.operator)&&c.some([e.left,e.right],e=>N(e)&&Lu(e.value))?a(e):d.void))}}),Hu=m.Literals([`node:path`,`path`]),Uu=m.is(Hu),Wu=r.define({name:`prefer-effect-path`,meta:H({type:`suggestion`,description:`Prefer the Effect Path service over direct Node.js path imports in Effect projects.`,messages:{effectPath:`Use the Path service from effect/Path instead of {{source}}.`},url:`https://www.effect.website/docs/v4/api/effect/Path`}),*create(){let e=yield*i;return(yield*V).hasEffectImport?s.on(`ImportDeclaration`,({source:n})=>Uu(n.value)?e.report(t.fromId({node:n,messageId:`effectPath`,data:{source:n.value}})):d.void):{}}}),Gu={Arr:`effect/Array`,P:`effect/Predicate`},Ku={bigint:`isBigInt`,boolean:`isBoolean`,function:`isFunction`,number:`isNumber`,object:`isObjectOrArray`,string:`isString`,symbol:`isSymbol`,undefined:`isUndefined`},qu={"!=":`isNotNullish`,"!==":`isNotNull`,"==":`isNullish`,"===":`isNull`},Ju={"!=":`isNotNullish`,"!==":`isNotUndefined`,"==":`isNullish`,"===":`isUndefined`},Yu={Array:[`Arr`,`isArray`,`similar`],BigInt:[`P`,`isBigInt`,`different`],Boolean:[`P`,`isBoolean`,`different`],Date:[`P`,`isDate`,`exact`],Error:[`P`,`isError`,`exact`],Function:[`P`,`isFunction`,`similar`],Map:[`P`,`isMap`,`similar`],Number:[`P`,`isNumber`,`different`],Promise:[`P`,`isPromise`,`similar`],RegExp:[`P`,`isRegExp`,`exact`],Set:[`P`,`isSet`,`similar`],String:[`P`,`isString`,`different`],Symbol:[`P`,`isSymbol`,`different`],Uint8Array:[`P`,`isUint8Array`,`exact`]},Xu=m.Literals([`!==`,`!=`]),Zu=m.is(Xu);function Qu(e){return e.type===`ArrowFunctionExpression`||e.type===`FunctionDeclaration`||e.type===`FunctionExpression`}function $u(e,t,n,r){return(n.type===`Literal`&&b.isNull(n.value)?f.some(qu):f.liftPredicate(Ju,()=>z(r,n,`undefined`))).pipe(f.flatMap(l.get(e.operator)),f.map(e=>({namespace:`P`,member:e,subject:t,negated:!1,equivalence:`exact`})))}function ed(e,t,n,r){if(t.type!==`UnaryExpression`||t.operator!==`typeof`||!N(n))return f.none();let i=O(t.argument);return i.type===`Identifier`&&z(r,i,i.name)?f.none():f.map(l.get(Ku,n.value),r=>{let i=n.value===`undefined`&&Zu(e.operator);return{namespace:`P`,member:i?`isNotUndefined`:r,subject:t.argument,negated:Zu(e.operator)&&!i,equivalence:n.value===`object`?`similar`:`exact`}})}function td(e,t){if(!le(e.operator))return f.none();let n=O(e.left),r=O(e.right);return ed(e,n,r,t).pipe(f.orElse(()=>ed(e,r,n,t)),f.orElse(()=>$u(e,e.left,r,t)),f.orElse(()=>$u(e,e.right,n,t)))}function nd(e,t){let n=O(e.right);return n.type===`Identifier`&&z(t,n,n.name)?f.map(l.get(Yu,n.name),([t,n,r])=>({namespace:t,member:n,subject:e.left,negated:!1,equivalence:r})):f.none()}function rd(e){return f.exists(Ce(e,Qu),e=>e.returnType?.typeAnnotation.type===`TSTypePredicate`)}const id=r.define({name:`prefer-effect-predicate`,meta:H({type:`suggestion`,description:`Prefer Effect Predicate guards over typeof, instanceof, and nullish comparisons in Effect files.`,messages:{predicate:`Use {{predicate}} from Effect instead of this check. Decode unknown input with Schema.is or a Schema decoder instead of narrowing it by hand.`,objectPredicate:`Use {{predicate}} from Effect instead of this check. Unlike typeof x === 'object', it treats null as not an object.`,boxedInstance:"`instanceof {{constructor}}` only matches boxed objects such as `new {{constructor}}(…)`, never primitive values. To check for the primitive, use {{predicate}}.",replace:`Replace with {{predicate}}.`},url:`https://www.effect.website/docs/v4/api/effect/Predicate`,fixable:`code`,hasSuggestions:!0}),*create(){let e=yield*i;if(!(yield*V).hasEffectImport)return{};let n=d.fnUntraced(function*(n,r){let{namespace:i,member:a,negated:o,equivalence:s}=r,l=o?`!`:``,u=`${l}${i}.${a}`,d=t.fromId(s===`different`?{node:n,messageId:`boxedInstance`,data:{constructor:e.sourceCode.getText(n.right),predicate:u}}:{node:n,messageId:a===`isObjectOrArray`?`objectPredicate`:`predicate`,data:{predicate:u}});if(s===`different`||c.isReadonlyArrayNonEmpty(e.sourceCode.getCommentsInside(n)))return yield*e.report(d);let f=yield*Pt(n,Gu[i],i,t=>`${l}${t}.${a}(${U(e.sourceCode,r.subject)})`);return yield*e.report(s===`exact`?t.withFix(d,f):t.withSuggestions(d,[{messageId:`replace`,data:{predicate:u},fix:f}]))});return s.on(`BinaryExpression`,e=>d.flatMap(o.getScope(e),t=>(e.operator===`instanceof`?nd(e,t):td(e,t)).pipe(f.filter(()=>!rd(e)),f.match({onNone:()=>d.void,onSome:t=>n(e,t)}))))}}),ad=m.Literals([`@microsoft/fetch-event-source`,`better-sse`,`event-source-polyfill`,`eventsource`,`eventsource-client`,`eventsource-parser`,`extended-eventsource`,`fetch-event-stream`,`reconnecting-eventsource`,`sse.js`]),od=m.is(ad),sd=r.define({name:`prefer-effect-sse`,meta:H({type:`suggestion`,description:"Prefer Effect Sse over Server-Sent Events libraries and `EventSource` in Effect projects.",messages:{library:`Use Sse from effect/encoding instead of {{source}}: Sse.decode, Sse.decodeSchema or Sse.makeParser parse event streams, and Sse.encode or HttpApiSchema.StreamSse write them.`,eventSource:`Read the event stream with HttpClient and Sse.decode or Sse.decodeSchema, so events are schema-decoded and the stream is interruptible.`},url:`https://www.effect.website/docs/v4/api/effect/encoding/Sse`}),*create(){let e=yield*i;return(yield*V).hasEffectImport?s.merge(qs(n=>od(Gs(n.value))?e.report(t.fromId({node:n,messageId:`library`,data:{source:n.value}})):d.void),s.on(`NewExpression`,n=>d.when(e.report(t.fromId({node:n,messageId:`eventSource`})),B(n.callee,`EventSource`)))):{}}}),cd=m.Literals([`canParse`,`parse`]),ld=m.is(cd),ud=r.define({name:`prefer-effect-url`,meta:H({type:`suggestion`,description:`Prefer Effect Url helpers for safe URL parsing in Effect projects.`,messages:{effectUrl:`Use Url.fromString or Url.make so invalid URLs are represented as Result failures.`},url:`https://www.effect.website/docs/v4/api/effect/unstable/http/Url`}),*create(){let e=yield*i,n=yield*V;function r(n,r){return d.when(e.report(t.fromId({node:n,messageId:`effectUrl`})),B(r,`URL`))}return n.hasEffectImport?s.merge(s.on(`NewExpression`,e=>r(e,e.callee)),s.on(`CallExpression`,e=>f.exists(w(e.callee),e=>e.length===2&&e[0]===`URL`&&ld(e[1]))&&e.callee.type===`MemberExpression`?r(e,e.callee.object):d.void)):{}}}),dd=/[?&][\w.%[\]-]+=$/u;function fd(e){return dd.test(e)}function pd(e){return c.some(c.take(e.quasis,e.expressions.length),e=>fd(e.value.cooked??e.value.raw))}function md(e){return f.match(c.head(e.arguments),{onNone:()=>!0,onSome:e=>e.type===`ObjectExpression`||e.type===`ArrayExpression`})}const hd=r.define({name:`prefer-effect-url-params`,meta:H({type:`suggestion`,description:`Prefer Effect UrlParams over URLSearchParams and hand-built query strings in Effect projects.`,messages:{urlSearchParams:`Use UrlParams.fromInput for immutable query parameters, and HttpClientRequest.setUrlParams or UrlParams.toString to apply them.`,manualQuery:`Build query strings with UrlParams.fromInput and UrlParams.toString, or HttpClientRequest.setUrlParams, which encode every value.`},url:`https://www.effect.website/docs/v4/api/effect/http/UrlParams`}),*create(){let e=yield*i;return!(yield*V).hasEffectImport||so(e.filename)?{}:s.merge(s.on(`NewExpression`,n=>d.when(e.report(t.fromId({node:n,messageId:`urlSearchParams`})),d.map(B(n.callee,`URLSearchParams`),e=>e&&md(n)))),s.on(`TemplateLiteral`,n=>pd(n)&&n.parent.type!==`TaggedTemplateExpression`?e.report(t.fromId({node:n,messageId:`manualQuery`})):d.void),s.on(`BinaryExpression`,n=>{let r=n.left.type===`BinaryExpression`&&n.left.operator===`+`?n.left.right:n.left;return n.operator===`+`&&N(r)&&fd(r.value)?e.report(t.fromId({node:n,messageId:`manualQuery`})):d.void}))}}),gd=m.Literals([`appdirsjs`,`application-config-path`,`env-paths`,`os-homedir`,`platform-folders`,`user-home`,`xdg-app-paths`,`xdg-basedir`]),_d=m.is(gd),vd=m.Literals([`APPDATA`,`HOME`,`LOCALAPPDATA`,`USERPROFILE`,`XDG_CACHE_HOME`,`XDG_CONFIG_HOME`,`XDG_DATA_HOME`,`XDG_STATE_HOME`]),yd=m.is(vd),bd=[`node:os`,`os`],xd=r.define({name:`prefer-effect-user-directories`,meta:H({type:`suggestion`,description:`Prefer the Effect UserDirectories service over home directories and XDG paths resolved by hand in Effect projects.`,messages:{homedir:`Use the UserDirectories service from effect/persistence instead of os.homedir(): dirs.config, dirs.data, dirs.cache and dirs.state resolve the platform directory, and dirs.home the home directory.`,variable:`Use the UserDirectories service from effect/persistence instead of reading {{name}}: it applies the XDG, macOS and Windows conventions and reads the environment through the ConfigProvider.`,library:`Use the UserDirectories service from effect/persistence instead of {{source}}.`},url:`https://effect.website/docs/v4/api/effect/persistence/UserDirectories`}),*create(){let e=yield*i,n=yield*V;if(!n.hasEffectImport)return{};function r(n,r){return e.report(t.fromId({node:n,messageId:`variable`,data:{name:r}}))}return s.merge(s.on(`ImportDeclaration`,({source:n})=>_d(n.value)?e.report(t.fromId({node:n,messageId:`library`,data:{source:n.value}})):d.void),s.on(`CallExpression`,i=>{if(f.contains(He(e.sourceCode,i.callee,bd),`homedir`))return e.report(t.fromId({node:i,messageId:`homedir`}));let a=n.isApi(i.callee,`Config`,[`String`,`NonEmptyString`,`Redacted`])&&Ae(e.sourceCode,i.callee)?D(i,0).pipe(f.filter(N),f.map(({value:e})=>e),f.filter(yd)):f.none();return f.match(a,{onNone:()=>d.void,onSome:e=>r(i,e)})}),s.on(`MemberExpression`,e=>{let t=e.parent.type===`AssignmentExpression`&&e.parent.left===e||!f.exists(w(e.object),e=>c.join(e,`.`)===`process.env`)?f.none():f.filter(C(e),yd);return f.match(t,{onNone:()=>d.void,onSome:t=>e.object.type===`MemberExpression`?d.when(r(e,t),B(e.object.object,`process`)):d.void})}))}}),Sd={"&&":[`===`,`==`],"||":[`!==`,`!=`],"??":[]};function Cd(e,t){let n=O(e);return n.type===`LogicalExpression`&&n.operator===t?[...Cd(n.left,t),...Cd(n.right,t)]:[n]}function wd(e,t,n){if(e.type!==`BinaryExpression`||!c.contains(t,e.operator)||e.left.type===`PrivateIdentifier`)return f.none();let r=O(e.left),i=O(e.right);if(r.type!==`MemberExpression`||i.type!==`MemberExpression`)return f.none();let a=n.getText(r.object),o=n.getText(i.object);return f.flatMap(C(r),e=>a===o||!f.contains(C(i),e)?f.none():f.some(a<o?`${a} and ${o}`:`${o} and ${a}`))}function Td(e,t){return we(e).pipe(f.flatMap(e=>Kn(e,t)),f.exists(e=>e.length===2&&e[0]===`Equivalence`&&e[1]===`make`))}const Ed=r.define({name:`prefer-equal`,meta:H({type:`suggestion`,description:`Prefer Equal.equals or an Equivalence over field-by-field comparisons in Effect files.`,messages:{preferEqual:`Compare {{pair}} with Equal.equals (Data and Schema classes implement Equal) or an Equivalence such as Equivalence.Struct instead of field by field.`},url:`https://www.effect.website/docs/v4/api/effect/Equal`}),*create(){let e=yield*i,n=yield*V;return n.hasEffectImport?s.on(`LogicalExpression`,r=>{let i=Sd[r.operator],a=r.parent;if(c.isReadonlyArrayEmpty(i)||a.type===`LogicalExpression`&&a.operator===r.operator)return d.void;let o=c.getSomes(c.map(Cd(r,r.operator),t=>wd(t,i,e.sourceCode)));return c.findFirst(o,(e,t)=>c.contains(c.take(o,t),e)).pipe(f.filter(()=>!Td(r,n)),f.match({onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:r,messageId:`preferEqual`,data:{pair:n}}))}))}):{}}});function Dd(e,t){return f.exists(e,e=>{let n=O(e);return n.type===`Identifier`&&n.name===t})}function Od(e,t,n){return e?.type===`CallExpression`&&e.arguments.length===1&&n.isApi(e.callee,`Match`,`value`)&&Dd(D(e,0),t)}function kd(e,t,n){return e.callee.type===`MemberExpression`&&f.contains(C(e.callee),`pipe`)?Od(e.callee.object,t,n):(n.isApiPath(e.callee,[`pipe`])||n.isApiPath(e.callee,[`Function`,`pipe`]))&&f.exists(D(e,0),e=>Od(e,t,n))}function Ad(e,t,n){if(n.isApi(e.callee,`Match`,`valueTags`))return e.arguments.length===2&&Dd(D(e,0),t)?c.get(e.arguments,1):f.none();let r=e.callee;return r.type===`CallExpression`&&n.isApi(r.callee,`Match`,`valueTags`)&&r.arguments.length===1&&e.arguments.length===1&&Dd(D(e,0),t)?c.head(r.arguments):f.none()}function jd(e){return e.type!==`ArrowFunctionExpression`&&b.isNotNull(e.id)||e.parent.type===`VariableDeclarator`&&e.parent.init===e}function Md(e){let[t]=e.params;return e.params.length===1&&t?.type===`Identifier`&&!e.typeParameters&&!e.async&&!e.generator?f.some(t):f.none()}function Nd(e,t,n){return G(e).pipe(f.filter(e=>e.type===`CallExpression`&&!k(e,e=>e.type===`ThisExpression`)),f.flatMap(r=>kd(r,t,n)?f.some(`value`):f.exists(Ad(r,t,n),n=>!jd(e)||ye(n,t))?f.some(`valueTags`):f.none()))}const Pd=r.define({name:`prefer-hoisted-match`,meta:H({type:`suggestion`,description:`Hoist Effect matchers with Match.type or Match.typeTags instead of wrapping Match.value or Match.valueTags in a function.`,messages:{value:"Replace this function with a hoisted `Match.type<…>().pipe(…)` matcher instead of calling `Match.value({{parameter}})` on every call. Case handlers already receive the narrowed value.",valueTags:"Replace this function with a hoisted `Match.typeTags<…>()({…})` or `Match.type<…>().pipe(Match.tagsExhaustive({…}))` matcher instead of calling `Match.valueTags` with `{{parameter}}`. Case handlers already receive the narrowed value."},url:`https://www.effect.website/docs/v4/api/effect/Match`}),*create(){let e=yield*i,n=yield*V;function r(r){return f.match(Md(r),{onNone:()=>d.void,onSome:({name:i})=>f.match(Nd(r,i,n),{onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:r,messageId:n,data:{parameter:i}}))})})}return s.merge(s.on(`ArrowFunctionExpression`,r),s.on(`FunctionDeclaration`,r),s.on(`FunctionExpression`,r))}});function Fd(e){return e.type===`SpreadElement`}function Id(e){if(!Fd(e))return!1;let t=O(e.argument);return t.type!==`ConditionalExpression`&&t.type!==`LogicalExpression`&&t.type!==`ObjectExpression`&&(t.type!==`MemberExpression`||!f.contains(C(t),`fields`))}function Ld(e){return A(e)&&c.some(e.params,e=>e.type!==`AssignmentPattern`&&e.type!==`TSParameterProperty`&&!e.typeAnnotation)}function Rd(e){return b.isNull(e)||e.type===`SpreadElement`?!1:_.value(O(e)).pipe(_.when({type:`Literal`},({value:e})=>b.isString(e)||b.isNumber(e)||b.isBoolean(e)),_.when({type:`TemplateLiteral`},({expressions:e})=>c.isReadonlyArrayEmpty(e)),_.when({type:`UnaryExpression`,operator:`-`},({argument:e})=>Rd(e)),_.when({type:`ArrayExpression`},({elements:e})=>c.some(e,Rd)),_.when({type:`ObjectExpression`},({properties:e})=>c.some(e,e=>e.type===`Property`&&Rd(e.value))),_.orElse(g.constFalse))}function zd(e){return Ld(e)||e.type===`CallExpression`&&c.some(e.arguments,Ld)}const Bd=_.type().pipe(_.when({type:`Property`,kind:`init`,method:!1},e=>{let t=O(e.value);return!zd(t)&&!Rd(t)}),_.orElse(g.constFalse));function Vd(e){let[t,...n]=e.properties;return b.isUndefined(t)||!Id(t)||c.isReadonlyArrayEmpty(n)?f.none():c.every(n,Id)?f.some(`merge`):c.every(n,Bd)?f.some(`copy`):f.none()}function Hd(e,t){let[n,...r]=e.properties;if(!n||!Fd(n)||!c.isReadonlyArrayNonEmpty(r))return f.none();let i=U(t,n.argument),a=c.headNonEmpty(r);if(!c.every(r,Fd)){let e=h.slice(v.get(a.range,0),v.get(c.lastNonEmpty(r).range,1))(t.text);return f.some(`${i}, { ${e} }`)}return r.length===1&&Fd(a)?f.some(`${i}, ${U(t,a.argument)}`):f.none()}const Ud=r.define({name:`prefer-struct-assign`,meta:H({type:`suggestion`,description:`Prefer Struct.assign over object spread merges and copies in Effect files.`,messages:{merge:`Use Struct.assign(a, b) instead of merging objects with spreads.`,copy:`Use Struct.assign(value, { … }) instead of copying an object with spread overrides. Spreading a class instance drops its prototype; rebuild Schema and Data class instances with their constructor.`,assign:`Replace with Struct.assign.`},url:`https://www.effect.website/docs/v4/api/effect/Struct#assign`,hasSuggestions:!0}),*create(){let e=yield*i;if(!(yield*V).hasEffectImport)return{};let n=d.fnUntraced(function*(n,r){let i=t.fromId({node:n,messageId:r}),a=f.filter(Hd(n,e.sourceCode),()=>c.isReadonlyArrayEmpty(e.sourceCode.getCommentsInside(n)));if(f.isNone(a))return yield*e.report(i);let o=yield*Pt(n,`effect/Struct`,`Struct`,e=>`${e}.assign(${a.value})`);return yield*e.report(t.withSuggestions(i,[{messageId:`assign`,fix:o}]))});return s.on(`ObjectExpression`,e=>f.match(Vd(e),{onNone:()=>d.void,onSome:t=>n(e,t)}))}}),Wd={interruptibleMask:`interruptible`,uninterruptibleMask:`uninterruptible`},Gd=r.define({name:`prefer-uninterruptible`,meta:H({type:`suggestion`,description:`Prefer the non-mask interruptibility API when the restore callback is unused.`,messages:{unusedRestore:`The mask callback never uses restore, so the mask is equivalent to {{replacement}} and misleadingly suggests a restored region.`},url:`https://github.com/Effect-TS/tsgo/issues/659`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>{let i=f.flatMap(n.member(r.callee,`Effect`),e=>l.get(Wd,e));return f.isSome(i)&&f.exists(D(r,0),e=>A(e)&&!Se(e))?e.report(t.fromId({node:r,messageId:`unusedRestore`,data:{replacement:`Effect.${i.value}`}})):d.void})}}),Kd=r.define({name:`prefer-with-span`,meta:H({type:`suggestion`,description:`Prefer Effect.withSpan when the callback does not use the span handle.`,messages:{unusedSpan:`The useSpan callback ignores its span. Use Effect.withSpan so nested spans are parented beneath this span.`},url:`https://github.com/Effect-TS/tsgo/issues/663`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Effect`,`useSpan`)&&f.exists(D(r,r.arguments.length-1),e=>A(e)&&!Se(e))?e.report(t.fromId({node:r,messageId:`unusedSpan`})):d.void)}}),qd=m.String.check(m.isPattern(/^0\s*(?:nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/i)),Jd=m.is(qd);function Yd(e,t){let n=O(e);return P(n,0)||t.isApi(n,`Duration`,`zero`)?!0:N(n)?Jd(n.value):n.type===`CallExpression`&&f.exists(t.path(n.callee),e=>f.contains(c.head(e),`Duration`))&&f.exists(D(n,0),P(0))}const Xd=r.define({name:`prefer-yield-now`,meta:H({type:`suggestion`,description:`Prefer scheduler yielding to a zero-duration Clock sleep.`,messages:{zeroSleep:`Effect.sleep(0) uses Clock and interacts with TestClock. Use Effect.yieldNow for a cooperative scheduler yield.`},url:`https://github.com/Effect-TS/tsgo/issues/661`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Effect`,`sleep`)&&f.exists(D(r,0),e=>Yd(e,n))?e.report(t.fromId({node:r,messageId:`zeroSleep`})):d.void)}}),Zd=m.Literals([`catch`,`mapError`,`catchAll`]),Qd=m.is(Zd);function $d(e,t){return f.exists(Kn(e,t),([e,t])=>e===`Effect`&&Qd(t))||f.exists(Gn(e,`catch`),e=>t.isApi(e.callee,`Effect`,[`try`,`tryPromise`]))}const ef=r.define({name:`preserve-caught-error`,meta:H({type:`suggestion`,description:`Preserve the underlying cause when wrapping an Effect failure.`,messages:{droppedCause:`This handler constructs a new error but drops the caught failure. Accept it as a parameter and attach it as cause.`},url:`https://github.com/Effect-TS/tsgo/issues/490`}),*create(){let e=yield*i,n=yield*V;function r(r){let i=xe(r);return b.isNotNullish(r.body)&&$d(r,n)&&k(r.body,e=>e.type===`NewExpression`&&Oe(e)&&!f.exists(i,({name:t})=>ye(e,t)))?e.report(t.fromId({node:r,messageId:`droppedCause`})):d.void}return s.merge(s.on(`ArrowFunctionExpression`,r),s.on(`FunctionExpression`,r))}}),tf=r.define({name:`require-schema-class-brand`,meta:H({type:`problem`,description:`Require Schema.Class declarations to carry a nominal brand.`,messages:{missingBrand:`Schema.Class without a second type parameter is structural. Add a unique brand so plain objects cannot masquerade as instances.`},url:`https://github.com/Effect-TS/tsgo/issues/468`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Schema`,`Class`)&&(r.typeArguments?.params.length??0)<2?e.report(t.fromId({node:r,messageId:`missingBrand`})):d.void)}}),nf=r.define({name:`require-try-promise-abort-signal`,meta:H({type:`suggestion`,description:`Require Effect.tryPromise thunks to accept and use their AbortSignal for interruption.`,messages:{missingSignal:"Accept the AbortSignal parameter and pass it to the Promise API. Name it `_signal` only when cancellation is unsupported.",unusedSignal:"Pass this AbortSignal to the Promise API, or rename it to `_signal` to explicitly acknowledge that cancellation is unsupported."},url:`https://www.effect.website/docs/v4/api/effect/Effect#tryPromise`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>n.isApi(r.callee,`Effect`,`tryPromise`)?f.match($n(D(r,0)),{onNone:()=>d.void,onSome:n=>f.match(xe(n),{onNone:()=>e.report(t.fromId({node:n,messageId:`missingSignal`})),onSome:r=>h.startsWith(`_`)(r.name)||Se(n)?d.void:e.report(t.fromId({node:r,messageId:`unusedSignal`}))})}):d.void)}}),rf=[`fn`,`fnUntraced`,`gen`],af=[`fn`,`fnUntraced`],of=[`try`,`tryPromise`];function sf(e,t){return _.value(e.parent).pipe(_.when({type:`CallExpression`},n=>I(D(n,0),e)&&t.isApi(n.callee,`Effect`,of)),_.when({type:`Property`,computed:!1,key:{type:`Identifier`,name:`try`},parent:{type:`ObjectExpression`,parent:{type:`CallExpression`}}},e=>t.isApi(e.parent.parent.callee,`Effect`,of)),_.orElse(()=>!1))}function cf(e,t){return f.exists(Te(e),({callee:e})=>t.isApi(e,`Effect`,rf)||e.type===`CallExpression`&&t.isApi(e.callee,`Effect`,af))}const lf=r.define({name:`throw-in-effect-gen`,meta:H({type:`problem`,description:`Disallow throw in Effect generator APIs because it creates an untyped defect.`,messages:{throwInGen:`Use yield* Effect.fail(...) instead of throw so the failure stays in the typed error channel.`}}),*create(){let e=yield*i,n=yield*V;return s.on(`ThrowStatement`,r=>f.exists(we(r),e=>!sf(e,n)&&cf(e,n))?e.report(t.fromId({node:r,messageId:`throwInGen`})):d.void)}}),uf=m.is(m.Literals([`BigDecimal`,`Config`,`Data`,`DateTime`,`Duration`,`Effect`,`Equivalence`,`Exit`,`Function`,`Layer`,`Match`,`Option`,`Order`,`Predicate`,`Result`,`Schedule`,`Schema`,`Stream`,`String`,`Struct`,`flow`,`pipe`])),df=m.is(m.Literals([`BigDecimal`,`Data`,`DateTime`,`Duration`,`Exit`,`Option`,`Result`,`String`,`Struct`,`pipe`])),ff=m.is(m.Literals([`pipe`,`value`,`valueTags`])),pf=/^run|unsafe/iu;function mf(e,t){return R(L(t.sourceCode,e,e.name))}function hf(e,t){let n=e.callee,r=f.getOrElse(t.imports.path(n),()=>[]),i=f.exists(c.head(r),uf)&&!c.some(r,e=>pf.test(e)),a=n.type===`MemberExpression`&&!n.computed&&f.contains(C(n),`pipe`)&&n.object.type===`CallExpression`&&hf(n.object,t)||n.type===`CallExpression`&&hf(n,t),o=f.exists(c.head(r),df)||f.exists(c.get(r,1),ff);return!e.optional&&(i||a)&&c.every(e.arguments,e=>e.type!==`SpreadElement`&&X(e,t)&&(!o||!gf(e,t)))}function gf(e,t){return e.type===`Identifier`?f.exists(mf(e,t),e=>e.type===`FunctionName`||e.type===`ImportBinding`||e.type===`Variable`&&e.node.type===`VariableDeclarator`&&b.isNotNull(e.node.init)&&A(e.node.init)):A(e)}function X(e,t){return _.value(e).pipe(_.discriminators(`type`)({Literal:e=>!(`regex`in e),ArrowFunctionExpression:g.constTrue,FunctionExpression:g.constTrue,Identifier:e=>!f.exists(mf(e,t),e=>e.type===`Variable`&&e.parent?.type===`VariableDeclaration`&&!be(e.parent)),TemplateLiteral:({expressions:e})=>c.every(e,e=>X(e,t)),ParenthesizedExpression:({expression:e})=>X(e,t),TSAsExpression:({expression:e})=>X(e,t),TSSatisfiesExpression:({expression:e})=>X(e,t),TSNonNullExpression:({expression:e})=>X(e,t),MemberExpression:e=>f.isSome(t.imports.path(e))||e.object.type===`CallExpression`&&hf(e.object,t)&&(!e.computed||X(e.property,t)),UnaryExpression:({argument:e,operator:n})=>n!==`delete`&&X(e,t),BinaryExpression:({left:e,right:n})=>X(e,t)&&X(n,t),LogicalExpression:({left:e,right:n})=>X(e,t)&&X(n,t),ConditionalExpression:({alternate:e,consequent:n,test:r})=>X(r,t)&&X(n,t)&&X(e,t),ArrayExpression:({elements:e})=>c.every(e,e=>b.isNull(e)||X(e,t)),ObjectExpression:({properties:e})=>c.every(e,e=>e.type===`SpreadElement`?X(e.argument,t):(!e.computed||X(e.key,t))&&X(e.value,t)),CallExpression:e=>hf(e,t)}),_.orElse(g.constFalse))}function _f(e,t){return e.type===`ObjectExpression`||e.type===`ArrayExpression`||A(e)||e.type===`Identifier`&&f.exists(mf(e,t),({type:e})=>e===`FunctionName`)}function vf(e,t){return c.isReadonlyArrayEmpty(e.params)&&!e.async&&!e.generator&&!e.typeParameters&&f.exists(G(e),e=>!_f(e,t)&&X(e,t))}function yf(e,t,n){return f.exists(c.findFirst(e.getDeclaredVariables(t),e=>e.name===n),({references:e})=>c.some(e,({identifier:e,init:t})=>{let n=e.parent;return!t&&(n.type!==`CallExpression`||n.callee!==e)}))}function bf(e){return(e.parent?.type===`ExportNamedDeclaration`?e.parent:e).parent?.type===`Program`}const xf=r.define({name:`no-constant-thunk`,meta:H({type:`suggestion`,description:`Disallow top-level functions without parameters that always return the same value.`,messages:{constantThunk:"`{{name}}` takes no parameters and always returns the same value. Make it a constant, or a static on its class."}}),*create(){let e=yield*i,n={sourceCode:e.sourceCode,imports:yield*V};function r(r,i,a){return vf(i,n)&&!yf(e.sourceCode,r,a.name)?e.report(t.fromId({node:a,messageId:`constantThunk`,data:{name:a.name}})):d.void}return s.merge(s.on(`FunctionDeclaration`,e=>e.id&&e.body&&bf(e)?r(e,e,e.id):d.void),s.on(`VariableDeclarator`,e=>e.id.type===`Identifier`&&e.init&&A(e.init)&&bf(e.parent)?r(e,e.init,e.id):d.void))}}),Sf=m.is(m.Literals([`Array`,`Chunk`,`HashMap`,`HashSet`,`Iterable`,`MutableHashMap`,`MutableHashSet`,`MutableList`,`Record`,`Trie`,`Tuple`,`TxChunk`,`TxHashMap`])),Cf=m.is(m.Literals(/* @__PURE__ */ `Channel.acquireRelease,Channel.acquireUseRelease,Channel.catchCauseFilter,Channel.catchReason,Channel.combine,Channel.filterArrayEffect,Channel.fromTransform,Channel.fromTransformBracket,Channel.map,Channel.mapAccum,Channel.mapEffect,Channel.runFold,Channel.runFoldEffect,Channel.scan,Channel.scanEffect,Channel.transformPull,Combiner.make,Duration.matchPair,Effect.acquireRelease,Effect.acquireUseRelease,Effect.catchCauseFilter,Effect.catchReason,Effect.effectify,Effect.filter,Effect.findFirst,Effect.findFirstFilter,Effect.forEach,Effect.onErrorFilter,Effect.onExitFilter,Effect.partition,Effect.reduce,Effect.repeatOrElse,Effect.retryOrElse,Effect.tapCauseFilter,Effect.validate,Effect.zipWith,Equivalence.make,Filter.zipWith,Graph.complement,Graph.findEdge,Graph.findEdges,Graph.floydWarshall,Layer.fromBuild,Layer.fromBuildMemo,Metric.mapInput,Optic.fromChecks,Optic.makeLens,Optic.makeOptional,Option.containsWith,Option.lift2,Option.reduceCompact,Option.zipWith,Order.make,Reducer.make,RequestResolver.around,RequestResolver.make,RequestResolver.makeGrouped,RequestResolver.makeWith,Schema.makeFilter,Schema.makeIsMultipleOf,Schema.middlewareDecoding,Schema.middlewareEncoding,SchemaGetter.checkEffect,SchemaGetter.fail,SchemaGetter.transformEffect,SchemaGetter.transformOptionalEffect,SchemaTransformation.transformEffect,Sink.fold,Sink.foldArray,Sink.foldUntil,Sink.fromTransform,Sink.reduce,Sink.reduceArray,Sink.reduceEffect,Sink.reduceWhile,Sink.reduceWhileArray,Sink.reduceWhileArrayEffect,Sink.reduceWhileEffect,Sink.summarized,Stream.catchCauseFilter,Stream.catchReason,Stream.changesWith,Stream.changesWithEffect,Stream.combine,Stream.combineArray,Stream.crossWith,Stream.dropUntil,Stream.dropUntilEffect,Stream.dropWhile,Stream.dropWhileEffect,Stream.filterEffect,Stream.map,Stream.mapAccum,Stream.mapAccumArray,Stream.mapAccumArrayEffect,Stream.mapAccumEffect,Stream.mapArray,Stream.mapArrayEffect,Stream.mapEffect,Stream.runFold,Stream.runFoldEffect,Stream.scan,Stream.scanEffect,Stream.takeUntil,Stream.takeUntilEffect,Stream.takeWhile,Stream.takeWhileEffect,Stream.transformPull,Stream.transformPullBracket,Stream.zipLatestWith,Stream.zipWith,Stream.zipWithArray,TextDiff.diffWith,TxHashSet.reduce`.split(`,`))),wf=m.is(m.Literals([`Match`]));function Tf(e,t){return t.type===`Identifier`&&f.exists(L(e,t,t.name),({defs:e})=>{let[t]=e;if(!t||e.length!==1)return!1;if(t.type===`FunctionName`)return t.node.type===`FunctionDeclaration`;let n=t.node;return t.type===`Variable`&&n.type===`VariableDeclarator`&&n.id.type===`Identifier`&&!n.id.typeAnnotation&&b.isNotNull(n.init)&&A(n.init)})}function Ef(e){return!!e.returnType||c.some(e.params,e=>e.type===`Identifier`&&!!e.typeAnnotation)}const Df=r.define({name:`no-forwarding-lambda`,meta:H({type:`suggestion`,description:`Disallow Effect callbacks that only forward their parameters to another function.`,messages:{forwardingLambda:`This callback only passes its parameters to {{callee}}. Pass {{callee}} directly.`,passCallee:`Pass {{callee}} directly.`},fixable:`code`,hasSuggestions:!0}),*create(){let e=yield*i,n=yield*V,{sourceCode:r}=e,a=d.fnUntraced(function*(n,i){let a=r.getText(i.callee),o=h.includes(`
5
+ `)(a)?`the callee`:`\`${a}\``,s=t.fromId({node:n,messageId:`forwardingLambda`,data:{callee:o}});if(c.isReadonlyArrayNonEmpty(r.getCommentsInside(n))||!Ko(r,i.callee,n))return yield*e.report(s);let l=t.replaceText(n,U(r,i.callee));return yield*e.report(Tf(r,i.callee)&&!Ef(n)?t.withFix(s,l):t.withSuggestions(s,[{messageId:`passCallee`,data:{callee:o},fix:l}]))});function o(e){return Te(e).pipe(f.flatMap(e=>n.path(e.callee)),f.filter(e=>e.length===2&&!f.exists(c.head(e),e=>Sf(e)||wf(e))&&!Cf(c.join(e,`.`))),f.flatMap(()=>Bo(e)),f.filter(({exact:t,call:r})=>t&&Uo(r.callee,n)&&(!Vo(e)||Ho(r.callee,n))),f.match({onNone:()=>d.void,onSome:({call:t})=>a(e,t)}))}return s.merge(s.on(`ArrowFunctionExpression`,o),s.on(`FunctionExpression`,o))}}),Of=[`Effect`,`fn`],kf=m.is(m.String.check(m.isPattern(/^\p{Lu}|^use\p{Lu}/u))),Af=m.Struct({maxLines:m.Int.pipe(m.optionalKey)});function jf(e,t){let n=O(e);return A(n)||n.type===`CallExpression`&&(t.isApiPath(n.callee,Of)||n.callee.type===`CallExpression`&&t.isApiPath(n.callee.callee,Of))}function Mf(e,t){return e.type===`FunctionDeclaration`&&e.id&&e.body?[{declaration:e,typed:Vo(e)||!!e.typeParameters,name:e.id}]:e.type===`VariableDeclaration`?c.flatMap(e.declarations,e=>{if(e.id.type!==`Identifier`||!e.init||!jf(e.init,t))return[];let n=O(e.init);return[{declaration:e,typed:A(n)&&(Vo(n)||!!n.typeParameters),name:e.id}]}):[]}const Nf=r.define({name:`no-single-use-private-function`,meta:H({type:`suggestion`,description:`Disallow short non-exported top-level functions that are used only once.`,messages:{singleUse:"`{{name}}` is only used once and not exported. Inline it where it is used instead of keeping a one-off helper."},schema:[{type:`object`,properties:{maxLines:{type:`integer`,minimum:1}},additionalProperties:!1}]}),options:Af.pipe(m.UndefinedOr),*create(e){let n=yield*i,r=yield*V;if(h.endsWith(`.d.ts`)(n.filename))return{};let{sourceCode:a}=n,o=e?.maxLines??3;function l(e,t){let{declaration:n,typed:r,name:i}=e,s=a.getText(n);if(r||c.contains(t,i.name)||kf(i.name)||h.split(s,`
6
+ `).length>o||s.length>o*120)return!1;let l=c.findFirst(a.getDeclaredVariables(n),e=>e.name===i.name).pipe(f.match({onSome:e=>c.filter(e.references,e=>!e.init),onNone:c.empty}));return l.length===1&&!c.some(l,e=>Ee(n,e.identifier))}return s.on(`Program`,e=>{let i=c.flatMap(e.body,e=>e.type===`ExportNamedDeclaration`&&!e.source?c.map(e.specifiers,e=>fe(e.local)):e.type===`ExportDefaultDeclaration`&&e.declaration.type===`Identifier`?[e.declaration.name]:[]);return d.forEach(c.filter(c.flatMap(e.body,e=>Mf(e,r)),e=>l(e,i)),({name:e})=>n.report(t.fromId({node:e,messageId:`singleUse`,data:{name:e.name}})),{discard:!0})})}});function Pf(e,t){let n=h.replaceAll(/\s+/gu,` `)(t.getText(e.callee));return n.length>60?`${h.slice(0,59)(n)}…`:n}function Ff(e,t,n){return Vo(e)&&(!Ho(t,n)||c.some(e.params,e=>e.type===`Identifier`&&b.isNotNullish(e.typeAnnotation)&&e.typeAnnotation.typeAnnotation.type!==`TSUnknownKeyword`))}const If=r.define({name:`no-trivial-wrapper`,meta:H({type:`suggestion`,description:`Disallow named functions that only forward their parameters to another call.`,messages:{forwardsParameters:"`{{name}}` only passes its parameters to `{{callee}}`. Call `{{callee}}` directly, or assign it to a constant instead of wrapping it.",forwardsWithArguments:"`{{name}}` only passes its parameters to `{{callee}}` with fixed arguments. Call it inline, or hoist a constant built from those arguments, such as `Match.typeTags` or `Schema.is(Schema)`."}}),*create(){let e=yield*i,n=yield*V;function r(r,i){return Bo(r).pipe(f.filter(({call:e,exact:t})=>!Ff(r,e.callee,n)&&Uo(e.callee,n)&&(t||n.isApi(e.callee,`Match`,`valueTags`)||n.isApi(e.callee,`Function`,`pipe`)&&e.arguments.length===2)),f.match({onNone:()=>d.void,onSome:({call:n,exact:r})=>e.report(t.fromId({node:i,messageId:r?`forwardsParameters`:`forwardsWithArguments`,data:{name:i.name,callee:Pf(n,e.sourceCode)}}))}))}return s.merge(s.on(`FunctionDeclaration`,e=>e.id&&e.body?r(e,e.id):d.void),s.on(`VariableDeclarator`,e=>e.id.type===`Identifier`&&e.init&&A(e.init)?r(e.init,e.id):d.void))}}),Lf=m.is(m.Literals([`replace`,`replaceAll`,`slice`,`split`,`substr`,`substring`])),Rf=[`replace`,`replaceAll`,`slice`,`split`,`substring`,`takeLeft`,`takeRight`],zf=[`split`,`takeLeft`,`takeRight`],Bf=[`flow`,`pipe`];function Vf(e){let t=O(e);return t.type===`ChainExpression`?t.expression:t}function Hf(e,t){return t.isApi(Vf(e),`DateTime`,`formatIso`)}function Uf(e,t){let n=Vf(e);if(n.type!==`CallExpression`)return!1;let r=Vf(n.callee);return r.type===`MemberExpression`&&f.contains(C(r),`toISOString`)&&c.isReadonlyArrayEmpty(n.arguments)||Hf(r,t)}function Wf(e,t){let n=Vf(e);return n.type===`CallExpression`&&t.isApi(n.callee,`String`,Rf)}function Gf(e,t){return t.isApi(e,`Function`,Bf)||t.isApiPath(e,[`pipe`])||t.isApiPath(e,[`flow`])}function Kf(e,t){let n=Vf(e.callee),r=c.filter(e.arguments,e=>e.type!==`SpreadElement`);return r.length===e.arguments.length?n.type===`MemberExpression`&&n.object.type!==`Super`&&f.contains(C(n),`pipe`)?f.some([n.object,...r]):Gf(n,t)?f.some(r):f.none():f.none()}function qf(e,t){let n=Vf(e.callee),r=f.exists(D(e,0),e=>Uf(e,t));return n.type===`MemberExpression`&&f.exists(C(n),Lf)&&Uf(n.object,t)||e.arguments.length===2&&t.isApi(n,`String`,zf)&&r||e.arguments.length===1&&Wf(n,t)&&r}function Jf(e,t){return qf(e,t)?f.some(e):Kf(e,t).pipe(f.flatMap(e=>c.findFirst(c.zip(e,c.drop(e,1)),([e,n])=>Wf(n,t)&&(Uf(e,t)||Hf(e,t)))),f.map(([,e])=>e))}const Yf=r.define({name:`no-utc-iso-slicing`,meta:H({type:`problem`,description:`Disallow slicing or rewriting a UTC ISO string to get a local date or time.`,messages:{utcIsoSlicing:`toISOString() and DateTime.formatIso give UTC, so slicing or rewriting them gives the UTC date and time: in Europe/Amsterdam the previous day between 00:00 and 02:00, and +00:00 instead of +01:00/+02:00. Format in an explicit zone instead: DateTime.setZone with DateTime.formatIsoDate, formatIsoOffset or formatIsoZoned, or Intl.DateTimeFormat with timeZone.`},url:`https://www.effect.website/docs/v4/api/effect/DateTime`}),*create(){let e=yield*i,n=yield*V;return s.on(`CallExpression`,r=>f.match(Jf(r,n),{onNone:()=>d.void,onSome:n=>e.report(t.fromId({node:n,messageId:`utcIsoSlicing`}))}))}}),Xf=String.raw`(?:\r\n|\r(?!\n)|[\n\u2028\u2029])`,Zf=String.raw`[^\S\r\n\u2028\u2029]*`,Qf=RegExp(`^(${Zf}${Xf})(?:${Zf}${Xf})+(${Zf};?)$`,`u`),$f=/^(?:module\s*\.\s*)?exports(?:\s*\.|\s*\[|$)/u,ep=/* @__PURE__ */ new Set([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`]),tp=/* @__PURE__ */ new Set([`any`,`never`,`always`]),np=/* @__PURE__ */ new Set([`any`,`singleline`,`multiline`]),rp=/* @__PURE__ */ new Set([`blankLine`,`prev`,`next`]),ip=/* @__PURE__ */ new Set([`selector`,`lineMode`]);function ap(e){return e.type===`Punctuator`&&e.value===`;`}function op(e,t){return e.loc.end.line===t.loc.start.line}function sp(e){return e.loc.start.line===e.loc.end.line}function cp(e){return ep.has(e.type)}function lp(e){return e.type===`ChainExpression`?e.expression:e}function Z(e,t){let n=new Set(c.ensure(e));return(e,r)=>r.getFirstToken(e)?.value===t&&n.has(e.type)}function up(e){return t=>t.type===e}function Q(e,t){return(n,r)=>e(n,r)&&sp(n)===(t===`singleline`)}function dp(e){if(e.type!==`ExpressionStatement`)return!1;let t=lp(e.expression);if(t.type===`UnaryExpression`&&(t=lp(t.argument)),t.type!==`CallExpression`)return!1;let n=t.callee;for(;n.type===`SequenceExpression`;)n=f.getOrThrowWith(c.last(n.expressions),()=>/* @__PURE__ */ Error(`Padding rule invariant: sequence expression is empty`));return cp(n)}function fp(e){if(e.type!==`VariableDeclaration`)return!1;let t=f.getOrUndefined(c.head(e.declarations))?.init;if(b.isNullish(t))return!1;for(;t.type===`MemberExpression`;)t=t.object;return t.type===`CallExpression`&&t.callee.type===`Identifier`&&t.callee.name===`require`}function pp(e,t){if(e.type===`DoWhileStatement`&&e.body.type===`BlockStatement`||dp(e))return!0;let n=t.getLastToken(e,e=>!ap(e)),r=n?.type===`Punctuator`&&n.value===`}`?t.getNodeByRangeIndex(v.get(n.range,0)):null;return r?.type===`BlockStatement`||r?.type===`SwitchStatement`}function mp(e,t){return e.type===`ExpressionStatement`&&(e.parent.type===`Program`||e.parent.type===`BlockStatement`&&cp(e.parent.parent))&&e.expression.type===`Literal`&&b.isString(e.expression.value)&&(t.getTokenBefore(e.expression)?.value!==`(`||t.getTokenAfter(e.expression)?.value!==`)`)}function hp(e,t){if(!mp(e,t)||!e.parent||!(`body`in e.parent)||!c.isArray(e.parent.body))return!1;let n=e.parent.body;return g.pipe(n,c.takeWhile(t=>t!==e),c.every(e=>mp(e,t)))}function gp(e){if(e.type!==`ExpressionStatement`||e.expression.type!==`AssignmentExpression`)return!1;let t=e.expression.left;if(t.type!==`MemberExpression`)return!1;for(;t.object.type===`MemberExpression`;)t=t.object;return t.object.type===`Identifier`&&(t.object.name===`exports`||t.object.name===`module`&&t.property.type===`Identifier`&&t.property.name===`exports`)}function _p(e,t){let n=f.fromNullOr(t.getLastToken(e)).pipe(f.getOrThrowWith(()=>/* @__PURE__ */ Error(`Padding rule invariant: statement has no token`))),r=t.getTokenBefore(n),i=t.getTokenAfter(n);return r&&i&&v.get(r.range,0)>=v.get(e.range,0)&&ap(n)&&!op(r,n)&&op(n,i)?r:n}function vp(e,t){if(sp(e))return e.loc;let n=e.loc.start.line,r=f.getOrThrowWith(c.get(t.lines,n-1),()=>/* @__PURE__ */ Error(`Padding rule invariant: statement source line is missing`));return{start:e.loc.start,end:{line:n,column:r.length}}}const yp=_.type().pipe(_.when({type:`VariableDeclaration`,kind:_.is(`using`,`await using`)},g.constTrue),_.orElse(g.constFalse)),$={"block-like":pp,expression:(e,t)=>e.type===`ExpressionStatement`&&!hp(e,t),return:Z(`ReturnStatement`,`return`),export:Z([`ExportAllDeclaration`,`ExportDefaultDeclaration`,`ExportNamedDeclaration`],`export`),var:Z(`VariableDeclaration`,`var`),let:Z(`VariableDeclaration`,`let`),const:Z(`VariableDeclaration`,`const`),using:yp,type:Z(`TSTypeAliasDeclaration`,`type`)},bp={"*":()=>!0,exports:gp,require:fp,directive:hp,iife:dp,block:up(`BlockStatement`),empty:up(`EmptyStatement`),function:up(`FunctionDeclaration`),"ts-method":up(`TSMethodSignature`),break:Z(`BreakStatement`,`break`),case:Z(`SwitchCase`,`case`),class:Z(`ClassDeclaration`,`class`),continue:Z(`ContinueStatement`,`continue`),debugger:Z(`DebuggerStatement`,`debugger`),default:Z([`SwitchCase`,`ExportDefaultDeclaration`],`default`),do:Z(`DoWhileStatement`,`do`),for:Z([`ForStatement`,`ForInStatement`,`ForOfStatement`],`for`),if:Z(`IfStatement`,`if`),import:Z(`ImportDeclaration`,`import`),switch:Z(`SwitchStatement`,`switch`),throw:Z(`ThrowStatement`,`throw`),try:Z(`TryStatement`,`try`),while:Z([`WhileStatement`,`DoWhileStatement`],`while`),with:Z(`WithStatement`,`with`),"cjs-export":(e,t)=>e.type===`ExpressionStatement`&&e.expression.type===`AssignmentExpression`&&$f.test(t.getText(e.expression.left)),"cjs-import":(e,t)=>e.type===`VariableDeclaration`&&f.exists(c.head(e.declarations),({init:e})=>b.isNotNullish(e)&&h.startsWith(`require(`)(t.getText(e))),enum:Z(`TSEnumDeclaration`,`enum`),interface:Z(`TSInterfaceDeclaration`,`interface`),"function-overload":up(`TSDeclareFunction`),...$,"singleline-block-like":Q($[`block-like`],`singleline`),"multiline-block-like":Q($[`block-like`],`multiline`),"singleline-expression":Q($.expression,`singleline`),"multiline-expression":Q($.expression,`multiline`),"singleline-return":Q($.return,`singleline`),"multiline-return":Q($.return,`multiline`),"singleline-export":Q($.export,`singleline`),"multiline-export":Q($.export,`multiline`),"singleline-var":Q($.var,`singleline`),"multiline-var":Q($.var,`multiline`),"singleline-let":Q($.let,`singleline`),"multiline-let":Q($.let,`multiline`),"singleline-const":Q($.const,`singleline`),"multiline-const":Q($.const,`multiline`),"singleline-using":Q($.using,`singleline`),"multiline-using":Q($.using,`multiline`),"singleline-type":Q($.type,`singleline`),"multiline-type":Q($.type,`multiline`)};function xp(e){return np.has(e)}function Sp(e){return tp.has(e)}function Cp(e){return b.isString(e)&&l.has(bp,e)}function wp(e){return c.isArray(e)}function Tp(e){if(Cp(e))return e;if(b.isObject(e)&&b.isString(e.selector)&&c.every(l.keys(e),e=>ip.has(e))){if(!(`lineMode`in e))return{selector:e.selector};if(xp(e.lineMode))return{selector:e.selector,lineMode:e.lineMode}}throw Error(`Invalid padding-line-between-statements statement matcher`)}function Ep(e){if(!c.isArray(e))return Tp(e);let t=e;if(!c.isReadonlyArrayNonEmpty(t))throw Error(`Padding statement matcher arrays must not be empty`);return c.map(t,e=>Tp(e))}function Dp(e){return c.map(e,e=>{if(!b.isObject(e)||!(`blankLine`in e)||!(`prev`in e)||!(`next`in e)||c.some(l.keys(e),e=>!rp.has(e))||!Sp(e.blankLine))throw Error(`Invalid padding-line-between-statements configuration`);return{blankLine:e.blankLine,prev:Ep(e.prev),next:Ep(e.next)}})}function Op(e,t,n){let r=[],i=_p(e,n);if(t.loc.start.line-i.loc.end.line>=2)do{let e=f.fromNullOr(n.getTokenAfter(i,{includeComments:!0})).pipe(f.getOrThrowWith(()=>/* @__PURE__ */ Error(`Padding rule invariant: next statement token is missing`)));e.loc.start.line-i.loc.end.line>=2&&r.push([i,e]),i=e}while(v.get(i.range,0)<v.get(t.range,0));return r}function kp(e,t,n){return d.gen(function*(){if(n===`any`)return yield*d.void;let r=yield*i,a=r.sourceCode,o=Op(e,t,a);return n===`never`?c.isArrayNonEmpty(o)?yield*r.report({node:t,messageId:`unexpectedBlankLine`,loc:vp(t,a),fix(e){if(o.length>=2)return null;let t=c.headNonEmpty(o),n=v.get(t[0].range,1),r=v.get(t[1].range,0);return e.replaceTextRange([n,r],g.pipe(a.text,h.slice(n,r),h.replace(Qf,`$1$2`)))}}):yield*d.void:c.isArrayNonEmpty(o)?yield*d.void:yield*r.report({node:t,messageId:`expectedBlankLine`,loc:vp(t,a),fix(n){let r=_p(e,a),i=a.getFirstTokenBetween(r,t,{includeComments:!0,filter(e){return!op(r,e)||(r=e,!1)}})??t;return n.insertTextAfter(r,op(r,i)?`
5
7
 
6
8
  `:`
7
- `)}})})}function*rc(e,t){let n=e.sourceCode,a=r.fromIterable(new Set(s.pipe(t,r.flatMap(e=>[...r.ensure(e.prev),...r.ensure(e.next)]),r.flatMap(e=>i.isString(e)?[]:[e.selector])))),u=yield*g.make(new Map(r.map(a,e=>[e,/* @__PURE__ */ new Set]))),d=yield*g.make(r.empty()),f=yield*g.make(l.none());function p(){return g.update(f,e=>l.some({upper:e,prevNode:l.none()}))}function m(){return g.update(f,l.flatMap(e=>e.upper))}function h(e,t,a){let o=e;for(;o.type===`LabeledStatement`;)o=o.body;return Zs(t)?r.some(t,e=>h(o,e,a)):i.isString(t)?qs[t](o,n):a.get(t.selector)?.has(o)===!0&&(t.lineMode===`singleline`?Ps(o):t.lineMode!==`multiline`||!Ps(o))}function ee(e,n,i){return s.pipe(r.findLast(t,t=>h(e,t.prev,i)&&h(n,t.next,i)),l.match({onNone:()=>`any`,onSome:e=>e.blankLine}))}let te=c.type().pipe(c.when({parent:c.null},s.constant(o.void)),c.not({parent:{type:c.is(`BlockStatement`,`Program`,`StaticBlock`,`SwitchCase`,`SwitchStatement`,`TSInterfaceBody`,`TSModuleBlock`,`TSTypeLiteral`)}},s.constant(o.void)),c.orElse(e=>o.gen(function*(){let t=yield*g.get(f);if(l.isNone(t))return yield*o.die(/* @__PURE__ */ Error(`Padding rule invariant: statement scope is missing`));if(l.isSome(t.value.prevNode)){let n=t.value.prevNode.value;yield*g.update(d,t=>(t.push({prevNode:n,nextNode:e}),t))}yield*g.set(f,l.some({upper:t.value.upper,prevNode:l.some(e)}))})));function _(e){return o.andThen(te(e),p())}let re={Program:p,"Program:exit":o.fn(`'Program:exit'`)(function*(){let e=yield*g.get(u);yield*g.get(d).pipe(o.flatMap(t=>o.all(r.map(t,({prevNode:t,nextNode:n})=>nc(t,n,ee(t,n,e)))))),yield*m()}),BlockStatement:p,"BlockStatement:exit":m,SwitchStatement:p,"SwitchStatement:exit":m,SwitchCase:_,"SwitchCase:exit":m,StaticBlock:p,"StaticBlock:exit":m,TSInterfaceBody:p,"TSInterfaceBody:exit":m,TSModuleBlock:p,"TSModuleBlock:exit":m,TSTypeLiteral:p,"TSTypeLiteral:exit":m,TSDeclareFunction:_,"TSDeclareFunction:exit":m,TSMethodSignature:_,"TSMethodSignature:exit":m,":statement":te};return ne.merge(re,...r.map(a,e=>ne.on(e,t=>g.update(u,n=>(n.get(e)?.add(t),n)))))}const ic=ee.define({name:`padding-line-between-statements`,meta:{type:`layout`,docs:{description:`Require or disallow padding lines between statements`,url:`https://eslint.style/rules/padding-line-between-statements`,recommended:!0},fixable:`whitespace`,schema:{type:`array`,items:{type:`object`,properties:{blankLine:{enum:[`any`,`never`,`always`]},prev:{$ref:`#/$defs/statementOption`},next:{$ref:`#/$defs/statementOption`}},required:[`blankLine`,`prev`,`next`],additionalProperties:!1},$defs:{statementMatcher:{anyOf:[{type:`string`,enum:n.keys(qs)},{type:`object`,properties:{selector:{type:`string`},lineMode:{enum:[`any`,`singleline`,`multiline`]}},required:[`selector`],additionalProperties:!1}]},statementOption:{anyOf:[{$ref:`#/$defs/statementMatcher`},{type:`array`,items:{$ref:`#/$defs/statementMatcher`},minItems:1,uniqueItems:!0}]}}},messages:{unexpectedBlankLine:`Unexpected blank line before this statement.`,expectedBlankLine:`Expected blank line before this statement.`}},*create(){let e=yield*te;return yield*rc(e,ec(e.options))}}),ac=/* @__PURE__ */ new Set([`document`,`localStorage`,`navigator`,`sessionStorage`,`window`]),oc=/\b(?:document|localStorage|navigator|sessionStorage|window)\b/u,sc=/* @__PURE__ */ new Set([`every`,`filter`,`find`,`findIndex`,`findLast`,`findLastIndex`,`flatMap`,`forEach`,`map`,`reduce`,`reduceRight`,`some`,`sort`,`toSorted`]),cc=/* @__PURE__ */ new Map([[`useMemo`,0],[`useReducer`,2],[`useState`,0]]),lc=/* @__PURE__ */ new Set([`forwardRef`,`memo`]),uc=y(x(`problem`,`Disallow reading browser-only APIs while a React component or hook renders.`,{browserApiInRender:"Reading `{{name}}` during render makes the server and client render differ, even behind a `typeof window` check. Read it in `useEffect` or subscribe with `useSyncExternalStore`."},`https://react.dev/reference/react-dom/client/hydrateRoot#handling-different-client-and-server-content`),e=>{function t(){if(!oc.test(e.sourceCode.text))return;let t=dc(e.sourceCode.scopeManager.globalScope);for(let n of t){let t=fc(n.identifier);t!==void 0&&pc(t.node)&&e.report({node:t.node,messageId:`browserApiInRender`,data:{name:t.name}})}}return{"Program:exit":t}});function dc(e){let t=new Set(e?.through);if(e===null)return t;for(let n of e.variables)if(n.defs.length===0)for(let e of n.references)t.add(e);return t}function fc(e){if(e.type!==`Identifier`)return;let t=e.name,n=e;if(t===`globalThis`){let{parent:r}=e,i=r.type===`MemberExpression`?S(r):void 0;if(i===void 0||!ac.has(i))return;t=`globalThis.${i}`,n=r}else if(!ac.has(t))return;let{parent:r}=n;if(!(r?.type===`UnaryExpression`&&r.operator===`typeof`||r?.type===`TSTypeQuery`||r?.type===`TSQualifiedName`))return{name:t,node:n}}function pc(e){for(let t=e.parent;t;t=t.parent)if(mc(t)){if(hc(t))return!0;if(!yc(t))return!1}return!1}function mc(e){return e.type===`ArrowFunctionExpression`||e.type===`FunctionDeclaration`||e.type===`FunctionExpression`}function hc(e){let t=gc(e);return t===void 0?!1:/^use[A-Z0-9]/u.test(t)?!0:/^_?[A-Z]/u.test(t)&&e.body!==null&&I(e.body,e=>e.type===`JSXElement`||e.type===`JSXFragment`)}function gc(e){if(e.type!==`ArrowFunctionExpression`&&e.id)return e.id.name;let t=e;for(;t.parent.type===`CallExpression`&&_c(t.parent.callee);)t=t.parent;let{parent:n}=t;return n.type===`VariableDeclarator`&&n.id.type===`Identifier`?n.id.name:void 0}function _c(e){let t=vc(e);return t!==void 0&&lc.has(t)}function vc(e){return e.type===`Identifier`?e.name:e.type===`MemberExpression`?S(e):void 0}function yc(e){let t=e.parent;if(t.type!==`CallExpression`)return!1;if(t.callee===e)return!0;let n=vc(t.callee);if(n===void 0)return!1;let r=cc.get(n);return r===void 0?t.callee.type===`MemberExpression`&&sc.has(n)&&M(t,0)===e:M(t,r)===e}const bc=y(x(`problem`,"Disallow `export *` in 'use client' modules, which Next.js does not support.",{exportAll:"Next.js does not support `export *` in a 'use client' module. Re-export each name instead."},`https://nextjs.org/docs/app/api-reference/directives/use-client`),e=>({Program(t){if(r.some(t.body,e=>e.type===`ExpressionStatement`&&e.directive===`use client`))for(let n of t.body)n.type===`ExportAllDeclaration`&&n.exportKind!==`type`&&e.report({node:n,messageId:`exportAll`})}})),xc=/^\s*use[\s_-]*(?:client|server|cache)\b/iu,Sc=/^use (?:client|server|cache(?:: [\w-]+)?)$/u,Cc={"alchemy-domain-block-file-name":Me,"alchemy-domain-pure-decide":Le,"alchemy-domain-pure-imports":He,"alchemy-domain-require-view-version":Ue,"alchemy-domain-total-handlers":qe,"alchemy-no-cloudflare-init-finalizer":et,"alchemy-no-deprecated-docker-constraints":rt,"alchemy-no-deprecated-resource":at,"alchemy-no-plaintext-github-secret":st,"alchemy-no-removed-config-api":ct,"alchemy-no-reserved-eventbridge-default-name":lt,"alchemy-no-runtime-config":ut,"alchemy-no-v1-import":ft,"alchemy-no-v1-worker-properties":mt,"avoid-data-tagged-error":ht,"ban-error-string":yt,"consistent-schema-pipe":Zt,"cors-credentials-with-wildcard":dn,"dual-numeric-arity-with-optional-parameter":pn,"effect-promise-vs-trypromise":mn,"no-already-started-promise":gn,"no-async-effect-try":_n,"no-browser-api-in-render":uc,"no-constant-thunk":Uo,"no-discarded-run-promise":vn,"no-discarded-schema-checks":xn,"no-effect-as-on-log":Vn,"no-empty-effect-callback":Hn,"no-empty-schema-struct":Un,"no-export-all-in-client":bc,"no-effect-alchemy-barrel-imports":Nn,"no-forwarding-lambda":ns,"no-function-config-default":Kn,"no-hash-as-identity":Yn,"no-inline-schema-compile":dr,"no-logging-in-catch":hr,"no-manual-effect-error-tag":Cr,"no-manual-tag-comparison":Tr,"no-manual-tagged-construction":Er,"no-millis-arithmetic":ri,"no-multi-shot-effect-callback":oi,"no-non-json-schema-annotation":pi,"no-option-of-service":hi,"no-overwritten-discriminant":gi,"no-service-option-get-or-throw":xi,"no-single-use-private-function":cs,"no-service-constructor-imports":yi,"no-throw-in-effect-callback":Ci,"no-trivial-wrapper":ds,"no-uppercase-http-api-header":Oi,"no-utc-iso-slicing":Ss,"no-zero-retry-times":ki,"padding-line-between-statements":ic,"prefer-data-match":Fi,"prefer-effect-alchemy-namespace-imports":Ii,"prefer-effect-array-ops":Ki,"prefer-effect-array-sort":qi,"prefer-effect-datetime":Yi,"prefer-effect-duration":Xi,"prefer-effect-duration-constants":ca,"prefer-effect-duration-types":ba,"prefer-effect-encoding":Ca,"prefer-effect-filesystem":Ta,"prefer-effect-filter":Oa,"prefer-effect-headers":ka,"prefer-effect-match":Na,"prefer-effect-path":Fa,"prefer-effect-predicate":qa,"prefer-effect-url":Ya,"prefer-hoisted-match":oo,"prefer-equal":eo,"prefer-struct-assign":mo,"prefer-uninterruptible":go,"prefer-with-span":_o,"prefer-yield-now":yo,"preserve-caught-error":So,"require-schema-class-brand":Co,"require-try-promise-abort-signal":To,"throw-in-effect-gen":Ao,"valid-directive":y(x(`problem`,`Disallow misspelled 'use client', 'use server' and 'use cache' directives, which do nothing.`,{invalidDirective:`'{{directive}}' is not a valid directive, so it does nothing. Directives are case- and whitespace-sensitive: write 'use client', 'use server' or 'use cache'.`},`https://react.dev/reference/rsc/directives`),e=>({ExpressionStatement(t){let{directive:n}=t;typeof n==`string`&&!Sc.test(n)&&xc.test(n)&&e.report({node:t,messageId:`invalidDirective`,data:{directive:n}})}}))},wc=/* @__PURE__ */ new Set([`prefer-effect-filesystem`,`prefer-effect-path`]),Tc=n.mapEntries(n.filter(Cc,(e,t)=>!wc.has(t)),(e,t)=>[`2digits/${t}`,`error`]),Ec=t({meta:{name:`@2digits/oxlint-plugin`},rules:Cc});export{Ec as default,Tc as recommendedRules,Cc as rules};
9
+ `)}})})}function*Ap(e,t){let n=e.sourceCode,r=g.pipe(t,c.flatMap(e=>[...c.ensure(e.prev),...c.ensure(e.next)]),c.flatMap(e=>b.isString(e)?[]:[e.selector]),c.dedupe),i=yield*p.make(new Map(c.map(r,e=>[e,/* @__PURE__ */ new Set]))),a=yield*p.make(c.empty()),o=yield*p.make(f.none());function l(){return p.update(o,e=>f.some({upper:e,prevNode:f.none()}))}function u(){return p.update(o,f.flatMap(e=>e.upper))}function m(e,t,r){let i=e;for(;i.type===`LabeledStatement`;)i=i.body;return wp(t)?c.some(t,e=>m(i,e,r)):b.isString(t)?bp[t](i,n):r.get(t.selector)?.has(i)===!0&&(t.lineMode===`singleline`?sp(i):t.lineMode!==`multiline`||!sp(i))}function h(e,n,r){return g.pipe(c.findLast(t,t=>m(e,t.prev,r)&&m(n,t.next,r)),f.match({onNone:()=>`any`,onSome:e=>e.blankLine}))}let v=_.type().pipe(_.when({parent:_.null},g.constant(d.void)),_.not({parent:{type:_.is(`BlockStatement`,`Program`,`StaticBlock`,`SwitchCase`,`SwitchStatement`,`TSInterfaceBody`,`TSModuleBlock`,`TSTypeLiteral`)}},g.constant(d.void)),_.orElse(e=>d.gen(function*(){let t=yield*p.get(o);if(f.isNone(t))return yield*d.die(/* @__PURE__ */ Error(`Padding rule invariant: statement scope is missing`));if(f.isSome(t.value.prevNode)){let n=t.value.prevNode.value;yield*p.update(a,t=>(t.push({prevNode:n,nextNode:e}),t))}yield*p.set(o,f.some({upper:t.value.upper,prevNode:f.some(e)}))})));function y(e){return d.andThen(v(e),l())}let x={Program:l,"Program:exit":d.fn(`'Program:exit'`)(function*(){let e=yield*p.get(i);yield*p.get(a).pipe(d.flatMap(t=>d.all(c.map(t,({prevNode:t,nextNode:n})=>kp(t,n,h(t,n,e)))))),yield*u()}),BlockStatement:l,"BlockStatement:exit":u,SwitchStatement:l,"SwitchStatement:exit":u,SwitchCase:y,"SwitchCase:exit":u,StaticBlock:l,"StaticBlock:exit":u,TSInterfaceBody:l,"TSInterfaceBody:exit":u,TSModuleBlock:l,"TSModuleBlock:exit":u,TSTypeLiteral:l,"TSTypeLiteral:exit":u,TSDeclareFunction:y,"TSDeclareFunction:exit":u,TSMethodSignature:y,"TSMethodSignature:exit":u,":statement":v};return s.merge(x,...c.map(r,e=>s.on(e,t=>p.update(i,n=>(n.get(e)?.add(t),n)))))}const jp=r.define({name:`padding-line-between-statements`,meta:{type:`layout`,docs:{description:`Require or disallow padding lines between statements`,url:`https://eslint.style/rules/padding-line-between-statements`,recommended:!0},fixable:`whitespace`,schema:{type:`array`,items:{type:`object`,properties:{blankLine:{enum:[`any`,`never`,`always`]},prev:{$ref:`#/$defs/statementOption`},next:{$ref:`#/$defs/statementOption`}},required:[`blankLine`,`prev`,`next`],additionalProperties:!1},$defs:{statementMatcher:{anyOf:[{type:`string`,enum:l.keys(bp)},{type:`object`,properties:{selector:{type:`string`},lineMode:{enum:[`any`,`singleline`,`multiline`]}},required:[`selector`],additionalProperties:!1}]},statementOption:{anyOf:[{$ref:`#/$defs/statementMatcher`},{type:`array`,items:{$ref:`#/$defs/statementMatcher`},minItems:1,uniqueItems:!0}]}}},messages:{unexpectedBlankLine:`Unexpected blank line before this statement.`,expectedBlankLine:`Expected blank line before this statement.`}},*create(){let e=yield*i;return yield*Ap(e,Dp(e.options))}}),Mp=m.Literals([`document`,`localStorage`,`navigator`,`sessionStorage`,`window`]),Np=m.is(Mp),Pp=/\b(?:document|localStorage|navigator|sessionStorage|window)\b/u,Fp=m.is(m.Literals([`every`,`filter`,`find`,`findIndex`,`findLast`,`findLastIndex`,`flatMap`,`forEach`,`map`,`reduce`,`reduceRight`,`some`,`sort`,`toSorted`])),Ip={useMemo:0,useReducer:2,useState:0},Lp=m.is(m.Literals([`forwardRef`,`memo`])),Rp=m.String.check(m.isPattern(/^use[A-Z0-9]/u)),zp=m.is(Rp),Bp=m.String.check(m.isPattern(/^_?[A-Z]/u)),Vp=m.is(Bp),Hp=r.define({name:`no-browser-api-in-render`,meta:H({type:`problem`,description:`Disallow reading browser-only APIs while a React component or hook renders.`,messages:{browserApiInRender:"Reading `{{name}}` during render makes the server and client render differ, even behind a `typeof window` check. Read it in `useEffect` or subscribe with `useSyncExternalStore`."},url:`https://react.dev/reference/react-dom/client/hydrateRoot#handling-different-client-and-server-content`}),*create(){let e=yield*i;return Pp.test(e.sourceCode.text)?s.onExit(`Program`,()=>{let n=c.filter(c.getSomes(c.map(Up(e.sourceCode.scopeManager.globalScope),({identifier:e})=>Wp(e))),({node:e})=>Gp(e));return d.forEach(n,({name:n,node:r})=>e.report(t.fromId({node:r,messageId:`browserApiInRender`,data:{name:n}})),{discard:!0})}):{}}});function Up(e){return f.fromNullishOr(e).pipe(f.match({onNone:()=>[],onSome:e=>c.dedupeWith([...a.throughReferences(e),...c.flatMap(c.filter(a.variables(e),({defs:e})=>c.isReadonlyArrayEmpty(e)),a.getReferences)],y.strictEqual())}))}function Wp(e){if(e.type!==`Identifier`)return f.none();let t=e.name===`globalThis`?f.flatMap(M(e,`MemberExpression`),e=>C(e).pipe(f.filter(Np),f.map(t=>({name:`globalThis.${t}`,node:e})))):f.liftPredicate({name:e.name,node:e},({name:e})=>Np(e));return f.filter(t,({node:e})=>!f.exists(j(e),e=>e.type===`UnaryExpression`&&e.operator===`typeof`||e.type===`TSTypeQuery`||e.type===`TSQualifiedName`))}function Gp(e){return f.exists(Ce(e,Kp),e=>qp(e)||Zp(e)&&Gp(e))}function Kp(e){return e.type===`ArrowFunctionExpression`||e.type===`FunctionDeclaration`||e.type===`FunctionExpression`}function qp(e){return f.exists(Yp(e),t=>zp(t)||Vp(t)&&b.isNotNull(e.body)&&k(e.body,e=>e.type===`JSXElement`||e.type===`JSXFragment`))}function Jp(e){return M(e,`CallExpression`).pipe(f.filter(e=>f.exists(Xp(e.callee),Lp)),f.match({onNone:()=>e,onSome:Jp}))}function Yp(e){if(e.type!==`ArrowFunctionExpression`&&e.id)return f.some(e.id.name);let{parent:t}=Jp(e);return t?.type===`VariableDeclarator`&&t.id.type===`Identifier`?f.some(t.id.name):f.none()}function Xp(e){return e.type===`Identifier`?f.some(e.name):e.type===`MemberExpression`?C(e):f.none()}function Zp(e){let t=e.parent;return t.type===`CallExpression`?t.callee===e||f.exists(Xp(t.callee),n=>f.match(l.get(Ip,n),{onSome:n=>I(D(t,n),e),onNone:()=>t.callee.type===`MemberExpression`&&Fp(n)&&I(D(t,0),e)})):!1}const Qp=r.define({name:`no-export-all-in-client`,meta:H({type:`problem`,description:"Disallow `export *` in 'use client' modules, which Next.js does not support.",messages:{exportAll:"Next.js does not support `export *` in a 'use client' module. Re-export each name instead."},url:`https://nextjs.org/docs/app/api-reference/directives/use-client`}),*create(){let e=yield*i;return c.some(e.sourceCode.ast.body,e=>e.type===`ExpressionStatement`&&e.directive===`use client`)?s.on(`ExportAllDeclaration`,n=>n.exportKind!==`type`&&n.parent.type===`Program`?e.report(t.fromId({node:n,messageId:`exportAll`})):d.void):{}}}),$p=m.is(m.String.check(m.isPattern(/^\s*use[\s_-]*(?:client|server|cache)\b/iu))),em=m.is(m.String.check(m.isPattern(/^use (?:client|server|cache(?:: [\w-]+)?)$/u))),tm={"alchemy-domain-block-file-name":rt,"alchemy-domain-pure-decide":lt,"alchemy-domain-pure-imports":ht,"alchemy-domain-require-view-version":_t,"alchemy-domain-total-handlers":xt,"alchemy-no-cloudflare-init-finalizer":kt,"alchemy-no-deprecated-docker-constraints":Lt,"alchemy-no-deprecated-resource":zt,"alchemy-no-plaintext-github-secret":Vt,"alchemy-no-removed-config-api":Ut,"alchemy-no-reserved-eventbridge-default-name":Wt,"alchemy-no-runtime-config":Gt,"alchemy-no-v1-import":qt,"alchemy-no-v1-worker-properties":Yt,"avoid-data-tagged-error":Xt,"ban-error-string":an,"consistent-schema-pipe":Ln,"cors-credentials-with-wildcard":Vn,"dual-numeric-arity-with-optional-parameter":Un,"effect-promise-vs-trypromise":Wn,"no-already-started-promise":er,"no-async-effect-try":tr,"no-browser-api-in-render":Hp,"no-constant-thunk":xf,"no-discarded-run-promise":nr,"no-discarded-schema-checks":sr,"no-effect-as-on-log":Ir,"no-empty-effect-callback":Lr,"no-empty-schema-struct":Rr,"no-encoding-get-or-throw":Gr,"no-export-all-in-client":Qp,"no-effect-alchemy-barrel-imports":Er,"no-forwarding-lambda":Df,"no-function-config-default":Jr,"no-hash-as-identity":Qr,"no-inline-schema-compile":gi,"no-logging-in-catch":Ci,"no-manual-effect-error-tag":Fi,"no-manual-encoding":Zi,"no-manual-sse":ia,"no-manual-tag-comparison":oa,"no-manual-tagged-construction":sa,"no-millis-arithmetic":za,"no-multi-shot-effect-callback":Wa,"no-non-json-schema-annotation":to,"no-option-of-service":ao,"no-overwritten-discriminant":oo,"no-service-option-get-or-throw":ho,"no-single-use-private-function":Nf,"no-service-constructor-imports":uo,"no-throw-in-effect-callback":vo,"no-trivial-wrapper":If,"no-uppercase-http-api-header":Do,"no-utc-iso-slicing":Yf,"no-zero-retry-times":Oo,"padding-line-between-statements":jp,"prefer-data-match":Po,"prefer-direct-effect-combinators":Us,"prefer-effect-alchemy-namespace-imports":Ws,"prefer-effect-archive":Qs,"prefer-effect-array-ops":cc,"prefer-effect-array-sort":lc,"prefer-effect-cookies":Oc,"prefer-effect-csv":rl,"prefer-effect-datetime":ol,"prefer-effect-duration":sl,"prefer-effect-duration-constants":yl,"prefer-effect-duration-types":Il,"prefer-effect-encoding":Kl,"prefer-effect-filesystem":Yl,"prefer-effect-filter":Zl,"prefer-effect-format-parser":nu,"prefer-effect-headers":ru,"prefer-effect-http-method":au,"prefer-effect-http-status":cu,"prefer-effect-jwt":hu,"prefer-effect-match":xu,"prefer-effect-match-status":ku,"prefer-effect-ndjson":Au,"prefer-effect-net-address":Vu,"prefer-effect-path":Wu,"prefer-effect-predicate":id,"prefer-effect-sse":sd,"prefer-effect-url":ud,"prefer-effect-url-params":hd,"prefer-effect-user-directories":xd,"prefer-hoisted-match":Pd,"prefer-equal":Ed,"prefer-struct-assign":Ud,"prefer-uninterruptible":Gd,"prefer-with-span":Kd,"prefer-yield-now":Xd,"preserve-caught-error":ef,"require-schema-class-brand":tf,"require-try-promise-abort-signal":nf,"throw-in-effect-gen":lf,"valid-directive":r.define({name:`valid-directive`,meta:H({type:`problem`,description:`Disallow misspelled 'use client', 'use server' and 'use cache' directives, which do nothing.`,messages:{invalidDirective:`'{{directive}}' is not a valid directive, so it does nothing. Directives are case- and whitespace-sensitive: write 'use client', 'use server' or 'use cache'.`},url:`https://react.dev/reference/rsc/directives`}),*create(){let e=yield*i;return s.on(`ExpressionStatement`,n=>f.liftPredicate(n.directive,h.isString).pipe(f.filter(e=>!em(e)&&$p(e)),f.match({onNone:()=>d.void,onSome:r=>e.report(t.fromId({node:n,messageId:`invalidDirective`,data:{directive:r}}))})))}})},nm=[`prefer-effect-filesystem`,`prefer-effect-path`],rm=[`prefer-effect-http-status`],im=c.filter(l.keys(tm),e=>!c.contains(nm,e)),am=l.fromEntries(c.map(im,e=>[`2digits/${e}`,c.contains(rm,e)?`warn`:`error`])),om=`@2digits/oxlint-plugin`,sm=n.define({name:om,rules:tm,recommended:{rules:im}}),cm=n.define({name:om,rules:tm,recommended:{rules:rm,severity:`warn`}}),lm=u.assign(sm,{configs:u.assign(sm.configs,{recommended:u.assign(sm.configs.recommended,{rules:u.assign(sm.configs.recommended.rules,cm.configs.recommended.rules)})})});export{lm as default,am as recommendedRules,tm as rules};