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