@ls-stack/extended-lint 0.19.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extended-lint.js +3 -3
- package/dist/extended-lint.mjs +3 -3
- package/package.json +1 -1
package/dist/extended-lint.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Ot=Object.create;var ae=Object.defineProperty;var Pt=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames;var Ft=Object.getPrototypeOf,Mt=Object.prototype.hasOwnProperty;var Lt=(e,t)=>{for(var n in t)ae(e,n,{get:t[n],enumerable:!0})},We=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let
|
|
1
|
+
"use strict";var Ot=Object.create;var ae=Object.defineProperty;var Pt=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames;var Ft=Object.getPrototypeOf,Mt=Object.prototype.hasOwnProperty;var Lt=(e,t)=>{for(var n in t)ae(e,n,{get:t[n],enumerable:!0})},We=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of _t(t))!Mt.call(e,c)&&c!==n&&ae(e,c,{get:()=>t[c],enumerable:!(r=Pt(t,c))||r.enumerable});return e};var jt=(e,t,n)=>(n=e!=null?Ot(Ft(e)):{},We(t||!e||!e.__esModule?ae(n,"default",{value:e,enumerable:!0}):n,e)),Nt=e=>We(ae({},"__esModule",{value:!0}),e);var Pn={};Lt(Pn,{extendedLintPlugin:()=>On});module.exports=Nt(Pn);var J=require("@typescript-eslint/utils");var he=Symbol.for("optional");function j(e){return{...e,[he]:!0}}function Ue(e,t){return{enum:e,...t}}function ce(e){return{...e,type:"boolean"}}function M(e){return{...e,type:"string"}}function te(e){return{...e,type:"number"}}function Ve(e){return{...e,type:"integer"}}function U(e,t){return{...t,type:"array",items:e}}function L(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,c=[];for(r in e)e[r][he]?e[r][he]=void 0:c.push(r);c.length>0&&(n.required=c)}return n}function Se(...e){return{anyOf:e}}var Ht=J.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Wt=L({disallow:j(U(L({selector:M(),message:M(),replace:j(Se(M(),L({regex:M(),with:M()}))),replaceType:j(Ue(["suggestion","autofix"]))}))),__dev_simulateFileName:j(M()),mustMatchSyntax:j(U(L({includeRegex:M(),mustCallFn:U(L({anyCall:U(L({fn:M(),withArgs:U(L({atIndex:Ve(),literal:Se(M(),te(),ce())}))})),message:j(M())}))})))}),qe="advanced-no-restricted-syntax",Ut=Ht({name:qe,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Wt],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:c,disallow:m}=t,h=c??e.filename,a=[],i=new Set;for(let{includeRegex:o,mustCallFn:d}of r??[]){let D=Vt(h,new RegExp(o));if(!D)continue;let A=_=>{let E=_;for(let{name:I,value:g}of D)E=E.replaceAll(I,g);return E};for(let{anyCall:_,message:E}of d){let I=`Expected file to call the function: ${_.map(({fn:g})=>g).join(" or ")}`;i.add(I),a.push(g=>{let{callee:$}=g;if($.type===J.AST_NODE_TYPES.Identifier){for(let{fn:R,withArgs:f}of _)if($.name===R){i.delete(I);for(let x of f){let T=g.arguments[x.atIndex],w=typeof x.literal=="string"?A(x.literal):x.literal;if(!T){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${w}" at index ${x.atIndex}${E?`: ${A(E)}`:""}`}});continue}if(T.type!==J.AST_NODE_TYPES.Literal){e.report({node:T,messageId:"default",data:{message:`Argument at position ${x.atIndex} should the literal "${w}"${E?`: ${A(E)}`:""}`}});continue}T.value!==w&&e.report({node:T,messageId:"default",data:{message:`Argument should have the value "${w}"${E?`: ${A(E)}`:""}`},fix:O=>O.replaceText(T,typeof w=="string"?`'${w}'`:String(w))})}break}}})}}for(let{selector:o,message:d,replace:D,replaceType:A="suggestion"}of m??[]){if(o==="CallExpression"){a.push(_=>{u(D,_,d,A)});continue}n[o]=_=>{u(D,_,d,A)}}return a.length>0&&(n.CallExpression=o=>{if(o.type===J.AST_NODE_TYPES.CallExpression)for(let d of a)d(o)}),n["Program:exit"]=o=>{for(let d of i)e.report({node:o,messageId:"default",data:{message:`${d}`}})},n;function u(o,d,D,A){let _=E=>{if(!o)return null;if(typeof o=="string")return E.replaceText(d,o);{let I=new RegExp(o.regex),g=e.sourceCode.getText(d);return E.replaceText(d,g.replace(I,o.with))}};e.report({node:d,messageId:"default",data:{message:D},fix:o&&A==="autofix"?_:void 0,suggest:o&&A==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof o=="string"?o:o.with}"`},fix:_}]:void 0})}}});function Vt(e,t){let n=[],r=t.exec(e);if(!r)return null;let[c,...m]=r;n.push({name:"$0_lowercase",value:c.toLowerCase()}),n.push({name:"$0_capitalize",value:ze(c)}),n.push({name:"$0_uncapitalize",value:Be(c)}),n.push({name:"$0",value:c});for(let h=0;h<m.length;h++){let a=`$${h+1}`,i=m[h];n.push({name:`${a}_lowercase`,value:i.toLowerCase()}),n.push({name:`${a}_capitalize`,value:ze(i)}),n.push({name:`${a}_uncapitalize`,value:Be(i)}),n.push({name:a,value:i})}return n}function ze(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Be(e){return e.charAt(0).toLowerCase()+e.slice(1)}var be={name:qe,rule:Ut};var zt=/eslint +react-compiler\/react-compiler: +\["error/,Xe={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),r=typeof e.getScope=="function"?()=>r():g=>e.sourceCode.getScope(g),c=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,m=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,h={additionalHooks:c,enableDangerousAutofixThisMayCauseInfiniteLoops:m};function a(g){m&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let i=e.getSourceCode().scopeManager,u=new WeakMap,o=new WeakSet,d=new WeakMap,D=new WeakMap,A=new WeakSet;function _(g,$){return function(R){if($.has(R))return $.get(R);let f=g(R);return $.set(R,f),f}}function E(g,$,R,f,x){x&&g.async&&a({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 T=s.acquire(S),$=new Set,P=null;{let o=T.upper;for(;o&&($.add(o),o.type!=="function");)o=o.upper;if(!o)return;P=o}let w=Array.isArray;function F(o){if(!w(o.defs))return!1;let c=o.defs[0];if(c==null||c.node.type!=="VariableDeclarator")return!1;let m=c.node.init;if(m==null)return!1;for(;m.type==="TSAsExpression";)m=m.expression;let d=c.node.parent;if(d==null&&(Te(P.block,c.node.id),d=c.node.parent,d==null))return!1;if(d.kind==="const"&&m.type==="Literal"&&(typeof m.value=="string"||typeof m.value=="number"||m.value===null))return!0;if(m.type!=="CallExpression")return!1;let h=m.callee;if(h.type==="MemberExpression"&&h.object.name==="React"&&h.property!=null&&!h.computed&&(h=h.property),h.type!=="Identifier")return!1;let y=c.node.id,{name:I}=h;if(I==="useRef"&&y.type==="Identifier")return!0;if(Yt(h)&&y.type==="Identifier"){for(let C of o.references)C!==y&&_.add(C.identifier);return!0}else if(I==="useState"||I==="useReducer"){if(y.type==="ArrayPattern"&&y.elements.length===2&&w(o.identifiers)){if(y.elements[1]===o.identifiers[0]){if(I==="useState"){let C=o.references,W=0;for(let B=0;B<C.length;B++){if(C[B].isWrite()&&W++,W>1)return!1;i.set(C[B].identifier,y.elements[0])}}return!0}else if(y.elements[0]===o.identifiers[0]){if(I==="useState"){let C=o.references;for(let W=0;W<C.length;W++)p.add(C[W].identifier)}return!1}}}else if(I==="useTransition"&&y.type==="ArrayPattern"&&y.elements.length===2&&Array.isArray(o.identifiers)&&y.elements[1]===o.identifiers[0])return!0;return!1}function z(o){if(!w(o.defs))return!1;let c=o.defs[0];if(c==null||c.node==null||c.node.id==null)return!1;let m=c.node,d=P.childScopes,h=null,y;for(y=0;y<d.length;y++){let I=d[y],C=I.block;if(m.type==="FunctionDeclaration"&&C===m||m.type==="VariableDeclarator"&&C.parent===m){h=I;break}}if(h==null)return!1;for(y=0;y<h.through.length;y++){let I=h.through[y];if(I.resolved!=null&&$.has(I.resolved.scope)&&!Fe(I.resolved))return!1}return!0}let Fe=v(F,E),It=v(z,k),Me=new Map;function Ct(o){let c=o.from,m=!1;for(;c.block!==S;)c.type==="function"&&(m=c.block.parent!=null&&c.block.parent.type==="ReturnStatement"),c=c.upper;return m}let H=new Map,me=new Map;Le(T);function Le(o){for(let c of o.references){if(!c.resolved||!$.has(c.resolved.scope))continue;let m=Te(S,c.identifier),d=Ye(m),h=q(d,me);if(b&&d.type==="Identifier"&&(d.parent.type==="MemberExpression"||d.parent.type==="OptionalMemberExpression")&&!d.parent.computed&&d.parent.property.type==="Identifier"&&d.parent.property.name==="current"&&Ct(c)&&Me.set(h,{reference:c,dependencyNode:d}),d.parent.type==="TSTypeQuery"||d.parent.type==="TSTypeReference")continue;let y=c.resolved.defs[0];if(y!=null&&!(y.node!=null&&y.node.init===S.parent)&&y.type!=="TypeParameter")if(H.has(h))H.get(h).references.push(c);else{let I=c.resolved,C=Fe(I)||It(I);H.set(h,{isStable:C,references:[c]})}}for(let c of o.childScopes)Le(c)}Me.forEach(({reference:o,dependencyNode:c},m)=>{let d=o.resolved.references,h=!1;for(let y=0;y<d.length;y++){let{identifier:I}=d[y],{parent:C}=I;if(C!=null&&C.type==="MemberExpression"&&!C.computed&&C.property.type==="Identifier"&&C.property.name==="current"&&C.parent.type==="AssignmentExpression"&&C.parent.left===C){h=!0;break}}h||u({node:c.parent.property,message:`The ref value '${m}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${m}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let de=new Set;function kt(o,c){de.has(c)||(de.add(c),u({node:o,message:`Assignments to the '${c}' variable from inside React Hook ${n(R)} 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(R)}.`}))}let ie=new Set;if(H.forEach(({isStable:o,references:c},m)=>{o&&ie.add(m),c.forEach(d=>{d.writeExpr&&kt(d.writeExpr,m)})}),de.size>0)return;if(!D){let o=null;if(H.forEach(({isStable:c,references:m},d)=>{o||m.forEach(h=>{if(o)return;let y=h.identifier;if(!i.has(y))return;let C=h.from;for(;C.type!=="function";)C=C.upper;C.block===S&&(o=d)})}),o){let{suggestedDependencies:c}=Ee({dependencies:H,declaredDependencies:[],stableDependencies:ie,externalDependencies:new Set,isEffect:!0});u({node:R,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 [`+c.join(", ")+`] as a second argument to the ${f} Hook.`,suggest:[{desc:`Add dependencies array: [${c.join(", ")}]`,fix(m){return m.insertTextAfter(S,`, [${c.join(", ")}]`)}}]})}return}let Q=[],ee=new Set;D.type!=="ArrayExpression"?u({node:D,message:`React Hook ${n(R)} 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"){u({node:o,message:`React Hook ${n(R)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}_.has(o)&&u({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(h){return h.removeRange(o.range)}}]});let c;try{c=q(o,me)}catch(h){if(/Unsupported node type/.test(h.message)){o.type==="Literal"?H.has(o.value)?u({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?`}):u({node:o,message:`The ${o.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):u({node:o,message:`React Hook ${n(R)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw h}let m=o;for(;m.type==="MemberExpression"||m.type==="OptionalMemberExpression"||m.type==="ChainExpression";)m=m.object||m.expression.object;let d=!P.through.some(h=>h.identifier===m);Q.push({key:c,node:o}),d||ee.add(c)});let{suggestedDependencies:vt,unnecessaryDependencies:se,missingDependencies:X,duplicateDependencies:je}=Ee({dependencies:H,declaredDependencies:Q,stableDependencies:ie,externalDependencies:ee,isEffect:b}),oe=vt;if(je.size+X.size+se.size===0){if(t)return;Bt({declaredDependencies:Q,declaredDependenciesNode:D,componentScope:P,scope:T}).forEach(({construction:c,isUsedOutsideOfHook:m,depType:d})=>{let h=d==="function"?"useCallback":"useMemo",y=d==="function"?"definition":"initialization",I=`wrap the ${y} of '${c.name.name}' in its own ${h}() Hook.`,C=m?`To fix this, ${I}`:`Move it inside the ${f} callback. Alternatively, ${I}`,W=d==="conditional"||d==="logical expression"?"could make":"makes",B=`The '${c.name.name}' ${d} ${W} the dependencies of ${f} Hook (at line ${D.loc.start.line}) change on every render. ${C}`,Ne;m&&c.type==="Variable"&&d==="function"&&(Ne=[{desc:`Wrap the ${y} of '${c.name.name}' in its own ${h}() Hook.`,fix(He){let[$t,Dt]=h==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[He.insertTextBefore(c.node.init,$t),He.insertTextAfter(c.node.init,Dt)]}}]),u({node:c.node,message:B,suggest:Ne})});return}!b&&X.size>0&&(oe=Ee({dependencies:H,declaredDependencies:[],stableDependencies:ie,externalDependencies:ee,isEffect:b}).suggestedDependencies);function At(){if(Q.length===0)return!0;let o=Q.map(m=>m.key),c=o.slice().sort();return o.join(",")===c.join(",")}At()&&oe.sort();function ge(o){let c=o.split("."),m="";for(let d=0;d<c.length;d++){if(d!==0){let h=c.slice(0,d+1).join("."),y=me.get(h)===!0;m+=y?"?.":"."}m+=c[d]}return m}function ye(o,c,m,d){return o.size===0?null:(o.size>1?"":c+" ")+m+" "+(o.size>1?"dependencies":"dependency")+": "+Gt(Array.from(o).sort().map(h=>"'"+ge(h)+"'"))+`. Either ${d} ${o.size>1?"them":"it"} or remove the dependency array.`}let V="";if(se.size>0){let o=null;if(Array.from(se.keys()).forEach(c=>{o===null&&c.endsWith(".current")&&(o=c)}),o!==null)V=` Mutable values like '${o}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(ee.size>0){let c=Array.from(ee)[0];T.set.has(c)||(V=` Outer scope values like '${c}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!V&&X.has("props")){let o=H.get("props");if(o==null)return;let c=o.references;if(!Array.isArray(c))return;let m=!0;for(let d=0;d<c.length;d++){let h=c[d],y=Te(P.block,h.identifier);if(!y){m=!1;break}let I=y.parent;if(I==null){m=!1;break}if(I.type!=="MemberExpression"&&I.type!=="OptionalMemberExpression"){m=!1;break}}m&&(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(R)}.`)}if(!V&&X.size>0){let o=null;X.forEach(c=>{if(o)return;let m=P.set.get(c),d=H.get(c);if(d.references[0].resolved!==m)return;let h=m.defs[0];if(h==null||h.name==null||h.type!=="Parameter")return;let y=!1,I;for(let C=0;C<d.references.length;C++)if(I=d.references[C].identifier,I!=null&&I.parent!=null&&(I.parent.type==="CallExpression"||I.parent.type==="OptionalCallExpression")&&I.parent.callee===I){y=!0;break}y&&(o=c)}),o!==null&&(V=` If '${o}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!V&&X.size>0){let o=null;if(X.forEach(c=>{if(o!==null)return;let d=H.get(c).references,h,y;for(let I=0;I<d.length;I++){for(h=d[I].identifier,y=h.parent;y!=null&&y!==P.block;){if(y.type==="CallExpression"){let C=i.get(y.callee);if(C!=null){if(C.name===c)o={missingDep:c,setter:y.callee.name,form:"updater"};else if(p.has(h))o={missingDep:c,setter:y.callee.name,form:"reducer"};else{let W=d[I].resolved;if(W!=null){let B=W.defs[0];B!=null&&B.type==="Parameter"&&(o={missingDep:c,setter:y.callee.name,form:"inlineReducer"})}}break}}y=y.parent}if(o!==null)break}}),o!==null)switch(o.form){case"reducer":V=` You can also replace multiple useState variables with useReducer if '${o.setter}' needs the current value of '${o.missingDep}'.`;break;case"inlineReducer":V=` 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":V=` 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.")}}u({node:D,message:`React Hook ${n(R)} has `+(ye(X,"a","missing","include")||ye(se,"an","unnecessary","exclude")||ye(je,"a","duplicate","omit"))+V,suggest:[{desc:`Update the dependencies array to be: [${oe.map(ge).join(", ")}]`,fix(o){return o.replaceText(D,`[${oe.map(ge).join(", ")}]`)}}]})}function A(S){let D=qt(S.callee,l);if(D===-1)return;let R=S.arguments[D],f=S.callee,b=Ke(f).name,T=S.arguments[D+1],$=/Effect($|[^a-z])/g.test(b);if(!R){u({node:f,message:`React Hook ${b} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!$)){if(!T&&!$){(b==="useMemo"||b==="useCallback")&&u({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(R.type){case"FunctionExpression":case"ArrowFunctionExpression":x(R,T,f,b,$);return;case"Identifier":if(!T||T.elements&&T.elements.some(F=>F&&F.type==="Identifier"&&F.name===R.name))return;let P=r(S).set.get(R.name);if(P==null||P.defs==null)return;let w=P.defs[0];if(!w||!w.node||w.type!=="Variable"&&w.type!=="FunctionName")break;switch(w.node.type){case"FunctionDeclaration":x(w.node,T,f,b,$);return;case"VariableDeclarator":let F=w.node.init;if(!F)break;switch(F.type){case"ArrowFunctionExpression":case"FunctionExpression":x(F,T,f,b,$);return}break}break;default:u({node:f,message:`React Hook ${b} received a function whose dependencies are unknown. Pass an inline function instead.`});return}u({node:f,message:`React Hook ${b} has a missing dependency: '${R.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${R.name}]`,fix(P){return P.replaceText(T,`[${R.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let S of e.sourceCode.getAllComments())if(zt.test(S.value))return t=!0,{CallExpression:D=>A(D,!0)}}return{CallExpression:S=>A(S)}}};function Ee({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:a}){let g=l();function l(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((x,A)=>{let S=u(g,A);S.isUsed=!0,s(g,A,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:x})=>{let A=u(g,x);A.isSatisfiedRecursively=!0}),n.forEach(x=>{let A=u(g,x);A.isSatisfiedRecursively=!0});function u(x,A){let S=A.split("."),D=x;for(let R of S){let f=D.children.get(R);f||(f=l(),D.children.set(R,f)),D=f}return D}function s(x,A,S){let D=A.split("."),R=x;for(let f of D){let b=R.children.get(f);if(!b)return;S(b),R=b}}let i=new Set,p=new Set;E(g,i,p,x=>x);function E(x,A,S,D){x.children.forEach((R,f)=>{let b=D(f);if(R.isSatisfiedRecursively){R.isSubtreeUsed&&S.add(b);return}if(R.isUsed){A.add(b);return}E(R,A,S,T=>b+"."+T)})}let k=[],_=new Set,v=new Set;return t.forEach(({key:x})=>{p.has(x)?k.indexOf(x)===-1?k.push(x):v.add(x):_.add(x)}),i.forEach(x=>{k.push(x)}),{suggestedDependencies:k,unnecessaryDependencies:_,duplicateDependencies:v,missingDependencies:i}}function Y(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 Y(e.consequent)!=null||Y(e.alternate)!=null?"conditional":null;case"LogicalExpression":return Y(e.left)!=null||Y(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return Y(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return Y(e.expression);case"TSAsExpression":return Y(e.expression)}return null}function Bt({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let a=e.map(({key:l})=>{let u=n.variables.find(i=>i.name===l);if(u==null)return null;let s=u.defs[0];if(s==null)return null;if(s.type==="Variable"&&s.node.type==="VariableDeclarator"&&s.node.id.type==="Identifier"&&s.node.init!=null){let i=Y(s.node.init);if(i!=null)return[u,i]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[u,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[u,"class"]:null}).filter(Boolean);function g(l){let u=!1;for(let s=0;s<l.references.length;s++){let i=l.references[s];if(i.writeExpr){if(u)return!0;u=!0;continue}let p=i.from;for(;p!==r&&p!=null;)p=p.upper;if(p!==r&&!Je(t,i.identifier))return!0}return!1}return a.map(([l,u])=>({construction:l.defs[0],depType:u,isUsedOutsideOfHook:g(l)}))}function Ye(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)?Ye(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function xe(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function q(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=q(e.object,t),r=q(e.property,null),a=`${n}.${r}`;return xe(e,t,a),a}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=q(e.object,t),r=q(e.property,null),a=`${n}.${r}`;return xe(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 r=q(n.object,t),a=q(n.property,null),g=`${r}.${a}`;return xe(n,t,g),g}else throw new Error(`Unsupported node type: ${e.type}`)}function Ke(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function qt(e,t){let n=Ke(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 r;try{r=q(n,null)}catch(a){if(/Unsupported node type/.test(a.message))return 0;throw a}return t.additionalHooks.test(r)?0:-1}else return-1}}function Te(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Xt(r,t))return r;if(Je(r,t))for(let[a,g]of Object.entries(r))a!=="parent"&&(Ge(g)?(g.parent=r,n.push(g)):Array.isArray(g)&&g.forEach(l=>{Ge(l)&&(l.parent=r,n.push(l))}))}return null}function Gt(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 Ge(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Xt(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 Je(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Yt(e){return!1}var le=require("@typescript-eslint/utils");var Kt=le.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ze="no-call-with-explicit-generics",Jt=L({functions:U(M())}),Zt=Kt({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:[Jt]},defaultOptions:[{functions:[]}],create(e){let t=e.options[0],n=new Set(t.functions);return{CallExpression(r){let{callee:a}=r;a.type===le.AST_NODE_TYPES.Identifier&&n.has(a.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:a.name}})}}}}),Re={name:Ze,rule:Zt};var K=require("@typescript-eslint/utils"),Qt=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qe="no-call-with-inferred-generics",en=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){let t=e.options[0],n=new Map(t.functions.map(r=>[r.name,r]));return{CallExpression(r){let{callee:a}=r;if(a.type!==K.AST_NODE_TYPES.Identifier)return;let g=n.get(a.name);if(!g)return;let{minGenerics:l=1,allowAny:u,disallowTypes:s=t.disallowTypes}=g;(r.typeArguments?.params.length||0)<(l||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:a.name,minGenerics:l||0}}),!(u&&!s)&&r.typeArguments?.params?.some(p=>!u&&p.type===K.AST_NODE_TYPES.TSAnyKeyword||s&&p.type===K.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===K.AST_NODE_TYPES.Identifier&&s.includes(p.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:a.name}})}}}}),we={name:Qe,rule:en};var re=require("@typescript-eslint/utils"),tn=re.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),et="no-commented-out-code",nn=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],rn=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],sn=tn({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:function(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let a of nn)if(r.startsWith(a))return{wrongPattern:a};for(let a of rn)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 r=e.sourceCode.getAllComments();for(let a of r)if(a.type===re.TSESTree.AST_TOKEN_TYPES.Line||a.type===re.TSESTree.AST_TOKEN_TYPES.Block){let g=t(a.value);g&&e.report({node:a,messageId:"commentedOutCode",data:{wrongPattern:g.wrongPattern}})}}}}}),Ie={name:et,rule:sn};var tt=require("@typescript-eslint/utils"),on=tt.ESLintUtils.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.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ce={name:nt,rule:an};var G=require("@typescript-eslint/utils"),cn=G.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),it="no-non-camel-case-functions",ln=/^[a-z][a-zA-Z0-9]*$/;function rt(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 un=cn({name:it,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&&!ln.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===G.AST_NODE_TYPES.TSTypeReference?rt(n):n.type===G.AST_NODE_TYPES.TSUnionType&&n.types.some(a=>a.type===G.AST_NODE_TYPES.TSTypeReference&&rt(a))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),ke={name:it,rule:un};var st=require("@typescript-eslint/utils"),ue=jt(require("path"));var pn=st.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ot="no-relative-imports",fn=L({find:M(),replacement:M()}),mn=L({aliases:U(fn),rootDir:j(M()),allowNotFoundAliases:j(ce()),_dev_simulateFileName:j(M())}),dn=pn({name:ot,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:[mn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e){let t=e.options[0],n=t._dev_simulateFileName??e.filename;function r(l){return l.startsWith(".")||l.startsWith("..")}function a(l,u){let s=ue.default.dirname(u);return ue.default.resolve(s,l)}function g(l){let u=t.rootDir??process.cwd(),s=ue.default.relative(u,l);if(s.startsWith("."))return null;s.startsWith("/")||(s=`/${s}`);for(let{find:i,replacement:p}of t.aliases)if(s.startsWith(p)){let E=s.replace(p,i);return{alias:i,newPath:E}}return null}return{ImportDeclaration(l){let u=l.source.value;if(!r(u))return;let s=a(u,n),i=g(s);!i&&t.allowNotFoundAliases||e.report({node:l,messageId:i?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:i?.alias},fix:i?p=>p.replaceText(l.source,`'${i.newPath}'`):void 0})}}}}),ve={name:ot,rule:dn};var O=require("@typescript-eslint/utils");var gn=O.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function at(e){let t=[];for(let n of e.members)n.type===O.AST_NODE_TYPES.TSPropertySignature&&n.key.type===O.AST_NODE_TYPES.Identifier&&t.push([n.key.name,n]);return t}function ct(e,...t){for(let n of t)e.set(...n);return e}var yn=L({forceCheckOnFCPropTypesWithName:j(U(M()))}),lt="no-unused-type-props-in-args",Ae=null,hn=gn({name:lt,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:[yn],fixable:"code"},defaultOptions:[{}],create(e){let{forceCheckOnFCPropTypesWithName:t}=e.options[0];t&&!Ae&&(Ae=t.map(l=>new RegExp(l)));function n(l,u,s,i,p=!0){let E=s.name,k=e.sourceCode.getScope(u).references.find(x=>x.identifier.name===E)?.resolved,_=l&&Ae?.some(x=>x.test(E));if(!k||!_&&k.references.filter(x=>x.isTypeReference).length>1)return;let v=k?.defs[0]?.node;if(!(p&&v?.parent?.type===O.AST_NODE_TYPES.ExportNamedDeclaration)){if(v?.type===O.AST_NODE_TYPES.TSTypeAliasDeclaration){r(l,u,i,v.typeAnnotation,!0);return}if(v?.type===O.AST_NODE_TYPES.TSInterfaceDeclaration){r(l,u,i,v.body,!0);return}}}function r(l,u,s,i,p){if(i.type===O.AST_NODE_TYPES.TSInterfaceBody){for(let E of i.body)E.type===O.AST_NODE_TYPES.TSPropertySignature&&E.key.type===O.AST_NODE_TYPES.Identifier&&s.set(E.key.name,E);return}if(i.type===O.AST_NODE_TYPES.TSTypeLiteral){ct(s,...at(i));return}if(i.type===O.AST_NODE_TYPES.TSIntersectionType){for(let E of i.types)r(l,u,s,E,!0);return}p||i.type===O.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===O.AST_NODE_TYPES.Identifier&&n(l,u,i.typeName,s)}function a(l,u,s){for(let i of s)if(i.type==="ObjectPattern"&&i.typeAnnotation){let p=new Map;if(r(l,u,p,i.typeAnnotation.typeAnnotation,!1),p.size===0)continue;g(i,p)}else i.type===O.AST_NODE_TYPES.AssignmentPattern&&i.left.type===O.AST_NODE_TYPES.ObjectPattern&&a(l,u,[i.left])}function g(l,u){let s=[];if(l.properties.at(-1)?.type===O.AST_NODE_TYPES.RestElement)return;for(let k of l.properties)k.type===O.AST_NODE_TYPES.Property&&k.key.type===O.AST_NODE_TYPES.Identifier&&s.push(k.key.name);let p=[],E=[];for(let[k,_]of u)s.includes(k)||(E.push(k),p.push({node:_,messageId:"unusedObjectTypeProperty",data:{propertyName:k}}));for(let[k,_]of p.entries())e.report({..._,fix:k===p.length-1?v=>{let x=l.properties.at(-1),A=E.join(", ");return x?x?.type===O.AST_NODE_TYPES.RestElement?null:v.insertTextAfter(x,`, ${A}`):v.insertTextBeforeRange([l.range[0]+1,l.range[1]],`${A}`)}:void 0})}return{VariableDeclaration(l){let u=l.declarations[0];if(!u)return;let s=new Map,i=u.id.type===O.AST_NODE_TYPES.Identifier&&u.id.typeAnnotation?.typeAnnotation.type===O.AST_NODE_TYPES.TSTypeReference&&u.id.typeAnnotation.typeAnnotation.typeName.type===O.AST_NODE_TYPES.Identifier&&u.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&u.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(i){if(i.type===O.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===O.AST_NODE_TYPES.Identifier)n(!0,l,i.typeName,s,!1);else if(i.type===O.AST_NODE_TYPES.TSTypeLiteral)ct(s,...at(i));else if(i.type===O.AST_NODE_TYPES.TSIntersectionType)for(let p of i.types)p.type===O.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===O.AST_NODE_TYPES.Identifier?n(!0,l,p.typeName,s,!1):r(!0,l,s,p,!0);if(s.size!==0&&u.init?.type===O.AST_NODE_TYPES.ArrowFunctionExpression){let p=u.init.params[0];if(!p){e.report({node:u.init,messageId:"missingComponentParam"});return}p.type===O.AST_NODE_TYPES.ObjectPattern&&g(p,s)}}},FunctionDeclaration:function(l){a(!1,l,l.params)},ArrowFunctionExpression(l){a(!1,l,l.params)}}}}),$e={name:lt,rule:hn};var Z=require("@typescript-eslint/utils"),Sn=Z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),pt="prefer-named-functions",ut=new Map,bn=Sn({name:pt,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){let t=e.options[0],n=null;if(t.ignoreRegex){let r=ut.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),ut.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===Z.AST_NODE_TYPES.ArrowFunctionExpression&&r.id.type===Z.AST_NODE_TYPES.Identifier){let a=r.id.name;if(r.id.typeAnnotation||n&&n.test(a)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==Z.AST_NODE_TYPES.BlockStatement)return;let g=r.parent,l=r.init.params,u=r.init.body,s=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:a,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:i=>i.replaceText(g,`${s.async?"async ":""}function ${a}(${l.map(p=>e.sourceCode.getText(p)).join(", ")||""}) ${e.sourceCode.getText(u)}`)}]})}}}}}),De={name:pt,rule:bn};var N=require("@typescript-eslint/utils");var En=N.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ft="prefer-single-line-if",xn=L({maxLineLength:j(te()),maxNonSimpleConditionLength:j(te())}),Tn=En({name:ft,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:[xn]},defaultOptions:[{}],create(e){let t=e.options[0],n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==N.AST_NODE_TYPES.BlockStatement||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let g=r.consequent.body[0],l;if(g.type===N.AST_NODE_TYPES.ReturnStatement){if(!(!g.argument||g.argument.type===N.AST_NODE_TYPES.Literal||g.argument.type===N.AST_NODE_TYPES.Identifier)||g.argument&&(r.test.type===N.AST_NODE_TYPES.LogicalExpression||r.test.type===N.AST_NODE_TYPES.ConditionalExpression||t.maxNonSimpleConditionLength&&(r.test.type===N.AST_NODE_TYPES.CallExpression||r.test.type===N.AST_NODE_TYPES.BinaryExpression||r.test.type===N.AST_NODE_TYPES.MemberExpression)&&(l=n.getText(r.test),l.length>t.maxNonSimpleConditionLength)))return}else if(!(g.type===N.AST_NODE_TYPES.ContinueStatement||g.type===N.AST_NODE_TYPES.BreakStatement))return;l||(l=n.getText(r.test));let u=n.getText(g);if(l.includes(`
|
|
13
|
-
`))return;let
|
|
12
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let T=i.acquire(g),w=new Set,O=null;{let s=T.upper;for(;s&&(w.add(s),s.type!=="function");)s=s.upper;if(!s)return;O=s}let C=Array.isArray;function F(s){if(!C(s.defs))return!1;let l=s.defs[0];if(l==null||l.node.type!=="VariableDeclarator")return!1;let p=l.node.init;if(p==null)return!1;for(;p.type==="TSAsExpression";)p=p.expression;let y=l.node.parent;if(y==null&&(Te(O.block,l.node.id),y=l.node.parent,y==null))return!1;if(y.kind==="const"&&p.type==="Literal"&&(typeof p.value=="string"||typeof p.value=="number"||p.value===null))return!0;if(p.type!=="CallExpression")return!1;let b=p.callee;if(b.type==="MemberExpression"&&b.object.name==="React"&&b.property!=null&&!b.computed&&(b=b.property),b.type!=="Identifier")return!1;let S=l.node.id,{name:k}=b;if(k==="useRef"&&S.type==="Identifier")return!0;if(Yt(b)&&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;u.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++)o.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 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 p=l.node,y=O.childScopes,b=null,S;for(S=0;S<y.length;S++){let k=y[S],v=k.block;if(p.type==="FunctionDeclaration"&&v===p||p.type==="VariableDeclarator"&&v.parent===p){b=k;break}}if(b==null)return!1;for(S=0;S<b.through.length;S++){let k=b.through[S];if(k.resolved!=null&&w.has(k.resolved.scope)&&!Fe(k.resolved))return!1}return!0}let Fe=_(F,d),It=_(z,D),Me=new Map;function Ct(s){let l=s.from,p=!1;for(;l.block!==g;)l.type==="function"&&(p=l.block.parent!=null&&l.block.parent.type==="ReturnStatement"),l=l.upper;return p}let H=new Map,me=new Map;Le(T);function Le(s){for(let l of s.references){if(!l.resolved||!w.has(l.resolved.scope))continue;let p=Te(g,l.identifier),y=Ye(p),b=q(y,me);if(x&&y.type==="Identifier"&&(y.parent.type==="MemberExpression"||y.parent.type==="OptionalMemberExpression")&&!y.parent.computed&&y.parent.property.type==="Identifier"&&y.parent.property.name==="current"&&Ct(l)&&Me.set(b,{reference:l,dependencyNode:y}),y.parent.type==="TSTypeQuery"||y.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(H.has(b))H.get(b).references.push(l);else{let k=l.resolved,v=Fe(k)||It(k);H.set(b,{isStable:v,references:[l]})}}for(let l of s.childScopes)Le(l)}Me.forEach(({reference:s,dependencyNode:l},p)=>{let y=s.resolved.references,b=!1;for(let S=0;S<y.length;S++){let{identifier:k}=y[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){b=!0;break}}b||a({node:l.parent.property,message:`The ref value '${p}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${p}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let de=new Set;function kt(s,l){de.has(l)||(de.add(l),a({node:s,message:`Assignments to the '${l}' variable from inside React Hook ${n(R)} 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(R)}.`}))}let ie=new Set;if(H.forEach(({isStable:s,references:l},p)=>{s&&ie.add(p),l.forEach(y=>{y.writeExpr&&kt(y.writeExpr,p)})}),de.size>0)return;if(!$){let s=null;if(H.forEach(({isStable:l,references:p},y)=>{s||p.forEach(b=>{if(s)return;let S=b.identifier;if(!u.has(S))return;let v=b.from;for(;v.type!=="function";)v=v.upper;v.block===g&&(s=y)})}),s){let{suggestedDependencies:l}=Ee({dependencies:H,declaredDependencies:[],stableDependencies:ie,externalDependencies:new Set,isEffect:!0});a({node:R,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(p){return p.insertTextAfter(g,`, [${l.join(", ")}]`)}}]})}return}let Q=[],ee=new Set;$.type!=="ArrayExpression"?a({node:$,message:`React Hook ${n(R)} 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"){a({node:s,message:`React Hook ${n(R)} 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)&&a({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(b){return b.removeRange(s.range)}}]});let l;try{l=q(s,me)}catch(b){if(/Unsupported node type/.test(b.message)){s.type==="Literal"?H.has(s.value)?a({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?`}):a({node:s,message:`The ${s.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):a({node:s,message:`React Hook ${n(R)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw b}let p=s;for(;p.type==="MemberExpression"||p.type==="OptionalMemberExpression"||p.type==="ChainExpression";)p=p.object||p.expression.object;let y=!O.through.some(b=>b.identifier===p);Q.push({key:l,node:s}),y||ee.add(l)});let{suggestedDependencies:vt,unnecessaryDependencies:se,missingDependencies:X,duplicateDependencies:je}=Ee({dependencies:H,declaredDependencies:Q,stableDependencies:ie,externalDependencies:ee,isEffect:x}),oe=vt;if(je.size+X.size+se.size===0){if(t)return;Bt({declaredDependencies:Q,declaredDependenciesNode:$,componentScope:O,scope:T}).forEach(({construction:l,isUsedOutsideOfHook:p,depType:y})=>{let b=y==="function"?"useCallback":"useMemo",S=y==="function"?"definition":"initialization",k=`wrap the ${S} of '${l.name.name}' in its own ${b}() Hook.`,v=p?`To fix this, ${k}`:`Move it inside the ${f} callback. Alternatively, ${k}`,W=y==="conditional"||y==="logical expression"?"could make":"makes",B=`The '${l.name.name}' ${y} ${W} the dependencies of ${f} Hook (at line ${$.loc.start.line}) change on every render. ${v}`,Ne;p&&l.type==="Variable"&&y==="function"&&(Ne=[{desc:`Wrap the ${S} of '${l.name.name}' in its own ${b}() Hook.`,fix(He){let[$t,Dt]=b==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[He.insertTextBefore(l.node.init,$t),He.insertTextAfter(l.node.init,Dt)]}}]),a({node:l.node,message:B,suggest:Ne})});return}!x&&X.size>0&&(oe=Ee({dependencies:H,declaredDependencies:[],stableDependencies:ie,externalDependencies:ee,isEffect:x}).suggestedDependencies);function At(){if(Q.length===0)return!0;let s=Q.map(p=>p.key),l=s.slice().sort();return s.join(",")===l.join(",")}At()&&oe.sort();function ge(s){let l=s.split("."),p="";for(let y=0;y<l.length;y++){if(y!==0){let b=l.slice(0,y+1).join("."),S=me.get(b)===!0;p+=S?"?.":"."}p+=l[y]}return p}function ye(s,l,p,y){return s.size===0?null:(s.size>1?"":l+" ")+p+" "+(s.size>1?"dependencies":"dependency")+": "+Gt(Array.from(s).sort().map(b=>"'"+ge(b)+"'"))+`. Either ${y} ${s.size>1?"them":"it"} or remove the dependency array.`}let V="";if(se.size>0){let s=null;if(Array.from(se.keys()).forEach(l=>{s===null&&l.endsWith(".current")&&(s=l)}),s!==null)V=` Mutable values like '${s}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(ee.size>0){let l=Array.from(ee)[0];T.set.has(l)||(V=` Outer scope values like '${l}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!V&&X.has("props")){let s=H.get("props");if(s==null)return;let l=s.references;if(!Array.isArray(l))return;let p=!0;for(let y=0;y<l.length;y++){let b=l[y],S=Te(O.block,b.identifier);if(!S){p=!1;break}let k=S.parent;if(k==null){p=!1;break}if(k.type!=="MemberExpression"&&k.type!=="OptionalMemberExpression"){p=!1;break}}p&&(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(R)}.`)}if(!V&&X.size>0){let s=null;X.forEach(l=>{if(s)return;let p=O.set.get(l),y=H.get(l);if(y.references[0].resolved!==p)return;let b=p.defs[0];if(b==null||b.name==null||b.type!=="Parameter")return;let S=!1,k;for(let v=0;v<y.references.length;v++)if(k=y.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&&(V=` If '${s}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!V&&X.size>0){let s=null;if(X.forEach(l=>{if(s!==null)return;let y=H.get(l).references,b,S;for(let k=0;k<y.length;k++){for(b=y[k].identifier,S=b.parent;S!=null&&S!==O.block;){if(S.type==="CallExpression"){let v=u.get(S.callee);if(v!=null){if(v.name===l)s={missingDep:l,setter:S.callee.name,form:"updater"};else if(o.has(b))s={missingDep:l,setter:S.callee.name,form:"reducer"};else{let W=y[k].resolved;if(W!=null){let B=W.defs[0];B!=null&&B.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":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.")}}a({node:$,message:`React Hook ${n(R)} has `+(ye(X,"a","missing","include")||ye(se,"an","unnecessary","exclude")||ye(je,"a","duplicate","omit"))+V,suggest:[{desc:`Update the dependencies array to be: [${oe.map(ge).join(", ")}]`,fix(s){return s.replaceText($,`[${oe.map(ge).join(", ")}]`)}}]})}function I(g){let $=qt(g.callee,h);if($===-1)return;let R=g.arguments[$],f=g.callee,x=Ke(f).name,T=g.arguments[$+1],w=/Effect($|[^a-z])/g.test(x);if(!R){a({node:f,message:`React Hook ${x} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!w)){if(!T&&!w){(x==="useMemo"||x==="useCallback")&&a({node:f,message:`React Hook ${x} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(R.type){case"FunctionExpression":case"ArrowFunctionExpression":E(R,T,f,x,w);return;case"Identifier":if(!T||T.elements&&T.elements.some(F=>F&&F.type==="Identifier"&&F.name===R.name))return;let O=r(g).set.get(R.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":E(C.node,T,f,x,w);return;case"VariableDeclarator":let F=C.node.init;if(!F)break;switch(F.type){case"ArrowFunctionExpression":case"FunctionExpression":E(F,T,f,x,w);return}break}break;default:a({node:f,message:`React Hook ${x} received a function whose dependencies are unknown. Pass an inline function instead.`});return}a({node:f,message:`React Hook ${x} has a missing dependency: '${R.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${R.name}]`,fix(O){return O.replaceText(T,`[${R.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(zt.test(g.value))return t=!0,{CallExpression:$=>I($,!0)}}return{CallExpression:g=>I(g)}}};function Ee({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:c}){let m=h();function h(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((E,I)=>{let g=a(m,I);g.isUsed=!0,i(m,I,$=>{$.isSubtreeUsed=!0})}),t.forEach(({key:E})=>{let I=a(m,E);I.isSatisfiedRecursively=!0}),n.forEach(E=>{let I=a(m,E);I.isSatisfiedRecursively=!0});function a(E,I){let g=I.split("."),$=E;for(let R of g){let f=$.children.get(R);f||(f=h(),$.children.set(R,f)),$=f}return $}function i(E,I,g){let $=I.split("."),R=E;for(let f of $){let x=R.children.get(f);if(!x)return;g(x),R=x}}let u=new Set,o=new Set;d(m,u,o,E=>E);function d(E,I,g,$){E.children.forEach((R,f)=>{let x=$(f);if(R.isSatisfiedRecursively){R.isSubtreeUsed&&g.add(x);return}if(R.isUsed){I.add(x);return}d(R,I,g,T=>x+"."+T)})}let D=[],A=new Set,_=new Set;return t.forEach(({key:E})=>{o.has(E)?D.indexOf(E)===-1?D.push(E):_.add(E):A.add(E)}),u.forEach(E=>{D.push(E)}),{suggestedDependencies:D,unnecessaryDependencies:A,duplicateDependencies:_,missingDependencies:u}}function Y(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 Y(e.consequent)!=null||Y(e.alternate)!=null?"conditional":null;case"LogicalExpression":return Y(e.left)!=null||Y(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return Y(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return Y(e.expression);case"TSAsExpression":return Y(e.expression)}return null}function Bt({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let c=e.map(({key:h})=>{let a=n.variables.find(u=>u.name===h);if(a==null)return null;let i=a.defs[0];if(i==null)return null;if(i.type==="Variable"&&i.node.type==="VariableDeclarator"&&i.node.id.type==="Identifier"&&i.node.init!=null){let u=Y(i.node.init);if(u!=null)return[a,u]}return i.type==="FunctionName"&&i.node.type==="FunctionDeclaration"?[a,"function"]:i.type==="ClassName"&&i.node.type==="ClassDeclaration"?[a,"class"]:null}).filter(Boolean);function m(h){let a=!1;for(let i=0;i<h.references.length;i++){let u=h.references[i];if(u.writeExpr){if(a)return!0;a=!0;continue}let o=u.from;for(;o!==r&&o!=null;)o=o.upper;if(o!==r&&!Je(t,u.identifier))return!0}return!1}return c.map(([h,a])=>({construction:h.defs[0],depType:a,isUsedOutsideOfHook:m(h)}))}function Ye(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)?Ye(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function xe(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function q(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=q(e.object,t),r=q(e.property,null),c=`${n}.${r}`;return xe(e,t,c),c}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=q(e.object,t),r=q(e.property,null),c=`${n}.${r}`;return xe(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 r=q(n.object,t),c=q(n.property,null),m=`${r}.${c}`;return xe(n,t,m),m}else throw new Error(`Unsupported node type: ${e.type}`)}function Ke(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function qt(e,t){let n=Ke(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 r;try{r=q(n,null)}catch(c){if(/Unsupported node type/.test(c.message))return 0;throw c}return t.additionalHooks.test(r)?0:-1}else return-1}}function Te(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Xt(r,t))return r;if(Je(r,t))for(let[c,m]of Object.entries(r))c!=="parent"&&(Ge(m)?(m.parent=r,n.push(m)):Array.isArray(m)&&m.forEach(h=>{Ge(h)&&(h.parent=r,n.push(h))}))}return null}function Gt(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 Ge(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Xt(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 Je(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Yt(e){return!1}var le=require("@typescript-eslint/utils");var Kt=le.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ze="no-call-with-explicit-generics",Jt=L({functions:U(M())}),Zt=Kt({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:[Jt]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:c}=r;c.type===le.AST_NODE_TYPES.Identifier&&n.has(c.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:c.name}})}}}}),Re={name:Ze,rule:Zt};var K=require("@typescript-eslint/utils"),Qt=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qe="no-call-with-inferred-generics",en=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(r=>[r.name,r]));return{CallExpression(r){let{callee:c}=r;if(c.type!==K.AST_NODE_TYPES.Identifier)return;let m=n.get(c.name);if(!m)return;let{minGenerics:h=1,allowAny:a,disallowTypes:i=t.disallowTypes}=m;(r.typeArguments?.params.length||0)<(h||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:c.name,minGenerics:h||0}}),!(a&&!i)&&r.typeArguments?.params?.some(o=>!a&&o.type===K.AST_NODE_TYPES.TSAnyKeyword||i&&o.type===K.AST_NODE_TYPES.TSTypeReference&&o.typeName.type===K.AST_NODE_TYPES.Identifier&&i.includes(o.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:c.name}})}}}}),we={name:Qe,rule:en};var re=require("@typescript-eslint/utils"),tn=re.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),et="no-commented-out-code",nn=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],rn=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],sn=tn({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 r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let c of nn)if(r.startsWith(c))return{wrongPattern:c};for(let c of rn)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 r=e.sourceCode.getAllComments();for(let c of r)if(c.type===re.TSESTree.AST_TOKEN_TYPES.Line||c.type===re.TSESTree.AST_TOKEN_TYPES.Block){let m=t(c.value);m&&e.report({node:c,messageId:"commentedOutCode",data:{wrongPattern:m.wrongPattern}})}}}}}),Ie={name:et,rule:sn};var tt=require("@typescript-eslint/utils"),on=tt.ESLintUtils.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.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ce={name:nt,rule:an};var G=require("@typescript-eslint/utils"),cn=G.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),it="no-non-camel-case-functions",ln=/^[a-z][a-zA-Z0-9]*$/;function rt(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 un=cn({name:it,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&&!ln.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===G.AST_NODE_TYPES.TSTypeReference?rt(n):n.type===G.AST_NODE_TYPES.TSUnionType&&n.types.some(c=>c.type===G.AST_NODE_TYPES.TSTypeReference&&rt(c))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),ke={name:it,rule:un};var st=require("@typescript-eslint/utils"),ue=jt(require("path"));var fn=st.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ot="no-relative-imports",pn=L({find:M(),replacement:M()}),mn=L({aliases:U(pn),rootDir:j(M()),allowNotFoundAliases:j(ce()),_dev_simulateFileName:j(M())}),dn=fn({name:ot,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:[mn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(h){return h.startsWith(".")||h.startsWith("..")}function c(h,a){let i=ue.default.dirname(a);return ue.default.resolve(i,h)}function m(h){let a=t.rootDir??process.cwd(),i=ue.default.relative(a,h);if(i.startsWith("."))return null;i.startsWith("/")||(i=`/${i}`);for(let{find:u,replacement:o}of t.aliases)if(i.startsWith(o)){let d=i.replace(o,u);return{alias:u,newPath:d}}return null}return{ImportDeclaration(h){let a=h.source.value;if(!r(a))return;let i=c(a,n),u=m(i);!u&&t.allowNotFoundAliases||e.report({node:h,messageId:u?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:u?.alias},fix:u?o=>o.replaceText(h.source,`'${u.newPath}'`):void 0})}}}}),ve={name:ot,rule:dn};var P=require("@typescript-eslint/utils");var gn=P.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function at(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 ct(e,...t){for(let n of t)e.set(...n);return e}var yn=L({forceCheckOnFCPropTypesWithName:j(U(M()))}),lt="no-unused-type-props-in-args",Ae=null,hn=gn({name:lt,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:[yn],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!Ae&&(Ae=n.map(a=>new RegExp(a)));function r(a,i,u,o,d=!0){let D=u.name,A=e.sourceCode.getScope(i).references.find(I=>I.identifier.name===D)?.resolved,_=a&&Ae?.some(I=>I.test(D));if(!A||!_&&A.references.filter(I=>I.isTypeReference).length>1)return;let E=A?.defs[0]?.node;if(!(d&&E?.parent?.type===P.AST_NODE_TYPES.ExportNamedDeclaration)){if(E?.type===P.AST_NODE_TYPES.TSTypeAliasDeclaration){c(a,i,o,E.typeAnnotation,!0);return}if(E?.type===P.AST_NODE_TYPES.TSInterfaceDeclaration){c(a,i,o,E.body,!0);return}}}function c(a,i,u,o,d){if(o.type===P.AST_NODE_TYPES.TSInterfaceBody){for(let D of o.body)D.type===P.AST_NODE_TYPES.TSPropertySignature&&D.key.type===P.AST_NODE_TYPES.Identifier&&u.set(D.key.name,D);return}if(o.type===P.AST_NODE_TYPES.TSTypeLiteral){ct(u,...at(o));return}if(o.type===P.AST_NODE_TYPES.TSIntersectionType){for(let D of o.types)c(a,i,u,D,!0);return}d||o.type===P.AST_NODE_TYPES.TSTypeReference&&o.typeName.type===P.AST_NODE_TYPES.Identifier&&r(a,i,o.typeName,u)}function m(a,i,u){for(let o of u)if(o.type==="ObjectPattern"&&o.typeAnnotation){let d=new Map;if(c(a,i,d,o.typeAnnotation.typeAnnotation,!1),d.size===0)continue;h(o,d)}else o.type===P.AST_NODE_TYPES.AssignmentPattern&&o.left.type===P.AST_NODE_TYPES.ObjectPattern&&m(a,i,[o.left])}function h(a,i){let u=[];if(a.properties.at(-1)?.type===P.AST_NODE_TYPES.RestElement)return;for(let A of a.properties)A.type===P.AST_NODE_TYPES.Property&&A.key.type===P.AST_NODE_TYPES.Identifier&&u.push(A.key.name);let d=[],D=[];for(let[A,_]of i)u.includes(A)||(D.push(A),d.push({node:_,messageId:"unusedObjectTypeProperty",data:{propertyName:A}}));for(let[A,_]of d.entries())e.report({..._,fix:A===d.length-1?E=>{let I=a.properties.at(-1),g=D.join(", ");return I?I?.type===P.AST_NODE_TYPES.RestElement?null:E.insertTextAfter(I,`, ${g}`):E.insertTextBeforeRange([a.range[0]+1,a.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(a){let i=a.declarations[0];if(!i)return;let u=new Map,o=i.id.type===P.AST_NODE_TYPES.Identifier&&i.id.typeAnnotation?.typeAnnotation.type===P.AST_NODE_TYPES.TSTypeReference&&i.id.typeAnnotation.typeAnnotation.typeName.type===P.AST_NODE_TYPES.Identifier&&i.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&i.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(o){if(o.type===P.AST_NODE_TYPES.TSTypeReference&&o.typeName.type===P.AST_NODE_TYPES.Identifier)r(!0,a,o.typeName,u,!1);else if(o.type===P.AST_NODE_TYPES.TSTypeLiteral)ct(u,...at(o));else if(o.type===P.AST_NODE_TYPES.TSIntersectionType)for(let d of o.types)d.type===P.AST_NODE_TYPES.TSTypeReference&&d.typeName.type===P.AST_NODE_TYPES.Identifier?r(!0,a,d.typeName,u,!1):c(!0,a,u,d,!0);if(u.size!==0&&i.init?.type===P.AST_NODE_TYPES.ArrowFunctionExpression){let d=i.init.params[0];if(!d){e.report({node:i.init,messageId:"missingComponentParam"});return}d.type===P.AST_NODE_TYPES.ObjectPattern&&h(d,u)}}},FunctionDeclaration:function(a){m(!1,a,a.params)},ArrowFunctionExpression(a){m(!1,a,a.params)}}}}),$e={name:lt,rule:hn};var Z=require("@typescript-eslint/utils"),Sn=Z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ft="prefer-named-functions",ut=new Map,bn=Sn({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 r=ut.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),ut.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===Z.AST_NODE_TYPES.ArrowFunctionExpression&&r.id.type===Z.AST_NODE_TYPES.Identifier){let c=r.id.name;if(r.id.typeAnnotation||n&&n.test(c)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==Z.AST_NODE_TYPES.BlockStatement)return;let m=r.parent,h=r.init.params,a=r.init.body,i=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:c,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:u=>u.replaceText(m,`${i.async?"async ":""}function ${c}(${h.map(o=>e.sourceCode.getText(o)).join(", ")||""}) ${e.sourceCode.getText(a)}`)}]})}}}}}),De={name:ft,rule:bn};var N=require("@typescript-eslint/utils");var En=N.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),pt="prefer-single-line-if",xn=L({maxLineLength:j(te()),maxNonSimpleConditionLength:j(te())}),Tn=En({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:[xn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==N.AST_NODE_TYPES.BlockStatement||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let m=r.consequent.body[0];if(m.type===N.AST_NODE_TYPES.ReturnStatement){if(!(!m.argument||m.argument.type===N.AST_NODE_TYPES.Literal||m.argument.type===N.AST_NODE_TYPES.Identifier))return}else if(!(m.type===N.AST_NODE_TYPES.ContinueStatement||m.type===N.AST_NODE_TYPES.BreakStatement))return;if(r.test.type===N.AST_NODE_TYPES.LogicalExpression||r.test.type===N.AST_NODE_TYPES.ConditionalExpression)return;let h;if(t.maxNonSimpleConditionLength&&(r.test.type===N.AST_NODE_TYPES.CallExpression||r.test.type===N.AST_NODE_TYPES.BinaryExpression||r.test.type===N.AST_NODE_TYPES.MemberExpression)&&(h=n.getText(r.test),h.length>t.maxNonSimpleConditionLength))return;h||(h=n.getText(r.test));let a=n.getText(m);if(h.includes(`
|
|
13
|
+
`))return;let i=n.getTokenAfter(r);if(i&&i.type===N.AST_TOKEN_TYPES.Punctuator&&i.value==="}")return;let u=Rn(n,r),o=`if (${h}) ${a}`;t.maxLineLength&&o.length+u.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:d=>d.replaceText(r,o)})}}}});function Rn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Oe={name:pt,rule:Tn};var fe=require("@typescript-eslint/utils"),wn=fe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),mt="require-description",In=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Cn=/^eslint-disable-(next-)?line$/u,kn=wn({name:mt,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,r=new Set(t.ignore||[]);return{Program(){for(let c of n.getAllComments()){let m=vn(c);m!=null&&(r.has(m.kind)||m.description||e.report({loc:$n(c.loc),messageId:"missingDescription"}))}}}}}),dt={name:mt,rule:kn};function vn(e){let{text:t,description:n}=An(e.value);if(!t)return null;let r=In.exec(t);if(!r)return null;let c=r[1];if(!c)return null;let m=Cn.test(c);if(e.type===fe.TSESTree.AST_TOKEN_TYPES.Line&&!m||m&&e.loc.start.line!==e.loc.end.line)return null;let h=t.slice(r.index+c.length);return{kind:c,value:h.trim(),description:n}}function An(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function $n(e){return{start:{line:e.start.line,column:-1},end:e.end}}function ht(e){return/^use[A-Z0-9]/.test(e)}function pe(e){return e.type==="Identifier"?ht(e.name):e.type==="MemberExpression"&&!e.computed&&pe(e.property)?e.object.type==="Identifier":!1}function St(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function bt(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&&bt(e.parent.callee,"forwardRef"))}function xt(e){return!!(e.parent&&e.parent.callee&&bt(e.parent.callee,"memo"))}function Pe(e){for(;e;){let t=Rt(e);if(t&&(St(t)||pe(t))||Et(e)||xt(e))return!0;e=e.parent}return!1}function gt(e){return!1}function _e(e){return!1}var Dn=/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 i of e.sourceCode.getAllComments())if(Dn.test(i.value))return{CallExpression(u){let o=null;u.callee.name==="useMemo"?o="useMemo":u.callee.name==="useCallback"&&(o="useCallback"),o&&e.report({node:u,message:`"${o}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?i=>t(i):i=>e.sourceCode.getText(i),n=typeof e.getScope=="function"?()=>n():i=>e.sourceCode.getScope(i),r=null,c=[],m=[],h=new WeakSet;function a(i){for(let u of i.references){let o=u.identifier.parent;if(o.type==="VariableDeclarator"&&o.init&&o.init.type==="CallExpression"&&o.init.callee&>(o.init.callee))for(let d of u.resolved.references)d!==u&&h.add(d.identifier)}}return{onCodePathSegmentStart:i=>m.push(i),onCodePathSegmentEnd:()=>m.pop(),onCodePathStart:()=>c.push(new Map),onCodePathEnd(i,u){let o=c.pop();if(o.size===0)return;let d=new Set;function D(f,x){let{cache:T}=D,w=T.get(f.id),O=new Set(x);if(O.has(f.id)){let C=[...O],F=C.slice(C.indexOf(f.id)+1);for(let z of F)d.add(z);return BigInt("0")}if(O.add(f.id),w!==void 0)return w;if(i.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+=D(C,O)}return f.reachable&&w===BigInt("0")?T.delete(f.id):T.set(f.id,w),w}function A(f,x){let{cache:T}=A,w=T.get(f.id),O=new Set(x);if(O.has(f.id)){let C=Array.from(O),F=C.slice(C.indexOf(f.id)+1);for(let z of F)d.add(z);return BigInt("0")}if(O.add(f.id),w!==void 0)return w;if(i.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+=A(C,O)}return T.set(f.id,w),w}function _(f){let{cache:x}=_,T=x.get(f.id);if(T===null)return 1/0;if(T!==void 0)return T;if(x.set(f.id,null),f.prevSegments.length===0)T=1;else{T=1/0;for(let w of f.prevSegments){let O=_(w);O<T&&(T=O)}T+=1}return x.set(f.id,T),T}D.cache=new Map,A.cache=new Map,_.cache=new Map;let E=A(i.initialSegment),I=Rt(u),g=Pe(u),$=I?St(I)||pe(I):Et(u)||xt(u),R=1/0;for(let f of i.finalSegments){if(!f.reachable)continue;let x=_(f);x<R&&(R=x)}for(let[f,x]of o){if(!f.reachable)continue;let T=f.nextSegments.length===0?R<=_(f):R<_(f),w=D(f)*A(f),O=d.has(f.id);for(let C of x)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(u.async&&e.report({node:C,message:`React Hook "${t(C)}" cannot be called in an async function.`}),!O&&w!==E&&!_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.`+(T?" Did you accidentally call a React Hook after an early return?":"");e.report({node:C,message:z})}}else if(u.parent&&(u.parent.type==="MethodDefinition"||u.parent.type==="ClassProperty")&&u.parent.value===u){let F=`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:F})}else if(I){let F=`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:F})}else if(u.type==="Program"){let F=`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:F})}else if(g&&!_e(C)){if(u.parent.type==="CallExpression"&&u.parent.callee.type==="Identifier"&&u.parent.callee.name==="useCallback"){let z=u.parent;if(z.parent.type==="VariableDeclarator"&&ht(z.parent.id.name))return}let F=`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:F})}}},CallExpression(i){if(pe(i.callee)){let u=yt(c),o=yt(m),d=u.get(o);d||(d=[],u.set(o,d)),d.push(i.callee)}i.callee.type==="Identifier"&&(i.callee.name==="useEffect"||gt(i.callee))&&i.arguments.length>0&&(r=i)},Identifier(i){r==null&&h.has(i)&&i.parent.type!=="CallExpression"&&e.report({node:i,message:`\`${t(i)}\` 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"(i){i===r&&(r=null)},FunctionDeclaration(i){Pe(i)&&a(n(i))},ArrowFunctionExpression(i){Pe(i)&&a(n(i))}}}};function Rt(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={[$e.name]:$e.rule,[Ie.name]:Ie.rule,[we.name]:we.rule,"rules-of-hooks":Tt,"exhaustive-deps":Xe,"require-description":dt.rule,[Ce.name]:Ce.rule,[ke.name]:ke.rule,[De.name]:De.rule,[be.name]:be.rule,[Re.name]:Re.rule,[ve.name]:ve.rule,[Oe.name]:Oe.rule};var On={rules:wt};0&&(module.exports={extendedLintPlugin});
|
package/dist/extended-lint.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{AST_NODE_TYPES as
|
|
1
|
+
import{AST_NODE_TYPES as pe,ESLintUtils as Ct}from"@typescript-eslint/utils";var ue=Symbol.for("optional");function j(e){return{...e,[ue]:!0}}function Le(e,t){return{enum:e,...t}}function re(e){return{...e,type:"boolean"}}function M(e){return{...e,type:"string"}}function Z(e){return{...e,type:"number"}}function je(e){return{...e,type:"integer"}}function W(e,t){return{...t,type:"array",items:e}}function L(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let i,l=[];for(i in e)e[i][ue]?e[i][ue]=void 0:l.push(i);l.length>0&&(n.required=l)}return n}function fe(...e){return{anyOf:e}}var kt=Ct.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),vt=L({disallow:j(W(L({selector:M(),message:M(),replace:j(fe(M(),L({regex:M(),with:M()}))),replaceType:j(Le(["suggestion","autofix"]))}))),__dev_simulateFileName:j(M()),mustMatchSyntax:j(W(L({includeRegex:M(),mustCallFn:W(L({anyCall:W(L({fn:M(),withArgs:W(L({atIndex:je(),literal:fe(M(),Z(),re())}))})),message:j(M())}))})))}),We="advanced-no-restricted-syntax",At=kt({name:We,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[vt],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:i,__dev_simulateFileName:l,disallow:m}=t,h=l??e.filename,a=[],r=new Set;for(let{includeRegex:o,mustCallFn:d}of i??[]){let D=$t(h,new RegExp(o));if(!D)continue;let A=P=>{let E=P;for(let{name:I,value:g}of D)E=E.replaceAll(I,g);return E};for(let{anyCall:P,message:E}of d){let I=`Expected file to call the function: ${P.map(({fn:g})=>g).join(" or ")}`;r.add(I),a.push(g=>{let{callee:$}=g;if($.type===pe.Identifier){for(let{fn:R,withArgs:f}of P)if($.name===R){r.delete(I);for(let x of f){let T=g.arguments[x.atIndex],w=typeof x.literal=="string"?A(x.literal):x.literal;if(!T){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${w}" at index ${x.atIndex}${E?`: ${A(E)}`:""}`}});continue}if(T.type!==pe.Literal){e.report({node:T,messageId:"default",data:{message:`Argument at position ${x.atIndex} should the literal "${w}"${E?`: ${A(E)}`:""}`}});continue}T.value!==w&&e.report({node:T,messageId:"default",data:{message:`Argument should have the value "${w}"${E?`: ${A(E)}`:""}`},fix:O=>O.replaceText(T,typeof w=="string"?`'${w}'`:String(w))})}break}}})}}for(let{selector:o,message:d,replace:D,replaceType:A="suggestion"}of m??[]){if(o==="CallExpression"){a.push(P=>{u(D,P,d,A)});continue}n[o]=P=>{u(D,P,d,A)}}return a.length>0&&(n.CallExpression=o=>{if(o.type===pe.CallExpression)for(let d of a)d(o)}),n["Program:exit"]=o=>{for(let d of r)e.report({node:o,messageId:"default",data:{message:`${d}`}})},n;function u(o,d,D,A){let P=E=>{if(!o)return null;if(typeof o=="string")return E.replaceText(d,o);{let I=new RegExp(o.regex),g=e.sourceCode.getText(d);return E.replaceText(d,g.replace(I,o.with))}};e.report({node:d,messageId:"default",data:{message:D},fix:o&&A==="autofix"?P:void 0,suggest:o&&A==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof o=="string"?o:o.with}"`},fix:P}]:void 0})}}});function $t(e,t){let n=[],i=t.exec(e);if(!i)return null;let[l,...m]=i;n.push({name:"$0_lowercase",value:l.toLowerCase()}),n.push({name:"$0_capitalize",value:Ne(l)}),n.push({name:"$0_uncapitalize",value:He(l)}),n.push({name:"$0",value:l});for(let h=0;h<m.length;h++){let a=`$${h+1}`,r=m[h];n.push({name:`${a}_lowercase`,value:r.toLowerCase()}),n.push({name:`${a}_capitalize`,value:Ne(r)}),n.push({name:`${a}_uncapitalize`,value:He(r)}),n.push({name:a,value:r})}return n}function Ne(e){return e.charAt(0).toUpperCase()+e.slice(1)}function He(e){return e.charAt(0).toLowerCase()+e.slice(1)}var me={name:We,rule:At};var Dt=/eslint +react-compiler\/react-compiler: +\["error/,Ve={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),l=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,m=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,h={additionalHooks:l,enableDangerousAutofixThisMayCauseInfiniteLoops:m};function a(g){m&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let r=e.getSourceCode().scopeManager,u=new WeakMap,o=new WeakSet,d=new WeakMap,D=new WeakMap,A=new WeakSet;function P(g,$){return function(R){if($.has(R))return $.get(R);let f=g(R);return $.set(R,f),f}}function E(g,$,R,f,x){x&&g.async&&a({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 T=s.acquire(S),$=new Set,O=null;{let o=T.upper;for(;o&&($.add(o),o.type!=="function");)o=o.upper;if(!o)return;O=o}let w=Array.isArray;function F(o){if(!w(o.defs))return!1;let a=o.defs[0];if(a==null||a.node.type!=="VariableDeclarator")return!1;let m=a.node.init;if(m==null)return!1;for(;m.type==="TSAsExpression";)m=m.expression;let d=a.node.parent;if(d==null&&(ye(O.block,a.node.id),d=a.node.parent,d==null))return!1;if(d.kind==="const"&&m.type==="Literal"&&(typeof m.value=="string"||typeof m.value=="number"||m.value===null))return!0;if(m.type!=="CallExpression")return!1;let h=m.callee;if(h.type==="MemberExpression"&&h.object.name==="React"&&h.property!=null&&!h.computed&&(h=h.property),h.type!=="Identifier")return!1;let y=a.node.id,{name:I}=h;if(I==="useRef"&&y.type==="Identifier")return!0;if(Mt(h)&&y.type==="Identifier"){for(let C of o.references)C!==y&&P.add(C.identifier);return!0}else if(I==="useState"||I==="useReducer"){if(y.type==="ArrayPattern"&&y.elements.length===2&&w(o.identifiers)){if(y.elements[1]===o.identifiers[0]){if(I==="useState"){let C=o.references,H=0;for(let B=0;B<C.length;B++){if(C[B].isWrite()&&H++,H>1)return!1;r.set(C[B].identifier,y.elements[0])}}return!0}else if(y.elements[0]===o.identifiers[0]){if(I==="useState"){let C=o.references;for(let H=0;H<C.length;H++)p.add(C[H].identifier)}return!1}}}else if(I==="useTransition"&&y.type==="ArrayPattern"&&y.elements.length===2&&Array.isArray(o.identifiers)&&y.elements[1]===o.identifiers[0])return!0;return!1}function z(o){if(!w(o.defs))return!1;let a=o.defs[0];if(a==null||a.node==null||a.node.id==null)return!1;let m=a.node,d=O.childScopes,h=null,y;for(y=0;y<d.length;y++){let I=d[y],C=I.block;if(m.type==="FunctionDeclaration"&&C===m||m.type==="VariableDeclarator"&&C.parent===m){h=I;break}}if(h==null)return!1;for(y=0;y<h.through.length;y++){let I=h.through[y];if(I.resolved!=null&&$.has(I.resolved.scope)&&!De(I.resolved))return!1}return!0}let De=v(F,E),bt=v(z,k),Oe=new Map;function Et(o){let a=o.from,m=!1;for(;a.block!==S;)a.type==="function"&&(m=a.block.parent!=null&&a.block.parent.type==="ReturnStatement"),a=a.upper;return m}let N=new Map,oe=new Map;Pe(T);function Pe(o){for(let a of o.references){if(!a.resolved||!$.has(a.resolved.scope))continue;let m=ye(S,a.identifier),d=ze(m),h=q(d,oe);if(b&&d.type==="Identifier"&&(d.parent.type==="MemberExpression"||d.parent.type==="OptionalMemberExpression")&&!d.parent.computed&&d.parent.property.type==="Identifier"&&d.parent.property.name==="current"&&Et(a)&&Oe.set(h,{reference:a,dependencyNode:d}),d.parent.type==="TSTypeQuery"||d.parent.type==="TSTypeReference")continue;let y=a.resolved.defs[0];if(y!=null&&!(y.node!=null&&y.node.init===S.parent)&&y.type!=="TypeParameter")if(N.has(h))N.get(h).references.push(a);else{let I=a.resolved,C=De(I)||bt(I);N.set(h,{isStable:C,references:[a]})}}for(let a of o.childScopes)Pe(a)}Oe.forEach(({reference:o,dependencyNode:a},m)=>{let d=o.resolved.references,h=!1;for(let y=0;y<d.length;y++){let{identifier:I}=d[y],{parent:C}=I;if(C!=null&&C.type==="MemberExpression"&&!C.computed&&C.property.type==="Identifier"&&C.property.name==="current"&&C.parent.type==="AssignmentExpression"&&C.parent.left===C){h=!0;break}}h||l({node:a.parent.property,message:`The ref value '${m}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${m}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let ae=new Set;function xt(o,a){ae.has(a)||(ae.add(a),l({node:o,message:`Assignments to the '${a}' variable from inside React Hook ${n(R)} 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(R)}.`}))}let ee=new Set;if(N.forEach(({isStable:o,references:a},m)=>{o&&ee.add(m),a.forEach(d=>{d.writeExpr&&xt(d.writeExpr,m)})}),ae.size>0)return;if(!D){let o=null;if(N.forEach(({isStable:a,references:m},d)=>{o||m.forEach(h=>{if(o)return;let y=h.identifier;if(!r.has(y))return;let C=h.from;for(;C.type!=="function";)C=C.upper;C.block===S&&(o=d)})}),o){let{suggestedDependencies:a}=de({dependencies:N,declaredDependencies:[],stableDependencies:ee,externalDependencies:new Set,isEffect:!0});l({node:R,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 [`+a.join(", ")+`] as a second argument to the ${f} Hook.`,suggest:[{desc:`Add dependencies array: [${a.join(", ")}]`,fix(m){return m.insertTextAfter(S,`, [${a.join(", ")}]`)}}]})}return}let K=[],J=new Set;D.type!=="ArrayExpression"?l({node:D,message:`React Hook ${n(R)} 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(R)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}P.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(h){return h.removeRange(o.range)}}]});let a;try{a=q(o,oe)}catch(h){if(/Unsupported node type/.test(h.message)){o.type==="Literal"?N.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(R)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw h}let m=o;for(;m.type==="MemberExpression"||m.type==="OptionalMemberExpression"||m.type==="ChainExpression";)m=m.object||m.expression.object;let d=!O.through.some(h=>h.identifier===m);K.push({key:a,node:o}),d||J.add(a)});let{suggestedDependencies:Tt,unnecessaryDependencies:te,missingDependencies:G,duplicateDependencies:_e}=de({dependencies:N,declaredDependencies:K,stableDependencies:ee,externalDependencies:J,isEffect:b}),ne=Tt;if(_e.size+G.size+te.size===0){if(t)return;Ot({declaredDependencies:K,declaredDependenciesNode:D,componentScope:O,scope:T}).forEach(({construction:a,isUsedOutsideOfHook:m,depType:d})=>{let h=d==="function"?"useCallback":"useMemo",y=d==="function"?"definition":"initialization",I=`wrap the ${y} of '${a.name.name}' in its own ${h}() Hook.`,C=m?`To fix this, ${I}`:`Move it inside the ${f} callback. Alternatively, ${I}`,H=d==="conditional"||d==="logical expression"?"could make":"makes",B=`The '${a.name.name}' ${d} ${H} the dependencies of ${f} Hook (at line ${D.loc.start.line}) change on every render. ${C}`,Fe;m&&a.type==="Variable"&&d==="function"&&(Fe=[{desc:`Wrap the ${y} of '${a.name.name}' in its own ${h}() Hook.`,fix(Me){let[wt,It]=h==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Me.insertTextBefore(a.node.init,wt),Me.insertTextAfter(a.node.init,It)]}}]),l({node:a.node,message:B,suggest:Fe})});return}!b&&G.size>0&&(ne=de({dependencies:N,declaredDependencies:[],stableDependencies:ee,externalDependencies:J,isEffect:b}).suggestedDependencies);function Rt(){if(K.length===0)return!0;let o=K.map(m=>m.key),a=o.slice().sort();return o.join(",")===a.join(",")}Rt()&&ne.sort();function ce(o){let a=o.split("."),m="";for(let d=0;d<a.length;d++){if(d!==0){let h=a.slice(0,d+1).join("."),y=oe.get(h)===!0;m+=y?"?.":"."}m+=a[d]}return m}function le(o,a,m,d){return o.size===0?null:(o.size>1?"":a+" ")+m+" "+(o.size>1?"dependencies":"dependency")+": "+_t(Array.from(o).sort().map(h=>"'"+ce(h)+"'"))+`. Either ${d} ${o.size>1?"them":"it"} or remove the dependency array.`}let U="";if(te.size>0){let o=null;if(Array.from(te.keys()).forEach(a=>{o===null&&a.endsWith(".current")&&(o=a)}),o!==null)U=` Mutable values like '${o}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(J.size>0){let a=Array.from(J)[0];T.set.has(a)||(U=` Outer scope values like '${a}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!U&&G.has("props")){let o=N.get("props");if(o==null)return;let a=o.references;if(!Array.isArray(a))return;let m=!0;for(let d=0;d<a.length;d++){let h=a[d],y=ye(O.block,h.identifier);if(!y){m=!1;break}let I=y.parent;if(I==null){m=!1;break}if(I.type!=="MemberExpression"&&I.type!=="OptionalMemberExpression"){m=!1;break}}m&&(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(R)}.`)}if(!U&&G.size>0){let o=null;G.forEach(a=>{if(o)return;let m=O.set.get(a),d=N.get(a);if(d.references[0].resolved!==m)return;let h=m.defs[0];if(h==null||h.name==null||h.type!=="Parameter")return;let y=!1,I;for(let C=0;C<d.references.length;C++)if(I=d.references[C].identifier,I!=null&&I.parent!=null&&(I.parent.type==="CallExpression"||I.parent.type==="OptionalCallExpression")&&I.parent.callee===I){y=!0;break}y&&(o=a)}),o!==null&&(U=` If '${o}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!U&&G.size>0){let o=null;if(G.forEach(a=>{if(o!==null)return;let d=N.get(a).references,h,y;for(let I=0;I<d.length;I++){for(h=d[I].identifier,y=h.parent;y!=null&&y!==O.block;){if(y.type==="CallExpression"){let C=r.get(y.callee);if(C!=null){if(C.name===a)o={missingDep:a,setter:y.callee.name,form:"updater"};else if(p.has(h))o={missingDep:a,setter:y.callee.name,form:"reducer"};else{let H=d[I].resolved;if(H!=null){let B=H.defs[0];B!=null&&B.type==="Parameter"&&(o={missingDep:a,setter:y.callee.name,form:"inlineReducer"})}}break}}y=y.parent}if(o!==null)break}}),o!==null)switch(o.form){case"reducer":U=` You can also replace multiple useState variables with useReducer if '${o.setter}' needs the current value of '${o.missingDep}'.`;break;case"inlineReducer":U=` 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":U=` 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(R)} has `+(le(G,"a","missing","include")||le(te,"an","unnecessary","exclude")||le(_e,"a","duplicate","omit"))+U,suggest:[{desc:`Update the dependencies array to be: [${ne.map(ce).join(", ")}]`,fix(o){return o.replaceText(D,`[${ne.map(ce).join(", ")}]`)}}]})}function A(S){let D=Pt(S.callee,c);if(D===-1)return;let R=S.arguments[D],f=S.callee,b=Be(f).name,T=S.arguments[D+1],$=/Effect($|[^a-z])/g.test(b);if(!R){l({node:f,message:`React Hook ${b} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!$)){if(!T&&!$){(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(R.type){case"FunctionExpression":case"ArrowFunctionExpression":x(R,T,f,b,$);return;case"Identifier":if(!T||T.elements&&T.elements.some(F=>F&&F.type==="Identifier"&&F.name===R.name))return;let O=i(S).set.get(R.name);if(O==null||O.defs==null)return;let w=O.defs[0];if(!w||!w.node||w.type!=="Variable"&&w.type!=="FunctionName")break;switch(w.node.type){case"FunctionDeclaration":x(w.node,T,f,b,$);return;case"VariableDeclarator":let F=w.node.init;if(!F)break;switch(F.type){case"ArrowFunctionExpression":case"FunctionExpression":x(F,T,f,b,$);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: '${R.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${R.name}]`,fix(O){return O.replaceText(T,`[${R.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let S of e.sourceCode.getAllComments())if(Dt.test(S.value))return t=!0,{CallExpression:D=>A(D,!0)}}return{CallExpression:S=>A(S)}}};function de({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:i,isEffect:u}){let g=c();function c(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((x,A)=>{let S=l(g,A);S.isUsed=!0,s(g,A,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:x})=>{let A=l(g,x);A.isSatisfiedRecursively=!0}),n.forEach(x=>{let A=l(g,x);A.isSatisfiedRecursively=!0});function l(x,A){let S=A.split("."),D=x;for(let R of S){let f=D.children.get(R);f||(f=c(),D.children.set(R,f)),D=f}return D}function s(x,A,S){let D=A.split("."),R=x;for(let f of D){let b=R.children.get(f);if(!b)return;S(b),R=b}}let r=new Set,p=new Set;E(g,r,p,x=>x);function E(x,A,S,D){x.children.forEach((R,f)=>{let b=D(f);if(R.isSatisfiedRecursively){R.isSubtreeUsed&&S.add(b);return}if(R.isUsed){A.add(b);return}E(R,A,S,T=>b+"."+T)})}let k=[],P=new Set,v=new Set;return t.forEach(({key:x})=>{p.has(x)?k.indexOf(x)===-1?k.push(x):v.add(x):P.add(x)}),r.forEach(x=>{k.push(x)}),{suggestedDependencies:k,unnecessaryDependencies:P,duplicateDependencies:v,missingDependencies:r}}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 Ot({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:i}){let u=e.map(({key:c})=>{let l=n.variables.find(r=>r.name===c);if(l==null)return null;let s=l.defs[0];if(s==null)return null;if(s.type==="Variable"&&s.node.type==="VariableDeclarator"&&s.node.id.type==="Identifier"&&s.node.init!=null){let r=X(s.node.init);if(r!=null)return[l,r]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[l,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[l,"class"]:null}).filter(Boolean);function g(c){let l=!1;for(let s=0;s<c.references.length;s++){let r=c.references[s];if(r.writeExpr){if(l)return!0;l=!0;continue}let p=r.from;for(;p!==i&&p!=null;)p=p.upper;if(p!==i&&!qe(t,r.identifier))return!0}return!1}return u.map(([c,l])=>({construction:c.defs[0],depType:l,isUsedOutsideOfHook:g(c)}))}function ze(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)?ze(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 q(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=q(e.object,t),i=q(e.property,null),u=`${n}.${i}`;return ge(e,t,u),u}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=q(e.object,t),i=q(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=q(n.object,t),u=q(n.property,null),g=`${i}.${u}`;return ge(n,t,g),g}else throw new Error(`Unsupported node type: ${e.type}`)}function Be(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Pt(e,t){let n=Be(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=q(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 ye(e,t){let n=[e],i=null;for(;n.length;){if(i=n.shift(),Ft(i,t))return i;if(qe(i,t))for(let[u,g]of Object.entries(i))u!=="parent"&&(Ue(g)?(g.parent=i,n.push(g)):Array.isArray(g)&&g.forEach(c=>{Ue(c)&&(c.parent=i,n.push(c))}))}return null}function _t(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 Ue(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ft(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 qe(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Mt(e){return!1}import{AST_NODE_TYPES as Lt,ESLintUtils as jt}from"@typescript-eslint/utils";var Nt=jt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ge="no-call-with-explicit-generics",Ht=L({functions:W(M())}),Wt=Nt({name:Ge,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:[Ht]},defaultOptions:[{functions:[]}],create(e){let t=e.options[0],n=new Set(t.functions);return{CallExpression(i){let{callee:u}=i;u.type===Lt.Identifier&&n.has(u.name)&&i.typeArguments&&e.report({node:i,messageId:"noExplicitGenerics",data:{functionName:u.name}})}}}}),he={name:Ge,rule:Wt};import{AST_NODE_TYPES as ie,ESLintUtils as Ut}from"@typescript-eslint/utils";var Vt=Ut.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Xe="no-call-with-inferred-generics",zt=Vt({name:Xe,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){let t=e.options[0],n=new Map(t.functions.map(i=>[i.name,i]));return{CallExpression(i){let{callee:u}=i;if(u.type!==ie.Identifier)return;let g=n.get(u.name);if(!g)return;let{minGenerics:c=1,allowAny:l,disallowTypes:s=t.disallowTypes}=g;(i.typeArguments?.params.length||0)<(c||0)&&e.report({node:i,messageId:"missingGenericDeclaration",data:{functionName:u.name,minGenerics:c||0}}),!(l&&!s)&&i.typeArguments?.params?.some(p=>!l&&p.type===ie.TSAnyKeyword||s&&p.type===ie.TSTypeReference&&p.typeName.type===ie.Identifier&&s.includes(p.typeName.name))&&e.report({node:i,messageId:"anyUsedInGenerics",data:{functionName:u.name}})}}}}),Se={name:Xe,rule:zt};import{ESLintUtils as Bt,TSESTree as Ye}from"@typescript-eslint/utils";var qt=Bt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ke="no-commented-out-code",Gt=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Xt=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Yt=qt({name:Ke,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:function(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 Gt)if(i.startsWith(u))return{wrongPattern:u};for(let u of Xt)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===Ye.AST_TOKEN_TYPES.Line||u.type===Ye.AST_TOKEN_TYPES.Block){let g=t(u.value);g&&e.report({node:u,messageId:"commentedOutCode",data:{wrongPattern:g.wrongPattern}})}}}}}),be={name:Ke,rule:Yt};import{ESLintUtils as Kt}from"@typescript-eslint/utils";var Jt=Kt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Je="no-default-export",Zt=Jt({name:Je,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.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ee={name:Je,rule:Zt};import{AST_NODE_TYPES as Y,ESLintUtils as Qt}from"@typescript-eslint/utils";var en=Qt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qe="no-non-camel-case-functions",tn=/^[a-z][a-zA-Z0-9]*$/;function Ze(e){return e.typeName.type===Y.TSQualifiedName&&e.typeName.left.type===Y.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===Y.Identifier&&e.typeName.right.name==="Element"}var nn=en({name:Qe,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&&!tn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===Y.TSTypeReference?Ze(n):n.type===Y.TSUnionType&&n.types.some(u=>u.type===Y.TSTypeReference&&Ze(u))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),xe={name:Qe,rule:nn};import{ESLintUtils as rn}from"@typescript-eslint/utils";import Te from"node:path";var sn=rn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),et="no-relative-imports",on=L({find:M(),replacement:M()}),an=L({aliases:W(on),rootDir:j(M()),allowNotFoundAliases:j(re()),_dev_simulateFileName:j(M())}),cn=sn({name:et,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:[an]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e){let t=e.options[0],n=t._dev_simulateFileName??e.filename;function i(c){return c.startsWith(".")||c.startsWith("..")}function u(c,l){let s=Te.dirname(l);return Te.resolve(s,c)}function g(c){let l=t.rootDir??process.cwd(),s=Te.relative(l,c);if(s.startsWith("."))return null;s.startsWith("/")||(s=`/${s}`);for(let{find:r,replacement:p}of t.aliases)if(s.startsWith(p)){let E=s.replace(p,r);return{alias:r,newPath:E}}return null}return{ImportDeclaration(c){let l=c.source.value;if(!i(l))return;let s=u(l,n),r=g(s);!r&&t.allowNotFoundAliases||e.report({node:c,messageId:r?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:r?.alias},fix:r?p=>p.replaceText(c.source,`'${r.newPath}'`):void 0})}}}}),Re={name:et,rule:cn};import{AST_NODE_TYPES as _,ESLintUtils as ln}from"@typescript-eslint/utils";var un=ln.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function tt(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 nt(e,...t){for(let n of t)e.set(...n);return e}var pn=L({forceCheckOnFCPropTypesWithName:j(W(M()))}),rt="no-unused-type-props-in-args",we=null,fn=un({name:rt,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:[pn],fixable:"code"},defaultOptions:[{}],create(e){let{forceCheckOnFCPropTypesWithName:t}=e.options[0];t&&!we&&(we=t.map(c=>new RegExp(c)));function n(c,l,s,r,p=!0){let E=s.name,k=e.sourceCode.getScope(l).references.find(x=>x.identifier.name===E)?.resolved,P=c&&we?.some(x=>x.test(E));if(!k||!P&&k.references.filter(x=>x.isTypeReference).length>1)return;let v=k?.defs[0]?.node;if(!(p&&v?.parent?.type===_.ExportNamedDeclaration)){if(v?.type===_.TSTypeAliasDeclaration){i(c,l,r,v.typeAnnotation,!0);return}if(v?.type===_.TSInterfaceDeclaration){i(c,l,r,v.body,!0);return}}}function i(c,l,s,r,p){if(r.type===_.TSInterfaceBody){for(let E of r.body)E.type===_.TSPropertySignature&&E.key.type===_.Identifier&&s.set(E.key.name,E);return}if(r.type===_.TSTypeLiteral){nt(s,...tt(r));return}if(r.type===_.TSIntersectionType){for(let E of r.types)i(c,l,s,E,!0);return}p||r.type===_.TSTypeReference&&r.typeName.type===_.Identifier&&n(c,l,r.typeName,s)}function u(c,l,s){for(let r of s)if(r.type==="ObjectPattern"&&r.typeAnnotation){let p=new Map;if(i(c,l,p,r.typeAnnotation.typeAnnotation,!1),p.size===0)continue;g(r,p)}else r.type===_.AssignmentPattern&&r.left.type===_.ObjectPattern&&u(c,l,[r.left])}function g(c,l){let s=[];if(c.properties.at(-1)?.type===_.RestElement)return;for(let k of c.properties)k.type===_.Property&&k.key.type===_.Identifier&&s.push(k.key.name);let p=[],E=[];for(let[k,P]of l)s.includes(k)||(E.push(k),p.push({node:P,messageId:"unusedObjectTypeProperty",data:{propertyName:k}}));for(let[k,P]of p.entries())e.report({...P,fix:k===p.length-1?v=>{let x=c.properties.at(-1),A=E.join(", ");return x?x?.type===_.RestElement?null:v.insertTextAfter(x,`, ${A}`):v.insertTextBeforeRange([c.range[0]+1,c.range[1]],`${A}`)}:void 0})}return{VariableDeclaration(c){let l=c.declarations[0];if(!l)return;let s=new Map,r=l.id.type===_.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===_.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===_.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(r){if(r.type===_.TSTypeReference&&r.typeName.type===_.Identifier)n(!0,c,r.typeName,s,!1);else if(r.type===_.TSTypeLiteral)nt(s,...tt(r));else if(r.type===_.TSIntersectionType)for(let p of r.types)p.type===_.TSTypeReference&&p.typeName.type===_.Identifier?n(!0,c,p.typeName,s,!1):i(!0,c,s,p,!0);if(s.size!==0&&l.init?.type===_.ArrowFunctionExpression){let p=l.init.params[0];if(!p){e.report({node:l.init,messageId:"missingComponentParam"});return}p.type===_.ObjectPattern&&g(p,s)}}},FunctionDeclaration:function(c){u(!1,c,c.params)},ArrowFunctionExpression(c){u(!1,c,c.params)}}}}),Ie={name:rt,rule:fn};import{AST_NODE_TYPES as Ce,ESLintUtils as mn}from"@typescript-eslint/utils";var dn=mn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),st="prefer-named-functions",it=new Map,gn=dn({name:st,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){let t=e.options[0],n=null;if(t.ignoreRegex){let i=it.get(t.ignoreRegex);i?n=i:(n=new RegExp(t.ignoreRegex),it.set(t.ignoreRegex,n))}return{VariableDeclarator(i){if(i.init&&i.init.type===Ce.ArrowFunctionExpression&&i.id.type===Ce.Identifier){let u=i.id.name;if(i.id.typeAnnotation||n&&n.test(u)||!t.disallowArrowFnWithImplicitReturns&&i.init.body.type!==Ce.BlockStatement)return;let g=i.parent,c=i.init.params,l=i.init.body,s=i.init;e.report({node:i.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:u,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:r=>r.replaceText(g,`${s.async?"async ":""}function ${u}(${c.map(p=>e.sourceCode.getText(p)).join(", ")||""}) ${e.sourceCode.getText(l)}`)}]})}}}}}),ke={name:st,rule:gn};import{AST_NODE_TYPES as V,AST_TOKEN_TYPES as yn,ESLintUtils as hn}from"@typescript-eslint/utils";var Sn=hn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ot="prefer-single-line-if",bn=L({maxLineLength:j(Z()),maxNonSimpleConditionLength:j(Z())}),En=Sn({name:ot,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:[bn]},defaultOptions:[{}],create(e){let t=e.options[0],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 g=i.consequent.body[0],c;if(g.type===V.ReturnStatement){if(!(!g.argument||g.argument.type===V.Literal||g.argument.type===V.Identifier)||g.argument&&(i.test.type===V.LogicalExpression||i.test.type===V.ConditionalExpression||t.maxNonSimpleConditionLength&&(i.test.type===V.CallExpression||i.test.type===V.BinaryExpression||i.test.type===V.MemberExpression)&&(c=n.getText(i.test),c.length>t.maxNonSimpleConditionLength)))return}else if(!(g.type===V.ContinueStatement||g.type===V.BreakStatement))return;c||(c=n.getText(i.test));let l=n.getText(g);if(c.includes(`
|
|
13
|
-
`))return;let
|
|
12
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let T=r.acquire(g),w=new Set,O=null;{let s=T.upper;for(;s&&(w.add(s),s.type!=="function");)s=s.upper;if(!s)return;O=s}let C=Array.isArray;function F(s){if(!C(s.defs))return!1;let c=s.defs[0];if(c==null||c.node.type!=="VariableDeclarator")return!1;let p=c.node.init;if(p==null)return!1;for(;p.type==="TSAsExpression";)p=p.expression;let y=c.node.parent;if(y==null&&(ye(O.block,c.node.id),y=c.node.parent,y==null))return!1;if(y.kind==="const"&&p.type==="Literal"&&(typeof p.value=="string"||typeof p.value=="number"||p.value===null))return!0;if(p.type!=="CallExpression")return!1;let b=p.callee;if(b.type==="MemberExpression"&&b.object.name==="React"&&b.property!=null&&!b.computed&&(b=b.property),b.type!=="Identifier")return!1;let S=c.node.id,{name:k}=b;if(k==="useRef"&&S.type==="Identifier")return!0;if(Mt(b)&&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 B=0;B<v.length;B++){if(v[B].isWrite()&&H++,H>1)return!1;u.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 H=0;H<v.length;H++)o.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 c=s.defs[0];if(c==null||c.node==null||c.node.id==null)return!1;let p=c.node,y=O.childScopes,b=null,S;for(S=0;S<y.length;S++){let k=y[S],v=k.block;if(p.type==="FunctionDeclaration"&&v===p||p.type==="VariableDeclarator"&&v.parent===p){b=k;break}}if(b==null)return!1;for(S=0;S<b.through.length;S++){let k=b.through[S];if(k.resolved!=null&&w.has(k.resolved.scope)&&!De(k.resolved))return!1}return!0}let De=P(F,d),bt=P(z,D),Oe=new Map;function Et(s){let c=s.from,p=!1;for(;c.block!==g;)c.type==="function"&&(p=c.block.parent!=null&&c.block.parent.type==="ReturnStatement"),c=c.upper;return p}let N=new Map,oe=new Map;Pe(T);function Pe(s){for(let c of s.references){if(!c.resolved||!w.has(c.resolved.scope))continue;let p=ye(g,c.identifier),y=ze(p),b=q(y,oe);if(x&&y.type==="Identifier"&&(y.parent.type==="MemberExpression"||y.parent.type==="OptionalMemberExpression")&&!y.parent.computed&&y.parent.property.type==="Identifier"&&y.parent.property.name==="current"&&Et(c)&&Oe.set(b,{reference:c,dependencyNode:y}),y.parent.type==="TSTypeQuery"||y.parent.type==="TSTypeReference")continue;let S=c.resolved.defs[0];if(S!=null&&!(S.node!=null&&S.node.init===g.parent)&&S.type!=="TypeParameter")if(N.has(b))N.get(b).references.push(c);else{let k=c.resolved,v=De(k)||bt(k);N.set(b,{isStable:v,references:[c]})}}for(let c of s.childScopes)Pe(c)}Oe.forEach(({reference:s,dependencyNode:c},p)=>{let y=s.resolved.references,b=!1;for(let S=0;S<y.length;S++){let{identifier:k}=y[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){b=!0;break}}b||a({node:c.parent.property,message:`The ref value '${p}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${p}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let ae=new Set;function xt(s,c){ae.has(c)||(ae.add(c),a({node:s,message:`Assignments to the '${c}' variable from inside React Hook ${n(R)} 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(R)}.`}))}let ee=new Set;if(N.forEach(({isStable:s,references:c},p)=>{s&&ee.add(p),c.forEach(y=>{y.writeExpr&&xt(y.writeExpr,p)})}),ae.size>0)return;if(!$){let s=null;if(N.forEach(({isStable:c,references:p},y)=>{s||p.forEach(b=>{if(s)return;let S=b.identifier;if(!u.has(S))return;let v=b.from;for(;v.type!=="function";)v=v.upper;v.block===g&&(s=y)})}),s){let{suggestedDependencies:c}=de({dependencies:N,declaredDependencies:[],stableDependencies:ee,externalDependencies:new Set,isEffect:!0});a({node:R,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 [`+c.join(", ")+`] as a second argument to the ${f} Hook.`,suggest:[{desc:`Add dependencies array: [${c.join(", ")}]`,fix(p){return p.insertTextAfter(g,`, [${c.join(", ")}]`)}}]})}return}let K=[],J=new Set;$.type!=="ArrayExpression"?a({node:$,message:`React Hook ${n(R)} 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"){a({node:s,message:`React Hook ${n(R)} 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)&&a({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(b){return b.removeRange(s.range)}}]});let c;try{c=q(s,oe)}catch(b){if(/Unsupported node type/.test(b.message)){s.type==="Literal"?N.has(s.value)?a({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?`}):a({node:s,message:`The ${s.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):a({node:s,message:`React Hook ${n(R)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw b}let p=s;for(;p.type==="MemberExpression"||p.type==="OptionalMemberExpression"||p.type==="ChainExpression";)p=p.object||p.expression.object;let y=!O.through.some(b=>b.identifier===p);K.push({key:c,node:s}),y||J.add(c)});let{suggestedDependencies:Tt,unnecessaryDependencies:te,missingDependencies:G,duplicateDependencies:_e}=de({dependencies:N,declaredDependencies:K,stableDependencies:ee,externalDependencies:J,isEffect:x}),ne=Tt;if(_e.size+G.size+te.size===0){if(t)return;Ot({declaredDependencies:K,declaredDependenciesNode:$,componentScope:O,scope:T}).forEach(({construction:c,isUsedOutsideOfHook:p,depType:y})=>{let b=y==="function"?"useCallback":"useMemo",S=y==="function"?"definition":"initialization",k=`wrap the ${S} of '${c.name.name}' in its own ${b}() Hook.`,v=p?`To fix this, ${k}`:`Move it inside the ${f} callback. Alternatively, ${k}`,H=y==="conditional"||y==="logical expression"?"could make":"makes",B=`The '${c.name.name}' ${y} ${H} the dependencies of ${f} Hook (at line ${$.loc.start.line}) change on every render. ${v}`,Fe;p&&c.type==="Variable"&&y==="function"&&(Fe=[{desc:`Wrap the ${S} of '${c.name.name}' in its own ${b}() Hook.`,fix(Me){let[wt,It]=b==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Me.insertTextBefore(c.node.init,wt),Me.insertTextAfter(c.node.init,It)]}}]),a({node:c.node,message:B,suggest:Fe})});return}!x&&G.size>0&&(ne=de({dependencies:N,declaredDependencies:[],stableDependencies:ee,externalDependencies:J,isEffect:x}).suggestedDependencies);function Rt(){if(K.length===0)return!0;let s=K.map(p=>p.key),c=s.slice().sort();return s.join(",")===c.join(",")}Rt()&&ne.sort();function ce(s){let c=s.split("."),p="";for(let y=0;y<c.length;y++){if(y!==0){let b=c.slice(0,y+1).join("."),S=oe.get(b)===!0;p+=S?"?.":"."}p+=c[y]}return p}function le(s,c,p,y){return s.size===0?null:(s.size>1?"":c+" ")+p+" "+(s.size>1?"dependencies":"dependency")+": "+_t(Array.from(s).sort().map(b=>"'"+ce(b)+"'"))+`. Either ${y} ${s.size>1?"them":"it"} or remove the dependency array.`}let U="";if(te.size>0){let s=null;if(Array.from(te.keys()).forEach(c=>{s===null&&c.endsWith(".current")&&(s=c)}),s!==null)U=` Mutable values like '${s}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(J.size>0){let c=Array.from(J)[0];T.set.has(c)||(U=` Outer scope values like '${c}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!U&&G.has("props")){let s=N.get("props");if(s==null)return;let c=s.references;if(!Array.isArray(c))return;let p=!0;for(let y=0;y<c.length;y++){let b=c[y],S=ye(O.block,b.identifier);if(!S){p=!1;break}let k=S.parent;if(k==null){p=!1;break}if(k.type!=="MemberExpression"&&k.type!=="OptionalMemberExpression"){p=!1;break}}p&&(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(R)}.`)}if(!U&&G.size>0){let s=null;G.forEach(c=>{if(s)return;let p=O.set.get(c),y=N.get(c);if(y.references[0].resolved!==p)return;let b=p.defs[0];if(b==null||b.name==null||b.type!=="Parameter")return;let S=!1,k;for(let v=0;v<y.references.length;v++)if(k=y.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=c)}),s!==null&&(U=` If '${s}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!U&&G.size>0){let s=null;if(G.forEach(c=>{if(s!==null)return;let y=N.get(c).references,b,S;for(let k=0;k<y.length;k++){for(b=y[k].identifier,S=b.parent;S!=null&&S!==O.block;){if(S.type==="CallExpression"){let v=u.get(S.callee);if(v!=null){if(v.name===c)s={missingDep:c,setter:S.callee.name,form:"updater"};else if(o.has(b))s={missingDep:c,setter:S.callee.name,form:"reducer"};else{let H=y[k].resolved;if(H!=null){let B=H.defs[0];B!=null&&B.type==="Parameter"&&(s={missingDep:c,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.")}}a({node:$,message:`React Hook ${n(R)} has `+(le(G,"a","missing","include")||le(te,"an","unnecessary","exclude")||le(_e,"a","duplicate","omit"))+U,suggest:[{desc:`Update the dependencies array to be: [${ne.map(ce).join(", ")}]`,fix(s){return s.replaceText($,`[${ne.map(ce).join(", ")}]`)}}]})}function I(g){let $=Pt(g.callee,h);if($===-1)return;let R=g.arguments[$],f=g.callee,x=Be(f).name,T=g.arguments[$+1],w=/Effect($|[^a-z])/g.test(x);if(!R){a({node:f,message:`React Hook ${x} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!w)){if(!T&&!w){(x==="useMemo"||x==="useCallback")&&a({node:f,message:`React Hook ${x} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(R.type){case"FunctionExpression":case"ArrowFunctionExpression":E(R,T,f,x,w);return;case"Identifier":if(!T||T.elements&&T.elements.some(F=>F&&F.type==="Identifier"&&F.name===R.name))return;let O=i(g).set.get(R.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":E(C.node,T,f,x,w);return;case"VariableDeclarator":let F=C.node.init;if(!F)break;switch(F.type){case"ArrowFunctionExpression":case"FunctionExpression":E(F,T,f,x,w);return}break}break;default:a({node:f,message:`React Hook ${x} received a function whose dependencies are unknown. Pass an inline function instead.`});return}a({node:f,message:`React Hook ${x} has a missing dependency: '${R.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${R.name}]`,fix(O){return O.replaceText(T,`[${R.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(Dt.test(g.value))return t=!0,{CallExpression:$=>I($,!0)}}return{CallExpression:g=>I(g)}}};function de({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:i,isEffect:l}){let m=h();function h(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((E,I)=>{let g=a(m,I);g.isUsed=!0,r(m,I,$=>{$.isSubtreeUsed=!0})}),t.forEach(({key:E})=>{let I=a(m,E);I.isSatisfiedRecursively=!0}),n.forEach(E=>{let I=a(m,E);I.isSatisfiedRecursively=!0});function a(E,I){let g=I.split("."),$=E;for(let R of g){let f=$.children.get(R);f||(f=h(),$.children.set(R,f)),$=f}return $}function r(E,I,g){let $=I.split("."),R=E;for(let f of $){let x=R.children.get(f);if(!x)return;g(x),R=x}}let u=new Set,o=new Set;d(m,u,o,E=>E);function d(E,I,g,$){E.children.forEach((R,f)=>{let x=$(f);if(R.isSatisfiedRecursively){R.isSubtreeUsed&&g.add(x);return}if(R.isUsed){I.add(x);return}d(R,I,g,T=>x+"."+T)})}let D=[],A=new Set,P=new Set;return t.forEach(({key:E})=>{o.has(E)?D.indexOf(E)===-1?D.push(E):P.add(E):A.add(E)}),u.forEach(E=>{D.push(E)}),{suggestedDependencies:D,unnecessaryDependencies:A,duplicateDependencies:P,missingDependencies:u}}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 Ot({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:i}){let l=e.map(({key:h})=>{let a=n.variables.find(u=>u.name===h);if(a==null)return null;let r=a.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 u=X(r.node.init);if(u!=null)return[a,u]}return r.type==="FunctionName"&&r.node.type==="FunctionDeclaration"?[a,"function"]:r.type==="ClassName"&&r.node.type==="ClassDeclaration"?[a,"class"]:null}).filter(Boolean);function m(h){let a=!1;for(let r=0;r<h.references.length;r++){let u=h.references[r];if(u.writeExpr){if(a)return!0;a=!0;continue}let o=u.from;for(;o!==i&&o!=null;)o=o.upper;if(o!==i&&!qe(t,u.identifier))return!0}return!1}return l.map(([h,a])=>({construction:h.defs[0],depType:a,isUsedOutsideOfHook:m(h)}))}function ze(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)?ze(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 q(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=q(e.object,t),i=q(e.property,null),l=`${n}.${i}`;return ge(e,t,l),l}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=q(e.object,t),i=q(e.property,null),l=`${n}.${i}`;return ge(e,t,l),l}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=q(n.object,t),l=q(n.property,null),m=`${i}.${l}`;return ge(n,t,m),m}else throw new Error(`Unsupported node type: ${e.type}`)}function Be(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Pt(e,t){let n=Be(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=q(n,null)}catch(l){if(/Unsupported node type/.test(l.message))return 0;throw l}return t.additionalHooks.test(i)?0:-1}else return-1}}function ye(e,t){let n=[e],i=null;for(;n.length;){if(i=n.shift(),Ft(i,t))return i;if(qe(i,t))for(let[l,m]of Object.entries(i))l!=="parent"&&(Ue(m)?(m.parent=i,n.push(m)):Array.isArray(m)&&m.forEach(h=>{Ue(h)&&(h.parent=i,n.push(h))}))}return null}function _t(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 Ue(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ft(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 qe(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Mt(e){return!1}import{AST_NODE_TYPES as Lt,ESLintUtils as jt}from"@typescript-eslint/utils";var Nt=jt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ge="no-call-with-explicit-generics",Ht=L({functions:W(M())}),Wt=Nt({name:Ge,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:[Ht]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(i){let{callee:l}=i;l.type===Lt.Identifier&&n.has(l.name)&&i.typeArguments&&e.report({node:i,messageId:"noExplicitGenerics",data:{functionName:l.name}})}}}}),he={name:Ge,rule:Wt};import{AST_NODE_TYPES as ie,ESLintUtils as Ut}from"@typescript-eslint/utils";var Vt=Ut.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Xe="no-call-with-inferred-generics",zt=Vt({name:Xe,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:l}=i;if(l.type!==ie.Identifier)return;let m=n.get(l.name);if(!m)return;let{minGenerics:h=1,allowAny:a,disallowTypes:r=t.disallowTypes}=m;(i.typeArguments?.params.length||0)<(h||0)&&e.report({node:i,messageId:"missingGenericDeclaration",data:{functionName:l.name,minGenerics:h||0}}),!(a&&!r)&&i.typeArguments?.params?.some(o=>!a&&o.type===ie.TSAnyKeyword||r&&o.type===ie.TSTypeReference&&o.typeName.type===ie.Identifier&&r.includes(o.typeName.name))&&e.report({node:i,messageId:"anyUsedInGenerics",data:{functionName:l.name}})}}}}),Se={name:Xe,rule:zt};import{ESLintUtils as Bt,TSESTree as Ye}from"@typescript-eslint/utils";var qt=Bt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ke="no-commented-out-code",Gt=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Xt=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Yt=qt({name:Ke,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 l of Gt)if(i.startsWith(l))return{wrongPattern:l};for(let l of Xt)if(typeof l=="string"){if(n.includes(l))return{wrongPattern:l}}else if(l.test(n))return{wrongPattern:`regex(${l.toString()})`};return!1}return{Program(){let i=e.sourceCode.getAllComments();for(let l of i)if(l.type===Ye.AST_TOKEN_TYPES.Line||l.type===Ye.AST_TOKEN_TYPES.Block){let m=t(l.value);m&&e.report({node:l,messageId:"commentedOutCode",data:{wrongPattern:m.wrongPattern}})}}}}}),be={name:Ke,rule:Yt};import{ESLintUtils as Kt}from"@typescript-eslint/utils";var Jt=Kt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Je="no-default-export",Zt=Jt({name:Je,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.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ee={name:Je,rule:Zt};import{AST_NODE_TYPES as Y,ESLintUtils as Qt}from"@typescript-eslint/utils";var en=Qt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qe="no-non-camel-case-functions",tn=/^[a-z][a-zA-Z0-9]*$/;function Ze(e){return e.typeName.type===Y.TSQualifiedName&&e.typeName.left.type===Y.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===Y.Identifier&&e.typeName.right.name==="Element"}var nn=en({name:Qe,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&&!tn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===Y.TSTypeReference?Ze(n):n.type===Y.TSUnionType&&n.types.some(l=>l.type===Y.TSTypeReference&&Ze(l))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),xe={name:Qe,rule:nn};import{ESLintUtils as rn}from"@typescript-eslint/utils";import Te from"node:path";var sn=rn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),et="no-relative-imports",on=L({find:M(),replacement:M()}),an=L({aliases:W(on),rootDir:j(M()),allowNotFoundAliases:j(re()),_dev_simulateFileName:j(M())}),cn=sn({name:et,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:[an]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function i(h){return h.startsWith(".")||h.startsWith("..")}function l(h,a){let r=Te.dirname(a);return Te.resolve(r,h)}function m(h){let a=t.rootDir??process.cwd(),r=Te.relative(a,h);if(r.startsWith("."))return null;r.startsWith("/")||(r=`/${r}`);for(let{find:u,replacement:o}of t.aliases)if(r.startsWith(o)){let d=r.replace(o,u);return{alias:u,newPath:d}}return null}return{ImportDeclaration(h){let a=h.source.value;if(!i(a))return;let r=l(a,n),u=m(r);!u&&t.allowNotFoundAliases||e.report({node:h,messageId:u?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:u?.alias},fix:u?o=>o.replaceText(h.source,`'${u.newPath}'`):void 0})}}}}),Re={name:et,rule:cn};import{AST_NODE_TYPES as _,ESLintUtils as ln}from"@typescript-eslint/utils";var un=ln.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function tt(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 nt(e,...t){for(let n of t)e.set(...n);return e}var fn=L({forceCheckOnFCPropTypesWithName:j(W(M()))}),rt="no-unused-type-props-in-args",we=null,pn=un({name:rt,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:[fn],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!we&&(we=n.map(a=>new RegExp(a)));function i(a,r,u,o,d=!0){let D=u.name,A=e.sourceCode.getScope(r).references.find(I=>I.identifier.name===D)?.resolved,P=a&&we?.some(I=>I.test(D));if(!A||!P&&A.references.filter(I=>I.isTypeReference).length>1)return;let E=A?.defs[0]?.node;if(!(d&&E?.parent?.type===_.ExportNamedDeclaration)){if(E?.type===_.TSTypeAliasDeclaration){l(a,r,o,E.typeAnnotation,!0);return}if(E?.type===_.TSInterfaceDeclaration){l(a,r,o,E.body,!0);return}}}function l(a,r,u,o,d){if(o.type===_.TSInterfaceBody){for(let D of o.body)D.type===_.TSPropertySignature&&D.key.type===_.Identifier&&u.set(D.key.name,D);return}if(o.type===_.TSTypeLiteral){nt(u,...tt(o));return}if(o.type===_.TSIntersectionType){for(let D of o.types)l(a,r,u,D,!0);return}d||o.type===_.TSTypeReference&&o.typeName.type===_.Identifier&&i(a,r,o.typeName,u)}function m(a,r,u){for(let o of u)if(o.type==="ObjectPattern"&&o.typeAnnotation){let d=new Map;if(l(a,r,d,o.typeAnnotation.typeAnnotation,!1),d.size===0)continue;h(o,d)}else o.type===_.AssignmentPattern&&o.left.type===_.ObjectPattern&&m(a,r,[o.left])}function h(a,r){let u=[];if(a.properties.at(-1)?.type===_.RestElement)return;for(let A of a.properties)A.type===_.Property&&A.key.type===_.Identifier&&u.push(A.key.name);let d=[],D=[];for(let[A,P]of r)u.includes(A)||(D.push(A),d.push({node:P,messageId:"unusedObjectTypeProperty",data:{propertyName:A}}));for(let[A,P]of d.entries())e.report({...P,fix:A===d.length-1?E=>{let I=a.properties.at(-1),g=D.join(", ");return I?I?.type===_.RestElement?null:E.insertTextAfter(I,`, ${g}`):E.insertTextBeforeRange([a.range[0]+1,a.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(a){let r=a.declarations[0];if(!r)return;let u=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,a,o.typeName,u,!1);else if(o.type===_.TSTypeLiteral)nt(u,...tt(o));else if(o.type===_.TSIntersectionType)for(let d of o.types)d.type===_.TSTypeReference&&d.typeName.type===_.Identifier?i(!0,a,d.typeName,u,!1):l(!0,a,u,d,!0);if(u.size!==0&&r.init?.type===_.ArrowFunctionExpression){let d=r.init.params[0];if(!d){e.report({node:r.init,messageId:"missingComponentParam"});return}d.type===_.ObjectPattern&&h(d,u)}}},FunctionDeclaration:function(a){m(!1,a,a.params)},ArrowFunctionExpression(a){m(!1,a,a.params)}}}}),Ie={name:rt,rule:pn};import{AST_NODE_TYPES as Ce,ESLintUtils as mn}from"@typescript-eslint/utils";var dn=mn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),st="prefer-named-functions",it=new Map,gn=dn({name:st,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=it.get(t.ignoreRegex);i?n=i:(n=new RegExp(t.ignoreRegex),it.set(t.ignoreRegex,n))}return{VariableDeclarator(i){if(i.init&&i.init.type===Ce.ArrowFunctionExpression&&i.id.type===Ce.Identifier){let l=i.id.name;if(i.id.typeAnnotation||n&&n.test(l)||!t.disallowArrowFnWithImplicitReturns&&i.init.body.type!==Ce.BlockStatement)return;let m=i.parent,h=i.init.params,a=i.init.body,r=i.init;e.report({node:i.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:l,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:u=>u.replaceText(m,`${r.async?"async ":""}function ${l}(${h.map(o=>e.sourceCode.getText(o)).join(", ")||""}) ${e.sourceCode.getText(a)}`)}]})}}}}}),ke={name:st,rule:gn};import{AST_NODE_TYPES as V,AST_TOKEN_TYPES as yn,ESLintUtils as hn}from"@typescript-eslint/utils";var Sn=hn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ot="prefer-single-line-if",bn=L({maxLineLength:j(Z()),maxNonSimpleConditionLength:j(Z())}),En=Sn({name:ot,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:[bn]},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 m=i.consequent.body[0];if(m.type===V.ReturnStatement){if(!(!m.argument||m.argument.type===V.Literal||m.argument.type===V.Identifier))return}else if(!(m.type===V.ContinueStatement||m.type===V.BreakStatement))return;if(i.test.type===V.LogicalExpression||i.test.type===V.ConditionalExpression)return;let h;if(t.maxNonSimpleConditionLength&&(i.test.type===V.CallExpression||i.test.type===V.BinaryExpression||i.test.type===V.MemberExpression)&&(h=n.getText(i.test),h.length>t.maxNonSimpleConditionLength))return;h||(h=n.getText(i.test));let a=n.getText(m);if(h.includes(`
|
|
13
|
+
`))return;let r=n.getTokenAfter(i);if(r&&r.type===yn.Punctuator&&r.value==="}")return;let u=xn(n,i),o=`if (${h}) ${a}`;t.maxLineLength&&o.length+u.length>t.maxLineLength||e.report({node:i,messageId:"noSingleLineCurly",fix:d=>d.replaceText(i,o)})}}}});function xn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var ve={name:ot,rule:En};import{ESLintUtils as Tn,TSESTree as Rn}from"@typescript-eslint/utils";var wn=Tn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),at="require-description",In=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Cn=/^eslint-disable-(next-)?line$/u,kn=wn({name:at,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 l of n.getAllComments()){let m=vn(l);m!=null&&(i.has(m.kind)||m.description||e.report({loc:$n(l.loc),messageId:"missingDescription"}))}}}}}),ct={name:at,rule:kn};function vn(e){let{text:t,description:n}=An(e.value);if(!t)return null;let i=In.exec(t);if(!i)return null;let l=i[1];if(!l)return null;let m=Cn.test(l);if(e.type===Rn.AST_TOKEN_TYPES.Line&&!m||m&&e.loc.start.line!==e.loc.end.line)return null;let h=t.slice(i.index+l.length);return{kind:l,value:h.trim(),description:n}}function An(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function $n(e){return{start:{line:e.start.line,column:-1},end:e.end}}function ft(e){return/^use[A-Z0-9]/.test(e)}function se(e){return e.type==="Identifier"?ft(e.name):e.type==="MemberExpression"&&!e.computed&&se(e.property)?e.object.type==="Identifier":!1}function pt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function mt(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function dt(e){return!!(e.parent&&e.parent.callee&&mt(e.parent.callee,"forwardRef"))}function gt(e){return!!(e.parent&&e.parent.callee&&mt(e.parent.callee,"memo"))}function Ae(e){for(;e;){let t=ht(e);if(t&&(pt(t)||se(t))||dt(e)||gt(e))return!0;e=e.parent}return!1}function lt(e){return!1}function $e(e){return!1}var Dn=/eslint +react-compiler\/react-compiler: +\["error/,yt={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(Dn.test(r.value))return{CallExpression(u){let o=null;u.callee.name==="useMemo"?o="useMemo":u.callee.name==="useCallback"&&(o="useCallback"),o&&e.report({node:u,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,l=[],m=[],h=new WeakSet;function a(r){for(let u of r.references){let o=u.identifier.parent;if(o.type==="VariableDeclarator"&&o.init&&o.init.type==="CallExpression"&&o.init.callee&<(o.init.callee))for(let d of u.resolved.references)d!==u&&h.add(d.identifier)}}return{onCodePathSegmentStart:r=>m.push(r),onCodePathSegmentEnd:()=>m.pop(),onCodePathStart:()=>l.push(new Map),onCodePathEnd(r,u){let o=l.pop();if(o.size===0)return;let d=new Set;function D(f,x){let{cache:T}=D,w=T.get(f.id),O=new Set(x);if(O.has(f.id)){let C=[...O],F=C.slice(C.indexOf(f.id)+1);for(let z of F)d.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+=D(C,O)}return f.reachable&&w===BigInt("0")?T.delete(f.id):T.set(f.id,w),w}function A(f,x){let{cache:T}=A,w=T.get(f.id),O=new Set(x);if(O.has(f.id)){let C=Array.from(O),F=C.slice(C.indexOf(f.id)+1);for(let z of F)d.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+=A(C,O)}return T.set(f.id,w),w}function P(f){let{cache:x}=P,T=x.get(f.id);if(T===null)return 1/0;if(T!==void 0)return T;if(x.set(f.id,null),f.prevSegments.length===0)T=1;else{T=1/0;for(let w of f.prevSegments){let O=P(w);O<T&&(T=O)}T+=1}return x.set(f.id,T),T}D.cache=new Map,A.cache=new Map,P.cache=new Map;let E=A(r.initialSegment),I=ht(u),g=Ae(u),$=I?pt(I)||se(I):dt(u)||gt(u),R=1/0;for(let f of r.finalSegments){if(!f.reachable)continue;let x=P(f);x<R&&(R=x)}for(let[f,x]of o){if(!f.reachable)continue;let T=f.nextSegments.length===0?R<=P(f):R<P(f),w=D(f)*A(f),O=d.has(f.id);for(let C of x)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(u.async&&e.report({node:C,message:`React Hook "${t(C)}" cannot be called in an async function.`}),!O&&w!==E&&!$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.`+(T?" Did you accidentally call a React Hook after an early return?":"");e.report({node:C,message:z})}}else if(u.parent&&(u.parent.type==="MethodDefinition"||u.parent.type==="ClassProperty")&&u.parent.value===u){let F=`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:F})}else if(I){let F=`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:F})}else if(u.type==="Program"){let F=`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:F})}else if(g&&!$e(C)){if(u.parent.type==="CallExpression"&&u.parent.callee.type==="Identifier"&&u.parent.callee.name==="useCallback"){let z=u.parent;if(z.parent.type==="VariableDeclarator"&&ft(z.parent.id.name))return}let F=`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:F})}}},CallExpression(r){if(se(r.callee)){let u=ut(l),o=ut(m),d=u.get(o);d||(d=[],u.set(o,d)),d.push(r.callee)}r.callee.type==="Identifier"&&(r.callee.name==="useEffect"||lt(r.callee))&&r.arguments.length>0&&(i=r)},Identifier(r){i==null&&h.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){Ae(r)&&a(n(r))},ArrowFunctionExpression(r){Ae(r)&&a(n(r))}}}};function ht(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 ut(e){return e[e.length-1]}var St={[Ie.name]:Ie.rule,[be.name]:be.rule,[Se.name]:Se.rule,"rules-of-hooks":yt,"exhaustive-deps":Ve,"require-description":ct.rule,[Ee.name]:Ee.rule,[xe.name]:xe.rule,[ke.name]:ke.rule,[me.name]:me.rule,[he.name]:he.rule,[Re.name]:Re.rule,[ve.name]:ve.rule};var Ir={rules:St};export{Ir as extendedLintPlugin};
|