@ls-stack/extended-lint 0.1.0 → 0.1.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.d.mts
CHANGED
package/dist/extended-lint.d.ts
CHANGED
package/dist/extended-lint.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ne=Object.defineProperty;var
|
|
1
|
+
"use strict";var ne=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var Ne=(e,t)=>{for(var s in t)ne(e,s,{get:t[s],enumerable:!0})},Ye=(e,t,s,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of qe(t))!Ke.call(e,c)&&c!==s&&ne(e,c,{get:()=>t[c],enumerable:!(u=Xe(t,c))||u.enumerable});return e};var Je=e=>Ye(ne({},"__esModule",{value:!0}),e);var St={};Ne(St,{extendedLintPlugin:()=>bt});module.exports=Je(St);var ge={meta:{type:"suggestion",docs:{description:"verifies the list of dependencies for Hooks like useEffect and similar",recommended:!0,url:"https://github.com/facebook/react/issues/14920"},fixable:"code",hasSuggestions:!0,schema:[{type:"object",additionalProperties:!1,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let t=typeof e.getSource=="function"?g=>t(g):g=>e.sourceCode.getText(g),s=typeof e.getScope=="function"?()=>s():g=>e.sourceCode.getScope(g),u=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,c=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,f={additionalHooks:u,enableDangerousAutofixThisMayCauseInfiniteLoops:c};function l(g){c&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let m=e.getSourceCode().scopeManager,i=new WeakMap,a=new WeakSet,w=new WeakMap,R=new WeakMap,M=new WeakSet;function O(g,$){return function(k){if($.has(k))return $.get(k);let I=g(k);return $.set(k,I),I}}function P(g,$,k,I,o){o&&g.async&&l({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
|
|
2
2
|
|
|
3
3
|
useEffect(() => {
|
|
4
4
|
async function fetchData() {
|
|
@@ -9,4 +9,4 @@ useEffect(() => {
|
|
|
9
9
|
fetchData();
|
|
10
10
|
}, [someId]); // Or [] if effect doesn't need props or state
|
|
11
11
|
|
|
12
|
-
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=p.acquire(g),C=new Set,S=null;{let t=x.upper;for(;t&&(C.add(t),t.type!=="function");)t=t.upper;if(!t)return;S=t}let M=Array.isArray;function E(t){if(!M(t.defs))return!1;let r=t.defs[0];if(r==null||r.node.type!=="VariableDeclarator")return!1;let c=r.node.init;if(c==null)return!1;for(;c.type==="TSAsExpression";)c=c.expression;let u=r.node.parent;if(u==null&&(ie(S.block,r.node.id),u=r.node.parent,u==null))return!1;if(u.kind==="const"&&c.type==="Literal"&&(typeof c.value=="string"||typeof c.value=="number"||c.value===null))return!0;if(c.type!=="CallExpression")return!1;let h=c.callee;if(h.type==="MemberExpression"&&h.object.name==="React"&&h.property!=null&&!h.computed&&(h=h.property),h.type!=="Identifier")return!1;let d=r.node.id,{name:b}=h;if(b==="useRef"&&d.type==="Identifier")return!0;if(Qe(h)&&d.type==="Identifier"){for(let T of t.references)T!==d&&D.add(T.identifier);return!0}else if(b==="useState"||b==="useReducer"){if(d.type==="ArrayPattern"&&d.elements.length===2&&M(t.identifiers)){if(d.elements[1]===t.identifiers[0]){if(b==="useState"){let T=t.references,j=0;for(let _=0;_<T.length;_++){if(T[_].isWrite()&&j++,j>1)return!1;s.set(T[_].identifier,d.elements[0])}}return!0}else if(d.elements[0]===t.identifiers[0]){if(b==="useState"){let T=t.references;for(let j=0;j<T.length;j++)a.add(T[j].identifier)}return!1}}}else if(b==="useTransition"&&d.type==="ArrayPattern"&&d.elements.length===2&&Array.isArray(t.identifiers)&&d.elements[1]===t.identifiers[0])return!0;return!1}function H(t){if(!M(t.defs))return!1;let r=t.defs[0];if(r==null||r.node==null||r.node.id==null)return!1;let c=r.node,u=S.childScopes,h=null,d;for(d=0;d<u.length;d++){let b=u[d],T=b.block;if(c.type==="FunctionDeclaration"&&T===c||c.type==="VariableDeclarator"&&T.parent===c){h=b;break}}if(h==null)return!1;for(d=0;d<h.through.length;d++){let b=h.through[d];if(b.resolved!=null&&C.has(b.resolved.scope)&&!L(b.resolved))return!1}return!0}let L=O(E,w),Fe=O(H,R),ue=new Map;function je(t){let r=t.from,c=!1;for(;r.block!==g;)r.type==="function"&&(c=r.block.parent!=null&&r.block.parent.type==="ReturnStatement"),r=r.upper;return c}let F=new Map,Z=new Map;pe(x);function pe(t){for(let r of t.references){if(!r.resolved||!C.has(r.resolved.scope))continue;let c=ie(g,r.identifier),u=be(c),h=U(u,Z);if(o&&u.type==="Identifier"&&(u.parent.type==="MemberExpression"||u.parent.type==="OptionalMemberExpression")&&!u.parent.computed&&u.parent.property.type==="Identifier"&&u.parent.property.name==="current"&&je(r)&&ue.set(h,{reference:r,dependencyNode:u}),u.parent.type==="TSTypeQuery"||u.parent.type==="TSTypeReference")continue;let d=r.resolved.defs[0];if(d!=null&&!(d.node!=null&&d.node.init===g.parent)&&d.type!=="TypeParameter")if(F.has(h))F.get(h).references.push(r);else{let b=r.resolved,T=L(b)||Fe(b);F.set(h,{isStable:T,references:[r]})}}for(let r of t.childScopes)pe(r)}ue.forEach(({reference:t,dependencyNode:r},c)=>{let u=t.resolved.references,h=!1;for(let d=0;d<u.length;d++){let{identifier:b}=u[d],{parent:T}=b;if(T!=null&&T.type==="MemberExpression"&&!T.computed&&T.property.type==="Identifier"&&T.property.name==="current"&&T.parent.type==="AssignmentExpression"&&T.parent.left===T){h=!0;break}}h||l({node:r.parent.property,message:`The ref value '${c}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${c}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Q=new Set;function Le(t,r){Q.has(r)||(Q.add(r),l({node:t,message:`Assignments to the '${r}' variable from inside React Hook ${n(k)} 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(k)}.`}))}let N=new Set;if(F.forEach(({isStable:t,references:r},c)=>{t&&N.add(c),r.forEach(u=>{u.writeExpr&&Le(u.writeExpr,c)})}),Q.size>0)return;if(!v){let t=null;if(F.forEach(({isStable:r,references:c},u)=>{t||c.forEach(h=>{if(t)return;let d=h.identifier;if(!s.has(d))return;let T=h.from;for(;T.type!=="function";)T=T.upper;T.block===g&&(t=u)})}),t){let{suggestedDependencies:r}=re({dependencies:F,declaredDependencies:[],stableDependencies:N,externalDependencies:new Set,isEffect:!0});l({node:k,message:`React Hook ${I} contains a call to '${t}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+r.join(", ")+`] as a second argument to the ${I} Hook.`,suggest:[{desc:`Add dependencies array: [${r.join(", ")}]`,fix(c){return c.insertTextAfter(g,`, [${r.join(", ")}]`)}}]})}return}let G=[],X=new Set;v.type!=="ArrayExpression"?l({node:v,message:`React Hook ${n(k)} 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.`}):v.elements.forEach(t=>{if(t===null)return;if(t.type==="SpreadElement"){l({node:t,message:`React Hook ${n(k)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}D.has(t)&&l({node:t,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(t)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(t)}\``,fix(h){return h.removeRange(t.range)}}]});let r;try{r=U(t,Z)}catch(h){if(/Unsupported node type/.test(h.message)){t.type==="Literal"?F.has(t.value)?l({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. Did you mean to include ${t.value} in the array instead?`}):l({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:t,message:`React Hook ${n(k)} 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 c=t;for(;c.type==="MemberExpression"||c.type==="OptionalMemberExpression"||c.type==="ChainExpression";)c=c.object||c.expression.object;let u=!S.through.some(h=>h.identifier===c);G.push({key:r,node:t}),u||X.add(r)});let{suggestedDependencies:We,unnecessaryDependencies:Y,missingDependencies:V,duplicateDependencies:de}=re({dependencies:F,declaredDependencies:G,stableDependencies:N,externalDependencies:X,isEffect:o}),q=We;if(de.size+V.size+Y.size===0){Ye({declaredDependencies:G,declaredDependenciesNode:v,componentScope:S,scope:x}).forEach(({construction:r,isUsedOutsideOfHook:c,depType:u})=>{let h=u==="function"?"useCallback":"useMemo",d=u==="function"?"definition":"initialization",b=`wrap the ${d} of '${r.name.name}' in its own ${h}() Hook.`,T=c?`To fix this, ${b}`:`Move it inside the ${I} callback. Alternatively, ${b}`,j=u==="conditional"||u==="logical expression"?"could make":"makes",_=`The '${r.name.name}' ${u} ${j} the dependencies of ${I} Hook (at line ${v.loc.start.line}) change on every render. ${T}`,me;c&&r.type==="Variable"&&u==="function"&&(me=[{desc:`Wrap the ${d} of '${r.name.name}' in its own ${h}() Hook.`,fix(ye){let[Ue,Ve]=h==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[ye.insertTextBefore(r.node.init,Ue),ye.insertTextAfter(r.node.init,Ve)]}}]),l({node:r.node,message:_,suggest:me})});return}!o&&V.size>0&&(q=re({dependencies:F,declaredDependencies:[],stableDependencies:N,externalDependencies:X,isEffect:o}).suggestedDependencies);function _e(){if(G.length===0)return!0;let t=G.map(c=>c.key),r=t.slice().sort();return t.join(",")===r.join(",")}_e()&&q.sort();function ee(t){let r=t.split("."),c="";for(let u=0;u<r.length;u++){if(u!==0){let h=r.slice(0,u+1).join("."),d=Z.get(h)===!0;c+=d?"?.":"."}c+=r[u]}return c}function te(t,r,c,u){return t.size===0?null:(t.size>1?"":r+" ")+c+" "+(t.size>1?"dependencies":"dependency")+": "+Je(Array.from(t).sort().map(h=>"'"+ee(h)+"'"))+`. Either ${u} ${t.size>1?"them":"it"} or remove the dependency array.`}let W="";if(Y.size>0){let t=null;if(Array.from(Y.keys()).forEach(r=>{t===null&&r.endsWith(".current")&&(t=r)}),t!==null)W=` Mutable values like '${t}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(X.size>0){let r=Array.from(X)[0];x.set.has(r)||(W=` Outer scope values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!W&&V.has("props")){let t=F.get("props");if(t==null)return;let r=t.references;if(!Array.isArray(r))return;let c=!0;for(let u=0;u<r.length;u++){let h=r[u],d=ie(S.block,h.identifier);if(!d){c=!1;break}let b=d.parent;if(b==null){c=!1;break}if(b.type!=="MemberExpression"&&b.type!=="OptionalMemberExpression"){c=!1;break}}c&&(W=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${I} call and refer to those specific props inside ${n(k)}.`)}if(!W&&V.size>0){let t=null;V.forEach(r=>{if(t)return;let c=S.set.get(r),u=F.get(r);if(u.references[0].resolved!==c)return;let h=c.defs[0];if(h==null||h.name==null||h.type!=="Parameter")return;let d=!1,b;for(let T=0;T<u.references.length;T++)if(b=u.references[T].identifier,b!=null&&b.parent!=null&&(b.parent.type==="CallExpression"||b.parent.type==="OptionalCallExpression")&&b.parent.callee===b){d=!0;break}d&&(t=r)}),t!==null&&(W=` If '${t}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!W&&V.size>0){let t=null;if(V.forEach(r=>{if(t!==null)return;let u=F.get(r).references,h,d;for(let b=0;b<u.length;b++){for(h=u[b].identifier,d=h.parent;d!=null&&d!==S.block;){if(d.type==="CallExpression"){let T=s.get(d.callee);if(T!=null){if(T.name===r)t={missingDep:r,setter:d.callee.name,form:"updater"};else if(a.has(h))t={missingDep:r,setter:d.callee.name,form:"reducer"};else{let j=u[b].resolved;if(j!=null){let _=j.defs[0];_!=null&&_.type==="Parameter"&&(t={missingDep:r,setter:d.callee.name,form:"inlineReducer"})}}break}}d=d.parent}if(t!==null)break}}),t!==null)switch(t.form){case"reducer":W=` You can also replace multiple useState variables with useReducer if '${t.setter}' needs the current value of '${t.missingDep}'.`;break;case"inlineReducer":W=` If '${t.setter}' needs the current value of '${t.missingDep}', you can also switch to useReducer instead of useState and read '${t.missingDep}' in the reducer.`;break;case"updater":W=` You can also do a functional update '${t.setter}(${t.missingDep.slice(0,1)} => ...)' if you only need '${t.missingDep}' in the '${t.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:v,message:`React Hook ${n(k)} has `+(te(V,"a","missing","include")||te(Y,"an","unnecessary","exclude")||te(de,"a","duplicate","omit"))+W,suggest:[{desc:`Update the dependencies array to be: [${q.map(ee).join(", ")}]`,fix(t){return t.replaceText(v,`[${q.map(ee).join(", ")}]`)}}]})}function $(g){let v=qe(g.callee,f);if(v===-1)return;let k=g.arguments[v],I=g.callee,o=Se(I).name,x=g.arguments[v+1],C=/Effect($|[^a-z])/g.test(o);if(!k){l({node:I,message:`React Hook ${o} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!x&&!C){(o==="useMemo"||o==="useCallback")&&l({node:I,message:`React Hook ${o} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(k.type){case"FunctionExpression":case"ArrowFunctionExpression":P(k,x,I,o,C);return;case"Identifier":if(!x||x.elements&&x.elements.some(E=>E&&E.type==="Identifier"&&E.name===k.name))return;let S=i(g).set.get(k.name);if(S==null||S.defs==null)return;let M=S.defs[0];if(!M||!M.node||M.type!=="Variable"&&M.type!=="FunctionName")break;switch(M.node.type){case"FunctionDeclaration":P(M.node,x,I,o,C);return;case"VariableDeclarator":let E=M.node.init;if(!E)break;switch(E.type){case"ArrowFunctionExpression":case"FunctionExpression":P(E,x,I,o,C);return}break}break;default:l({node:I,message:`React Hook ${o} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:I,message:`React Hook ${o} has a missing dependency: '${k.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${k.name}]`,fix(S){return S.replaceText(x,`[${k.name}]`)}}]})}return{CallExpression:$}}};function re({dependencies:e,declaredDependencies:n,stableDependencies:i,externalDependencies:m,isEffect:y}){let f=l();function l(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach(($,g)=>{let v=p(f,g);v.isUsed=!0,s(f,g,k=>{k.isSubtreeUsed=!0})}),n.forEach(({key:$})=>{let g=p(f,$);g.isSatisfiedRecursively=!0}),i.forEach($=>{let g=p(f,$);g.isSatisfiedRecursively=!0});function p($,g){let v=g.split("."),k=$;for(let I of v){let o=k.children.get(I);o||(o=l(),k.children.set(I,o)),k=o}return k}function s($,g,v){let k=g.split("."),I=$;for(let o of k){let x=I.children.get(o);if(!x)return;v(x),I=x}}let a=new Set,w=new Set;R(f,a,w,$=>$);function R($,g,v,k){$.children.forEach((I,o)=>{let x=k(o);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&v.add(x);return}if(I.isUsed){g.add(x);return}R(I,g,v,C=>x+"."+C)})}let D=[],O=new Set,P=new Set;return n.forEach(({key:$})=>{w.has($)?D.indexOf($)===-1?D.push($):P.add($):O.add($)}),a.forEach($=>{D.push($)}),{suggestedDependencies:D,unnecessaryDependencies:O,duplicateDependencies:P,missingDependencies:a}}function z(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 z(e.consequent)!=null||z(e.alternate)!=null?"conditional":null;case"LogicalExpression":return z(e.left)!=null||z(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return z(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return z(e.expression);case"TSAsExpression":return z(e.expression)}return null}function Ye({declaredDependencies:e,declaredDependenciesNode:n,componentScope:i,scope:m}){let y=e.map(({key:l})=>{let p=i.variables.find(a=>a.name===l);if(p==null)return null;let s=p.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 a=z(s.node.init);if(a!=null)return[p,a]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[p,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[p,"class"]:null}).filter(Boolean);function f(l){let p=!1;for(let s=0;s<l.references.length;s++){let a=l.references[s];if(a.writeExpr){if(p)return!0;p=!0;continue}let w=a.from;for(;w!==m&&w!=null;)w=w.upper;if(w!==m&&!Ee(n,a.identifier))return!0}return!1}return y.map(([l,p])=>({construction:l.defs[0],depType:p,isUsedOutsideOfHook:f(l)}))}function be(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)?be(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function se(e,n,i){n&&(e.optional?n.has(i)||n.set(i,!0):n.has(i)||n.set(i,!1))}function U(e,n){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let i=e.name;return n&&n.set(i,!1),i}else if(e.type==="MemberExpression"&&!e.computed){let i=U(e.object,n),m=U(e.property,null),y=`${i}.${m}`;return se(e,n,y),y}else if(e.type==="OptionalMemberExpression"&&!e.computed){let i=U(e.object,n),m=U(e.property,null),y=`${i}.${m}`;return se(e,n,y),y}else if(e.type==="ChainExpression"&&!e.computed){let i=e.expression;if(i.type==="CallExpression")throw new Error(`Unsupported node type: ${i.type}`);let m=U(i.object,n),y=U(i.property,null),f=`${m}.${y}`;return se(i,n,f),f}else throw new Error(`Unsupported node type: ${e.type}`)}function Se(e,n){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function qe(e,n){let i=Se(e);if(i.type!=="Identifier")return-1;switch(i.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(i===e&&n&&n.additionalHooks){let m;try{m=U(i,null)}catch(y){if(/Unsupported node type/.test(y.message))return 0;throw y}return n.additionalHooks.test(m)?0:-1}else return-1}}function ie(e,n){let i=[e],m=null;for(;i.length;){if(m=i.shift(),Ze(m,n))return m;if(Ee(m,n))for(let[y,f]of Object.entries(m))y!=="parent"&&(he(f)?(f.parent=m,i.push(f)):Array.isArray(f)&&f.forEach(l=>{he(l)&&(l.parent=m,i.push(l))}))}return null}function Je(e){let n="";for(let i=0;i<e.length;i++)n+=e[i],i===0&&e.length===2?n+=" and ":i===e.length-2&&e.length>2?n+=", and ":i<e.length-1&&(n+=", ");return n}function he(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ze(e,n){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===n.type&&e.name===n.name&&e.range[0]===n.range[0]&&e.range[1]===n.range[1]}function Ee(e,n){return e.range[0]<=n.range[0]&&e.range[1]>=n.range[1]}function Qe(e){return!1}var B=require("@typescript-eslint/utils"),et=B.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Te="no-call-with-infered-generics",tt=et({name:Te,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 n=e.options[0],i=new Map(n.functions.map(m=>[m.name,m]));return{CallExpression(m){let{callee:y}=m;if(y.type!==B.AST_NODE_TYPES.Identifier)return;let f=i.get(y.name);if(!f)return;let{minGenerics:l=1,allowAny:p,disallowTypes:s=n.disallowTypes}=f;(m.typeArguments?.params.length||0)<(l||0)&&e.report({node:m,messageId:"missingGenericDeclaration",data:{functionName:y.name,minGenerics:l||0}}),!(p&&!s)&&m.typeArguments?.params?.some(w=>!p&&w.type===B.AST_NODE_TYPES.TSAnyKeyword||s&&w.type===B.AST_NODE_TYPES.TSTypeReference&&w.typeName.type===B.AST_NODE_TYPES.Identifier&&s.includes(w.typeName.name))&&e.report({node:m,messageId:"anyUsedInGenerics",data:{functionName:y.name}})}}}}),oe={name:Te,rule:tt};var K=require("@typescript-eslint/utils"),nt=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ke="no-commented-out-code",rt=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],st=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],it=nt({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 n(i){if(i.startsWith("/"))return!1;let m=i.trimStart();if(i.startsWith("*")||m.startsWith("INFO:")||m.startsWith("TODO:")||m.startsWith("FIX:")||m.startsWith("eslint-disable")||i.includes("@deprecated")||i.includes("@example"))return!1;for(let y of rt)if(m.startsWith(y))return{wrongPattern:y};for(let y of st)if(typeof y=="string"){if(i.includes(y))return{wrongPattern:y}}else if(y.test(i))return{wrongPattern:`regex(${y.toString()})`};return!1}return{Program(){let m=e.sourceCode.getAllComments();for(let y of m)if(y.type===K.TSESTree.AST_TOKEN_TYPES.Line||y.type===K.TSESTree.AST_TOKEN_TYPES.Block){let f=n(y.value);f&&e.report({node:y,messageId:"commentedOutCode",data:{wrongPattern:f.wrongPattern}})}}}}}),ae={name:ke,rule:it};var A=require("@typescript-eslint/utils"),ot=A.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function we(e){let n=[];for(let i of e.members)i.type===A.AST_NODE_TYPES.TSPropertySignature&&i.key.type===A.AST_NODE_TYPES.Identifier&&n.push([i.key.name,i]);return n}function xe(e,...n){for(let i of n)e.set(...i);return e}var Ie="no-unused-type-props-in-args",at=ot({name:Ie,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used"},schema:[],fixable:"code"},defaultOptions:[],create:function(e){function n(f,l,p,s=!0){let a=l.name,w=e.sourceCode.getScope(f).references.find(D=>D.identifier.name===a)?.resolved;if(!w||w.references.filter(D=>D.isTypeReference).length>1)return;let R=w?.defs[0]?.node;if(!(s&&R?.parent?.type===A.AST_NODE_TYPES.ExportNamedDeclaration)){if(R?.type===A.AST_NODE_TYPES.TSTypeAliasDeclaration){i(f,p,R.typeAnnotation,!0);return}if(R?.type===A.AST_NODE_TYPES.TSInterfaceDeclaration){i(f,p,R.body,!0);return}}}function i(f,l,p,s){if(p.type===A.AST_NODE_TYPES.TSInterfaceBody){for(let a of p.body)a.type===A.AST_NODE_TYPES.TSPropertySignature&&a.key.type===A.AST_NODE_TYPES.Identifier&&l.set(a.key.name,a);return}if(p.type===A.AST_NODE_TYPES.TSTypeLiteral){xe(l,...we(p));return}if(p.type===A.AST_NODE_TYPES.TSIntersectionType){for(let a of p.types)i(f,l,a,!0);return}s||p.type===A.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===A.AST_NODE_TYPES.Identifier&&n(f,p.typeName,l)}function m(f,l){for(let p of l)if(p.type==="ObjectPattern"&&p.typeAnnotation){let s=new Map;if(i(f,s,p.typeAnnotation.typeAnnotation,!1),s.size===0)continue;y(p,s)}else p.type===A.AST_NODE_TYPES.AssignmentPattern&&p.left.type===A.AST_NODE_TYPES.ObjectPattern&&m(f,[p.left])}function y(f,l){let p=[];if(f.properties.at(-1)?.type===A.AST_NODE_TYPES.RestElement)return;for(let R of f.properties)R.type===A.AST_NODE_TYPES.Property&&R.key.type===A.AST_NODE_TYPES.Identifier&&p.push(R.key.name);let a=[],w=[];for(let[R,D]of l)p.includes(R)||(w.push(R),a.push({node:D,messageId:"unusedObjectTypeProperty",data:{propertyName:R}}));for(let[R,D]of a.entries())e.report({...D,fix:R===a.length-1?O=>{let P=f.properties.at(-1),$=w.join(", ");return P?P?.type===A.AST_NODE_TYPES.RestElement?null:O.insertTextAfter(P,`, ${$}`):O.insertTextBeforeRange([f.range[0]+1,f.range[1]],`${$}`)}:void 0})}return{VariableDeclaration:function(f){let l=f.declarations[0];if(!l)return;let p=new Map,s=l.id.type===A.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===A.AST_NODE_TYPES.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===A.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===A.AST_NODE_TYPES.TSTypeReference&&s.typeName.type===A.AST_NODE_TYPES.Identifier)n(f,s.typeName,p,!1);else if(s.type===A.AST_NODE_TYPES.TSTypeLiteral)xe(p,...we(s));else if(s.type===A.AST_NODE_TYPES.TSIntersectionType)for(let a of s.types)a.type===A.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===A.AST_NODE_TYPES.Identifier?n(f,a.typeName,p,!1):i(f,p,a,!0);if(p.size!==0&&l.init?.type===A.AST_NODE_TYPES.ArrowFunctionExpression){let a=l.init.params[0];a&&a.type===A.AST_NODE_TYPES.ObjectPattern&&y(a,p)}}},FunctionDeclaration:function(f){m(f,f.params)},ArrowFunctionExpression:function(f){m(f,f.params)}}}}),ce={name:Ie,rule:at};function Ce(e){return/^use[A-Z0-9]/.test(e)}function J(e){return e.type==="Identifier"?Ce(e.name):e.type==="MemberExpression"&&!e.computed&&J(e.property)?e.object.type==="Identifier":!1}function $e(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function ve(e,n){return e.name===n||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===n}function Me(e){return!!(e.parent&&e.parent.callee&&ve(e.parent.callee,"forwardRef"))}function De(e){return!!(e.parent&&e.parent.callee&&ve(e.parent.callee,"memo"))}function le(e){for(;e;){let n=Oe(e);if(n&&($e(n)||J(n))||Me(e)||De(e))return!0;e=e.parent}return!1}function Re(e){return!1}function fe(e){return!1}var Pe={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"}},create(e){let n=typeof e.getSource=="function"?s=>n(s):s=>e.sourceCode.getText(s),i=typeof e.getScope=="function"?()=>i():s=>e.sourceCode.getScope(s),m=null,y=[],f=[],l=new WeakSet;function p(s){for(let a of s.references){let w=a.identifier.parent;if(w.type==="VariableDeclarator"&&w.init&&w.init.type==="CallExpression"&&w.init.callee&&Re(w.init.callee))for(let R of a.resolved.references)R!==a&&l.add(R.identifier)}}return{onCodePathSegmentStart:s=>f.push(s),onCodePathSegmentEnd:()=>f.pop(),onCodePathStart:()=>y.push(new Map),onCodePathEnd(s,a){let w=y.pop();if(w.size===0)return;let R=new Set;function D(o,x){let{cache:C}=D,S=C.get(o.id),M=new Set(x);if(M.has(o.id)){let E=[...M],H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(M.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.prevSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.prevSegments)S+=D(E,M)}return o.reachable&&S===BigInt("0")?C.delete(o.id):C.set(o.id,S),S}function O(o,x){let{cache:C}=O,S=C.get(o.id),M=new Set(x);if(M.has(o.id)){let E=Array.from(M),H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(M.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.nextSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.nextSegments)S+=O(E,M)}return C.set(o.id,S),S}function P(o){let{cache:x}=P,C=x.get(o.id);if(C===null)return 1/0;if(C!==void 0)return C;if(x.set(o.id,null),o.prevSegments.length===0)C=1;else{C=1/0;for(let S of o.prevSegments){let M=P(S);M<C&&(C=M)}C+=1}return x.set(o.id,C),C}D.cache=new Map,O.cache=new Map,P.cache=new Map;let $=O(s.initialSegment),g=Oe(a),v=le(a),k=g?$e(g)||J(g):Me(a)||De(a),I=1/0;for(let o of s.finalSegments){if(!o.reachable)continue;let x=P(o);x<I&&(I=x)}for(let[o,x]of w){if(!o.reachable)continue;let C=o.nextSegments.length===0?I<=P(o):I<P(o),S=D(o)*O(o),M=R.has(o.id);for(let E of x)if(M&&!fe(E)&&e.report({node:E,message:`React Hook "${n(E)}" 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.`}),k){if(a.async&&e.report({node:E,message:`React Hook "${n(E)}" cannot be called in an async function.`}),!M&&S!==$&&!fe(E)){let L=`React Hook "${n(E)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(C?" Did you accidentally call a React Hook after an early return?":"");e.report({node:E,message:L})}}else if(a.parent&&(a.parent.type==="MethodDefinition"||a.parent.type==="ClassProperty")&&a.parent.value===a){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(g){let H=`React Hook "${n(E)}" is called in function "${n(g)}" 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:E,message:H})}else if(a.type==="Program"){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(v&&!fe(E)){if(a.parent.type==="CallExpression"&&a.parent.callee.type==="Identifier"&&a.parent.callee.name==="useCallback"){let L=a.parent;if(L.parent.type==="VariableDeclarator"&&Ce(L.parent.id.name))return}let H=`React Hook "${n(E)}" 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:E,message:H})}}},CallExpression(s){if(J(s.callee)){let a=Ae(y),w=Ae(f),R=a.get(w);R||(R=[],a.set(w,R)),R.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Re(s.callee))&&s.arguments.length>0&&(m=s)},Identifier(s){m==null&&l.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${n(s)}\` 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"(s){s===m&&(m=null)},FunctionDeclaration(s){le(s)&&p(i(s))},ArrowFunctionExpression(s){le(s)&&p(i(s))}}}};function Oe(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 Ae(e){return e[e.length-1]}var He={[ce.name]:ce.rule,[ae.name]:ae.rule,[oe.name]:oe.rule,"rules-of-hooks":Pe,"exhaustive-deps":ge};var ct={rules:He};0&&(module.exports={extendedLintPlugin});
|
|
12
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=m.acquire(g),C=new Set,S=null;{let n=x.upper;for(;n&&(C.add(n),n.type!=="function");)n=n.upper;if(!n)return;S=n}let D=Array.isArray;function E(n){if(!D(n.defs))return!1;let r=n.defs[0];if(r==null||r.node.type!=="VariableDeclarator")return!1;let p=r.node.init;if(p==null)return!1;for(;p.type==="TSAsExpression";)p=p.expression;let d=r.node.parent;if(d==null&&(ie(S.block,r.node.id),d=r.node.parent,d==null))return!1;if(d.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 h=p.callee;if(h.type==="MemberExpression"&&h.object.name==="React"&&h.property!=null&&!h.computed&&(h=h.property),h.type!=="Identifier")return!1;let y=r.node.id,{name:b}=h;if(b==="useRef"&&y.type==="Identifier")return!0;if(nt(h)&&y.type==="Identifier"){for(let T of n.references)T!==y&&M.add(T.identifier);return!0}else if(b==="useState"||b==="useReducer"){if(y.type==="ArrayPattern"&&y.elements.length===2&&D(n.identifiers)){if(y.elements[1]===n.identifiers[0]){if(b==="useState"){let T=n.references,j=0;for(let W=0;W<T.length;W++){if(T[W].isWrite()&&j++,j>1)return!1;i.set(T[W].identifier,y.elements[0])}}return!0}else if(y.elements[0]===n.identifiers[0]){if(b==="useState"){let T=n.references;for(let j=0;j<T.length;j++)a.add(T[j].identifier)}return!1}}}else if(b==="useTransition"&&y.type==="ArrayPattern"&&y.elements.length===2&&Array.isArray(n.identifiers)&&y.elements[1]===n.identifiers[0])return!0;return!1}function H(n){if(!D(n.defs))return!1;let r=n.defs[0];if(r==null||r.node==null||r.node.id==null)return!1;let p=r.node,d=S.childScopes,h=null,y;for(y=0;y<d.length;y++){let b=d[y],T=b.block;if(p.type==="FunctionDeclaration"&&T===p||p.type==="VariableDeclarator"&&T.parent===p){h=b;break}}if(h==null)return!1;for(y=0;y<h.through.length;y++){let b=h.through[y];if(b.resolved!=null&&C.has(b.resolved.scope)&&!L(b.resolved))return!1}return!0}let L=O(E,w),_e=O(H,R),fe=new Map;function We(n){let r=n.from,p=!1;for(;r.block!==g;)r.type==="function"&&(p=r.block.parent!=null&&r.block.parent.type==="ReturnStatement"),r=r.upper;return p}let F=new Map,Z=new Map;pe(x);function pe(n){for(let r of n.references){if(!r.resolved||!C.has(r.resolved.scope))continue;let p=ie(g,r.identifier),d=be(p),h=U(d,Z);if(o&&d.type==="Identifier"&&(d.parent.type==="MemberExpression"||d.parent.type==="OptionalMemberExpression")&&!d.parent.computed&&d.parent.property.type==="Identifier"&&d.parent.property.name==="current"&&We(r)&&fe.set(h,{reference:r,dependencyNode:d}),d.parent.type==="TSTypeQuery"||d.parent.type==="TSTypeReference")continue;let y=r.resolved.defs[0];if(y!=null&&!(y.node!=null&&y.node.init===g.parent)&&y.type!=="TypeParameter")if(F.has(h))F.get(h).references.push(r);else{let b=r.resolved,T=L(b)||_e(b);F.set(h,{isStable:T,references:[r]})}}for(let r of n.childScopes)pe(r)}fe.forEach(({reference:n,dependencyNode:r},p)=>{let d=n.resolved.references,h=!1;for(let y=0;y<d.length;y++){let{identifier:b}=d[y],{parent:T}=b;if(T!=null&&T.type==="MemberExpression"&&!T.computed&&T.property.type==="Identifier"&&T.property.name==="current"&&T.parent.type==="AssignmentExpression"&&T.parent.left===T){h=!0;break}}h||l({node:r.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 Q=new Set;function Ue(n,r){Q.has(r)||(Q.add(r),l({node:n,message:`Assignments to the '${r}' variable from inside React Hook ${t(k)} 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 ${t(k)}.`}))}let K=new Set;if(F.forEach(({isStable:n,references:r},p)=>{n&&K.add(p),r.forEach(d=>{d.writeExpr&&Ue(d.writeExpr,p)})}),Q.size>0)return;if(!$){let n=null;if(F.forEach(({isStable:r,references:p},d)=>{n||p.forEach(h=>{if(n)return;let y=h.identifier;if(!i.has(y))return;let T=h.from;for(;T.type!=="function";)T=T.upper;T.block===g&&(n=d)})}),n){let{suggestedDependencies:r}=re({dependencies:F,declaredDependencies:[],stableDependencies:K,externalDependencies:new Set,isEffect:!0});l({node:k,message:`React Hook ${I} contains a call to '${n}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+r.join(", ")+`] as a second argument to the ${I} Hook.`,suggest:[{desc:`Add dependencies array: [${r.join(", ")}]`,fix(p){return p.insertTextAfter(g,`, [${r.join(", ")}]`)}}]})}return}let G=[],X=new Set;$.type!=="ArrayExpression"?l({node:$,message:`React Hook ${t(k)} 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(n=>{if(n===null)return;if(n.type==="SpreadElement"){l({node:n,message:`React Hook ${t(k)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}M.has(n)&&l({node:n,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${t(n)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${t(n)}\``,fix(h){return h.removeRange(n.range)}}]});let r;try{r=U(n,Z)}catch(h){if(/Unsupported node type/.test(h.message)){n.type==="Literal"?F.has(n.value)?l({node:n,message:`The ${n.raw} literal is not a valid dependency because it never changes. Did you mean to include ${n.value} in the array instead?`}):l({node:n,message:`The ${n.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:n,message:`React Hook ${t(k)} 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 p=n;for(;p.type==="MemberExpression"||p.type==="OptionalMemberExpression"||p.type==="ChainExpression";)p=p.object||p.expression.object;let d=!S.through.some(h=>h.identifier===p);G.push({key:r,node:n}),d||X.add(r)});let{suggestedDependencies:Ve,unnecessaryDependencies:N,missingDependencies:V,duplicateDependencies:de}=re({dependencies:F,declaredDependencies:G,stableDependencies:K,externalDependencies:X,isEffect:o}),Y=Ve;if(de.size+V.size+N.size===0){Ze({declaredDependencies:G,declaredDependenciesNode:$,componentScope:S,scope:x}).forEach(({construction:r,isUsedOutsideOfHook:p,depType:d})=>{let h=d==="function"?"useCallback":"useMemo",y=d==="function"?"definition":"initialization",b=`wrap the ${y} of '${r.name.name}' in its own ${h}() Hook.`,T=p?`To fix this, ${b}`:`Move it inside the ${I} callback. Alternatively, ${b}`,j=d==="conditional"||d==="logical expression"?"could make":"makes",W=`The '${r.name.name}' ${d} ${j} the dependencies of ${I} Hook (at line ${$.loc.start.line}) change on every render. ${T}`,me;p&&r.type==="Variable"&&d==="function"&&(me=[{desc:`Wrap the ${y} of '${r.name.name}' in its own ${h}() Hook.`,fix(ye){let[Be,Ge]=h==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[ye.insertTextBefore(r.node.init,Be),ye.insertTextAfter(r.node.init,Ge)]}}]),l({node:r.node,message:W,suggest:me})});return}!o&&V.size>0&&(Y=re({dependencies:F,declaredDependencies:[],stableDependencies:K,externalDependencies:X,isEffect:o}).suggestedDependencies);function ze(){if(G.length===0)return!0;let n=G.map(p=>p.key),r=n.slice().sort();return n.join(",")===r.join(",")}ze()&&Y.sort();function ee(n){let r=n.split("."),p="";for(let d=0;d<r.length;d++){if(d!==0){let h=r.slice(0,d+1).join("."),y=Z.get(h)===!0;p+=y?"?.":"."}p+=r[d]}return p}function te(n,r,p,d){return n.size===0?null:(n.size>1?"":r+" ")+p+" "+(n.size>1?"dependencies":"dependency")+": "+et(Array.from(n).sort().map(h=>"'"+ee(h)+"'"))+`. Either ${d} ${n.size>1?"them":"it"} or remove the dependency array.`}let _="";if(N.size>0){let n=null;if(Array.from(N.keys()).forEach(r=>{n===null&&r.endsWith(".current")&&(n=r)}),n!==null)_=` Mutable values like '${n}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(X.size>0){let r=Array.from(X)[0];x.set.has(r)||(_=` Outer scope values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!_&&V.has("props")){let n=F.get("props");if(n==null)return;let r=n.references;if(!Array.isArray(r))return;let p=!0;for(let d=0;d<r.length;d++){let h=r[d],y=ie(S.block,h.identifier);if(!y){p=!1;break}let b=y.parent;if(b==null){p=!1;break}if(b.type!=="MemberExpression"&&b.type!=="OptionalMemberExpression"){p=!1;break}}p&&(_=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${I} call and refer to those specific props inside ${t(k)}.`)}if(!_&&V.size>0){let n=null;V.forEach(r=>{if(n)return;let p=S.set.get(r),d=F.get(r);if(d.references[0].resolved!==p)return;let h=p.defs[0];if(h==null||h.name==null||h.type!=="Parameter")return;let y=!1,b;for(let T=0;T<d.references.length;T++)if(b=d.references[T].identifier,b!=null&&b.parent!=null&&(b.parent.type==="CallExpression"||b.parent.type==="OptionalCallExpression")&&b.parent.callee===b){y=!0;break}y&&(n=r)}),n!==null&&(_=` If '${n}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!_&&V.size>0){let n=null;if(V.forEach(r=>{if(n!==null)return;let d=F.get(r).references,h,y;for(let b=0;b<d.length;b++){for(h=d[b].identifier,y=h.parent;y!=null&&y!==S.block;){if(y.type==="CallExpression"){let T=i.get(y.callee);if(T!=null){if(T.name===r)n={missingDep:r,setter:y.callee.name,form:"updater"};else if(a.has(h))n={missingDep:r,setter:y.callee.name,form:"reducer"};else{let j=d[b].resolved;if(j!=null){let W=j.defs[0];W!=null&&W.type==="Parameter"&&(n={missingDep:r,setter:y.callee.name,form:"inlineReducer"})}}break}}y=y.parent}if(n!==null)break}}),n!==null)switch(n.form){case"reducer":_=` You can also replace multiple useState variables with useReducer if '${n.setter}' needs the current value of '${n.missingDep}'.`;break;case"inlineReducer":_=` If '${n.setter}' needs the current value of '${n.missingDep}', you can also switch to useReducer instead of useState and read '${n.missingDep}' in the reducer.`;break;case"updater":_=` You can also do a functional update '${n.setter}(${n.missingDep.slice(0,1)} => ...)' if you only need '${n.missingDep}' in the '${n.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:$,message:`React Hook ${t(k)} has `+(te(V,"a","missing","include")||te(N,"an","unnecessary","exclude")||te(de,"a","duplicate","omit"))+_,suggest:[{desc:`Update the dependencies array to be: [${Y.map(ee).join(", ")}]`,fix(n){return n.replaceText($,`[${Y.map(ee).join(", ")}]`)}}]})}function v(g){let $=Qe(g.callee,f);if($===-1)return;let k=g.arguments[$],I=g.callee,o=Se(I).name,x=g.arguments[$+1],C=/Effect($|[^a-z])/g.test(o);if(!k){l({node:I,message:`React Hook ${o} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!x&&!C){(o==="useMemo"||o==="useCallback")&&l({node:I,message:`React Hook ${o} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(k.type){case"FunctionExpression":case"ArrowFunctionExpression":P(k,x,I,o,C);return;case"Identifier":if(!x||x.elements&&x.elements.some(E=>E&&E.type==="Identifier"&&E.name===k.name))return;let S=s(g).set.get(k.name);if(S==null||S.defs==null)return;let D=S.defs[0];if(!D||!D.node||D.type!=="Variable"&&D.type!=="FunctionName")break;switch(D.node.type){case"FunctionDeclaration":P(D.node,x,I,o,C);return;case"VariableDeclarator":let E=D.node.init;if(!E)break;switch(E.type){case"ArrowFunctionExpression":case"FunctionExpression":P(E,x,I,o,C);return}break}break;default:l({node:I,message:`React Hook ${o} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:I,message:`React Hook ${o} has a missing dependency: '${k.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${k.name}]`,fix(S){return S.replaceText(x,`[${k.name}]`)}}]})}return{CallExpression:v}}};function re({dependencies:e,declaredDependencies:t,stableDependencies:s,externalDependencies:u,isEffect:c}){let f=l();function l(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((v,g)=>{let $=m(f,g);$.isUsed=!0,i(f,g,k=>{k.isSubtreeUsed=!0})}),t.forEach(({key:v})=>{let g=m(f,v);g.isSatisfiedRecursively=!0}),s.forEach(v=>{let g=m(f,v);g.isSatisfiedRecursively=!0});function m(v,g){let $=g.split("."),k=v;for(let I of $){let o=k.children.get(I);o||(o=l(),k.children.set(I,o)),k=o}return k}function i(v,g,$){let k=g.split("."),I=v;for(let o of k){let x=I.children.get(o);if(!x)return;$(x),I=x}}let a=new Set,w=new Set;R(f,a,w,v=>v);function R(v,g,$,k){v.children.forEach((I,o)=>{let x=k(o);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&$.add(x);return}if(I.isUsed){g.add(x);return}R(I,g,$,C=>x+"."+C)})}let M=[],O=new Set,P=new Set;return t.forEach(({key:v})=>{w.has(v)?M.indexOf(v)===-1?M.push(v):P.add(v):O.add(v)}),a.forEach(v=>{M.push(v)}),{suggestedDependencies:M,unnecessaryDependencies:O,duplicateDependencies:P,missingDependencies:a}}function z(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 z(e.consequent)!=null||z(e.alternate)!=null?"conditional":null;case"LogicalExpression":return z(e.left)!=null||z(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return z(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return z(e.expression);case"TSAsExpression":return z(e.expression)}return null}function Ze({declaredDependencies:e,declaredDependenciesNode:t,componentScope:s,scope:u}){let c=e.map(({key:l})=>{let m=s.variables.find(a=>a.name===l);if(m==null)return null;let i=m.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 a=z(i.node.init);if(a!=null)return[m,a]}return i.type==="FunctionName"&&i.node.type==="FunctionDeclaration"?[m,"function"]:i.type==="ClassName"&&i.node.type==="ClassDeclaration"?[m,"class"]:null}).filter(Boolean);function f(l){let m=!1;for(let i=0;i<l.references.length;i++){let a=l.references[i];if(a.writeExpr){if(m)return!0;m=!0;continue}let w=a.from;for(;w!==u&&w!=null;)w=w.upper;if(w!==u&&!Ee(t,a.identifier))return!0}return!1}return c.map(([l,m])=>({construction:l.defs[0],depType:m,isUsedOutsideOfHook:f(l)}))}function be(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)?be(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function se(e,t,s){t&&(e.optional?t.has(s)||t.set(s,!0):t.has(s)||t.set(s,!1))}function U(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let s=e.name;return t&&t.set(s,!1),s}else if(e.type==="MemberExpression"&&!e.computed){let s=U(e.object,t),u=U(e.property,null),c=`${s}.${u}`;return se(e,t,c),c}else if(e.type==="OptionalMemberExpression"&&!e.computed){let s=U(e.object,t),u=U(e.property,null),c=`${s}.${u}`;return se(e,t,c),c}else if(e.type==="ChainExpression"&&!e.computed){let s=e.expression;if(s.type==="CallExpression")throw new Error(`Unsupported node type: ${s.type}`);let u=U(s.object,t),c=U(s.property,null),f=`${u}.${c}`;return se(s,t,f),f}else throw new Error(`Unsupported node type: ${e.type}`)}function Se(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Qe(e,t){let s=Se(e);if(s.type!=="Identifier")return-1;switch(s.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(s===e&&t&&t.additionalHooks){let u;try{u=U(s,null)}catch(c){if(/Unsupported node type/.test(c.message))return 0;throw c}return t.additionalHooks.test(u)?0:-1}else return-1}}function ie(e,t){let s=[e],u=null;for(;s.length;){if(u=s.shift(),tt(u,t))return u;if(Ee(u,t))for(let[c,f]of Object.entries(u))c!=="parent"&&(he(f)?(f.parent=u,s.push(f)):Array.isArray(f)&&f.forEach(l=>{he(l)&&(l.parent=u,s.push(l))}))}return null}function et(e){let t="";for(let s=0;s<e.length;s++)t+=e[s],s===0&&e.length===2?t+=" and ":s===e.length-2&&e.length>2?t+=", and ":s<e.length-1&&(t+=", ");return t}function he(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function tt(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 Ee(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function nt(e){return!1}var B=require("@typescript-eslint/utils"),rt=B.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Te="no-call-with-infered-generics",st=rt({name:Te,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],s=new Map(t.functions.map(u=>[u.name,u]));return{CallExpression(u){let{callee:c}=u;if(c.type!==B.AST_NODE_TYPES.Identifier)return;let f=s.get(c.name);if(!f)return;let{minGenerics:l=1,allowAny:m,disallowTypes:i=t.disallowTypes}=f;(u.typeArguments?.params.length||0)<(l||0)&&e.report({node:u,messageId:"missingGenericDeclaration",data:{functionName:c.name,minGenerics:l||0}}),!(m&&!i)&&u.typeArguments?.params?.some(w=>!m&&w.type===B.AST_NODE_TYPES.TSAnyKeyword||i&&w.type===B.AST_NODE_TYPES.TSTypeReference&&w.typeName.type===B.AST_NODE_TYPES.Identifier&&i.includes(w.typeName.name))&&e.report({node:u,messageId:"anyUsedInGenerics",data:{functionName:c.name}})}}}}),oe={name:Te,rule:st};var q=require("@typescript-eslint/utils"),it=q.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ke="no-commented-out-code",ot=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],at=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],ct=it({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(s){if(s.startsWith("/"))return!1;let u=s.trimStart();if(s.startsWith("*")||u.startsWith("INFO:")||u.startsWith("TODO:")||u.startsWith("FIX:")||u.startsWith("eslint-disable")||s.includes("@deprecated")||s.includes("@example"))return!1;for(let c of ot)if(u.startsWith(c))return{wrongPattern:c};for(let c of at)if(typeof c=="string"){if(s.includes(c))return{wrongPattern:c}}else if(c.test(s))return{wrongPattern:`regex(${c.toString()})`};return!1}return{Program(){let u=e.sourceCode.getAllComments();for(let c of u)if(c.type===q.TSESTree.AST_TOKEN_TYPES.Line||c.type===q.TSESTree.AST_TOKEN_TYPES.Block){let f=t(c.value);f&&e.report({node:c,messageId:"commentedOutCode",data:{wrongPattern:f.wrongPattern}})}}}}}),ae={name:ke,rule:ct};var A=require("@typescript-eslint/utils"),lt=A.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function we(e){let t=[];for(let s of e.members)s.type===A.AST_NODE_TYPES.TSPropertySignature&&s.key.type===A.AST_NODE_TYPES.Identifier&&t.push([s.key.name,s]);return t}function xe(e,...t){for(let s of t)e.set(...s);return e}var Ie="no-unused-type-props-in-args",ut=lt({name:Ie,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used"},schema:[],fixable:"code"},defaultOptions:[],create:function(e){function t(f,l,m,i=!0){let a=l.name,w=e.sourceCode.getScope(f).references.find(M=>M.identifier.name===a)?.resolved;if(!w||w.references.filter(M=>M.isTypeReference).length>1)return;let R=w?.defs[0]?.node;if(!(i&&R?.parent?.type===A.AST_NODE_TYPES.ExportNamedDeclaration)){if(R?.type===A.AST_NODE_TYPES.TSTypeAliasDeclaration){s(f,m,R.typeAnnotation,!0);return}if(R?.type===A.AST_NODE_TYPES.TSInterfaceDeclaration){s(f,m,R.body,!0);return}}}function s(f,l,m,i){if(m.type===A.AST_NODE_TYPES.TSInterfaceBody){for(let a of m.body)a.type===A.AST_NODE_TYPES.TSPropertySignature&&a.key.type===A.AST_NODE_TYPES.Identifier&&l.set(a.key.name,a);return}if(m.type===A.AST_NODE_TYPES.TSTypeLiteral){xe(l,...we(m));return}if(m.type===A.AST_NODE_TYPES.TSIntersectionType){for(let a of m.types)s(f,l,a,!0);return}i||m.type===A.AST_NODE_TYPES.TSTypeReference&&m.typeName.type===A.AST_NODE_TYPES.Identifier&&t(f,m.typeName,l)}function u(f,l){for(let m of l)if(m.type==="ObjectPattern"&&m.typeAnnotation){let i=new Map;if(s(f,i,m.typeAnnotation.typeAnnotation,!1),i.size===0)continue;c(m,i)}else m.type===A.AST_NODE_TYPES.AssignmentPattern&&m.left.type===A.AST_NODE_TYPES.ObjectPattern&&u(f,[m.left])}function c(f,l){let m=[];if(f.properties.at(-1)?.type===A.AST_NODE_TYPES.RestElement)return;for(let R of f.properties)R.type===A.AST_NODE_TYPES.Property&&R.key.type===A.AST_NODE_TYPES.Identifier&&m.push(R.key.name);let a=[],w=[];for(let[R,M]of l)m.includes(R)||(w.push(R),a.push({node:M,messageId:"unusedObjectTypeProperty",data:{propertyName:R}}));for(let[R,M]of a.entries())e.report({...M,fix:R===a.length-1?O=>{let P=f.properties.at(-1),v=w.join(", ");return P?P?.type===A.AST_NODE_TYPES.RestElement?null:O.insertTextAfter(P,`, ${v}`):O.insertTextBeforeRange([f.range[0]+1,f.range[1]],`${v}`)}:void 0})}return{VariableDeclaration:function(f){let l=f.declarations[0];if(!l)return;let m=new Map,i=l.id.type===A.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===A.AST_NODE_TYPES.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===A.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(i){if(i.type===A.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===A.AST_NODE_TYPES.Identifier)t(f,i.typeName,m,!1);else if(i.type===A.AST_NODE_TYPES.TSTypeLiteral)xe(m,...we(i));else if(i.type===A.AST_NODE_TYPES.TSIntersectionType)for(let a of i.types)a.type===A.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===A.AST_NODE_TYPES.Identifier?t(f,a.typeName,m,!1):s(f,m,a,!0);if(m.size!==0&&l.init?.type===A.AST_NODE_TYPES.ArrowFunctionExpression){let a=l.init.params[0];a&&a.type===A.AST_NODE_TYPES.ObjectPattern&&c(a,m)}}},FunctionDeclaration:function(f){u(f,f.params)},ArrowFunctionExpression:function(f){u(f,f.params)}}}}),ce={name:Ie,rule:ut};var Re=require("@typescript-eslint/utils"),ft=Re.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ae="require-description",pt=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,dt=/^eslint-disable-(next-)?line$/u,mt=ft({name:Ae,meta:{type:"problem",docs:{description:"Require descriptions for exported functions"},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){let t=e.sourceCode,s=new Set(e.options[0]&&e.options[0].ignore||[]);return{Program(){for(let u of t.getAllComments()){let c=yt(u);c!=null&&(s.has(c.kind)||c.description||e.report({loc:gt(u.loc),messageId:"missingDescription"}))}}}}}),Ce={name:Ae,rule:mt};function yt(e){let{text:t,description:s}=ht(e.value);if(!t)return null;let u=pt.exec(t);if(!u)return null;let c=u[1];if(!c)return null;let f=dt.test(c);if(e.type==="Line"&&!f||f&&e.loc.start.line!==e.loc.end.line)return null;let l=t.slice(u.index+c.length);return{kind:c,value:l.trim(),description:s}}function ht(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function gt(e){return{start:{line:e.start.line,column:-1},end:e.end}}function De(e){return/^use[A-Z0-9]/.test(e)}function J(e){return e.type==="Identifier"?De(e.name):e.type==="MemberExpression"&&!e.computed&&J(e.property)?e.object.type==="Identifier":!1}function Me(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Pe(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Oe(e){return!!(e.parent&&e.parent.callee&&Pe(e.parent.callee,"forwardRef"))}function He(e){return!!(e.parent&&e.parent.callee&&Pe(e.parent.callee,"memo"))}function le(e){for(;e;){let t=je(e);if(t&&(Me(t)||J(t))||Oe(e)||He(e))return!0;e=e.parent}return!1}function ve(e){return!1}function ue(e){return!1}var Fe={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"}},create(e){let t=typeof e.getSource=="function"?i=>t(i):i=>e.sourceCode.getText(i),s=typeof e.getScope=="function"?()=>s():i=>e.sourceCode.getScope(i),u=null,c=[],f=[],l=new WeakSet;function m(i){for(let a of i.references){let w=a.identifier.parent;if(w.type==="VariableDeclarator"&&w.init&&w.init.type==="CallExpression"&&w.init.callee&&ve(w.init.callee))for(let R of a.resolved.references)R!==a&&l.add(R.identifier)}}return{onCodePathSegmentStart:i=>f.push(i),onCodePathSegmentEnd:()=>f.pop(),onCodePathStart:()=>c.push(new Map),onCodePathEnd(i,a){let w=c.pop();if(w.size===0)return;let R=new Set;function M(o,x){let{cache:C}=M,S=C.get(o.id),D=new Set(x);if(D.has(o.id)){let E=[...D],H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(D.add(o.id),S!==void 0)return S;if(i.thrownSegments.includes(o))S=BigInt("0");else if(o.prevSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.prevSegments)S+=M(E,D)}return o.reachable&&S===BigInt("0")?C.delete(o.id):C.set(o.id,S),S}function O(o,x){let{cache:C}=O,S=C.get(o.id),D=new Set(x);if(D.has(o.id)){let E=Array.from(D),H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(D.add(o.id),S!==void 0)return S;if(i.thrownSegments.includes(o))S=BigInt("0");else if(o.nextSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.nextSegments)S+=O(E,D)}return C.set(o.id,S),S}function P(o){let{cache:x}=P,C=x.get(o.id);if(C===null)return 1/0;if(C!==void 0)return C;if(x.set(o.id,null),o.prevSegments.length===0)C=1;else{C=1/0;for(let S of o.prevSegments){let D=P(S);D<C&&(C=D)}C+=1}return x.set(o.id,C),C}M.cache=new Map,O.cache=new Map,P.cache=new Map;let v=O(i.initialSegment),g=je(a),$=le(a),k=g?Me(g)||J(g):Oe(a)||He(a),I=1/0;for(let o of i.finalSegments){if(!o.reachable)continue;let x=P(o);x<I&&(I=x)}for(let[o,x]of w){if(!o.reachable)continue;let C=o.nextSegments.length===0?I<=P(o):I<P(o),S=M(o)*O(o),D=R.has(o.id);for(let E of x)if(D&&!ue(E)&&e.report({node:E,message:`React Hook "${t(E)}" 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.`}),k){if(a.async&&e.report({node:E,message:`React Hook "${t(E)}" cannot be called in an async function.`}),!D&&S!==v&&!ue(E)){let L=`React Hook "${t(E)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(C?" Did you accidentally call a React Hook after an early return?":"");e.report({node:E,message:L})}}else if(a.parent&&(a.parent.type==="MethodDefinition"||a.parent.type==="ClassProperty")&&a.parent.value===a){let H=`React Hook "${t(E)}" 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:E,message:H})}else if(g){let H=`React Hook "${t(E)}" is called in function "${t(g)}" 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:E,message:H})}else if(a.type==="Program"){let H=`React Hook "${t(E)}" 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:E,message:H})}else if($&&!ue(E)){if(a.parent.type==="CallExpression"&&a.parent.callee.type==="Identifier"&&a.parent.callee.name==="useCallback"){let L=a.parent;if(L.parent.type==="VariableDeclarator"&&De(L.parent.id.name))return}let H=`React Hook "${t(E)}" 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:E,message:H})}}},CallExpression(i){if(J(i.callee)){let a=$e(c),w=$e(f),R=a.get(w);R||(R=[],a.set(w,R)),R.push(i.callee)}i.callee.type==="Identifier"&&(i.callee.name==="useEffect"||ve(i.callee))&&i.arguments.length>0&&(u=i)},Identifier(i){u==null&&l.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===u&&(u=null)},FunctionDeclaration(i){le(i)&&m(s(i))},ArrowFunctionExpression(i){le(i)&&m(s(i))}}}};function je(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 $e(e){return e[e.length-1]}var Le={[ce.name]:ce.rule,[ae.name]:ae.rule,[oe.name]:oe.rule,"rules-of-hooks":Fe,"exhaustive-deps":ge,"require-description":Ce.rule};var bt={rules:Le};0&&(module.exports={extendedLintPlugin});
|
package/dist/extended-lint.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ye={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,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let n=typeof e.getSource=="function"?
|
|
1
|
+
var ye={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,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let n=typeof e.getSource=="function"?g=>n(g):g=>e.sourceCode.getText(g),i=typeof e.getScope=="function"?()=>i():g=>e.sourceCode.getScope(g),f=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,d=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,l={additionalHooks:f,enableDangerousAutofixThisMayCauseInfiniteLoops:d};function c(g){d&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let m=e.getSourceCode().scopeManager,s=new WeakMap,a=new WeakSet,w=new WeakMap,R=new WeakMap,M=new WeakSet;function O(g,$){return function(k){if($.has(k))return $.get(k);let I=g(k);return $.set(k,I),I}}function P(g,$,k,I,o){o&&g.async&&c({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,4 +9,4 @@ useEffect(() => {
|
|
|
9
9
|
fetchData();
|
|
10
10
|
}, [someId]); // Or [] if effect doesn't need props or state
|
|
11
11
|
|
|
12
|
-
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=p.acquire(h),A=new Set,S=null;{let t=x.upper;for(;t&&(A.add(t),t.type!=="function");)t=t.upper;if(!t)return;S=t}let M=Array.isArray;function E(t){if(!M(t.defs))return!1;let r=t.defs[0];if(r==null||r.node.type!=="VariableDeclarator")return!1;let c=r.node.init;if(c==null)return!1;for(;c.type==="TSAsExpression";)c=c.expression;let u=r.node.parent;if(u==null&&(re(S.block,r.node.id),u=r.node.parent,u==null))return!1;if(u.kind==="const"&&c.type==="Literal"&&(typeof c.value=="string"||typeof c.value=="number"||c.value===null))return!0;if(c.type!=="CallExpression")return!1;let m=c.callee;if(m.type==="MemberExpression"&&m.object.name==="React"&&m.property!=null&&!m.computed&&(m=m.property),m.type!=="Identifier")return!1;let d=r.node.id,{name:b}=m;if(b==="useRef"&&d.type==="Identifier")return!0;if(Xe(m)&&d.type==="Identifier"){for(let T of t.references)T!==d&&D.add(T.identifier);return!0}else if(b==="useState"||b==="useReducer"){if(d.type==="ArrayPattern"&&d.elements.length===2&&M(t.identifiers)){if(d.elements[1]===t.identifiers[0]){if(b==="useState"){let T=t.references,j=0;for(let _=0;_<T.length;_++){if(T[_].isWrite()&&j++,j>1)return!1;s.set(T[_].identifier,d.elements[0])}}return!0}else if(d.elements[0]===t.identifiers[0]){if(b==="useState"){let T=t.references;for(let j=0;j<T.length;j++)a.add(T[j].identifier)}return!1}}}else if(b==="useTransition"&&d.type==="ArrayPattern"&&d.elements.length===2&&Array.isArray(t.identifiers)&&d.elements[1]===t.identifiers[0])return!0;return!1}function H(t){if(!M(t.defs))return!1;let r=t.defs[0];if(r==null||r.node==null||r.node.id==null)return!1;let c=r.node,u=S.childScopes,m=null,d;for(d=0;d<u.length;d++){let b=u[d],T=b.block;if(c.type==="FunctionDeclaration"&&T===c||c.type==="VariableDeclarator"&&T.parent===c){m=b;break}}if(m==null)return!1;for(d=0;d<m.through.length;d++){let b=m.through[d];if(b.resolved!=null&&A.has(b.resolved.scope)&&!L(b.resolved))return!1}return!0}let L=O(E,w),He=O(H,R),le=new Map;function Fe(t){let r=t.from,c=!1;for(;r.block!==h;)r.type==="function"&&(c=r.block.parent!=null&&r.block.parent.type==="ReturnStatement"),r=r.upper;return c}let F=new Map,J=new Map;fe(x);function fe(t){for(let r of t.references){if(!r.resolved||!A.has(r.resolved.scope))continue;let c=re(h,r.identifier),u=he(c),m=U(u,J);if(o&&u.type==="Identifier"&&(u.parent.type==="MemberExpression"||u.parent.type==="OptionalMemberExpression")&&!u.parent.computed&&u.parent.property.type==="Identifier"&&u.parent.property.name==="current"&&Fe(r)&&le.set(m,{reference:r,dependencyNode:u}),u.parent.type==="TSTypeQuery"||u.parent.type==="TSTypeReference")continue;let d=r.resolved.defs[0];if(d!=null&&!(d.node!=null&&d.node.init===h.parent)&&d.type!=="TypeParameter")if(F.has(m))F.get(m).references.push(r);else{let b=r.resolved,T=L(b)||He(b);F.set(m,{isStable:T,references:[r]})}}for(let r of t.childScopes)fe(r)}le.forEach(({reference:t,dependencyNode:r},c)=>{let u=t.resolved.references,m=!1;for(let d=0;d<u.length;d++){let{identifier:b}=u[d],{parent:T}=b;if(T!=null&&T.type==="MemberExpression"&&!T.computed&&T.property.type==="Identifier"&&T.property.name==="current"&&T.parent.type==="AssignmentExpression"&&T.parent.left===T){m=!0;break}}m||l({node:r.parent.property,message:`The ref value '${c}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${c}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Z=new Set;function je(t,r){Z.has(r)||(Z.add(r),l({node:t,message:`Assignments to the '${r}' variable from inside React Hook ${n(k)} 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(k)}.`}))}let X=new Set;if(F.forEach(({isStable:t,references:r},c)=>{t&&X.add(c),r.forEach(u=>{u.writeExpr&&je(u.writeExpr,c)})}),Z.size>0)return;if(!v){let t=null;if(F.forEach(({isStable:r,references:c},u)=>{t||c.forEach(m=>{if(t)return;let d=m.identifier;if(!s.has(d))return;let T=m.from;for(;T.type!=="function";)T=T.upper;T.block===h&&(t=u)})}),t){let{suggestedDependencies:r}=te({dependencies:F,declaredDependencies:[],stableDependencies:X,externalDependencies:new Set,isEffect:!0});l({node:k,message:`React Hook ${I} contains a call to '${t}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+r.join(", ")+`] as a second argument to the ${I} Hook.`,suggest:[{desc:`Add dependencies array: [${r.join(", ")}]`,fix(c){return c.insertTextAfter(h,`, [${r.join(", ")}]`)}}]})}return}let B=[],G=new Set;v.type!=="ArrayExpression"?l({node:v,message:`React Hook ${n(k)} 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.`}):v.elements.forEach(t=>{if(t===null)return;if(t.type==="SpreadElement"){l({node:t,message:`React Hook ${n(k)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}D.has(t)&&l({node:t,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(t)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(t)}\``,fix(m){return m.removeRange(t.range)}}]});let r;try{r=U(t,J)}catch(m){if(/Unsupported node type/.test(m.message)){t.type==="Literal"?F.has(t.value)?l({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. Did you mean to include ${t.value} in the array instead?`}):l({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:t,message:`React Hook ${n(k)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw m}let c=t;for(;c.type==="MemberExpression"||c.type==="OptionalMemberExpression"||c.type==="ChainExpression";)c=c.object||c.expression.object;let u=!S.through.some(m=>m.identifier===c);B.push({key:r,node:t}),u||G.add(r)});let{suggestedDependencies:Le,unnecessaryDependencies:K,missingDependencies:V,duplicateDependencies:ue}=te({dependencies:F,declaredDependencies:B,stableDependencies:X,externalDependencies:G,isEffect:o}),N=Le;if(ue.size+V.size+K.size===0){Ve({declaredDependencies:B,declaredDependenciesNode:v,componentScope:S,scope:x}).forEach(({construction:r,isUsedOutsideOfHook:c,depType:u})=>{let m=u==="function"?"useCallback":"useMemo",d=u==="function"?"definition":"initialization",b=`wrap the ${d} of '${r.name.name}' in its own ${m}() Hook.`,T=c?`To fix this, ${b}`:`Move it inside the ${I} callback. Alternatively, ${b}`,j=u==="conditional"||u==="logical expression"?"could make":"makes",_=`The '${r.name.name}' ${u} ${j} the dependencies of ${I} Hook (at line ${v.loc.start.line}) change on every render. ${T}`,pe;c&&r.type==="Variable"&&u==="function"&&(pe=[{desc:`Wrap the ${d} of '${r.name.name}' in its own ${m}() Hook.`,fix(de){let[_e,Ue]=m==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[de.insertTextBefore(r.node.init,_e),de.insertTextAfter(r.node.init,Ue)]}}]),l({node:r.node,message:_,suggest:pe})});return}!o&&V.size>0&&(N=te({dependencies:F,declaredDependencies:[],stableDependencies:X,externalDependencies:G,isEffect:o}).suggestedDependencies);function We(){if(B.length===0)return!0;let t=B.map(c=>c.key),r=t.slice().sort();return t.join(",")===r.join(",")}We()&&N.sort();function Q(t){let r=t.split("."),c="";for(let u=0;u<r.length;u++){if(u!==0){let m=r.slice(0,u+1).join("."),d=J.get(m)===!0;c+=d?"?.":"."}c+=r[u]}return c}function ee(t,r,c,u){return t.size===0?null:(t.size>1?"":r+" ")+c+" "+(t.size>1?"dependencies":"dependency")+": "+Be(Array.from(t).sort().map(m=>"'"+Q(m)+"'"))+`. Either ${u} ${t.size>1?"them":"it"} or remove the dependency array.`}let W="";if(K.size>0){let t=null;if(Array.from(K.keys()).forEach(r=>{t===null&&r.endsWith(".current")&&(t=r)}),t!==null)W=` Mutable values like '${t}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(G.size>0){let r=Array.from(G)[0];x.set.has(r)||(W=` Outer scope values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!W&&V.has("props")){let t=F.get("props");if(t==null)return;let r=t.references;if(!Array.isArray(r))return;let c=!0;for(let u=0;u<r.length;u++){let m=r[u],d=re(S.block,m.identifier);if(!d){c=!1;break}let b=d.parent;if(b==null){c=!1;break}if(b.type!=="MemberExpression"&&b.type!=="OptionalMemberExpression"){c=!1;break}}c&&(W=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${I} call and refer to those specific props inside ${n(k)}.`)}if(!W&&V.size>0){let t=null;V.forEach(r=>{if(t)return;let c=S.set.get(r),u=F.get(r);if(u.references[0].resolved!==c)return;let m=c.defs[0];if(m==null||m.name==null||m.type!=="Parameter")return;let d=!1,b;for(let T=0;T<u.references.length;T++)if(b=u.references[T].identifier,b!=null&&b.parent!=null&&(b.parent.type==="CallExpression"||b.parent.type==="OptionalCallExpression")&&b.parent.callee===b){d=!0;break}d&&(t=r)}),t!==null&&(W=` If '${t}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!W&&V.size>0){let t=null;if(V.forEach(r=>{if(t!==null)return;let u=F.get(r).references,m,d;for(let b=0;b<u.length;b++){for(m=u[b].identifier,d=m.parent;d!=null&&d!==S.block;){if(d.type==="CallExpression"){let T=s.get(d.callee);if(T!=null){if(T.name===r)t={missingDep:r,setter:d.callee.name,form:"updater"};else if(a.has(m))t={missingDep:r,setter:d.callee.name,form:"reducer"};else{let j=u[b].resolved;if(j!=null){let _=j.defs[0];_!=null&&_.type==="Parameter"&&(t={missingDep:r,setter:d.callee.name,form:"inlineReducer"})}}break}}d=d.parent}if(t!==null)break}}),t!==null)switch(t.form){case"reducer":W=` You can also replace multiple useState variables with useReducer if '${t.setter}' needs the current value of '${t.missingDep}'.`;break;case"inlineReducer":W=` If '${t.setter}' needs the current value of '${t.missingDep}', you can also switch to useReducer instead of useState and read '${t.missingDep}' in the reducer.`;break;case"updater":W=` You can also do a functional update '${t.setter}(${t.missingDep.slice(0,1)} => ...)' if you only need '${t.missingDep}' in the '${t.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:v,message:`React Hook ${n(k)} has `+(ee(V,"a","missing","include")||ee(K,"an","unnecessary","exclude")||ee(ue,"a","duplicate","omit"))+W,suggest:[{desc:`Update the dependencies array to be: [${N.map(Q).join(", ")}]`,fix(t){return t.replaceText(v,`[${N.map(Q).join(", ")}]`)}}]})}function $(h){let v=ze(h.callee,f);if(v===-1)return;let k=h.arguments[v],I=h.callee,o=ge(I).name,x=h.arguments[v+1],A=/Effect($|[^a-z])/g.test(o);if(!k){l({node:I,message:`React Hook ${o} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!x&&!A){(o==="useMemo"||o==="useCallback")&&l({node:I,message:`React Hook ${o} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(k.type){case"FunctionExpression":case"ArrowFunctionExpression":P(k,x,I,o,A);return;case"Identifier":if(!x||x.elements&&x.elements.some(E=>E&&E.type==="Identifier"&&E.name===k.name))return;let S=i(h).set.get(k.name);if(S==null||S.defs==null)return;let M=S.defs[0];if(!M||!M.node||M.type!=="Variable"&&M.type!=="FunctionName")break;switch(M.node.type){case"FunctionDeclaration":P(M.node,x,I,o,A);return;case"VariableDeclarator":let E=M.node.init;if(!E)break;switch(E.type){case"ArrowFunctionExpression":case"FunctionExpression":P(E,x,I,o,A);return}break}break;default:l({node:I,message:`React Hook ${o} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:I,message:`React Hook ${o} has a missing dependency: '${k.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${k.name}]`,fix(S){return S.replaceText(x,`[${k.name}]`)}}]})}return{CallExpression:$}}};function te({dependencies:e,declaredDependencies:n,stableDependencies:i,externalDependencies:y,isEffect:g}){let f=l();function l(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach(($,h)=>{let v=p(f,h);v.isUsed=!0,s(f,h,k=>{k.isSubtreeUsed=!0})}),n.forEach(({key:$})=>{let h=p(f,$);h.isSatisfiedRecursively=!0}),i.forEach($=>{let h=p(f,$);h.isSatisfiedRecursively=!0});function p($,h){let v=h.split("."),k=$;for(let I of v){let o=k.children.get(I);o||(o=l(),k.children.set(I,o)),k=o}return k}function s($,h,v){let k=h.split("."),I=$;for(let o of k){let x=I.children.get(o);if(!x)return;v(x),I=x}}let a=new Set,w=new Set;R(f,a,w,$=>$);function R($,h,v,k){$.children.forEach((I,o)=>{let x=k(o);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&v.add(x);return}if(I.isUsed){h.add(x);return}R(I,h,v,A=>x+"."+A)})}let D=[],O=new Set,P=new Set;return n.forEach(({key:$})=>{w.has($)?D.indexOf($)===-1?D.push($):P.add($):O.add($)}),a.forEach($=>{D.push($)}),{suggestedDependencies:D,unnecessaryDependencies:O,duplicateDependencies:P,missingDependencies:a}}function z(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 z(e.consequent)!=null||z(e.alternate)!=null?"conditional":null;case"LogicalExpression":return z(e.left)!=null||z(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return z(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return z(e.expression);case"TSAsExpression":return z(e.expression)}return null}function Ve({declaredDependencies:e,declaredDependenciesNode:n,componentScope:i,scope:y}){let g=e.map(({key:l})=>{let p=i.variables.find(a=>a.name===l);if(p==null)return null;let s=p.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 a=z(s.node.init);if(a!=null)return[p,a]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[p,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[p,"class"]:null}).filter(Boolean);function f(l){let p=!1;for(let s=0;s<l.references.length;s++){let a=l.references[s];if(a.writeExpr){if(p)return!0;p=!0;continue}let w=a.from;for(;w!==y&&w!=null;)w=w.upper;if(w!==y&&!be(n,a.identifier))return!0}return!1}return g.map(([l,p])=>({construction:l.defs[0],depType:p,isUsedOutsideOfHook:f(l)}))}function he(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)?he(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function ne(e,n,i){n&&(e.optional?n.has(i)||n.set(i,!0):n.has(i)||n.set(i,!1))}function U(e,n){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let i=e.name;return n&&n.set(i,!1),i}else if(e.type==="MemberExpression"&&!e.computed){let i=U(e.object,n),y=U(e.property,null),g=`${i}.${y}`;return ne(e,n,g),g}else if(e.type==="OptionalMemberExpression"&&!e.computed){let i=U(e.object,n),y=U(e.property,null),g=`${i}.${y}`;return ne(e,n,g),g}else if(e.type==="ChainExpression"&&!e.computed){let i=e.expression;if(i.type==="CallExpression")throw new Error(`Unsupported node type: ${i.type}`);let y=U(i.object,n),g=U(i.property,null),f=`${y}.${g}`;return ne(i,n,f),f}else throw new Error(`Unsupported node type: ${e.type}`)}function ge(e,n){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function ze(e,n){let i=ge(e);if(i.type!=="Identifier")return-1;switch(i.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(i===e&&n&&n.additionalHooks){let y;try{y=U(i,null)}catch(g){if(/Unsupported node type/.test(g.message))return 0;throw g}return n.additionalHooks.test(y)?0:-1}else return-1}}function re(e,n){let i=[e],y=null;for(;i.length;){if(y=i.shift(),Ge(y,n))return y;if(be(y,n))for(let[g,f]of Object.entries(y))g!=="parent"&&(me(f)?(f.parent=y,i.push(f)):Array.isArray(f)&&f.forEach(l=>{me(l)&&(l.parent=y,i.push(l))}))}return null}function Be(e){let n="";for(let i=0;i<e.length;i++)n+=e[i],i===0&&e.length===2?n+=" and ":i===e.length-2&&e.length>2?n+=", and ":i<e.length-1&&(n+=", ");return n}function me(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ge(e,n){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===n.type&&e.name===n.name&&e.range[0]===n.range[0]&&e.range[1]===n.range[1]}function be(e,n){return e.range[0]<=n.range[0]&&e.range[1]>=n.range[1]}function Xe(e){return!1}import{AST_NODE_TYPES as Y,ESLintUtils as Ke}from"@typescript-eslint/utils";var Ne=Ke.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Se="no-call-with-infered-generics",Ye=Ne({name:Se,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 n=e.options[0],i=new Map(n.functions.map(y=>[y.name,y]));return{CallExpression(y){let{callee:g}=y;if(g.type!==Y.Identifier)return;let f=i.get(g.name);if(!f)return;let{minGenerics:l=1,allowAny:p,disallowTypes:s=n.disallowTypes}=f;(y.typeArguments?.params.length||0)<(l||0)&&e.report({node:y,messageId:"missingGenericDeclaration",data:{functionName:g.name,minGenerics:l||0}}),!(p&&!s)&&y.typeArguments?.params?.some(w=>!p&&w.type===Y.TSAnyKeyword||s&&w.type===Y.TSTypeReference&&w.typeName.type===Y.Identifier&&s.includes(w.typeName.name))&&e.report({node:y,messageId:"anyUsedInGenerics",data:{functionName:g.name}})}}}}),se={name:Se,rule:Ye};import{ESLintUtils as qe,TSESTree as Ee}from"@typescript-eslint/utils";var Je=qe.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Te="no-commented-out-code",Ze=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Qe=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],et=Je({name:Te,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 n(i){if(i.startsWith("/"))return!1;let y=i.trimStart();if(i.startsWith("*")||y.startsWith("INFO:")||y.startsWith("TODO:")||y.startsWith("FIX:")||y.startsWith("eslint-disable")||i.includes("@deprecated")||i.includes("@example"))return!1;for(let g of Ze)if(y.startsWith(g))return{wrongPattern:g};for(let g of Qe)if(typeof g=="string"){if(i.includes(g))return{wrongPattern:g}}else if(g.test(i))return{wrongPattern:`regex(${g.toString()})`};return!1}return{Program(){let y=e.sourceCode.getAllComments();for(let g of y)if(g.type===Ee.AST_TOKEN_TYPES.Line||g.type===Ee.AST_TOKEN_TYPES.Block){let f=n(g.value);f&&e.report({node:g,messageId:"commentedOutCode",data:{wrongPattern:f.wrongPattern}})}}}}}),ie={name:Te,rule:et};import{AST_NODE_TYPES as C,ESLintUtils as tt}from"@typescript-eslint/utils";var nt=tt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function ke(e){let n=[];for(let i of e.members)i.type===C.TSPropertySignature&&i.key.type===C.Identifier&&n.push([i.key.name,i]);return n}function we(e,...n){for(let i of n)e.set(...i);return e}var xe="no-unused-type-props-in-args",rt=nt({name:xe,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used"},schema:[],fixable:"code"},defaultOptions:[],create:function(e){function n(f,l,p,s=!0){let a=l.name,w=e.sourceCode.getScope(f).references.find(D=>D.identifier.name===a)?.resolved;if(!w||w.references.filter(D=>D.isTypeReference).length>1)return;let R=w?.defs[0]?.node;if(!(s&&R?.parent?.type===C.ExportNamedDeclaration)){if(R?.type===C.TSTypeAliasDeclaration){i(f,p,R.typeAnnotation,!0);return}if(R?.type===C.TSInterfaceDeclaration){i(f,p,R.body,!0);return}}}function i(f,l,p,s){if(p.type===C.TSInterfaceBody){for(let a of p.body)a.type===C.TSPropertySignature&&a.key.type===C.Identifier&&l.set(a.key.name,a);return}if(p.type===C.TSTypeLiteral){we(l,...ke(p));return}if(p.type===C.TSIntersectionType){for(let a of p.types)i(f,l,a,!0);return}s||p.type===C.TSTypeReference&&p.typeName.type===C.Identifier&&n(f,p.typeName,l)}function y(f,l){for(let p of l)if(p.type==="ObjectPattern"&&p.typeAnnotation){let s=new Map;if(i(f,s,p.typeAnnotation.typeAnnotation,!1),s.size===0)continue;g(p,s)}else p.type===C.AssignmentPattern&&p.left.type===C.ObjectPattern&&y(f,[p.left])}function g(f,l){let p=[];if(f.properties.at(-1)?.type===C.RestElement)return;for(let R of f.properties)R.type===C.Property&&R.key.type===C.Identifier&&p.push(R.key.name);let a=[],w=[];for(let[R,D]of l)p.includes(R)||(w.push(R),a.push({node:D,messageId:"unusedObjectTypeProperty",data:{propertyName:R}}));for(let[R,D]of a.entries())e.report({...D,fix:R===a.length-1?O=>{let P=f.properties.at(-1),$=w.join(", ");return P?P?.type===C.RestElement?null:O.insertTextAfter(P,`, ${$}`):O.insertTextBeforeRange([f.range[0]+1,f.range[1]],`${$}`)}:void 0})}return{VariableDeclaration:function(f){let l=f.declarations[0];if(!l)return;let p=new Map,s=l.id.type===C.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===C.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===C.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===C.TSTypeReference&&s.typeName.type===C.Identifier)n(f,s.typeName,p,!1);else if(s.type===C.TSTypeLiteral)we(p,...ke(s));else if(s.type===C.TSIntersectionType)for(let a of s.types)a.type===C.TSTypeReference&&a.typeName.type===C.Identifier?n(f,a.typeName,p,!1):i(f,p,a,!0);if(p.size!==0&&l.init?.type===C.ArrowFunctionExpression){let a=l.init.params[0];a&&a.type===C.ObjectPattern&&g(a,p)}}},FunctionDeclaration:function(f){y(f,f.params)},ArrowFunctionExpression:function(f){y(f,f.params)}}}}),oe={name:xe,rule:rt};function Ae(e){return/^use[A-Z0-9]/.test(e)}function q(e){return e.type==="Identifier"?Ae(e.name):e.type==="MemberExpression"&&!e.computed&&q(e.property)?e.object.type==="Identifier":!1}function Ce(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function $e(e,n){return e.name===n||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===n}function ve(e){return!!(e.parent&&e.parent.callee&&$e(e.parent.callee,"forwardRef"))}function Me(e){return!!(e.parent&&e.parent.callee&&$e(e.parent.callee,"memo"))}function ae(e){for(;e;){let n=Pe(e);if(n&&(Ce(n)||q(n))||ve(e)||Me(e))return!0;e=e.parent}return!1}function Ie(e){return!1}function ce(e){return!1}var De={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"}},create(e){let n=typeof e.getSource=="function"?s=>n(s):s=>e.sourceCode.getText(s),i=typeof e.getScope=="function"?()=>i():s=>e.sourceCode.getScope(s),y=null,g=[],f=[],l=new WeakSet;function p(s){for(let a of s.references){let w=a.identifier.parent;if(w.type==="VariableDeclarator"&&w.init&&w.init.type==="CallExpression"&&w.init.callee&&Ie(w.init.callee))for(let R of a.resolved.references)R!==a&&l.add(R.identifier)}}return{onCodePathSegmentStart:s=>f.push(s),onCodePathSegmentEnd:()=>f.pop(),onCodePathStart:()=>g.push(new Map),onCodePathEnd(s,a){let w=g.pop();if(w.size===0)return;let R=new Set;function D(o,x){let{cache:A}=D,S=A.get(o.id),M=new Set(x);if(M.has(o.id)){let E=[...M],H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(M.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.prevSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.prevSegments)S+=D(E,M)}return o.reachable&&S===BigInt("0")?A.delete(o.id):A.set(o.id,S),S}function O(o,x){let{cache:A}=O,S=A.get(o.id),M=new Set(x);if(M.has(o.id)){let E=Array.from(M),H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(M.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.nextSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.nextSegments)S+=O(E,M)}return A.set(o.id,S),S}function P(o){let{cache:x}=P,A=x.get(o.id);if(A===null)return 1/0;if(A!==void 0)return A;if(x.set(o.id,null),o.prevSegments.length===0)A=1;else{A=1/0;for(let S of o.prevSegments){let M=P(S);M<A&&(A=M)}A+=1}return x.set(o.id,A),A}D.cache=new Map,O.cache=new Map,P.cache=new Map;let $=O(s.initialSegment),h=Pe(a),v=ae(a),k=h?Ce(h)||q(h):ve(a)||Me(a),I=1/0;for(let o of s.finalSegments){if(!o.reachable)continue;let x=P(o);x<I&&(I=x)}for(let[o,x]of w){if(!o.reachable)continue;let A=o.nextSegments.length===0?I<=P(o):I<P(o),S=D(o)*O(o),M=R.has(o.id);for(let E of x)if(M&&!ce(E)&&e.report({node:E,message:`React Hook "${n(E)}" 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.`}),k){if(a.async&&e.report({node:E,message:`React Hook "${n(E)}" cannot be called in an async function.`}),!M&&S!==$&&!ce(E)){let L=`React Hook "${n(E)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(A?" Did you accidentally call a React Hook after an early return?":"");e.report({node:E,message:L})}}else if(a.parent&&(a.parent.type==="MethodDefinition"||a.parent.type==="ClassProperty")&&a.parent.value===a){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(h){let H=`React Hook "${n(E)}" is called in function "${n(h)}" 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:E,message:H})}else if(a.type==="Program"){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(v&&!ce(E)){if(a.parent.type==="CallExpression"&&a.parent.callee.type==="Identifier"&&a.parent.callee.name==="useCallback"){let L=a.parent;if(L.parent.type==="VariableDeclarator"&&Ae(L.parent.id.name))return}let H=`React Hook "${n(E)}" 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:E,message:H})}}},CallExpression(s){if(q(s.callee)){let a=Re(g),w=Re(f),R=a.get(w);R||(R=[],a.set(w,R)),R.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Ie(s.callee))&&s.arguments.length>0&&(y=s)},Identifier(s){y==null&&l.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${n(s)}\` 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"(s){s===y&&(y=null)},FunctionDeclaration(s){ae(s)&&p(i(s))},ArrowFunctionExpression(s){ae(s)&&p(i(s))}}}};function Pe(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 Re(e){return e[e.length-1]}var Oe={[oe.name]:oe.rule,[ie.name]:ie.rule,[se.name]:se.rule,"rules-of-hooks":De,"exhaustive-deps":ye};var kt={rules:Oe};export{kt as extendedLintPlugin};
|
|
12
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=m.acquire(g),A=new Set,S=null;{let t=x.upper;for(;t&&(A.add(t),t.type!=="function");)t=t.upper;if(!t)return;S=t}let D=Array.isArray;function E(t){if(!D(t.defs))return!1;let r=t.defs[0];if(r==null||r.node.type!=="VariableDeclarator")return!1;let u=r.node.init;if(u==null)return!1;for(;u.type==="TSAsExpression";)u=u.expression;let p=r.node.parent;if(p==null&&(re(S.block,r.node.id),p=r.node.parent,p==null))return!1;if(p.kind==="const"&&u.type==="Literal"&&(typeof u.value=="string"||typeof u.value=="number"||u.value===null))return!0;if(u.type!=="CallExpression")return!1;let h=u.callee;if(h.type==="MemberExpression"&&h.object.name==="React"&&h.property!=null&&!h.computed&&(h=h.property),h.type!=="Identifier")return!1;let y=r.node.id,{name:b}=h;if(b==="useRef"&&y.type==="Identifier")return!0;if(Ke(h)&&y.type==="Identifier"){for(let T of t.references)T!==y&&M.add(T.identifier);return!0}else if(b==="useState"||b==="useReducer"){if(y.type==="ArrayPattern"&&y.elements.length===2&&D(t.identifiers)){if(y.elements[1]===t.identifiers[0]){if(b==="useState"){let T=t.references,j=0;for(let W=0;W<T.length;W++){if(T[W].isWrite()&&j++,j>1)return!1;s.set(T[W].identifier,y.elements[0])}}return!0}else if(y.elements[0]===t.identifiers[0]){if(b==="useState"){let T=t.references;for(let j=0;j<T.length;j++)a.add(T[j].identifier)}return!1}}}else if(b==="useTransition"&&y.type==="ArrayPattern"&&y.elements.length===2&&Array.isArray(t.identifiers)&&y.elements[1]===t.identifiers[0])return!0;return!1}function H(t){if(!D(t.defs))return!1;let r=t.defs[0];if(r==null||r.node==null||r.node.id==null)return!1;let u=r.node,p=S.childScopes,h=null,y;for(y=0;y<p.length;y++){let b=p[y],T=b.block;if(u.type==="FunctionDeclaration"&&T===u||u.type==="VariableDeclarator"&&T.parent===u){h=b;break}}if(h==null)return!1;for(y=0;y<h.through.length;y++){let b=h.through[y];if(b.resolved!=null&&A.has(b.resolved.scope)&&!L(b.resolved))return!1}return!0}let L=O(E,w),je=O(H,R),le=new Map;function Le(t){let r=t.from,u=!1;for(;r.block!==g;)r.type==="function"&&(u=r.block.parent!=null&&r.block.parent.type==="ReturnStatement"),r=r.upper;return u}let F=new Map,J=new Map;ue(x);function ue(t){for(let r of t.references){if(!r.resolved||!A.has(r.resolved.scope))continue;let u=re(g,r.identifier),p=he(u),h=U(p,J);if(o&&p.type==="Identifier"&&(p.parent.type==="MemberExpression"||p.parent.type==="OptionalMemberExpression")&&!p.parent.computed&&p.parent.property.type==="Identifier"&&p.parent.property.name==="current"&&Le(r)&&le.set(h,{reference:r,dependencyNode:p}),p.parent.type==="TSTypeQuery"||p.parent.type==="TSTypeReference")continue;let y=r.resolved.defs[0];if(y!=null&&!(y.node!=null&&y.node.init===g.parent)&&y.type!=="TypeParameter")if(F.has(h))F.get(h).references.push(r);else{let b=r.resolved,T=L(b)||je(b);F.set(h,{isStable:T,references:[r]})}}for(let r of t.childScopes)ue(r)}le.forEach(({reference:t,dependencyNode:r},u)=>{let p=t.resolved.references,h=!1;for(let y=0;y<p.length;y++){let{identifier:b}=p[y],{parent:T}=b;if(T!=null&&T.type==="MemberExpression"&&!T.computed&&T.property.type==="Identifier"&&T.property.name==="current"&&T.parent.type==="AssignmentExpression"&&T.parent.left===T){h=!0;break}}h||c({node:r.parent.property,message:`The ref value '${u}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${u}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Z=new Set;function _e(t,r){Z.has(r)||(Z.add(r),c({node:t,message:`Assignments to the '${r}' variable from inside React Hook ${n(k)} 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(k)}.`}))}let X=new Set;if(F.forEach(({isStable:t,references:r},u)=>{t&&X.add(u),r.forEach(p=>{p.writeExpr&&_e(p.writeExpr,u)})}),Z.size>0)return;if(!$){let t=null;if(F.forEach(({isStable:r,references:u},p)=>{t||u.forEach(h=>{if(t)return;let y=h.identifier;if(!s.has(y))return;let T=h.from;for(;T.type!=="function";)T=T.upper;T.block===g&&(t=p)})}),t){let{suggestedDependencies:r}=te({dependencies:F,declaredDependencies:[],stableDependencies:X,externalDependencies:new Set,isEffect:!0});c({node:k,message:`React Hook ${I} contains a call to '${t}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+r.join(", ")+`] as a second argument to the ${I} Hook.`,suggest:[{desc:`Add dependencies array: [${r.join(", ")}]`,fix(u){return u.insertTextAfter(g,`, [${r.join(", ")}]`)}}]})}return}let B=[],G=new Set;$.type!=="ArrayExpression"?c({node:$,message:`React Hook ${n(k)} 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(t=>{if(t===null)return;if(t.type==="SpreadElement"){c({node:t,message:`React Hook ${n(k)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}M.has(t)&&c({node:t,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(t)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(t)}\``,fix(h){return h.removeRange(t.range)}}]});let r;try{r=U(t,J)}catch(h){if(/Unsupported node type/.test(h.message)){t.type==="Literal"?F.has(t.value)?c({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. Did you mean to include ${t.value} in the array instead?`}):c({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):c({node:t,message:`React Hook ${n(k)} 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 u=t;for(;u.type==="MemberExpression"||u.type==="OptionalMemberExpression"||u.type==="ChainExpression";)u=u.object||u.expression.object;let p=!S.through.some(h=>h.identifier===u);B.push({key:r,node:t}),p||G.add(r)});let{suggestedDependencies:We,unnecessaryDependencies:q,missingDependencies:V,duplicateDependencies:fe}=te({dependencies:F,declaredDependencies:B,stableDependencies:X,externalDependencies:G,isEffect:o}),K=We;if(fe.size+V.size+q.size===0){Be({declaredDependencies:B,declaredDependenciesNode:$,componentScope:S,scope:x}).forEach(({construction:r,isUsedOutsideOfHook:u,depType:p})=>{let h=p==="function"?"useCallback":"useMemo",y=p==="function"?"definition":"initialization",b=`wrap the ${y} of '${r.name.name}' in its own ${h}() Hook.`,T=u?`To fix this, ${b}`:`Move it inside the ${I} callback. Alternatively, ${b}`,j=p==="conditional"||p==="logical expression"?"could make":"makes",W=`The '${r.name.name}' ${p} ${j} the dependencies of ${I} Hook (at line ${$.loc.start.line}) change on every render. ${T}`,pe;u&&r.type==="Variable"&&p==="function"&&(pe=[{desc:`Wrap the ${y} of '${r.name.name}' in its own ${h}() Hook.`,fix(de){let[Ve,ze]=h==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[de.insertTextBefore(r.node.init,Ve),de.insertTextAfter(r.node.init,ze)]}}]),c({node:r.node,message:W,suggest:pe})});return}!o&&V.size>0&&(K=te({dependencies:F,declaredDependencies:[],stableDependencies:X,externalDependencies:G,isEffect:o}).suggestedDependencies);function Ue(){if(B.length===0)return!0;let t=B.map(u=>u.key),r=t.slice().sort();return t.join(",")===r.join(",")}Ue()&&K.sort();function Q(t){let r=t.split("."),u="";for(let p=0;p<r.length;p++){if(p!==0){let h=r.slice(0,p+1).join("."),y=J.get(h)===!0;u+=y?"?.":"."}u+=r[p]}return u}function ee(t,r,u,p){return t.size===0?null:(t.size>1?"":r+" ")+u+" "+(t.size>1?"dependencies":"dependency")+": "+Xe(Array.from(t).sort().map(h=>"'"+Q(h)+"'"))+`. Either ${p} ${t.size>1?"them":"it"} or remove the dependency array.`}let _="";if(q.size>0){let t=null;if(Array.from(q.keys()).forEach(r=>{t===null&&r.endsWith(".current")&&(t=r)}),t!==null)_=` Mutable values like '${t}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(G.size>0){let r=Array.from(G)[0];x.set.has(r)||(_=` Outer scope values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!_&&V.has("props")){let t=F.get("props");if(t==null)return;let r=t.references;if(!Array.isArray(r))return;let u=!0;for(let p=0;p<r.length;p++){let h=r[p],y=re(S.block,h.identifier);if(!y){u=!1;break}let b=y.parent;if(b==null){u=!1;break}if(b.type!=="MemberExpression"&&b.type!=="OptionalMemberExpression"){u=!1;break}}u&&(_=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${I} call and refer to those specific props inside ${n(k)}.`)}if(!_&&V.size>0){let t=null;V.forEach(r=>{if(t)return;let u=S.set.get(r),p=F.get(r);if(p.references[0].resolved!==u)return;let h=u.defs[0];if(h==null||h.name==null||h.type!=="Parameter")return;let y=!1,b;for(let T=0;T<p.references.length;T++)if(b=p.references[T].identifier,b!=null&&b.parent!=null&&(b.parent.type==="CallExpression"||b.parent.type==="OptionalCallExpression")&&b.parent.callee===b){y=!0;break}y&&(t=r)}),t!==null&&(_=` If '${t}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!_&&V.size>0){let t=null;if(V.forEach(r=>{if(t!==null)return;let p=F.get(r).references,h,y;for(let b=0;b<p.length;b++){for(h=p[b].identifier,y=h.parent;y!=null&&y!==S.block;){if(y.type==="CallExpression"){let T=s.get(y.callee);if(T!=null){if(T.name===r)t={missingDep:r,setter:y.callee.name,form:"updater"};else if(a.has(h))t={missingDep:r,setter:y.callee.name,form:"reducer"};else{let j=p[b].resolved;if(j!=null){let W=j.defs[0];W!=null&&W.type==="Parameter"&&(t={missingDep:r,setter:y.callee.name,form:"inlineReducer"})}}break}}y=y.parent}if(t!==null)break}}),t!==null)switch(t.form){case"reducer":_=` You can also replace multiple useState variables with useReducer if '${t.setter}' needs the current value of '${t.missingDep}'.`;break;case"inlineReducer":_=` If '${t.setter}' needs the current value of '${t.missingDep}', you can also switch to useReducer instead of useState and read '${t.missingDep}' in the reducer.`;break;case"updater":_=` You can also do a functional update '${t.setter}(${t.missingDep.slice(0,1)} => ...)' if you only need '${t.missingDep}' in the '${t.setter}' call.`;break;default:throw new Error("Unknown case.")}}c({node:$,message:`React Hook ${n(k)} has `+(ee(V,"a","missing","include")||ee(q,"an","unnecessary","exclude")||ee(fe,"a","duplicate","omit"))+_,suggest:[{desc:`Update the dependencies array to be: [${K.map(Q).join(", ")}]`,fix(t){return t.replaceText($,`[${K.map(Q).join(", ")}]`)}}]})}function v(g){let $=Ge(g.callee,l);if($===-1)return;let k=g.arguments[$],I=g.callee,o=ge(I).name,x=g.arguments[$+1],A=/Effect($|[^a-z])/g.test(o);if(!k){c({node:I,message:`React Hook ${o} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!x&&!A){(o==="useMemo"||o==="useCallback")&&c({node:I,message:`React Hook ${o} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(k.type){case"FunctionExpression":case"ArrowFunctionExpression":P(k,x,I,o,A);return;case"Identifier":if(!x||x.elements&&x.elements.some(E=>E&&E.type==="Identifier"&&E.name===k.name))return;let S=i(g).set.get(k.name);if(S==null||S.defs==null)return;let D=S.defs[0];if(!D||!D.node||D.type!=="Variable"&&D.type!=="FunctionName")break;switch(D.node.type){case"FunctionDeclaration":P(D.node,x,I,o,A);return;case"VariableDeclarator":let E=D.node.init;if(!E)break;switch(E.type){case"ArrowFunctionExpression":case"FunctionExpression":P(E,x,I,o,A);return}break}break;default:c({node:I,message:`React Hook ${o} received a function whose dependencies are unknown. Pass an inline function instead.`});return}c({node:I,message:`React Hook ${o} has a missing dependency: '${k.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${k.name}]`,fix(S){return S.replaceText(x,`[${k.name}]`)}}]})}return{CallExpression:v}}};function te({dependencies:e,declaredDependencies:n,stableDependencies:i,externalDependencies:f,isEffect:d}){let l=c();function c(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((v,g)=>{let $=m(l,g);$.isUsed=!0,s(l,g,k=>{k.isSubtreeUsed=!0})}),n.forEach(({key:v})=>{let g=m(l,v);g.isSatisfiedRecursively=!0}),i.forEach(v=>{let g=m(l,v);g.isSatisfiedRecursively=!0});function m(v,g){let $=g.split("."),k=v;for(let I of $){let o=k.children.get(I);o||(o=c(),k.children.set(I,o)),k=o}return k}function s(v,g,$){let k=g.split("."),I=v;for(let o of k){let x=I.children.get(o);if(!x)return;$(x),I=x}}let a=new Set,w=new Set;R(l,a,w,v=>v);function R(v,g,$,k){v.children.forEach((I,o)=>{let x=k(o);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&$.add(x);return}if(I.isUsed){g.add(x);return}R(I,g,$,A=>x+"."+A)})}let M=[],O=new Set,P=new Set;return n.forEach(({key:v})=>{w.has(v)?M.indexOf(v)===-1?M.push(v):P.add(v):O.add(v)}),a.forEach(v=>{M.push(v)}),{suggestedDependencies:M,unnecessaryDependencies:O,duplicateDependencies:P,missingDependencies:a}}function z(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 z(e.consequent)!=null||z(e.alternate)!=null?"conditional":null;case"LogicalExpression":return z(e.left)!=null||z(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return z(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return z(e.expression);case"TSAsExpression":return z(e.expression)}return null}function Be({declaredDependencies:e,declaredDependenciesNode:n,componentScope:i,scope:f}){let d=e.map(({key:c})=>{let m=i.variables.find(a=>a.name===c);if(m==null)return null;let s=m.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 a=z(s.node.init);if(a!=null)return[m,a]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[m,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[m,"class"]:null}).filter(Boolean);function l(c){let m=!1;for(let s=0;s<c.references.length;s++){let a=c.references[s];if(a.writeExpr){if(m)return!0;m=!0;continue}let w=a.from;for(;w!==f&&w!=null;)w=w.upper;if(w!==f&&!be(n,a.identifier))return!0}return!1}return d.map(([c,m])=>({construction:c.defs[0],depType:m,isUsedOutsideOfHook:l(c)}))}function he(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)?he(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function ne(e,n,i){n&&(e.optional?n.has(i)||n.set(i,!0):n.has(i)||n.set(i,!1))}function U(e,n){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let i=e.name;return n&&n.set(i,!1),i}else if(e.type==="MemberExpression"&&!e.computed){let i=U(e.object,n),f=U(e.property,null),d=`${i}.${f}`;return ne(e,n,d),d}else if(e.type==="OptionalMemberExpression"&&!e.computed){let i=U(e.object,n),f=U(e.property,null),d=`${i}.${f}`;return ne(e,n,d),d}else if(e.type==="ChainExpression"&&!e.computed){let i=e.expression;if(i.type==="CallExpression")throw new Error(`Unsupported node type: ${i.type}`);let f=U(i.object,n),d=U(i.property,null),l=`${f}.${d}`;return ne(i,n,l),l}else throw new Error(`Unsupported node type: ${e.type}`)}function ge(e,n){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Ge(e,n){let i=ge(e);if(i.type!=="Identifier")return-1;switch(i.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(i===e&&n&&n.additionalHooks){let f;try{f=U(i,null)}catch(d){if(/Unsupported node type/.test(d.message))return 0;throw d}return n.additionalHooks.test(f)?0:-1}else return-1}}function re(e,n){let i=[e],f=null;for(;i.length;){if(f=i.shift(),qe(f,n))return f;if(be(f,n))for(let[d,l]of Object.entries(f))d!=="parent"&&(me(l)?(l.parent=f,i.push(l)):Array.isArray(l)&&l.forEach(c=>{me(c)&&(c.parent=f,i.push(c))}))}return null}function Xe(e){let n="";for(let i=0;i<e.length;i++)n+=e[i],i===0&&e.length===2?n+=" and ":i===e.length-2&&e.length>2?n+=", and ":i<e.length-1&&(n+=", ");return n}function me(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function qe(e,n){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===n.type&&e.name===n.name&&e.range[0]===n.range[0]&&e.range[1]===n.range[1]}function be(e,n){return e.range[0]<=n.range[0]&&e.range[1]>=n.range[1]}function Ke(e){return!1}import{AST_NODE_TYPES as N,ESLintUtils as Ne}from"@typescript-eslint/utils";var Ye=Ne.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Se="no-call-with-infered-generics",Je=Ye({name:Se,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 n=e.options[0],i=new Map(n.functions.map(f=>[f.name,f]));return{CallExpression(f){let{callee:d}=f;if(d.type!==N.Identifier)return;let l=i.get(d.name);if(!l)return;let{minGenerics:c=1,allowAny:m,disallowTypes:s=n.disallowTypes}=l;(f.typeArguments?.params.length||0)<(c||0)&&e.report({node:f,messageId:"missingGenericDeclaration",data:{functionName:d.name,minGenerics:c||0}}),!(m&&!s)&&f.typeArguments?.params?.some(w=>!m&&w.type===N.TSAnyKeyword||s&&w.type===N.TSTypeReference&&w.typeName.type===N.Identifier&&s.includes(w.typeName.name))&&e.report({node:f,messageId:"anyUsedInGenerics",data:{functionName:d.name}})}}}}),se={name:Se,rule:Je};import{ESLintUtils as Ze,TSESTree as Ee}from"@typescript-eslint/utils";var Qe=Ze.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Te="no-commented-out-code",et=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],tt=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],nt=Qe({name:Te,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 n(i){if(i.startsWith("/"))return!1;let f=i.trimStart();if(i.startsWith("*")||f.startsWith("INFO:")||f.startsWith("TODO:")||f.startsWith("FIX:")||f.startsWith("eslint-disable")||i.includes("@deprecated")||i.includes("@example"))return!1;for(let d of et)if(f.startsWith(d))return{wrongPattern:d};for(let d of tt)if(typeof d=="string"){if(i.includes(d))return{wrongPattern:d}}else if(d.test(i))return{wrongPattern:`regex(${d.toString()})`};return!1}return{Program(){let f=e.sourceCode.getAllComments();for(let d of f)if(d.type===Ee.AST_TOKEN_TYPES.Line||d.type===Ee.AST_TOKEN_TYPES.Block){let l=n(d.value);l&&e.report({node:d,messageId:"commentedOutCode",data:{wrongPattern:l.wrongPattern}})}}}}}),ie={name:Te,rule:nt};import{AST_NODE_TYPES as C,ESLintUtils as rt}from"@typescript-eslint/utils";var st=rt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function ke(e){let n=[];for(let i of e.members)i.type===C.TSPropertySignature&&i.key.type===C.Identifier&&n.push([i.key.name,i]);return n}function we(e,...n){for(let i of n)e.set(...i);return e}var xe="no-unused-type-props-in-args",it=st({name:xe,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used"},schema:[],fixable:"code"},defaultOptions:[],create:function(e){function n(l,c,m,s=!0){let a=c.name,w=e.sourceCode.getScope(l).references.find(M=>M.identifier.name===a)?.resolved;if(!w||w.references.filter(M=>M.isTypeReference).length>1)return;let R=w?.defs[0]?.node;if(!(s&&R?.parent?.type===C.ExportNamedDeclaration)){if(R?.type===C.TSTypeAliasDeclaration){i(l,m,R.typeAnnotation,!0);return}if(R?.type===C.TSInterfaceDeclaration){i(l,m,R.body,!0);return}}}function i(l,c,m,s){if(m.type===C.TSInterfaceBody){for(let a of m.body)a.type===C.TSPropertySignature&&a.key.type===C.Identifier&&c.set(a.key.name,a);return}if(m.type===C.TSTypeLiteral){we(c,...ke(m));return}if(m.type===C.TSIntersectionType){for(let a of m.types)i(l,c,a,!0);return}s||m.type===C.TSTypeReference&&m.typeName.type===C.Identifier&&n(l,m.typeName,c)}function f(l,c){for(let m of c)if(m.type==="ObjectPattern"&&m.typeAnnotation){let s=new Map;if(i(l,s,m.typeAnnotation.typeAnnotation,!1),s.size===0)continue;d(m,s)}else m.type===C.AssignmentPattern&&m.left.type===C.ObjectPattern&&f(l,[m.left])}function d(l,c){let m=[];if(l.properties.at(-1)?.type===C.RestElement)return;for(let R of l.properties)R.type===C.Property&&R.key.type===C.Identifier&&m.push(R.key.name);let a=[],w=[];for(let[R,M]of c)m.includes(R)||(w.push(R),a.push({node:M,messageId:"unusedObjectTypeProperty",data:{propertyName:R}}));for(let[R,M]of a.entries())e.report({...M,fix:R===a.length-1?O=>{let P=l.properties.at(-1),v=w.join(", ");return P?P?.type===C.RestElement?null:O.insertTextAfter(P,`, ${v}`):O.insertTextBeforeRange([l.range[0]+1,l.range[1]],`${v}`)}:void 0})}return{VariableDeclaration:function(l){let c=l.declarations[0];if(!c)return;let m=new Map,s=c.id.type===C.Identifier&&c.id.typeAnnotation?.typeAnnotation.type===C.TSTypeReference&&c.id.typeAnnotation.typeAnnotation.typeName.type===C.Identifier&&c.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&c.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===C.TSTypeReference&&s.typeName.type===C.Identifier)n(l,s.typeName,m,!1);else if(s.type===C.TSTypeLiteral)we(m,...ke(s));else if(s.type===C.TSIntersectionType)for(let a of s.types)a.type===C.TSTypeReference&&a.typeName.type===C.Identifier?n(l,a.typeName,m,!1):i(l,m,a,!0);if(m.size!==0&&c.init?.type===C.ArrowFunctionExpression){let a=c.init.params[0];a&&a.type===C.ObjectPattern&&d(a,m)}}},FunctionDeclaration:function(l){f(l,l.params)},ArrowFunctionExpression:function(l){f(l,l.params)}}}}),oe={name:xe,rule:it};import{ESLintUtils as ot}from"@typescript-eslint/utils";var at=ot.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ie="require-description",ct=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,lt=/^eslint-disable-(next-)?line$/u,ut=at({name:Ie,meta:{type:"problem",docs:{description:"Require descriptions for exported functions"},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){let n=e.sourceCode,i=new Set(e.options[0]&&e.options[0].ignore||[]);return{Program(){for(let f of n.getAllComments()){let d=ft(f);d!=null&&(i.has(d.kind)||d.description||e.report({loc:dt(f.loc),messageId:"missingDescription"}))}}}}}),Re={name:Ie,rule:ut};function ft(e){let{text:n,description:i}=pt(e.value);if(!n)return null;let f=ct.exec(n);if(!f)return null;let d=f[1];if(!d)return null;let l=lt.test(d);if(e.type==="Line"&&!l||l&&e.loc.start.line!==e.loc.end.line)return null;let c=n.slice(f.index+d.length);return{kind:d,value:c.trim(),description:i}}function pt(e){let n=e.split(/\s-{2,}\s/u);return{text:n[0]?.trim(),description:n.length>1?n[1]?.trim()??null:null}}function dt(e){return{start:{line:e.start.line,column:-1},end:e.end}}function ve(e){return/^use[A-Z0-9]/.test(e)}function Y(e){return e.type==="Identifier"?ve(e.name):e.type==="MemberExpression"&&!e.computed&&Y(e.property)?e.object.type==="Identifier":!1}function $e(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function De(e,n){return e.name===n||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===n}function Me(e){return!!(e.parent&&e.parent.callee&&De(e.parent.callee,"forwardRef"))}function Pe(e){return!!(e.parent&&e.parent.callee&&De(e.parent.callee,"memo"))}function ae(e){for(;e;){let n=He(e);if(n&&($e(n)||Y(n))||Me(e)||Pe(e))return!0;e=e.parent}return!1}function Ae(e){return!1}function ce(e){return!1}var Oe={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"}},create(e){let n=typeof e.getSource=="function"?s=>n(s):s=>e.sourceCode.getText(s),i=typeof e.getScope=="function"?()=>i():s=>e.sourceCode.getScope(s),f=null,d=[],l=[],c=new WeakSet;function m(s){for(let a of s.references){let w=a.identifier.parent;if(w.type==="VariableDeclarator"&&w.init&&w.init.type==="CallExpression"&&w.init.callee&&Ae(w.init.callee))for(let R of a.resolved.references)R!==a&&c.add(R.identifier)}}return{onCodePathSegmentStart:s=>l.push(s),onCodePathSegmentEnd:()=>l.pop(),onCodePathStart:()=>d.push(new Map),onCodePathEnd(s,a){let w=d.pop();if(w.size===0)return;let R=new Set;function M(o,x){let{cache:A}=M,S=A.get(o.id),D=new Set(x);if(D.has(o.id)){let E=[...D],H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(D.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.prevSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.prevSegments)S+=M(E,D)}return o.reachable&&S===BigInt("0")?A.delete(o.id):A.set(o.id,S),S}function O(o,x){let{cache:A}=O,S=A.get(o.id),D=new Set(x);if(D.has(o.id)){let E=Array.from(D),H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(D.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.nextSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.nextSegments)S+=O(E,D)}return A.set(o.id,S),S}function P(o){let{cache:x}=P,A=x.get(o.id);if(A===null)return 1/0;if(A!==void 0)return A;if(x.set(o.id,null),o.prevSegments.length===0)A=1;else{A=1/0;for(let S of o.prevSegments){let D=P(S);D<A&&(A=D)}A+=1}return x.set(o.id,A),A}M.cache=new Map,O.cache=new Map,P.cache=new Map;let v=O(s.initialSegment),g=He(a),$=ae(a),k=g?$e(g)||Y(g):Me(a)||Pe(a),I=1/0;for(let o of s.finalSegments){if(!o.reachable)continue;let x=P(o);x<I&&(I=x)}for(let[o,x]of w){if(!o.reachable)continue;let A=o.nextSegments.length===0?I<=P(o):I<P(o),S=M(o)*O(o),D=R.has(o.id);for(let E of x)if(D&&!ce(E)&&e.report({node:E,message:`React Hook "${n(E)}" 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.`}),k){if(a.async&&e.report({node:E,message:`React Hook "${n(E)}" cannot be called in an async function.`}),!D&&S!==v&&!ce(E)){let L=`React Hook "${n(E)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(A?" Did you accidentally call a React Hook after an early return?":"");e.report({node:E,message:L})}}else if(a.parent&&(a.parent.type==="MethodDefinition"||a.parent.type==="ClassProperty")&&a.parent.value===a){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(g){let H=`React Hook "${n(E)}" is called in function "${n(g)}" 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:E,message:H})}else if(a.type==="Program"){let H=`React Hook "${n(E)}" 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:E,message:H})}else if($&&!ce(E)){if(a.parent.type==="CallExpression"&&a.parent.callee.type==="Identifier"&&a.parent.callee.name==="useCallback"){let L=a.parent;if(L.parent.type==="VariableDeclarator"&&ve(L.parent.id.name))return}let H=`React Hook "${n(E)}" 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:E,message:H})}}},CallExpression(s){if(Y(s.callee)){let a=Ce(d),w=Ce(l),R=a.get(w);R||(R=[],a.set(w,R)),R.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Ae(s.callee))&&s.arguments.length>0&&(f=s)},Identifier(s){f==null&&c.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${n(s)}\` 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"(s){s===f&&(f=null)},FunctionDeclaration(s){ae(s)&&m(i(s))},ArrowFunctionExpression(s){ae(s)&&m(i(s))}}}};function He(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 Ce(e){return e[e.length-1]}var Fe={[oe.name]:oe.rule,[ie.name]:ie.rule,[se.name]:se.rule,"rules-of-hooks":Oe,"exhaustive-deps":ye,"require-description":Re.rule};var Ft={rules:Fe};export{Ft as extendedLintPlugin};
|