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