@ls-stack/extended-lint 0.21.1 → 0.22.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.
@@ -1,4 +1,4 @@
1
- "use strict";var Mt=Object.create;var ce=Object.defineProperty;var Lt=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var Ht=Object.getPrototypeOf,Wt=Object.prototype.hasOwnProperty;var Ut=(e,t)=>{for(var n in t)ce(e,n,{get:t[n],enumerable:!0})},Be=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of jt(t))!Wt.call(e,c)&&c!==n&&ce(e,c,{get:()=>t[c],enumerable:!(i=Lt(t,c))||i.enumerable});return e};var Vt=(e,t,n)=>(n=e!=null?Mt(Ht(e)):{},Be(t||!e||!e.__esModule?ce(n,"default",{value:e,enumerable:!0}):n,e)),zt=e=>Be(ce({},"__esModule",{value:!0}),e);var Hn={};Ut(Hn,{extendedLintPlugin:()=>jn});module.exports=zt(Hn);var Z=require("@typescript-eslint/utils");var Ee=Symbol.for("optional");function L(e){return{...e,[Ee]:!0}}function Ge(e,t){return{enum:e,...t}}function le(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function ne(e){return{...e,type:"number"}}function qe(e){return{...e,type:"integer"}}function U(e,t){return{...t,type:"array",items:e}}function M(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let i,c=[];for(i in e)e[i][Ee]?e[i][Ee]=void 0:c.push(i);c.length>0&&(n.required=c)}return n}function be(...e){return{anyOf:e}}var Yt=Z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Bt=M({disallow:L(U(M({selector:F(),message:F(),replace:L(be(F(),M({regex:F(),with:F()}))),replaceType:L(Ge(["suggestion","autofix"]))}))),__dev_simulateFileName:L(F()),mustMatchSyntax:L(U(M({includeRegex:F(),mustCallFn:U(M({anyCall:U(M({fn:F(),withArgs:U(M({atIndex:qe(),literal:be(F(),ne(),le())}))})),message:L(F())}))})))}),Je="advanced-no-restricted-syntax",Gt=Yt({name:Je,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Bt],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:i,__dev_simulateFileName:c,disallow:p}=t,m=c??e.filename,o=[],r=new Set;for(let{includeRegex:a,mustCallFn:y}of i??[]){let D=qt(m,new RegExp(a));if(!D)continue;let A=_=>{let b=_;for(let{name:I,value:g}of D)b=b.replaceAll(I,g);return b};for(let{anyCall:_,message:b}of y){let I=`Expected file to call the function: ${_.map(({fn:g})=>g).join(" or ")}`;r.add(I),o.push(g=>{let{callee:$}=g;if($.type===Z.AST_NODE_TYPES.Identifier){for(let{fn:w,withArgs:f}of _)if($.name===w){r.delete(I);for(let T of f){let x=g.arguments[T.atIndex],R=typeof T.literal=="string"?A(T.literal):T.literal;if(!x){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${R}" at index ${T.atIndex}${b?`: ${A(b)}`:""}`}});continue}if(x.type!==Z.AST_NODE_TYPES.Literal){e.report({node:x,messageId:"default",data:{message:`Argument at position ${T.atIndex} should the literal "${R}"${b?`: ${A(b)}`:""}`}});continue}x.value!==R&&e.report({node:x,messageId:"default",data:{message:`Argument should have the value "${R}"${b?`: ${A(b)}`:""}`},fix:O=>O.replaceText(x,typeof R=="string"?`'${R}'`:String(R))})}break}}})}}for(let{selector:a,message:y,replace:D,replaceType:A="suggestion"}of p??[]){if(a==="CallExpression"){o.push(_=>{l(D,_,y,A)});continue}n[a]=_=>{l(D,_,y,A)}}return o.length>0&&(n.CallExpression=a=>{if(a.type===Z.AST_NODE_TYPES.CallExpression)for(let y of o)y(a)}),n["Program:exit"]=a=>{for(let y of r)e.report({node:a,messageId:"default",data:{message:`${y}`}})},n;function l(a,y,D,A){let _=b=>{if(!a)return null;if(typeof a=="string")return b.replaceText(y,a);{let I=new RegExp(a.regex),g=e.sourceCode.getText(y);return b.replaceText(y,g.replace(I,a.with))}};e.report({node:y,messageId:"default",data:{message:D},fix:a&&A==="autofix"?_:void 0,suggest:a&&A==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof a=="string"?a:a.with}"`},fix:_}]:void 0})}}});function qt(e,t){let n=[],i=t.exec(e);if(!i)return null;let[c,...p]=i;n.push({name:"$0_lowercase",value:c.toLowerCase()}),n.push({name:"$0_capitalize",value:Xe(c)}),n.push({name:"$0_uncapitalize",value:Ke(c)}),n.push({name:"$0",value:c});for(let m=0;m<p.length;m++){let o=`$${m+1}`,r=p[m];n.push({name:`${o}_lowercase`,value:r.toLowerCase()}),n.push({name:`${o}_capitalize`,value:Xe(r)}),n.push({name:`${o}_uncapitalize`,value:Ke(r)}),n.push({name:o,value:r})}return n}function Xe(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ke(e){return e.charAt(0).toLowerCase()+e.slice(1)}var Te={name:Je,rule:Gt};var Xt=/eslint +react-compiler\/react-compiler: +\["error/,Qe={meta:{type:"suggestion",docs:{description:"verifies the list of dependencies for Hooks like useEffect and similar",recommended:!0,url:"https://github.com/facebook/react/issues/14920"},fixable:"code",hasSuggestions:!0,schema:[{type:"object",additionalProperties:!1,ignoreIfReactCompilerIsEnabled:!1,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},ignoreIfReactCompilerIsEnabled:{type:"boolean"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let t=!1,n=typeof e.getSource=="function"?g=>n(g):g=>e.sourceCode.getText(g),i=typeof e.getScope=="function"?()=>i():g=>e.sourceCode.getScope(g),c=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,p=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,m={additionalHooks:c,enableDangerousAutofixThisMayCauseInfiniteLoops:p};function o(g){p&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let r=e.getSourceCode().scopeManager,l=new WeakMap,a=new WeakSet,y=new WeakMap,D=new WeakMap,A=new WeakSet;function _(g,$){return function(w){if($.has(w))return $.get(w);let f=g(w);return $.set(w,f),f}}function b(g,$,w,f,T){T&&g.async&&o({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
1
+ "use strict";var Ht=Object.create;var ce=Object.defineProperty;var Wt=Object.getOwnPropertyDescriptor;var Ut=Object.getOwnPropertyNames;var Vt=Object.getPrototypeOf,Yt=Object.prototype.hasOwnProperty;var zt=(e,t)=>{for(var n in t)ce(e,n,{get:t[n],enumerable:!0})},Xe=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ut(t))!Yt.call(e,s)&&s!==n&&ce(e,s,{get:()=>t[s],enumerable:!(i=Wt(t,s))||i.enumerable});return e};var Bt=(e,t,n)=>(n=e!=null?Ht(Vt(e)):{},Xe(t||!e||!e.__esModule?ce(n,"default",{value:e,enumerable:!0}):n,e)),Xt=e=>Xe(ce({},"__esModule",{value:!0}),e);var zn={};zt(zn,{extendedLintPlugin:()=>Yn});module.exports=Xt(zn);var Z=require("@typescript-eslint/utils");var Te=Symbol.for("optional");function j(e){return{...e,[Te]:!0}}function Ge(e,t){return{enum:e,...t}}function ue(e){return{...e,type:"boolean"}}function L(e){return{...e,type:"string"}}function ne(e){return{...e,type:"number"}}function Je(e){return{...e,type:"integer"}}function V(e,t){return{...t,type:"array",items:e}}function M(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let i,s=[];for(i in e)e[i][Te]?e[i][Te]=void 0:s.push(i);s.length>0&&(n.required=s)}return n}function be(...e){return{anyOf:e}}var Gt=Z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Jt=M({disallow:j(V(M({selector:L(),message:L(),replace:j(be(L(),M({regex:L(),with:L()}))),replaceType:j(Ge(["suggestion","autofix"]))}))),__dev_simulateFileName:j(L()),mustMatchSyntax:j(V(M({includeRegex:L(),mustCallFn:V(M({anyCall:V(M({fn:L(),withArgs:V(M({atIndex:Je(),literal:be(L(),ne(),ue())}))})),message:j(L())}))})))}),Ze="advanced-no-restricted-syntax",qt=Gt({name:Ze,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Jt],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:i,__dev_simulateFileName:s,disallow:p}=t,d=s??e.filename,l=[],r=new Set;for(let{includeRegex:a,mustCallFn:m}of i??[]){let $=Kt(d,new RegExp(a));if(!$)continue;let v=_=>{let T=_;for(let{name:R,value:g}of $)T=T.replaceAll(R,g);return T};for(let{anyCall:_,message:T}of m){let R=`Expected file to call the function: ${_.map(({fn:g})=>g).join(" or ")}`;r.add(R),l.push(g=>{let{callee:D}=g;if(D.type===Z.AST_NODE_TYPES.Identifier){for(let{fn:I,withArgs:f}of _)if(D.name===I){r.delete(R);for(let b of f){let x=g.arguments[b.atIndex],w=typeof b.literal=="string"?v(b.literal):b.literal;if(!x){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${w}" at index ${b.atIndex}${T?`: ${v(T)}`:""}`}});continue}if(x.type!==Z.AST_NODE_TYPES.Literal){e.report({node:x,messageId:"default",data:{message:`Argument at position ${b.atIndex} should the literal "${w}"${T?`: ${v(T)}`:""}`}});continue}x.value!==w&&e.report({node:x,messageId:"default",data:{message:`Argument should have the value "${w}"${T?`: ${v(T)}`:""}`},fix:O=>O.replaceText(x,typeof w=="string"?`'${w}'`:String(w))})}break}}})}}for(let{selector:a,message:m,replace:$,replaceType:v="suggestion"}of p??[]){if(a==="CallExpression"){l.push(_=>{c($,_,m,v)});continue}n[a]=_=>{c($,_,m,v)}}return l.length>0&&(n.CallExpression=a=>{if(a.type===Z.AST_NODE_TYPES.CallExpression)for(let m of l)m(a)}),n["Program:exit"]=a=>{for(let m of r)e.report({node:a,messageId:"default",data:{message:`${m}`}})},n;function c(a,m,$,v){let _=T=>{if(!a)return null;if(typeof a=="string")return T.replaceText(m,a);{let R=new RegExp(a.regex),g=e.sourceCode.getText(m);return T.replaceText(m,g.replace(R,a.with))}};e.report({node:m,messageId:"default",data:{message:$},fix:a&&v==="autofix"?_:void 0,suggest:a&&v==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof a=="string"?a:a.with}"`},fix:_}]:void 0})}}});function Kt(e,t){let n=[],i=t.exec(e);if(!i)return null;let[s,...p]=i;n.push({name:"$0_lowercase",value:s.toLowerCase()}),n.push({name:"$0_capitalize",value:qe(s)}),n.push({name:"$0_uncapitalize",value:Ke(s)}),n.push({name:"$0",value:s});for(let d=0;d<p.length;d++){let l=`$${d+1}`,r=p[d];n.push({name:`${l}_lowercase`,value:r.toLowerCase()}),n.push({name:`${l}_capitalize`,value:qe(r)}),n.push({name:`${l}_uncapitalize`,value:Ke(r)}),n.push({name:l,value:r})}return n}function qe(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ke(e){return e.charAt(0).toLowerCase()+e.slice(1)}var xe={name:Ze,rule:qt};var Zt=/eslint +react-compiler\/react-compiler: +\["error/,et={meta:{type:"suggestion",docs:{description:"verifies the list of dependencies for Hooks like useEffect and similar",recommended:!0,url:"https://github.com/facebook/react/issues/14920"},fixable:"code",hasSuggestions:!0,schema:[{type:"object",additionalProperties:!1,ignoreIfReactCompilerIsEnabled:!1,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},ignoreIfReactCompilerIsEnabled:{type:"boolean"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let t=!1,n=typeof e.getSource=="function"?g=>n(g):g=>e.sourceCode.getText(g),i=typeof e.getScope=="function"?()=>i():g=>e.sourceCode.getScope(g),s=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,p=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,d={additionalHooks:s,enableDangerousAutofixThisMayCauseInfiniteLoops:p};function l(g){p&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let r=e.getSourceCode().scopeManager,c=new WeakMap,a=new WeakSet,m=new WeakMap,$=new WeakMap,v=new WeakSet;function _(g,D){return function(I){if(D.has(I))return D.get(I);let f=g(I);return D.set(I,f),f}}function T(g,D,I,f,b){b&&g.async&&l({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
2
2
 
3
3
  useEffect(() => {
4
4
  async function fetchData() {
@@ -9,5 +9,5 @@ useEffect(() => {
9
9
  fetchData();
10
10
  }, [someId]); // Or [] if effect doesn't need props or state
11
11
 
12
- Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=r.acquire(g),R=new Set,O=null;{let s=x.upper;for(;s&&(R.add(s),s.type!=="function");)s=s.upper;if(!s)return;O=s}let C=Array.isArray;function N(s){if(!C(s.defs))return!1;let u=s.defs[0];if(u==null||u.node.type!=="VariableDeclarator")return!1;let d=u.node.init;if(d==null)return!1;for(;d.type==="TSAsExpression";)d=d.expression;let h=u.node.parent;if(h==null&&(Re(O.block,u.node.id),h=u.node.parent,h==null))return!1;if(h.kind==="const"&&d.type==="Literal"&&(typeof d.value=="string"||typeof d.value=="number"||d.value===null))return!0;if(d.type!=="CallExpression")return!1;let E=d.callee;if(E.type==="MemberExpression"&&E.object.name==="React"&&E.property!=null&&!E.computed&&(E=E.property),E.type!=="Identifier")return!1;let S=u.node.id,{name:k}=E;if(k==="useRef"&&S.type==="Identifier")return!0;if(en(E)&&S.type==="Identifier"){for(let v of s.references)v!==S&&A.add(v.identifier);return!0}else if(k==="useState"||k==="useReducer"){if(S.type==="ArrayPattern"&&S.elements.length===2&&C(s.identifiers)){if(S.elements[1]===s.identifiers[0]){if(k==="useState"){let v=s.references,W=0;for(let B=0;B<v.length;B++){if(v[B].isWrite()&&W++,W>1)return!1;l.set(v[B].identifier,S.elements[0])}}return!0}else if(S.elements[0]===s.identifiers[0]){if(k==="useState"){let v=s.references;for(let W=0;W<v.length;W++)a.add(v[W].identifier)}return!1}}}else if(k==="useTransition"&&S.type==="ArrayPattern"&&S.elements.length===2&&Array.isArray(s.identifiers)&&S.elements[1]===s.identifiers[0])return!0;return!1}function Y(s){if(!C(s.defs))return!1;let u=s.defs[0];if(u==null||u.node==null||u.node.id==null)return!1;let d=u.node,h=O.childScopes,E=null,S;for(S=0;S<h.length;S++){let k=h[S],v=k.block;if(d.type==="FunctionDeclaration"&&v===d||d.type==="VariableDeclarator"&&v.parent===d){E=k;break}}if(E==null)return!1;for(S=0;S<E.through.length;S++){let k=E.through[S];if(k.resolved!=null&&R.has(k.resolved.scope)&&!He(k.resolved))return!1}return!0}let He=_(N,y),$t=_(Y,D),We=new Map;function Dt(s){let u=s.from,d=!1;for(;u.block!==g;)u.type==="function"&&(d=u.block.parent!=null&&u.block.parent.type==="ReturnStatement"),u=u.upper;return d}let H=new Map,ye=new Map;Ue(x);function Ue(s){for(let u of s.references){if(!u.resolved||!R.has(u.resolved.scope))continue;let d=Re(g,u.identifier),h=et(d),E=G(h,ye);if(T&&h.type==="Identifier"&&(h.parent.type==="MemberExpression"||h.parent.type==="OptionalMemberExpression")&&!h.parent.computed&&h.parent.property.type==="Identifier"&&h.parent.property.name==="current"&&Dt(u)&&We.set(E,{reference:u,dependencyNode:h}),h.parent.type==="TSTypeQuery"||h.parent.type==="TSTypeReference")continue;let S=u.resolved.defs[0];if(S!=null&&!(S.node!=null&&S.node.init===g.parent)&&S.type!=="TypeParameter")if(H.has(E))H.get(E).references.push(u);else{let k=u.resolved,v=He(k)||$t(k);H.set(E,{isStable:v,references:[u]})}}for(let u of s.childScopes)Ue(u)}We.forEach(({reference:s,dependencyNode:u},d)=>{let h=s.resolved.references,E=!1;for(let S=0;S<h.length;S++){let{identifier:k}=h[S],{parent:v}=k;if(v!=null&&v.type==="MemberExpression"&&!v.computed&&v.property.type==="Identifier"&&v.property.name==="current"&&v.parent.type==="AssignmentExpression"&&v.parent.left===v){E=!0;break}}E||o({node:u.parent.property,message:`The ref value '${d}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${d}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let ge=new Set;function Ot(s,u){ge.has(u)||(ge.add(u),o({node:s,message:`Assignments to the '${u}' variable from inside React Hook ${n(w)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(w)}.`}))}let se=new Set;if(H.forEach(({isStable:s,references:u},d)=>{s&&se.add(d),u.forEach(h=>{h.writeExpr&&Ot(h.writeExpr,d)})}),ge.size>0)return;if(!$){let s=null;if(H.forEach(({isStable:u,references:d},h)=>{s||d.forEach(E=>{if(s)return;let S=E.identifier;if(!l.has(S))return;let v=E.from;for(;v.type!=="function";)v=v.upper;v.block===g&&(s=h)})}),s){let{suggestedDependencies:u}=xe({dependencies:H,declaredDependencies:[],stableDependencies:se,externalDependencies:new Set,isEffect:!0});o({node:w,message:`React Hook ${f} contains a call to '${s}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+u.join(", ")+`] as a second argument to the ${f} Hook.`,suggest:[{desc:`Add dependencies array: [${u.join(", ")}]`,fix(d){return d.insertTextAfter(g,`, [${u.join(", ")}]`)}}]})}return}let ee=[],te=new Set;$.type!=="ArrayExpression"?o({node:$,message:`React Hook ${n(w)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):$.elements.forEach(s=>{if(s===null)return;if(s.type==="SpreadElement"){o({node:s,message:`React Hook ${n(w)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}A.has(s)&&o({node:s,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(s)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(s)}\``,fix(E){return E.removeRange(s.range)}}]});let u;try{u=G(s,ye)}catch(E){if(/Unsupported node type/.test(E.message)){s.type==="Literal"?H.has(s.value)?o({node:s,message:`The ${s.raw} literal is not a valid dependency because it never changes. Did you mean to include ${s.value} in the array instead?`}):o({node:s,message:`The ${s.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):o({node:s,message:`React Hook ${n(w)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw E}let d=s;for(;d.type==="MemberExpression"||d.type==="OptionalMemberExpression"||d.type==="ChainExpression";)d=d.object||d.expression.object;let h=!O.through.some(E=>E.identifier===d);ee.push({key:u,node:s}),h||te.add(u)});let{suggestedDependencies:Pt,unnecessaryDependencies:oe,missingDependencies:X,duplicateDependencies:Ve}=xe({dependencies:H,declaredDependencies:ee,stableDependencies:se,externalDependencies:te,isEffect:T}),ae=Pt;if(Ve.size+X.size+oe.size===0){if(t)return;Kt({declaredDependencies:ee,declaredDependenciesNode:$,componentScope:O,scope:x}).forEach(({construction:u,isUsedOutsideOfHook:d,depType:h})=>{let E=h==="function"?"useCallback":"useMemo",S=h==="function"?"definition":"initialization",k=`wrap the ${S} of '${u.name.name}' in its own ${E}() Hook.`,v=d?`To fix this, ${k}`:`Move it inside the ${f} callback. Alternatively, ${k}`,W=h==="conditional"||h==="logical expression"?"could make":"makes",B=`The '${u.name.name}' ${h} ${W} the dependencies of ${f} Hook (at line ${$.loc.start.line}) change on every render. ${v}`,ze;d&&u.type==="Variable"&&h==="function"&&(ze=[{desc:`Wrap the ${S} of '${u.name.name}' in its own ${E}() Hook.`,fix(Ye){let[Nt,Ft]=E==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Ye.insertTextBefore(u.node.init,Nt),Ye.insertTextAfter(u.node.init,Ft)]}}]),o({node:u.node,message:B,suggest:ze})});return}!T&&X.size>0&&(ae=xe({dependencies:H,declaredDependencies:[],stableDependencies:se,externalDependencies:te,isEffect:T}).suggestedDependencies);function _t(){if(ee.length===0)return!0;let s=ee.map(d=>d.key),u=s.slice().sort();return s.join(",")===u.join(",")}_t()&&ae.sort();function he(s){let u=s.split("."),d="";for(let h=0;h<u.length;h++){if(h!==0){let E=u.slice(0,h+1).join("."),S=ye.get(E)===!0;d+=S?"?.":"."}d+=u[h]}return d}function Se(s,u,d,h){return s.size===0?null:(s.size>1?"":u+" ")+d+" "+(s.size>1?"dependencies":"dependency")+": "+Zt(Array.from(s).sort().map(E=>"'"+he(E)+"'"))+`. Either ${h} ${s.size>1?"them":"it"} or remove the dependency array.`}let z="";if(oe.size>0){let s=null;if(Array.from(oe.keys()).forEach(u=>{s===null&&u.endsWith(".current")&&(s=u)}),s!==null)z=` Mutable values like '${s}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(te.size>0){let u=Array.from(te)[0];x.set.has(u)||(z=` Outer scope values like '${u}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!z&&X.has("props")){let s=H.get("props");if(s==null)return;let u=s.references;if(!Array.isArray(u))return;let d=!0;for(let h=0;h<u.length;h++){let E=u[h],S=Re(O.block,E.identifier);if(!S){d=!1;break}let k=S.parent;if(k==null){d=!1;break}if(k.type!=="MemberExpression"&&k.type!=="OptionalMemberExpression"){d=!1;break}}d&&(z=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${f} call and refer to those specific props inside ${n(w)}.`)}if(!z&&X.size>0){let s=null;X.forEach(u=>{if(s)return;let d=O.set.get(u),h=H.get(u);if(h.references[0].resolved!==d)return;let E=d.defs[0];if(E==null||E.name==null||E.type!=="Parameter")return;let S=!1,k;for(let v=0;v<h.references.length;v++)if(k=h.references[v].identifier,k!=null&&k.parent!=null&&(k.parent.type==="CallExpression"||k.parent.type==="OptionalCallExpression")&&k.parent.callee===k){S=!0;break}S&&(s=u)}),s!==null&&(z=` If '${s}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!z&&X.size>0){let s=null;if(X.forEach(u=>{if(s!==null)return;let h=H.get(u).references,E,S;for(let k=0;k<h.length;k++){for(E=h[k].identifier,S=E.parent;S!=null&&S!==O.block;){if(S.type==="CallExpression"){let v=l.get(S.callee);if(v!=null){if(v.name===u)s={missingDep:u,setter:S.callee.name,form:"updater"};else if(a.has(E))s={missingDep:u,setter:S.callee.name,form:"reducer"};else{let W=h[k].resolved;if(W!=null){let B=W.defs[0];B!=null&&B.type==="Parameter"&&(s={missingDep:u,setter:S.callee.name,form:"inlineReducer"})}}break}}S=S.parent}if(s!==null)break}}),s!==null)switch(s.form){case"reducer":z=` You can also replace multiple useState variables with useReducer if '${s.setter}' needs the current value of '${s.missingDep}'.`;break;case"inlineReducer":z=` If '${s.setter}' needs the current value of '${s.missingDep}', you can also switch to useReducer instead of useState and read '${s.missingDep}' in the reducer.`;break;case"updater":z=` You can also do a functional update '${s.setter}(${s.missingDep.slice(0,1)} => ...)' if you only need '${s.missingDep}' in the '${s.setter}' call.`;break;default:throw new Error("Unknown case.")}}o({node:$,message:`React Hook ${n(w)} has `+(Se(X,"a","missing","include")||Se(oe,"an","unnecessary","exclude")||Se(Ve,"a","duplicate","omit"))+z,suggest:[{desc:`Update the dependencies array to be: [${ae.map(he).join(", ")}]`,fix(s){return s.replaceText($,`[${ae.map(he).join(", ")}]`)}}]})}function I(g){let $=Jt(g.callee,m);if($===-1)return;let w=g.arguments[$],f=g.callee,T=tt(f).name,x=g.arguments[$+1],R=/Effect($|[^a-z])/g.test(T);if(!w){o({node:f,message:`React Hook ${T} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!R)){if(!x&&!R){(T==="useMemo"||T==="useCallback")&&o({node:f,message:`React Hook ${T} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(w.type){case"FunctionExpression":case"ArrowFunctionExpression":b(w,x,f,T,R);return;case"Identifier":if(!x||x.elements&&x.elements.some(N=>N&&N.type==="Identifier"&&N.name===w.name))return;let O=i(g).set.get(w.name);if(O==null||O.defs==null)return;let C=O.defs[0];if(!C||!C.node||C.type!=="Variable"&&C.type!=="FunctionName")break;switch(C.node.type){case"FunctionDeclaration":b(C.node,x,f,T,R);return;case"VariableDeclarator":let N=C.node.init;if(!N)break;switch(N.type){case"ArrowFunctionExpression":case"FunctionExpression":b(N,x,f,T,R);return}break}break;default:o({node:f,message:`React Hook ${T} received a function whose dependencies are unknown. Pass an inline function instead.`});return}o({node:f,message:`React Hook ${T} has a missing dependency: '${w.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${w.name}]`,fix(O){return O.replaceText(x,`[${w.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(Xt.test(g.value))return t=!0,{CallExpression:$=>I($,!0)}}return{CallExpression:g=>I(g)}}};function xe({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:i,isEffect:c}){let p=m();function m(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((b,I)=>{let g=o(p,I);g.isUsed=!0,r(p,I,$=>{$.isSubtreeUsed=!0})}),t.forEach(({key:b})=>{let I=o(p,b);I.isSatisfiedRecursively=!0}),n.forEach(b=>{let I=o(p,b);I.isSatisfiedRecursively=!0});function o(b,I){let g=I.split("."),$=b;for(let w of g){let f=$.children.get(w);f||(f=m(),$.children.set(w,f)),$=f}return $}function r(b,I,g){let $=I.split("."),w=b;for(let f of $){let T=w.children.get(f);if(!T)return;g(T),w=T}}let l=new Set,a=new Set;y(p,l,a,b=>b);function y(b,I,g,$){b.children.forEach((w,f)=>{let T=$(f);if(w.isSatisfiedRecursively){w.isSubtreeUsed&&g.add(T);return}if(w.isUsed){I.add(T);return}y(w,I,g,x=>T+"."+x)})}let D=[],A=new Set,_=new Set;return t.forEach(({key:b})=>{a.has(b)?D.indexOf(b)===-1?D.push(b):_.add(b):A.add(b)}),l.forEach(b=>{D.push(b)}),{suggestedDependencies:D,unnecessaryDependencies:A,duplicateDependencies:_,missingDependencies:l}}function K(e){switch(e.type){case"ObjectExpression":return"object";case"ArrayExpression":return"array";case"ArrowFunctionExpression":case"FunctionExpression":return"function";case"ClassExpression":return"class";case"ConditionalExpression":return K(e.consequent)!=null||K(e.alternate)!=null?"conditional":null;case"LogicalExpression":return K(e.left)!=null||K(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return K(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return K(e.expression);case"TSAsExpression":return K(e.expression)}return null}function Kt({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:i}){let c=e.map(({key:m})=>{let o=n.variables.find(l=>l.name===m);if(o==null)return null;let r=o.defs[0];if(r==null)return null;if(r.type==="Variable"&&r.node.type==="VariableDeclarator"&&r.node.id.type==="Identifier"&&r.node.init!=null){let l=K(r.node.init);if(l!=null)return[o,l]}return r.type==="FunctionName"&&r.node.type==="FunctionDeclaration"?[o,"function"]:r.type==="ClassName"&&r.node.type==="ClassDeclaration"?[o,"class"]:null}).filter(Boolean);function p(m){let o=!1;for(let r=0;r<m.references.length;r++){let l=m.references[r];if(l.writeExpr){if(o)return!0;o=!0;continue}let a=l.from;for(;a!==i&&a!=null;)a=a.upper;if(a!==i&&!nt(t,l.identifier))return!0}return!1}return c.map(([m,o])=>({construction:m.defs[0],depType:o,isUsedOutsideOfHook:p(m)}))}function et(e){return(e.parent.type==="MemberExpression"||e.parent.type==="OptionalMemberExpression")&&e.parent.object===e&&e.parent.property.name!=="current"&&!e.parent.computed&&!(e.parent.parent!=null&&(e.parent.parent.type==="CallExpression"||e.parent.parent.type==="OptionalCallExpression")&&e.parent.parent.callee===e.parent)?et(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function we(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function G(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let n=e.name;return t&&t.set(n,!1),n}else if(e.type==="MemberExpression"&&!e.computed){let n=G(e.object,t),i=G(e.property,null),c=`${n}.${i}`;return we(e,t,c),c}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=G(e.object,t),i=G(e.property,null),c=`${n}.${i}`;return we(e,t,c),c}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let i=G(n.object,t),c=G(n.property,null),p=`${i}.${c}`;return we(n,t,p),p}else throw new Error(`Unsupported node type: ${e.type}`)}function tt(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Jt(e,t){let n=tt(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let i;try{i=G(n,null)}catch(c){if(/Unsupported node type/.test(c.message))return 0;throw c}return t.additionalHooks.test(i)?0:-1}else return-1}}function Re(e,t){let n=[e],i=null;for(;n.length;){if(i=n.shift(),Qt(i,t))return i;if(nt(i,t))for(let[c,p]of Object.entries(i))c!=="parent"&&(Ze(p)?(p.parent=i,n.push(p)):Array.isArray(p)&&p.forEach(m=>{Ze(m)&&(m.parent=i,n.push(m))}))}return null}function Zt(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function Ze(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Qt(e,t){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===t.type&&e.name===t.name&&e.range[0]===t.range[0]&&e.range[1]===t.range[1]}function nt(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function en(e){return!1}var ue=require("@typescript-eslint/utils");var tn=ue.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),rt="no-call-with-explicit-generics",nn=M({functions:U(F())}),rn=tn({name:rt,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[nn]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(i){let{callee:c}=i;c.type===ue.AST_NODE_TYPES.Identifier&&n.has(c.name)&&i.typeArguments&&e.report({node:i,messageId:"noExplicitGenerics",data:{functionName:c.name}})}}}}),Ie={name:rt,rule:rn};var J=require("@typescript-eslint/utils"),sn=J.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),it="no-call-with-inferred-generics",on=sn({name:it,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Map(t.functions.map(i=>[i.name,i]));return{CallExpression(i){let{callee:c}=i;if(c.type!==J.AST_NODE_TYPES.Identifier)return;let p=n.get(c.name);if(!p)return;let{minGenerics:m=1,allowAny:o,disallowTypes:r=t.disallowTypes}=p;(i.typeArguments?.params.length||0)<(m||0)&&e.report({node:i,messageId:"missingGenericDeclaration",data:{functionName:c.name,minGenerics:m||0}}),!(o&&!r)&&i.typeArguments?.params?.some(a=>!o&&a.type===J.AST_NODE_TYPES.TSAnyKeyword||r&&a.type===J.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===J.AST_NODE_TYPES.Identifier&&r.includes(a.typeName.name))&&e.report({node:i,messageId:"anyUsedInGenerics",data:{functionName:c.name}})}}}}),Ce={name:it,rule:on};var ie=require("@typescript-eslint/utils"),an=ie.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),st="no-commented-out-code",cn=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],ln=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],un=an({name:st,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create(e){function t(n){if(n.startsWith("/"))return!1;let i=n.trimStart();if(n.startsWith("*")||i.startsWith("INFO:")||i.startsWith("TODO:")||i.startsWith("DOCS:")||i.startsWith("FIX:")||i.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let c of cn)if(i.startsWith(c))return{wrongPattern:c};for(let c of ln)if(typeof c=="string"){if(n.includes(c))return{wrongPattern:c}}else if(c.test(n))return{wrongPattern:`regex(${c.toString()})`};return!1}return{Program(){let i=e.sourceCode.getAllComments();for(let c of i)if(c.type===ie.TSESTree.AST_TOKEN_TYPES.Line||c.type===ie.TSESTree.AST_TOKEN_TYPES.Block){let p=t(c.value);p&&e.report({node:c,messageId:"commentedOutCode",data:{wrongPattern:p.wrongPattern}})}}}}}),ke={name:st,rule:un};var pe=require("@typescript-eslint/utils"),pn=pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ot="no-default-export",fn=pn({name:ot,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.type===pe.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),ve={name:ot,rule:fn};var q=require("@typescript-eslint/utils"),mn=q.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ct="no-non-camel-case-functions",dn=/^[a-z][a-zA-Z0-9]*$/;function at(e){return e.typeName.type===q.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===q.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===q.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var yn=mn({name:ct,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!dn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===q.AST_NODE_TYPES.TSTypeReference?at(n):n.type===q.AST_NODE_TYPES.TSUnionType&&n.types.some(c=>c.type===q.AST_NODE_TYPES.TSTypeReference&&at(c))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Ae={name:ct,rule:yn};var V=require("@typescript-eslint/utils");function $e(e,t){if(e.parent)return e.type===t?e:$e(e.parent,t)}function*De(e){yield e,e.parent&&(yield*De(e.parent))}var gn=V.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),lt="no-optional-root-props",hn=gn({name:lt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.'},schema:[],fixable:"code"},defaultOptions:[],create(e){function t(p){return p.parent.type===V.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration}let n=new Set;function i(p){if(n.has(p))return!1;n.add(p);let o=e.sourceCode.getDeclaredVariables(p)[0];if(!o||o.references.length!==1)return!1;let r=o.references[0];if(!r)return!1;for(let l of De(r.identifier)){if("returnType"in l||l.type===V.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;if(l.type===V.TSESTree.AST_NODE_TYPES.TSTypeAliasDeclaration||l.type===V.TSESTree.AST_NODE_TYPES.TSInterfaceDeclaration)return i(l)}return!0}function c(p){p.key.type!==V.TSESTree.AST_NODE_TYPES.Identifier||!p.optional||e.report({node:p.key,messageId:"optionalNotAllowed",data:{propertyName:p.key.name},fix:m=>{let o=$e(p,V.TSESTree.AST_NODE_TYPES.TSPropertySignature);if(!o)return null;let r=e.sourceCode.getText(o);return m.replaceText(o,r.replace("?:",": undefined |"))}})}return{TSTypeAliasDeclaration(p){if(p.typeAnnotation.type===V.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(t(p)||!i(p)))for(let m of p.typeAnnotation.members)m.type===V.TSESTree.AST_NODE_TYPES.TSPropertySignature&&c(m)},TSInterfaceDeclaration(p){if(!(t(p)||!i(p)))for(let m of p.body.body)m.type===V.TSESTree.AST_NODE_TYPES.TSPropertySignature&&c(m)}}}}),Oe={name:lt,rule:hn};var ut=require("@typescript-eslint/utils"),fe=Vt(require("path"));var Sn=ut.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),pt="no-relative-imports",En=M({find:F(),replacement:F()}),bn=M({aliases:U(En),rootDir:L(F()),allowNotFoundAliases:L(le()),_dev_simulateFileName:L(F())}),Tn=Sn({name:pt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[bn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function i(m){return m.startsWith(".")||m.startsWith("..")}function c(m,o){let r=fe.default.dirname(o);return fe.default.resolve(r,m)}function p(m){let o=t.rootDir??process.cwd(),r=fe.default.relative(o,m);if(r.startsWith("."))return null;r.startsWith("/")||(r=`/${r}`);for(let{find:l,replacement:a}of t.aliases)if(r.startsWith(a)){let y=r.replace(a,l);return{alias:l,newPath:y}}return null}return{ImportDeclaration(m){let o=m.source.value;if(!i(o))return;let r=c(o,n),l=p(r);!l&&t.allowNotFoundAliases||e.report({node:m,messageId:l?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:l?.alias},fix:l?a=>a.replaceText(m.source,`'${l.newPath}'`):void 0})}}}}),Pe={name:pt,rule:Tn};var P=require("@typescript-eslint/utils");var xn=P.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function ft(e){let t=[];for(let n of e.members)n.type===P.AST_NODE_TYPES.TSPropertySignature&&n.key.type===P.AST_NODE_TYPES.Identifier&&t.push([n.key.name,n]);return t}function mt(e,...t){for(let n of t)e.set(...n);return e}var wn=M({forceCheckOnFCPropTypesWithName:L(U(F()))}),dt="no-unused-type-props-in-args",_e=null,Rn=xn({name:dt,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[wn],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!_e&&(_e=n.map(o=>new RegExp(o)));function i(o,r,l,a,y=!0){let D=l.name,A=e.sourceCode.getScope(r).references.find(I=>I.identifier.name===D)?.resolved,_=o&&_e?.some(I=>I.test(D));if(!A||!_&&A.references.filter(I=>I.isTypeReference).length>1)return;let b=A?.defs[0]?.node;if(!(y&&b?.parent?.type===P.AST_NODE_TYPES.ExportNamedDeclaration)){if(b?.type===P.AST_NODE_TYPES.TSTypeAliasDeclaration){c(o,r,a,b.typeAnnotation,!0);return}if(b?.type===P.AST_NODE_TYPES.TSInterfaceDeclaration){c(o,r,a,b.body,!0);return}}}function c(o,r,l,a,y){if(a.type===P.AST_NODE_TYPES.TSInterfaceBody){for(let D of a.body)D.type===P.AST_NODE_TYPES.TSPropertySignature&&D.key.type===P.AST_NODE_TYPES.Identifier&&l.set(D.key.name,D);return}if(a.type===P.AST_NODE_TYPES.TSTypeLiteral){mt(l,...ft(a));return}if(a.type===P.AST_NODE_TYPES.TSIntersectionType){for(let D of a.types)c(o,r,l,D,!0);return}y||a.type===P.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===P.AST_NODE_TYPES.Identifier&&i(o,r,a.typeName,l)}function p(o,r,l){for(let a of l)if(a.type==="ObjectPattern"&&a.typeAnnotation){let y=new Map;if(c(o,r,y,a.typeAnnotation.typeAnnotation,!1),y.size===0)continue;m(a,y)}else a.type===P.AST_NODE_TYPES.AssignmentPattern&&a.left.type===P.AST_NODE_TYPES.ObjectPattern&&p(o,r,[a.left])}function m(o,r){let l=[];if(o.properties.at(-1)?.type===P.AST_NODE_TYPES.RestElement)return;for(let A of o.properties)A.type===P.AST_NODE_TYPES.Property&&A.key.type===P.AST_NODE_TYPES.Identifier&&l.push(A.key.name);let y=[],D=[];for(let[A,_]of r)l.includes(A)||(D.push(A),y.push({node:_,messageId:"unusedObjectTypeProperty",data:{propertyName:A}}));for(let[A,_]of y.entries())e.report({..._,fix:A===y.length-1?b=>{let I=o.properties.at(-1),g=D.join(", ");return I?I?.type===P.AST_NODE_TYPES.RestElement?null:b.insertTextAfter(I,`, ${g}`):b.insertTextBeforeRange([o.range[0]+1,o.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(o){let r=o.declarations[0];if(!r)return;let l=new Map,a=r.id.type===P.AST_NODE_TYPES.Identifier&&r.id.typeAnnotation?.typeAnnotation.type===P.AST_NODE_TYPES.TSTypeReference&&r.id.typeAnnotation.typeAnnotation.typeName.type===P.AST_NODE_TYPES.Identifier&&r.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&r.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(a){if(a.type===P.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===P.AST_NODE_TYPES.Identifier)i(!0,o,a.typeName,l,!1);else if(a.type===P.AST_NODE_TYPES.TSTypeLiteral)mt(l,...ft(a));else if(a.type===P.AST_NODE_TYPES.TSIntersectionType)for(let y of a.types)y.type===P.AST_NODE_TYPES.TSTypeReference&&y.typeName.type===P.AST_NODE_TYPES.Identifier?i(!0,o,y.typeName,l,!1):c(!0,o,l,y,!0);if(l.size!==0&&r.init?.type===P.AST_NODE_TYPES.ArrowFunctionExpression){let y=r.init.params[0];if(!y){e.report({node:r.init,messageId:"missingComponentParam"});return}y.type===P.AST_NODE_TYPES.ObjectPattern&&m(y,l)}}},FunctionDeclaration:function(o){p(!1,o,o.params)},ArrowFunctionExpression(o){p(!1,o,o.params)}}}}),Ne={name:dt,rule:Rn};var Q=require("@typescript-eslint/utils"),In=Q.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),gt="prefer-named-functions",yt=new Map,Cn=In({name:gt,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let i=yt.get(t.ignoreRegex);i?n=i:(n=new RegExp(t.ignoreRegex),yt.set(t.ignoreRegex,n))}return{VariableDeclarator(i){if(i.init&&i.init.type===Q.AST_NODE_TYPES.ArrowFunctionExpression&&i.id.type===Q.AST_NODE_TYPES.Identifier){let c=i.id.name;if(i.id.typeAnnotation||n&&n.test(c)||!t.disallowArrowFnWithImplicitReturns&&i.init.body.type!==Q.AST_NODE_TYPES.BlockStatement)return;let p=i.parent,m=i.init.params,o=i.init.body,r=i.init;e.report({node:i.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:c,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:l=>l.replaceText(p,`${r.async?"async ":""}function ${c}(${m.map(a=>e.sourceCode.getText(a)).join(", ")||""}) ${e.sourceCode.getText(o)}`)}]})}}}}}),Fe={name:gt,rule:Cn};var j=require("@typescript-eslint/utils");var kn=j.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ht="prefer-single-line-if",vn=M({maxLineLength:L(ne()),maxNonSimpleConditionLength:L(ne())}),An=kn({name:ht,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[vn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(i){if(i.consequent.type!==j.AST_NODE_TYPES.BlockStatement||n.getCommentsInside(i.consequent).length>0||i.alternate||i.consequent.body.length!==1)return;let p=i.consequent.body[0];if(p.type===j.AST_NODE_TYPES.ReturnStatement){if(!(!p.argument||p.argument.type===j.AST_NODE_TYPES.Literal||p.argument.type===j.AST_NODE_TYPES.Identifier))return}else if(!(p.type===j.AST_NODE_TYPES.ContinueStatement||p.type===j.AST_NODE_TYPES.BreakStatement))return;if(i.test.type===j.AST_NODE_TYPES.LogicalExpression||i.test.type===j.AST_NODE_TYPES.ConditionalExpression)return;let m;if(t.maxNonSimpleConditionLength&&(i.test.type===j.AST_NODE_TYPES.CallExpression||i.test.type===j.AST_NODE_TYPES.BinaryExpression||i.test.type===j.AST_NODE_TYPES.MemberExpression)&&(m=n.getText(i.test),m.length>t.maxNonSimpleConditionLength))return;m||(m=n.getText(i.test));let o=n.getText(p);if(m.includes(`
13
- `))return;let r=n.getTokenAfter(i);if(r&&r.type===j.AST_TOKEN_TYPES.Punctuator&&r.value==="}")return;let l=$n(n,i),a=`if (${m}) ${o}`;t.maxLineLength&&a.length+l.length>t.maxLineLength||e.report({node:i,messageId:"noSingleLineCurly",fix:y=>y.replaceText(i,a)})}}}});function $n(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Me={name:ht,rule:An};var me=require("@typescript-eslint/utils"),Dn=me.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),St="require-description",On=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Pn=/^eslint-disable-(next-)?line$/u,_n=Dn({name:St,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,i=new Set(t.ignore||[]);return{Program(){for(let c of n.getAllComments()){let p=Nn(c);p!=null&&(i.has(p.kind)||p.description||e.report({loc:Mn(c.loc),messageId:"missingDescription"}))}}}}}),Et={name:St,rule:_n};function Nn(e){let{text:t,description:n}=Fn(e.value);if(!t)return null;let i=On.exec(t);if(!i)return null;let c=i[1];if(!c)return null;let p=Pn.test(c);if(e.type===me.TSESTree.AST_TOKEN_TYPES.Line&&!p||p&&e.loc.start.line!==e.loc.end.line)return null;let m=t.slice(i.index+c.length);return{kind:c,value:m.trim(),description:n}}function Fn(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Mn(e){return{start:{line:e.start.line,column:-1},end:e.end}}function xt(e){return/^use[A-Z0-9]/.test(e)}function de(e){return e.type==="Identifier"?xt(e.name):e.type==="MemberExpression"&&!e.computed&&de(e.property)?e.object.type==="Identifier":!1}function wt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Rt(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function It(e){return!!(e.parent&&e.parent.callee&&Rt(e.parent.callee,"forwardRef"))}function Ct(e){return!!(e.parent&&e.parent.callee&&Rt(e.parent.callee,"memo"))}function Le(e){for(;e;){let t=vt(e);if(t&&(wt(t)||de(t))||It(e)||Ct(e))return!0;e=e.parent}return!1}function bt(e){return!1}function je(e){return!1}var Ln=/eslint +react-compiler\/react-compiler: +\["error/,kt={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let r of e.sourceCode.getAllComments())if(Ln.test(r.value))return{CallExpression(l){let a=null;l.callee.name==="useMemo"?a="useMemo":l.callee.name==="useCallback"&&(a="useCallback"),a&&e.report({node:l,message:`"${a}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?r=>t(r):r=>e.sourceCode.getText(r),n=typeof e.getScope=="function"?()=>n():r=>e.sourceCode.getScope(r),i=null,c=[],p=[],m=new WeakSet;function o(r){for(let l of r.references){let a=l.identifier.parent;if(a.type==="VariableDeclarator"&&a.init&&a.init.type==="CallExpression"&&a.init.callee&&bt(a.init.callee))for(let y of l.resolved.references)y!==l&&m.add(y.identifier)}}return{onCodePathSegmentStart:r=>p.push(r),onCodePathSegmentEnd:()=>p.pop(),onCodePathStart:()=>c.push(new Map),onCodePathEnd(r,l){let a=c.pop();if(a.size===0)return;let y=new Set;function D(f,T){let{cache:x}=D,R=x.get(f.id),O=new Set(T);if(O.has(f.id)){let C=[...O],N=C.slice(C.indexOf(f.id)+1);for(let Y of N)y.add(Y);return BigInt("0")}if(O.add(f.id),R!==void 0)return R;if(r.thrownSegments.includes(f))R=BigInt("0");else if(f.prevSegments.length===0)R=BigInt("1");else{R=BigInt("0");for(let C of f.prevSegments)R+=D(C,O)}return f.reachable&&R===BigInt("0")?x.delete(f.id):x.set(f.id,R),R}function A(f,T){let{cache:x}=A,R=x.get(f.id),O=new Set(T);if(O.has(f.id)){let C=Array.from(O),N=C.slice(C.indexOf(f.id)+1);for(let Y of N)y.add(Y);return BigInt("0")}if(O.add(f.id),R!==void 0)return R;if(r.thrownSegments.includes(f))R=BigInt("0");else if(f.nextSegments.length===0)R=BigInt("1");else{R=BigInt("0");for(let C of f.nextSegments)R+=A(C,O)}return x.set(f.id,R),R}function _(f){let{cache:T}=_,x=T.get(f.id);if(x===null)return 1/0;if(x!==void 0)return x;if(T.set(f.id,null),f.prevSegments.length===0)x=1;else{x=1/0;for(let R of f.prevSegments){let O=_(R);O<x&&(x=O)}x+=1}return T.set(f.id,x),x}D.cache=new Map,A.cache=new Map,_.cache=new Map;let b=A(r.initialSegment),I=vt(l),g=Le(l),$=I?wt(I)||de(I):It(l)||Ct(l),w=1/0;for(let f of r.finalSegments){if(!f.reachable)continue;let T=_(f);T<w&&(w=T)}for(let[f,T]of a){if(!f.reachable)continue;let x=f.nextSegments.length===0?w<=_(f):w<_(f),R=D(f)*A(f),O=y.has(f.id);for(let C of T)if(O&&!je(C)&&e.report({node:C,message:`React Hook "${t(C)}" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.`}),$){if(l.async&&e.report({node:C,message:`React Hook "${t(C)}" cannot be called in an async function.`}),!O&&R!==b&&!je(C)){let Y=`React Hook "${t(C)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(x?" Did you accidentally call a React Hook after an early return?":"");e.report({node:C,message:Y})}}else if(l.parent&&(l.parent.type==="MethodDefinition"||l.parent.type==="ClassProperty")&&l.parent.value===l){let N=`React Hook "${t(C)}" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}else if(I){let N=`React Hook "${t(C)}" is called in function "${t(I)}" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".`;e.report({node:C,message:N})}else if(l.type==="Program"){let N=`React Hook "${t(C)}" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}else if(g&&!je(C)){if(l.parent.type==="CallExpression"&&l.parent.callee.type==="Identifier"&&l.parent.callee.name==="useCallback"){let Y=l.parent;if(Y.parent.type==="VariableDeclarator"&&xt(Y.parent.id.name))return}let N=`React Hook "${t(C)}" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}}},CallExpression(r){if(de(r.callee)){let l=Tt(c),a=Tt(p),y=l.get(a);y||(y=[],l.set(a,y)),y.push(r.callee)}r.callee.type==="Identifier"&&(r.callee.name==="useEffect"||bt(r.callee))&&r.arguments.length>0&&(i=r)},Identifier(r){i==null&&m.has(r)&&r.parent.type!=="CallExpression"&&e.report({node:r,message:`\`${t(r)}\` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.`})},"CallExpression:exit"(r){r===i&&(i=null)},FunctionDeclaration(r){Le(r)&&o(n(r))},ArrowFunctionExpression(r){Le(r)&&o(n(r))}}}};function vt(e){return e.type==="FunctionDeclaration"||e.type==="FunctionExpression"&&e.id?e.id:e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"?e.parent.type==="VariableDeclarator"&&e.parent.init===e?e.parent.id:e.parent.type==="AssignmentExpression"&&e.parent.right===e&&e.parent.operator==="="?e.parent.left:e.parent.type==="Property"&&e.parent.value===e&&!e.parent.computed?e.parent.key:e.parent.type==="AssignmentPattern"&&e.parent.right===e&&!e.parent.computed?e.parent.left:void 0:void 0}function Tt(e){return e[e.length-1]}var At={[Ne.name]:Ne.rule,[ke.name]:ke.rule,[Ce.name]:Ce.rule,"rules-of-hooks":kt,"exhaustive-deps":Qe,"require-description":Et.rule,[ve.name]:ve.rule,[Ae.name]:Ae.rule,[Fe.name]:Fe.rule,[Te.name]:Te.rule,[Ie.name]:Ie.rule,[Pe.name]:Pe.rule,[Me.name]:Me.rule,[Oe.name]:Oe.rule};var jn={rules:At};0&&(module.exports={extendedLintPlugin});
12
+ Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=r.acquire(g),w=new Set,O=null;{let o=x.upper;for(;o&&(w.add(o),o.type!=="function");)o=o.upper;if(!o)return;O=o}let C=Array.isArray;function N(o){if(!C(o.defs))return!1;let u=o.defs[0];if(u==null||u.node.type!=="VariableDeclarator")return!1;let y=u.node.init;if(y==null)return!1;for(;y.type==="TSAsExpression";)y=y.expression;let h=u.node.parent;if(h==null&&(Re(O.block,u.node.id),h=u.node.parent,h==null))return!1;if(h.kind==="const"&&y.type==="Literal"&&(typeof y.value=="string"||typeof y.value=="number"||y.value===null))return!0;if(y.type!=="CallExpression")return!1;let E=y.callee;if(E.type==="MemberExpression"&&E.object.name==="React"&&E.property!=null&&!E.computed&&(E=E.property),E.type!=="Identifier")return!1;let S=u.node.id,{name:k}=E;if(k==="useRef"&&S.type==="Identifier")return!0;if(rn(E)&&S.type==="Identifier"){for(let A of o.references)A!==S&&v.add(A.identifier);return!0}else if(k==="useState"||k==="useReducer"){if(S.type==="ArrayPattern"&&S.elements.length===2&&C(o.identifiers)){if(S.elements[1]===o.identifiers[0]){if(k==="useState"){let A=o.references,U=0;for(let B=0;B<A.length;B++){if(A[B].isWrite()&&U++,U>1)return!1;c.set(A[B].identifier,S.elements[0])}}return!0}else if(S.elements[0]===o.identifiers[0]){if(k==="useState"){let A=o.references;for(let U=0;U<A.length;U++)a.add(A[U].identifier)}return!1}}}else if(k==="useTransition"&&S.type==="ArrayPattern"&&S.elements.length===2&&Array.isArray(o.identifiers)&&S.elements[1]===o.identifiers[0])return!0;return!1}function z(o){if(!C(o.defs))return!1;let u=o.defs[0];if(u==null||u.node==null||u.node.id==null)return!1;let y=u.node,h=O.childScopes,E=null,S;for(S=0;S<h.length;S++){let k=h[S],A=k.block;if(y.type==="FunctionDeclaration"&&A===y||y.type==="VariableDeclarator"&&A.parent===y){E=k;break}}if(E==null)return!1;for(S=0;S<E.through.length;S++){let k=E.through[S];if(k.resolved!=null&&w.has(k.resolved.scope)&&!We(k.resolved))return!1}return!0}let We=_(N,m),Pt=_(z,$),Ue=new Map;function _t(o){let u=o.from,y=!1;for(;u.block!==g;)u.type==="function"&&(y=u.block.parent!=null&&u.block.parent.type==="ReturnStatement"),u=u.upper;return y}let W=new Map,ge=new Map;Ve(x);function Ve(o){for(let u of o.references){if(!u.resolved||!w.has(u.resolved.scope))continue;let y=Re(g,u.identifier),h=tt(y),E=X(h,ge);if(b&&h.type==="Identifier"&&(h.parent.type==="MemberExpression"||h.parent.type==="OptionalMemberExpression")&&!h.parent.computed&&h.parent.property.type==="Identifier"&&h.parent.property.name==="current"&&_t(u)&&Ue.set(E,{reference:u,dependencyNode:h}),h.parent.type==="TSTypeQuery"||h.parent.type==="TSTypeReference")continue;let S=u.resolved.defs[0];if(S!=null&&!(S.node!=null&&S.node.init===g.parent)&&S.type!=="TypeParameter")if(W.has(E))W.get(E).references.push(u);else{let k=u.resolved,A=We(k)||Pt(k);W.set(E,{isStable:A,references:[u]})}}for(let u of o.childScopes)Ve(u)}Ue.forEach(({reference:o,dependencyNode:u},y)=>{let h=o.resolved.references,E=!1;for(let S=0;S<h.length;S++){let{identifier:k}=h[S],{parent:A}=k;if(A!=null&&A.type==="MemberExpression"&&!A.computed&&A.property.type==="Identifier"&&A.property.name==="current"&&A.parent.type==="AssignmentExpression"&&A.parent.left===A){E=!0;break}}E||l({node:u.parent.property,message:`The ref value '${y}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${y}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let he=new Set;function Nt(o,u){he.has(u)||(he.add(u),l({node:o,message:`Assignments to the '${u}' variable from inside React Hook ${n(I)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(I)}.`}))}let oe=new Set;if(W.forEach(({isStable:o,references:u},y)=>{o&&oe.add(y),u.forEach(h=>{h.writeExpr&&Nt(h.writeExpr,y)})}),he.size>0)return;if(!D){let o=null;if(W.forEach(({isStable:u,references:y},h)=>{o||y.forEach(E=>{if(o)return;let S=E.identifier;if(!c.has(S))return;let A=E.from;for(;A.type!=="function";)A=A.upper;A.block===g&&(o=h)})}),o){let{suggestedDependencies:u}=Ie({dependencies:W,declaredDependencies:[],stableDependencies:oe,externalDependencies:new Set,isEffect:!0});l({node:I,message:`React Hook ${f} contains a call to '${o}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+u.join(", ")+`] as a second argument to the ${f} Hook.`,suggest:[{desc:`Add dependencies array: [${u.join(", ")}]`,fix(y){return y.insertTextAfter(g,`, [${u.join(", ")}]`)}}]})}return}let ee=[],te=new Set;D.type!=="ArrayExpression"?l({node:D,message:`React Hook ${n(I)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(o=>{if(o===null)return;if(o.type==="SpreadElement"){l({node:o,message:`React Hook ${n(I)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}v.has(o)&&l({node:o,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(o)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(o)}\``,fix(E){return E.removeRange(o.range)}}]});let u;try{u=X(o,ge)}catch(E){if(/Unsupported node type/.test(E.message)){o.type==="Literal"?W.has(o.value)?l({node:o,message:`The ${o.raw} literal is not a valid dependency because it never changes. Did you mean to include ${o.value} in the array instead?`}):l({node:o,message:`The ${o.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:o,message:`React Hook ${n(I)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw E}let y=o;for(;y.type==="MemberExpression"||y.type==="OptionalMemberExpression"||y.type==="ChainExpression";)y=y.object||y.expression.object;let h=!O.through.some(E=>E.identifier===y);ee.push({key:u,node:o}),h||te.add(u)});let{suggestedDependencies:Ft,unnecessaryDependencies:ae,missingDependencies:J,duplicateDependencies:Ye}=Ie({dependencies:W,declaredDependencies:ee,stableDependencies:oe,externalDependencies:te,isEffect:b}),le=Ft;if(Ye.size+J.size+ae.size===0){if(t)return;Qt({declaredDependencies:ee,declaredDependenciesNode:D,componentScope:O,scope:x}).forEach(({construction:u,isUsedOutsideOfHook:y,depType:h})=>{let E=h==="function"?"useCallback":"useMemo",S=h==="function"?"definition":"initialization",k=`wrap the ${S} of '${u.name.name}' in its own ${E}() Hook.`,A=y?`To fix this, ${k}`:`Move it inside the ${f} callback. Alternatively, ${k}`,U=h==="conditional"||h==="logical expression"?"could make":"makes",B=`The '${u.name.name}' ${h} ${U} the dependencies of ${f} Hook (at line ${D.loc.start.line}) change on every render. ${A}`,ze;y&&u.type==="Variable"&&h==="function"&&(ze=[{desc:`Wrap the ${S} of '${u.name.name}' in its own ${E}() Hook.`,fix(Be){let[Mt,jt]=E==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Be.insertTextBefore(u.node.init,Mt),Be.insertTextAfter(u.node.init,jt)]}}]),l({node:u.node,message:B,suggest:ze})});return}!b&&J.size>0&&(le=Ie({dependencies:W,declaredDependencies:[],stableDependencies:oe,externalDependencies:te,isEffect:b}).suggestedDependencies);function Lt(){if(ee.length===0)return!0;let o=ee.map(y=>y.key),u=o.slice().sort();return o.join(",")===u.join(",")}Lt()&&le.sort();function Se(o){let u=o.split("."),y="";for(let h=0;h<u.length;h++){if(h!==0){let E=u.slice(0,h+1).join("."),S=ge.get(E)===!0;y+=S?"?.":"."}y+=u[h]}return y}function Ee(o,u,y,h){return o.size===0?null:(o.size>1?"":u+" ")+y+" "+(o.size>1?"dependencies":"dependency")+": "+tn(Array.from(o).sort().map(E=>"'"+Se(E)+"'"))+`. Either ${h} ${o.size>1?"them":"it"} or remove the dependency array.`}let Y="";if(ae.size>0){let o=null;if(Array.from(ae.keys()).forEach(u=>{o===null&&u.endsWith(".current")&&(o=u)}),o!==null)Y=` Mutable values like '${o}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(te.size>0){let u=Array.from(te)[0];x.set.has(u)||(Y=` Outer scope values like '${u}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!Y&&J.has("props")){let o=W.get("props");if(o==null)return;let u=o.references;if(!Array.isArray(u))return;let y=!0;for(let h=0;h<u.length;h++){let E=u[h],S=Re(O.block,E.identifier);if(!S){y=!1;break}let k=S.parent;if(k==null){y=!1;break}if(k.type!=="MemberExpression"&&k.type!=="OptionalMemberExpression"){y=!1;break}}y&&(Y=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${f} call and refer to those specific props inside ${n(I)}.`)}if(!Y&&J.size>0){let o=null;J.forEach(u=>{if(o)return;let y=O.set.get(u),h=W.get(u);if(h.references[0].resolved!==y)return;let E=y.defs[0];if(E==null||E.name==null||E.type!=="Parameter")return;let S=!1,k;for(let A=0;A<h.references.length;A++)if(k=h.references[A].identifier,k!=null&&k.parent!=null&&(k.parent.type==="CallExpression"||k.parent.type==="OptionalCallExpression")&&k.parent.callee===k){S=!0;break}S&&(o=u)}),o!==null&&(Y=` If '${o}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!Y&&J.size>0){let o=null;if(J.forEach(u=>{if(o!==null)return;let h=W.get(u).references,E,S;for(let k=0;k<h.length;k++){for(E=h[k].identifier,S=E.parent;S!=null&&S!==O.block;){if(S.type==="CallExpression"){let A=c.get(S.callee);if(A!=null){if(A.name===u)o={missingDep:u,setter:S.callee.name,form:"updater"};else if(a.has(E))o={missingDep:u,setter:S.callee.name,form:"reducer"};else{let U=h[k].resolved;if(U!=null){let B=U.defs[0];B!=null&&B.type==="Parameter"&&(o={missingDep:u,setter:S.callee.name,form:"inlineReducer"})}}break}}S=S.parent}if(o!==null)break}}),o!==null)switch(o.form){case"reducer":Y=` You can also replace multiple useState variables with useReducer if '${o.setter}' needs the current value of '${o.missingDep}'.`;break;case"inlineReducer":Y=` If '${o.setter}' needs the current value of '${o.missingDep}', you can also switch to useReducer instead of useState and read '${o.missingDep}' in the reducer.`;break;case"updater":Y=` You can also do a functional update '${o.setter}(${o.missingDep.slice(0,1)} => ...)' if you only need '${o.missingDep}' in the '${o.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:D,message:`React Hook ${n(I)} has `+(Ee(J,"a","missing","include")||Ee(ae,"an","unnecessary","exclude")||Ee(Ye,"a","duplicate","omit"))+Y,suggest:[{desc:`Update the dependencies array to be: [${le.map(Se).join(", ")}]`,fix(o){return o.replaceText(D,`[${le.map(Se).join(", ")}]`)}}]})}function R(g){let D=en(g.callee,d);if(D===-1)return;let I=g.arguments[D],f=g.callee,b=nt(f).name,x=g.arguments[D+1],w=/Effect($|[^a-z])/g.test(b);if(!I){l({node:f,message:`React Hook ${b} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!w)){if(!x&&!w){(b==="useMemo"||b==="useCallback")&&l({node:f,message:`React Hook ${b} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(I.type){case"FunctionExpression":case"ArrowFunctionExpression":T(I,x,f,b,w);return;case"Identifier":if(!x||x.elements&&x.elements.some(N=>N&&N.type==="Identifier"&&N.name===I.name))return;let O=i(g).set.get(I.name);if(O==null||O.defs==null)return;let C=O.defs[0];if(!C||!C.node||C.type!=="Variable"&&C.type!=="FunctionName")break;switch(C.node.type){case"FunctionDeclaration":T(C.node,x,f,b,w);return;case"VariableDeclarator":let N=C.node.init;if(!N)break;switch(N.type){case"ArrowFunctionExpression":case"FunctionExpression":T(N,x,f,b,w);return}break}break;default:l({node:f,message:`React Hook ${b} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:f,message:`React Hook ${b} has a missing dependency: '${I.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${I.name}]`,fix(O){return O.replaceText(x,`[${I.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(Zt.test(g.value))return t=!0,{CallExpression:D=>R(D,!0)}}return{CallExpression:g=>R(g)}}};function Ie({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:i,isEffect:s}){let p=d();function d(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,R)=>{let g=l(p,R);g.isUsed=!0,r(p,R,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let R=l(p,T);R.isSatisfiedRecursively=!0}),n.forEach(T=>{let R=l(p,T);R.isSatisfiedRecursively=!0});function l(T,R){let g=R.split("."),D=T;for(let I of g){let f=D.children.get(I);f||(f=d(),D.children.set(I,f)),D=f}return D}function r(T,R,g){let D=R.split("."),I=T;for(let f of D){let b=I.children.get(f);if(!b)return;g(b),I=b}}let c=new Set,a=new Set;m(p,c,a,T=>T);function m(T,R,g,D){T.children.forEach((I,f)=>{let b=D(f);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&g.add(b);return}if(I.isUsed){R.add(b);return}m(I,R,g,x=>b+"."+x)})}let $=[],v=new Set,_=new Set;return t.forEach(({key:T})=>{a.has(T)?$.indexOf(T)===-1?$.push(T):_.add(T):v.add(T)}),c.forEach(T=>{$.push(T)}),{suggestedDependencies:$,unnecessaryDependencies:v,duplicateDependencies:_,missingDependencies:c}}function q(e){switch(e.type){case"ObjectExpression":return"object";case"ArrayExpression":return"array";case"ArrowFunctionExpression":case"FunctionExpression":return"function";case"ClassExpression":return"class";case"ConditionalExpression":return q(e.consequent)!=null||q(e.alternate)!=null?"conditional":null;case"LogicalExpression":return q(e.left)!=null||q(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return q(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return q(e.expression);case"TSAsExpression":return q(e.expression)}return null}function Qt({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:i}){let s=e.map(({key:d})=>{let l=n.variables.find(c=>c.name===d);if(l==null)return null;let r=l.defs[0];if(r==null)return null;if(r.type==="Variable"&&r.node.type==="VariableDeclarator"&&r.node.id.type==="Identifier"&&r.node.init!=null){let c=q(r.node.init);if(c!=null)return[l,c]}return r.type==="FunctionName"&&r.node.type==="FunctionDeclaration"?[l,"function"]:r.type==="ClassName"&&r.node.type==="ClassDeclaration"?[l,"class"]:null}).filter(Boolean);function p(d){let l=!1;for(let r=0;r<d.references.length;r++){let c=d.references[r];if(c.writeExpr){if(l)return!0;l=!0;continue}let a=c.from;for(;a!==i&&a!=null;)a=a.upper;if(a!==i&&!rt(t,c.identifier))return!0}return!1}return s.map(([d,l])=>({construction:d.defs[0],depType:l,isUsedOutsideOfHook:p(d)}))}function tt(e){return(e.parent.type==="MemberExpression"||e.parent.type==="OptionalMemberExpression")&&e.parent.object===e&&e.parent.property.name!=="current"&&!e.parent.computed&&!(e.parent.parent!=null&&(e.parent.parent.type==="CallExpression"||e.parent.parent.type==="OptionalCallExpression")&&e.parent.parent.callee===e.parent)?tt(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function we(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function X(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let n=e.name;return t&&t.set(n,!1),n}else if(e.type==="MemberExpression"&&!e.computed){let n=X(e.object,t),i=X(e.property,null),s=`${n}.${i}`;return we(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=X(e.object,t),i=X(e.property,null),s=`${n}.${i}`;return we(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let i=X(n.object,t),s=X(n.property,null),p=`${i}.${s}`;return we(n,t,p),p}else throw new Error(`Unsupported node type: ${e.type}`)}function nt(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function en(e,t){let n=nt(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let i;try{i=X(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(i)?0:-1}else return-1}}function Re(e,t){let n=[e],i=null;for(;n.length;){if(i=n.shift(),nn(i,t))return i;if(rt(i,t))for(let[s,p]of Object.entries(i))s!=="parent"&&(Qe(p)?(p.parent=i,n.push(p)):Array.isArray(p)&&p.forEach(d=>{Qe(d)&&(d.parent=i,n.push(d))}))}return null}function tn(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function Qe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function nn(e,t){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===t.type&&e.name===t.name&&e.range[0]===t.range[0]&&e.range[1]===t.range[1]}function rt(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function rn(e){return!1}var pe=require("@typescript-eslint/utils");var sn=pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),it="no-call-with-explicit-generics",on=M({functions:V(L())}),an=sn({name:it,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[on]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(i){let{callee:s}=i;s.type===pe.AST_NODE_TYPES.Identifier&&n.has(s.name)&&i.typeArguments&&e.report({node:i,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),Ce={name:it,rule:an};var K=require("@typescript-eslint/utils"),ln=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),st="no-call-with-inferred-generics",cn=ln({name:st,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Map(t.functions.map(i=>[i.name,i]));return{CallExpression(i){let{callee:s}=i;if(s.type!==K.AST_NODE_TYPES.Identifier)return;let p=n.get(s.name);if(!p)return;let{minGenerics:d=1,allowAny:l,disallowTypes:r=t.disallowTypes}=p;(i.typeArguments?.params.length||0)<(d||0)&&e.report({node:i,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:d||0}}),!(l&&!r)&&i.typeArguments?.params?.some(a=>!l&&a.type===K.AST_NODE_TYPES.TSAnyKeyword||r&&a.type===K.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===K.AST_NODE_TYPES.Identifier&&r.includes(a.typeName.name))&&e.report({node:i,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),ke={name:st,rule:cn};var ie=require("@typescript-eslint/utils"),un=ie.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ot="no-commented-out-code",pn=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],fn=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],mn=un({name:ot,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create(e){function t(n){if(n.startsWith("/"))return!1;let i=n.trimStart();if(n.startsWith("*")||i.startsWith("INFO:")||i.startsWith("TODO:")||i.startsWith("DOCS:")||i.startsWith("FIX:")||i.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of pn)if(i.startsWith(s))return{wrongPattern:s};for(let s of fn)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let i=e.sourceCode.getAllComments();for(let s of i)if(s.type===ie.TSESTree.AST_TOKEN_TYPES.Line||s.type===ie.TSESTree.AST_TOKEN_TYPES.Block){let p=t(s.value);p&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:p.wrongPattern}})}}}}}),Ae={name:ot,rule:mn};var fe=require("@typescript-eslint/utils"),dn=fe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),at="no-default-export",yn=dn({name:at,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.type===fe.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),ve={name:at,rule:yn};var lt=require("@typescript-eslint/utils"),gn=lt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ct="no-leaked-text-in-jsx",hn=gn({name:ct,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;[",",";","[","]"].includes(n)&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:n}})}}}}),De={name:ct,rule:hn};var G=require("@typescript-eslint/utils"),Sn=G.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),pt="no-non-camel-case-functions",En=/^[a-z][a-zA-Z0-9]*$/;function ut(e){return e.typeName.type===G.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===G.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===G.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var Tn=Sn({name:pt,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!En.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===G.AST_NODE_TYPES.TSTypeReference?ut(n):n.type===G.AST_NODE_TYPES.TSUnionType&&n.types.some(s=>s.type===G.AST_NODE_TYPES.TSTypeReference&&ut(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),$e={name:pt,rule:Tn};var F=require("@typescript-eslint/utils");function se(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:se(e.parent,t,n===1/0?n:n-1)}function*Oe(e){yield e,e.parent&&(yield*Oe(e.parent))}var bn=F.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ft="no-optional-root-props",xn=bn({name:ft,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.'},schema:[],fixable:"code"},defaultOptions:[],create(e){function t(s){return s.parent.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration}function n(s){let d=e.sourceCode.getDeclaredVariables(s)[0];if(!d||d.references.length!==1)return!1;let l=d.references[0];if(!l)return!1;for(let r of Oe(l.identifier)){if("returnType"in r||r.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let c=r.parent;if(!c)return!1;if(c.type===F.TSESTree.AST_NODE_TYPES.TSTypeParameterInstantiation&&c.parent.type===F.TSESTree.AST_NODE_TYPES.TSTypeReference&&c.parent.typeName.type===F.TSESTree.AST_NODE_TYPES.Identifier&&c.parent.typeName.name==="FC"){let m=se(c.parent.parent,F.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(m)return!(m.parent.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)}if(r.type===F.TSESTree.AST_NODE_TYPES.AssignmentPattern)return!1;if(c.type===F.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression){let a=se(c,F.TSESTree.AST_NODE_TYPES.VariableDeclaration);return a?.parent&&a.parent.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration?!1:c.params.some(m=>m===r)}if(c.type===F.TSESTree.AST_NODE_TYPES.FunctionDeclaration)return c.parent.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration?!1:c.params.some(m=>m===r)}return!1}function i(s){s.key.type!==F.TSESTree.AST_NODE_TYPES.Identifier||!s.optional||e.report({node:s.key,messageId:"optionalNotAllowed",data:{propertyName:s.key.name},fix:p=>{let d=se(s,F.TSESTree.AST_NODE_TYPES.TSPropertySignature);if(!d)return null;let l=e.sourceCode.getText(d);return p.replaceText(d,l.replace("?:",": undefined |"))}})}return{TSTypeAliasDeclaration(s){if(s.typeAnnotation.type===F.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(t(s)||!n(s)))for(let p of s.typeAnnotation.members)p.type===F.TSESTree.AST_NODE_TYPES.TSPropertySignature&&i(p)},TSInterfaceDeclaration(s){if(!(t(s)||!n(s)))for(let p of s.body.body)p.type===F.TSESTree.AST_NODE_TYPES.TSPropertySignature&&i(p)}}}}),Pe={name:ft,rule:xn};var mt=require("@typescript-eslint/utils"),me=Bt(require("path"));var In=mt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),dt="no-relative-imports",wn=M({find:L(),replacement:L()}),Rn=M({aliases:V(wn),rootDir:j(L()),allowNotFoundAliases:j(ue()),_dev_simulateFileName:j(L())}),Cn=In({name:dt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[Rn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function i(d){return d.startsWith(".")||d.startsWith("..")}function s(d,l){let r=me.default.dirname(l);return me.default.resolve(r,d)}function p(d){let l=t.rootDir??process.cwd(),r=me.default.relative(l,d);if(r.startsWith("."))return null;r.startsWith("/")||(r=`/${r}`);for(let{find:c,replacement:a}of t.aliases)if(r.startsWith(a)){let m=r.replace(a,c);return{alias:c,newPath:m}}return null}return{ImportDeclaration(d){let l=d.source.value;if(!i(l))return;let r=s(l,n),c=p(r);!c&&t.allowNotFoundAliases||e.report({node:d,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?a=>a.replaceText(d.source,`'${c.newPath}'`):void 0})}}}}),_e={name:dt,rule:Cn};var P=require("@typescript-eslint/utils");var kn=P.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function yt(e){let t=[];for(let n of e.members)n.type===P.AST_NODE_TYPES.TSPropertySignature&&n.key.type===P.AST_NODE_TYPES.Identifier&&t.push([n.key.name,n]);return t}function gt(e,...t){for(let n of t)e.set(...n);return e}var An=M({forceCheckOnFCPropTypesWithName:j(V(L()))}),ht="no-unused-type-props-in-args",Ne=null,vn=kn({name:ht,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[An],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!Ne&&(Ne=n.map(l=>new RegExp(l)));function i(l,r,c,a,m=!0){let $=c.name,v=e.sourceCode.getScope(r).references.find(R=>R.identifier.name===$)?.resolved,_=l&&Ne?.some(R=>R.test($));if(!v||!_&&v.references.filter(R=>R.isTypeReference).length>1)return;let T=v?.defs[0]?.node;if(!(m&&T?.parent?.type===P.AST_NODE_TYPES.ExportNamedDeclaration)){if(T?.type===P.AST_NODE_TYPES.TSTypeAliasDeclaration){s(l,r,a,T.typeAnnotation,!0);return}if(T?.type===P.AST_NODE_TYPES.TSInterfaceDeclaration){s(l,r,a,T.body,!0);return}}}function s(l,r,c,a,m){if(a.type===P.AST_NODE_TYPES.TSInterfaceBody){for(let $ of a.body)$.type===P.AST_NODE_TYPES.TSPropertySignature&&$.key.type===P.AST_NODE_TYPES.Identifier&&c.set($.key.name,$);return}if(a.type===P.AST_NODE_TYPES.TSTypeLiteral){gt(c,...yt(a));return}if(a.type===P.AST_NODE_TYPES.TSIntersectionType){for(let $ of a.types)s(l,r,c,$,!0);return}m||a.type===P.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===P.AST_NODE_TYPES.Identifier&&i(l,r,a.typeName,c)}function p(l,r,c){for(let a of c)if(a.type==="ObjectPattern"&&a.typeAnnotation){let m=new Map;if(s(l,r,m,a.typeAnnotation.typeAnnotation,!1),m.size===0)continue;d(a,m)}else a.type===P.AST_NODE_TYPES.AssignmentPattern&&a.left.type===P.AST_NODE_TYPES.ObjectPattern&&p(l,r,[a.left])}function d(l,r){let c=[];if(l.properties.at(-1)?.type===P.AST_NODE_TYPES.RestElement)return;for(let v of l.properties)v.type===P.AST_NODE_TYPES.Property&&v.key.type===P.AST_NODE_TYPES.Identifier&&c.push(v.key.name);let m=[],$=[];for(let[v,_]of r)c.includes(v)||($.push(v),m.push({node:_,messageId:"unusedObjectTypeProperty",data:{propertyName:v}}));for(let[v,_]of m.entries())e.report({..._,fix:v===m.length-1?T=>{let R=l.properties.at(-1),g=$.join(", ");return R?R?.type===P.AST_NODE_TYPES.RestElement?null:T.insertTextAfter(R,`, ${g}`):T.insertTextBeforeRange([l.range[0]+1,l.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(l){let r=l.declarations[0];if(!r)return;let c=new Map,a=r.id.type===P.AST_NODE_TYPES.Identifier&&r.id.typeAnnotation?.typeAnnotation.type===P.AST_NODE_TYPES.TSTypeReference&&r.id.typeAnnotation.typeAnnotation.typeName.type===P.AST_NODE_TYPES.Identifier&&r.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&r.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(a){if(a.type===P.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===P.AST_NODE_TYPES.Identifier)i(!0,l,a.typeName,c,!1);else if(a.type===P.AST_NODE_TYPES.TSTypeLiteral)gt(c,...yt(a));else if(a.type===P.AST_NODE_TYPES.TSIntersectionType)for(let m of a.types)m.type===P.AST_NODE_TYPES.TSTypeReference&&m.typeName.type===P.AST_NODE_TYPES.Identifier?i(!0,l,m.typeName,c,!1):s(!0,l,c,m,!0);if(c.size!==0&&r.init?.type===P.AST_NODE_TYPES.ArrowFunctionExpression){let m=r.init.params[0];if(!m){e.report({node:r.init,messageId:"missingComponentParam"});return}m.type===P.AST_NODE_TYPES.ObjectPattern&&d(m,c)}}},FunctionDeclaration:function(l){p(!1,l,l.params)},ArrowFunctionExpression(l){p(!1,l,l.params)}}}}),Fe={name:ht,rule:vn};var Q=require("@typescript-eslint/utils"),Dn=Q.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Et="prefer-named-functions",St=new Map,$n=Dn({name:Et,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let i=St.get(t.ignoreRegex);i?n=i:(n=new RegExp(t.ignoreRegex),St.set(t.ignoreRegex,n))}return{VariableDeclarator(i){if(i.init&&i.init.type===Q.AST_NODE_TYPES.ArrowFunctionExpression&&i.id.type===Q.AST_NODE_TYPES.Identifier){let s=i.id.name;if(i.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&i.init.body.type!==Q.AST_NODE_TYPES.BlockStatement)return;let p=i.parent,d=i.init.params,l=i.init.body,r=i.init;e.report({node:i.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(p,`${r.async?"async ":""}function ${s}(${d.map(a=>e.sourceCode.getText(a)).join(", ")||""}) ${e.sourceCode.getText(l)}`)}]})}}}}}),Le={name:Et,rule:$n};var H=require("@typescript-eslint/utils");var On=H.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Tt="prefer-single-line-if",Pn=M({maxLineLength:j(ne()),maxNonSimpleConditionLength:j(ne())}),_n=On({name:Tt,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[Pn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(i){if(i.consequent.type!==H.AST_NODE_TYPES.BlockStatement||n.getCommentsInside(i.consequent).length>0||i.alternate||i.consequent.body.length!==1)return;let p=i.consequent.body[0];if(p.type===H.AST_NODE_TYPES.ReturnStatement){if(!(!p.argument||p.argument.type===H.AST_NODE_TYPES.Literal||p.argument.type===H.AST_NODE_TYPES.Identifier))return}else if(!(p.type===H.AST_NODE_TYPES.ContinueStatement||p.type===H.AST_NODE_TYPES.BreakStatement))return;if(i.test.type===H.AST_NODE_TYPES.LogicalExpression||i.test.type===H.AST_NODE_TYPES.ConditionalExpression)return;let d;if(t.maxNonSimpleConditionLength&&(i.test.type===H.AST_NODE_TYPES.CallExpression||i.test.type===H.AST_NODE_TYPES.BinaryExpression||i.test.type===H.AST_NODE_TYPES.MemberExpression)&&(d=n.getText(i.test),d.length>t.maxNonSimpleConditionLength))return;d||(d=n.getText(i.test));let l=n.getText(p);if(d.includes(`
13
+ `))return;let r=n.getTokenAfter(i);if(r&&r.type===H.AST_TOKEN_TYPES.Punctuator&&r.value==="}")return;let c=Nn(n,i),a=`if (${d}) ${l}`;t.maxLineLength&&a.length+c.length>t.maxLineLength||e.report({node:i,messageId:"noSingleLineCurly",fix:m=>m.replaceText(i,a)})}}}});function Nn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Me={name:Tt,rule:_n};var de=require("@typescript-eslint/utils"),Fn=de.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),bt="require-description",Ln=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Mn=/^eslint-disable-(next-)?line$/u,jn=Fn({name:bt,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,i=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let p=Hn(s);p!=null&&(i.has(p.kind)||p.description||e.report({loc:Un(s.loc),messageId:"missingDescription"}))}}}}}),xt={name:bt,rule:jn};function Hn(e){let{text:t,description:n}=Wn(e.value);if(!t)return null;let i=Ln.exec(t);if(!i)return null;let s=i[1];if(!s)return null;let p=Mn.test(s);if(e.type===de.TSESTree.AST_TOKEN_TYPES.Line&&!p||p&&e.loc.start.line!==e.loc.end.line)return null;let d=t.slice(i.index+s.length);return{kind:s,value:d.trim(),description:n}}function Wn(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Un(e){return{start:{line:e.start.line,column:-1},end:e.end}}function Rt(e){return/^use[A-Z0-9]/.test(e)}function ye(e){return e.type==="Identifier"?Rt(e.name):e.type==="MemberExpression"&&!e.computed&&ye(e.property)?e.object.type==="Identifier":!1}function Ct(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function kt(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function At(e){return!!(e.parent&&e.parent.callee&&kt(e.parent.callee,"forwardRef"))}function vt(e){return!!(e.parent&&e.parent.callee&&kt(e.parent.callee,"memo"))}function je(e){for(;e;){let t=$t(e);if(t&&(Ct(t)||ye(t))||At(e)||vt(e))return!0;e=e.parent}return!1}function It(e){return!1}function He(e){return!1}var Vn=/eslint +react-compiler\/react-compiler: +\["error/,Dt={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let r of e.sourceCode.getAllComments())if(Vn.test(r.value))return{CallExpression(c){let a=null;c.callee.name==="useMemo"?a="useMemo":c.callee.name==="useCallback"&&(a="useCallback"),a&&e.report({node:c,message:`"${a}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?r=>t(r):r=>e.sourceCode.getText(r),n=typeof e.getScope=="function"?()=>n():r=>e.sourceCode.getScope(r),i=null,s=[],p=[],d=new WeakSet;function l(r){for(let c of r.references){let a=c.identifier.parent;if(a.type==="VariableDeclarator"&&a.init&&a.init.type==="CallExpression"&&a.init.callee&&It(a.init.callee))for(let m of c.resolved.references)m!==c&&d.add(m.identifier)}}return{onCodePathSegmentStart:r=>p.push(r),onCodePathSegmentEnd:()=>p.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(r,c){let a=s.pop();if(a.size===0)return;let m=new Set;function $(f,b){let{cache:x}=$,w=x.get(f.id),O=new Set(b);if(O.has(f.id)){let C=[...O],N=C.slice(C.indexOf(f.id)+1);for(let z of N)m.add(z);return BigInt("0")}if(O.add(f.id),w!==void 0)return w;if(r.thrownSegments.includes(f))w=BigInt("0");else if(f.prevSegments.length===0)w=BigInt("1");else{w=BigInt("0");for(let C of f.prevSegments)w+=$(C,O)}return f.reachable&&w===BigInt("0")?x.delete(f.id):x.set(f.id,w),w}function v(f,b){let{cache:x}=v,w=x.get(f.id),O=new Set(b);if(O.has(f.id)){let C=Array.from(O),N=C.slice(C.indexOf(f.id)+1);for(let z of N)m.add(z);return BigInt("0")}if(O.add(f.id),w!==void 0)return w;if(r.thrownSegments.includes(f))w=BigInt("0");else if(f.nextSegments.length===0)w=BigInt("1");else{w=BigInt("0");for(let C of f.nextSegments)w+=v(C,O)}return x.set(f.id,w),w}function _(f){let{cache:b}=_,x=b.get(f.id);if(x===null)return 1/0;if(x!==void 0)return x;if(b.set(f.id,null),f.prevSegments.length===0)x=1;else{x=1/0;for(let w of f.prevSegments){let O=_(w);O<x&&(x=O)}x+=1}return b.set(f.id,x),x}$.cache=new Map,v.cache=new Map,_.cache=new Map;let T=v(r.initialSegment),R=$t(c),g=je(c),D=R?Ct(R)||ye(R):At(c)||vt(c),I=1/0;for(let f of r.finalSegments){if(!f.reachable)continue;let b=_(f);b<I&&(I=b)}for(let[f,b]of a){if(!f.reachable)continue;let x=f.nextSegments.length===0?I<=_(f):I<_(f),w=$(f)*v(f),O=m.has(f.id);for(let C of b)if(O&&!He(C)&&e.report({node:C,message:`React Hook "${t(C)}" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.`}),D){if(c.async&&e.report({node:C,message:`React Hook "${t(C)}" cannot be called in an async function.`}),!O&&w!==T&&!He(C)){let z=`React Hook "${t(C)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(x?" Did you accidentally call a React Hook after an early return?":"");e.report({node:C,message:z})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let N=`React Hook "${t(C)}" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}else if(R){let N=`React Hook "${t(C)}" is called in function "${t(R)}" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".`;e.report({node:C,message:N})}else if(c.type==="Program"){let N=`React Hook "${t(C)}" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}else if(g&&!He(C)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let z=c.parent;if(z.parent.type==="VariableDeclarator"&&Rt(z.parent.id.name))return}let N=`React Hook "${t(C)}" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}}},CallExpression(r){if(ye(r.callee)){let c=wt(s),a=wt(p),m=c.get(a);m||(m=[],c.set(a,m)),m.push(r.callee)}r.callee.type==="Identifier"&&(r.callee.name==="useEffect"||It(r.callee))&&r.arguments.length>0&&(i=r)},Identifier(r){i==null&&d.has(r)&&r.parent.type!=="CallExpression"&&e.report({node:r,message:`\`${t(r)}\` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.`})},"CallExpression:exit"(r){r===i&&(i=null)},FunctionDeclaration(r){je(r)&&l(n(r))},ArrowFunctionExpression(r){je(r)&&l(n(r))}}}};function $t(e){return e.type==="FunctionDeclaration"||e.type==="FunctionExpression"&&e.id?e.id:e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"?e.parent.type==="VariableDeclarator"&&e.parent.init===e?e.parent.id:e.parent.type==="AssignmentExpression"&&e.parent.right===e&&e.parent.operator==="="?e.parent.left:e.parent.type==="Property"&&e.parent.value===e&&!e.parent.computed?e.parent.key:e.parent.type==="AssignmentPattern"&&e.parent.right===e&&!e.parent.computed?e.parent.left:void 0:void 0}function wt(e){return e[e.length-1]}var Ot={[Fe.name]:Fe.rule,[Ae.name]:Ae.rule,[ke.name]:ke.rule,"rules-of-hooks":Dt,"exhaustive-deps":et,"require-description":xt.rule,[ve.name]:ve.rule,[$e.name]:$e.rule,[Le.name]:Le.rule,[xe.name]:xe.rule,[Ce.name]:Ce.rule,[_e.name]:_e.rule,[Me.name]:Me.rule,[Pe.name]:Pe.rule,[De.name]:De.rule};var Yn={rules:Ot};0&&(module.exports={extendedLintPlugin});
@@ -1,4 +1,4 @@
1
- import{AST_NODE_TYPES as me,ESLintUtils as Dt}from"@typescript-eslint/utils";var pe=Symbol.for("optional");function L(e){return{...e,[pe]:!0}}function We(e,t){return{enum:e,...t}}function ie(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function Q(e){return{...e,type:"number"}}function Ue(e){return{...e,type:"integer"}}function W(e,t){return{...t,type:"array",items:e}}function M(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let i,u=[];for(i in e)e[i][pe]?e[i][pe]=void 0:u.push(i);u.length>0&&(n.required=u)}return n}function fe(...e){return{anyOf:e}}var Ot=Dt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Pt=M({disallow:L(W(M({selector:F(),message:F(),replace:L(fe(F(),M({regex:F(),with:F()}))),replaceType:L(We(["suggestion","autofix"]))}))),__dev_simulateFileName:L(F()),mustMatchSyntax:L(W(M({includeRegex:F(),mustCallFn:W(M({anyCall:W(M({fn:F(),withArgs:W(M({atIndex:Ue(),literal:fe(F(),Q(),ie())}))})),message:L(F())}))})))}),Ye="advanced-no-restricted-syntax",_t=Ot({name:Ye,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Pt],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:i,__dev_simulateFileName:u,disallow:p}=t,m=u??e.filename,o=[],r=new Set;for(let{includeRegex:a,mustCallFn:y}of i??[]){let D=Nt(m,new RegExp(a));if(!D)continue;let A=P=>{let b=P;for(let{name:I,value:g}of D)b=b.replaceAll(I,g);return b};for(let{anyCall:P,message:b}of y){let I=`Expected file to call the function: ${P.map(({fn:g})=>g).join(" or ")}`;r.add(I),o.push(g=>{let{callee:$}=g;if($.type===me.Identifier){for(let{fn:w,withArgs:f}of P)if($.name===w){r.delete(I);for(let T of f){let x=g.arguments[T.atIndex],R=typeof T.literal=="string"?A(T.literal):T.literal;if(!x){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${R}" at index ${T.atIndex}${b?`: ${A(b)}`:""}`}});continue}if(x.type!==me.Literal){e.report({node:x,messageId:"default",data:{message:`Argument at position ${T.atIndex} should the literal "${R}"${b?`: ${A(b)}`:""}`}});continue}x.value!==R&&e.report({node:x,messageId:"default",data:{message:`Argument should have the value "${R}"${b?`: ${A(b)}`:""}`},fix:O=>O.replaceText(x,typeof R=="string"?`'${R}'`:String(R))})}break}}})}}for(let{selector:a,message:y,replace:D,replaceType:A="suggestion"}of p??[]){if(a==="CallExpression"){o.push(P=>{c(D,P,y,A)});continue}n[a]=P=>{c(D,P,y,A)}}return o.length>0&&(n.CallExpression=a=>{if(a.type===me.CallExpression)for(let y of o)y(a)}),n["Program:exit"]=a=>{for(let y of r)e.report({node:a,messageId:"default",data:{message:`${y}`}})},n;function c(a,y,D,A){let P=b=>{if(!a)return null;if(typeof a=="string")return b.replaceText(y,a);{let I=new RegExp(a.regex),g=e.sourceCode.getText(y);return b.replaceText(y,g.replace(I,a.with))}};e.report({node:y,messageId:"default",data:{message:D},fix:a&&A==="autofix"?P:void 0,suggest:a&&A==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof a=="string"?a:a.with}"`},fix:P}]:void 0})}}});function Nt(e,t){let n=[],i=t.exec(e);if(!i)return null;let[u,...p]=i;n.push({name:"$0_lowercase",value:u.toLowerCase()}),n.push({name:"$0_capitalize",value:Ve(u)}),n.push({name:"$0_uncapitalize",value:ze(u)}),n.push({name:"$0",value:u});for(let m=0;m<p.length;m++){let o=`$${m+1}`,r=p[m];n.push({name:`${o}_lowercase`,value:r.toLowerCase()}),n.push({name:`${o}_capitalize`,value:Ve(r)}),n.push({name:`${o}_uncapitalize`,value:ze(r)}),n.push({name:o,value:r})}return n}function Ve(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ze(e){return e.charAt(0).toLowerCase()+e.slice(1)}var de={name:Ye,rule:_t};var Ft=/eslint +react-compiler\/react-compiler: +\["error/,Ge={meta:{type:"suggestion",docs:{description:"verifies the list of dependencies for Hooks like useEffect and similar",recommended:!0,url:"https://github.com/facebook/react/issues/14920"},fixable:"code",hasSuggestions:!0,schema:[{type:"object",additionalProperties:!1,ignoreIfReactCompilerIsEnabled:!1,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},ignoreIfReactCompilerIsEnabled:{type:"boolean"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let t=!1,n=typeof e.getSource=="function"?g=>n(g):g=>e.sourceCode.getText(g),i=typeof e.getScope=="function"?()=>i():g=>e.sourceCode.getScope(g),u=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,p=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,m={additionalHooks:u,enableDangerousAutofixThisMayCauseInfiniteLoops:p};function o(g){p&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let r=e.getSourceCode().scopeManager,c=new WeakMap,a=new WeakSet,y=new WeakMap,D=new WeakMap,A=new WeakSet;function P(g,$){return function(w){if($.has(w))return $.get(w);let f=g(w);return $.set(w,f),f}}function b(g,$,w,f,T){T&&g.async&&o({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
1
+ import{AST_NODE_TYPES as de,ESLintUtils as Pt}from"@typescript-eslint/utils";var fe=Symbol.for("optional");function j(e){return{...e,[fe]:!0}}function Ue(e,t){return{enum:e,...t}}function se(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function Q(e){return{...e,type:"number"}}function Ve(e){return{...e,type:"integer"}}function U(e,t){return{...t,type:"array",items:e}}function M(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let i,a=[];for(i in e)e[i][fe]?e[i][fe]=void 0:a.push(i);a.length>0&&(n.required=a)}return n}function me(...e){return{anyOf:e}}var _t=Pt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Nt=M({disallow:j(U(M({selector:F(),message:F(),replace:j(me(F(),M({regex:F(),with:F()}))),replaceType:j(Ue(["suggestion","autofix"]))}))),__dev_simulateFileName:j(F()),mustMatchSyntax:j(U(M({includeRegex:F(),mustCallFn:U(M({anyCall:U(M({fn:F(),withArgs:U(M({atIndex:Ve(),literal:me(F(),Q(),se())}))})),message:j(F())}))})))}),Be="advanced-no-restricted-syntax",Ft=_t({name:Be,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Nt],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:i,__dev_simulateFileName:a,disallow:p}=t,d=a??e.filename,l=[],r=new Set;for(let{includeRegex:o,mustCallFn:m}of i??[]){let $=Lt(d,new RegExp(o));if(!$)continue;let v=P=>{let T=P;for(let{name:R,value:g}of $)T=T.replaceAll(R,g);return T};for(let{anyCall:P,message:T}of m){let R=`Expected file to call the function: ${P.map(({fn:g})=>g).join(" or ")}`;r.add(R),l.push(g=>{let{callee:D}=g;if(D.type===de.Identifier){for(let{fn:I,withArgs:f}of P)if(D.name===I){r.delete(R);for(let b of f){let x=g.arguments[b.atIndex],w=typeof b.literal=="string"?v(b.literal):b.literal;if(!x){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${w}" at index ${b.atIndex}${T?`: ${v(T)}`:""}`}});continue}if(x.type!==de.Literal){e.report({node:x,messageId:"default",data:{message:`Argument at position ${b.atIndex} should the literal "${w}"${T?`: ${v(T)}`:""}`}});continue}x.value!==w&&e.report({node:x,messageId:"default",data:{message:`Argument should have the value "${w}"${T?`: ${v(T)}`:""}`},fix:O=>O.replaceText(x,typeof w=="string"?`'${w}'`:String(w))})}break}}})}}for(let{selector:o,message:m,replace:$,replaceType:v="suggestion"}of p??[]){if(o==="CallExpression"){l.push(P=>{c($,P,m,v)});continue}n[o]=P=>{c($,P,m,v)}}return l.length>0&&(n.CallExpression=o=>{if(o.type===de.CallExpression)for(let m of l)m(o)}),n["Program:exit"]=o=>{for(let m of r)e.report({node:o,messageId:"default",data:{message:`${m}`}})},n;function c(o,m,$,v){let P=T=>{if(!o)return null;if(typeof o=="string")return T.replaceText(m,o);{let R=new RegExp(o.regex),g=e.sourceCode.getText(m);return T.replaceText(m,g.replace(R,o.with))}};e.report({node:m,messageId:"default",data:{message:$},fix:o&&v==="autofix"?P:void 0,suggest:o&&v==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof o=="string"?o:o.with}"`},fix:P}]:void 0})}}});function Lt(e,t){let n=[],i=t.exec(e);if(!i)return null;let[a,...p]=i;n.push({name:"$0_lowercase",value:a.toLowerCase()}),n.push({name:"$0_capitalize",value:Ye(a)}),n.push({name:"$0_uncapitalize",value:ze(a)}),n.push({name:"$0",value:a});for(let d=0;d<p.length;d++){let l=`$${d+1}`,r=p[d];n.push({name:`${l}_lowercase`,value:r.toLowerCase()}),n.push({name:`${l}_capitalize`,value:Ye(r)}),n.push({name:`${l}_uncapitalize`,value:ze(r)}),n.push({name:l,value:r})}return n}function Ye(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ze(e){return e.charAt(0).toLowerCase()+e.slice(1)}var ye={name:Be,rule:Ft};var Mt=/eslint +react-compiler\/react-compiler: +\["error/,Ge={meta:{type:"suggestion",docs:{description:"verifies the list of dependencies for Hooks like useEffect and similar",recommended:!0,url:"https://github.com/facebook/react/issues/14920"},fixable:"code",hasSuggestions:!0,schema:[{type:"object",additionalProperties:!1,ignoreIfReactCompilerIsEnabled:!1,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},ignoreIfReactCompilerIsEnabled:{type:"boolean"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let t=!1,n=typeof e.getSource=="function"?g=>n(g):g=>e.sourceCode.getText(g),i=typeof e.getScope=="function"?()=>i():g=>e.sourceCode.getScope(g),a=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,p=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,d={additionalHooks:a,enableDangerousAutofixThisMayCauseInfiniteLoops:p};function l(g){p&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let r=e.getSourceCode().scopeManager,c=new WeakMap,o=new WeakSet,m=new WeakMap,$=new WeakMap,v=new WeakSet;function P(g,D){return function(I){if(D.has(I))return D.get(I);let f=g(I);return D.set(I,f),f}}function T(g,D,I,f,b){b&&g.async&&l({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
2
2
 
3
3
  useEffect(() => {
4
4
  async function fetchData() {
@@ -9,5 +9,5 @@ useEffect(() => {
9
9
  fetchData();
10
10
  }, [someId]); // Or [] if effect doesn't need props or state
11
11
 
12
- Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=r.acquire(g),R=new Set,O=null;{let s=x.upper;for(;s&&(R.add(s),s.type!=="function");)s=s.upper;if(!s)return;O=s}let C=Array.isArray;function N(s){if(!C(s.defs))return!1;let l=s.defs[0];if(l==null||l.node.type!=="VariableDeclarator")return!1;let d=l.node.init;if(d==null)return!1;for(;d.type==="TSAsExpression";)d=d.expression;let h=l.node.parent;if(h==null&&(he(O.block,l.node.id),h=l.node.parent,h==null))return!1;if(h.kind==="const"&&d.type==="Literal"&&(typeof d.value=="string"||typeof d.value=="number"||d.value===null))return!0;if(d.type!=="CallExpression")return!1;let E=d.callee;if(E.type==="MemberExpression"&&E.object.name==="React"&&E.property!=null&&!E.computed&&(E=E.property),E.type!=="Identifier")return!1;let S=l.node.id,{name:k}=E;if(k==="useRef"&&S.type==="Identifier")return!0;if(Wt(E)&&S.type==="Identifier"){for(let v of s.references)v!==S&&A.add(v.identifier);return!0}else if(k==="useState"||k==="useReducer"){if(S.type==="ArrayPattern"&&S.elements.length===2&&C(s.identifiers)){if(S.elements[1]===s.identifiers[0]){if(k==="useState"){let v=s.references,H=0;for(let Y=0;Y<v.length;Y++){if(v[Y].isWrite()&&H++,H>1)return!1;c.set(v[Y].identifier,S.elements[0])}}return!0}else if(S.elements[0]===s.identifiers[0]){if(k==="useState"){let v=s.references;for(let H=0;H<v.length;H++)a.add(v[H].identifier)}return!1}}}else if(k==="useTransition"&&S.type==="ArrayPattern"&&S.elements.length===2&&Array.isArray(s.identifiers)&&S.elements[1]===s.identifiers[0])return!0;return!1}function z(s){if(!C(s.defs))return!1;let l=s.defs[0];if(l==null||l.node==null||l.node.id==null)return!1;let d=l.node,h=O.childScopes,E=null,S;for(S=0;S<h.length;S++){let k=h[S],v=k.block;if(d.type==="FunctionDeclaration"&&v===d||d.type==="VariableDeclarator"&&v.parent===d){E=k;break}}if(E==null)return!1;for(S=0;S<E.through.length;S++){let k=E.through[S];if(k.resolved!=null&&R.has(k.resolved.scope)&&!Ne(k.resolved))return!1}return!0}let Ne=P(N,y),Rt=P(z,D),Fe=new Map;function It(s){let l=s.from,d=!1;for(;l.block!==g;)l.type==="function"&&(d=l.block.parent!=null&&l.block.parent.type==="ReturnStatement"),l=l.upper;return d}let j=new Map,ae=new Map;Me(x);function Me(s){for(let l of s.references){if(!l.resolved||!R.has(l.resolved.scope))continue;let d=he(g,l.identifier),h=qe(d),E=B(h,ae);if(T&&h.type==="Identifier"&&(h.parent.type==="MemberExpression"||h.parent.type==="OptionalMemberExpression")&&!h.parent.computed&&h.parent.property.type==="Identifier"&&h.parent.property.name==="current"&&It(l)&&Fe.set(E,{reference:l,dependencyNode:h}),h.parent.type==="TSTypeQuery"||h.parent.type==="TSTypeReference")continue;let S=l.resolved.defs[0];if(S!=null&&!(S.node!=null&&S.node.init===g.parent)&&S.type!=="TypeParameter")if(j.has(E))j.get(E).references.push(l);else{let k=l.resolved,v=Ne(k)||Rt(k);j.set(E,{isStable:v,references:[l]})}}for(let l of s.childScopes)Me(l)}Fe.forEach(({reference:s,dependencyNode:l},d)=>{let h=s.resolved.references,E=!1;for(let S=0;S<h.length;S++){let{identifier:k}=h[S],{parent:v}=k;if(v!=null&&v.type==="MemberExpression"&&!v.computed&&v.property.type==="Identifier"&&v.property.name==="current"&&v.parent.type==="AssignmentExpression"&&v.parent.left===v){E=!0;break}}E||o({node:l.parent.property,message:`The ref value '${d}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${d}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let ce=new Set;function Ct(s,l){ce.has(l)||(ce.add(l),o({node:s,message:`Assignments to the '${l}' variable from inside React Hook ${n(w)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(w)}.`}))}let te=new Set;if(j.forEach(({isStable:s,references:l},d)=>{s&&te.add(d),l.forEach(h=>{h.writeExpr&&Ct(h.writeExpr,d)})}),ce.size>0)return;if(!$){let s=null;if(j.forEach(({isStable:l,references:d},h)=>{s||d.forEach(E=>{if(s)return;let S=E.identifier;if(!c.has(S))return;let v=E.from;for(;v.type!=="function";)v=v.upper;v.block===g&&(s=h)})}),s){let{suggestedDependencies:l}=ye({dependencies:j,declaredDependencies:[],stableDependencies:te,externalDependencies:new Set,isEffect:!0});o({node:w,message:`React Hook ${f} contains a call to '${s}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+l.join(", ")+`] as a second argument to the ${f} Hook.`,suggest:[{desc:`Add dependencies array: [${l.join(", ")}]`,fix(d){return d.insertTextAfter(g,`, [${l.join(", ")}]`)}}]})}return}let J=[],Z=new Set;$.type!=="ArrayExpression"?o({node:$,message:`React Hook ${n(w)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):$.elements.forEach(s=>{if(s===null)return;if(s.type==="SpreadElement"){o({node:s,message:`React Hook ${n(w)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}A.has(s)&&o({node:s,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(s)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(s)}\``,fix(E){return E.removeRange(s.range)}}]});let l;try{l=B(s,ae)}catch(E){if(/Unsupported node type/.test(E.message)){s.type==="Literal"?j.has(s.value)?o({node:s,message:`The ${s.raw} literal is not a valid dependency because it never changes. Did you mean to include ${s.value} in the array instead?`}):o({node:s,message:`The ${s.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):o({node:s,message:`React Hook ${n(w)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw E}let d=s;for(;d.type==="MemberExpression"||d.type==="OptionalMemberExpression"||d.type==="ChainExpression";)d=d.object||d.expression.object;let h=!O.through.some(E=>E.identifier===d);J.push({key:l,node:s}),h||Z.add(l)});let{suggestedDependencies:kt,unnecessaryDependencies:ne,missingDependencies:q,duplicateDependencies:Le}=ye({dependencies:j,declaredDependencies:J,stableDependencies:te,externalDependencies:Z,isEffect:T}),re=kt;if(Le.size+q.size+ne.size===0){if(t)return;Mt({declaredDependencies:J,declaredDependenciesNode:$,componentScope:O,scope:x}).forEach(({construction:l,isUsedOutsideOfHook:d,depType:h})=>{let E=h==="function"?"useCallback":"useMemo",S=h==="function"?"definition":"initialization",k=`wrap the ${S} of '${l.name.name}' in its own ${E}() Hook.`,v=d?`To fix this, ${k}`:`Move it inside the ${f} callback. Alternatively, ${k}`,H=h==="conditional"||h==="logical expression"?"could make":"makes",Y=`The '${l.name.name}' ${h} ${H} the dependencies of ${f} Hook (at line ${$.loc.start.line}) change on every render. ${v}`,je;d&&l.type==="Variable"&&h==="function"&&(je=[{desc:`Wrap the ${S} of '${l.name.name}' in its own ${E}() Hook.`,fix(He){let[At,$t]=E==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[He.insertTextBefore(l.node.init,At),He.insertTextAfter(l.node.init,$t)]}}]),o({node:l.node,message:Y,suggest:je})});return}!T&&q.size>0&&(re=ye({dependencies:j,declaredDependencies:[],stableDependencies:te,externalDependencies:Z,isEffect:T}).suggestedDependencies);function vt(){if(J.length===0)return!0;let s=J.map(d=>d.key),l=s.slice().sort();return s.join(",")===l.join(",")}vt()&&re.sort();function le(s){let l=s.split("."),d="";for(let h=0;h<l.length;h++){if(h!==0){let E=l.slice(0,h+1).join("."),S=ae.get(E)===!0;d+=S?"?.":"."}d+=l[h]}return d}function ue(s,l,d,h){return s.size===0?null:(s.size>1?"":l+" ")+d+" "+(s.size>1?"dependencies":"dependency")+": "+jt(Array.from(s).sort().map(E=>"'"+le(E)+"'"))+`. Either ${h} ${s.size>1?"them":"it"} or remove the dependency array.`}let U="";if(ne.size>0){let s=null;if(Array.from(ne.keys()).forEach(l=>{s===null&&l.endsWith(".current")&&(s=l)}),s!==null)U=` Mutable values like '${s}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(Z.size>0){let l=Array.from(Z)[0];x.set.has(l)||(U=` Outer scope values like '${l}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!U&&q.has("props")){let s=j.get("props");if(s==null)return;let l=s.references;if(!Array.isArray(l))return;let d=!0;for(let h=0;h<l.length;h++){let E=l[h],S=he(O.block,E.identifier);if(!S){d=!1;break}let k=S.parent;if(k==null){d=!1;break}if(k.type!=="MemberExpression"&&k.type!=="OptionalMemberExpression"){d=!1;break}}d&&(U=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${f} call and refer to those specific props inside ${n(w)}.`)}if(!U&&q.size>0){let s=null;q.forEach(l=>{if(s)return;let d=O.set.get(l),h=j.get(l);if(h.references[0].resolved!==d)return;let E=d.defs[0];if(E==null||E.name==null||E.type!=="Parameter")return;let S=!1,k;for(let v=0;v<h.references.length;v++)if(k=h.references[v].identifier,k!=null&&k.parent!=null&&(k.parent.type==="CallExpression"||k.parent.type==="OptionalCallExpression")&&k.parent.callee===k){S=!0;break}S&&(s=l)}),s!==null&&(U=` If '${s}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!U&&q.size>0){let s=null;if(q.forEach(l=>{if(s!==null)return;let h=j.get(l).references,E,S;for(let k=0;k<h.length;k++){for(E=h[k].identifier,S=E.parent;S!=null&&S!==O.block;){if(S.type==="CallExpression"){let v=c.get(S.callee);if(v!=null){if(v.name===l)s={missingDep:l,setter:S.callee.name,form:"updater"};else if(a.has(E))s={missingDep:l,setter:S.callee.name,form:"reducer"};else{let H=h[k].resolved;if(H!=null){let Y=H.defs[0];Y!=null&&Y.type==="Parameter"&&(s={missingDep:l,setter:S.callee.name,form:"inlineReducer"})}}break}}S=S.parent}if(s!==null)break}}),s!==null)switch(s.form){case"reducer":U=` You can also replace multiple useState variables with useReducer if '${s.setter}' needs the current value of '${s.missingDep}'.`;break;case"inlineReducer":U=` If '${s.setter}' needs the current value of '${s.missingDep}', you can also switch to useReducer instead of useState and read '${s.missingDep}' in the reducer.`;break;case"updater":U=` You can also do a functional update '${s.setter}(${s.missingDep.slice(0,1)} => ...)' if you only need '${s.missingDep}' in the '${s.setter}' call.`;break;default:throw new Error("Unknown case.")}}o({node:$,message:`React Hook ${n(w)} has `+(ue(q,"a","missing","include")||ue(ne,"an","unnecessary","exclude")||ue(Le,"a","duplicate","omit"))+U,suggest:[{desc:`Update the dependencies array to be: [${re.map(le).join(", ")}]`,fix(s){return s.replaceText($,`[${re.map(le).join(", ")}]`)}}]})}function I(g){let $=Lt(g.callee,m);if($===-1)return;let w=g.arguments[$],f=g.callee,T=Xe(f).name,x=g.arguments[$+1],R=/Effect($|[^a-z])/g.test(T);if(!w){o({node:f,message:`React Hook ${T} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!R)){if(!x&&!R){(T==="useMemo"||T==="useCallback")&&o({node:f,message:`React Hook ${T} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(w.type){case"FunctionExpression":case"ArrowFunctionExpression":b(w,x,f,T,R);return;case"Identifier":if(!x||x.elements&&x.elements.some(N=>N&&N.type==="Identifier"&&N.name===w.name))return;let O=i(g).set.get(w.name);if(O==null||O.defs==null)return;let C=O.defs[0];if(!C||!C.node||C.type!=="Variable"&&C.type!=="FunctionName")break;switch(C.node.type){case"FunctionDeclaration":b(C.node,x,f,T,R);return;case"VariableDeclarator":let N=C.node.init;if(!N)break;switch(N.type){case"ArrowFunctionExpression":case"FunctionExpression":b(N,x,f,T,R);return}break}break;default:o({node:f,message:`React Hook ${T} received a function whose dependencies are unknown. Pass an inline function instead.`});return}o({node:f,message:`React Hook ${T} has a missing dependency: '${w.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${w.name}]`,fix(O){return O.replaceText(x,`[${w.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(Ft.test(g.value))return t=!0,{CallExpression:$=>I($,!0)}}return{CallExpression:g=>I(g)}}};function ye({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:i,isEffect:u}){let p=m();function m(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((b,I)=>{let g=o(p,I);g.isUsed=!0,r(p,I,$=>{$.isSubtreeUsed=!0})}),t.forEach(({key:b})=>{let I=o(p,b);I.isSatisfiedRecursively=!0}),n.forEach(b=>{let I=o(p,b);I.isSatisfiedRecursively=!0});function o(b,I){let g=I.split("."),$=b;for(let w of g){let f=$.children.get(w);f||(f=m(),$.children.set(w,f)),$=f}return $}function r(b,I,g){let $=I.split("."),w=b;for(let f of $){let T=w.children.get(f);if(!T)return;g(T),w=T}}let c=new Set,a=new Set;y(p,c,a,b=>b);function y(b,I,g,$){b.children.forEach((w,f)=>{let T=$(f);if(w.isSatisfiedRecursively){w.isSubtreeUsed&&g.add(T);return}if(w.isUsed){I.add(T);return}y(w,I,g,x=>T+"."+x)})}let D=[],A=new Set,P=new Set;return t.forEach(({key:b})=>{a.has(b)?D.indexOf(b)===-1?D.push(b):P.add(b):A.add(b)}),c.forEach(b=>{D.push(b)}),{suggestedDependencies:D,unnecessaryDependencies:A,duplicateDependencies:P,missingDependencies:c}}function X(e){switch(e.type){case"ObjectExpression":return"object";case"ArrayExpression":return"array";case"ArrowFunctionExpression":case"FunctionExpression":return"function";case"ClassExpression":return"class";case"ConditionalExpression":return X(e.consequent)!=null||X(e.alternate)!=null?"conditional":null;case"LogicalExpression":return X(e.left)!=null||X(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return X(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return X(e.expression);case"TSAsExpression":return X(e.expression)}return null}function Mt({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:i}){let u=e.map(({key:m})=>{let o=n.variables.find(c=>c.name===m);if(o==null)return null;let r=o.defs[0];if(r==null)return null;if(r.type==="Variable"&&r.node.type==="VariableDeclarator"&&r.node.id.type==="Identifier"&&r.node.init!=null){let c=X(r.node.init);if(c!=null)return[o,c]}return r.type==="FunctionName"&&r.node.type==="FunctionDeclaration"?[o,"function"]:r.type==="ClassName"&&r.node.type==="ClassDeclaration"?[o,"class"]:null}).filter(Boolean);function p(m){let o=!1;for(let r=0;r<m.references.length;r++){let c=m.references[r];if(c.writeExpr){if(o)return!0;o=!0;continue}let a=c.from;for(;a!==i&&a!=null;)a=a.upper;if(a!==i&&!Ke(t,c.identifier))return!0}return!1}return u.map(([m,o])=>({construction:m.defs[0],depType:o,isUsedOutsideOfHook:p(m)}))}function qe(e){return(e.parent.type==="MemberExpression"||e.parent.type==="OptionalMemberExpression")&&e.parent.object===e&&e.parent.property.name!=="current"&&!e.parent.computed&&!(e.parent.parent!=null&&(e.parent.parent.type==="CallExpression"||e.parent.parent.type==="OptionalCallExpression")&&e.parent.parent.callee===e.parent)?qe(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function ge(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function B(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let n=e.name;return t&&t.set(n,!1),n}else if(e.type==="MemberExpression"&&!e.computed){let n=B(e.object,t),i=B(e.property,null),u=`${n}.${i}`;return ge(e,t,u),u}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=B(e.object,t),i=B(e.property,null),u=`${n}.${i}`;return ge(e,t,u),u}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let i=B(n.object,t),u=B(n.property,null),p=`${i}.${u}`;return ge(n,t,p),p}else throw new Error(`Unsupported node type: ${e.type}`)}function Xe(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Lt(e,t){let n=Xe(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let i;try{i=B(n,null)}catch(u){if(/Unsupported node type/.test(u.message))return 0;throw u}return t.additionalHooks.test(i)?0:-1}else return-1}}function he(e,t){let n=[e],i=null;for(;n.length;){if(i=n.shift(),Ht(i,t))return i;if(Ke(i,t))for(let[u,p]of Object.entries(i))u!=="parent"&&(Be(p)?(p.parent=i,n.push(p)):Array.isArray(p)&&p.forEach(m=>{Be(m)&&(m.parent=i,n.push(m))}))}return null}function jt(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function Be(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ht(e,t){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===t.type&&e.name===t.name&&e.range[0]===t.range[0]&&e.range[1]===t.range[1]}function Ke(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Wt(e){return!1}import{AST_NODE_TYPES as Ut,ESLintUtils as Vt}from"@typescript-eslint/utils";var zt=Vt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Je="no-call-with-explicit-generics",Yt=M({functions:W(F())}),Bt=zt({name:Je,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[Yt]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(i){let{callee:u}=i;u.type===Ut.Identifier&&n.has(u.name)&&i.typeArguments&&e.report({node:i,messageId:"noExplicitGenerics",data:{functionName:u.name}})}}}}),Se={name:Je,rule:Bt};import{AST_NODE_TYPES as se,ESLintUtils as Gt}from"@typescript-eslint/utils";var qt=Gt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ze="no-call-with-inferred-generics",Xt=qt({name:Ze,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Map(t.functions.map(i=>[i.name,i]));return{CallExpression(i){let{callee:u}=i;if(u.type!==se.Identifier)return;let p=n.get(u.name);if(!p)return;let{minGenerics:m=1,allowAny:o,disallowTypes:r=t.disallowTypes}=p;(i.typeArguments?.params.length||0)<(m||0)&&e.report({node:i,messageId:"missingGenericDeclaration",data:{functionName:u.name,minGenerics:m||0}}),!(o&&!r)&&i.typeArguments?.params?.some(a=>!o&&a.type===se.TSAnyKeyword||r&&a.type===se.TSTypeReference&&a.typeName.type===se.Identifier&&r.includes(a.typeName.name))&&e.report({node:i,messageId:"anyUsedInGenerics",data:{functionName:u.name}})}}}}),Ee={name:Ze,rule:Xt};import{ESLintUtils as Kt,TSESTree as Qe}from"@typescript-eslint/utils";var Jt=Kt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),et="no-commented-out-code",Zt=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Qt=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],en=Jt({name:et,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create(e){function t(n){if(n.startsWith("/"))return!1;let i=n.trimStart();if(n.startsWith("*")||i.startsWith("INFO:")||i.startsWith("TODO:")||i.startsWith("DOCS:")||i.startsWith("FIX:")||i.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let u of Zt)if(i.startsWith(u))return{wrongPattern:u};for(let u of Qt)if(typeof u=="string"){if(n.includes(u))return{wrongPattern:u}}else if(u.test(n))return{wrongPattern:`regex(${u.toString()})`};return!1}return{Program(){let i=e.sourceCode.getAllComments();for(let u of i)if(u.type===Qe.AST_TOKEN_TYPES.Line||u.type===Qe.AST_TOKEN_TYPES.Block){let p=t(u.value);p&&e.report({node:u,messageId:"commentedOutCode",data:{wrongPattern:p.wrongPattern}})}}}}}),be={name:et,rule:en};import{ESLintUtils as tn,TSESTree as nn}from"@typescript-eslint/utils";var rn=tn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),tt="no-default-export",sn=rn({name:tt,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.type===nn.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Te={name:tt,rule:sn};import{AST_NODE_TYPES as K,ESLintUtils as on}from"@typescript-eslint/utils";var an=on.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),rt="no-non-camel-case-functions",cn=/^[a-z][a-zA-Z0-9]*$/;function nt(e){return e.typeName.type===K.TSQualifiedName&&e.typeName.left.type===K.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===K.Identifier&&e.typeName.right.name==="Element"}var ln=an({name:rt,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!cn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===K.TSTypeReference?nt(n):n.type===K.TSUnionType&&n.types.some(u=>u.type===K.TSTypeReference&&nt(u))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),xe={name:rt,rule:ln};import{ESLintUtils as un,TSESTree as G}from"@typescript-eslint/utils";function we(e,t){if(e.parent)return e.type===t?e:we(e.parent,t)}function*Re(e){yield e,e.parent&&(yield*Re(e.parent))}var pn=un.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),it="no-optional-root-props",fn=pn({name:it,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.'},schema:[],fixable:"code"},defaultOptions:[],create(e){function t(p){return p.parent.type===G.AST_NODE_TYPES.ExportNamedDeclaration}let n=new Set;function i(p){if(n.has(p))return!1;n.add(p);let o=e.sourceCode.getDeclaredVariables(p)[0];if(!o||o.references.length!==1)return!1;let r=o.references[0];if(!r)return!1;for(let c of Re(r.identifier)){if("returnType"in c||c.type===G.AST_NODE_TYPES.ExportNamedDeclaration)return!1;if(c.type===G.AST_NODE_TYPES.TSTypeAliasDeclaration||c.type===G.AST_NODE_TYPES.TSInterfaceDeclaration)return i(c)}return!0}function u(p){p.key.type!==G.AST_NODE_TYPES.Identifier||!p.optional||e.report({node:p.key,messageId:"optionalNotAllowed",data:{propertyName:p.key.name},fix:m=>{let o=we(p,G.AST_NODE_TYPES.TSPropertySignature);if(!o)return null;let r=e.sourceCode.getText(o);return m.replaceText(o,r.replace("?:",": undefined |"))}})}return{TSTypeAliasDeclaration(p){if(p.typeAnnotation.type===G.AST_NODE_TYPES.TSTypeLiteral&&!(t(p)||!i(p)))for(let m of p.typeAnnotation.members)m.type===G.AST_NODE_TYPES.TSPropertySignature&&u(m)},TSInterfaceDeclaration(p){if(!(t(p)||!i(p)))for(let m of p.body.body)m.type===G.AST_NODE_TYPES.TSPropertySignature&&u(m)}}}}),Ie={name:it,rule:fn};import{ESLintUtils as mn}from"@typescript-eslint/utils";import Ce from"node:path";var dn=mn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),st="no-relative-imports",yn=M({find:F(),replacement:F()}),gn=M({aliases:W(yn),rootDir:L(F()),allowNotFoundAliases:L(ie()),_dev_simulateFileName:L(F())}),hn=dn({name:st,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[gn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function i(m){return m.startsWith(".")||m.startsWith("..")}function u(m,o){let r=Ce.dirname(o);return Ce.resolve(r,m)}function p(m){let o=t.rootDir??process.cwd(),r=Ce.relative(o,m);if(r.startsWith("."))return null;r.startsWith("/")||(r=`/${r}`);for(let{find:c,replacement:a}of t.aliases)if(r.startsWith(a)){let y=r.replace(a,c);return{alias:c,newPath:y}}return null}return{ImportDeclaration(m){let o=m.source.value;if(!i(o))return;let r=u(o,n),c=p(r);!c&&t.allowNotFoundAliases||e.report({node:m,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?a=>a.replaceText(m.source,`'${c.newPath}'`):void 0})}}}}),ke={name:st,rule:hn};import{AST_NODE_TYPES as _,ESLintUtils as Sn}from"@typescript-eslint/utils";var En=Sn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function ot(e){let t=[];for(let n of e.members)n.type===_.TSPropertySignature&&n.key.type===_.Identifier&&t.push([n.key.name,n]);return t}function at(e,...t){for(let n of t)e.set(...n);return e}var bn=M({forceCheckOnFCPropTypesWithName:L(W(F()))}),ct="no-unused-type-props-in-args",ve=null,Tn=En({name:ct,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[bn],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!ve&&(ve=n.map(o=>new RegExp(o)));function i(o,r,c,a,y=!0){let D=c.name,A=e.sourceCode.getScope(r).references.find(I=>I.identifier.name===D)?.resolved,P=o&&ve?.some(I=>I.test(D));if(!A||!P&&A.references.filter(I=>I.isTypeReference).length>1)return;let b=A?.defs[0]?.node;if(!(y&&b?.parent?.type===_.ExportNamedDeclaration)){if(b?.type===_.TSTypeAliasDeclaration){u(o,r,a,b.typeAnnotation,!0);return}if(b?.type===_.TSInterfaceDeclaration){u(o,r,a,b.body,!0);return}}}function u(o,r,c,a,y){if(a.type===_.TSInterfaceBody){for(let D of a.body)D.type===_.TSPropertySignature&&D.key.type===_.Identifier&&c.set(D.key.name,D);return}if(a.type===_.TSTypeLiteral){at(c,...ot(a));return}if(a.type===_.TSIntersectionType){for(let D of a.types)u(o,r,c,D,!0);return}y||a.type===_.TSTypeReference&&a.typeName.type===_.Identifier&&i(o,r,a.typeName,c)}function p(o,r,c){for(let a of c)if(a.type==="ObjectPattern"&&a.typeAnnotation){let y=new Map;if(u(o,r,y,a.typeAnnotation.typeAnnotation,!1),y.size===0)continue;m(a,y)}else a.type===_.AssignmentPattern&&a.left.type===_.ObjectPattern&&p(o,r,[a.left])}function m(o,r){let c=[];if(o.properties.at(-1)?.type===_.RestElement)return;for(let A of o.properties)A.type===_.Property&&A.key.type===_.Identifier&&c.push(A.key.name);let y=[],D=[];for(let[A,P]of r)c.includes(A)||(D.push(A),y.push({node:P,messageId:"unusedObjectTypeProperty",data:{propertyName:A}}));for(let[A,P]of y.entries())e.report({...P,fix:A===y.length-1?b=>{let I=o.properties.at(-1),g=D.join(", ");return I?I?.type===_.RestElement?null:b.insertTextAfter(I,`, ${g}`):b.insertTextBeforeRange([o.range[0]+1,o.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(o){let r=o.declarations[0];if(!r)return;let c=new Map,a=r.id.type===_.Identifier&&r.id.typeAnnotation?.typeAnnotation.type===_.TSTypeReference&&r.id.typeAnnotation.typeAnnotation.typeName.type===_.Identifier&&r.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&r.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(a){if(a.type===_.TSTypeReference&&a.typeName.type===_.Identifier)i(!0,o,a.typeName,c,!1);else if(a.type===_.TSTypeLiteral)at(c,...ot(a));else if(a.type===_.TSIntersectionType)for(let y of a.types)y.type===_.TSTypeReference&&y.typeName.type===_.Identifier?i(!0,o,y.typeName,c,!1):u(!0,o,c,y,!0);if(c.size!==0&&r.init?.type===_.ArrowFunctionExpression){let y=r.init.params[0];if(!y){e.report({node:r.init,messageId:"missingComponentParam"});return}y.type===_.ObjectPattern&&m(y,c)}}},FunctionDeclaration:function(o){p(!1,o,o.params)},ArrowFunctionExpression(o){p(!1,o,o.params)}}}}),Ae={name:ct,rule:Tn};import{AST_NODE_TYPES as $e,ESLintUtils as xn}from"@typescript-eslint/utils";var wn=xn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ut="prefer-named-functions",lt=new Map,Rn=wn({name:ut,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let i=lt.get(t.ignoreRegex);i?n=i:(n=new RegExp(t.ignoreRegex),lt.set(t.ignoreRegex,n))}return{VariableDeclarator(i){if(i.init&&i.init.type===$e.ArrowFunctionExpression&&i.id.type===$e.Identifier){let u=i.id.name;if(i.id.typeAnnotation||n&&n.test(u)||!t.disallowArrowFnWithImplicitReturns&&i.init.body.type!==$e.BlockStatement)return;let p=i.parent,m=i.init.params,o=i.init.body,r=i.init;e.report({node:i.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:u,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(p,`${r.async?"async ":""}function ${u}(${m.map(a=>e.sourceCode.getText(a)).join(", ")||""}) ${e.sourceCode.getText(o)}`)}]})}}}}}),De={name:ut,rule:Rn};import{AST_NODE_TYPES as V,AST_TOKEN_TYPES as In,ESLintUtils as Cn}from"@typescript-eslint/utils";var kn=Cn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),pt="prefer-single-line-if",vn=M({maxLineLength:L(Q()),maxNonSimpleConditionLength:L(Q())}),An=kn({name:pt,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[vn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(i){if(i.consequent.type!==V.BlockStatement||n.getCommentsInside(i.consequent).length>0||i.alternate||i.consequent.body.length!==1)return;let p=i.consequent.body[0];if(p.type===V.ReturnStatement){if(!(!p.argument||p.argument.type===V.Literal||p.argument.type===V.Identifier))return}else if(!(p.type===V.ContinueStatement||p.type===V.BreakStatement))return;if(i.test.type===V.LogicalExpression||i.test.type===V.ConditionalExpression)return;let m;if(t.maxNonSimpleConditionLength&&(i.test.type===V.CallExpression||i.test.type===V.BinaryExpression||i.test.type===V.MemberExpression)&&(m=n.getText(i.test),m.length>t.maxNonSimpleConditionLength))return;m||(m=n.getText(i.test));let o=n.getText(p);if(m.includes(`
13
- `))return;let r=n.getTokenAfter(i);if(r&&r.type===In.Punctuator&&r.value==="}")return;let c=$n(n,i),a=`if (${m}) ${o}`;t.maxLineLength&&a.length+c.length>t.maxLineLength||e.report({node:i,messageId:"noSingleLineCurly",fix:y=>y.replaceText(i,a)})}}}});function $n(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Oe={name:pt,rule:An};import{ESLintUtils as Dn,TSESTree as On}from"@typescript-eslint/utils";var Pn=Dn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ft="require-description",_n=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Nn=/^eslint-disable-(next-)?line$/u,Fn=Pn({name:ft,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,i=new Set(t.ignore||[]);return{Program(){for(let u of n.getAllComments()){let p=Mn(u);p!=null&&(i.has(p.kind)||p.description||e.report({loc:jn(u.loc),messageId:"missingDescription"}))}}}}}),mt={name:ft,rule:Fn};function Mn(e){let{text:t,description:n}=Ln(e.value);if(!t)return null;let i=_n.exec(t);if(!i)return null;let u=i[1];if(!u)return null;let p=Nn.test(u);if(e.type===On.AST_TOKEN_TYPES.Line&&!p||p&&e.loc.start.line!==e.loc.end.line)return null;let m=t.slice(i.index+u.length);return{kind:u,value:m.trim(),description:n}}function Ln(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function jn(e){return{start:{line:e.start.line,column:-1},end:e.end}}function gt(e){return/^use[A-Z0-9]/.test(e)}function oe(e){return e.type==="Identifier"?gt(e.name):e.type==="MemberExpression"&&!e.computed&&oe(e.property)?e.object.type==="Identifier":!1}function ht(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function St(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Et(e){return!!(e.parent&&e.parent.callee&&St(e.parent.callee,"forwardRef"))}function bt(e){return!!(e.parent&&e.parent.callee&&St(e.parent.callee,"memo"))}function Pe(e){for(;e;){let t=xt(e);if(t&&(ht(t)||oe(t))||Et(e)||bt(e))return!0;e=e.parent}return!1}function dt(e){return!1}function _e(e){return!1}var Hn=/eslint +react-compiler\/react-compiler: +\["error/,Tt={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let r of e.sourceCode.getAllComments())if(Hn.test(r.value))return{CallExpression(c){let a=null;c.callee.name==="useMemo"?a="useMemo":c.callee.name==="useCallback"&&(a="useCallback"),a&&e.report({node:c,message:`"${a}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?r=>t(r):r=>e.sourceCode.getText(r),n=typeof e.getScope=="function"?()=>n():r=>e.sourceCode.getScope(r),i=null,u=[],p=[],m=new WeakSet;function o(r){for(let c of r.references){let a=c.identifier.parent;if(a.type==="VariableDeclarator"&&a.init&&a.init.type==="CallExpression"&&a.init.callee&&dt(a.init.callee))for(let y of c.resolved.references)y!==c&&m.add(y.identifier)}}return{onCodePathSegmentStart:r=>p.push(r),onCodePathSegmentEnd:()=>p.pop(),onCodePathStart:()=>u.push(new Map),onCodePathEnd(r,c){let a=u.pop();if(a.size===0)return;let y=new Set;function D(f,T){let{cache:x}=D,R=x.get(f.id),O=new Set(T);if(O.has(f.id)){let C=[...O],N=C.slice(C.indexOf(f.id)+1);for(let z of N)y.add(z);return BigInt("0")}if(O.add(f.id),R!==void 0)return R;if(r.thrownSegments.includes(f))R=BigInt("0");else if(f.prevSegments.length===0)R=BigInt("1");else{R=BigInt("0");for(let C of f.prevSegments)R+=D(C,O)}return f.reachable&&R===BigInt("0")?x.delete(f.id):x.set(f.id,R),R}function A(f,T){let{cache:x}=A,R=x.get(f.id),O=new Set(T);if(O.has(f.id)){let C=Array.from(O),N=C.slice(C.indexOf(f.id)+1);for(let z of N)y.add(z);return BigInt("0")}if(O.add(f.id),R!==void 0)return R;if(r.thrownSegments.includes(f))R=BigInt("0");else if(f.nextSegments.length===0)R=BigInt("1");else{R=BigInt("0");for(let C of f.nextSegments)R+=A(C,O)}return x.set(f.id,R),R}function P(f){let{cache:T}=P,x=T.get(f.id);if(x===null)return 1/0;if(x!==void 0)return x;if(T.set(f.id,null),f.prevSegments.length===0)x=1;else{x=1/0;for(let R of f.prevSegments){let O=P(R);O<x&&(x=O)}x+=1}return T.set(f.id,x),x}D.cache=new Map,A.cache=new Map,P.cache=new Map;let b=A(r.initialSegment),I=xt(c),g=Pe(c),$=I?ht(I)||oe(I):Et(c)||bt(c),w=1/0;for(let f of r.finalSegments){if(!f.reachable)continue;let T=P(f);T<w&&(w=T)}for(let[f,T]of a){if(!f.reachable)continue;let x=f.nextSegments.length===0?w<=P(f):w<P(f),R=D(f)*A(f),O=y.has(f.id);for(let C of T)if(O&&!_e(C)&&e.report({node:C,message:`React Hook "${t(C)}" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.`}),$){if(c.async&&e.report({node:C,message:`React Hook "${t(C)}" cannot be called in an async function.`}),!O&&R!==b&&!_e(C)){let z=`React Hook "${t(C)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(x?" Did you accidentally call a React Hook after an early return?":"");e.report({node:C,message:z})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let N=`React Hook "${t(C)}" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}else if(I){let N=`React Hook "${t(C)}" is called in function "${t(I)}" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".`;e.report({node:C,message:N})}else if(c.type==="Program"){let N=`React Hook "${t(C)}" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}else if(g&&!_e(C)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let z=c.parent;if(z.parent.type==="VariableDeclarator"&&gt(z.parent.id.name))return}let N=`React Hook "${t(C)}" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}}},CallExpression(r){if(oe(r.callee)){let c=yt(u),a=yt(p),y=c.get(a);y||(y=[],c.set(a,y)),y.push(r.callee)}r.callee.type==="Identifier"&&(r.callee.name==="useEffect"||dt(r.callee))&&r.arguments.length>0&&(i=r)},Identifier(r){i==null&&m.has(r)&&r.parent.type!=="CallExpression"&&e.report({node:r,message:`\`${t(r)}\` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.`})},"CallExpression:exit"(r){r===i&&(i=null)},FunctionDeclaration(r){Pe(r)&&o(n(r))},ArrowFunctionExpression(r){Pe(r)&&o(n(r))}}}};function xt(e){return e.type==="FunctionDeclaration"||e.type==="FunctionExpression"&&e.id?e.id:e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"?e.parent.type==="VariableDeclarator"&&e.parent.init===e?e.parent.id:e.parent.type==="AssignmentExpression"&&e.parent.right===e&&e.parent.operator==="="?e.parent.left:e.parent.type==="Property"&&e.parent.value===e&&!e.parent.computed?e.parent.key:e.parent.type==="AssignmentPattern"&&e.parent.right===e&&!e.parent.computed?e.parent.left:void 0:void 0}function yt(e){return e[e.length-1]}var wt={[Ae.name]:Ae.rule,[be.name]:be.rule,[Ee.name]:Ee.rule,"rules-of-hooks":Tt,"exhaustive-deps":Ge,"require-description":mt.rule,[Te.name]:Te.rule,[xe.name]:xe.rule,[De.name]:De.rule,[de.name]:de.rule,[Se.name]:Se.rule,[ke.name]:ke.rule,[Oe.name]:Oe.rule,[Ie.name]:Ie.rule};var jr={rules:wt};export{jr as extendedLintPlugin};
12
+ Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=r.acquire(g),w=new Set,O=null;{let s=x.upper;for(;s&&(w.add(s),s.type!=="function");)s=s.upper;if(!s)return;O=s}let C=Array.isArray;function N(s){if(!C(s.defs))return!1;let u=s.defs[0];if(u==null||u.node.type!=="VariableDeclarator")return!1;let y=u.node.init;if(y==null)return!1;for(;y.type==="TSAsExpression";)y=y.expression;let h=u.node.parent;if(h==null&&(Se(O.block,u.node.id),h=u.node.parent,h==null))return!1;if(h.kind==="const"&&y.type==="Literal"&&(typeof y.value=="string"||typeof y.value=="number"||y.value===null))return!0;if(y.type!=="CallExpression")return!1;let E=y.callee;if(E.type==="MemberExpression"&&E.object.name==="React"&&E.property!=null&&!E.computed&&(E=E.property),E.type!=="Identifier")return!1;let S=u.node.id,{name:k}=E;if(k==="useRef"&&S.type==="Identifier")return!0;if(Vt(E)&&S.type==="Identifier"){for(let A of s.references)A!==S&&v.add(A.identifier);return!0}else if(k==="useState"||k==="useReducer"){if(S.type==="ArrayPattern"&&S.elements.length===2&&C(s.identifiers)){if(S.elements[1]===s.identifiers[0]){if(k==="useState"){let A=s.references,W=0;for(let B=0;B<A.length;B++){if(A[B].isWrite()&&W++,W>1)return!1;c.set(A[B].identifier,S.elements[0])}}return!0}else if(S.elements[0]===s.identifiers[0]){if(k==="useState"){let A=s.references;for(let W=0;W<A.length;W++)o.add(A[W].identifier)}return!1}}}else if(k==="useTransition"&&S.type==="ArrayPattern"&&S.elements.length===2&&Array.isArray(s.identifiers)&&S.elements[1]===s.identifiers[0])return!0;return!1}function z(s){if(!C(s.defs))return!1;let u=s.defs[0];if(u==null||u.node==null||u.node.id==null)return!1;let y=u.node,h=O.childScopes,E=null,S;for(S=0;S<h.length;S++){let k=h[S],A=k.block;if(y.type==="FunctionDeclaration"&&A===y||y.type==="VariableDeclarator"&&A.parent===y){E=k;break}}if(E==null)return!1;for(S=0;S<E.through.length;S++){let k=E.through[S];if(k.resolved!=null&&w.has(k.resolved.scope)&&!Fe(k.resolved))return!1}return!0}let Fe=P(N,m),Ct=P(z,$),Le=new Map;function kt(s){let u=s.from,y=!1;for(;u.block!==g;)u.type==="function"&&(y=u.block.parent!=null&&u.block.parent.type==="ReturnStatement"),u=u.upper;return y}let H=new Map,le=new Map;Me(x);function Me(s){for(let u of s.references){if(!u.resolved||!w.has(u.resolved.scope))continue;let y=Se(g,u.identifier),h=Je(y),E=X(h,le);if(b&&h.type==="Identifier"&&(h.parent.type==="MemberExpression"||h.parent.type==="OptionalMemberExpression")&&!h.parent.computed&&h.parent.property.type==="Identifier"&&h.parent.property.name==="current"&&kt(u)&&Le.set(E,{reference:u,dependencyNode:h}),h.parent.type==="TSTypeQuery"||h.parent.type==="TSTypeReference")continue;let S=u.resolved.defs[0];if(S!=null&&!(S.node!=null&&S.node.init===g.parent)&&S.type!=="TypeParameter")if(H.has(E))H.get(E).references.push(u);else{let k=u.resolved,A=Fe(k)||Ct(k);H.set(E,{isStable:A,references:[u]})}}for(let u of s.childScopes)Me(u)}Le.forEach(({reference:s,dependencyNode:u},y)=>{let h=s.resolved.references,E=!1;for(let S=0;S<h.length;S++){let{identifier:k}=h[S],{parent:A}=k;if(A!=null&&A.type==="MemberExpression"&&!A.computed&&A.property.type==="Identifier"&&A.property.name==="current"&&A.parent.type==="AssignmentExpression"&&A.parent.left===A){E=!0;break}}E||l({node:u.parent.property,message:`The ref value '${y}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${y}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let ce=new Set;function At(s,u){ce.has(u)||(ce.add(u),l({node:s,message:`Assignments to the '${u}' variable from inside React Hook ${n(I)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(I)}.`}))}let ne=new Set;if(H.forEach(({isStable:s,references:u},y)=>{s&&ne.add(y),u.forEach(h=>{h.writeExpr&&At(h.writeExpr,y)})}),ce.size>0)return;if(!D){let s=null;if(H.forEach(({isStable:u,references:y},h)=>{s||y.forEach(E=>{if(s)return;let S=E.identifier;if(!c.has(S))return;let A=E.from;for(;A.type!=="function";)A=A.upper;A.block===g&&(s=h)})}),s){let{suggestedDependencies:u}=ge({dependencies:H,declaredDependencies:[],stableDependencies:ne,externalDependencies:new Set,isEffect:!0});l({node:I,message:`React Hook ${f} contains a call to '${s}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+u.join(", ")+`] as a second argument to the ${f} Hook.`,suggest:[{desc:`Add dependencies array: [${u.join(", ")}]`,fix(y){return y.insertTextAfter(g,`, [${u.join(", ")}]`)}}]})}return}let K=[],Z=new Set;D.type!=="ArrayExpression"?l({node:D,message:`React Hook ${n(I)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(s=>{if(s===null)return;if(s.type==="SpreadElement"){l({node:s,message:`React Hook ${n(I)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}v.has(s)&&l({node:s,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(s)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(s)}\``,fix(E){return E.removeRange(s.range)}}]});let u;try{u=X(s,le)}catch(E){if(/Unsupported node type/.test(E.message)){s.type==="Literal"?H.has(s.value)?l({node:s,message:`The ${s.raw} literal is not a valid dependency because it never changes. Did you mean to include ${s.value} in the array instead?`}):l({node:s,message:`The ${s.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:s,message:`React Hook ${n(I)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw E}let y=s;for(;y.type==="MemberExpression"||y.type==="OptionalMemberExpression"||y.type==="ChainExpression";)y=y.object||y.expression.object;let h=!O.through.some(E=>E.identifier===y);K.push({key:u,node:s}),h||Z.add(u)});let{suggestedDependencies:vt,unnecessaryDependencies:re,missingDependencies:G,duplicateDependencies:je}=ge({dependencies:H,declaredDependencies:K,stableDependencies:ne,externalDependencies:Z,isEffect:b}),ie=vt;if(je.size+G.size+re.size===0){if(t)return;jt({declaredDependencies:K,declaredDependenciesNode:D,componentScope:O,scope:x}).forEach(({construction:u,isUsedOutsideOfHook:y,depType:h})=>{let E=h==="function"?"useCallback":"useMemo",S=h==="function"?"definition":"initialization",k=`wrap the ${S} of '${u.name.name}' in its own ${E}() Hook.`,A=y?`To fix this, ${k}`:`Move it inside the ${f} callback. Alternatively, ${k}`,W=h==="conditional"||h==="logical expression"?"could make":"makes",B=`The '${u.name.name}' ${h} ${W} the dependencies of ${f} Hook (at line ${D.loc.start.line}) change on every render. ${A}`,He;y&&u.type==="Variable"&&h==="function"&&(He=[{desc:`Wrap the ${S} of '${u.name.name}' in its own ${E}() Hook.`,fix(We){let[$t,Ot]=E==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[We.insertTextBefore(u.node.init,$t),We.insertTextAfter(u.node.init,Ot)]}}]),l({node:u.node,message:B,suggest:He})});return}!b&&G.size>0&&(ie=ge({dependencies:H,declaredDependencies:[],stableDependencies:ne,externalDependencies:Z,isEffect:b}).suggestedDependencies);function Dt(){if(K.length===0)return!0;let s=K.map(y=>y.key),u=s.slice().sort();return s.join(",")===u.join(",")}Dt()&&ie.sort();function ue(s){let u=s.split("."),y="";for(let h=0;h<u.length;h++){if(h!==0){let E=u.slice(0,h+1).join("."),S=le.get(E)===!0;y+=S?"?.":"."}y+=u[h]}return y}function pe(s,u,y,h){return s.size===0?null:(s.size>1?"":u+" ")+y+" "+(s.size>1?"dependencies":"dependency")+": "+Wt(Array.from(s).sort().map(E=>"'"+ue(E)+"'"))+`. Either ${h} ${s.size>1?"them":"it"} or remove the dependency array.`}let V="";if(re.size>0){let s=null;if(Array.from(re.keys()).forEach(u=>{s===null&&u.endsWith(".current")&&(s=u)}),s!==null)V=` Mutable values like '${s}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(Z.size>0){let u=Array.from(Z)[0];x.set.has(u)||(V=` Outer scope values like '${u}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!V&&G.has("props")){let s=H.get("props");if(s==null)return;let u=s.references;if(!Array.isArray(u))return;let y=!0;for(let h=0;h<u.length;h++){let E=u[h],S=Se(O.block,E.identifier);if(!S){y=!1;break}let k=S.parent;if(k==null){y=!1;break}if(k.type!=="MemberExpression"&&k.type!=="OptionalMemberExpression"){y=!1;break}}y&&(V=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${f} call and refer to those specific props inside ${n(I)}.`)}if(!V&&G.size>0){let s=null;G.forEach(u=>{if(s)return;let y=O.set.get(u),h=H.get(u);if(h.references[0].resolved!==y)return;let E=y.defs[0];if(E==null||E.name==null||E.type!=="Parameter")return;let S=!1,k;for(let A=0;A<h.references.length;A++)if(k=h.references[A].identifier,k!=null&&k.parent!=null&&(k.parent.type==="CallExpression"||k.parent.type==="OptionalCallExpression")&&k.parent.callee===k){S=!0;break}S&&(s=u)}),s!==null&&(V=` If '${s}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!V&&G.size>0){let s=null;if(G.forEach(u=>{if(s!==null)return;let h=H.get(u).references,E,S;for(let k=0;k<h.length;k++){for(E=h[k].identifier,S=E.parent;S!=null&&S!==O.block;){if(S.type==="CallExpression"){let A=c.get(S.callee);if(A!=null){if(A.name===u)s={missingDep:u,setter:S.callee.name,form:"updater"};else if(o.has(E))s={missingDep:u,setter:S.callee.name,form:"reducer"};else{let W=h[k].resolved;if(W!=null){let B=W.defs[0];B!=null&&B.type==="Parameter"&&(s={missingDep:u,setter:S.callee.name,form:"inlineReducer"})}}break}}S=S.parent}if(s!==null)break}}),s!==null)switch(s.form){case"reducer":V=` You can also replace multiple useState variables with useReducer if '${s.setter}' needs the current value of '${s.missingDep}'.`;break;case"inlineReducer":V=` If '${s.setter}' needs the current value of '${s.missingDep}', you can also switch to useReducer instead of useState and read '${s.missingDep}' in the reducer.`;break;case"updater":V=` You can also do a functional update '${s.setter}(${s.missingDep.slice(0,1)} => ...)' if you only need '${s.missingDep}' in the '${s.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:D,message:`React Hook ${n(I)} has `+(pe(G,"a","missing","include")||pe(re,"an","unnecessary","exclude")||pe(je,"a","duplicate","omit"))+V,suggest:[{desc:`Update the dependencies array to be: [${ie.map(ue).join(", ")}]`,fix(s){return s.replaceText(D,`[${ie.map(ue).join(", ")}]`)}}]})}function R(g){let D=Ht(g.callee,d);if(D===-1)return;let I=g.arguments[D],f=g.callee,b=qe(f).name,x=g.arguments[D+1],w=/Effect($|[^a-z])/g.test(b);if(!I){l({node:f,message:`React Hook ${b} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!w)){if(!x&&!w){(b==="useMemo"||b==="useCallback")&&l({node:f,message:`React Hook ${b} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(I.type){case"FunctionExpression":case"ArrowFunctionExpression":T(I,x,f,b,w);return;case"Identifier":if(!x||x.elements&&x.elements.some(N=>N&&N.type==="Identifier"&&N.name===I.name))return;let O=i(g).set.get(I.name);if(O==null||O.defs==null)return;let C=O.defs[0];if(!C||!C.node||C.type!=="Variable"&&C.type!=="FunctionName")break;switch(C.node.type){case"FunctionDeclaration":T(C.node,x,f,b,w);return;case"VariableDeclarator":let N=C.node.init;if(!N)break;switch(N.type){case"ArrowFunctionExpression":case"FunctionExpression":T(N,x,f,b,w);return}break}break;default:l({node:f,message:`React Hook ${b} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:f,message:`React Hook ${b} has a missing dependency: '${I.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${I.name}]`,fix(O){return O.replaceText(x,`[${I.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(Mt.test(g.value))return t=!0,{CallExpression:D=>R(D,!0)}}return{CallExpression:g=>R(g)}}};function ge({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:i,isEffect:a}){let p=d();function d(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,R)=>{let g=l(p,R);g.isUsed=!0,r(p,R,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let R=l(p,T);R.isSatisfiedRecursively=!0}),n.forEach(T=>{let R=l(p,T);R.isSatisfiedRecursively=!0});function l(T,R){let g=R.split("."),D=T;for(let I of g){let f=D.children.get(I);f||(f=d(),D.children.set(I,f)),D=f}return D}function r(T,R,g){let D=R.split("."),I=T;for(let f of D){let b=I.children.get(f);if(!b)return;g(b),I=b}}let c=new Set,o=new Set;m(p,c,o,T=>T);function m(T,R,g,D){T.children.forEach((I,f)=>{let b=D(f);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&g.add(b);return}if(I.isUsed){R.add(b);return}m(I,R,g,x=>b+"."+x)})}let $=[],v=new Set,P=new Set;return t.forEach(({key:T})=>{o.has(T)?$.indexOf(T)===-1?$.push(T):P.add(T):v.add(T)}),c.forEach(T=>{$.push(T)}),{suggestedDependencies:$,unnecessaryDependencies:v,duplicateDependencies:P,missingDependencies:c}}function J(e){switch(e.type){case"ObjectExpression":return"object";case"ArrayExpression":return"array";case"ArrowFunctionExpression":case"FunctionExpression":return"function";case"ClassExpression":return"class";case"ConditionalExpression":return J(e.consequent)!=null||J(e.alternate)!=null?"conditional":null;case"LogicalExpression":return J(e.left)!=null||J(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return J(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return J(e.expression);case"TSAsExpression":return J(e.expression)}return null}function jt({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:i}){let a=e.map(({key:d})=>{let l=n.variables.find(c=>c.name===d);if(l==null)return null;let r=l.defs[0];if(r==null)return null;if(r.type==="Variable"&&r.node.type==="VariableDeclarator"&&r.node.id.type==="Identifier"&&r.node.init!=null){let c=J(r.node.init);if(c!=null)return[l,c]}return r.type==="FunctionName"&&r.node.type==="FunctionDeclaration"?[l,"function"]:r.type==="ClassName"&&r.node.type==="ClassDeclaration"?[l,"class"]:null}).filter(Boolean);function p(d){let l=!1;for(let r=0;r<d.references.length;r++){let c=d.references[r];if(c.writeExpr){if(l)return!0;l=!0;continue}let o=c.from;for(;o!==i&&o!=null;)o=o.upper;if(o!==i&&!Ke(t,c.identifier))return!0}return!1}return a.map(([d,l])=>({construction:d.defs[0],depType:l,isUsedOutsideOfHook:p(d)}))}function Je(e){return(e.parent.type==="MemberExpression"||e.parent.type==="OptionalMemberExpression")&&e.parent.object===e&&e.parent.property.name!=="current"&&!e.parent.computed&&!(e.parent.parent!=null&&(e.parent.parent.type==="CallExpression"||e.parent.parent.type==="OptionalCallExpression")&&e.parent.parent.callee===e.parent)?Je(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function he(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function X(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let n=e.name;return t&&t.set(n,!1),n}else if(e.type==="MemberExpression"&&!e.computed){let n=X(e.object,t),i=X(e.property,null),a=`${n}.${i}`;return he(e,t,a),a}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=X(e.object,t),i=X(e.property,null),a=`${n}.${i}`;return he(e,t,a),a}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let i=X(n.object,t),a=X(n.property,null),p=`${i}.${a}`;return he(n,t,p),p}else throw new Error(`Unsupported node type: ${e.type}`)}function qe(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Ht(e,t){let n=qe(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let i;try{i=X(n,null)}catch(a){if(/Unsupported node type/.test(a.message))return 0;throw a}return t.additionalHooks.test(i)?0:-1}else return-1}}function Se(e,t){let n=[e],i=null;for(;n.length;){if(i=n.shift(),Ut(i,t))return i;if(Ke(i,t))for(let[a,p]of Object.entries(i))a!=="parent"&&(Xe(p)?(p.parent=i,n.push(p)):Array.isArray(p)&&p.forEach(d=>{Xe(d)&&(d.parent=i,n.push(d))}))}return null}function Wt(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function Xe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ut(e,t){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===t.type&&e.name===t.name&&e.range[0]===t.range[0]&&e.range[1]===t.range[1]}function Ke(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Vt(e){return!1}import{AST_NODE_TYPES as Yt,ESLintUtils as zt}from"@typescript-eslint/utils";var Bt=zt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ze="no-call-with-explicit-generics",Xt=M({functions:U(F())}),Gt=Bt({name:Ze,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[Xt]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(i){let{callee:a}=i;a.type===Yt.Identifier&&n.has(a.name)&&i.typeArguments&&e.report({node:i,messageId:"noExplicitGenerics",data:{functionName:a.name}})}}}}),Ee={name:Ze,rule:Gt};import{AST_NODE_TYPES as oe,ESLintUtils as Jt}from"@typescript-eslint/utils";var qt=Jt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qe="no-call-with-inferred-generics",Kt=qt({name:Qe,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Map(t.functions.map(i=>[i.name,i]));return{CallExpression(i){let{callee:a}=i;if(a.type!==oe.Identifier)return;let p=n.get(a.name);if(!p)return;let{minGenerics:d=1,allowAny:l,disallowTypes:r=t.disallowTypes}=p;(i.typeArguments?.params.length||0)<(d||0)&&e.report({node:i,messageId:"missingGenericDeclaration",data:{functionName:a.name,minGenerics:d||0}}),!(l&&!r)&&i.typeArguments?.params?.some(o=>!l&&o.type===oe.TSAnyKeyword||r&&o.type===oe.TSTypeReference&&o.typeName.type===oe.Identifier&&r.includes(o.typeName.name))&&e.report({node:i,messageId:"anyUsedInGenerics",data:{functionName:a.name}})}}}}),Te={name:Qe,rule:Kt};import{ESLintUtils as Zt,TSESTree as et}from"@typescript-eslint/utils";var Qt=Zt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),tt="no-commented-out-code",en=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],tn=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],nn=Qt({name:tt,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create(e){function t(n){if(n.startsWith("/"))return!1;let i=n.trimStart();if(n.startsWith("*")||i.startsWith("INFO:")||i.startsWith("TODO:")||i.startsWith("DOCS:")||i.startsWith("FIX:")||i.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let a of en)if(i.startsWith(a))return{wrongPattern:a};for(let a of tn)if(typeof a=="string"){if(n.includes(a))return{wrongPattern:a}}else if(a.test(n))return{wrongPattern:`regex(${a.toString()})`};return!1}return{Program(){let i=e.sourceCode.getAllComments();for(let a of i)if(a.type===et.AST_TOKEN_TYPES.Line||a.type===et.AST_TOKEN_TYPES.Block){let p=t(a.value);p&&e.report({node:a,messageId:"commentedOutCode",data:{wrongPattern:p.wrongPattern}})}}}}}),be={name:tt,rule:nn};import{ESLintUtils as rn,TSESTree as sn}from"@typescript-eslint/utils";var on=rn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),nt="no-default-export",an=on({name:nt,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.type===sn.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),xe={name:nt,rule:an};import{ESLintUtils as ln}from"@typescript-eslint/utils";var cn=ln.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),rt="no-leaked-text-in-jsx",un=cn({name:rt,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;[",",";","[","]"].includes(n)&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:n}})}}}}),Ie={name:rt,rule:un};import{AST_NODE_TYPES as q,ESLintUtils as pn}from"@typescript-eslint/utils";var fn=pn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),st="no-non-camel-case-functions",mn=/^[a-z][a-zA-Z0-9]*$/;function it(e){return e.typeName.type===q.TSQualifiedName&&e.typeName.left.type===q.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===q.Identifier&&e.typeName.right.name==="Element"}var dn=fn({name:st,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!mn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===q.TSTypeReference?it(n):n.type===q.TSUnionType&&n.types.some(a=>a.type===q.TSTypeReference&&it(a))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),we={name:st,rule:dn};import{ESLintUtils as yn,TSESTree as L}from"@typescript-eslint/utils";function te(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:te(e.parent,t,n===1/0?n:n-1)}function*Re(e){yield e,e.parent&&(yield*Re(e.parent))}var gn=yn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ot="no-optional-root-props",hn=gn({name:ot,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.'},schema:[],fixable:"code"},defaultOptions:[],create(e){function t(a){return a.parent.type===L.AST_NODE_TYPES.ExportNamedDeclaration}function n(a){let d=e.sourceCode.getDeclaredVariables(a)[0];if(!d||d.references.length!==1)return!1;let l=d.references[0];if(!l)return!1;for(let r of Re(l.identifier)){if("returnType"in r||r.type===L.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let c=r.parent;if(!c)return!1;if(c.type===L.AST_NODE_TYPES.TSTypeParameterInstantiation&&c.parent.type===L.AST_NODE_TYPES.TSTypeReference&&c.parent.typeName.type===L.AST_NODE_TYPES.Identifier&&c.parent.typeName.name==="FC"){let m=te(c.parent.parent,L.AST_NODE_TYPES.VariableDeclaration,4);if(m)return!(m.parent.type===L.AST_NODE_TYPES.ExportNamedDeclaration)}if(r.type===L.AST_NODE_TYPES.AssignmentPattern)return!1;if(c.type===L.AST_NODE_TYPES.ArrowFunctionExpression){let o=te(c,L.AST_NODE_TYPES.VariableDeclaration);return o?.parent&&o.parent.type===L.AST_NODE_TYPES.ExportNamedDeclaration?!1:c.params.some(m=>m===r)}if(c.type===L.AST_NODE_TYPES.FunctionDeclaration)return c.parent.type===L.AST_NODE_TYPES.ExportNamedDeclaration?!1:c.params.some(m=>m===r)}return!1}function i(a){a.key.type!==L.AST_NODE_TYPES.Identifier||!a.optional||e.report({node:a.key,messageId:"optionalNotAllowed",data:{propertyName:a.key.name},fix:p=>{let d=te(a,L.AST_NODE_TYPES.TSPropertySignature);if(!d)return null;let l=e.sourceCode.getText(d);return p.replaceText(d,l.replace("?:",": undefined |"))}})}return{TSTypeAliasDeclaration(a){if(a.typeAnnotation.type===L.AST_NODE_TYPES.TSTypeLiteral&&!(t(a)||!n(a)))for(let p of a.typeAnnotation.members)p.type===L.AST_NODE_TYPES.TSPropertySignature&&i(p)},TSInterfaceDeclaration(a){if(!(t(a)||!n(a)))for(let p of a.body.body)p.type===L.AST_NODE_TYPES.TSPropertySignature&&i(p)}}}}),Ce={name:ot,rule:hn};import{ESLintUtils as Sn}from"@typescript-eslint/utils";import ke from"node:path";var En=Sn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),at="no-relative-imports",Tn=M({find:F(),replacement:F()}),bn=M({aliases:U(Tn),rootDir:j(F()),allowNotFoundAliases:j(se()),_dev_simulateFileName:j(F())}),xn=En({name:at,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[bn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function i(d){return d.startsWith(".")||d.startsWith("..")}function a(d,l){let r=ke.dirname(l);return ke.resolve(r,d)}function p(d){let l=t.rootDir??process.cwd(),r=ke.relative(l,d);if(r.startsWith("."))return null;r.startsWith("/")||(r=`/${r}`);for(let{find:c,replacement:o}of t.aliases)if(r.startsWith(o)){let m=r.replace(o,c);return{alias:c,newPath:m}}return null}return{ImportDeclaration(d){let l=d.source.value;if(!i(l))return;let r=a(l,n),c=p(r);!c&&t.allowNotFoundAliases||e.report({node:d,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?o=>o.replaceText(d.source,`'${c.newPath}'`):void 0})}}}}),Ae={name:at,rule:xn};import{AST_NODE_TYPES as _,ESLintUtils as In}from"@typescript-eslint/utils";var wn=In.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function lt(e){let t=[];for(let n of e.members)n.type===_.TSPropertySignature&&n.key.type===_.Identifier&&t.push([n.key.name,n]);return t}function ct(e,...t){for(let n of t)e.set(...n);return e}var Rn=M({forceCheckOnFCPropTypesWithName:j(U(F()))}),ut="no-unused-type-props-in-args",ve=null,Cn=wn({name:ut,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Rn],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!ve&&(ve=n.map(l=>new RegExp(l)));function i(l,r,c,o,m=!0){let $=c.name,v=e.sourceCode.getScope(r).references.find(R=>R.identifier.name===$)?.resolved,P=l&&ve?.some(R=>R.test($));if(!v||!P&&v.references.filter(R=>R.isTypeReference).length>1)return;let T=v?.defs[0]?.node;if(!(m&&T?.parent?.type===_.ExportNamedDeclaration)){if(T?.type===_.TSTypeAliasDeclaration){a(l,r,o,T.typeAnnotation,!0);return}if(T?.type===_.TSInterfaceDeclaration){a(l,r,o,T.body,!0);return}}}function a(l,r,c,o,m){if(o.type===_.TSInterfaceBody){for(let $ of o.body)$.type===_.TSPropertySignature&&$.key.type===_.Identifier&&c.set($.key.name,$);return}if(o.type===_.TSTypeLiteral){ct(c,...lt(o));return}if(o.type===_.TSIntersectionType){for(let $ of o.types)a(l,r,c,$,!0);return}m||o.type===_.TSTypeReference&&o.typeName.type===_.Identifier&&i(l,r,o.typeName,c)}function p(l,r,c){for(let o of c)if(o.type==="ObjectPattern"&&o.typeAnnotation){let m=new Map;if(a(l,r,m,o.typeAnnotation.typeAnnotation,!1),m.size===0)continue;d(o,m)}else o.type===_.AssignmentPattern&&o.left.type===_.ObjectPattern&&p(l,r,[o.left])}function d(l,r){let c=[];if(l.properties.at(-1)?.type===_.RestElement)return;for(let v of l.properties)v.type===_.Property&&v.key.type===_.Identifier&&c.push(v.key.name);let m=[],$=[];for(let[v,P]of r)c.includes(v)||($.push(v),m.push({node:P,messageId:"unusedObjectTypeProperty",data:{propertyName:v}}));for(let[v,P]of m.entries())e.report({...P,fix:v===m.length-1?T=>{let R=l.properties.at(-1),g=$.join(", ");return R?R?.type===_.RestElement?null:T.insertTextAfter(R,`, ${g}`):T.insertTextBeforeRange([l.range[0]+1,l.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(l){let r=l.declarations[0];if(!r)return;let c=new Map,o=r.id.type===_.Identifier&&r.id.typeAnnotation?.typeAnnotation.type===_.TSTypeReference&&r.id.typeAnnotation.typeAnnotation.typeName.type===_.Identifier&&r.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&r.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(o){if(o.type===_.TSTypeReference&&o.typeName.type===_.Identifier)i(!0,l,o.typeName,c,!1);else if(o.type===_.TSTypeLiteral)ct(c,...lt(o));else if(o.type===_.TSIntersectionType)for(let m of o.types)m.type===_.TSTypeReference&&m.typeName.type===_.Identifier?i(!0,l,m.typeName,c,!1):a(!0,l,c,m,!0);if(c.size!==0&&r.init?.type===_.ArrowFunctionExpression){let m=r.init.params[0];if(!m){e.report({node:r.init,messageId:"missingComponentParam"});return}m.type===_.ObjectPattern&&d(m,c)}}},FunctionDeclaration:function(l){p(!1,l,l.params)},ArrowFunctionExpression(l){p(!1,l,l.params)}}}}),De={name:ut,rule:Cn};import{AST_NODE_TYPES as $e,ESLintUtils as kn}from"@typescript-eslint/utils";var An=kn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ft="prefer-named-functions",pt=new Map,vn=An({name:ft,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let i=pt.get(t.ignoreRegex);i?n=i:(n=new RegExp(t.ignoreRegex),pt.set(t.ignoreRegex,n))}return{VariableDeclarator(i){if(i.init&&i.init.type===$e.ArrowFunctionExpression&&i.id.type===$e.Identifier){let a=i.id.name;if(i.id.typeAnnotation||n&&n.test(a)||!t.disallowArrowFnWithImplicitReturns&&i.init.body.type!==$e.BlockStatement)return;let p=i.parent,d=i.init.params,l=i.init.body,r=i.init;e.report({node:i.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:a,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(p,`${r.async?"async ":""}function ${a}(${d.map(o=>e.sourceCode.getText(o)).join(", ")||""}) ${e.sourceCode.getText(l)}`)}]})}}}}}),Oe={name:ft,rule:vn};import{AST_NODE_TYPES as Y,AST_TOKEN_TYPES as Dn,ESLintUtils as $n}from"@typescript-eslint/utils";var On=$n.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),mt="prefer-single-line-if",Pn=M({maxLineLength:j(Q()),maxNonSimpleConditionLength:j(Q())}),_n=On({name:mt,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[Pn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(i){if(i.consequent.type!==Y.BlockStatement||n.getCommentsInside(i.consequent).length>0||i.alternate||i.consequent.body.length!==1)return;let p=i.consequent.body[0];if(p.type===Y.ReturnStatement){if(!(!p.argument||p.argument.type===Y.Literal||p.argument.type===Y.Identifier))return}else if(!(p.type===Y.ContinueStatement||p.type===Y.BreakStatement))return;if(i.test.type===Y.LogicalExpression||i.test.type===Y.ConditionalExpression)return;let d;if(t.maxNonSimpleConditionLength&&(i.test.type===Y.CallExpression||i.test.type===Y.BinaryExpression||i.test.type===Y.MemberExpression)&&(d=n.getText(i.test),d.length>t.maxNonSimpleConditionLength))return;d||(d=n.getText(i.test));let l=n.getText(p);if(d.includes(`
13
+ `))return;let r=n.getTokenAfter(i);if(r&&r.type===Dn.Punctuator&&r.value==="}")return;let c=Nn(n,i),o=`if (${d}) ${l}`;t.maxLineLength&&o.length+c.length>t.maxLineLength||e.report({node:i,messageId:"noSingleLineCurly",fix:m=>m.replaceText(i,o)})}}}});function Nn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Pe={name:mt,rule:_n};import{ESLintUtils as Fn,TSESTree as Ln}from"@typescript-eslint/utils";var Mn=Fn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),dt="require-description",jn=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Hn=/^eslint-disable-(next-)?line$/u,Wn=Mn({name:dt,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,i=new Set(t.ignore||[]);return{Program(){for(let a of n.getAllComments()){let p=Un(a);p!=null&&(i.has(p.kind)||p.description||e.report({loc:Yn(a.loc),messageId:"missingDescription"}))}}}}}),yt={name:dt,rule:Wn};function Un(e){let{text:t,description:n}=Vn(e.value);if(!t)return null;let i=jn.exec(t);if(!i)return null;let a=i[1];if(!a)return null;let p=Hn.test(a);if(e.type===Ln.AST_TOKEN_TYPES.Line&&!p||p&&e.loc.start.line!==e.loc.end.line)return null;let d=t.slice(i.index+a.length);return{kind:a,value:d.trim(),description:n}}function Vn(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Yn(e){return{start:{line:e.start.line,column:-1},end:e.end}}function St(e){return/^use[A-Z0-9]/.test(e)}function ae(e){return e.type==="Identifier"?St(e.name):e.type==="MemberExpression"&&!e.computed&&ae(e.property)?e.object.type==="Identifier":!1}function Et(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Tt(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function bt(e){return!!(e.parent&&e.parent.callee&&Tt(e.parent.callee,"forwardRef"))}function xt(e){return!!(e.parent&&e.parent.callee&&Tt(e.parent.callee,"memo"))}function _e(e){for(;e;){let t=wt(e);if(t&&(Et(t)||ae(t))||bt(e)||xt(e))return!0;e=e.parent}return!1}function gt(e){return!1}function Ne(e){return!1}var zn=/eslint +react-compiler\/react-compiler: +\["error/,It={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let r of e.sourceCode.getAllComments())if(zn.test(r.value))return{CallExpression(c){let o=null;c.callee.name==="useMemo"?o="useMemo":c.callee.name==="useCallback"&&(o="useCallback"),o&&e.report({node:c,message:`"${o}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?r=>t(r):r=>e.sourceCode.getText(r),n=typeof e.getScope=="function"?()=>n():r=>e.sourceCode.getScope(r),i=null,a=[],p=[],d=new WeakSet;function l(r){for(let c of r.references){let o=c.identifier.parent;if(o.type==="VariableDeclarator"&&o.init&&o.init.type==="CallExpression"&&o.init.callee&&gt(o.init.callee))for(let m of c.resolved.references)m!==c&&d.add(m.identifier)}}return{onCodePathSegmentStart:r=>p.push(r),onCodePathSegmentEnd:()=>p.pop(),onCodePathStart:()=>a.push(new Map),onCodePathEnd(r,c){let o=a.pop();if(o.size===0)return;let m=new Set;function $(f,b){let{cache:x}=$,w=x.get(f.id),O=new Set(b);if(O.has(f.id)){let C=[...O],N=C.slice(C.indexOf(f.id)+1);for(let z of N)m.add(z);return BigInt("0")}if(O.add(f.id),w!==void 0)return w;if(r.thrownSegments.includes(f))w=BigInt("0");else if(f.prevSegments.length===0)w=BigInt("1");else{w=BigInt("0");for(let C of f.prevSegments)w+=$(C,O)}return f.reachable&&w===BigInt("0")?x.delete(f.id):x.set(f.id,w),w}function v(f,b){let{cache:x}=v,w=x.get(f.id),O=new Set(b);if(O.has(f.id)){let C=Array.from(O),N=C.slice(C.indexOf(f.id)+1);for(let z of N)m.add(z);return BigInt("0")}if(O.add(f.id),w!==void 0)return w;if(r.thrownSegments.includes(f))w=BigInt("0");else if(f.nextSegments.length===0)w=BigInt("1");else{w=BigInt("0");for(let C of f.nextSegments)w+=v(C,O)}return x.set(f.id,w),w}function P(f){let{cache:b}=P,x=b.get(f.id);if(x===null)return 1/0;if(x!==void 0)return x;if(b.set(f.id,null),f.prevSegments.length===0)x=1;else{x=1/0;for(let w of f.prevSegments){let O=P(w);O<x&&(x=O)}x+=1}return b.set(f.id,x),x}$.cache=new Map,v.cache=new Map,P.cache=new Map;let T=v(r.initialSegment),R=wt(c),g=_e(c),D=R?Et(R)||ae(R):bt(c)||xt(c),I=1/0;for(let f of r.finalSegments){if(!f.reachable)continue;let b=P(f);b<I&&(I=b)}for(let[f,b]of o){if(!f.reachable)continue;let x=f.nextSegments.length===0?I<=P(f):I<P(f),w=$(f)*v(f),O=m.has(f.id);for(let C of b)if(O&&!Ne(C)&&e.report({node:C,message:`React Hook "${t(C)}" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.`}),D){if(c.async&&e.report({node:C,message:`React Hook "${t(C)}" cannot be called in an async function.`}),!O&&w!==T&&!Ne(C)){let z=`React Hook "${t(C)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(x?" Did you accidentally call a React Hook after an early return?":"");e.report({node:C,message:z})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let N=`React Hook "${t(C)}" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}else if(R){let N=`React Hook "${t(C)}" is called in function "${t(R)}" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".`;e.report({node:C,message:N})}else if(c.type==="Program"){let N=`React Hook "${t(C)}" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}else if(g&&!Ne(C)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let z=c.parent;if(z.parent.type==="VariableDeclarator"&&St(z.parent.id.name))return}let N=`React Hook "${t(C)}" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:C,message:N})}}},CallExpression(r){if(ae(r.callee)){let c=ht(a),o=ht(p),m=c.get(o);m||(m=[],c.set(o,m)),m.push(r.callee)}r.callee.type==="Identifier"&&(r.callee.name==="useEffect"||gt(r.callee))&&r.arguments.length>0&&(i=r)},Identifier(r){i==null&&d.has(r)&&r.parent.type!=="CallExpression"&&e.report({node:r,message:`\`${t(r)}\` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.`})},"CallExpression:exit"(r){r===i&&(i=null)},FunctionDeclaration(r){_e(r)&&l(n(r))},ArrowFunctionExpression(r){_e(r)&&l(n(r))}}}};function wt(e){return e.type==="FunctionDeclaration"||e.type==="FunctionExpression"&&e.id?e.id:e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"?e.parent.type==="VariableDeclarator"&&e.parent.init===e?e.parent.id:e.parent.type==="AssignmentExpression"&&e.parent.right===e&&e.parent.operator==="="?e.parent.left:e.parent.type==="Property"&&e.parent.value===e&&!e.parent.computed?e.parent.key:e.parent.type==="AssignmentPattern"&&e.parent.right===e&&!e.parent.computed?e.parent.left:void 0:void 0}function ht(e){return e[e.length-1]}var Rt={[De.name]:De.rule,[be.name]:be.rule,[Te.name]:Te.rule,"rules-of-hooks":It,"exhaustive-deps":Ge,"require-description":yt.rule,[xe.name]:xe.rule,[we.name]:we.rule,[Oe.name]:Oe.rule,[ye.name]:ye.rule,[Ee.name]:Ee.rule,[Ae.name]:Ae.rule,[Pe.name]:Pe.rule,[Ce.name]:Ce.rule,[Ie.name]:Ie.rule};var Gr={rules:Rt};export{Gr as extendedLintPlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ls-stack/extended-lint",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"
@@ -50,7 +50,7 @@
50
50
  "test:ui": "vitest --ui",
51
51
  "build": "pnpm test && pnpm lint && pnpm run build:no-test",
52
52
  "build:no-test": "tsup --minify --dts",
53
- "run-in-test-project": "pnpm build && node --experimental-strip-types ./debug/runInTestProject.ts",
53
+ "run-in-test-project": "pnpm build:no-test && node --experimental-strip-types ./debug/runInTestProject.ts",
54
54
  "pre-publish": "./scripts/check-if-is-sync.sh && pnpm build",
55
55
  "npm-publish": "pnpm publish --access=public"
56
56
  }