@ls-stack/extended-lint 0.14.4 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extended-lint.js +1 -1
- package/dist/extended-lint.mjs +1 -1
- package/package.json +1 -1
package/dist/extended-lint.js
CHANGED
|
@@ -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 E=i.acquire(h),A=new Set,F=null;{let r=E.upper;for(;r&&(A.add(r),r.type!=="function");)r=r.upper;if(!r)return;F=r}let w=Array.isArray;function P(r){if(!w(r.defs))return!1;let a=r.defs[0];if(a==null||a.node.type!=="VariableDeclarator")return!1;let m=a.node.init;if(m==null)return!1;for(;m.type==="TSAsExpression";)m=m.expression;let d=a.node.parent;if(d==null&&(de(F.block,a.node.id),d=a.node.parent,d==null))return!1;if(d.kind==="const"&&m.type==="Literal"&&(typeof m.value=="string"||typeof m.value=="number"||m.value===null))return!0;if(m.type!=="CallExpression")return!1;let g=m.callee;if(g.type==="MemberExpression"&&g.object.name==="React"&&g.property!=null&&!g.computed&&(g=g.property),g.type!=="Identifier")return!1;let y=a.node.id,{name:R}=g;if(R==="useRef"&&y.type==="Identifier")return!0;if(_t(g)&&y.type==="Identifier"){for(let C of r.references)C!==y&&M.add(C.identifier);return!0}else if(R==="useState"||R==="useReducer"){if(y.type==="ArrayPattern"&&y.elements.length===2&&w(r.identifiers)){if(y.elements[1]===r.identifiers[0]){if(R==="useState"){let C=r.references,L=0;for(let U=0;U<C.length;U++){if(C[U].isWrite()&&L++,L>1)return!1;s.set(C[U].identifier,y.elements[0])}}return!0}else if(y.elements[0]===r.identifiers[0]){if(R==="useState"){let C=r.references;for(let L=0;L<C.length;L++)f.add(C[L].identifier)}return!1}}}else if(R==="useTransition"&&y.type==="ArrayPattern"&&y.elements.length===2&&Array.isArray(r.identifiers)&&y.elements[1]===r.identifiers[0])return!0;return!1}function N(r){if(!w(r.defs))return!1;let a=r.defs[0];if(a==null||a.node==null||a.node.id==null)return!1;let m=a.node,d=F.childScopes,g=null,y;for(y=0;y<d.length;y++){let R=d[y],C=R.block;if(m.type==="FunctionDeclaration"&&C===m||m.type==="VariableDeclarator"&&C.parent===m){g=R;break}}if(g==null)return!1;for(y=0;y<g.through.length;y++){let R=g.through[y];if(R.resolved!=null&&A.has(R.resolved.scope)&&!Re(R.resolved))return!1}return!0}let Re=v(P,I),dt=v(N,k),Ie=new Map;function yt(r){let a=r.from,m=!1;for(;a.block!==h;)a.type==="function"&&(m=a.block.parent!=null&&a.block.parent.type==="ReturnStatement"),a=a.upper;return m}let j=new Map,se=new Map;Ce(E);function Ce(r){for(let a of r.references){if(!a.resolved||!A.has(a.resolved.scope))continue;let m=de(h,a.identifier),d=Ne(m),g=V(d,se);if(b&&d.type==="Identifier"&&(d.parent.type==="MemberExpression"||d.parent.type==="OptionalMemberExpression")&&!d.parent.computed&&d.parent.property.type==="Identifier"&&d.parent.property.name==="current"&&yt(a)&&Ie.set(g,{reference:a,dependencyNode:d}),d.parent.type==="TSTypeQuery"||d.parent.type==="TSTypeReference")continue;let y=a.resolved.defs[0];if(y!=null&&!(y.node!=null&&y.node.init===h.parent)&&y.type!=="TypeParameter")if(j.has(g))j.get(g).references.push(a);else{let R=a.resolved,C=Re(R)||dt(R);j.set(g,{isStable:C,references:[a]})}}for(let a of r.childScopes)Ce(a)}Ie.forEach(({reference:r,dependencyNode:a},m)=>{let d=r.resolved.references,g=!1;for(let y=0;y<d.length;y++){let{identifier:R}=d[y],{parent:C}=R;if(C!=null&&C.type==="MemberExpression"&&!C.computed&&C.property.type==="Identifier"&&C.property.name==="current"&&C.parent.type==="AssignmentExpression"&&C.parent.left===C){g=!0;break}}g||u({node:a.parent.property,message:`The ref value '${m}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${m}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let ie=new Set;function gt(r,a){ie.has(a)||(ie.add(a),u({node:r,message:`Assignments to the '${a}' variable from inside React Hook ${n(T)} 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(T)}.`}))}let ee=new Set;if(j.forEach(({isStable:r,references:a},m)=>{r&&ee.add(m),a.forEach(d=>{d.writeExpr&>(d.writeExpr,m)})}),ie.size>0)return;if(!D){let r=null;if(j.forEach(({isStable:a,references:m},d)=>{r||m.forEach(g=>{if(r)return;let y=g.identifier;if(!s.has(y))return;let C=g.from;for(;C.type!=="function";)C=C.upper;C.block===h&&(r=d)})}),r){let{suggestedDependencies:a}=pe({dependencies:j,declaredDependencies:[],stableDependencies:ee,externalDependencies:new Set,isEffect:!0});u({node:T,message:`React Hook ${l} contains a call to '${r}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+a.join(", ")+`] as a second argument to the ${l} Hook.`,suggest:[{desc:`Add dependencies array: [${a.join(", ")}]`,fix(m){return m.insertTextAfter(h,`, [${a.join(", ")}]`)}}]})}return}let Y=[],Z=new Set;D.type!=="ArrayExpression"?u({node:D,message:`React Hook ${n(T)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(r=>{if(r===null)return;if(r.type==="SpreadElement"){u({node:r,message:`React Hook ${n(T)} 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(r)&&u({node:r,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(r)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(r)}\``,fix(g){return g.removeRange(r.range)}}]});let a;try{a=V(r,se)}catch(g){if(/Unsupported node type/.test(g.message)){r.type==="Literal"?j.has(r.value)?u({node:r,message:`The ${r.raw} literal is not a valid dependency because it never changes. Did you mean to include ${r.value} in the array instead?`}):u({node:r,message:`The ${r.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):u({node:r,message:`React Hook ${n(T)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw g}let m=r;for(;m.type==="MemberExpression"||m.type==="OptionalMemberExpression"||m.type==="ChainExpression";)m=m.object||m.expression.object;let d=!F.through.some(g=>g.identifier===m);Y.push({key:a,node:r}),d||Z.add(a)});let{suggestedDependencies:ht,unnecessaryDependencies:te,missingDependencies:q,duplicateDependencies:ke}=pe({dependencies:j,declaredDependencies:Y,stableDependencies:ee,externalDependencies:Z,isEffect:b}),ne=ht;if(ke.size+q.size+te.size===0){if(t)return;Ot({declaredDependencies:Y,declaredDependenciesNode:D,componentScope:F,scope:E}).forEach(({construction:a,isUsedOutsideOfHook:m,depType:d})=>{let g=d==="function"?"useCallback":"useMemo",y=d==="function"?"definition":"initialization",R=`wrap the ${y} of '${a.name.name}' in its own ${g}() Hook.`,C=m?`To fix this, ${R}`:`Move it inside the ${l} callback. Alternatively, ${R}`,L=d==="conditional"||d==="logical expression"?"could make":"makes",U=`The '${a.name.name}' ${d} ${L} the dependencies of ${l} Hook (at line ${D.loc.start.line}) change on every render. ${C}`,ve;m&&a.type==="Variable"&&d==="function"&&(ve=[{desc:`Wrap the ${y} of '${a.name.name}' in its own ${g}() Hook.`,fix($e){let[St,Et]=g==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[$e.insertTextBefore(a.node.init,St),$e.insertTextAfter(a.node.init,Et)]}}]),u({node:a.node,message:U,suggest:ve})});return}!b&&q.size>0&&(ne=pe({dependencies:j,declaredDependencies:[],stableDependencies:ee,externalDependencies:Z,isEffect:b}).suggestedDependencies);function bt(){if(Y.length===0)return!0;let r=Y.map(m=>m.key),a=r.slice().sort();return r.join(",")===a.join(",")}bt()&&ne.sort();function oe(r){let a=r.split("."),m="";for(let d=0;d<a.length;d++){if(d!==0){let g=a.slice(0,d+1).join("."),y=se.get(g)===!0;m+=y?"?.":"."}m+=a[d]}return m}function ae(r,a,m,d){return r.size===0?null:(r.size>1?"":a+" ")+m+" "+(r.size>1?"dependencies":"dependency")+": "+Mt(Array.from(r).sort().map(g=>"'"+oe(g)+"'"))+`. Either ${d} ${r.size>1?"them":"it"} or remove the dependency array.`}let H="";if(te.size>0){let r=null;if(Array.from(te.keys()).forEach(a=>{r===null&&a.endsWith(".current")&&(r=a)}),r!==null)H=` Mutable values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(Z.size>0){let a=Array.from(Z)[0];E.set.has(a)||(H=` Outer scope values like '${a}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!H&&q.has("props")){let r=j.get("props");if(r==null)return;let a=r.references;if(!Array.isArray(a))return;let m=!0;for(let d=0;d<a.length;d++){let g=a[d],y=de(F.block,g.identifier);if(!y){m=!1;break}let R=y.parent;if(R==null){m=!1;break}if(R.type!=="MemberExpression"&&R.type!=="OptionalMemberExpression"){m=!1;break}}m&&(H=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${l} call and refer to those specific props inside ${n(T)}.`)}if(!H&&q.size>0){let r=null;q.forEach(a=>{if(r)return;let m=F.set.get(a),d=j.get(a);if(d.references[0].resolved!==m)return;let g=m.defs[0];if(g==null||g.name==null||g.type!=="Parameter")return;let y=!1,R;for(let C=0;C<d.references.length;C++)if(R=d.references[C].identifier,R!=null&&R.parent!=null&&(R.parent.type==="CallExpression"||R.parent.type==="OptionalCallExpression")&&R.parent.callee===R){y=!0;break}y&&(r=a)}),r!==null&&(H=` If '${r}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!H&&q.size>0){let r=null;if(q.forEach(a=>{if(r!==null)return;let d=j.get(a).references,g,y;for(let R=0;R<d.length;R++){for(g=d[R].identifier,y=g.parent;y!=null&&y!==F.block;){if(y.type==="CallExpression"){let C=s.get(y.callee);if(C!=null){if(C.name===a)r={missingDep:a,setter:y.callee.name,form:"updater"};else if(f.has(g))r={missingDep:a,setter:y.callee.name,form:"reducer"};else{let L=d[R].resolved;if(L!=null){let U=L.defs[0];U!=null&&U.type==="Parameter"&&(r={missingDep:a,setter:y.callee.name,form:"inlineReducer"})}}break}}y=y.parent}if(r!==null)break}}),r!==null)switch(r.form){case"reducer":H=` You can also replace multiple useState variables with useReducer if '${r.setter}' needs the current value of '${r.missingDep}'.`;break;case"inlineReducer":H=` If '${r.setter}' needs the current value of '${r.missingDep}', you can also switch to useReducer instead of useState and read '${r.missingDep}' in the reducer.`;break;case"updater":H=` You can also do a functional update '${r.setter}(${r.missingDep.slice(0,1)} => ...)' if you only need '${r.missingDep}' in the '${r.setter}' call.`;break;default:throw new Error("Unknown case.")}}u({node:D,message:`React Hook ${n(T)} has `+(ae(q,"a","missing","include")||ae(te,"an","unnecessary","exclude")||ae(ke,"a","duplicate","omit"))+H,suggest:[{desc:`Update the dependencies array to be: [${ne.map(oe).join(", ")}]`,fix(r){return r.replaceText(D,`[${ne.map(oe).join(", ")}]`)}}]})}function $(h){let D=Ft(h.callee,p);if(D===-1)return;let T=h.arguments[D],l=h.callee,b=We(l).name,E=h.arguments[D+1],A=/Effect($|[^a-z])/g.test(b);if(!T){u({node:l,message:`React Hook ${b} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!A)){if(!E&&!A){(b==="useMemo"||b==="useCallback")&&u({node:l,message:`React Hook ${b} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(T.type){case"FunctionExpression":case"ArrowFunctionExpression":S(T,E,l,b,A);return;case"Identifier":if(!E||E.elements&&E.elements.some(P=>P&&P.type==="Identifier"&&P.name===T.name))return;let F=o(h).set.get(T.name);if(F==null||F.defs==null)return;let w=F.defs[0];if(!w||!w.node||w.type!=="Variable"&&w.type!=="FunctionName")break;switch(w.node.type){case"FunctionDeclaration":S(w.node,E,l,b,A);return;case"VariableDeclarator":let P=w.node.init;if(!P)break;switch(P.type){case"ArrowFunctionExpression":case"FunctionExpression":S(P,E,l,b,A);return}break}break;default:u({node:l,message:`React Hook ${b} received a function whose dependencies are unknown. Pass an inline function instead.`});return}u({node:l,message:`React Hook ${b} has a missing dependency: '${T.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${T.name}]`,fix(F){return F.replaceText(E,`[${T.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let h of e.sourceCode.getAllComments())if(Dt.test(h.value))return t=!0,{CallExpression:D=>$(D,!0)}}return{CallExpression:h=>$(h)}}};function pe({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:o,isEffect:c}){let x=p();function p(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((S,$)=>{let h=u(x,$);h.isUsed=!0,i(x,$,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:S})=>{let $=u(x,S);$.isSatisfiedRecursively=!0}),n.forEach(S=>{let $=u(x,S);$.isSatisfiedRecursively=!0});function u(S,$){let h=$.split("."),D=S;for(let T of h){let l=D.children.get(T);l||(l=p(),D.children.set(T,l)),D=l}return D}function i(S,$,h){let D=$.split("."),T=S;for(let l of D){let b=T.children.get(l);if(!b)return;h(b),T=b}}let s=new Set,f=new Set;I(x,s,f,S=>S);function I(S,$,h,D){S.children.forEach((T,l)=>{let b=D(l);if(T.isSatisfiedRecursively){T.isSubtreeUsed&&h.add(b);return}if(T.isUsed){$.add(b);return}I(T,$,h,E=>b+"."+E)})}let k=[],M=new Set,v=new Set;return t.forEach(({key:S})=>{f.has(S)?k.indexOf(S)===-1?k.push(S):v.add(S):M.add(S)}),s.forEach(S=>{k.push(S)}),{suggestedDependencies:k,unnecessaryDependencies:M,duplicateDependencies:v,missingDependencies:s}}function G(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 G(e.consequent)!=null||G(e.alternate)!=null?"conditional":null;case"LogicalExpression":return G(e.left)!=null||G(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return G(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return G(e.expression);case"TSAsExpression":return G(e.expression)}return null}function Ot({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:o}){let c=e.map(({key:p})=>{let u=n.variables.find(s=>s.name===p);if(u==null)return null;let i=u.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 s=G(i.node.init);if(s!=null)return[u,s]}return i.type==="FunctionName"&&i.node.type==="FunctionDeclaration"?[u,"function"]:i.type==="ClassName"&&i.node.type==="ClassDeclaration"?[u,"class"]:null}).filter(Boolean);function x(p){let u=!1;for(let i=0;i<p.references.length;i++){let s=p.references[i];if(s.writeExpr){if(u)return!0;u=!0;continue}let f=s.from;for(;f!==o&&f!=null;)f=f.upper;if(f!==o&&!Ue(t,s.identifier))return!0}return!1}return c.map(([p,u])=>({construction:p.defs[0],depType:u,isUsedOutsideOfHook:x(p)}))}function Ne(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)?Ne(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function me(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function V(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let n=e.name;return t&&t.set(n,!1),n}else if(e.type==="MemberExpression"&&!e.computed){let n=V(e.object,t),o=V(e.property,null),c=`${n}.${o}`;return me(e,t,c),c}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=V(e.object,t),o=V(e.property,null),c=`${n}.${o}`;return me(e,t,c),c}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let o=V(n.object,t),c=V(n.property,null),x=`${o}.${c}`;return me(n,t,x),x}else throw new Error(`Unsupported node type: ${e.type}`)}function We(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Ft(e,t){let n=We(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let o;try{o=V(n,null)}catch(c){if(/Unsupported node type/.test(c.message))return 0;throw c}return t.additionalHooks.test(o)?0:-1}else return-1}}function de(e,t){let n=[e],o=null;for(;n.length;){if(o=n.shift(),Pt(o,t))return o;if(Ue(o,t))for(let[c,x]of Object.entries(o))c!=="parent"&&(Le(x)?(x.parent=o,n.push(x)):Array.isArray(x)&&x.forEach(p=>{Le(p)&&(p.parent=o,n.push(p))}))}return null}function Mt(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function Le(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Pt(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 Ue(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function _t(e){return!1}var K=require("@typescript-eslint/utils"),jt=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ze="no-call-with-inferred-generics",Lt=jt({name:ze,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e){let t=e.options[0],n=new Map(t.functions.map(o=>[o.name,o]));return{CallExpression(o){let{callee:c}=o;if(c.type!==K.AST_NODE_TYPES.Identifier)return;let x=n.get(c.name);if(!x)return;let{minGenerics:p=1,allowAny:u,disallowTypes:i=t.disallowTypes}=x;(o.typeArguments?.params.length||0)<(p||0)&&e.report({node:o,messageId:"missingGenericDeclaration",data:{functionName:c.name,minGenerics:p||0}}),!(u&&!i)&&o.typeArguments?.params?.some(f=>!u&&f.type===K.AST_NODE_TYPES.TSAnyKeyword||i&&f.type===K.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===K.AST_NODE_TYPES.Identifier&&i.includes(f.typeName.name))&&e.report({node:o,messageId:"anyUsedInGenerics",data:{functionName:c.name}})}}}}),ye={name:ze,rule:Lt};var Q=require("@typescript-eslint/utils"),Ht=Q.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ve="no-commented-out-code",Nt=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Wt=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Ut=Ht({name:Ve,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create:function(e){function t(n){if(n.startsWith("/"))return!1;let o=n.trimStart();if(n.startsWith("*")||o.startsWith("INFO:")||o.startsWith("TODO:")||o.startsWith("DOCS:")||o.startsWith("FIX:")||o.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let c of Nt)if(o.startsWith(c))return{wrongPattern:c};for(let c of Wt)if(typeof c=="string"){if(n.includes(c))return{wrongPattern:c}}else if(c.test(n))return{wrongPattern:`regex(${c.toString()})`};return!1}return{Program(){let o=e.sourceCode.getAllComments();for(let c of o)if(c.type===Q.TSESTree.AST_TOKEN_TYPES.Line||c.type===Q.TSESTree.AST_TOKEN_TYPES.Block){let x=t(c.value);x&&e.report({node:c,messageId:"commentedOutCode",data:{wrongPattern:x.wrongPattern}})}}}}}),ge={name:Ve,rule:Ut};var Be=require("@typescript-eslint/utils"),zt=Be.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qe="no-default-export",Vt=zt({name:qe,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),he={name:qe,rule:Vt};var B=require("@typescript-eslint/utils"),Bt=B.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ge="no-non-camel-case-functions",qt=/^[a-z][a-zA-Z0-9]*$/;function Xe(e){return e.typeName.type===B.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===B.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===B.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var Xt=Bt({name:Ge,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!qt.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===B.AST_NODE_TYPES.TSTypeReference?Xe(n):n.type===B.AST_NODE_TYPES.TSUnionType&&n.types.some(c=>c.type===B.AST_NODE_TYPES.TSTypeReference&&Xe(c))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),be={name:Ge,rule:Xt};var O=require("@typescript-eslint/utils");var Gt=O.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Ke(e){let t=[];for(let n of e.members)n.type===O.AST_NODE_TYPES.TSPropertySignature&&n.key.type===O.AST_NODE_TYPES.Identifier&&t.push([n.key.name,n]);return t}function Je(e,...t){for(let n of t)e.set(...n);return e}var Kt=W({forceCheckOnFCPropTypesWithName:z(X(_()))}),Ye="no-unused-type-props-in-args",Se=null,Jt=Gt({name:Ye,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Kt],fixable:"code"},defaultOptions:[{}],create:function(e){let{forceCheckOnFCPropTypesWithName:t}=e.options[0]||{};t&&!Se&&(Se=t.map(p=>new RegExp(p)));function n(p,u,i,s,f=!0){let I=i.name,k=e.sourceCode.getScope(u).references.find(S=>S.identifier.name===I)?.resolved,M=p&&Se?.some(S=>S.test(I));if(!k||!M&&k.references.filter(S=>S.isTypeReference).length>1)return;let v=k?.defs[0]?.node;if(!(f&&v?.parent?.type===O.AST_NODE_TYPES.ExportNamedDeclaration)){if(v?.type===O.AST_NODE_TYPES.TSTypeAliasDeclaration){o(p,u,s,v.typeAnnotation,!0);return}if(v?.type===O.AST_NODE_TYPES.TSInterfaceDeclaration){o(p,u,s,v.body,!0);return}}}function o(p,u,i,s,f){if(s.type===O.AST_NODE_TYPES.TSInterfaceBody){for(let I of s.body)I.type===O.AST_NODE_TYPES.TSPropertySignature&&I.key.type===O.AST_NODE_TYPES.Identifier&&i.set(I.key.name,I);return}if(s.type===O.AST_NODE_TYPES.TSTypeLiteral){Je(i,...Ke(s));return}if(s.type===O.AST_NODE_TYPES.TSIntersectionType){for(let I of s.types)o(p,u,i,I,!0);return}f||s.type===O.AST_NODE_TYPES.TSTypeReference&&s.typeName.type===O.AST_NODE_TYPES.Identifier&&n(p,u,s.typeName,i)}function c(p,u,i){for(let s of i)if(s.type==="ObjectPattern"&&s.typeAnnotation){let f=new Map;if(o(p,u,f,s.typeAnnotation.typeAnnotation,!1),f.size===0)continue;x(s,f)}else s.type===O.AST_NODE_TYPES.AssignmentPattern&&s.left.type===O.AST_NODE_TYPES.ObjectPattern&&c(p,u,[s.left])}function x(p,u){let i=[];if(p.properties.at(-1)?.type===O.AST_NODE_TYPES.RestElement)return;for(let k of p.properties)k.type===O.AST_NODE_TYPES.Property&&k.key.type===O.AST_NODE_TYPES.Identifier&&i.push(k.key.name);let f=[],I=[];for(let[k,M]of u)i.includes(k)||(I.push(k),f.push({node:M,messageId:"unusedObjectTypeProperty",data:{propertyName:k}}));for(let[k,M]of f.entries())e.report({...M,fix:k===f.length-1?v=>{let S=p.properties.at(-1),$=I.join(", ");return S?S?.type===O.AST_NODE_TYPES.RestElement?null:v.insertTextAfter(S,`, ${$}`):v.insertTextBeforeRange([p.range[0]+1,p.range[1]],`${$}`)}:void 0})}return{VariableDeclaration:function(p){let u=p.declarations[0];if(!u)return;let i=new Map,s=u.id.type===O.AST_NODE_TYPES.Identifier&&u.id.typeAnnotation?.typeAnnotation.type===O.AST_NODE_TYPES.TSTypeReference&&u.id.typeAnnotation.typeAnnotation.typeName.type===O.AST_NODE_TYPES.Identifier&&u.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&u.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===O.AST_NODE_TYPES.TSTypeReference&&s.typeName.type===O.AST_NODE_TYPES.Identifier)n(!0,p,s.typeName,i,!1);else if(s.type===O.AST_NODE_TYPES.TSTypeLiteral)Je(i,...Ke(s));else if(s.type===O.AST_NODE_TYPES.TSIntersectionType)for(let f of s.types)f.type===O.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===O.AST_NODE_TYPES.Identifier?n(!0,p,f.typeName,i,!1):o(!0,p,i,f,!0);if(i.size!==0&&u.init?.type===O.AST_NODE_TYPES.ArrowFunctionExpression){let f=u.init.params[0];if(!f){e.report({node:u.init,messageId:"missingComponentParam"});return}f.type===O.AST_NODE_TYPES.ObjectPattern&&x(f,i)}}},FunctionDeclaration:function(p){c(!1,p,p.params)},ArrowFunctionExpression:function(p){c(!1,p,p.params)}}}}),Ee={name:Ye,rule:Jt};var Qe=require("@typescript-eslint/utils"),Yt=Qe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),et="prefer-named-functions",Ze=new Map,Zt=Yt({name:et,meta:{type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e){let t=e.options[0]||{},n=null;if(t.ignoreRegex){let o=Ze.get(t.ignoreRegex);o?n=o:(n=new RegExp(t.ignoreRegex),Ze.set(t.ignoreRegex,n))}return{VariableDeclarator(o){if(o.init&&o.init.type==="ArrowFunctionExpression"&&o.id.type==="Identifier"){let c=o.id.name;if(o.id.typeAnnotation||n&&n.test(c)||!t.disallowArrowFnWithImplicitReturns&&o.init.body.type!=="BlockStatement")return;e.report({node:o.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:c,ignoreRegex:t.ignoreRegex}})}}}}}),xe={name:et,rule:Zt};var tt=require("@typescript-eslint/utils"),Qt=tt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),nt="require-description",en=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,tn=/^eslint-disable-(next-)?line$/u,nn=Qt({name:nt,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e){let t=e.sourceCode,n=new Set(e.options[0]&&e.options[0].ignore||[]);return{Program(){for(let o of t.getAllComments()){let c=rn(o);c!=null&&(n.has(c.kind)||c.description||e.report({loc:on(o.loc),messageId:"missingDescription"}))}}}}}),rt={name:nt,rule:nn};function rn(e){let{text:t,description:n}=sn(e.value);if(!t)return null;let o=en.exec(t);if(!o)return null;let c=o[1];if(!c)return null;let x=tn.test(c);if(e.type==="Line"&&!x||x&&e.loc.start.line!==e.loc.end.line)return null;let p=t.slice(o.index+c.length);return{kind:c,value:p.trim(),description:n}}function sn(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function on(e){return{start:{line:e.start.line,column:-1},end:e.end}}function ot(e){return/^use[A-Z0-9]/.test(e)}function re(e){return e.type==="Identifier"?ot(e.name):e.type==="MemberExpression"&&!e.computed&&re(e.property)?e.object.type==="Identifier":!1}function at(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function ct(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function lt(e){return!!(e.parent&&e.parent.callee&&ct(e.parent.callee,"forwardRef"))}function ut(e){return!!(e.parent&&e.parent.callee&&ct(e.parent.callee,"memo"))}function Te(e){for(;e;){let t=pt(e);if(t&&(at(t)||re(t))||lt(e)||ut(e))return!0;e=e.parent}return!1}function st(e){return!1}function we(e){return!1}var an=/eslint +react-compiler\/react-compiler: +\["error/,ft={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let i of e.sourceCode.getAllComments())if(an.test(i.value))return{CallExpression(s){let f=null;s.callee.name==="useMemo"?f="useMemo":s.callee.name==="useCallback"&&(f="useCallback"),f&&e.report({node:s,message:`"${f}" is not necessary when using React Compiler.`})},VariableDeclaration(s){s.kind==="using"&&e.report({node:s,message:'"using" syntax is not yet supported by React Compiler.'})}}}let t=typeof e.getSource=="function"?i=>t(i):i=>e.sourceCode.getText(i),n=typeof e.getScope=="function"?()=>n():i=>e.sourceCode.getScope(i),o=null,c=[],x=[],p=new WeakSet;function u(i){for(let s of i.references){let f=s.identifier.parent;if(f.type==="VariableDeclarator"&&f.init&&f.init.type==="CallExpression"&&f.init.callee&&st(f.init.callee))for(let I of s.resolved.references)I!==s&&p.add(I.identifier)}}return{onCodePathSegmentStart:i=>x.push(i),onCodePathSegmentEnd:()=>x.pop(),onCodePathStart:()=>c.push(new Map),onCodePathEnd(i,s){let f=c.pop();if(f.size===0)return;let I=new Set;function k(l,b){let{cache:E}=k,A=E.get(l.id),F=new Set(b);if(F.has(l.id)){let w=[...F],P=w.slice(w.indexOf(l.id)+1);for(let N of P)I.add(N);return BigInt("0")}if(F.add(l.id),A!==void 0)return A;if(i.thrownSegments.includes(l))A=BigInt("0");else if(l.prevSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let w of l.prevSegments)A+=k(w,F)}return l.reachable&&A===BigInt("0")?E.delete(l.id):E.set(l.id,A),A}function M(l,b){let{cache:E}=M,A=E.get(l.id),F=new Set(b);if(F.has(l.id)){let w=Array.from(F),P=w.slice(w.indexOf(l.id)+1);for(let N of P)I.add(N);return BigInt("0")}if(F.add(l.id),A!==void 0)return A;if(i.thrownSegments.includes(l))A=BigInt("0");else if(l.nextSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let w of l.nextSegments)A+=M(w,F)}return E.set(l.id,A),A}function v(l){let{cache:b}=v,E=b.get(l.id);if(E===null)return 1/0;if(E!==void 0)return E;if(b.set(l.id,null),l.prevSegments.length===0)E=1;else{E=1/0;for(let A of l.prevSegments){let F=v(A);F<E&&(E=F)}E+=1}return b.set(l.id,E),E}k.cache=new Map,M.cache=new Map,v.cache=new Map;let S=M(i.initialSegment),$=pt(s),h=Te(s),D=$?at($)||re($):lt(s)||ut(s),T=1/0;for(let l of i.finalSegments){if(!l.reachable)continue;let b=v(l);b<T&&(T=b)}for(let[l,b]of f){if(!l.reachable)continue;let E=l.nextSegments.length===0?T<=v(l):T<v(l),A=k(l)*M(l),F=I.has(l.id);for(let w of b)if(F&&!we(w)&&e.report({node:w,message:`React Hook "${t(w)}" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.`}),D){if(s.async&&e.report({node:w,message:`React Hook "${t(w)}" cannot be called in an async function.`}),!F&&A!==S&&!we(w)){let N=`React Hook "${t(w)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(E?" Did you accidentally call a React Hook after an early return?":"");e.report({node:w,message:N})}}else if(s.parent&&(s.parent.type==="MethodDefinition"||s.parent.type==="ClassProperty")&&s.parent.value===s){let P=`React Hook "${t(w)}" 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:w,message:P})}else if($){let P=`React Hook "${t(w)}" is called in function "${t($)}" 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:w,message:P})}else if(s.type==="Program"){let P=`React Hook "${t(w)}" 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:w,message:P})}else if(h&&!we(w)){if(s.parent.type==="CallExpression"&&s.parent.callee.type==="Identifier"&&s.parent.callee.name==="useCallback"){let N=s.parent;if(N.parent.type==="VariableDeclarator"&&ot(N.parent.id.name))return}let P=`React Hook "${t(w)}" 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:w,message:P})}}},CallExpression(i){if(re(i.callee)){let s=it(c),f=it(x),I=s.get(f);I||(I=[],s.set(f,I)),I.push(i.callee)}i.callee.type==="Identifier"&&(i.callee.name==="useEffect"||st(i.callee))&&i.arguments.length>0&&(o=i)},Identifier(i){o==null&&p.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===o&&(o=null)},FunctionDeclaration(i){Te(i)&&u(n(i))},ArrowFunctionExpression(i){Te(i)&&u(n(i))}}}};function pt(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 it(e){return e[e.length-1]}var mt={[Ee.name]:Ee.rule,[ge.name]:ge.rule,[ye.name]:ye.rule,"rules-of-hooks":ft,"exhaustive-deps":He,"require-description":rt.rule,[he.name]:he.rule,[be.name]:be.rule,[xe.name]:xe.rule,[fe.name]:fe.rule};var cn={rules:mt};0&&(module.exports={extendedLintPlugin});
|
|
12
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let E=i.acquire(h),A=new Set,F=null;{let r=E.upper;for(;r&&(A.add(r),r.type!=="function");)r=r.upper;if(!r)return;F=r}let w=Array.isArray;function P(r){if(!w(r.defs))return!1;let a=r.defs[0];if(a==null||a.node.type!=="VariableDeclarator")return!1;let m=a.node.init;if(m==null)return!1;for(;m.type==="TSAsExpression";)m=m.expression;let d=a.node.parent;if(d==null&&(de(F.block,a.node.id),d=a.node.parent,d==null))return!1;if(d.kind==="const"&&m.type==="Literal"&&(typeof m.value=="string"||typeof m.value=="number"||m.value===null))return!0;if(m.type!=="CallExpression")return!1;let g=m.callee;if(g.type==="MemberExpression"&&g.object.name==="React"&&g.property!=null&&!g.computed&&(g=g.property),g.type!=="Identifier")return!1;let y=a.node.id,{name:R}=g;if(R==="useRef"&&y.type==="Identifier")return!0;if(_t(g)&&y.type==="Identifier"){for(let C of r.references)C!==y&&M.add(C.identifier);return!0}else if(R==="useState"||R==="useReducer"){if(y.type==="ArrayPattern"&&y.elements.length===2&&w(r.identifiers)){if(y.elements[1]===r.identifiers[0]){if(R==="useState"){let C=r.references,L=0;for(let U=0;U<C.length;U++){if(C[U].isWrite()&&L++,L>1)return!1;s.set(C[U].identifier,y.elements[0])}}return!0}else if(y.elements[0]===r.identifiers[0]){if(R==="useState"){let C=r.references;for(let L=0;L<C.length;L++)f.add(C[L].identifier)}return!1}}}else if(R==="useTransition"&&y.type==="ArrayPattern"&&y.elements.length===2&&Array.isArray(r.identifiers)&&y.elements[1]===r.identifiers[0])return!0;return!1}function N(r){if(!w(r.defs))return!1;let a=r.defs[0];if(a==null||a.node==null||a.node.id==null)return!1;let m=a.node,d=F.childScopes,g=null,y;for(y=0;y<d.length;y++){let R=d[y],C=R.block;if(m.type==="FunctionDeclaration"&&C===m||m.type==="VariableDeclarator"&&C.parent===m){g=R;break}}if(g==null)return!1;for(y=0;y<g.through.length;y++){let R=g.through[y];if(R.resolved!=null&&A.has(R.resolved.scope)&&!Re(R.resolved))return!1}return!0}let Re=v(P,I),dt=v(N,k),Ie=new Map;function yt(r){let a=r.from,m=!1;for(;a.block!==h;)a.type==="function"&&(m=a.block.parent!=null&&a.block.parent.type==="ReturnStatement"),a=a.upper;return m}let j=new Map,se=new Map;Ce(E);function Ce(r){for(let a of r.references){if(!a.resolved||!A.has(a.resolved.scope))continue;let m=de(h,a.identifier),d=Ne(m),g=V(d,se);if(b&&d.type==="Identifier"&&(d.parent.type==="MemberExpression"||d.parent.type==="OptionalMemberExpression")&&!d.parent.computed&&d.parent.property.type==="Identifier"&&d.parent.property.name==="current"&&yt(a)&&Ie.set(g,{reference:a,dependencyNode:d}),d.parent.type==="TSTypeQuery"||d.parent.type==="TSTypeReference")continue;let y=a.resolved.defs[0];if(y!=null&&!(y.node!=null&&y.node.init===h.parent)&&y.type!=="TypeParameter")if(j.has(g))j.get(g).references.push(a);else{let R=a.resolved,C=Re(R)||dt(R);j.set(g,{isStable:C,references:[a]})}}for(let a of r.childScopes)Ce(a)}Ie.forEach(({reference:r,dependencyNode:a},m)=>{let d=r.resolved.references,g=!1;for(let y=0;y<d.length;y++){let{identifier:R}=d[y],{parent:C}=R;if(C!=null&&C.type==="MemberExpression"&&!C.computed&&C.property.type==="Identifier"&&C.property.name==="current"&&C.parent.type==="AssignmentExpression"&&C.parent.left===C){g=!0;break}}g||u({node:a.parent.property,message:`The ref value '${m}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${m}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let ie=new Set;function gt(r,a){ie.has(a)||(ie.add(a),u({node:r,message:`Assignments to the '${a}' variable from inside React Hook ${n(T)} 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(T)}.`}))}let ee=new Set;if(j.forEach(({isStable:r,references:a},m)=>{r&&ee.add(m),a.forEach(d=>{d.writeExpr&>(d.writeExpr,m)})}),ie.size>0)return;if(!D){let r=null;if(j.forEach(({isStable:a,references:m},d)=>{r||m.forEach(g=>{if(r)return;let y=g.identifier;if(!s.has(y))return;let C=g.from;for(;C.type!=="function";)C=C.upper;C.block===h&&(r=d)})}),r){let{suggestedDependencies:a}=pe({dependencies:j,declaredDependencies:[],stableDependencies:ee,externalDependencies:new Set,isEffect:!0});u({node:T,message:`React Hook ${l} contains a call to '${r}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+a.join(", ")+`] as a second argument to the ${l} Hook.`,suggest:[{desc:`Add dependencies array: [${a.join(", ")}]`,fix(m){return m.insertTextAfter(h,`, [${a.join(", ")}]`)}}]})}return}let Y=[],Z=new Set;D.type!=="ArrayExpression"?u({node:D,message:`React Hook ${n(T)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(r=>{if(r===null)return;if(r.type==="SpreadElement"){u({node:r,message:`React Hook ${n(T)} 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(r)&&u({node:r,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(r)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(r)}\``,fix(g){return g.removeRange(r.range)}}]});let a;try{a=V(r,se)}catch(g){if(/Unsupported node type/.test(g.message)){r.type==="Literal"?j.has(r.value)?u({node:r,message:`The ${r.raw} literal is not a valid dependency because it never changes. Did you mean to include ${r.value} in the array instead?`}):u({node:r,message:`The ${r.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):u({node:r,message:`React Hook ${n(T)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw g}let m=r;for(;m.type==="MemberExpression"||m.type==="OptionalMemberExpression"||m.type==="ChainExpression";)m=m.object||m.expression.object;let d=!F.through.some(g=>g.identifier===m);Y.push({key:a,node:r}),d||Z.add(a)});let{suggestedDependencies:ht,unnecessaryDependencies:te,missingDependencies:q,duplicateDependencies:ke}=pe({dependencies:j,declaredDependencies:Y,stableDependencies:ee,externalDependencies:Z,isEffect:b}),ne=ht;if(ke.size+q.size+te.size===0){if(t)return;Ot({declaredDependencies:Y,declaredDependenciesNode:D,componentScope:F,scope:E}).forEach(({construction:a,isUsedOutsideOfHook:m,depType:d})=>{let g=d==="function"?"useCallback":"useMemo",y=d==="function"?"definition":"initialization",R=`wrap the ${y} of '${a.name.name}' in its own ${g}() Hook.`,C=m?`To fix this, ${R}`:`Move it inside the ${l} callback. Alternatively, ${R}`,L=d==="conditional"||d==="logical expression"?"could make":"makes",U=`The '${a.name.name}' ${d} ${L} the dependencies of ${l} Hook (at line ${D.loc.start.line}) change on every render. ${C}`,ve;m&&a.type==="Variable"&&d==="function"&&(ve=[{desc:`Wrap the ${y} of '${a.name.name}' in its own ${g}() Hook.`,fix($e){let[St,Et]=g==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[$e.insertTextBefore(a.node.init,St),$e.insertTextAfter(a.node.init,Et)]}}]),u({node:a.node,message:U,suggest:ve})});return}!b&&q.size>0&&(ne=pe({dependencies:j,declaredDependencies:[],stableDependencies:ee,externalDependencies:Z,isEffect:b}).suggestedDependencies);function bt(){if(Y.length===0)return!0;let r=Y.map(m=>m.key),a=r.slice().sort();return r.join(",")===a.join(",")}bt()&&ne.sort();function oe(r){let a=r.split("."),m="";for(let d=0;d<a.length;d++){if(d!==0){let g=a.slice(0,d+1).join("."),y=se.get(g)===!0;m+=y?"?.":"."}m+=a[d]}return m}function ae(r,a,m,d){return r.size===0?null:(r.size>1?"":a+" ")+m+" "+(r.size>1?"dependencies":"dependency")+": "+Mt(Array.from(r).sort().map(g=>"'"+oe(g)+"'"))+`. Either ${d} ${r.size>1?"them":"it"} or remove the dependency array.`}let H="";if(te.size>0){let r=null;if(Array.from(te.keys()).forEach(a=>{r===null&&a.endsWith(".current")&&(r=a)}),r!==null)H=` Mutable values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(Z.size>0){let a=Array.from(Z)[0];E.set.has(a)||(H=` Outer scope values like '${a}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!H&&q.has("props")){let r=j.get("props");if(r==null)return;let a=r.references;if(!Array.isArray(a))return;let m=!0;for(let d=0;d<a.length;d++){let g=a[d],y=de(F.block,g.identifier);if(!y){m=!1;break}let R=y.parent;if(R==null){m=!1;break}if(R.type!=="MemberExpression"&&R.type!=="OptionalMemberExpression"){m=!1;break}}m&&(H=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${l} call and refer to those specific props inside ${n(T)}.`)}if(!H&&q.size>0){let r=null;q.forEach(a=>{if(r)return;let m=F.set.get(a),d=j.get(a);if(d.references[0].resolved!==m)return;let g=m.defs[0];if(g==null||g.name==null||g.type!=="Parameter")return;let y=!1,R;for(let C=0;C<d.references.length;C++)if(R=d.references[C].identifier,R!=null&&R.parent!=null&&(R.parent.type==="CallExpression"||R.parent.type==="OptionalCallExpression")&&R.parent.callee===R){y=!0;break}y&&(r=a)}),r!==null&&(H=` If '${r}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!H&&q.size>0){let r=null;if(q.forEach(a=>{if(r!==null)return;let d=j.get(a).references,g,y;for(let R=0;R<d.length;R++){for(g=d[R].identifier,y=g.parent;y!=null&&y!==F.block;){if(y.type==="CallExpression"){let C=s.get(y.callee);if(C!=null){if(C.name===a)r={missingDep:a,setter:y.callee.name,form:"updater"};else if(f.has(g))r={missingDep:a,setter:y.callee.name,form:"reducer"};else{let L=d[R].resolved;if(L!=null){let U=L.defs[0];U!=null&&U.type==="Parameter"&&(r={missingDep:a,setter:y.callee.name,form:"inlineReducer"})}}break}}y=y.parent}if(r!==null)break}}),r!==null)switch(r.form){case"reducer":H=` You can also replace multiple useState variables with useReducer if '${r.setter}' needs the current value of '${r.missingDep}'.`;break;case"inlineReducer":H=` If '${r.setter}' needs the current value of '${r.missingDep}', you can also switch to useReducer instead of useState and read '${r.missingDep}' in the reducer.`;break;case"updater":H=` You can also do a functional update '${r.setter}(${r.missingDep.slice(0,1)} => ...)' if you only need '${r.missingDep}' in the '${r.setter}' call.`;break;default:throw new Error("Unknown case.")}}u({node:D,message:`React Hook ${n(T)} has `+(ae(q,"a","missing","include")||ae(te,"an","unnecessary","exclude")||ae(ke,"a","duplicate","omit"))+H,suggest:[{desc:`Update the dependencies array to be: [${ne.map(oe).join(", ")}]`,fix(r){return r.replaceText(D,`[${ne.map(oe).join(", ")}]`)}}]})}function $(h){let D=Ft(h.callee,p);if(D===-1)return;let T=h.arguments[D],l=h.callee,b=We(l).name,E=h.arguments[D+1],A=/Effect($|[^a-z])/g.test(b);if(!T){u({node:l,message:`React Hook ${b} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!A)){if(!E&&!A){(b==="useMemo"||b==="useCallback")&&u({node:l,message:`React Hook ${b} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(T.type){case"FunctionExpression":case"ArrowFunctionExpression":S(T,E,l,b,A);return;case"Identifier":if(!E||E.elements&&E.elements.some(P=>P&&P.type==="Identifier"&&P.name===T.name))return;let F=o(h).set.get(T.name);if(F==null||F.defs==null)return;let w=F.defs[0];if(!w||!w.node||w.type!=="Variable"&&w.type!=="FunctionName")break;switch(w.node.type){case"FunctionDeclaration":S(w.node,E,l,b,A);return;case"VariableDeclarator":let P=w.node.init;if(!P)break;switch(P.type){case"ArrowFunctionExpression":case"FunctionExpression":S(P,E,l,b,A);return}break}break;default:u({node:l,message:`React Hook ${b} received a function whose dependencies are unknown. Pass an inline function instead.`});return}u({node:l,message:`React Hook ${b} has a missing dependency: '${T.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${T.name}]`,fix(F){return F.replaceText(E,`[${T.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let h of e.sourceCode.getAllComments())if(Dt.test(h.value))return t=!0,{CallExpression:D=>$(D,!0)}}return{CallExpression:h=>$(h)}}};function pe({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:o,isEffect:c}){let x=p();function p(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((S,$)=>{let h=u(x,$);h.isUsed=!0,i(x,$,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:S})=>{let $=u(x,S);$.isSatisfiedRecursively=!0}),n.forEach(S=>{let $=u(x,S);$.isSatisfiedRecursively=!0});function u(S,$){let h=$.split("."),D=S;for(let T of h){let l=D.children.get(T);l||(l=p(),D.children.set(T,l)),D=l}return D}function i(S,$,h){let D=$.split("."),T=S;for(let l of D){let b=T.children.get(l);if(!b)return;h(b),T=b}}let s=new Set,f=new Set;I(x,s,f,S=>S);function I(S,$,h,D){S.children.forEach((T,l)=>{let b=D(l);if(T.isSatisfiedRecursively){T.isSubtreeUsed&&h.add(b);return}if(T.isUsed){$.add(b);return}I(T,$,h,E=>b+"."+E)})}let k=[],M=new Set,v=new Set;return t.forEach(({key:S})=>{f.has(S)?k.indexOf(S)===-1?k.push(S):v.add(S):M.add(S)}),s.forEach(S=>{k.push(S)}),{suggestedDependencies:k,unnecessaryDependencies:M,duplicateDependencies:v,missingDependencies:s}}function G(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 G(e.consequent)!=null||G(e.alternate)!=null?"conditional":null;case"LogicalExpression":return G(e.left)!=null||G(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return G(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return G(e.expression);case"TSAsExpression":return G(e.expression)}return null}function Ot({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:o}){let c=e.map(({key:p})=>{let u=n.variables.find(s=>s.name===p);if(u==null)return null;let i=u.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 s=G(i.node.init);if(s!=null)return[u,s]}return i.type==="FunctionName"&&i.node.type==="FunctionDeclaration"?[u,"function"]:i.type==="ClassName"&&i.node.type==="ClassDeclaration"?[u,"class"]:null}).filter(Boolean);function x(p){let u=!1;for(let i=0;i<p.references.length;i++){let s=p.references[i];if(s.writeExpr){if(u)return!0;u=!0;continue}let f=s.from;for(;f!==o&&f!=null;)f=f.upper;if(f!==o&&!Ue(t,s.identifier))return!0}return!1}return c.map(([p,u])=>({construction:p.defs[0],depType:u,isUsedOutsideOfHook:x(p)}))}function Ne(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)?Ne(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function me(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function V(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let n=e.name;return t&&t.set(n,!1),n}else if(e.type==="MemberExpression"&&!e.computed){let n=V(e.object,t),o=V(e.property,null),c=`${n}.${o}`;return me(e,t,c),c}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=V(e.object,t),o=V(e.property,null),c=`${n}.${o}`;return me(e,t,c),c}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let o=V(n.object,t),c=V(n.property,null),x=`${o}.${c}`;return me(n,t,x),x}else throw new Error(`Unsupported node type: ${e.type}`)}function We(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Ft(e,t){let n=We(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let o;try{o=V(n,null)}catch(c){if(/Unsupported node type/.test(c.message))return 0;throw c}return t.additionalHooks.test(o)?0:-1}else return-1}}function de(e,t){let n=[e],o=null;for(;n.length;){if(o=n.shift(),Pt(o,t))return o;if(Ue(o,t))for(let[c,x]of Object.entries(o))c!=="parent"&&(Le(x)?(x.parent=o,n.push(x)):Array.isArray(x)&&x.forEach(p=>{Le(p)&&(p.parent=o,n.push(p))}))}return null}function Mt(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function Le(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Pt(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 Ue(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function _t(e){return!1}var K=require("@typescript-eslint/utils"),jt=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ze="no-call-with-inferred-generics",Lt=jt({name:ze,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e){let t=e.options[0],n=new Map(t.functions.map(o=>[o.name,o]));return{CallExpression(o){let{callee:c}=o;if(c.type!==K.AST_NODE_TYPES.Identifier)return;let x=n.get(c.name);if(!x)return;let{minGenerics:p=1,allowAny:u,disallowTypes:i=t.disallowTypes}=x;(o.typeArguments?.params.length||0)<(p||0)&&e.report({node:o,messageId:"missingGenericDeclaration",data:{functionName:c.name,minGenerics:p||0}}),!(u&&!i)&&o.typeArguments?.params?.some(f=>!u&&f.type===K.AST_NODE_TYPES.TSAnyKeyword||i&&f.type===K.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===K.AST_NODE_TYPES.Identifier&&i.includes(f.typeName.name))&&e.report({node:o,messageId:"anyUsedInGenerics",data:{functionName:c.name}})}}}}),ye={name:ze,rule:Lt};var Q=require("@typescript-eslint/utils"),Ht=Q.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ve="no-commented-out-code",Nt=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Wt=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Ut=Ht({name:Ve,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create:function(e){function t(n){if(n.startsWith("/"))return!1;let o=n.trimStart();if(n.startsWith("*")||o.startsWith("INFO:")||o.startsWith("TODO:")||o.startsWith("DOCS:")||o.startsWith("FIX:")||o.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let c of Nt)if(o.startsWith(c))return{wrongPattern:c};for(let c of Wt)if(typeof c=="string"){if(n.includes(c))return{wrongPattern:c}}else if(c.test(n))return{wrongPattern:`regex(${c.toString()})`};return!1}return{Program(){let o=e.sourceCode.getAllComments();for(let c of o)if(c.type===Q.TSESTree.AST_TOKEN_TYPES.Line||c.type===Q.TSESTree.AST_TOKEN_TYPES.Block){let x=t(c.value);x&&e.report({node:c,messageId:"commentedOutCode",data:{wrongPattern:x.wrongPattern}})}}}}}),ge={name:Ve,rule:Ut};var Be=require("@typescript-eslint/utils"),zt=Be.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qe="no-default-export",Vt=zt({name:qe,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),he={name:qe,rule:Vt};var B=require("@typescript-eslint/utils"),Bt=B.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ge="no-non-camel-case-functions",qt=/^[a-z][a-zA-Z0-9]*$/;function Xe(e){return e.typeName.type===B.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===B.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===B.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var Xt=Bt({name:Ge,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!qt.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===B.AST_NODE_TYPES.TSTypeReference?Xe(n):n.type===B.AST_NODE_TYPES.TSUnionType&&n.types.some(c=>c.type===B.AST_NODE_TYPES.TSTypeReference&&Xe(c))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),be={name:Ge,rule:Xt};var O=require("@typescript-eslint/utils");var Gt=O.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Ke(e){let t=[];for(let n of e.members)n.type===O.AST_NODE_TYPES.TSPropertySignature&&n.key.type===O.AST_NODE_TYPES.Identifier&&t.push([n.key.name,n]);return t}function Je(e,...t){for(let n of t)e.set(...n);return e}var Kt=W({forceCheckOnFCPropTypesWithName:z(X(_()))}),Ye="no-unused-type-props-in-args",Se=null,Jt=Gt({name:Ye,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Kt],fixable:"code"},defaultOptions:[{}],create:function(e){let{forceCheckOnFCPropTypesWithName:t}=e.options[0]||{};t&&!Se&&(Se=t.map(p=>new RegExp(p)));function n(p,u,i,s,f=!0){let I=i.name,k=e.sourceCode.getScope(u).references.find(S=>S.identifier.name===I)?.resolved,M=p&&Se?.some(S=>S.test(I));if(!k||!M&&k.references.filter(S=>S.isTypeReference).length>1)return;let v=k?.defs[0]?.node;if(!(f&&v?.parent?.type===O.AST_NODE_TYPES.ExportNamedDeclaration)){if(v?.type===O.AST_NODE_TYPES.TSTypeAliasDeclaration){o(p,u,s,v.typeAnnotation,!0);return}if(v?.type===O.AST_NODE_TYPES.TSInterfaceDeclaration){o(p,u,s,v.body,!0);return}}}function o(p,u,i,s,f){if(s.type===O.AST_NODE_TYPES.TSInterfaceBody){for(let I of s.body)I.type===O.AST_NODE_TYPES.TSPropertySignature&&I.key.type===O.AST_NODE_TYPES.Identifier&&i.set(I.key.name,I);return}if(s.type===O.AST_NODE_TYPES.TSTypeLiteral){Je(i,...Ke(s));return}if(s.type===O.AST_NODE_TYPES.TSIntersectionType){for(let I of s.types)o(p,u,i,I,!0);return}f||s.type===O.AST_NODE_TYPES.TSTypeReference&&s.typeName.type===O.AST_NODE_TYPES.Identifier&&n(p,u,s.typeName,i)}function c(p,u,i){for(let s of i)if(s.type==="ObjectPattern"&&s.typeAnnotation){let f=new Map;if(o(p,u,f,s.typeAnnotation.typeAnnotation,!1),f.size===0)continue;x(s,f)}else s.type===O.AST_NODE_TYPES.AssignmentPattern&&s.left.type===O.AST_NODE_TYPES.ObjectPattern&&c(p,u,[s.left])}function x(p,u){let i=[];if(p.properties.at(-1)?.type===O.AST_NODE_TYPES.RestElement)return;for(let k of p.properties)k.type===O.AST_NODE_TYPES.Property&&k.key.type===O.AST_NODE_TYPES.Identifier&&i.push(k.key.name);let f=[],I=[];for(let[k,M]of u)i.includes(k)||(I.push(k),f.push({node:M,messageId:"unusedObjectTypeProperty",data:{propertyName:k}}));for(let[k,M]of f.entries())e.report({...M,fix:k===f.length-1?v=>{let S=p.properties.at(-1),$=I.join(", ");return S?S?.type===O.AST_NODE_TYPES.RestElement?null:v.insertTextAfter(S,`, ${$}`):v.insertTextBeforeRange([p.range[0]+1,p.range[1]],`${$}`)}:void 0})}return{VariableDeclaration:function(p){let u=p.declarations[0];if(!u)return;let i=new Map,s=u.id.type===O.AST_NODE_TYPES.Identifier&&u.id.typeAnnotation?.typeAnnotation.type===O.AST_NODE_TYPES.TSTypeReference&&u.id.typeAnnotation.typeAnnotation.typeName.type===O.AST_NODE_TYPES.Identifier&&u.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&u.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===O.AST_NODE_TYPES.TSTypeReference&&s.typeName.type===O.AST_NODE_TYPES.Identifier)n(!0,p,s.typeName,i,!1);else if(s.type===O.AST_NODE_TYPES.TSTypeLiteral)Je(i,...Ke(s));else if(s.type===O.AST_NODE_TYPES.TSIntersectionType)for(let f of s.types)f.type===O.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===O.AST_NODE_TYPES.Identifier?n(!0,p,f.typeName,i,!1):o(!0,p,i,f,!0);if(i.size!==0&&u.init?.type===O.AST_NODE_TYPES.ArrowFunctionExpression){let f=u.init.params[0];if(!f){e.report({node:u.init,messageId:"missingComponentParam"});return}f.type===O.AST_NODE_TYPES.ObjectPattern&&x(f,i)}}},FunctionDeclaration:function(p){c(!1,p,p.params)},ArrowFunctionExpression:function(p){c(!1,p,p.params)}}}}),Ee={name:Ye,rule:Jt};var Qe=require("@typescript-eslint/utils"),Yt=Qe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),et="prefer-named-functions",Ze=new Map,Zt=Yt({name:et,meta:{type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e){let t=e.options[0]||{},n=null;if(t.ignoreRegex){let o=Ze.get(t.ignoreRegex);o?n=o:(n=new RegExp(t.ignoreRegex),Ze.set(t.ignoreRegex,n))}return{VariableDeclarator(o){if(o.init&&o.init.type==="ArrowFunctionExpression"&&o.id.type==="Identifier"){let c=o.id.name;if(o.id.typeAnnotation||n&&n.test(c)||!t.disallowArrowFnWithImplicitReturns&&o.init.body.type!=="BlockStatement")return;e.report({node:o.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:c,ignoreRegex:t.ignoreRegex}})}}}}}),xe={name:et,rule:Zt};var tt=require("@typescript-eslint/utils"),Qt=tt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),nt="require-description",en=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,tn=/^eslint-disable-(next-)?line$/u,nn=Qt({name:nt,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e){let t=e.sourceCode,n=new Set(e.options[0]&&e.options[0].ignore||[]);return{Program(){for(let o of t.getAllComments()){let c=rn(o);c!=null&&(n.has(c.kind)||c.description||e.report({loc:on(o.loc),messageId:"missingDescription"}))}}}}}),rt={name:nt,rule:nn};function rn(e){let{text:t,description:n}=sn(e.value);if(!t)return null;let o=en.exec(t);if(!o)return null;let c=o[1];if(!c)return null;let x=tn.test(c);if(e.type==="Line"&&!x||x&&e.loc.start.line!==e.loc.end.line)return null;let p=t.slice(o.index+c.length);return{kind:c,value:p.trim(),description:n}}function sn(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function on(e){return{start:{line:e.start.line,column:-1},end:e.end}}function ot(e){return/^use[A-Z0-9]/.test(e)}function re(e){return e.type==="Identifier"?ot(e.name):e.type==="MemberExpression"&&!e.computed&&re(e.property)?e.object.type==="Identifier":!1}function at(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function ct(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function lt(e){return!!(e.parent&&e.parent.callee&&ct(e.parent.callee,"forwardRef"))}function ut(e){return!!(e.parent&&e.parent.callee&&ct(e.parent.callee,"memo"))}function Te(e){for(;e;){let t=pt(e);if(t&&(at(t)||re(t))||lt(e)||ut(e))return!0;e=e.parent}return!1}function st(e){return!1}function we(e){return!1}var an=/eslint +react-compiler\/react-compiler: +\["error/,ft={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let i of e.sourceCode.getAllComments())if(an.test(i.value))return{CallExpression(s){let f=null;s.callee.name==="useMemo"?f="useMemo":s.callee.name==="useCallback"&&(f="useCallback"),f&&e.report({node:s,message:`"${f}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?i=>t(i):i=>e.sourceCode.getText(i),n=typeof e.getScope=="function"?()=>n():i=>e.sourceCode.getScope(i),o=null,c=[],x=[],p=new WeakSet;function u(i){for(let s of i.references){let f=s.identifier.parent;if(f.type==="VariableDeclarator"&&f.init&&f.init.type==="CallExpression"&&f.init.callee&&st(f.init.callee))for(let I of s.resolved.references)I!==s&&p.add(I.identifier)}}return{onCodePathSegmentStart:i=>x.push(i),onCodePathSegmentEnd:()=>x.pop(),onCodePathStart:()=>c.push(new Map),onCodePathEnd(i,s){let f=c.pop();if(f.size===0)return;let I=new Set;function k(l,b){let{cache:E}=k,A=E.get(l.id),F=new Set(b);if(F.has(l.id)){let w=[...F],P=w.slice(w.indexOf(l.id)+1);for(let N of P)I.add(N);return BigInt("0")}if(F.add(l.id),A!==void 0)return A;if(i.thrownSegments.includes(l))A=BigInt("0");else if(l.prevSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let w of l.prevSegments)A+=k(w,F)}return l.reachable&&A===BigInt("0")?E.delete(l.id):E.set(l.id,A),A}function M(l,b){let{cache:E}=M,A=E.get(l.id),F=new Set(b);if(F.has(l.id)){let w=Array.from(F),P=w.slice(w.indexOf(l.id)+1);for(let N of P)I.add(N);return BigInt("0")}if(F.add(l.id),A!==void 0)return A;if(i.thrownSegments.includes(l))A=BigInt("0");else if(l.nextSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let w of l.nextSegments)A+=M(w,F)}return E.set(l.id,A),A}function v(l){let{cache:b}=v,E=b.get(l.id);if(E===null)return 1/0;if(E!==void 0)return E;if(b.set(l.id,null),l.prevSegments.length===0)E=1;else{E=1/0;for(let A of l.prevSegments){let F=v(A);F<E&&(E=F)}E+=1}return b.set(l.id,E),E}k.cache=new Map,M.cache=new Map,v.cache=new Map;let S=M(i.initialSegment),$=pt(s),h=Te(s),D=$?at($)||re($):lt(s)||ut(s),T=1/0;for(let l of i.finalSegments){if(!l.reachable)continue;let b=v(l);b<T&&(T=b)}for(let[l,b]of f){if(!l.reachable)continue;let E=l.nextSegments.length===0?T<=v(l):T<v(l),A=k(l)*M(l),F=I.has(l.id);for(let w of b)if(F&&!we(w)&&e.report({node:w,message:`React Hook "${t(w)}" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.`}),D){if(s.async&&e.report({node:w,message:`React Hook "${t(w)}" cannot be called in an async function.`}),!F&&A!==S&&!we(w)){let N=`React Hook "${t(w)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(E?" Did you accidentally call a React Hook after an early return?":"");e.report({node:w,message:N})}}else if(s.parent&&(s.parent.type==="MethodDefinition"||s.parent.type==="ClassProperty")&&s.parent.value===s){let P=`React Hook "${t(w)}" 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:w,message:P})}else if($){let P=`React Hook "${t(w)}" is called in function "${t($)}" 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:w,message:P})}else if(s.type==="Program"){let P=`React Hook "${t(w)}" 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:w,message:P})}else if(h&&!we(w)){if(s.parent.type==="CallExpression"&&s.parent.callee.type==="Identifier"&&s.parent.callee.name==="useCallback"){let N=s.parent;if(N.parent.type==="VariableDeclarator"&&ot(N.parent.id.name))return}let P=`React Hook "${t(w)}" 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:w,message:P})}}},CallExpression(i){if(re(i.callee)){let s=it(c),f=it(x),I=s.get(f);I||(I=[],s.set(f,I)),I.push(i.callee)}i.callee.type==="Identifier"&&(i.callee.name==="useEffect"||st(i.callee))&&i.arguments.length>0&&(o=i)},Identifier(i){o==null&&p.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===o&&(o=null)},FunctionDeclaration(i){Te(i)&&u(n(i))},ArrowFunctionExpression(i){Te(i)&&u(n(i))}}}};function pt(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 it(e){return e[e.length-1]}var mt={[Ee.name]:Ee.rule,[ge.name]:ge.rule,[ye.name]:ye.rule,"rules-of-hooks":ft,"exhaustive-deps":He,"require-description":rt.rule,[he.name]:he.rule,[be.name]:be.rule,[xe.name]:xe.rule,[fe.name]:fe.rule};var cn={rules:mt};0&&(module.exports={extendedLintPlugin});
|
package/dist/extended-lint.mjs
CHANGED
|
@@ -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 E=i.acquire(h),A=new Set,O=null;{let r=E.upper;for(;r&&(A.add(r),r.type!=="function");)r=r.upper;if(!r)return;O=r}let w=Array.isArray;function P(r){if(!w(r.defs))return!1;let o=r.defs[0];if(o==null||o.node.type!=="VariableDeclarator")return!1;let m=o.node.init;if(m==null)return!1;for(;m.type==="TSAsExpression";)m=m.expression;let d=o.node.parent;if(d==null&&(pe(O.block,o.node.id),d=o.node.parent,d==null))return!1;if(d.kind==="const"&&m.type==="Literal"&&(typeof m.value=="string"||typeof m.value=="number"||m.value===null))return!0;if(m.type!=="CallExpression")return!1;let g=m.callee;if(g.type==="MemberExpression"&&g.object.name==="React"&&g.property!=null&&!g.computed&&(g=g.property),g.type!=="Identifier")return!1;let y=o.node.id,{name:R}=g;if(R==="useRef"&&y.type==="Identifier")return!0;if(kt(g)&&y.type==="Identifier"){for(let C of r.references)C!==y&&F.add(C.identifier);return!0}else if(R==="useState"||R==="useReducer"){if(y.type==="ArrayPattern"&&y.elements.length===2&&w(r.identifiers)){if(y.elements[1]===r.identifiers[0]){if(R==="useState"){let C=r.references,L=0;for(let U=0;U<C.length;U++){if(C[U].isWrite()&&L++,L>1)return!1;s.set(C[U].identifier,y.elements[0])}}return!0}else if(y.elements[0]===r.identifiers[0]){if(R==="useState"){let C=r.references;for(let L=0;L<C.length;L++)f.add(C[L].identifier)}return!1}}}else if(R==="useTransition"&&y.type==="ArrayPattern"&&y.elements.length===2&&Array.isArray(r.identifiers)&&y.elements[1]===r.identifiers[0])return!0;return!1}function N(r){if(!w(r.defs))return!1;let o=r.defs[0];if(o==null||o.node==null||o.node.id==null)return!1;let m=o.node,d=O.childScopes,g=null,y;for(y=0;y<d.length;y++){let R=d[y],C=R.block;if(m.type==="FunctionDeclaration"&&C===m||m.type==="VariableDeclarator"&&C.parent===m){g=R;break}}if(g==null)return!1;for(y=0;y<g.through.length;y++){let R=g.through[y];if(R.resolved!=null&&A.has(R.resolved.scope)&&!Te(R.resolved))return!1}return!0}let Te=v(P,I),ut=v(N,k),we=new Map;function ft(r){let o=r.from,m=!1;for(;o.block!==h;)o.type==="function"&&(m=o.block.parent!=null&&o.block.parent.type==="ReturnStatement"),o=o.upper;return m}let j=new Map,ne=new Map;Re(E);function Re(r){for(let o of r.references){if(!o.resolved||!A.has(o.resolved.scope))continue;let m=pe(h,o.identifier),d=Le(m),g=V(d,ne);if(b&&d.type==="Identifier"&&(d.parent.type==="MemberExpression"||d.parent.type==="OptionalMemberExpression")&&!d.parent.computed&&d.parent.property.type==="Identifier"&&d.parent.property.name==="current"&&ft(o)&&we.set(g,{reference:o,dependencyNode:d}),d.parent.type==="TSTypeQuery"||d.parent.type==="TSTypeReference")continue;let y=o.resolved.defs[0];if(y!=null&&!(y.node!=null&&y.node.init===h.parent)&&y.type!=="TypeParameter")if(j.has(g))j.get(g).references.push(o);else{let R=o.resolved,C=Te(R)||ut(R);j.set(g,{isStable:C,references:[o]})}}for(let o of r.childScopes)Re(o)}we.forEach(({reference:r,dependencyNode:o},m)=>{let d=r.resolved.references,g=!1;for(let y=0;y<d.length;y++){let{identifier:R}=d[y],{parent:C}=R;if(C!=null&&C.type==="MemberExpression"&&!C.computed&&C.property.type==="Identifier"&&C.property.name==="current"&&C.parent.type==="AssignmentExpression"&&C.parent.left===C){g=!0;break}}g||u({node:o.parent.property,message:`The ref value '${m}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${m}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let re=new Set;function pt(r,o){re.has(o)||(re.add(o),u({node:r,message:`Assignments to the '${o}' variable from inside React Hook ${n(T)} 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(T)}.`}))}let Y=new Set;if(j.forEach(({isStable:r,references:o},m)=>{r&&Y.add(m),o.forEach(d=>{d.writeExpr&&pt(d.writeExpr,m)})}),re.size>0)return;if(!D){let r=null;if(j.forEach(({isStable:o,references:m},d)=>{r||m.forEach(g=>{if(r)return;let y=g.identifier;if(!s.has(y))return;let C=g.from;for(;C.type!=="function";)C=C.upper;C.block===h&&(r=d)})}),r){let{suggestedDependencies:o}=ue({dependencies:j,declaredDependencies:[],stableDependencies:Y,externalDependencies:new Set,isEffect:!0});u({node:T,message:`React Hook ${l} contains a call to '${r}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+o.join(", ")+`] as a second argument to the ${l} Hook.`,suggest:[{desc:`Add dependencies array: [${o.join(", ")}]`,fix(m){return m.insertTextAfter(h,`, [${o.join(", ")}]`)}}]})}return}let K=[],J=new Set;D.type!=="ArrayExpression"?u({node:D,message:`React Hook ${n(T)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(r=>{if(r===null)return;if(r.type==="SpreadElement"){u({node:r,message:`React Hook ${n(T)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}F.has(r)&&u({node:r,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(r)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(r)}\``,fix(g){return g.removeRange(r.range)}}]});let o;try{o=V(r,ne)}catch(g){if(/Unsupported node type/.test(g.message)){r.type==="Literal"?j.has(r.value)?u({node:r,message:`The ${r.raw} literal is not a valid dependency because it never changes. Did you mean to include ${r.value} in the array instead?`}):u({node:r,message:`The ${r.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):u({node:r,message:`React Hook ${n(T)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw g}let m=r;for(;m.type==="MemberExpression"||m.type==="OptionalMemberExpression"||m.type==="ChainExpression";)m=m.object||m.expression.object;let d=!O.through.some(g=>g.identifier===m);K.push({key:o,node:r}),d||J.add(o)});let{suggestedDependencies:mt,unnecessaryDependencies:Z,missingDependencies:B,duplicateDependencies:Ie}=ue({dependencies:j,declaredDependencies:K,stableDependencies:Y,externalDependencies:J,isEffect:b}),Q=mt;if(Ie.size+B.size+Z.size===0){if(t)return;wt({declaredDependencies:K,declaredDependenciesNode:D,componentScope:O,scope:E}).forEach(({construction:o,isUsedOutsideOfHook:m,depType:d})=>{let g=d==="function"?"useCallback":"useMemo",y=d==="function"?"definition":"initialization",R=`wrap the ${y} of '${o.name.name}' in its own ${g}() Hook.`,C=m?`To fix this, ${R}`:`Move it inside the ${l} callback. Alternatively, ${R}`,L=d==="conditional"||d==="logical expression"?"could make":"makes",U=`The '${o.name.name}' ${d} ${L} the dependencies of ${l} Hook (at line ${D.loc.start.line}) change on every render. ${C}`,Ce;m&&o.type==="Variable"&&d==="function"&&(Ce=[{desc:`Wrap the ${y} of '${o.name.name}' in its own ${g}() Hook.`,fix(ke){let[yt,gt]=g==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[ke.insertTextBefore(o.node.init,yt),ke.insertTextAfter(o.node.init,gt)]}}]),u({node:o.node,message:U,suggest:Ce})});return}!b&&B.size>0&&(Q=ue({dependencies:j,declaredDependencies:[],stableDependencies:Y,externalDependencies:J,isEffect:b}).suggestedDependencies);function dt(){if(K.length===0)return!0;let r=K.map(m=>m.key),o=r.slice().sort();return r.join(",")===o.join(",")}dt()&&Q.sort();function se(r){let o=r.split("."),m="";for(let d=0;d<o.length;d++){if(d!==0){let g=o.slice(0,d+1).join("."),y=ne.get(g)===!0;m+=y?"?.":"."}m+=o[d]}return m}function ie(r,o,m,d){return r.size===0?null:(r.size>1?"":o+" ")+m+" "+(r.size>1?"dependencies":"dependency")+": "+It(Array.from(r).sort().map(g=>"'"+se(g)+"'"))+`. Either ${d} ${r.size>1?"them":"it"} or remove the dependency array.`}let H="";if(Z.size>0){let r=null;if(Array.from(Z.keys()).forEach(o=>{r===null&&o.endsWith(".current")&&(r=o)}),r!==null)H=` Mutable values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(J.size>0){let o=Array.from(J)[0];E.set.has(o)||(H=` Outer scope values like '${o}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!H&&B.has("props")){let r=j.get("props");if(r==null)return;let o=r.references;if(!Array.isArray(o))return;let m=!0;for(let d=0;d<o.length;d++){let g=o[d],y=pe(O.block,g.identifier);if(!y){m=!1;break}let R=y.parent;if(R==null){m=!1;break}if(R.type!=="MemberExpression"&&R.type!=="OptionalMemberExpression"){m=!1;break}}m&&(H=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${l} call and refer to those specific props inside ${n(T)}.`)}if(!H&&B.size>0){let r=null;B.forEach(o=>{if(r)return;let m=O.set.get(o),d=j.get(o);if(d.references[0].resolved!==m)return;let g=m.defs[0];if(g==null||g.name==null||g.type!=="Parameter")return;let y=!1,R;for(let C=0;C<d.references.length;C++)if(R=d.references[C].identifier,R!=null&&R.parent!=null&&(R.parent.type==="CallExpression"||R.parent.type==="OptionalCallExpression")&&R.parent.callee===R){y=!0;break}y&&(r=o)}),r!==null&&(H=` If '${r}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!H&&B.size>0){let r=null;if(B.forEach(o=>{if(r!==null)return;let d=j.get(o).references,g,y;for(let R=0;R<d.length;R++){for(g=d[R].identifier,y=g.parent;y!=null&&y!==O.block;){if(y.type==="CallExpression"){let C=s.get(y.callee);if(C!=null){if(C.name===o)r={missingDep:o,setter:y.callee.name,form:"updater"};else if(f.has(g))r={missingDep:o,setter:y.callee.name,form:"reducer"};else{let L=d[R].resolved;if(L!=null){let U=L.defs[0];U!=null&&U.type==="Parameter"&&(r={missingDep:o,setter:y.callee.name,form:"inlineReducer"})}}break}}y=y.parent}if(r!==null)break}}),r!==null)switch(r.form){case"reducer":H=` You can also replace multiple useState variables with useReducer if '${r.setter}' needs the current value of '${r.missingDep}'.`;break;case"inlineReducer":H=` If '${r.setter}' needs the current value of '${r.missingDep}', you can also switch to useReducer instead of useState and read '${r.missingDep}' in the reducer.`;break;case"updater":H=` You can also do a functional update '${r.setter}(${r.missingDep.slice(0,1)} => ...)' if you only need '${r.missingDep}' in the '${r.setter}' call.`;break;default:throw new Error("Unknown case.")}}u({node:D,message:`React Hook ${n(T)} has `+(ie(B,"a","missing","include")||ie(Z,"an","unnecessary","exclude")||ie(Ie,"a","duplicate","omit"))+H,suggest:[{desc:`Update the dependencies array to be: [${Q.map(se).join(", ")}]`,fix(r){return r.replaceText(D,`[${Q.map(se).join(", ")}]`)}}]})}function $(h){let D=Rt(h.callee,p);if(D===-1)return;let T=h.arguments[D],l=h.callee,b=He(l).name,E=h.arguments[D+1],A=/Effect($|[^a-z])/g.test(b);if(!T){u({node:l,message:`React Hook ${b} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!A)){if(!E&&!A){(b==="useMemo"||b==="useCallback")&&u({node:l,message:`React Hook ${b} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(T.type){case"FunctionExpression":case"ArrowFunctionExpression":S(T,E,l,b,A);return;case"Identifier":if(!E||E.elements&&E.elements.some(P=>P&&P.type==="Identifier"&&P.name===T.name))return;let O=a(h).set.get(T.name);if(O==null||O.defs==null)return;let w=O.defs[0];if(!w||!w.node||w.type!=="Variable"&&w.type!=="FunctionName")break;switch(w.node.type){case"FunctionDeclaration":S(w.node,E,l,b,A);return;case"VariableDeclarator":let P=w.node.init;if(!P)break;switch(P.type){case"ArrowFunctionExpression":case"FunctionExpression":S(P,E,l,b,A);return}break}break;default:u({node:l,message:`React Hook ${b} received a function whose dependencies are unknown. Pass an inline function instead.`});return}u({node:l,message:`React Hook ${b} has a missing dependency: '${T.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${T.name}]`,fix(O){return O.replaceText(E,`[${T.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let h of e.sourceCode.getAllComments())if(Tt.test(h.value))return t=!0,{CallExpression:D=>$(D,!0)}}return{CallExpression:h=>$(h)}}};function ue({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:a,isEffect:c}){let x=p();function p(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((S,$)=>{let h=u(x,$);h.isUsed=!0,i(x,$,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:S})=>{let $=u(x,S);$.isSatisfiedRecursively=!0}),n.forEach(S=>{let $=u(x,S);$.isSatisfiedRecursively=!0});function u(S,$){let h=$.split("."),D=S;for(let T of h){let l=D.children.get(T);l||(l=p(),D.children.set(T,l)),D=l}return D}function i(S,$,h){let D=$.split("."),T=S;for(let l of D){let b=T.children.get(l);if(!b)return;h(b),T=b}}let s=new Set,f=new Set;I(x,s,f,S=>S);function I(S,$,h,D){S.children.forEach((T,l)=>{let b=D(l);if(T.isSatisfiedRecursively){T.isSubtreeUsed&&h.add(b);return}if(T.isUsed){$.add(b);return}I(T,$,h,E=>b+"."+E)})}let k=[],F=new Set,v=new Set;return t.forEach(({key:S})=>{f.has(S)?k.indexOf(S)===-1?k.push(S):v.add(S):F.add(S)}),s.forEach(S=>{k.push(S)}),{suggestedDependencies:k,unnecessaryDependencies:F,duplicateDependencies:v,missingDependencies:s}}function X(e){switch(e.type){case"ObjectExpression":return"object";case"ArrayExpression":return"array";case"ArrowFunctionExpression":case"FunctionExpression":return"function";case"ClassExpression":return"class";case"ConditionalExpression":return X(e.consequent)!=null||X(e.alternate)!=null?"conditional":null;case"LogicalExpression":return X(e.left)!=null||X(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return X(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return X(e.expression);case"TSAsExpression":return X(e.expression)}return null}function wt({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:a}){let c=e.map(({key:p})=>{let u=n.variables.find(s=>s.name===p);if(u==null)return null;let i=u.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 s=X(i.node.init);if(s!=null)return[u,s]}return i.type==="FunctionName"&&i.node.type==="FunctionDeclaration"?[u,"function"]:i.type==="ClassName"&&i.node.type==="ClassDeclaration"?[u,"class"]:null}).filter(Boolean);function x(p){let u=!1;for(let i=0;i<p.references.length;i++){let s=p.references[i];if(s.writeExpr){if(u)return!0;u=!0;continue}let f=s.from;for(;f!==a&&f!=null;)f=f.upper;if(f!==a&&!Ne(t,s.identifier))return!0}return!1}return c.map(([p,u])=>({construction:p.defs[0],depType:u,isUsedOutsideOfHook:x(p)}))}function Le(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)?Le(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function fe(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function V(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let n=e.name;return t&&t.set(n,!1),n}else if(e.type==="MemberExpression"&&!e.computed){let n=V(e.object,t),a=V(e.property,null),c=`${n}.${a}`;return fe(e,t,c),c}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=V(e.object,t),a=V(e.property,null),c=`${n}.${a}`;return fe(e,t,c),c}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let a=V(n.object,t),c=V(n.property,null),x=`${a}.${c}`;return fe(n,t,x),x}else throw new Error(`Unsupported node type: ${e.type}`)}function He(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Rt(e,t){let n=He(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let a;try{a=V(n,null)}catch(c){if(/Unsupported node type/.test(c.message))return 0;throw c}return t.additionalHooks.test(a)?0:-1}else return-1}}function pe(e,t){let n=[e],a=null;for(;n.length;){if(a=n.shift(),Ct(a,t))return a;if(Ne(a,t))for(let[c,x]of Object.entries(a))c!=="parent"&&(_e(x)?(x.parent=a,n.push(x)):Array.isArray(x)&&x.forEach(p=>{_e(p)&&(p.parent=a,n.push(p))}))}return null}function It(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function _e(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ct(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 Ne(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function kt(e){return!1}import{AST_NODE_TYPES as ee,ESLintUtils as vt}from"@typescript-eslint/utils";var $t=vt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),We="no-call-with-inferred-generics",At=$t({name:We,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e){let t=e.options[0],n=new Map(t.functions.map(a=>[a.name,a]));return{CallExpression(a){let{callee:c}=a;if(c.type!==ee.Identifier)return;let x=n.get(c.name);if(!x)return;let{minGenerics:p=1,allowAny:u,disallowTypes:i=t.disallowTypes}=x;(a.typeArguments?.params.length||0)<(p||0)&&e.report({node:a,messageId:"missingGenericDeclaration",data:{functionName:c.name,minGenerics:p||0}}),!(u&&!i)&&a.typeArguments?.params?.some(f=>!u&&f.type===ee.TSAnyKeyword||i&&f.type===ee.TSTypeReference&&f.typeName.type===ee.Identifier&&i.includes(f.typeName.name))&&e.report({node:a,messageId:"anyUsedInGenerics",data:{functionName:c.name}})}}}}),me={name:We,rule:At};import{ESLintUtils as Dt,TSESTree as Ue}from"@typescript-eslint/utils";var Ot=Dt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ze="no-commented-out-code",Ft=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Mt=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Pt=Ot({name:ze,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create:function(e){function t(n){if(n.startsWith("/"))return!1;let a=n.trimStart();if(n.startsWith("*")||a.startsWith("INFO:")||a.startsWith("TODO:")||a.startsWith("DOCS:")||a.startsWith("FIX:")||a.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let c of Ft)if(a.startsWith(c))return{wrongPattern:c};for(let c of Mt)if(typeof c=="string"){if(n.includes(c))return{wrongPattern:c}}else if(c.test(n))return{wrongPattern:`regex(${c.toString()})`};return!1}return{Program(){let a=e.sourceCode.getAllComments();for(let c of a)if(c.type===Ue.AST_TOKEN_TYPES.Line||c.type===Ue.AST_TOKEN_TYPES.Block){let x=t(c.value);x&&e.report({node:c,messageId:"commentedOutCode",data:{wrongPattern:x.wrongPattern}})}}}}}),de={name:ze,rule:Pt};import{ESLintUtils as _t}from"@typescript-eslint/utils";var jt=_t.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ve="no-default-export",Lt=jt({name:Ve,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),ye={name:Ve,rule:Lt};import{AST_NODE_TYPES as G,ESLintUtils as Ht}from"@typescript-eslint/utils";var Nt=Ht.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qe="no-non-camel-case-functions",Wt=/^[a-z][a-zA-Z0-9]*$/;function Be(e){return e.typeName.type===G.TSQualifiedName&&e.typeName.left.type===G.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===G.Identifier&&e.typeName.right.name==="Element"}var Ut=Nt({name:qe,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!Wt.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===G.TSTypeReference?Be(n):n.type===G.TSUnionType&&n.types.some(c=>c.type===G.TSTypeReference&&Be(c))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),ge={name:qe,rule:Ut};import{AST_NODE_TYPES as M,ESLintUtils as zt}from"@typescript-eslint/utils";var Vt=zt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Xe(e){let t=[];for(let n of e.members)n.type===M.TSPropertySignature&&n.key.type===M.Identifier&&t.push([n.key.name,n]);return t}function Ge(e,...t){for(let n of t)e.set(...n);return e}var Bt=W({forceCheckOnFCPropTypesWithName:z(q(_()))}),Ke="no-unused-type-props-in-args",he=null,qt=Vt({name:Ke,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Bt],fixable:"code"},defaultOptions:[{}],create:function(e){let{forceCheckOnFCPropTypesWithName:t}=e.options[0]||{};t&&!he&&(he=t.map(p=>new RegExp(p)));function n(p,u,i,s,f=!0){let I=i.name,k=e.sourceCode.getScope(u).references.find(S=>S.identifier.name===I)?.resolved,F=p&&he?.some(S=>S.test(I));if(!k||!F&&k.references.filter(S=>S.isTypeReference).length>1)return;let v=k?.defs[0]?.node;if(!(f&&v?.parent?.type===M.ExportNamedDeclaration)){if(v?.type===M.TSTypeAliasDeclaration){a(p,u,s,v.typeAnnotation,!0);return}if(v?.type===M.TSInterfaceDeclaration){a(p,u,s,v.body,!0);return}}}function a(p,u,i,s,f){if(s.type===M.TSInterfaceBody){for(let I of s.body)I.type===M.TSPropertySignature&&I.key.type===M.Identifier&&i.set(I.key.name,I);return}if(s.type===M.TSTypeLiteral){Ge(i,...Xe(s));return}if(s.type===M.TSIntersectionType){for(let I of s.types)a(p,u,i,I,!0);return}f||s.type===M.TSTypeReference&&s.typeName.type===M.Identifier&&n(p,u,s.typeName,i)}function c(p,u,i){for(let s of i)if(s.type==="ObjectPattern"&&s.typeAnnotation){let f=new Map;if(a(p,u,f,s.typeAnnotation.typeAnnotation,!1),f.size===0)continue;x(s,f)}else s.type===M.AssignmentPattern&&s.left.type===M.ObjectPattern&&c(p,u,[s.left])}function x(p,u){let i=[];if(p.properties.at(-1)?.type===M.RestElement)return;for(let k of p.properties)k.type===M.Property&&k.key.type===M.Identifier&&i.push(k.key.name);let f=[],I=[];for(let[k,F]of u)i.includes(k)||(I.push(k),f.push({node:F,messageId:"unusedObjectTypeProperty",data:{propertyName:k}}));for(let[k,F]of f.entries())e.report({...F,fix:k===f.length-1?v=>{let S=p.properties.at(-1),$=I.join(", ");return S?S?.type===M.RestElement?null:v.insertTextAfter(S,`, ${$}`):v.insertTextBeforeRange([p.range[0]+1,p.range[1]],`${$}`)}:void 0})}return{VariableDeclaration:function(p){let u=p.declarations[0];if(!u)return;let i=new Map,s=u.id.type===M.Identifier&&u.id.typeAnnotation?.typeAnnotation.type===M.TSTypeReference&&u.id.typeAnnotation.typeAnnotation.typeName.type===M.Identifier&&u.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&u.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===M.TSTypeReference&&s.typeName.type===M.Identifier)n(!0,p,s.typeName,i,!1);else if(s.type===M.TSTypeLiteral)Ge(i,...Xe(s));else if(s.type===M.TSIntersectionType)for(let f of s.types)f.type===M.TSTypeReference&&f.typeName.type===M.Identifier?n(!0,p,f.typeName,i,!1):a(!0,p,i,f,!0);if(i.size!==0&&u.init?.type===M.ArrowFunctionExpression){let f=u.init.params[0];if(!f){e.report({node:u.init,messageId:"missingComponentParam"});return}f.type===M.ObjectPattern&&x(f,i)}}},FunctionDeclaration:function(p){c(!1,p,p.params)},ArrowFunctionExpression:function(p){c(!1,p,p.params)}}}}),be={name:Ke,rule:qt};import{ESLintUtils as Xt}from"@typescript-eslint/utils";var Gt=Xt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ye="prefer-named-functions",Je=new Map,Kt=Gt({name:Ye,meta:{type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e){let t=e.options[0]||{},n=null;if(t.ignoreRegex){let a=Je.get(t.ignoreRegex);a?n=a:(n=new RegExp(t.ignoreRegex),Je.set(t.ignoreRegex,n))}return{VariableDeclarator(a){if(a.init&&a.init.type==="ArrowFunctionExpression"&&a.id.type==="Identifier"){let c=a.id.name;if(a.id.typeAnnotation||n&&n.test(c)||!t.disallowArrowFnWithImplicitReturns&&a.init.body.type!=="BlockStatement")return;e.report({node:a.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:c,ignoreRegex:t.ignoreRegex}})}}}}}),Se={name:Ye,rule:Kt};import{ESLintUtils as Jt}from"@typescript-eslint/utils";var Yt=Jt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ze="require-description",Zt=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Qt=/^eslint-disable-(next-)?line$/u,en=Yt({name:Ze,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e){let t=e.sourceCode,n=new Set(e.options[0]&&e.options[0].ignore||[]);return{Program(){for(let a of t.getAllComments()){let c=tn(a);c!=null&&(n.has(c.kind)||c.description||e.report({loc:rn(a.loc),messageId:"missingDescription"}))}}}}}),Qe={name:Ze,rule:en};function tn(e){let{text:t,description:n}=nn(e.value);if(!t)return null;let a=Zt.exec(t);if(!a)return null;let c=a[1];if(!c)return null;let x=Qt.test(c);if(e.type==="Line"&&!x||x&&e.loc.start.line!==e.loc.end.line)return null;let p=t.slice(a.index+c.length);return{kind:c,value:p.trim(),description:n}}function nn(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function rn(e){return{start:{line:e.start.line,column:-1},end:e.end}}function nt(e){return/^use[A-Z0-9]/.test(e)}function te(e){return e.type==="Identifier"?nt(e.name):e.type==="MemberExpression"&&!e.computed&&te(e.property)?e.object.type==="Identifier":!1}function rt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function st(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function it(e){return!!(e.parent&&e.parent.callee&&st(e.parent.callee,"forwardRef"))}function ot(e){return!!(e.parent&&e.parent.callee&&st(e.parent.callee,"memo"))}function Ee(e){for(;e;){let t=ct(e);if(t&&(rt(t)||te(t))||it(e)||ot(e))return!0;e=e.parent}return!1}function et(e){return!1}function xe(e){return!1}var sn=/eslint +react-compiler\/react-compiler: +\["error/,at={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let i of e.sourceCode.getAllComments())if(sn.test(i.value))return{CallExpression(s){let f=null;s.callee.name==="useMemo"?f="useMemo":s.callee.name==="useCallback"&&(f="useCallback"),f&&e.report({node:s,message:`"${f}" is not necessary when using React Compiler.`})},VariableDeclaration(s){s.kind==="using"&&e.report({node:s,message:'"using" syntax is not yet supported by React Compiler.'})}}}let t=typeof e.getSource=="function"?i=>t(i):i=>e.sourceCode.getText(i),n=typeof e.getScope=="function"?()=>n():i=>e.sourceCode.getScope(i),a=null,c=[],x=[],p=new WeakSet;function u(i){for(let s of i.references){let f=s.identifier.parent;if(f.type==="VariableDeclarator"&&f.init&&f.init.type==="CallExpression"&&f.init.callee&&et(f.init.callee))for(let I of s.resolved.references)I!==s&&p.add(I.identifier)}}return{onCodePathSegmentStart:i=>x.push(i),onCodePathSegmentEnd:()=>x.pop(),onCodePathStart:()=>c.push(new Map),onCodePathEnd(i,s){let f=c.pop();if(f.size===0)return;let I=new Set;function k(l,b){let{cache:E}=k,A=E.get(l.id),O=new Set(b);if(O.has(l.id)){let w=[...O],P=w.slice(w.indexOf(l.id)+1);for(let N of P)I.add(N);return BigInt("0")}if(O.add(l.id),A!==void 0)return A;if(i.thrownSegments.includes(l))A=BigInt("0");else if(l.prevSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let w of l.prevSegments)A+=k(w,O)}return l.reachable&&A===BigInt("0")?E.delete(l.id):E.set(l.id,A),A}function F(l,b){let{cache:E}=F,A=E.get(l.id),O=new Set(b);if(O.has(l.id)){let w=Array.from(O),P=w.slice(w.indexOf(l.id)+1);for(let N of P)I.add(N);return BigInt("0")}if(O.add(l.id),A!==void 0)return A;if(i.thrownSegments.includes(l))A=BigInt("0");else if(l.nextSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let w of l.nextSegments)A+=F(w,O)}return E.set(l.id,A),A}function v(l){let{cache:b}=v,E=b.get(l.id);if(E===null)return 1/0;if(E!==void 0)return E;if(b.set(l.id,null),l.prevSegments.length===0)E=1;else{E=1/0;for(let A of l.prevSegments){let O=v(A);O<E&&(E=O)}E+=1}return b.set(l.id,E),E}k.cache=new Map,F.cache=new Map,v.cache=new Map;let S=F(i.initialSegment),$=ct(s),h=Ee(s),D=$?rt($)||te($):it(s)||ot(s),T=1/0;for(let l of i.finalSegments){if(!l.reachable)continue;let b=v(l);b<T&&(T=b)}for(let[l,b]of f){if(!l.reachable)continue;let E=l.nextSegments.length===0?T<=v(l):T<v(l),A=k(l)*F(l),O=I.has(l.id);for(let w of b)if(O&&!xe(w)&&e.report({node:w,message:`React Hook "${t(w)}" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.`}),D){if(s.async&&e.report({node:w,message:`React Hook "${t(w)}" cannot be called in an async function.`}),!O&&A!==S&&!xe(w)){let N=`React Hook "${t(w)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(E?" Did you accidentally call a React Hook after an early return?":"");e.report({node:w,message:N})}}else if(s.parent&&(s.parent.type==="MethodDefinition"||s.parent.type==="ClassProperty")&&s.parent.value===s){let P=`React Hook "${t(w)}" 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:w,message:P})}else if($){let P=`React Hook "${t(w)}" is called in function "${t($)}" 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:w,message:P})}else if(s.type==="Program"){let P=`React Hook "${t(w)}" 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:w,message:P})}else if(h&&!xe(w)){if(s.parent.type==="CallExpression"&&s.parent.callee.type==="Identifier"&&s.parent.callee.name==="useCallback"){let N=s.parent;if(N.parent.type==="VariableDeclarator"&&nt(N.parent.id.name))return}let P=`React Hook "${t(w)}" 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:w,message:P})}}},CallExpression(i){if(te(i.callee)){let s=tt(c),f=tt(x),I=s.get(f);I||(I=[],s.set(f,I)),I.push(i.callee)}i.callee.type==="Identifier"&&(i.callee.name==="useEffect"||et(i.callee))&&i.arguments.length>0&&(a=i)},Identifier(i){a==null&&p.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===a&&(a=null)},FunctionDeclaration(i){Ee(i)&&u(n(i))},ArrowFunctionExpression(i){Ee(i)&&u(n(i))}}}};function ct(e){return e.type==="FunctionDeclaration"||e.type==="FunctionExpression"&&e.id?e.id:e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"?e.parent.type==="VariableDeclarator"&&e.parent.init===e?e.parent.id:e.parent.type==="AssignmentExpression"&&e.parent.right===e&&e.parent.operator==="="?e.parent.left:e.parent.type==="Property"&&e.parent.value===e&&!e.parent.computed?e.parent.key:e.parent.type==="AssignmentPattern"&&e.parent.right===e&&!e.parent.computed?e.parent.left:void 0:void 0}function tt(e){return e[e.length-1]}var lt={[be.name]:be.rule,[de.name]:de.rule,[me.name]:me.rule,"rules-of-hooks":at,"exhaustive-deps":je,"require-description":Qe.rule,[ye.name]:ye.rule,[ge.name]:ge.rule,[Se.name]:Se.rule,[le.name]:le.rule};var Un={rules:lt};export{Un as extendedLintPlugin};
|
|
12
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let E=i.acquire(h),A=new Set,O=null;{let r=E.upper;for(;r&&(A.add(r),r.type!=="function");)r=r.upper;if(!r)return;O=r}let w=Array.isArray;function P(r){if(!w(r.defs))return!1;let o=r.defs[0];if(o==null||o.node.type!=="VariableDeclarator")return!1;let m=o.node.init;if(m==null)return!1;for(;m.type==="TSAsExpression";)m=m.expression;let d=o.node.parent;if(d==null&&(pe(O.block,o.node.id),d=o.node.parent,d==null))return!1;if(d.kind==="const"&&m.type==="Literal"&&(typeof m.value=="string"||typeof m.value=="number"||m.value===null))return!0;if(m.type!=="CallExpression")return!1;let g=m.callee;if(g.type==="MemberExpression"&&g.object.name==="React"&&g.property!=null&&!g.computed&&(g=g.property),g.type!=="Identifier")return!1;let y=o.node.id,{name:R}=g;if(R==="useRef"&&y.type==="Identifier")return!0;if(kt(g)&&y.type==="Identifier"){for(let C of r.references)C!==y&&F.add(C.identifier);return!0}else if(R==="useState"||R==="useReducer"){if(y.type==="ArrayPattern"&&y.elements.length===2&&w(r.identifiers)){if(y.elements[1]===r.identifiers[0]){if(R==="useState"){let C=r.references,L=0;for(let U=0;U<C.length;U++){if(C[U].isWrite()&&L++,L>1)return!1;s.set(C[U].identifier,y.elements[0])}}return!0}else if(y.elements[0]===r.identifiers[0]){if(R==="useState"){let C=r.references;for(let L=0;L<C.length;L++)f.add(C[L].identifier)}return!1}}}else if(R==="useTransition"&&y.type==="ArrayPattern"&&y.elements.length===2&&Array.isArray(r.identifiers)&&y.elements[1]===r.identifiers[0])return!0;return!1}function N(r){if(!w(r.defs))return!1;let o=r.defs[0];if(o==null||o.node==null||o.node.id==null)return!1;let m=o.node,d=O.childScopes,g=null,y;for(y=0;y<d.length;y++){let R=d[y],C=R.block;if(m.type==="FunctionDeclaration"&&C===m||m.type==="VariableDeclarator"&&C.parent===m){g=R;break}}if(g==null)return!1;for(y=0;y<g.through.length;y++){let R=g.through[y];if(R.resolved!=null&&A.has(R.resolved.scope)&&!Te(R.resolved))return!1}return!0}let Te=v(P,I),ut=v(N,k),we=new Map;function ft(r){let o=r.from,m=!1;for(;o.block!==h;)o.type==="function"&&(m=o.block.parent!=null&&o.block.parent.type==="ReturnStatement"),o=o.upper;return m}let j=new Map,ne=new Map;Re(E);function Re(r){for(let o of r.references){if(!o.resolved||!A.has(o.resolved.scope))continue;let m=pe(h,o.identifier),d=Le(m),g=V(d,ne);if(b&&d.type==="Identifier"&&(d.parent.type==="MemberExpression"||d.parent.type==="OptionalMemberExpression")&&!d.parent.computed&&d.parent.property.type==="Identifier"&&d.parent.property.name==="current"&&ft(o)&&we.set(g,{reference:o,dependencyNode:d}),d.parent.type==="TSTypeQuery"||d.parent.type==="TSTypeReference")continue;let y=o.resolved.defs[0];if(y!=null&&!(y.node!=null&&y.node.init===h.parent)&&y.type!=="TypeParameter")if(j.has(g))j.get(g).references.push(o);else{let R=o.resolved,C=Te(R)||ut(R);j.set(g,{isStable:C,references:[o]})}}for(let o of r.childScopes)Re(o)}we.forEach(({reference:r,dependencyNode:o},m)=>{let d=r.resolved.references,g=!1;for(let y=0;y<d.length;y++){let{identifier:R}=d[y],{parent:C}=R;if(C!=null&&C.type==="MemberExpression"&&!C.computed&&C.property.type==="Identifier"&&C.property.name==="current"&&C.parent.type==="AssignmentExpression"&&C.parent.left===C){g=!0;break}}g||u({node:o.parent.property,message:`The ref value '${m}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${m}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let re=new Set;function pt(r,o){re.has(o)||(re.add(o),u({node:r,message:`Assignments to the '${o}' variable from inside React Hook ${n(T)} 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(T)}.`}))}let Y=new Set;if(j.forEach(({isStable:r,references:o},m)=>{r&&Y.add(m),o.forEach(d=>{d.writeExpr&&pt(d.writeExpr,m)})}),re.size>0)return;if(!D){let r=null;if(j.forEach(({isStable:o,references:m},d)=>{r||m.forEach(g=>{if(r)return;let y=g.identifier;if(!s.has(y))return;let C=g.from;for(;C.type!=="function";)C=C.upper;C.block===h&&(r=d)})}),r){let{suggestedDependencies:o}=ue({dependencies:j,declaredDependencies:[],stableDependencies:Y,externalDependencies:new Set,isEffect:!0});u({node:T,message:`React Hook ${l} contains a call to '${r}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+o.join(", ")+`] as a second argument to the ${l} Hook.`,suggest:[{desc:`Add dependencies array: [${o.join(", ")}]`,fix(m){return m.insertTextAfter(h,`, [${o.join(", ")}]`)}}]})}return}let K=[],J=new Set;D.type!=="ArrayExpression"?u({node:D,message:`React Hook ${n(T)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(r=>{if(r===null)return;if(r.type==="SpreadElement"){u({node:r,message:`React Hook ${n(T)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}F.has(r)&&u({node:r,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(r)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(r)}\``,fix(g){return g.removeRange(r.range)}}]});let o;try{o=V(r,ne)}catch(g){if(/Unsupported node type/.test(g.message)){r.type==="Literal"?j.has(r.value)?u({node:r,message:`The ${r.raw} literal is not a valid dependency because it never changes. Did you mean to include ${r.value} in the array instead?`}):u({node:r,message:`The ${r.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):u({node:r,message:`React Hook ${n(T)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw g}let m=r;for(;m.type==="MemberExpression"||m.type==="OptionalMemberExpression"||m.type==="ChainExpression";)m=m.object||m.expression.object;let d=!O.through.some(g=>g.identifier===m);K.push({key:o,node:r}),d||J.add(o)});let{suggestedDependencies:mt,unnecessaryDependencies:Z,missingDependencies:B,duplicateDependencies:Ie}=ue({dependencies:j,declaredDependencies:K,stableDependencies:Y,externalDependencies:J,isEffect:b}),Q=mt;if(Ie.size+B.size+Z.size===0){if(t)return;wt({declaredDependencies:K,declaredDependenciesNode:D,componentScope:O,scope:E}).forEach(({construction:o,isUsedOutsideOfHook:m,depType:d})=>{let g=d==="function"?"useCallback":"useMemo",y=d==="function"?"definition":"initialization",R=`wrap the ${y} of '${o.name.name}' in its own ${g}() Hook.`,C=m?`To fix this, ${R}`:`Move it inside the ${l} callback. Alternatively, ${R}`,L=d==="conditional"||d==="logical expression"?"could make":"makes",U=`The '${o.name.name}' ${d} ${L} the dependencies of ${l} Hook (at line ${D.loc.start.line}) change on every render. ${C}`,Ce;m&&o.type==="Variable"&&d==="function"&&(Ce=[{desc:`Wrap the ${y} of '${o.name.name}' in its own ${g}() Hook.`,fix(ke){let[yt,gt]=g==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[ke.insertTextBefore(o.node.init,yt),ke.insertTextAfter(o.node.init,gt)]}}]),u({node:o.node,message:U,suggest:Ce})});return}!b&&B.size>0&&(Q=ue({dependencies:j,declaredDependencies:[],stableDependencies:Y,externalDependencies:J,isEffect:b}).suggestedDependencies);function dt(){if(K.length===0)return!0;let r=K.map(m=>m.key),o=r.slice().sort();return r.join(",")===o.join(",")}dt()&&Q.sort();function se(r){let o=r.split("."),m="";for(let d=0;d<o.length;d++){if(d!==0){let g=o.slice(0,d+1).join("."),y=ne.get(g)===!0;m+=y?"?.":"."}m+=o[d]}return m}function ie(r,o,m,d){return r.size===0?null:(r.size>1?"":o+" ")+m+" "+(r.size>1?"dependencies":"dependency")+": "+It(Array.from(r).sort().map(g=>"'"+se(g)+"'"))+`. Either ${d} ${r.size>1?"them":"it"} or remove the dependency array.`}let H="";if(Z.size>0){let r=null;if(Array.from(Z.keys()).forEach(o=>{r===null&&o.endsWith(".current")&&(r=o)}),r!==null)H=` Mutable values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(J.size>0){let o=Array.from(J)[0];E.set.has(o)||(H=` Outer scope values like '${o}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!H&&B.has("props")){let r=j.get("props");if(r==null)return;let o=r.references;if(!Array.isArray(o))return;let m=!0;for(let d=0;d<o.length;d++){let g=o[d],y=pe(O.block,g.identifier);if(!y){m=!1;break}let R=y.parent;if(R==null){m=!1;break}if(R.type!=="MemberExpression"&&R.type!=="OptionalMemberExpression"){m=!1;break}}m&&(H=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${l} call and refer to those specific props inside ${n(T)}.`)}if(!H&&B.size>0){let r=null;B.forEach(o=>{if(r)return;let m=O.set.get(o),d=j.get(o);if(d.references[0].resolved!==m)return;let g=m.defs[0];if(g==null||g.name==null||g.type!=="Parameter")return;let y=!1,R;for(let C=0;C<d.references.length;C++)if(R=d.references[C].identifier,R!=null&&R.parent!=null&&(R.parent.type==="CallExpression"||R.parent.type==="OptionalCallExpression")&&R.parent.callee===R){y=!0;break}y&&(r=o)}),r!==null&&(H=` If '${r}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!H&&B.size>0){let r=null;if(B.forEach(o=>{if(r!==null)return;let d=j.get(o).references,g,y;for(let R=0;R<d.length;R++){for(g=d[R].identifier,y=g.parent;y!=null&&y!==O.block;){if(y.type==="CallExpression"){let C=s.get(y.callee);if(C!=null){if(C.name===o)r={missingDep:o,setter:y.callee.name,form:"updater"};else if(f.has(g))r={missingDep:o,setter:y.callee.name,form:"reducer"};else{let L=d[R].resolved;if(L!=null){let U=L.defs[0];U!=null&&U.type==="Parameter"&&(r={missingDep:o,setter:y.callee.name,form:"inlineReducer"})}}break}}y=y.parent}if(r!==null)break}}),r!==null)switch(r.form){case"reducer":H=` You can also replace multiple useState variables with useReducer if '${r.setter}' needs the current value of '${r.missingDep}'.`;break;case"inlineReducer":H=` If '${r.setter}' needs the current value of '${r.missingDep}', you can also switch to useReducer instead of useState and read '${r.missingDep}' in the reducer.`;break;case"updater":H=` You can also do a functional update '${r.setter}(${r.missingDep.slice(0,1)} => ...)' if you only need '${r.missingDep}' in the '${r.setter}' call.`;break;default:throw new Error("Unknown case.")}}u({node:D,message:`React Hook ${n(T)} has `+(ie(B,"a","missing","include")||ie(Z,"an","unnecessary","exclude")||ie(Ie,"a","duplicate","omit"))+H,suggest:[{desc:`Update the dependencies array to be: [${Q.map(se).join(", ")}]`,fix(r){return r.replaceText(D,`[${Q.map(se).join(", ")}]`)}}]})}function $(h){let D=Rt(h.callee,p);if(D===-1)return;let T=h.arguments[D],l=h.callee,b=He(l).name,E=h.arguments[D+1],A=/Effect($|[^a-z])/g.test(b);if(!T){u({node:l,message:`React Hook ${b} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!A)){if(!E&&!A){(b==="useMemo"||b==="useCallback")&&u({node:l,message:`React Hook ${b} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(T.type){case"FunctionExpression":case"ArrowFunctionExpression":S(T,E,l,b,A);return;case"Identifier":if(!E||E.elements&&E.elements.some(P=>P&&P.type==="Identifier"&&P.name===T.name))return;let O=a(h).set.get(T.name);if(O==null||O.defs==null)return;let w=O.defs[0];if(!w||!w.node||w.type!=="Variable"&&w.type!=="FunctionName")break;switch(w.node.type){case"FunctionDeclaration":S(w.node,E,l,b,A);return;case"VariableDeclarator":let P=w.node.init;if(!P)break;switch(P.type){case"ArrowFunctionExpression":case"FunctionExpression":S(P,E,l,b,A);return}break}break;default:u({node:l,message:`React Hook ${b} received a function whose dependencies are unknown. Pass an inline function instead.`});return}u({node:l,message:`React Hook ${b} has a missing dependency: '${T.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${T.name}]`,fix(O){return O.replaceText(E,`[${T.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let h of e.sourceCode.getAllComments())if(Tt.test(h.value))return t=!0,{CallExpression:D=>$(D,!0)}}return{CallExpression:h=>$(h)}}};function ue({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:a,isEffect:c}){let x=p();function p(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((S,$)=>{let h=u(x,$);h.isUsed=!0,i(x,$,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:S})=>{let $=u(x,S);$.isSatisfiedRecursively=!0}),n.forEach(S=>{let $=u(x,S);$.isSatisfiedRecursively=!0});function u(S,$){let h=$.split("."),D=S;for(let T of h){let l=D.children.get(T);l||(l=p(),D.children.set(T,l)),D=l}return D}function i(S,$,h){let D=$.split("."),T=S;for(let l of D){let b=T.children.get(l);if(!b)return;h(b),T=b}}let s=new Set,f=new Set;I(x,s,f,S=>S);function I(S,$,h,D){S.children.forEach((T,l)=>{let b=D(l);if(T.isSatisfiedRecursively){T.isSubtreeUsed&&h.add(b);return}if(T.isUsed){$.add(b);return}I(T,$,h,E=>b+"."+E)})}let k=[],F=new Set,v=new Set;return t.forEach(({key:S})=>{f.has(S)?k.indexOf(S)===-1?k.push(S):v.add(S):F.add(S)}),s.forEach(S=>{k.push(S)}),{suggestedDependencies:k,unnecessaryDependencies:F,duplicateDependencies:v,missingDependencies:s}}function X(e){switch(e.type){case"ObjectExpression":return"object";case"ArrayExpression":return"array";case"ArrowFunctionExpression":case"FunctionExpression":return"function";case"ClassExpression":return"class";case"ConditionalExpression":return X(e.consequent)!=null||X(e.alternate)!=null?"conditional":null;case"LogicalExpression":return X(e.left)!=null||X(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return X(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return X(e.expression);case"TSAsExpression":return X(e.expression)}return null}function wt({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:a}){let c=e.map(({key:p})=>{let u=n.variables.find(s=>s.name===p);if(u==null)return null;let i=u.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 s=X(i.node.init);if(s!=null)return[u,s]}return i.type==="FunctionName"&&i.node.type==="FunctionDeclaration"?[u,"function"]:i.type==="ClassName"&&i.node.type==="ClassDeclaration"?[u,"class"]:null}).filter(Boolean);function x(p){let u=!1;for(let i=0;i<p.references.length;i++){let s=p.references[i];if(s.writeExpr){if(u)return!0;u=!0;continue}let f=s.from;for(;f!==a&&f!=null;)f=f.upper;if(f!==a&&!Ne(t,s.identifier))return!0}return!1}return c.map(([p,u])=>({construction:p.defs[0],depType:u,isUsedOutsideOfHook:x(p)}))}function Le(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)?Le(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function fe(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function V(e,t){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let n=e.name;return t&&t.set(n,!1),n}else if(e.type==="MemberExpression"&&!e.computed){let n=V(e.object,t),a=V(e.property,null),c=`${n}.${a}`;return fe(e,t,c),c}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=V(e.object,t),a=V(e.property,null),c=`${n}.${a}`;return fe(e,t,c),c}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let a=V(n.object,t),c=V(n.property,null),x=`${a}.${c}`;return fe(n,t,x),x}else throw new Error(`Unsupported node type: ${e.type}`)}function He(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Rt(e,t){let n=He(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let a;try{a=V(n,null)}catch(c){if(/Unsupported node type/.test(c.message))return 0;throw c}return t.additionalHooks.test(a)?0:-1}else return-1}}function pe(e,t){let n=[e],a=null;for(;n.length;){if(a=n.shift(),Ct(a,t))return a;if(Ne(a,t))for(let[c,x]of Object.entries(a))c!=="parent"&&(_e(x)?(x.parent=a,n.push(x)):Array.isArray(x)&&x.forEach(p=>{_e(p)&&(p.parent=a,n.push(p))}))}return null}function It(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function _e(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ct(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 Ne(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function kt(e){return!1}import{AST_NODE_TYPES as ee,ESLintUtils as vt}from"@typescript-eslint/utils";var $t=vt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),We="no-call-with-inferred-generics",At=$t({name:We,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e){let t=e.options[0],n=new Map(t.functions.map(a=>[a.name,a]));return{CallExpression(a){let{callee:c}=a;if(c.type!==ee.Identifier)return;let x=n.get(c.name);if(!x)return;let{minGenerics:p=1,allowAny:u,disallowTypes:i=t.disallowTypes}=x;(a.typeArguments?.params.length||0)<(p||0)&&e.report({node:a,messageId:"missingGenericDeclaration",data:{functionName:c.name,minGenerics:p||0}}),!(u&&!i)&&a.typeArguments?.params?.some(f=>!u&&f.type===ee.TSAnyKeyword||i&&f.type===ee.TSTypeReference&&f.typeName.type===ee.Identifier&&i.includes(f.typeName.name))&&e.report({node:a,messageId:"anyUsedInGenerics",data:{functionName:c.name}})}}}}),me={name:We,rule:At};import{ESLintUtils as Dt,TSESTree as Ue}from"@typescript-eslint/utils";var Ot=Dt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ze="no-commented-out-code",Ft=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Mt=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Pt=Ot({name:ze,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create:function(e){function t(n){if(n.startsWith("/"))return!1;let a=n.trimStart();if(n.startsWith("*")||a.startsWith("INFO:")||a.startsWith("TODO:")||a.startsWith("DOCS:")||a.startsWith("FIX:")||a.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let c of Ft)if(a.startsWith(c))return{wrongPattern:c};for(let c of Mt)if(typeof c=="string"){if(n.includes(c))return{wrongPattern:c}}else if(c.test(n))return{wrongPattern:`regex(${c.toString()})`};return!1}return{Program(){let a=e.sourceCode.getAllComments();for(let c of a)if(c.type===Ue.AST_TOKEN_TYPES.Line||c.type===Ue.AST_TOKEN_TYPES.Block){let x=t(c.value);x&&e.report({node:c,messageId:"commentedOutCode",data:{wrongPattern:x.wrongPattern}})}}}}}),de={name:ze,rule:Pt};import{ESLintUtils as _t}from"@typescript-eslint/utils";var jt=_t.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ve="no-default-export",Lt=jt({name:Ve,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),ye={name:Ve,rule:Lt};import{AST_NODE_TYPES as G,ESLintUtils as Ht}from"@typescript-eslint/utils";var Nt=Ht.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qe="no-non-camel-case-functions",Wt=/^[a-z][a-zA-Z0-9]*$/;function Be(e){return e.typeName.type===G.TSQualifiedName&&e.typeName.left.type===G.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===G.Identifier&&e.typeName.right.name==="Element"}var Ut=Nt({name:qe,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!Wt.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===G.TSTypeReference?Be(n):n.type===G.TSUnionType&&n.types.some(c=>c.type===G.TSTypeReference&&Be(c))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),ge={name:qe,rule:Ut};import{AST_NODE_TYPES as M,ESLintUtils as zt}from"@typescript-eslint/utils";var Vt=zt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Xe(e){let t=[];for(let n of e.members)n.type===M.TSPropertySignature&&n.key.type===M.Identifier&&t.push([n.key.name,n]);return t}function Ge(e,...t){for(let n of t)e.set(...n);return e}var Bt=W({forceCheckOnFCPropTypesWithName:z(q(_()))}),Ke="no-unused-type-props-in-args",he=null,qt=Vt({name:Ke,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Bt],fixable:"code"},defaultOptions:[{}],create:function(e){let{forceCheckOnFCPropTypesWithName:t}=e.options[0]||{};t&&!he&&(he=t.map(p=>new RegExp(p)));function n(p,u,i,s,f=!0){let I=i.name,k=e.sourceCode.getScope(u).references.find(S=>S.identifier.name===I)?.resolved,F=p&&he?.some(S=>S.test(I));if(!k||!F&&k.references.filter(S=>S.isTypeReference).length>1)return;let v=k?.defs[0]?.node;if(!(f&&v?.parent?.type===M.ExportNamedDeclaration)){if(v?.type===M.TSTypeAliasDeclaration){a(p,u,s,v.typeAnnotation,!0);return}if(v?.type===M.TSInterfaceDeclaration){a(p,u,s,v.body,!0);return}}}function a(p,u,i,s,f){if(s.type===M.TSInterfaceBody){for(let I of s.body)I.type===M.TSPropertySignature&&I.key.type===M.Identifier&&i.set(I.key.name,I);return}if(s.type===M.TSTypeLiteral){Ge(i,...Xe(s));return}if(s.type===M.TSIntersectionType){for(let I of s.types)a(p,u,i,I,!0);return}f||s.type===M.TSTypeReference&&s.typeName.type===M.Identifier&&n(p,u,s.typeName,i)}function c(p,u,i){for(let s of i)if(s.type==="ObjectPattern"&&s.typeAnnotation){let f=new Map;if(a(p,u,f,s.typeAnnotation.typeAnnotation,!1),f.size===0)continue;x(s,f)}else s.type===M.AssignmentPattern&&s.left.type===M.ObjectPattern&&c(p,u,[s.left])}function x(p,u){let i=[];if(p.properties.at(-1)?.type===M.RestElement)return;for(let k of p.properties)k.type===M.Property&&k.key.type===M.Identifier&&i.push(k.key.name);let f=[],I=[];for(let[k,F]of u)i.includes(k)||(I.push(k),f.push({node:F,messageId:"unusedObjectTypeProperty",data:{propertyName:k}}));for(let[k,F]of f.entries())e.report({...F,fix:k===f.length-1?v=>{let S=p.properties.at(-1),$=I.join(", ");return S?S?.type===M.RestElement?null:v.insertTextAfter(S,`, ${$}`):v.insertTextBeforeRange([p.range[0]+1,p.range[1]],`${$}`)}:void 0})}return{VariableDeclaration:function(p){let u=p.declarations[0];if(!u)return;let i=new Map,s=u.id.type===M.Identifier&&u.id.typeAnnotation?.typeAnnotation.type===M.TSTypeReference&&u.id.typeAnnotation.typeAnnotation.typeName.type===M.Identifier&&u.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&u.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===M.TSTypeReference&&s.typeName.type===M.Identifier)n(!0,p,s.typeName,i,!1);else if(s.type===M.TSTypeLiteral)Ge(i,...Xe(s));else if(s.type===M.TSIntersectionType)for(let f of s.types)f.type===M.TSTypeReference&&f.typeName.type===M.Identifier?n(!0,p,f.typeName,i,!1):a(!0,p,i,f,!0);if(i.size!==0&&u.init?.type===M.ArrowFunctionExpression){let f=u.init.params[0];if(!f){e.report({node:u.init,messageId:"missingComponentParam"});return}f.type===M.ObjectPattern&&x(f,i)}}},FunctionDeclaration:function(p){c(!1,p,p.params)},ArrowFunctionExpression:function(p){c(!1,p,p.params)}}}}),be={name:Ke,rule:qt};import{ESLintUtils as Xt}from"@typescript-eslint/utils";var Gt=Xt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ye="prefer-named-functions",Je=new Map,Kt=Gt({name:Ye,meta:{type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e){let t=e.options[0]||{},n=null;if(t.ignoreRegex){let a=Je.get(t.ignoreRegex);a?n=a:(n=new RegExp(t.ignoreRegex),Je.set(t.ignoreRegex,n))}return{VariableDeclarator(a){if(a.init&&a.init.type==="ArrowFunctionExpression"&&a.id.type==="Identifier"){let c=a.id.name;if(a.id.typeAnnotation||n&&n.test(c)||!t.disallowArrowFnWithImplicitReturns&&a.init.body.type!=="BlockStatement")return;e.report({node:a.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:c,ignoreRegex:t.ignoreRegex}})}}}}}),Se={name:Ye,rule:Kt};import{ESLintUtils as Jt}from"@typescript-eslint/utils";var Yt=Jt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ze="require-description",Zt=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Qt=/^eslint-disable-(next-)?line$/u,en=Yt({name:Ze,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e){let t=e.sourceCode,n=new Set(e.options[0]&&e.options[0].ignore||[]);return{Program(){for(let a of t.getAllComments()){let c=tn(a);c!=null&&(n.has(c.kind)||c.description||e.report({loc:rn(a.loc),messageId:"missingDescription"}))}}}}}),Qe={name:Ze,rule:en};function tn(e){let{text:t,description:n}=nn(e.value);if(!t)return null;let a=Zt.exec(t);if(!a)return null;let c=a[1];if(!c)return null;let x=Qt.test(c);if(e.type==="Line"&&!x||x&&e.loc.start.line!==e.loc.end.line)return null;let p=t.slice(a.index+c.length);return{kind:c,value:p.trim(),description:n}}function nn(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function rn(e){return{start:{line:e.start.line,column:-1},end:e.end}}function nt(e){return/^use[A-Z0-9]/.test(e)}function te(e){return e.type==="Identifier"?nt(e.name):e.type==="MemberExpression"&&!e.computed&&te(e.property)?e.object.type==="Identifier":!1}function rt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function st(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function it(e){return!!(e.parent&&e.parent.callee&&st(e.parent.callee,"forwardRef"))}function ot(e){return!!(e.parent&&e.parent.callee&&st(e.parent.callee,"memo"))}function Ee(e){for(;e;){let t=ct(e);if(t&&(rt(t)||te(t))||it(e)||ot(e))return!0;e=e.parent}return!1}function et(e){return!1}function xe(e){return!1}var sn=/eslint +react-compiler\/react-compiler: +\["error/,at={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let i of e.sourceCode.getAllComments())if(sn.test(i.value))return{CallExpression(s){let f=null;s.callee.name==="useMemo"?f="useMemo":s.callee.name==="useCallback"&&(f="useCallback"),f&&e.report({node:s,message:`"${f}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?i=>t(i):i=>e.sourceCode.getText(i),n=typeof e.getScope=="function"?()=>n():i=>e.sourceCode.getScope(i),a=null,c=[],x=[],p=new WeakSet;function u(i){for(let s of i.references){let f=s.identifier.parent;if(f.type==="VariableDeclarator"&&f.init&&f.init.type==="CallExpression"&&f.init.callee&&et(f.init.callee))for(let I of s.resolved.references)I!==s&&p.add(I.identifier)}}return{onCodePathSegmentStart:i=>x.push(i),onCodePathSegmentEnd:()=>x.pop(),onCodePathStart:()=>c.push(new Map),onCodePathEnd(i,s){let f=c.pop();if(f.size===0)return;let I=new Set;function k(l,b){let{cache:E}=k,A=E.get(l.id),O=new Set(b);if(O.has(l.id)){let w=[...O],P=w.slice(w.indexOf(l.id)+1);for(let N of P)I.add(N);return BigInt("0")}if(O.add(l.id),A!==void 0)return A;if(i.thrownSegments.includes(l))A=BigInt("0");else if(l.prevSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let w of l.prevSegments)A+=k(w,O)}return l.reachable&&A===BigInt("0")?E.delete(l.id):E.set(l.id,A),A}function F(l,b){let{cache:E}=F,A=E.get(l.id),O=new Set(b);if(O.has(l.id)){let w=Array.from(O),P=w.slice(w.indexOf(l.id)+1);for(let N of P)I.add(N);return BigInt("0")}if(O.add(l.id),A!==void 0)return A;if(i.thrownSegments.includes(l))A=BigInt("0");else if(l.nextSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let w of l.nextSegments)A+=F(w,O)}return E.set(l.id,A),A}function v(l){let{cache:b}=v,E=b.get(l.id);if(E===null)return 1/0;if(E!==void 0)return E;if(b.set(l.id,null),l.prevSegments.length===0)E=1;else{E=1/0;for(let A of l.prevSegments){let O=v(A);O<E&&(E=O)}E+=1}return b.set(l.id,E),E}k.cache=new Map,F.cache=new Map,v.cache=new Map;let S=F(i.initialSegment),$=ct(s),h=Ee(s),D=$?rt($)||te($):it(s)||ot(s),T=1/0;for(let l of i.finalSegments){if(!l.reachable)continue;let b=v(l);b<T&&(T=b)}for(let[l,b]of f){if(!l.reachable)continue;let E=l.nextSegments.length===0?T<=v(l):T<v(l),A=k(l)*F(l),O=I.has(l.id);for(let w of b)if(O&&!xe(w)&&e.report({node:w,message:`React Hook "${t(w)}" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.`}),D){if(s.async&&e.report({node:w,message:`React Hook "${t(w)}" cannot be called in an async function.`}),!O&&A!==S&&!xe(w)){let N=`React Hook "${t(w)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(E?" Did you accidentally call a React Hook after an early return?":"");e.report({node:w,message:N})}}else if(s.parent&&(s.parent.type==="MethodDefinition"||s.parent.type==="ClassProperty")&&s.parent.value===s){let P=`React Hook "${t(w)}" 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:w,message:P})}else if($){let P=`React Hook "${t(w)}" is called in function "${t($)}" 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:w,message:P})}else if(s.type==="Program"){let P=`React Hook "${t(w)}" 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:w,message:P})}else if(h&&!xe(w)){if(s.parent.type==="CallExpression"&&s.parent.callee.type==="Identifier"&&s.parent.callee.name==="useCallback"){let N=s.parent;if(N.parent.type==="VariableDeclarator"&&nt(N.parent.id.name))return}let P=`React Hook "${t(w)}" 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:w,message:P})}}},CallExpression(i){if(te(i.callee)){let s=tt(c),f=tt(x),I=s.get(f);I||(I=[],s.set(f,I)),I.push(i.callee)}i.callee.type==="Identifier"&&(i.callee.name==="useEffect"||et(i.callee))&&i.arguments.length>0&&(a=i)},Identifier(i){a==null&&p.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===a&&(a=null)},FunctionDeclaration(i){Ee(i)&&u(n(i))},ArrowFunctionExpression(i){Ee(i)&&u(n(i))}}}};function ct(e){return e.type==="FunctionDeclaration"||e.type==="FunctionExpression"&&e.id?e.id:e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"?e.parent.type==="VariableDeclarator"&&e.parent.init===e?e.parent.id:e.parent.type==="AssignmentExpression"&&e.parent.right===e&&e.parent.operator==="="?e.parent.left:e.parent.type==="Property"&&e.parent.value===e&&!e.parent.computed?e.parent.key:e.parent.type==="AssignmentPattern"&&e.parent.right===e&&!e.parent.computed?e.parent.left:void 0:void 0}function tt(e){return e[e.length-1]}var lt={[be.name]:be.rule,[de.name]:de.rule,[me.name]:me.rule,"rules-of-hooks":at,"exhaustive-deps":je,"require-description":Qe.rule,[ye.name]:ye.rule,[ge.name]:ge.rule,[Se.name]:Se.rule,[le.name]:le.rule};var Un={rules:lt};export{Un as extendedLintPlugin};
|