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