@ls-stack/extended-lint 0.41.0 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extended-lint.js +5 -5
- package/dist/extended-lint.mjs +5 -5
- package/package.json +1 -1
package/dist/extended-lint.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var wn=Object.create;var he=Object.defineProperty;var Rn=Object.getOwnPropertyDescriptor;var vn=Object.getOwnPropertyNames;var On=Object.getPrototypeOf,kn=Object.prototype.hasOwnProperty;var An=(e,t)=>{for(var n in t)he(e,n,{get:t[n],enumerable:!0})},ht=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of vn(t))!kn.call(e,s)&&s!==n&&he(e,s,{get:()=>t[s],enumerable:!(r=Rn(t,s))||r.enumerable});return e};var _e=(e,t,n)=>(n=e!=null?wn(On(e)):{},ht(t||!e||!e.__esModule?he(n,"default",{value:e,enumerable:!0}):n,e)),Pn=e=>ht(he({},"__esModule",{value:!0}),e);var si={};An(si,{extendedLintPlugin:()=>ii});module.exports=Pn(si);var z=require("@typescript-eslint/utils");var De=Symbol.for("optional");function F(e){return{...e,[De]:!0}}function Ee(e,t){return{enum:e,...t}}function le(e){return{...e,type:"boolean"}}function N(e){return{...e,type:"string"}}function G(e){return{...e,type:"number"}}function Et(e){return{...e,type:"integer"}}function Y(e,t){return{...t,type:"array",items:e}}function _(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,s=[];for(r in e)e[r][De]?e[r][De]=void 0:s.push(r);s.length>0&&(n.required=s)}return n}function je(...e){return{anyOf:e}}var Fn=z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),xt="react-compiler-extra",Nn=_({runOnlyWithEnableCompilerDirective:F(le())}),Ln=/eslint +react-compiler\/react-compiler: +\["error/;function _n(e){return e.type===z.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===z.AST_NODE_TYPES.MemberExpression&&e.property.type===z.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var Dn=/\bthis[.[]/;function bt(e){return Dn.test(e)}var jn=Fn({name:xt,meta:{type:"suggestion",fixable:"code",docs:{description:"Extra rules to enforce best practices when using the React compiler"},messages:{objectMethodIsNotSupported:"Object methods such as `{ method() {} }` have limited support to optimizations in the React compiler, use a function expression `{ method: () => {} }` instead.",replaceWithFunctionExpression:"Replace with function expression",thisKeywordInMethod:"Object method uses `this` keyword which would have different behavior if converted to an arrow function. Fix this manually."},hasSuggestions:!0,schema:[Nn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let a of e.sourceCode.getAllComments())if(Ln.test(a.value)){n=!0;break}if(!n)return{}}function r(a){for(let u of a.properties)if(u.type===z.AST_NODE_TYPES.Property&&u.method&&u.value.type===z.AST_NODE_TYPES.FunctionExpression){let i=e.sourceCode,o=i.getText(u.key),l=u.value,c=i.getText(l.body);if(bt(c))e.report({node:u,messageId:"thisKeywordInMethod"});else{let f=l.params.map(m=>i.getText(m)).join(", "),h="";l.generator?h=`${o}: function* (${f}) ${c}`:h=`${o}: (${f}) => ${c}`,e.report({node:u,messageId:"objectMethodIsNotSupported",fix:m=>m.replaceText(u,h)})}}}function s(a){for(let u of a.properties)if(u.type===z.AST_NODE_TYPES.Property&&u.value.type===z.AST_NODE_TYPES.ObjectExpression){for(let i of u.value.properties)if(i.type===z.AST_NODE_TYPES.Property&&i.method&&i.value.type===z.AST_NODE_TYPES.FunctionExpression){let l=e.sourceCode.getText(i.value.body);bt(l)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(a){if(_n(a.callee))for(let u of a.arguments){if(u.type===z.AST_NODE_TYPES.ObjectExpression&&(r(u),s(u)),u.type===z.AST_NODE_TYPES.ArrowFunctionExpression&&(u.body.type===z.AST_NODE_TYPES.ObjectExpression&&(r(u.body),s(u.body)),u.body.type===z.AST_NODE_TYPES.BlockStatement))for(let i of u.body.body)i.type===z.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===z.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),s(i.argument));if(u.type===z.AST_NODE_TYPES.FunctionExpression)for(let i of u.body.body)i.type===z.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===z.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),s(i.argument))}}}}}),Me={name:xt,rule:jn};var xe=require("@typescript-eslint/utils");var Ct=require("@typescript-eslint/utils");function be(e){let n=Ct.ESLintUtils.RuleCreator(r=>`https://github.com/lucasols/extended-lint#${r}`)(e);return{name:e.name,rule:n}}var Mn=_({disallow:F(Y(_({selector:N(),message:N(),replace:F(je(N(),_({regex:N(),with:N()}))),replaceType:F(Ee(["suggestion","autofix"]))}))),__dev_simulateFileName:F(N()),mustMatchSyntax:F(Y(_({includeRegex:N(),mustCallFn:F(Y(_({anyCall:Y(_({fn:N(),withArgs:Y(_({atIndex:Et(),literal:je(N(),G(),le())}))})),message:F(N())}))),mustMatchSelector:F(Y(_({selector:N(),message:N()})))})))}),$e=be({name:"advanced-no-restricted-syntax",meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Mn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:s,disallow:a}=t,u=s??e.filename,i=[],o=new Map,l=new Set,c=new Map;for(let{includeRegex:m,mustCallFn:y,mustMatchSelector:T}of r??[]){let E=$n(u,new RegExp(m));if(!E)continue;let g=O=>{let C=O;for(let{name:S,value:v}of E)C=C.replaceAll(S,v);return C};for(let{anyCall:O,message:C}of y??[]){let S=`Expected file to call the function: ${O.map(({fn:v})=>v).join(" or ")}`;l.add(S),i.push(v=>{let{callee:A}=v;if(A.type===xe.AST_NODE_TYPES.Identifier){for(let{fn:L,withArgs:j}of O)if(A.name===L){l.delete(S);for(let R of j){let U=v.arguments[R.atIndex],B=typeof R.literal=="string"?g(R.literal):R.literal;if(!U){e.report({node:v,messageId:"default",data:{message:`Missing argument with value "${B}" at index ${R.atIndex}${C?`: ${g(C)}`:""}`}});continue}if(U.type!==xe.AST_NODE_TYPES.Literal){e.report({node:U,messageId:"default",data:{message:`Argument at position ${R.atIndex} should the literal "${B}"${C?`: ${g(C)}`:""}`}});continue}U.value!==B&&e.report({node:U,messageId:"default",data:{message:`Argument should have the value "${B}"${C?`: ${g(C)}`:""}`},fix:ye=>ye.replaceText(U,typeof B=="string"?`'${B}'`:String(B))})}break}}})}for(let{selector:O,message:C}of T??[])c.set(O,g(C)),o.set(g(O),()=>{c.delete(O)})}function f(m,y){let T=n[m];T?n[m]=E=>{T(E),y(E)}:n[m]=y}for(let{selector:m,message:y,replace:T,replaceType:E="suggestion"}of a??[]){if(m==="CallExpression"){i.push(g=>{h(T,g,y,E)});continue}n[m]=g=>{h(T,g,y,E)}}if(o.size>0)for(let[m,y]of o)f(m,y);return i.length>0&&(n.CallExpression=m=>{if(m.type===xe.AST_NODE_TYPES.CallExpression)for(let y of i)y(m)}),n["Program:exit"]=m=>{for(let y of l)e.report({node:m,messageId:"default",data:{message:y}});for(let[,y]of c)e.report({node:m,messageId:"default",data:{message:y}})},n;function h(m,y,T,E){let g=O=>{if(!m)return null;if(typeof m=="string")return O.replaceText(y,m);{let C=new RegExp(m.regex),S=e.sourceCode.getText(y);return O.replaceText(y,S.replace(C,m.with))}};e.report({node:y,messageId:"default",data:{message:T},fix:m&&E==="autofix"?g:void 0,suggest:m&&E==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof m=="string"?m:m.with}"`},fix:g}]:void 0})}}});function $n(e,t){let n=[],r=t.exec(e);if(!r)return null;let[s,...a]=r;n.push({name:"$0_lowercase",value:s.toLowerCase()}),n.push({name:"$0_capitalize",value:It(s)}),n.push({name:"$0_uncapitalize",value:wt(s)}),n.push({name:"$0",value:s});for(let u=0;u<a.length;u++){let i=`$${u+1}`,o=a[u];n.push({name:`${i}_lowercase`,value:o.toLowerCase()}),n.push({name:`${i}_capitalize`,value:It(o)}),n.push({name:`${i}_uncapitalize`,value:wt(o)}),n.push({name:i,value:o})}return n}function It(e){return e.charAt(0).toUpperCase()+e.slice(1)}function wt(e){return e.charAt(0).toLowerCase()+e.slice(1)}var D=require("@typescript-eslint/utils");var Un=D.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),vt="collapse-simple-objs-in-one-line",Vn=_({maxLineLength:F(G()),maxProperties:F(G()),nestedObjMaxLineLength:F(G()),nestedObjMaxProperties:F(G()),ignoreTypesWithSuffix:F(Y(N()))}),Wn=Un({name:vt,meta:{type:"suggestion",fixable:"code",docs:{description:"Format simple objects and types in one line"},messages:{singleLineProp:"Object/type should be written in a single line"},schema:[Vn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],s=t.maxProperties??2,a=t.nestedObjMaxLineLength??t.maxLineLength,u=t.nestedObjMaxProperties??3;function i(l){if(l.type===D.AST_NODE_TYPES.ObjectExpression){let c=l.parent.type===D.AST_NODE_TYPES.Property,f=c?u:s,h=l.properties.length;if(h>f)return!1;if(h===1){let y=l.properties[0];return y.type===D.AST_NODE_TYPES.Property&&y.value.type===D.AST_NODE_TYPES.ObjectExpression||y.type===D.AST_NODE_TYPES.Property&&y.value.type===D.AST_NODE_TYPES.ArrayExpression&&!y.value.elements.every(E=>E&&Ue(E))?!1:{text:n.getText(y),isNested:c,propsSize:h}}let m=[];for(let y of l.properties){if(y.type===D.AST_NODE_TYPES.Property&&!Ue(y.value))return!1;m.push(n.getText(y))}return{text:m.join(", "),isNested:c,propsSize:h}}else{let c=l.parent.parent?.type===D.AST_NODE_TYPES.TSPropertySignature,f=c?u:s,h=l.members.length;if(h>f)return!1;if(r.length>0&&l.parent.type===D.AST_NODE_TYPES.TSTypeAliasDeclaration){let y=l.parent.id.name;if(r.some(T=>y.endsWith(T)))return!1}if(h===1){let y=l.members[0];return y.type===D.AST_NODE_TYPES.TSPropertySignature&&y.typeAnnotation?.typeAnnotation.type===D.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(y),isNested:c,propsSize:1}}if(l.parent.type===D.AST_NODE_TYPES.TSIntersectionType||l.parent.type===D.AST_NODE_TYPES.TSUnionType)return!1;let m=[];for(let y of l.members){if(y.type!==D.AST_NODE_TYPES.TSPropertySignature)return!1;let T=y.typeAnnotation?.typeAnnotation;if(!T||T.type===D.AST_NODE_TYPES.TSTypeLiteral||!Rt(T))return!1;if(T.type===D.AST_NODE_TYPES.TSTypeReference&&T.typeArguments){if(T.typeArguments.params.length>1)return!1;let g=T.typeArguments.params[0];if(!Rt(g))return!1}let E=n.getText(y).trim();(E.endsWith(";")||E.endsWith(","))&&(E=E.slice(0,-1)),m.push(E)}return{text:m.join("; "),isNested:c,propsSize:h}}}function o(l){if(l.loc.start.line===l.loc.end.line)return;if(l.parent.type!==D.AST_NODE_TYPES.JSXExpressionContainer){let T=0,E=n.getTokenAfter(l,{filter:g=>g.type!==D.AST_TOKEN_TYPES.Punctuator?!0:g.value===","||g.value===";"||g.value===")"||g.value==="}"?(T++,!1):!0});if(T>4||E?.loc.start.line===l.loc.end.line)return}let c=i(l);if(!c)return;let f=c.text;if(f.includes(`
|
|
2
|
-
`)||n.getCommentsInside(
|
|
3
|
-
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function
|
|
1
|
+
"use strict";var Ln=Object.create;var xe=Object.defineProperty;var _n=Object.getOwnPropertyDescriptor;var Mn=Object.getOwnPropertyNames;var $n=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var Vn=(e,t)=>{for(var n in t)xe(e,n,{get:t[n],enumerable:!0})},wt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Mn(t))!Un.call(e,s)&&s!==n&&xe(e,s,{get:()=>t[s],enumerable:!(r=_n(t,s))||r.enumerable});return e};var Me=(e,t,n)=>(n=e!=null?Ln($n(e)):{},wt(t||!e||!e.__esModule?xe(n,"default",{value:e,enumerable:!0}):n,e)),Wn=e=>wt(xe({},"__esModule",{value:!0}),e);var xi={};Vn(xi,{extendedLintPlugin:()=>bi});module.exports=Wn(xi);var B=require("@typescript-eslint/utils");var $e=Symbol.for("optional");function O(e){return{...e,[$e]:!0}}function Ie(e,t){return{enum:e,...t}}function ue(e){return{...e,type:"boolean"}}function A(e){return{...e,type:"string"}}function Q(e){return{...e,type:"number"}}function Rt(e){return{...e,type:"integer"}}function z(e,t){return{...t,type:"array",items:e}}function j(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,s=[];for(r in e)e[r][$e]?e[r][$e]=void 0:s.push(r);s.length>0&&(n.required=s)}return n}function Ue(...e){return{anyOf:e}}var Hn=B.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),vt="react-compiler-extra",Yn=j({runOnlyWithEnableCompilerDirective:O(ue())}),zn=/eslint +react-compiler\/react-compiler: +\["error/;function Bn(e){return e.type===B.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===B.AST_NODE_TYPES.MemberExpression&&e.property.type===B.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var qn=/\bthis[.[]/;function kt(e){return qn.test(e)}var Xn=Hn({name:vt,meta:{type:"suggestion",fixable:"code",docs:{description:"Extra rules to enforce best practices when using the React compiler"},messages:{objectMethodIsNotSupported:"Object methods such as `{ method() {} }` have limited support to optimizations in the React compiler, use a function expression `{ method: () => {} }` instead.",replaceWithFunctionExpression:"Replace with function expression",thisKeywordInMethod:"Object method uses `this` keyword which would have different behavior if converted to an arrow function. Fix this manually."},hasSuggestions:!0,schema:[Yn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let a of e.sourceCode.getAllComments())if(zn.test(a.value)){n=!0;break}if(!n)return{}}function r(a){for(let o of a.properties)if(o.type===B.AST_NODE_TYPES.Property&&o.method&&o.value.type===B.AST_NODE_TYPES.FunctionExpression){let i=e.sourceCode,l=i.getText(o.key),c=o.value,p=i.getText(c.body);if(kt(p))e.report({node:o,messageId:"thisKeywordInMethod"});else{let f=c.params.map(m=>i.getText(m)).join(", "),h="";c.generator?h=`${l}: function* (${f}) ${p}`:h=`${l}: (${f}) => ${p}`,e.report({node:o,messageId:"objectMethodIsNotSupported",fix:m=>m.replaceText(o,h)})}}}function s(a){for(let o of a.properties)if(o.type===B.AST_NODE_TYPES.Property&&o.value.type===B.AST_NODE_TYPES.ObjectExpression){for(let i of o.value.properties)if(i.type===B.AST_NODE_TYPES.Property&&i.method&&i.value.type===B.AST_NODE_TYPES.FunctionExpression){let c=e.sourceCode.getText(i.value.body);kt(c)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(a){if(Bn(a.callee))for(let o of a.arguments){if(o.type===B.AST_NODE_TYPES.ObjectExpression&&(r(o),s(o)),o.type===B.AST_NODE_TYPES.ArrowFunctionExpression&&(o.body.type===B.AST_NODE_TYPES.ObjectExpression&&(r(o.body),s(o.body)),o.body.type===B.AST_NODE_TYPES.BlockStatement))for(let i of o.body.body)i.type===B.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===B.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),s(i.argument));if(o.type===B.AST_NODE_TYPES.FunctionExpression)for(let i of o.body.body)i.type===B.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===B.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),s(i.argument))}}}}}),Ve={name:vt,rule:Xn};var Ce=require("@typescript-eslint/utils");var Ot=require("@typescript-eslint/utils");function ae(e){let n=Ot.ESLintUtils.RuleCreator(r=>`https://github.com/lucasols/extended-lint#${r}`)(e);return{name:e.name,rule:n}}var Kn=j({disallow:O(z(j({selector:A(),message:A(),replace:O(Ue(A(),j({regex:A(),with:A()}))),replaceType:O(Ie(["suggestion","autofix"]))}))),__dev_simulateFileName:O(A()),mustMatchSyntax:O(z(j({includeRegex:A(),mustCallFn:O(z(j({anyCall:z(j({fn:A(),withArgs:z(j({atIndex:Rt(),literal:Ue(A(),Q(),ue())}))})),message:O(A())}))),mustMatchSelector:O(z(j({selector:A(),message:A()})))})))}),We=ae({name:"advanced-no-restricted-syntax",meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Kn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:s,disallow:a}=t,o=s??e.filename,i=[],l=new Map,c=new Set,p=new Map;for(let{includeRegex:m,mustCallFn:y,mustMatchSelector:T}of r??[]){let E=Jn(o,new RegExp(m));if(!E)continue;let g=v=>{let I=v;for(let{name:S,value:k}of E)I=I.replaceAll(S,k);return I};for(let{anyCall:v,message:I}of y??[]){let S=`Expected file to call the function: ${v.map(({fn:k})=>k).join(" or ")}`;c.add(S),i.push(k=>{let{callee:N}=k;if(N.type===Ce.AST_NODE_TYPES.Identifier){for(let{fn:L,withArgs:M}of v)if(N.name===L){c.delete(S);for(let R of M){let V=k.arguments[R.atIndex],q=typeof R.literal=="string"?g(R.literal):R.literal;if(!V){e.report({node:k,messageId:"default",data:{message:`Missing argument with value "${q}" at index ${R.atIndex}${I?`: ${g(I)}`:""}`}});continue}if(V.type!==Ce.AST_NODE_TYPES.Literal){e.report({node:V,messageId:"default",data:{message:`Argument at position ${R.atIndex} should the literal "${q}"${I?`: ${g(I)}`:""}`}});continue}V.value!==q&&e.report({node:V,messageId:"default",data:{message:`Argument should have the value "${q}"${I?`: ${g(I)}`:""}`},fix:Te=>Te.replaceText(V,typeof q=="string"?`'${q}'`:String(q))})}break}}})}for(let{selector:v,message:I}of T??[])p.set(v,g(I)),l.set(g(v),()=>{p.delete(v)})}function f(m,y){let T=n[m];T?n[m]=E=>{T(E),y(E)}:n[m]=y}for(let{selector:m,message:y,replace:T,replaceType:E="suggestion"}of a??[]){if(m==="CallExpression"){i.push(g=>{h(T,g,y,E)});continue}n[m]=g=>{h(T,g,y,E)}}if(l.size>0)for(let[m,y]of l)f(m,y);return i.length>0&&(n.CallExpression=m=>{if(m.type===Ce.AST_NODE_TYPES.CallExpression)for(let y of i)y(m)}),n["Program:exit"]=m=>{for(let y of c)e.report({node:m,messageId:"default",data:{message:y}});for(let[,y]of p)e.report({node:m,messageId:"default",data:{message:y}})},n;function h(m,y,T,E){let g=v=>{if(!m)return null;if(typeof m=="string")return v.replaceText(y,m);{let I=new RegExp(m.regex),S=e.sourceCode.getText(y);return v.replaceText(y,S.replace(I,m.with))}};e.report({node:y,messageId:"default",data:{message:T},fix:m&&E==="autofix"?g:void 0,suggest:m&&E==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof m=="string"?m:m.with}"`},fix:g}]:void 0})}}});function Jn(e,t){let n=[],r=t.exec(e);if(!r)return null;let[s,...a]=r;n.push({name:"$0_lowercase",value:s.toLowerCase()}),n.push({name:"$0_capitalize",value:At(s)}),n.push({name:"$0_uncapitalize",value:Pt(s)}),n.push({name:"$0",value:s});for(let o=0;o<a.length;o++){let i=`$${o+1}`,l=a[o];n.push({name:`${i}_lowercase`,value:l.toLowerCase()}),n.push({name:`${i}_capitalize`,value:At(l)}),n.push({name:`${i}_uncapitalize`,value:Pt(l)}),n.push({name:i,value:l})}return n}function At(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Pt(e){return e.charAt(0).toLowerCase()+e.slice(1)}var _=require("@typescript-eslint/utils");var Gn=_.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Nt="collapse-simple-objs-in-one-line",Zn=j({maxLineLength:O(Q()),maxProperties:O(Q()),nestedObjMaxLineLength:O(Q()),nestedObjMaxProperties:O(Q()),ignoreTypesWithSuffix:O(z(A()))}),Qn=Gn({name:Nt,meta:{type:"suggestion",fixable:"code",docs:{description:"Format simple objects and types in one line"},messages:{singleLineProp:"Object/type should be written in a single line"},schema:[Zn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],s=t.maxProperties??2,a=t.nestedObjMaxLineLength??t.maxLineLength,o=t.nestedObjMaxProperties??3;function i(c){if(c.type===_.AST_NODE_TYPES.ObjectExpression){let p=c.parent.type===_.AST_NODE_TYPES.Property,f=p?o:s,h=c.properties.length;if(h>f)return!1;if(h===1){let y=c.properties[0];return y.type===_.AST_NODE_TYPES.Property&&y.value.type===_.AST_NODE_TYPES.ObjectExpression||y.type===_.AST_NODE_TYPES.Property&&y.value.type===_.AST_NODE_TYPES.ArrayExpression&&!y.value.elements.every(E=>E&&He(E))?!1:{text:n.getText(y),isNested:p,propsSize:h}}let m=[];for(let y of c.properties){if(y.type===_.AST_NODE_TYPES.Property&&!He(y.value))return!1;m.push(n.getText(y))}return{text:m.join(", "),isNested:p,propsSize:h}}else{let p=c.parent.parent?.type===_.AST_NODE_TYPES.TSPropertySignature,f=p?o:s,h=c.members.length;if(h>f)return!1;if(r.length>0&&c.parent.type===_.AST_NODE_TYPES.TSTypeAliasDeclaration){let y=c.parent.id.name;if(r.some(T=>y.endsWith(T)))return!1}if(h===1){let y=c.members[0];return y.type===_.AST_NODE_TYPES.TSPropertySignature&&y.typeAnnotation?.typeAnnotation.type===_.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(y),isNested:p,propsSize:1}}if(c.parent.type===_.AST_NODE_TYPES.TSIntersectionType||c.parent.type===_.AST_NODE_TYPES.TSUnionType)return!1;let m=[];for(let y of c.members){if(y.type!==_.AST_NODE_TYPES.TSPropertySignature)return!1;let T=y.typeAnnotation?.typeAnnotation;if(!T||T.type===_.AST_NODE_TYPES.TSTypeLiteral||!Ft(T))return!1;if(T.type===_.AST_NODE_TYPES.TSTypeReference&&T.typeArguments){if(T.typeArguments.params.length>1)return!1;let g=T.typeArguments.params[0];if(!Ft(g))return!1}let E=n.getText(y).trim();(E.endsWith(";")||E.endsWith(","))&&(E=E.slice(0,-1)),m.push(E)}return{text:m.join("; "),isNested:p,propsSize:h}}}function l(c){if(c.loc.start.line===c.loc.end.line)return;if(c.parent.type!==_.AST_NODE_TYPES.JSXExpressionContainer){let T=0,E=n.getTokenAfter(c,{filter:g=>g.type!==_.AST_TOKEN_TYPES.Punctuator?!0:g.value===","||g.value===";"||g.value===")"||g.value==="}"?(T++,!1):!0});if(T>4||E?.loc.start.line===c.loc.end.line)return}let p=i(c);if(!p)return;let f=p.text;if(f.includes(`
|
|
2
|
+
`)||n.getCommentsInside(c).length>0)return;f.endsWith(";")&&(f=f.slice(0,-1));let h=`{ ${f} }`,m=tr(n,c),y=p.isNested&&p.propsSize>2?a:t.maxLineLength;y&&h.length+m.length+er(c,n)>y||e.report({node:c,messageId:"singleLineProp",fix:T=>T.replaceText(c,h)})}return{TSTypeLiteral:l,ObjectExpression:l}}});function Ft(e){return e.type===_.AST_NODE_TYPES.TSLiteralType||e.type===_.AST_NODE_TYPES.TSTypeReference||e.type===_.AST_NODE_TYPES.TSNumberKeyword||e.type===_.AST_NODE_TYPES.TSStringKeyword||e.type===_.AST_NODE_TYPES.TSBooleanKeyword||e.type===_.AST_NODE_TYPES.TSNullKeyword||e.type===_.AST_NODE_TYPES.TSUndefinedKeyword}function He(e,t){return!!(e.type===_.AST_NODE_TYPES.Literal||e.type===_.AST_NODE_TYPES.Identifier||e.type===_.AST_NODE_TYPES.TemplateLiteral||e.type===_.AST_NODE_TYPES.TaggedTemplateExpression||!t&&e.type===_.AST_NODE_TYPES.ArrayExpression&&e.elements.every(n=>n&&He(n,!0)))}function er(e,t){let n=t.getLastToken(e);if(!n)return 0;let r=t.text.indexOf(`
|
|
3
|
+
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function tr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Ye={name:Nt,rule:Qn};var nr=/eslint +react-compiler\/react-compiler: +\["error/,jt={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){let t=!1,n=typeof e.getSource=="function"?g=>n(g):g=>e.sourceCode.getText(g),r=typeof e.getScope=="function"?()=>r():g=>e.sourceCode.getScope(g),s=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,a=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,o={additionalHooks:s,enableDangerousAutofixThisMayCauseInfiniteLoops:a};function i(g){a&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let l=e.getSourceCode().scopeManager,c=new WeakMap,p=new WeakSet,f=new WeakMap,h=new WeakMap,m=new WeakSet;function y(g,v){return function(I){if(v.has(I))return v.get(I);let S=g(I);return v.set(I,S),S}}function T(g,v,I,S,k){k&&g.async&&i({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
|
|
4
4
|
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
async function fetchData() {
|
|
@@ -11,5 +11,5 @@ useEffect(() => {
|
|
|
11
11
|
fetchData();
|
|
12
12
|
}, [someId]); // Or [] if effect doesn't need props or state
|
|
13
13
|
|
|
14
|
-
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let A=o.acquire(g),L=new Set,j=null;{let p=A.upper;for(;p&&(L.add(p),p.type!=="function");)p=p.upper;if(!p)return;j=p}let R=Array.isArray;function U(p){if(!R(p.defs))return!1;let d=p.defs[0];if(d==null||d.node.type!=="VariableDeclarator")return!1;let b=d.node.init;if(b==null)return!1;for(;b.type==="TSAsExpression";)b=b.expression;let x=d.node.parent;if(x==null&&(Ye(j.block,d.node.id),x=d.node.parent,x==null))return!1;if(x.kind==="const"&&b.type==="Literal"&&(typeof b.value=="string"||typeof b.value=="number"||b.value===null))return!0;if(b.type!=="CallExpression")return!1;let w=b.callee;if(w.type==="MemberExpression"&&w.object.name==="React"&&w.property!=null&&!w.computed&&(w=w.property),w.type!=="Identifier")return!1;let I=d.node.id,{name:k}=w;if(k==="useRef"&&I.type==="Identifier")return!0;if(Jn(w)&&I.type==="Identifier"){for(let P of p.references)P!==I&&m.add(P.identifier);return!0}else if(k==="useState"||k==="useReducer"){if(I.type==="ArrayPattern"&&I.elements.length===2&&R(p.identifiers)){if(I.elements[1]===p.identifiers[0]){if(k==="useState"){let P=p.references,J=0;for(let ee=0;ee<P.length;ee++){if(P[ee].isWrite()&&J++,J>1)return!1;l.set(P[ee].identifier,I.elements[0])}}return!0}else if(I.elements[0]===p.identifiers[0]){if(k==="useState"){let P=p.references;for(let J=0;J<P.length;J++)c.add(P[J].identifier)}return!1}}}else if(k==="useTransition"&&I.type==="ArrayPattern"&&I.elements.length===2&&Array.isArray(p.identifiers)&&I.elements[1]===p.identifiers[0])return!0;return!1}function B(p){if(!R(p.defs))return!1;let d=p.defs[0];if(d==null||d.node==null||d.node.id==null)return!1;let b=d.node,x=j.childScopes,w=null,I;for(I=0;I<x.length;I++){let k=x[I],P=k.block;if(b.type==="FunctionDeclaration"&&P===b||b.type==="VariableDeclarator"&&P.parent===b){w=k;break}}if(w==null)return!1;for(I=0;I<w.through.length;I++){let k=w.through[I];if(k.resolved!=null&&L.has(k.resolved.scope)&&!ye(k.resolved))return!1}return!0}let ye=y(U,f),Tn=y(B,h),dt=new Map;function hn(p){let d=p.from,b=!1;for(;d.block!==g;)d.type==="function"&&(b=d.block.parent!=null&&d.block.parent.type==="ReturnStatement"),d=d.upper;return b}let X=new Map,Pe=new Map;yt(A);function yt(p){for(let d of p.references){if(!d.resolved||!L.has(d.resolved.scope))continue;let b=Ye(g,d.identifier),x=At(b),w=te(x,Pe);if(v&&x.type==="Identifier"&&(x.parent.type==="MemberExpression"||x.parent.type==="OptionalMemberExpression")&&!x.parent.computed&&x.parent.property.type==="Identifier"&&x.parent.property.name==="current"&&hn(d)&&dt.set(w,{reference:d,dependencyNode:x}),x.parent.type==="TSTypeQuery"||x.parent.type==="TSTypeReference")continue;let I=d.resolved.defs[0];if(I!=null&&!(I.node!=null&&I.node.init===g.parent)&&I.type!=="TypeParameter")if(X.has(w))X.get(w).references.push(d);else{let k=d.resolved,P=ye(k)||Tn(k);X.set(w,{isStable:P,references:[d]})}}for(let d of p.childScopes)yt(d)}dt.forEach(({reference:p,dependencyNode:d},b)=>{let x=p.resolved.references,w=!1;for(let I=0;I<x.length;I++){let{identifier:k}=x[I],{parent:P}=k;if(P!=null&&P.type==="MemberExpression"&&!P.computed&&P.property.type==="Identifier"&&P.property.name==="current"&&P.parent.type==="AssignmentExpression"&&P.parent.left===P){w=!0;break}}w||i({node:d.parent.property,message:`The ref value '${b}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${b}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Fe=new Set;function En(p,d){Fe.has(d)||(Fe.add(d),i({node:p,message:`Assignments to the '${d}' variable from inside React Hook ${n(C)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(C)}.`}))}let ge=new Set;if(X.forEach(({isStable:p,references:d},b)=>{p&&ge.add(b),d.forEach(x=>{x.writeExpr&&En(x.writeExpr,b)})}),Fe.size>0)return;if(!O){let p=null;if(X.forEach(({isStable:d,references:b},x)=>{p||b.forEach(w=>{if(p)return;let I=w.identifier;if(!l.has(I))return;let P=w.from;for(;P.type!=="function";)P=P.upper;P.block===g&&(p=x)})}),p){let{suggestedDependencies:d}=We({dependencies:X,declaredDependencies:[],stableDependencies:ge,externalDependencies:new Set,isEffect:!0});i({node:C,message:`React Hook ${S} contains a call to '${p}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+d.join(", ")+`] as a second argument to the ${S} Hook.`,suggest:[{desc:`Add dependencies array: [${d.join(", ")}]`,fix(b){return b.insertTextAfter(g,`, [${d.join(", ")}]`)}}]})}return}let fe=[],me=new Set;O.type!=="ArrayExpression"?i({node:O,message:`React Hook ${n(C)} 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(p=>{if(p===null)return;if(p.type==="SpreadElement"){i({node:p,message:`React Hook ${n(C)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}m.has(p)&&i({node:p,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(p)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(p)}\``,fix(w){return w.removeRange(p.range)}}]});let d;try{d=te(p,Pe)}catch(w){if(/Unsupported node type/.test(w.message)){p.type==="Literal"?X.has(p.value)?i({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. Did you mean to include ${p.value} in the array instead?`}):i({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):i({node:p,message:`React Hook ${n(C)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw w}let b=p;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let x=!j.through.some(w=>w.identifier===b);fe.push({key:d,node:p}),x||me.add(d)});let{suggestedDependencies:bn,unnecessaryDependencies:Se,missingDependencies:ie,duplicateDependencies:gt}=We({dependencies:X,declaredDependencies:fe,stableDependencies:ge,externalDependencies:me,isEffect:v}),Te=bn;if(gt.size+ie.size+Se.size===0){if(t)return;Bn({declaredDependencies:fe,declaredDependenciesNode:O,componentScope:j,scope:A}).forEach(({construction:d,isUsedOutsideOfHook:b,depType:x})=>{let w=x==="function"?"useCallback":"useMemo",I=x==="function"?"definition":"initialization",k=`wrap the ${I} of '${d.name.name}' in its own ${w}() Hook.`,P=b?`To fix this, ${k}`:`Move it inside the ${S} callback. Alternatively, ${k}`,J=x==="conditional"||x==="logical expression"?"could make":"makes",ee=`The '${d.name.name}' ${x} ${J} the dependencies of ${S} Hook (at line ${O.loc.start.line}) change on every render. ${P}`,St;b&&d.type==="Variable"&&x==="function"&&(St=[{desc:`Wrap the ${I} of '${d.name.name}' in its own ${w}() Hook.`,fix(Tt){let[Cn,In]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Tt.insertTextBefore(d.node.init,Cn),Tt.insertTextAfter(d.node.init,In)]}}]),i({node:d.node,message:ee,suggest:St})});return}!v&&ie.size>0&&(Te=We({dependencies:X,declaredDependencies:[],stableDependencies:ge,externalDependencies:me,isEffect:v}).suggestedDependencies);function xn(){if(fe.length===0)return!0;let p=fe.map(b=>b.key),d=p.slice().sort();return p.join(",")===d.join(",")}xn()&&Te.sort();function Ne(p){let d=p.split("."),b="";for(let x=0;x<d.length;x++){if(x!==0){let w=d.slice(0,x+1).join("."),I=Pe.get(w)===!0;b+=I?"?.":"."}b+=d[x]}return b}function Le(p,d,b,x){return p.size===0?null:(p.size>1?"":d+" ")+b+" "+(p.size>1?"dependencies":"dependency")+": "+Kn(Array.from(p).sort().map(w=>"'"+Ne(w)+"'"))+`. Either ${x} ${p.size>1?"them":"it"} or remove the dependency array.`}let Z="";if(Se.size>0){let p=null;if(Array.from(Se.keys()).forEach(d=>{p===null&&d.endsWith(".current")&&(p=d)}),p!==null)Z=` Mutable values like '${p}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(me.size>0){let d=Array.from(me)[0];A.set.has(d)||(Z=` Outer scope values like '${d}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!Z&&ie.has("props")){let p=X.get("props");if(p==null)return;let d=p.references;if(!Array.isArray(d))return;let b=!0;for(let x=0;x<d.length;x++){let w=d[x],I=Ye(j.block,w.identifier);if(!I){b=!1;break}let k=I.parent;if(k==null){b=!1;break}if(k.type!=="MemberExpression"&&k.type!=="OptionalMemberExpression"){b=!1;break}}b&&(Z=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${S} call and refer to those specific props inside ${n(C)}.`)}if(!Z&&ie.size>0){let p=null;ie.forEach(d=>{if(p)return;let b=j.set.get(d),x=X.get(d);if(x.references[0].resolved!==b)return;let w=b.defs[0];if(w==null||w.name==null||w.type!=="Parameter")return;let I=!1,k;for(let P=0;P<x.references.length;P++)if(k=x.references[P].identifier,k!=null&&k.parent!=null&&(k.parent.type==="CallExpression"||k.parent.type==="OptionalCallExpression")&&k.parent.callee===k){I=!0;break}I&&(p=d)}),p!==null&&(Z=` If '${p}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!Z&&ie.size>0){let p=null;if(ie.forEach(d=>{if(p!==null)return;let x=X.get(d).references,w,I;for(let k=0;k<x.length;k++){for(w=x[k].identifier,I=w.parent;I!=null&&I!==j.block;){if(I.type==="CallExpression"){let P=l.get(I.callee);if(P!=null){if(P.name===d)p={missingDep:d,setter:I.callee.name,form:"updater"};else if(c.has(w))p={missingDep:d,setter:I.callee.name,form:"reducer"};else{let J=x[k].resolved;if(J!=null){let ee=J.defs[0];ee!=null&&ee.type==="Parameter"&&(p={missingDep:d,setter:I.callee.name,form:"inlineReducer"})}}break}}I=I.parent}if(p!==null)break}}),p!==null)switch(p.form){case"reducer":Z=` You can also replace multiple useState variables with useReducer if '${p.setter}' needs the current value of '${p.missingDep}'.`;break;case"inlineReducer":Z=` If '${p.setter}' needs the current value of '${p.missingDep}', you can also switch to useReducer instead of useState and read '${p.missingDep}' in the reducer.`;break;case"updater":Z=` You can also do a functional update '${p.setter}(${p.missingDep.slice(0,1)} => ...)' if you only need '${p.missingDep}' in the '${p.setter}' call.`;break;default:throw new Error("Unknown case.")}}i({node:O,message:`React Hook ${n(C)} has `+(Le(ie,"a","missing","include")||Le(Se,"an","unnecessary","exclude")||Le(gt,"a","duplicate","omit"))+Z,suggest:[{desc:`Update the dependencies array to be: [${Te.map(Ne).join(", ")}]`,fix(p){return p.replaceText(O,`[${Te.map(Ne).join(", ")}]`)}}]})}function E(g){let O=qn(g.callee,u);if(O===-1)return;let C=g.arguments[O],S=g.callee,v=Pt(S).name,A=g.arguments[O+1],L=/Effect($|[^a-z])/g.test(v);if(!C){i({node:S,message:`React Hook ${v} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!L)){if(!A&&!L){(v==="useMemo"||v==="useCallback")&&i({node:S,message:`React Hook ${v} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(C.type){case"FunctionExpression":case"ArrowFunctionExpression":T(C,A,S,v,L);return;case"Identifier":if(!A||A.elements&&A.elements.some(U=>U&&U.type==="Identifier"&&U.name===C.name))return;let j=r(g).set.get(C.name);if(j==null||j.defs==null)return;let R=j.defs[0];if(!R||!R.node||R.type!=="Variable"&&R.type!=="FunctionName")break;switch(R.node.type){case"FunctionDeclaration":T(R.node,A,S,v,L);return;case"VariableDeclarator":let U=R.node.init;if(!U)break;switch(U.type){case"ArrowFunctionExpression":case"FunctionExpression":T(U,A,S,v,L);return}break}break;default:i({node:S,message:`React Hook ${v} received a function whose dependencies are unknown. Pass an inline function instead.`});return}i({node:S,message:`React Hook ${v} has a missing dependency: '${C.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${C.name}]`,fix(j){return j.replaceText(A,`[${C.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(zn.test(g.value))return t=!0,{CallExpression:O=>E(O,!0)}}return{CallExpression:g=>E(g)}}};function We({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:s}){let a=u();function u(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,E)=>{let g=i(a,E);g.isUsed=!0,o(a,E,O=>{O.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let E=i(a,T);E.isSatisfiedRecursively=!0}),n.forEach(T=>{let E=i(a,T);E.isSatisfiedRecursively=!0});function i(T,E){let g=E.split("."),O=T;for(let C of g){let S=O.children.get(C);S||(S=u(),O.children.set(C,S)),O=S}return O}function o(T,E,g){let O=E.split("."),C=T;for(let S of O){let v=C.children.get(S);if(!v)return;g(v),C=v}}let l=new Set,c=new Set;f(a,l,c,T=>T);function f(T,E,g,O){T.children.forEach((C,S)=>{let v=O(S);if(C.isSatisfiedRecursively){C.isSubtreeUsed&&g.add(v);return}if(C.isUsed){E.add(v);return}f(C,E,g,A=>v+"."+A)})}let h=[],m=new Set,y=new Set;return t.forEach(({key:T})=>{c.has(T)?h.indexOf(T)===-1?h.push(T):y.add(T):m.add(T)}),l.forEach(T=>{h.push(T)}),{suggestedDependencies:h,unnecessaryDependencies:m,duplicateDependencies:y,missingDependencies:l}}function se(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 se(e.consequent)!=null||se(e.alternate)!=null?"conditional":null;case"LogicalExpression":return se(e.left)!=null||se(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return se(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return se(e.expression);case"TSAsExpression":return se(e.expression)}return null}function Bn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let s=e.map(({key:u})=>{let i=n.variables.find(l=>l.name===u);if(i==null)return null;let o=i.defs[0];if(o==null)return null;if(o.type==="Variable"&&o.node.type==="VariableDeclarator"&&o.node.id.type==="Identifier"&&o.node.init!=null){let l=se(o.node.init);if(l!=null)return[i,l]}return o.type==="FunctionName"&&o.node.type==="FunctionDeclaration"?[i,"function"]:o.type==="ClassName"&&o.node.type==="ClassDeclaration"?[i,"class"]:null}).filter(Boolean);function a(u){let i=!1;for(let o=0;o<u.references.length;o++){let l=u.references[o];if(l.writeExpr){if(i)return!0;i=!0;continue}let c=l.from;for(;c!==r&&c!=null;)c=c.upper;if(c!==r&&!Ft(t,l.identifier))return!0}return!1}return s.map(([u,i])=>({construction:u.defs[0],depType:i,isUsedOutsideOfHook:a(u)}))}function At(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)?At(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function He(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function te(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=te(e.object,t),r=te(e.property,null),s=`${n}.${r}`;return He(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=te(e.object,t),r=te(e.property,null),s=`${n}.${r}`;return He(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=te(n.object,t),s=te(n.property,null),a=`${r}.${s}`;return He(n,t,a),a}else throw new Error(`Unsupported node type: ${e.type}`)}function Pt(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function qn(e,t){let n=Pt(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 r;try{r=te(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(r)?0:-1}else return-1}}function Ye(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Xn(r,t))return r;if(Ft(r,t))for(let[s,a]of Object.entries(r))s!=="parent"&&(Ot(a)?(a.parent=r,n.push(a)):Array.isArray(a)&&a.forEach(u=>{Ot(u)&&(u.parent=r,n.push(u))}))}return null}function Kn(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 Ot(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Xn(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 Ft(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Jn(e){return!1}var oe=require("@typescript-eslint/utils");var q=_e(require("typescript")),Gn=oe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Nt="improved-no-unnecessary-condition",Zn=_({}),Qn=["string","number","bigint","boolean","symbol","undefined","object","function","never"],er=new Set(Qn),ze={name:Nt,rule:Gn({name:Nt,meta:{type:"suggestion",docs:{description:"Extends checks of `no-unnecessary-condition` rule"},messages:{unnecessaryTypeofCondition:'This condition is unnecessary. The type of "{{name}}" is always "{{type}}".',alwaysFalseTypeofCondition:'This condition will always be false. The type of "{{name}}" is "{{actualType}}" so the condition has no overlap with "{{conditionType}}".'},schema:[Zn]},defaultOptions:[{}],create(e){let t=oe.ESLintUtils.getParserServices(e,!0),n=t.program?.getTypeChecker();if(!n||!t.program)throw new Error("TypeScript services or program not available");function r(i){return i.type===oe.AST_NODE_TYPES.UnaryExpression&&i.operator==="typeof"}function s(i){return i.flags&q.default.TypeFlags.Any||i.flags&q.default.TypeFlags.Unknown?null:i.flags&q.default.TypeFlags.StringLike?["string"]:i.flags&q.default.TypeFlags.NumberLike?["number"]:i.flags&q.default.TypeFlags.BigIntLike?["bigint"]:i.flags&q.default.TypeFlags.BooleanLike?["boolean"]:i.flags&q.default.TypeFlags.ESSymbolLike?["symbol"]:i.flags&q.default.TypeFlags.Undefined||i.flags&q.default.TypeFlags.Void?["undefined"]:i.flags&q.default.TypeFlags.Null?["object"]:i.getCallSignatures().length>0?["function"]:i.flags&q.default.TypeFlags.Object?i.getProperties().length===0?["string","number","bigint","boolean","symbol","object","function"]:["object"]:i.flags&q.default.TypeFlags.NonPrimitive?["object"]:i.flags&q.default.TypeFlags.Never?["never"]:null}function a(i){if(!n)return null;let o=t.esTreeNodeToTSNodeMap.get(i),l=n.getTypeAtLocation(o.expression);if(l.flags&q.default.TypeFlags.Any||l.flags&q.default.TypeFlags.Unknown)return null;let c=[];if(l.isUnion()){for(let h of l.types){let m=s(h);if(m)c.push(...m);else return null}return c}let f=s(l);return f?(c.push(...f),c):null}function u(i){if(!(i.operator==="==="||i.operator==="!=="))return;let l=null,c=null;if(r(i.left)?(l=i.left,c=i.right.type===oe.AST_NODE_TYPES.Literal&&typeof i.right.value=="string"?i.right.value:null):r(i.right)&&(l=i.right,c=i.left.type===oe.AST_NODE_TYPES.Literal&&typeof i.left.value=="string"?i.left.value:null),!l||!c||!tr(c,er))return;let f=a(l);if(!f)return;let h=i.operator==="!==",m=f.includes(c);f.length===1?m&&!h?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ce(l,e),type:c}}):!m&&h?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ce(l,e),type:Array.from(f)[0]}}):!m&&!h?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ce(l,e),actualType:Ce(f),conditionType:c}}):m&&h&&e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ce(l,e),actualType:Ce(f),conditionType:c}}):!m&&!h?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ce(l,e),actualType:Ce(f),conditionType:c}}):!m&&h&&e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ce(l,e),type:Ce(f)}})}return{BinaryExpression:u}}})};function Ce(e){return Array.from(new Set(e)).join(" | ")||"never"}function ce(e,t){let n=e.argument;return n.type===oe.AST_NODE_TYPES.Identifier?n.name:t.sourceCode.getText(n)}function tr(e,t){return t.has(e)}var Ie=require("@typescript-eslint/utils");var nr=Ie.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Lt="no-call-with-explicit-generics",rr=_({functions:Y(N())}),ir=nr({name:Lt,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[rr]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:s}=r;s.type===Ie.AST_NODE_TYPES.Identifier&&n.has(s.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),Be={name:Lt,rule:ir};var ae=require("@typescript-eslint/utils"),sr=ae.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),_t="no-call-with-inferred-generics",or=sr({name:_t,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,[t]){let n=new Map(t.functions.map(r=>[r.name,r]));return{CallExpression(r){let{callee:s}=r;if(s.type!==ae.AST_NODE_TYPES.Identifier)return;let a=n.get(s.name);if(!a)return;let{minGenerics:u=1,allowAny:i,disallowTypes:o=t.disallowTypes}=a;(r.typeArguments?.params.length||0)<(u||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:u||0}}),!(i&&!o)&&r.typeArguments?.params?.some(c=>!i&&c.type===ae.AST_NODE_TYPES.TSAnyKeyword||o&&c.type===ae.AST_NODE_TYPES.TSTypeReference&&c.typeName.type===ae.AST_NODE_TYPES.Identifier&&o.includes(c.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),qe={name:_t,rule:or};var de=require("@typescript-eslint/utils"),ar=de.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Dt="no-commented-out-code",lr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],cr=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],ur=ar({name:Dt,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(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of lr)if(r.startsWith(s))return{wrongPattern:s};for(let s of cr)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let s of r)if(s.type===de.TSESTree.AST_TOKEN_TYPES.Line||s.type===de.TSESTree.AST_TOKEN_TYPES.Block){let a=t(s.value);a&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:a.wrongPattern}})}}}}}),Ke={name:Dt,rule:ur};var we=require("@typescript-eslint/utils"),pr=we.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),jt="no-default-export",fr=pr({name:jt,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.type===we.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Xe={name:jt,rule:fr};var Mt=require("@typescript-eslint/utils"),mr=Mt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="no-leaked-text-in-jsx",dr=[",",";","[","]","(",")"],yr=mr({name:$t,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";dr.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Je={name:$t,rule:yr};var ne=require("@typescript-eslint/utils"),gr=ne.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="no-non-camel-case-functions",Sr=/^[a-z][a-zA-Z0-9]*$/;function Ut(e){return e.typeName.type===ne.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===ne.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===ne.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var Tr=gr({name:Vt,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&&!Sr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ne.AST_NODE_TYPES.TSTypeReference?Ut(n):n.type===ne.AST_NODE_TYPES.TSUnionType&&n.types.some(s=>s.type===ne.AST_NODE_TYPES.TSTypeReference&&Ut(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Ge={name:Vt,rule:Tr};var $=require("@typescript-eslint/utils");var Ze=require("@typescript-eslint/utils");function ue(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:ue(e.parent,t,n===1/0?n:n-1)}function*Qe(e){yield e,e.parent&&(yield*Qe(e.parent))}function et(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function Wt(e,t,n){let s=n.getDeclaredVariables(e).find(a=>a.name===t||a.identifiers[0]?.parent.type===Ze.AST_NODE_TYPES.Property&&a.identifiers[0]?.parent.key.type===Ze.AST_NODE_TYPES.Identifier&&a.identifiers[0]?.parent.key.name===t);return s?s.references.filter(a=>!a.init):[]}var hr=$.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ht="no-optional-root-props",Er=hr({name:Ht,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let a=e.sourceCode.getDeclaredVariables(r)[0];if(!a||a.references.length!==1)return!1;let u=a.references[0];if(!u)return!1;for(let i of Qe(u.identifier)){if("returnType"in i||i.type===$.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let o=i.parent;if(!o)return!1;if(o.type===$.TSESTree.AST_NODE_TYPES.TSTypeParameterInstantiation&&o.parent.type===$.TSESTree.AST_NODE_TYPES.TSTypeReference&&o.parent.typeName.type===$.TSESTree.AST_NODE_TYPES.Identifier&&o.parent.typeName.name==="FC"){let c=ue(o.parent.parent,$.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!c)return!1;let f=Re(c,e.sourceCode);return f?!(f.parent.type===$.TSESTree.AST_NODE_TYPES.CallExpression&&f.parent.callee.type===$.TSESTree.AST_NODE_TYPES.Identifier&&f.parent.callee.name==="memo"):!1}if(i.type===$.TSESTree.AST_NODE_TYPES.AssignmentPattern)return!1;if(o.type===$.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression){let l=ue(o,$.TSESTree.AST_NODE_TYPES.VariableDeclaration);return l?!!Re(l,e.sourceCode):!1}if(o.type===$.TSESTree.AST_NODE_TYPES.FunctionDeclaration)return!!Re(o,e.sourceCode)}return!1}function n(r){r.key.type!==$.TSESTree.AST_NODE_TYPES.Identifier||!r.optional||e.report({node:r.key,messageId:"optionalNotAllowed",data:{propertyName:r.key.name},suggest:[{messageId:"suggestion",fix:s=>{let a=ue(r,$.TSESTree.AST_NODE_TYPES.TSPropertySignature);if(!a)return null;let u=e.sourceCode.getText(a);return s.replaceText(a,u.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(r){if(r.typeAnnotation.type===$.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(ve(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===$.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(ve(r)||!t(r)))for(let s of r.body.body)s.type===$.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSTypeReference(r){if(r.typeName.type!==$.TSESTree.AST_NODE_TYPES.Identifier||r.typeName.name!=="FC"||!r.typeArguments?.params[0])return;let s=r.typeArguments.params[0];if(s.type!==$.TSESTree.AST_NODE_TYPES.TSTypeLiteral)return;let a=ue(r.parent,$.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!a)return;let u=Re(a,e.sourceCode);if(!(!u||u.parent.type===$.TSESTree.AST_NODE_TYPES.CallExpression&&u.parent.callee.type===$.TSESTree.AST_NODE_TYPES.Identifier&&u.parent.callee.name==="memo"))for(let o of s.members)o.type===$.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(o)}}}});function ve(e){return e?e.parent?.type===$.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===$.TSESTree.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function Re(e,t){if(ve(e))return;let n;if(e.type===$.TSESTree.AST_NODE_TYPES.VariableDeclaration){if(e.declarations.length!==1)return;e.declarations[0].id.type===$.TSESTree.AST_NODE_TYPES.Identifier&&(n=e.declarations[0].id)}else{if(!e.id)return;n=e.id}if(!n)return;let r=t.getScope(e);e.type===$.TSESTree.AST_NODE_TYPES.FunctionDeclaration&&r.upper&&(r=r.upper);let s=r.variables.find(u=>u.identifiers.includes(n));if(!s)return;let a=s.references.filter(u=>u.identifier!==n);if(!(a.length!==1||!a[0])&&!ve(a[0].identifier.parent.parent))return a[0].identifier}var tt={name:Ht,rule:Er};var Yt=require("@typescript-eslint/utils"),Oe=_e(require("path"));var br=Yt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),zt="no-relative-imports",xr=_({find:N(),replacement:N()}),Cr=_({aliases:Y(xr),rootDir:F(N()),allowNotFoundAliases:F(le()),_dev_simulateFileName:F(N())}),Ir=br({name:zt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[Cr]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(u){return u.startsWith(".")||u.startsWith("..")}function s(u,i){let o=Oe.default.dirname(i);return Oe.default.resolve(o,u)}function a(u){let i=t.rootDir??process.cwd(),o=Oe.default.relative(i,u);if(o.startsWith("."))return null;o.startsWith("/")||(o=`/${o}`);for(let{find:l,replacement:c}of t.aliases)if(o.startsWith(c)){let f=o.replace(c,l);return{alias:l,newPath:f}}return null}return{ImportDeclaration(u){let i=u.source.value;if(!r(i))return;let o=s(i,n),l=a(o);!l&&t.allowNotFoundAliases||e.report({node:u,messageId:l?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:l?.alias},fix:l?c=>c.replaceText(u.source,`'${l.newPath}'`):void 0})}}}}),nt={name:zt,rule:Ir};var re=require("@typescript-eslint/utils");var rt=_e(require("typescript")),wr=re.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Bt="no-unnecessary-casting",Rr=_({additionalCastFunctions:F(Y(_({name:N(),expectedType:Ee(["string","number"])})))}),it={name:Bt,rule:wr({name:Bt,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[Rr],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=re.ESLintUtils.getParserServices(e,!0),a=s.program?.getTypeChecker();if(!a||!s.program)throw new Error("TypeScript services or program not available");function u(c,f){switch(c.type){case re.AST_NODE_TYPES.Literal:return f==="number"?typeof c.value=="number":typeof c.value=="string";case re.AST_NODE_TYPES.TemplateLiteral:return f==="string";case re.AST_NODE_TYPES.UnaryExpression:return f==="number"?c.operator==="+"||c.operator==="-"||c.operator==="~":!1;default:return!1}}function i(c,f){return f==="number"?!!(c.flags&rt.TypeFlags.NumberLike):!!(c.flags&rt.TypeFlags.StringLike)}function o(c,f){return h=>h.replaceText(c,e.sourceCode.getText(f))}function l(c){if(!a||c.arguments.length!==1)return;let f=c.arguments[0];if(!f||f.type===re.AST_NODE_TYPES.SpreadElement)return;let{callee:h}=c;if(h.type!==re.AST_NODE_TYPES.Identifier)return;let m=h.name,y=r.find(E=>E.name===m);if(!y)return;if(u(f,y.expectedType)||i(a.getTypeAtLocation(s.esTreeNodeToTSNodeMap.get(f)),y.expectedType)){let E,g;m==="Number"?E="unnecessaryNumberCasting":m==="String"?E="unnecessaryStringCasting":(E="unnecessaryCustomCasting",g={name:y.name,type:y.expectedType}),e.report({node:c,messageId:E,...g?{data:g}:{},fix:o(c,f)})}}return{CallExpression:l}}})};var V=require("@typescript-eslint/utils");var vr=_({selectors:Y(_({name:N(),selectorProp:F(N()),selectorArgPos:F(G()),returnProp:F(N())}))}),Or=V.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qt="no-unused-selected-values",st={name:qt,rule:Or({name:qt,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[vr]},defaultOptions:[{selectors:[]}],create(e,[t]){let{selectors:n=[]}=t,r=new Map(n.map(s=>[s.name,s]));return{VariableDeclarator(s){let a=null;if(s.init?.type===V.AST_NODE_TYPES.CallExpression&&(a=s.init),!a)return;let u=Ar(a);if(!u)return;let i=r.get(u);if(!i)return;let o=kr(a,i.selectorArgPos??0,i.selectorProp);if(!o)return;let l=Pr(o);if(!l)return;let c=Kt(l.properties,void 0);if(!c)return;if(s.id.type===V.AST_NODE_TYPES.ObjectPattern){let m=Kt(s.id.properties,i.returnProp);if(!m)return;for(let[y,T]of c)m.has(y)||e.report({node:T,messageId:"unusedSelectedValue",data:{name:y}});return}if(s.id.type!==V.AST_NODE_TYPES.Identifier||i.returnProp)return;let f=Fr(s,e.sourceCode);if(f.length===0)return;let h=new Set;for(let m of f){if(m.identifier.parent.type!==V.AST_NODE_TYPES.MemberExpression)return;let y=m.identifier.parent.property;if(y.type!==V.AST_NODE_TYPES.Identifier)return;h.add(y.name)}for(let[m,y]of c)h.has(m)||e.report({node:y,messageId:"unusedSelectedValue",data:{name:m}})}}}})};function kr(e,t,n){let r=e.arguments[t];if(!r)return null;if(r.type===V.AST_NODE_TYPES.ArrowFunctionExpression||r.type===V.AST_NODE_TYPES.FunctionExpression)return r;if(n&&r.type===V.AST_NODE_TYPES.ObjectExpression){let s=r.properties.find(u=>u.type===V.AST_NODE_TYPES.Property&&u.key.type===V.AST_NODE_TYPES.Identifier&&u.key.name===n);if(s?.type!==V.AST_NODE_TYPES.Property)return null;let a=s.value;if(a.type===V.AST_NODE_TYPES.ArrowFunctionExpression||a.type===V.AST_NODE_TYPES.FunctionExpression)return a}return null}function Ar(e){return e.callee.type===V.AST_NODE_TYPES.Identifier?e.callee.name:e.callee.type===V.AST_NODE_TYPES.MemberExpression&&e.callee.property.type===V.AST_NODE_TYPES.Identifier?e.callee.property.name:null}function Pr(e){if(e.body.type===V.AST_NODE_TYPES.ObjectExpression)return e.body;if(e.body.type===V.AST_NODE_TYPES.BlockStatement){let t=e.body.body.filter(n=>n.type===V.AST_NODE_TYPES.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==V.AST_NODE_TYPES.ObjectExpression?null:t[0].argument}return null}function Kt(e,t){let n=e;if(t){let s=e.find(a=>a.type===V.AST_NODE_TYPES.Property&&a.key.type===V.AST_NODE_TYPES.Identifier&&a.key.name===t);if(s?.type!==V.AST_NODE_TYPES.Property||s.value.type!==V.AST_NODE_TYPES.ObjectPattern)return null;n=s.value.properties}let r=new Map;for(let s of n){if(s.type!==V.AST_NODE_TYPES.Property||s.key.type!==V.AST_NODE_TYPES.Identifier)return null;r.set(s.key.name,s)}return r.size>0?r:null}function Fr(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}var W=require("@typescript-eslint/utils");var ot=be({name:"no-unused-t-state-field",meta:{type:"suggestion",docs:{description:"Prevent declaring unused t-state fields"},messages:{unusedField:'Field "{{name}}" is not being used, you can safely remove it'},schema:[]},defaultOptions:[],create(e){if(!(e.filename.endsWith(".jsx")||e.filename.endsWith(".tsx")))return{};if(!e.sourceCode.ast.body.some(a=>a.type===W.AST_NODE_TYPES.ImportDeclaration&&a.source.value==="t-state-form"))return{};let r=null,s=!1;return{CallExpression(a){if(s)return;if(!r){let i=Nr(a);i&&(r=i);return}let u=Lr(a,e.sourceCode);if(u){s=!0;for(let i of u)r.delete(i);if(r.size!==0)for(let[i,o]of r)e.report({node:o,messageId:"unusedField",data:{name:i}})}}}}});function Nr(e){if(!(e.callee.type===W.AST_NODE_TYPES.Identifier&&e.callee.name==="useForm"))return null;let n=e.arguments[0];if(!n||n.type!==W.AST_NODE_TYPES.ObjectExpression)return null;let r=et(n.properties,a=>a.type!==W.AST_NODE_TYPES.Property||a.key.type!==W.AST_NODE_TYPES.Identifier||a.key.name!=="initialConfig"?null:a.value.type===W.AST_NODE_TYPES.ObjectExpression?a.value:a.value.type===W.AST_NODE_TYPES.ArrowFunctionExpression||a.value.type===W.AST_NODE_TYPES.FunctionExpression?_r(a.value):null);if(!r)return null;let s=new Map;for(let a of r.properties)a.type===W.AST_NODE_TYPES.Property&&a.key.type===W.AST_NODE_TYPES.Identifier&&s.set(a.key.name,a);return s}function Lr(e,t){if(!(e.callee.type===W.AST_NODE_TYPES.Identifier&&e.callee.name==="useFormState")||e.parent.type!==W.AST_NODE_TYPES.VariableDeclarator||e.parent.id.type!==W.AST_NODE_TYPES.ObjectPattern||!et(e.parent.id.properties,u=>u.type===W.AST_NODE_TYPES.Property&&u.key.type===W.AST_NODE_TYPES.Identifier&&u.key.name==="formFields"&&u))return null;let s=Wt(e.parent,"formFields",t),a=new Set;for(let{identifier:u}of s){if(u.type!==W.AST_NODE_TYPES.Identifier||u.parent.type===W.AST_NODE_TYPES.Property&&u.parent.parent.type===W.AST_NODE_TYPES.ObjectExpression&&u.parent.parent.parent.type===W.AST_NODE_TYPES.ReturnStatement||u.parent.type===W.AST_NODE_TYPES.ReturnStatement)return null;if(u.parent.type===W.AST_NODE_TYPES.MemberExpression){if(u.parent.object.type!==W.AST_NODE_TYPES.Identifier||u.parent.property.type!==W.AST_NODE_TYPES.Identifier)return null;a.add(u.parent.property.name)}}return a}function _r(e){if(e.body.type===W.AST_NODE_TYPES.ObjectExpression)return e.body;if(e.body.type===W.AST_NODE_TYPES.BlockStatement){let t=e.body.body.filter(n=>n.type===W.AST_NODE_TYPES.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==W.AST_NODE_TYPES.ObjectExpression?null:t[0].argument}return null}var M=require("@typescript-eslint/utils");var Dr=M.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Xt(e){let t=[];for(let n of e.members)n.type===M.AST_NODE_TYPES.TSPropertySignature&&n.key.type===M.AST_NODE_TYPES.Identifier&&t.push([n.key.name,n]);return t}function Jt(e,...t){for(let n of t)e.set(...n);return e}var jr=_({forceCheckOnFCPropTypesWithName:F(Y(N()))}),Gt="no-unused-type-props-in-args",at=null,Mr=Dr({name:Gt,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:[jr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!at&&(at=n.map(i=>new RegExp(i)));function r(i,o,l,c,f=!0){let h=l.name,m=e.sourceCode.getScope(o).references.find(E=>E.identifier.name===h)?.resolved,y=i&&at?.some(E=>E.test(h));if(!m||!y&&m.references.filter(E=>E.isTypeReference).length>1)return;let T=m?.defs[0]?.node;if(!(f&&T?.parent?.type===M.AST_NODE_TYPES.ExportNamedDeclaration)){if(T?.type===M.AST_NODE_TYPES.TSTypeAliasDeclaration){s(i,o,c,T.typeAnnotation,!0);return}if(T?.type===M.AST_NODE_TYPES.TSInterfaceDeclaration){s(i,o,c,T.body,!0);return}}}function s(i,o,l,c,f){if(c.type===M.AST_NODE_TYPES.TSInterfaceBody){for(let h of c.body)h.type===M.AST_NODE_TYPES.TSPropertySignature&&h.key.type===M.AST_NODE_TYPES.Identifier&&l.set(h.key.name,h);return}if(c.type===M.AST_NODE_TYPES.TSTypeLiteral){Jt(l,...Xt(c));return}if(c.type===M.AST_NODE_TYPES.TSIntersectionType){for(let h of c.types)s(i,o,l,h,!0);return}f||c.type===M.AST_NODE_TYPES.TSTypeReference&&c.typeName.type===M.AST_NODE_TYPES.Identifier&&r(i,o,c.typeName,l)}function a(i,o,l){for(let c of l)if(c.type==="ObjectPattern"&&c.typeAnnotation){let f=new Map;if(s(i,o,f,c.typeAnnotation.typeAnnotation,!1),f.size===0)continue;u(c,f)}else c.type===M.AST_NODE_TYPES.AssignmentPattern&&c.left.type===M.AST_NODE_TYPES.ObjectPattern&&a(i,o,[c.left])}function u(i,o){let l=[];if(i.properties.at(-1)?.type===M.AST_NODE_TYPES.RestElement)return;for(let m of i.properties)m.type===M.AST_NODE_TYPES.Property&&m.key.type===M.AST_NODE_TYPES.Identifier&&l.push(m.key.name);let f=[],h=[];for(let[m,y]of o)l.includes(m)||(h.push(m),f.push({node:y,messageId:"unusedObjectTypeProperty",data:{propertyName:m}}));for(let[m,y]of f.entries())e.report({...y,fix:m===f.length-1?T=>{let E=i.properties.at(-1),g=h.join(", ");return E?E?.type===M.AST_NODE_TYPES.RestElement?null:T.insertTextAfter(E,`, ${g}`):T.insertTextBeforeRange([i.range[0]+1,i.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(i){let o=i.declarations[0];if(!o)return;let l=new Map,c=o.id.type===M.AST_NODE_TYPES.Identifier&&o.id.typeAnnotation?.typeAnnotation.type===M.AST_NODE_TYPES.TSTypeReference&&o.id.typeAnnotation.typeAnnotation.typeName.type===M.AST_NODE_TYPES.Identifier&&o.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&o.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(c){if(c.type===M.AST_NODE_TYPES.TSTypeReference&&c.typeName.type===M.AST_NODE_TYPES.Identifier)r(!0,i,c.typeName,l,!1);else if(c.type===M.AST_NODE_TYPES.TSTypeLiteral)Jt(l,...Xt(c));else if(c.type===M.AST_NODE_TYPES.TSIntersectionType)for(let f of c.types)f.type===M.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===M.AST_NODE_TYPES.Identifier?r(!0,i,f.typeName,l,!1):s(!0,i,l,f,!0);if(l.size!==0&&o.init?.type===M.AST_NODE_TYPES.ArrowFunctionExpression){let f=o.init.params[0];if(!f){e.report({node:o.init,messageId:"missingComponentParam"});return}f.type===M.AST_NODE_TYPES.ObjectPattern&&u(f,l)}}},FunctionDeclaration:function(i){a(!1,i,i.params)},ArrowFunctionExpression(i){a(!1,i,i.params)}}}}),lt={name:Gt,rule:Mr};var pe=require("@typescript-eslint/utils"),$r=pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qt="prefer-named-functions",Zt=new Map,Ur=$r({name:Qt,meta:{hasSuggestions:!0,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:{suggestion:"Convert to named function",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,[t]){let n=null;if(t.ignoreRegex){let r=Zt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),Zt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===pe.AST_NODE_TYPES.ArrowFunctionExpression&&r.id.type===pe.AST_NODE_TYPES.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==pe.AST_NODE_TYPES.BlockStatement)return;let a=r.parent,u=r.init.params,i=r.init.body,o=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:l=>l.replaceText(a,`${o.async?"async ":""}function ${s}(${u.map(c=>e.sourceCode.getText(c)).join(", ")||""}) ${e.sourceCode.getText(i)}`)}]})}}}}}),ct={name:Qt,rule:Ur};var H=require("@typescript-eslint/utils");var Vr=H.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),tn="prefer-single-line-if",Wr=_({maxLineLength:F(G()),maxNonSimpleConditionLength:F(G())}),Hr=Vr({name:tn,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[Wr]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==H.AST_NODE_TYPES.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let a=r.consequent.body[0];if(a.type===H.AST_NODE_TYPES.ReturnStatement){if(!rn(a))return}else if(!(a.type===H.AST_NODE_TYPES.ContinueStatement||a.type===H.AST_NODE_TYPES.BreakStatement))return;if(r.test.type===H.AST_NODE_TYPES.LogicalExpression||r.test.type===H.AST_NODE_TYPES.ConditionalExpression)return;let u;if(t.maxNonSimpleConditionLength){let f=en(r.test);if(!f&&r.test.type===H.AST_NODE_TYPES.UnaryExpression&&r.test.operator==="!"){let h=r.test.argument;en(h)&&(f=!0)}if(f&&(u=n.getText(r.test),u.length>t.maxNonSimpleConditionLength))return}u||(u=n.getText(r.test));let i=n.getText(a);if(u.includes(`
|
|
15
|
-
`))return;let o=n.getTokenAfter(r);if(o&&o.type===H.AST_TOKEN_TYPES.Punctuator&&o.value==="}"){let f=n.getTokenAfter(o);if(f&&f.type===H.AST_TOKEN_TYPES.Keyword&&(f.value==="else"||f.value==="catch"))return}let l=Yr(n,r),c=`if (${u}) ${i}`;t.maxLineLength&&c.length+l.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:f=>f.replaceText(r,c)})}}}});function en(e){return e.type===H.AST_NODE_TYPES.CallExpression||e.type===H.AST_NODE_TYPES.BinaryExpression||e.type===H.AST_NODE_TYPES.MemberExpression&&nn(e)}function nn(e){return e.object.type===H.AST_NODE_TYPES.MemberExpression?nn(e.object):e.object.type!==H.AST_NODE_TYPES.Identifier}function Yr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function rn(e){if(!e.argument)return!0;let t=e.argument;return t.type===H.AST_NODE_TYPES.ArrayExpression&&t.elements.length===0||t.type===H.AST_NODE_TYPES.ObjectExpression&&t.properties.length===0||t.type===H.AST_NODE_TYPES.Literal||t.type===H.AST_NODE_TYPES.Identifier||t.type===H.AST_NODE_TYPES.TemplateLiteral||t.type===H.AST_NODE_TYPES.TaggedTemplateExpression?!0:t.type===H.AST_NODE_TYPES.CallExpression?t.arguments.length===0:t.type===H.AST_NODE_TYPES.UnaryExpression?rn(t):!1}var ut={name:tn,rule:Hr};var K=require("@typescript-eslint/utils");var zr=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),sn="react-compiler-migration",Br=_({disallowHooks:F(Y(_({name:N(),replacement:N()}))),disallowMethods:F(Y(_({name:N(),replacement:F(N()),requireTrueProp:F(N())})))}),qr=/eslint +react-compiler\/react-compiler: +\["error/;function Kr(e){return e.type===K.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===K.AST_NODE_TYPES.MemberExpression&&e.property.type===K.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var Xr=zr({name:sn,meta:{type:"suggestion",fixable:"code",docs:{description:"Rules to help migrate to the new React compiler"},messages:{disallowedFunctionOrMethod:"{{functionOrMethod}} is not supported in react compiler. Use {{replacement}} instead.",replace:"Replace with safe alternative {{replacement}}",disallowedMethodWithMissingRequireTrueProp:"{{method}} is should have a prop named {{requireTrueProp}} set to true when used in react compiler."},hasSuggestions:!0,schema:[Br]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(qr.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let s=null,a=null;if(r.callee.type===K.AST_NODE_TYPES.Identifier?(s=r.callee.name,a=r.callee):r.callee.type===K.AST_NODE_TYPES.MemberExpression&&r.callee.property.type===K.AST_NODE_TYPES.Identifier&&(s=r.callee.property.name,a=r.callee.property),s){let u=t.disallowHooks.find(i=>i.name===s);u&&a&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:u.name,replacement:u.replacement},suggest:[{messageId:"replace",data:{replacement:u.replacement},fix:i=>i.replaceText(a,u.replacement)}]})}}if(t.disallowMethods?.length&&Kr(r.callee)){for(let s of r.arguments)if(s.type===K.AST_NODE_TYPES.ObjectExpression){for(let a of s.properties)if(a.type===K.AST_NODE_TYPES.Property&&a.key.type===K.AST_NODE_TYPES.Identifier){let u=a.key.name,i=t.disallowMethods.find(o=>o.name===u);if(i){if(i.requireTrueProp){let o=i.requireTrueProp,l=!1;for(let c of s.properties)if(c.type===K.AST_NODE_TYPES.Property&&c.key.type===K.AST_NODE_TYPES.Identifier&&c.key.name===o&&c.value.type===K.AST_NODE_TYPES.Literal&&c.value.value===!0){l=!0;break}if(!l){e.report({node:a,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:i.name,requireTrueProp:o}});continue}}i.replacement&&e.report({node:a,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:i.name,replacement:i.replacement},suggest:[{messageId:"replace",data:{replacement:i.replacement},fix:o=>o.replaceText(a.key,i.replacement)}]})}}}}}}:{}}}),pt={name:sn,rule:Xr};var ke=require("@typescript-eslint/utils"),Jr=ke.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),on="require-description",Gr=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Zr=/^eslint-disable-(next-)?line$/u,Qr=Jr({name:on,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,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let a=ei(s);a!=null&&(r.has(a.kind)||a.description||e.report({loc:ni(s.loc),messageId:"missingDescription"}))}}}}}),an={name:on,rule:Qr};function ei(e){let{text:t,description:n}=ti(e.value);if(!t)return null;let r=Gr.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let a=Zr.test(s);if(e.type===ke.TSESTree.AST_TOKEN_TYPES.Line&&!a||a&&e.loc.start.line!==e.loc.end.line)return null;let u=t.slice(r.index+s.length);return{kind:s,value:u.trim(),description:n}}function ti(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function ni(e){return{start:{line:e.start.line,column:-1},end:e.end}}function un(e){return/^use[A-Z0-9]/.test(e)}function Ae(e){return e.type==="Identifier"?un(e.name):e.type==="MemberExpression"&&!e.computed&&Ae(e.property)?e.object.type==="Identifier":!1}function pn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function fn(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function mn(e){return!!(e.parent&&e.parent.callee&&fn(e.parent.callee,"forwardRef"))}function dn(e){return!!(e.parent&&e.parent.callee&&fn(e.parent.callee,"memo"))}function ft(e){for(;e;){let t=gn(e);if(t&&(pn(t)||Ae(t))||mn(e)||dn(e))return!0;e=e.parent}return!1}function ln(e){return!1}function mt(e){return!1}var ri=/eslint +react-compiler\/react-compiler: +\["error/,yn={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 o of e.sourceCode.getAllComments())if(ri.test(o.value))return{CallExpression(l){let c=null;l.callee.name==="useMemo"?c="useMemo":l.callee.name==="useCallback"&&(c="useCallback"),c&&e.report({node:l,message:`"${c}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?o=>t(o):o=>e.sourceCode.getText(o),n=typeof e.getScope=="function"?()=>n():o=>e.sourceCode.getScope(o),r=null,s=[],a=[],u=new WeakSet;function i(o){for(let l of o.references){let c=l.identifier.parent;if(c.type==="VariableDeclarator"&&c.init&&c.init.type==="CallExpression"&&c.init.callee&&ln(c.init.callee))for(let f of l.resolved.references)f!==l&&u.add(f.identifier)}}return{onCodePathSegmentStart:o=>a.push(o),onCodePathSegmentEnd:()=>a.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(o,l){let c=s.pop();if(c.size===0)return;let f=new Set;function h(S,v){let{cache:A}=h,L=A.get(S.id),j=new Set(v);if(j.has(S.id)){let R=[...j],U=R.slice(R.indexOf(S.id)+1);for(let B of U)f.add(B);return BigInt("0")}if(j.add(S.id),L!==void 0)return L;if(o.thrownSegments.includes(S))L=BigInt("0");else if(S.prevSegments.length===0)L=BigInt("1");else{L=BigInt("0");for(let R of S.prevSegments)L+=h(R,j)}return S.reachable&&L===BigInt("0")?A.delete(S.id):A.set(S.id,L),L}function m(S,v){let{cache:A}=m,L=A.get(S.id),j=new Set(v);if(j.has(S.id)){let R=Array.from(j),U=R.slice(R.indexOf(S.id)+1);for(let B of U)f.add(B);return BigInt("0")}if(j.add(S.id),L!==void 0)return L;if(o.thrownSegments.includes(S))L=BigInt("0");else if(S.nextSegments.length===0)L=BigInt("1");else{L=BigInt("0");for(let R of S.nextSegments)L+=m(R,j)}return A.set(S.id,L),L}function y(S){let{cache:v}=y,A=v.get(S.id);if(A===null)return 1/0;if(A!==void 0)return A;if(v.set(S.id,null),S.prevSegments.length===0)A=1;else{A=1/0;for(let L of S.prevSegments){let j=y(L);j<A&&(A=j)}A+=1}return v.set(S.id,A),A}h.cache=new Map,m.cache=new Map,y.cache=new Map;let T=m(o.initialSegment),E=gn(l),g=ft(l),O=E?pn(E)||Ae(E):mn(l)||dn(l),C=1/0;for(let S of o.finalSegments){if(!S.reachable)continue;let v=y(S);v<C&&(C=v)}for(let[S,v]of c){if(!S.reachable)continue;let A=S.nextSegments.length===0?C<=y(S):C<y(S),L=h(S)*m(S),j=f.has(S.id);for(let R of v)if(j&&!mt(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.`}),O){if(l.async&&e.report({node:R,message:`React Hook "${t(R)}" cannot be called in an async function.`}),!j&&L!==T&&!mt(R)){let B=`React Hook "${t(R)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(A?" Did you accidentally call a React Hook after an early return?":"");e.report({node:R,message:B})}}else if(l.parent&&(l.parent.type==="MethodDefinition"||l.parent.type==="ClassProperty")&&l.parent.value===l){let U=`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:U})}else if(E){let U=`React Hook "${t(R)}" is called in function "${t(E)}" 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:U})}else if(l.type==="Program"){let U=`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:U})}else if(g&&!mt(R)){if(l.parent.type==="CallExpression"&&l.parent.callee.type==="Identifier"&&l.parent.callee.name==="useCallback"){let B=l.parent;if(B.parent.type==="VariableDeclarator"&&un(B.parent.id.name))return}let U=`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:U})}}},CallExpression(o){if(Ae(o.callee)){let l=cn(s),c=cn(a),f=l.get(c);f||(f=[],l.set(c,f)),f.push(o.callee)}o.callee.type==="Identifier"&&(o.callee.name==="useEffect"||ln(o.callee))&&o.arguments.length>0&&(r=o)},Identifier(o){r==null&&u.has(o)&&o.parent.type!=="CallExpression"&&e.report({node:o,message:`\`${t(o)}\` 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"(o){o===r&&(r=null)},FunctionDeclaration(o){ft(o)&&i(n(o))},ArrowFunctionExpression(o){ft(o)&&i(n(o))}}}};function gn(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 cn(e){return e[e.length-1]}var Sn={[lt.name]:lt.rule,[Ke.name]:Ke.rule,[qe.name]:qe.rule,"rules-of-hooks":yn,"exhaustive-deps":kt,"require-description":an.rule,[Xe.name]:Xe.rule,[Ge.name]:Ge.rule,[ct.name]:ct.rule,[$e.name]:$e.rule,[Be.name]:Be.rule,[nt.name]:nt.rule,[ut.name]:ut.rule,[tt.name]:tt.rule,[Je.name]:Je.rule,[Ve.name]:Ve.rule,[pt.name]:pt.rule,[Me.name]:Me.rule,[ze.name]:ze.rule,[it.name]:it.rule,[st.name]:st.rule,[ot.name]:ot.rule};var ii={rules:Sn};0&&(module.exports={extendedLintPlugin});
|
|
14
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let N=l.acquire(g),L=new Set,M=null;{let u=N.upper;for(;u&&(L.add(u),u.type!=="function");)u=u.upper;if(!u)return;M=u}let R=Array.isArray;function V(u){if(!R(u.defs))return!1;let d=u.defs[0];if(d==null||d.node.type!=="VariableDeclarator")return!1;let b=d.node.init;if(b==null)return!1;for(;b.type==="TSAsExpression";)b=b.expression;let x=d.node.parent;if(x==null&&(qe(M.block,d.node.id),x=d.node.parent,x==null))return!1;if(x.kind==="const"&&b.type==="Literal"&&(typeof b.value=="string"||typeof b.value=="number"||b.value===null))return!0;if(b.type!=="CallExpression")return!1;let w=b.callee;if(w.type==="MemberExpression"&&w.object.name==="React"&&w.property!=null&&!w.computed&&(w=w.property),w.type!=="Identifier")return!1;let C=d.node.id,{name:P}=w;if(P==="useRef"&&C.type==="Identifier")return!0;if(ar(w)&&C.type==="Identifier"){for(let D of u.references)D!==C&&m.add(D.identifier);return!0}else if(P==="useState"||P==="useReducer"){if(C.type==="ArrayPattern"&&C.elements.length===2&&R(u.identifiers)){if(C.elements[1]===u.identifiers[0]){if(P==="useState"){let D=u.references,Z=0;for(let ne=0;ne<D.length;ne++){if(D[ne].isWrite()&&Z++,Z>1)return!1;c.set(D[ne].identifier,C.elements[0])}}return!0}else if(C.elements[0]===u.identifiers[0]){if(P==="useState"){let D=u.references;for(let Z=0;Z<D.length;Z++)p.add(D[Z].identifier)}return!1}}}else if(P==="useTransition"&&C.type==="ArrayPattern"&&C.elements.length===2&&Array.isArray(u.identifiers)&&C.elements[1]===u.identifiers[0])return!0;return!1}function q(u){if(!R(u.defs))return!1;let d=u.defs[0];if(d==null||d.node==null||d.node.id==null)return!1;let b=d.node,x=M.childScopes,w=null,C;for(C=0;C<x.length;C++){let P=x[C],D=P.block;if(b.type==="FunctionDeclaration"&&D===b||b.type==="VariableDeclarator"&&D.parent===b){w=P;break}}if(w==null)return!1;for(C=0;C<w.through.length;C++){let P=w.through[C];if(P.resolved!=null&&L.has(P.resolved.scope)&&!Te(P.resolved))return!1}return!0}let Te=y(V,f),On=y(q,h),Et=new Map;function An(u){let d=u.from,b=!1;for(;d.block!==g;)d.type==="function"&&(b=d.block.parent!=null&&d.block.parent.type==="ReturnStatement"),d=d.upper;return b}let G=new Map,De=new Map;bt(N);function bt(u){for(let d of u.references){if(!d.resolved||!L.has(d.resolved.scope))continue;let b=qe(g,d.identifier),x=Lt(b),w=re(x,De);if(k&&x.type==="Identifier"&&(x.parent.type==="MemberExpression"||x.parent.type==="OptionalMemberExpression")&&!x.parent.computed&&x.parent.property.type==="Identifier"&&x.parent.property.name==="current"&&An(d)&&Et.set(w,{reference:d,dependencyNode:x}),x.parent.type==="TSTypeQuery"||x.parent.type==="TSTypeReference")continue;let C=d.resolved.defs[0];if(C!=null&&!(C.node!=null&&C.node.init===g.parent)&&C.type!=="TypeParameter")if(G.has(w))G.get(w).references.push(d);else{let P=d.resolved,D=Te(P)||On(P);G.set(w,{isStable:D,references:[d]})}}for(let d of u.childScopes)bt(d)}Et.forEach(({reference:u,dependencyNode:d},b)=>{let x=u.resolved.references,w=!1;for(let C=0;C<x.length;C++){let{identifier:P}=x[C],{parent:D}=P;if(D!=null&&D.type==="MemberExpression"&&!D.computed&&D.property.type==="Identifier"&&D.property.name==="current"&&D.parent.type==="AssignmentExpression"&&D.parent.left===D){w=!0;break}}w||i({node:d.parent.property,message:`The ref value '${b}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${b}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let je=new Set;function Pn(u,d){je.has(d)||(je.add(d),i({node:u,message:`Assignments to the '${d}' variable from inside React Hook ${n(I)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(I)}.`}))}let he=new Set;if(G.forEach(({isStable:u,references:d},b)=>{u&&he.add(b),d.forEach(x=>{x.writeExpr&&Pn(x.writeExpr,b)})}),je.size>0)return;if(!v){let u=null;if(G.forEach(({isStable:d,references:b},x)=>{u||b.forEach(w=>{if(u)return;let C=w.identifier;if(!c.has(C))return;let D=w.from;for(;D.type!=="function";)D=D.upper;D.block===g&&(u=x)})}),u){let{suggestedDependencies:d}=ze({dependencies:G,declaredDependencies:[],stableDependencies:he,externalDependencies:new Set,isEffect:!0});i({node:I,message:`React Hook ${S} contains a call to '${u}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+d.join(", ")+`] as a second argument to the ${S} Hook.`,suggest:[{desc:`Add dependencies array: [${d.join(", ")}]`,fix(b){return b.insertTextAfter(g,`, [${d.join(", ")}]`)}}]})}return}let ye=[],ge=new Set;v.type!=="ArrayExpression"?i({node:v,message:`React Hook ${n(I)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):v.elements.forEach(u=>{if(u===null)return;if(u.type==="SpreadElement"){i({node:u,message:`React Hook ${n(I)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}m.has(u)&&i({node:u,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(u)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(u)}\``,fix(w){return w.removeRange(u.range)}}]});let d;try{d=re(u,De)}catch(w){if(/Unsupported node type/.test(w.message)){u.type==="Literal"?G.has(u.value)?i({node:u,message:`The ${u.raw} literal is not a valid dependency because it never changes. Did you mean to include ${u.value} in the array instead?`}):i({node:u,message:`The ${u.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):i({node:u,message:`React Hook ${n(I)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw w}let b=u;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let x=!M.through.some(w=>w.identifier===b);ye.push({key:d,node:u}),x||ge.add(d)});let{suggestedDependencies:Fn,unnecessaryDependencies:Ee,missingDependencies:oe,duplicateDependencies:xt}=ze({dependencies:G,declaredDependencies:ye,stableDependencies:he,externalDependencies:ge,isEffect:k}),be=Fn;if(xt.size+oe.size+Ee.size===0){if(t)return;rr({declaredDependencies:ye,declaredDependenciesNode:v,componentScope:M,scope:N}).forEach(({construction:d,isUsedOutsideOfHook:b,depType:x})=>{let w=x==="function"?"useCallback":"useMemo",C=x==="function"?"definition":"initialization",P=`wrap the ${C} of '${d.name.name}' in its own ${w}() Hook.`,D=b?`To fix this, ${P}`:`Move it inside the ${S} callback. Alternatively, ${P}`,Z=x==="conditional"||x==="logical expression"?"could make":"makes",ne=`The '${d.name.name}' ${x} ${Z} the dependencies of ${S} Hook (at line ${v.loc.start.line}) change on every render. ${D}`,It;b&&d.type==="Variable"&&x==="function"&&(It=[{desc:`Wrap the ${C} of '${d.name.name}' in its own ${w}() Hook.`,fix(Ct){let[Dn,jn]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Ct.insertTextBefore(d.node.init,Dn),Ct.insertTextAfter(d.node.init,jn)]}}]),i({node:d.node,message:ne,suggest:It})});return}!k&&oe.size>0&&(be=ze({dependencies:G,declaredDependencies:[],stableDependencies:he,externalDependencies:ge,isEffect:k}).suggestedDependencies);function Nn(){if(ye.length===0)return!0;let u=ye.map(b=>b.key),d=u.slice().sort();return u.join(",")===d.join(",")}Nn()&&be.sort();function Le(u){let d=u.split("."),b="";for(let x=0;x<d.length;x++){if(x!==0){let w=d.slice(0,x+1).join("."),C=De.get(w)===!0;b+=C?"?.":"."}b+=d[x]}return b}function _e(u,d,b,x){return u.size===0?null:(u.size>1?"":d+" ")+b+" "+(u.size>1?"dependencies":"dependency")+": "+sr(Array.from(u).sort().map(w=>"'"+Le(w)+"'"))+`. Either ${x} ${u.size>1?"them":"it"} or remove the dependency array.`}let te="";if(Ee.size>0){let u=null;if(Array.from(Ee.keys()).forEach(d=>{u===null&&d.endsWith(".current")&&(u=d)}),u!==null)te=` Mutable values like '${u}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(ge.size>0){let d=Array.from(ge)[0];N.set.has(d)||(te=` Outer scope values like '${d}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!te&&oe.has("props")){let u=G.get("props");if(u==null)return;let d=u.references;if(!Array.isArray(d))return;let b=!0;for(let x=0;x<d.length;x++){let w=d[x],C=qe(M.block,w.identifier);if(!C){b=!1;break}let P=C.parent;if(P==null){b=!1;break}if(P.type!=="MemberExpression"&&P.type!=="OptionalMemberExpression"){b=!1;break}}b&&(te=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${S} call and refer to those specific props inside ${n(I)}.`)}if(!te&&oe.size>0){let u=null;oe.forEach(d=>{if(u)return;let b=M.set.get(d),x=G.get(d);if(x.references[0].resolved!==b)return;let w=b.defs[0];if(w==null||w.name==null||w.type!=="Parameter")return;let C=!1,P;for(let D=0;D<x.references.length;D++)if(P=x.references[D].identifier,P!=null&&P.parent!=null&&(P.parent.type==="CallExpression"||P.parent.type==="OptionalCallExpression")&&P.parent.callee===P){C=!0;break}C&&(u=d)}),u!==null&&(te=` If '${u}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!te&&oe.size>0){let u=null;if(oe.forEach(d=>{if(u!==null)return;let x=G.get(d).references,w,C;for(let P=0;P<x.length;P++){for(w=x[P].identifier,C=w.parent;C!=null&&C!==M.block;){if(C.type==="CallExpression"){let D=c.get(C.callee);if(D!=null){if(D.name===d)u={missingDep:d,setter:C.callee.name,form:"updater"};else if(p.has(w))u={missingDep:d,setter:C.callee.name,form:"reducer"};else{let Z=x[P].resolved;if(Z!=null){let ne=Z.defs[0];ne!=null&&ne.type==="Parameter"&&(u={missingDep:d,setter:C.callee.name,form:"inlineReducer"})}}break}}C=C.parent}if(u!==null)break}}),u!==null)switch(u.form){case"reducer":te=` You can also replace multiple useState variables with useReducer if '${u.setter}' needs the current value of '${u.missingDep}'.`;break;case"inlineReducer":te=` If '${u.setter}' needs the current value of '${u.missingDep}', you can also switch to useReducer instead of useState and read '${u.missingDep}' in the reducer.`;break;case"updater":te=` You can also do a functional update '${u.setter}(${u.missingDep.slice(0,1)} => ...)' if you only need '${u.missingDep}' in the '${u.setter}' call.`;break;default:throw new Error("Unknown case.")}}i({node:v,message:`React Hook ${n(I)} has `+(_e(oe,"a","missing","include")||_e(Ee,"an","unnecessary","exclude")||_e(xt,"a","duplicate","omit"))+te,suggest:[{desc:`Update the dependencies array to be: [${be.map(Le).join(", ")}]`,fix(u){return u.replaceText(v,`[${be.map(Le).join(", ")}]`)}}]})}function E(g){let v=ir(g.callee,o);if(v===-1)return;let I=g.arguments[v],S=g.callee,k=_t(S).name,N=g.arguments[v+1],L=/Effect($|[^a-z])/g.test(k);if(!I){i({node:S,message:`React Hook ${k} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!L)){if(!N&&!L){(k==="useMemo"||k==="useCallback")&&i({node:S,message:`React Hook ${k} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(I.type){case"FunctionExpression":case"ArrowFunctionExpression":T(I,N,S,k,L);return;case"Identifier":if(!N||N.elements&&N.elements.some(V=>V&&V.type==="Identifier"&&V.name===I.name))return;let M=r(g).set.get(I.name);if(M==null||M.defs==null)return;let R=M.defs[0];if(!R||!R.node||R.type!=="Variable"&&R.type!=="FunctionName")break;switch(R.node.type){case"FunctionDeclaration":T(R.node,N,S,k,L);return;case"VariableDeclarator":let V=R.node.init;if(!V)break;switch(V.type){case"ArrowFunctionExpression":case"FunctionExpression":T(V,N,S,k,L);return}break}break;default:i({node:S,message:`React Hook ${k} received a function whose dependencies are unknown. Pass an inline function instead.`});return}i({node:S,message:`React Hook ${k} has a missing dependency: '${I.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${I.name}]`,fix(M){return M.replaceText(N,`[${I.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(nr.test(g.value))return t=!0,{CallExpression:v=>E(v,!0)}}return{CallExpression:g=>E(g)}}};function ze({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:s}){let a=o();function o(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,E)=>{let g=i(a,E);g.isUsed=!0,l(a,E,v=>{v.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let E=i(a,T);E.isSatisfiedRecursively=!0}),n.forEach(T=>{let E=i(a,T);E.isSatisfiedRecursively=!0});function i(T,E){let g=E.split("."),v=T;for(let I of g){let S=v.children.get(I);S||(S=o(),v.children.set(I,S)),v=S}return v}function l(T,E,g){let v=E.split("."),I=T;for(let S of v){let k=I.children.get(S);if(!k)return;g(k),I=k}}let c=new Set,p=new Set;f(a,c,p,T=>T);function f(T,E,g,v){T.children.forEach((I,S)=>{let k=v(S);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&g.add(k);return}if(I.isUsed){E.add(k);return}f(I,E,g,N=>k+"."+N)})}let h=[],m=new Set,y=new Set;return t.forEach(({key:T})=>{p.has(T)?h.indexOf(T)===-1?h.push(T):y.add(T):m.add(T)}),c.forEach(T=>{h.push(T)}),{suggestedDependencies:h,unnecessaryDependencies:m,duplicateDependencies:y,missingDependencies:c}}function le(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 le(e.consequent)!=null||le(e.alternate)!=null?"conditional":null;case"LogicalExpression":return le(e.left)!=null||le(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return le(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return le(e.expression);case"TSAsExpression":return le(e.expression)}return null}function rr({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let s=e.map(({key:o})=>{let i=n.variables.find(c=>c.name===o);if(i==null)return null;let l=i.defs[0];if(l==null)return null;if(l.type==="Variable"&&l.node.type==="VariableDeclarator"&&l.node.id.type==="Identifier"&&l.node.init!=null){let c=le(l.node.init);if(c!=null)return[i,c]}return l.type==="FunctionName"&&l.node.type==="FunctionDeclaration"?[i,"function"]:l.type==="ClassName"&&l.node.type==="ClassDeclaration"?[i,"class"]:null}).filter(Boolean);function a(o){let i=!1;for(let l=0;l<o.references.length;l++){let c=o.references[l];if(c.writeExpr){if(i)return!0;i=!0;continue}let p=c.from;for(;p!==r&&p!=null;)p=p.upper;if(p!==r&&!Mt(t,c.identifier))return!0}return!1}return s.map(([o,i])=>({construction:o.defs[0],depType:i,isUsedOutsideOfHook:a(o)}))}function Lt(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)?Lt(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function Be(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function re(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=re(e.object,t),r=re(e.property,null),s=`${n}.${r}`;return Be(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=re(e.object,t),r=re(e.property,null),s=`${n}.${r}`;return Be(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=re(n.object,t),s=re(n.property,null),a=`${r}.${s}`;return Be(n,t,a),a}else throw new Error(`Unsupported node type: ${e.type}`)}function _t(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function ir(e,t){let n=_t(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 r;try{r=re(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(r)?0:-1}else return-1}}function qe(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),or(r,t))return r;if(Mt(r,t))for(let[s,a]of Object.entries(r))s!=="parent"&&(Dt(a)?(a.parent=r,n.push(a)):Array.isArray(a)&&a.forEach(o=>{Dt(o)&&(o.parent=r,n.push(o))}))}return null}function sr(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 Dt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function or(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 Mt(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function ar(e){return!1}var ce=require("@typescript-eslint/utils");var X=Me(require("typescript")),lr=ce.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="improved-no-unnecessary-condition",cr=j({}),pr=["string","number","bigint","boolean","symbol","undefined","object","function","never"],ur=new Set(pr),Xe={name:$t,rule:lr({name:$t,meta:{type:"suggestion",docs:{description:"Extends checks of `no-unnecessary-condition` rule"},messages:{unnecessaryTypeofCondition:'This condition is unnecessary. The type of "{{name}}" is always "{{type}}".',alwaysFalseTypeofCondition:'This condition will always be false. The type of "{{name}}" is "{{actualType}}" so the condition has no overlap with "{{conditionType}}".'},schema:[cr]},defaultOptions:[{}],create(e){let t=ce.ESLintUtils.getParserServices(e,!0),n=t.program?.getTypeChecker();if(!n||!t.program)throw new Error("TypeScript services or program not available");function r(i){return i.type===ce.AST_NODE_TYPES.UnaryExpression&&i.operator==="typeof"}function s(i){return i.flags&X.default.TypeFlags.Any||i.flags&X.default.TypeFlags.Unknown?null:i.flags&X.default.TypeFlags.StringLike?["string"]:i.flags&X.default.TypeFlags.NumberLike?["number"]:i.flags&X.default.TypeFlags.BigIntLike?["bigint"]:i.flags&X.default.TypeFlags.BooleanLike?["boolean"]:i.flags&X.default.TypeFlags.ESSymbolLike?["symbol"]:i.flags&X.default.TypeFlags.Undefined||i.flags&X.default.TypeFlags.Void?["undefined"]:i.flags&X.default.TypeFlags.Null?["object"]:i.getCallSignatures().length>0?["function"]:i.flags&X.default.TypeFlags.Object?i.getProperties().length===0?["string","number","bigint","boolean","symbol","object","function"]:["object"]:i.flags&X.default.TypeFlags.NonPrimitive?["object"]:i.flags&X.default.TypeFlags.Never?["never"]:null}function a(i){if(!n)return null;let l=t.esTreeNodeToTSNodeMap.get(i),c=n.getTypeAtLocation(l.expression);if(c.flags&X.default.TypeFlags.Any||c.flags&X.default.TypeFlags.Unknown)return null;let p=[];if(c.isUnion()){for(let h of c.types){let m=s(h);if(m)p.push(...m);else return null}return p}let f=s(c);return f?(p.push(...f),p):null}function o(i){if(!(i.operator==="==="||i.operator==="!=="))return;let c=null,p=null;if(r(i.left)?(c=i.left,p=i.right.type===ce.AST_NODE_TYPES.Literal&&typeof i.right.value=="string"?i.right.value:null):r(i.right)&&(c=i.right,p=i.left.type===ce.AST_NODE_TYPES.Literal&&typeof i.left.value=="string"?i.left.value:null),!c||!p||!fr(p,ur))return;let f=a(c);if(!f)return;let h=i.operator==="!==",m=f.includes(p);f.length===1?m&&!h?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:p}}):!m&&h?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:Array.from(f)[0]}}):!m&&!h?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(f),conditionType:p}}):m&&h&&e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(f),conditionType:p}}):!m&&!h?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(f),conditionType:p}}):!m&&h&&e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:we(f)}})}return{BinaryExpression:o}}})};function we(e){return Array.from(new Set(e)).join(" | ")||"never"}function fe(e,t){let n=e.argument;return n.type===ce.AST_NODE_TYPES.Identifier?n.name:t.sourceCode.getText(n)}function fr(e,t){return t.has(e)}var Re=require("@typescript-eslint/utils");var mr=Re.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ut="no-call-with-explicit-generics",dr=j({functions:z(A())}),yr=mr({name:Ut,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[dr]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:s}=r;s.type===Re.AST_NODE_TYPES.Identifier&&n.has(s.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),Ke={name:Ut,rule:yr};var pe=require("@typescript-eslint/utils"),gr=pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="no-call-with-inferred-generics",Sr=gr({name:Vt,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,[t]){let n=new Map(t.functions.map(r=>[r.name,r]));return{CallExpression(r){let{callee:s}=r;if(s.type!==pe.AST_NODE_TYPES.Identifier)return;let a=n.get(s.name);if(!a)return;let{minGenerics:o=1,allowAny:i,disallowTypes:l=t.disallowTypes}=a;(r.typeArguments?.params.length||0)<(o||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:o||0}}),!(i&&!l)&&r.typeArguments?.params?.some(p=>!i&&p.type===pe.AST_NODE_TYPES.TSAnyKeyword||l&&p.type===pe.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===pe.AST_NODE_TYPES.Identifier&&l.includes(p.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),Je={name:Vt,rule:Sr};var Se=require("@typescript-eslint/utils"),Tr=Se.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Wt="no-commented-out-code",hr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Er=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],br=Tr({name:Wt,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(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of hr)if(r.startsWith(s))return{wrongPattern:s};for(let s of Er)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let s of r)if(s.type===Se.TSESTree.AST_TOKEN_TYPES.Line||s.type===Se.TSESTree.AST_TOKEN_TYPES.Block){let a=t(s.value);a&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:a.wrongPattern}})}}}}}),Ge={name:Wt,rule:br};var ke=require("@typescript-eslint/utils"),xr=ke.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ht="no-default-export",Ir=xr({name:Ht,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.type===ke.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ze={name:Ht,rule:Ir};var Yt=require("@typescript-eslint/utils"),Cr=Yt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),zt="no-leaked-text-in-jsx",wr=[",",";","[","]","(",")"],Rr=Cr({name:zt,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";wr.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Qe={name:zt,rule:Rr};var ie=require("@typescript-eslint/utils"),kr=ie.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qt="no-non-camel-case-functions",vr=/^[a-z][a-zA-Z0-9]*$/;function Bt(e){return e.typeName.type===ie.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===ie.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===ie.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var Or=kr({name:qt,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&&!vr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ie.AST_NODE_TYPES.TSTypeReference?Bt(n):n.type===ie.AST_NODE_TYPES.TSUnionType&&n.types.some(s=>s.type===ie.AST_NODE_TYPES.TSTypeReference&&Bt(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),et={name:qt,rule:Or};var U=require("@typescript-eslint/utils");var tt=require("@typescript-eslint/utils");function me(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:me(e.parent,t,n===1/0?n:n-1)}function*nt(e){yield e,e.parent&&(yield*nt(e.parent))}function rt(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function Xt(e,t,n){let s=n.getDeclaredVariables(e).find(a=>a.name===t||a.identifiers[0]?.parent.type===tt.AST_NODE_TYPES.Property&&a.identifiers[0]?.parent.key.type===tt.AST_NODE_TYPES.Identifier&&a.identifiers[0]?.parent.key.name===t);return s?s.references.filter(a=>!a.init):[]}var Ar=U.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Kt="no-optional-root-props",Pr=Ar({name:Kt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let a=e.sourceCode.getDeclaredVariables(r)[0];if(!a||a.references.length!==1)return!1;let o=a.references[0];if(!o)return!1;for(let i of nt(o.identifier)){if("returnType"in i||i.type===U.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let l=i.parent;if(!l)return!1;if(l.type===U.TSESTree.AST_NODE_TYPES.TSTypeParameterInstantiation&&l.parent.type===U.TSESTree.AST_NODE_TYPES.TSTypeReference&&l.parent.typeName.type===U.TSESTree.AST_NODE_TYPES.Identifier&&l.parent.typeName.name==="FC"){let p=me(l.parent.parent,U.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!p)return!1;let f=ve(p,e.sourceCode);return f?!(f.parent.type===U.TSESTree.AST_NODE_TYPES.CallExpression&&f.parent.callee.type===U.TSESTree.AST_NODE_TYPES.Identifier&&f.parent.callee.name==="memo"):!1}if(i.type===U.TSESTree.AST_NODE_TYPES.AssignmentPattern)return!1;if(l.type===U.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression){let c=me(l,U.TSESTree.AST_NODE_TYPES.VariableDeclaration);return c?!!ve(c,e.sourceCode):!1}if(l.type===U.TSESTree.AST_NODE_TYPES.FunctionDeclaration)return!!ve(l,e.sourceCode)}return!1}function n(r){r.key.type!==U.TSESTree.AST_NODE_TYPES.Identifier||!r.optional||e.report({node:r.key,messageId:"optionalNotAllowed",data:{propertyName:r.key.name},suggest:[{messageId:"suggestion",fix:s=>{let a=me(r,U.TSESTree.AST_NODE_TYPES.TSPropertySignature);if(!a)return null;let o=e.sourceCode.getText(a);return s.replaceText(a,o.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(r){if(r.typeAnnotation.type===U.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(Oe(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===U.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(Oe(r)||!t(r)))for(let s of r.body.body)s.type===U.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSTypeReference(r){if(r.typeName.type!==U.TSESTree.AST_NODE_TYPES.Identifier||r.typeName.name!=="FC"||!r.typeArguments?.params[0])return;let s=r.typeArguments.params[0];if(s.type!==U.TSESTree.AST_NODE_TYPES.TSTypeLiteral)return;let a=me(r.parent,U.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!a)return;let o=ve(a,e.sourceCode);if(!(!o||o.parent.type===U.TSESTree.AST_NODE_TYPES.CallExpression&&o.parent.callee.type===U.TSESTree.AST_NODE_TYPES.Identifier&&o.parent.callee.name==="memo"))for(let l of s.members)l.type===U.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(l)}}}});function Oe(e){return e?e.parent?.type===U.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===U.TSESTree.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function ve(e,t){if(Oe(e))return;let n;if(e.type===U.TSESTree.AST_NODE_TYPES.VariableDeclaration){if(e.declarations.length!==1)return;e.declarations[0].id.type===U.TSESTree.AST_NODE_TYPES.Identifier&&(n=e.declarations[0].id)}else{if(!e.id)return;n=e.id}if(!n)return;let r=t.getScope(e);e.type===U.TSESTree.AST_NODE_TYPES.FunctionDeclaration&&r.upper&&(r=r.upper);let s=r.variables.find(o=>o.identifiers.includes(n));if(!s)return;let a=s.references.filter(o=>o.identifier!==n);if(!(a.length!==1||!a[0])&&!Oe(a[0].identifier.parent.parent))return a[0].identifier}var it={name:Kt,rule:Pr};var Jt=require("@typescript-eslint/utils"),Ae=Me(require("path"));var Fr=Jt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Gt="no-relative-imports",Nr=j({find:A(),replacement:A()}),Dr=j({aliases:z(Nr),rootDir:O(A()),allowNotFoundAliases:O(ue()),_dev_simulateFileName:O(A())}),jr=Fr({name:Gt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[Dr]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(o){return o.startsWith(".")||o.startsWith("..")}function s(o,i){let l=Ae.default.dirname(i);return Ae.default.resolve(l,o)}function a(o){let i=t.rootDir??process.cwd(),l=Ae.default.relative(i,o);if(l.startsWith("."))return null;l.startsWith("/")||(l=`/${l}`);for(let{find:c,replacement:p}of t.aliases)if(l.startsWith(p)){let f=l.replace(p,c);return{alias:c,newPath:f}}return null}return{ImportDeclaration(o){let i=o.source.value;if(!r(i))return;let l=s(i,n),c=a(l);!c&&t.allowNotFoundAliases||e.report({node:o,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?p=>p.replaceText(o.source,`'${c.newPath}'`):void 0})}}}}),st={name:Gt,rule:jr};var se=require("@typescript-eslint/utils");var ot=Me(require("typescript")),Lr=se.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Zt="no-unnecessary-casting",_r=j({additionalCastFunctions:O(z(j({name:A(),expectedType:Ie(["string","number"])})))}),at={name:Zt,rule:Lr({name:Zt,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[_r],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=se.ESLintUtils.getParserServices(e,!0),a=s.program?.getTypeChecker();if(!a||!s.program)throw new Error("TypeScript services or program not available");function o(p,f){switch(p.type){case se.AST_NODE_TYPES.Literal:return f==="number"?typeof p.value=="number":typeof p.value=="string";case se.AST_NODE_TYPES.TemplateLiteral:return f==="string";case se.AST_NODE_TYPES.UnaryExpression:return f==="number"?p.operator==="+"||p.operator==="-"||p.operator==="~":!1;default:return!1}}function i(p,f){return f==="number"?!!(p.flags&ot.TypeFlags.NumberLike):!!(p.flags&ot.TypeFlags.StringLike)}function l(p,f){return h=>h.replaceText(p,e.sourceCode.getText(f))}function c(p){if(!a||p.arguments.length!==1)return;let f=p.arguments[0];if(!f||f.type===se.AST_NODE_TYPES.SpreadElement)return;let{callee:h}=p;if(h.type!==se.AST_NODE_TYPES.Identifier)return;let m=h.name,y=r.find(E=>E.name===m);if(!y)return;if(o(f,y.expectedType)||i(a.getTypeAtLocation(s.esTreeNodeToTSNodeMap.get(f)),y.expectedType)){let E,g;m==="Number"?E="unnecessaryNumberCasting":m==="String"?E="unnecessaryStringCasting":(E="unnecessaryCustomCasting",g={name:y.name,type:y.expectedType}),e.report({node:p,messageId:E,...g?{data:g}:{},fix:l(p,f)})}}return{CallExpression:c}}})};var J=require("@typescript-eslint/utils");var lt=ae({name:"no-unused-obj-props",meta:{type:"suggestion",docs:{description:"Disallow unused properties when it is safe to remove them"},messages:{unusedObjectProperty:'The object property "{{name}}" is not being used',unusedReturnObjectProperty:'The object property "{{name}}" returned by this function is not being used'},schema:[]},defaultOptions:[],create(e){return{VariableDeclarator(t){if(t.id.type===J.AST_NODE_TYPES.ObjectPattern||!t.init||t.init.type!==J.AST_NODE_TYPES.ObjectExpression||t.id.type===J.AST_NODE_TYPES.Identifier&&t.id.typeAnnotation||t.parent.parent.type===J.AST_NODE_TYPES.ExportNamedDeclaration)return;let n=new Map;for(let o of t.init.properties)o.type===J.AST_NODE_TYPES.Property&&o.key.type===J.AST_NODE_TYPES.Identifier&&n.set(o.key.name,o);if(n.size===0||t.id.type!==J.AST_NODE_TYPES.Identifier)return;let r=Mr(t,e.sourceCode);if(r.length===0)return;let s=t.init.properties.some(o=>o.type!==J.AST_NODE_TYPES.Property?!1:o.value.type===J.AST_NODE_TYPES.FunctionExpression),a=new Set;for(let o of r){if(o.identifier.parent.type!==J.AST_NODE_TYPES.MemberExpression)return;let i=o.identifier.parent;if(i.object!==o.identifier)return;if(i.computed)if(i.property.type===J.AST_NODE_TYPES.Literal&&typeof i.property.value=="string")a.add(i.property.value);else return;else{if(i.property.type!==J.AST_NODE_TYPES.Identifier)return;a.add(i.property.name)}if(i.parent.type===J.AST_NODE_TYPES.CallExpression&&s)return}for(let[o,i]of n)a.has(o)||e.report({node:i,messageId:"unusedObjectProperty",data:{name:o}})}}}});function Mr(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}var W=require("@typescript-eslint/utils");var $r=j({selectors:z(j({name:A(),selectorProp:O(A()),selectorArgPos:O(Q()),returnProp:O(A())}))}),Ur=W.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qt="no-unused-selected-values",ct={name:Qt,rule:Ur({name:Qt,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[$r]},defaultOptions:[{selectors:[]}],create(e,[t]){let{selectors:n=[]}=t,r=new Map(n.map(s=>[s.name,s]));return{VariableDeclarator(s){let a=null;if(s.init?.type===W.AST_NODE_TYPES.CallExpression&&(a=s.init),!a)return;let o=Wr(a);if(!o)return;let i=r.get(o);if(!i)return;let l=Vr(a,i.selectorArgPos??0,i.selectorProp);if(!l)return;let c=Hr(l);if(!c)return;let p=en(c.properties,void 0);if(!p)return;if(s.id.type===W.AST_NODE_TYPES.ObjectPattern){let m=en(s.id.properties,i.returnProp);if(!m)return;for(let[y,T]of p)m.has(y)||e.report({node:T,messageId:"unusedSelectedValue",data:{name:y}});return}if(s.id.type!==W.AST_NODE_TYPES.Identifier||i.returnProp)return;let f=Yr(s,e.sourceCode);if(f.length===0)return;let h=new Set;for(let m of f){if(m.identifier.parent.type!==W.AST_NODE_TYPES.MemberExpression)return;let y=m.identifier.parent.property;if(y.type!==W.AST_NODE_TYPES.Identifier)return;h.add(y.name)}for(let[m,y]of p)h.has(m)||e.report({node:y,messageId:"unusedSelectedValue",data:{name:m}})}}}})};function Vr(e,t,n){let r=e.arguments[t];if(!r)return null;if(r.type===W.AST_NODE_TYPES.ArrowFunctionExpression||r.type===W.AST_NODE_TYPES.FunctionExpression)return r;if(n&&r.type===W.AST_NODE_TYPES.ObjectExpression){let s=r.properties.find(o=>o.type===W.AST_NODE_TYPES.Property&&o.key.type===W.AST_NODE_TYPES.Identifier&&o.key.name===n);if(s?.type!==W.AST_NODE_TYPES.Property)return null;let a=s.value;if(a.type===W.AST_NODE_TYPES.ArrowFunctionExpression||a.type===W.AST_NODE_TYPES.FunctionExpression)return a}return null}function Wr(e){return e.callee.type===W.AST_NODE_TYPES.Identifier?e.callee.name:e.callee.type===W.AST_NODE_TYPES.MemberExpression&&e.callee.property.type===W.AST_NODE_TYPES.Identifier?e.callee.property.name:null}function Hr(e){if(e.body.type===W.AST_NODE_TYPES.ObjectExpression)return e.body;if(e.body.type===W.AST_NODE_TYPES.BlockStatement){let t=e.body.body.filter(n=>n.type===W.AST_NODE_TYPES.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==W.AST_NODE_TYPES.ObjectExpression?null:t[0].argument}return null}function en(e,t){let n=e;if(t){let s=e.find(a=>a.type===W.AST_NODE_TYPES.Property&&a.key.type===W.AST_NODE_TYPES.Identifier&&a.key.name===t);if(s?.type!==W.AST_NODE_TYPES.Property||s.value.type!==W.AST_NODE_TYPES.ObjectPattern)return null;n=s.value.properties}let r=new Map;for(let s of n){if(s.type!==W.AST_NODE_TYPES.Property||s.key.type!==W.AST_NODE_TYPES.Identifier)return null;r.set(s.key.name,s)}return r.size>0?r:null}function Yr(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}var H=require("@typescript-eslint/utils");var pt=ae({name:"no-unused-t-state-field",meta:{type:"suggestion",docs:{description:"Prevent declaring unused t-state fields"},messages:{unusedField:'Field "{{name}}" is not being used, you can safely remove it'},schema:[]},defaultOptions:[],create(e){if(!(e.filename.endsWith(".jsx")||e.filename.endsWith(".tsx")))return{};if(!e.sourceCode.ast.body.some(a=>a.type===H.AST_NODE_TYPES.ImportDeclaration&&a.source.value==="t-state-form"))return{};let r=null,s=!1;return{CallExpression(a){if(s)return;if(!r){let i=zr(a);i&&(r=i);return}let o=Br(a,e.sourceCode);if(o){s=!0;for(let i of o)r.delete(i);if(r.size!==0)for(let[i,l]of r)e.report({node:l,messageId:"unusedField",data:{name:i}})}}}}});function zr(e){if(!(e.callee.type===H.AST_NODE_TYPES.Identifier&&e.callee.name==="useForm"))return null;let n=e.arguments[0];if(!n||n.type!==H.AST_NODE_TYPES.ObjectExpression)return null;let r=rt(n.properties,a=>a.type!==H.AST_NODE_TYPES.Property||a.key.type!==H.AST_NODE_TYPES.Identifier||a.key.name!=="initialConfig"?null:a.value.type===H.AST_NODE_TYPES.ObjectExpression?a.value:a.value.type===H.AST_NODE_TYPES.ArrowFunctionExpression||a.value.type===H.AST_NODE_TYPES.FunctionExpression?qr(a.value):null);if(!r)return null;let s=new Map;for(let a of r.properties)a.type===H.AST_NODE_TYPES.Property&&a.key.type===H.AST_NODE_TYPES.Identifier&&s.set(a.key.name,a);return s}function Br(e,t){if(!(e.callee.type===H.AST_NODE_TYPES.Identifier&&e.callee.name==="useFormState")||e.parent.type!==H.AST_NODE_TYPES.VariableDeclarator||e.parent.id.type!==H.AST_NODE_TYPES.ObjectPattern||!rt(e.parent.id.properties,o=>o.type===H.AST_NODE_TYPES.Property&&o.key.type===H.AST_NODE_TYPES.Identifier&&o.key.name==="formFields"&&o))return null;let s=Xt(e.parent,"formFields",t),a=new Set;for(let{identifier:o}of s){if(o.type!==H.AST_NODE_TYPES.Identifier||o.parent.type===H.AST_NODE_TYPES.Property&&o.parent.parent.type===H.AST_NODE_TYPES.ObjectExpression&&o.parent.parent.parent.type===H.AST_NODE_TYPES.ReturnStatement||o.parent.type===H.AST_NODE_TYPES.ReturnStatement)return null;if(o.parent.type===H.AST_NODE_TYPES.MemberExpression){if(o.parent.object.type!==H.AST_NODE_TYPES.Identifier||o.parent.property.type!==H.AST_NODE_TYPES.Identifier)return null;a.add(o.parent.property.name)}}return a}function qr(e){if(e.body.type===H.AST_NODE_TYPES.ObjectExpression)return e.body;if(e.body.type===H.AST_NODE_TYPES.BlockStatement){let t=e.body.body.filter(n=>n.type===H.AST_NODE_TYPES.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==H.AST_NODE_TYPES.ObjectExpression?null:t[0].argument}return null}var $=require("@typescript-eslint/utils");var Xr=$.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function tn(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 nn(e,...t){for(let n of t)e.set(...n);return e}var Kr=j({forceCheckOnFCPropTypesWithName:O(z(A()))}),rn="no-unused-type-props-in-args",ut=null,Jr=Xr({name:rn,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:[Kr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!ut&&(ut=n.map(i=>new RegExp(i)));function r(i,l,c,p,f=!0){let h=c.name,m=e.sourceCode.getScope(l).references.find(E=>E.identifier.name===h)?.resolved,y=i&&ut?.some(E=>E.test(h));if(!m||!y&&m.references.filter(E=>E.isTypeReference).length>1)return;let T=m?.defs[0]?.node;if(!(f&&T?.parent?.type===$.AST_NODE_TYPES.ExportNamedDeclaration)){if(T?.type===$.AST_NODE_TYPES.TSTypeAliasDeclaration){s(i,l,p,T.typeAnnotation,!0);return}if(T?.type===$.AST_NODE_TYPES.TSInterfaceDeclaration){s(i,l,p,T.body,!0);return}}}function s(i,l,c,p,f){if(p.type===$.AST_NODE_TYPES.TSInterfaceBody){for(let h of p.body)h.type===$.AST_NODE_TYPES.TSPropertySignature&&h.key.type===$.AST_NODE_TYPES.Identifier&&c.set(h.key.name,h);return}if(p.type===$.AST_NODE_TYPES.TSTypeLiteral){nn(c,...tn(p));return}if(p.type===$.AST_NODE_TYPES.TSIntersectionType){for(let h of p.types)s(i,l,c,h,!0);return}f||p.type===$.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===$.AST_NODE_TYPES.Identifier&&r(i,l,p.typeName,c)}function a(i,l,c){for(let p of c)if(p.type==="ObjectPattern"&&p.typeAnnotation){let f=new Map;if(s(i,l,f,p.typeAnnotation.typeAnnotation,!1),f.size===0)continue;o(p,f)}else p.type===$.AST_NODE_TYPES.AssignmentPattern&&p.left.type===$.AST_NODE_TYPES.ObjectPattern&&a(i,l,[p.left])}function o(i,l){let c=[];if(i.properties.at(-1)?.type===$.AST_NODE_TYPES.RestElement)return;for(let m of i.properties)m.type===$.AST_NODE_TYPES.Property&&m.key.type===$.AST_NODE_TYPES.Identifier&&c.push(m.key.name);let f=[],h=[];for(let[m,y]of l)c.includes(m)||(h.push(m),f.push({node:y,messageId:"unusedObjectTypeProperty",data:{propertyName:m}}));for(let[m,y]of f.entries())e.report({...y,fix:m===f.length-1?T=>{let E=i.properties.at(-1),g=h.join(", ");return E?E?.type===$.AST_NODE_TYPES.RestElement?null:T.insertTextAfter(E,`, ${g}`):T.insertTextBeforeRange([i.range[0]+1,i.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(i){let l=i.declarations[0];if(!l)return;let c=new Map,p=l.id.type===$.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===$.AST_NODE_TYPES.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===$.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(p){if(p.type===$.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===$.AST_NODE_TYPES.Identifier)r(!0,i,p.typeName,c,!1);else if(p.type===$.AST_NODE_TYPES.TSTypeLiteral)nn(c,...tn(p));else if(p.type===$.AST_NODE_TYPES.TSIntersectionType)for(let f of p.types)f.type===$.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===$.AST_NODE_TYPES.Identifier?r(!0,i,f.typeName,c,!1):s(!0,i,c,f,!0);if(c.size!==0&&l.init?.type===$.AST_NODE_TYPES.ArrowFunctionExpression){let f=l.init.params[0];if(!f){e.report({node:l.init,messageId:"missingComponentParam"});return}f.type===$.AST_NODE_TYPES.ObjectPattern&&o(f,c)}}},FunctionDeclaration:function(i){a(!1,i,i.params)},ArrowFunctionExpression(i){a(!1,i,i.params)}}}}),ft={name:rn,rule:Jr};var de=require("@typescript-eslint/utils"),Gr=de.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),on="prefer-named-functions",sn=new Map,Zr=Gr({name:on,meta:{hasSuggestions:!0,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:{suggestion:"Convert to named function",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,[t]){let n=null;if(t.ignoreRegex){let r=sn.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),sn.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===de.AST_NODE_TYPES.ArrowFunctionExpression&&r.id.type===de.AST_NODE_TYPES.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==de.AST_NODE_TYPES.BlockStatement)return;let a=r.parent,o=r.init.params,i=r.init.body,l=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(a,`${l.async?"async ":""}function ${s}(${o.map(p=>e.sourceCode.getText(p)).join(", ")||""}) ${e.sourceCode.getText(i)}`)}]})}}}}}),mt={name:on,rule:Zr};var F=require("@typescript-eslint/utils");var Qr=j({disallowedFunctions:z(j({name:A(),hookAlternative:O(A()),message:O(A()),allowUseInside:O(z(A()))}))});function Pe(e){return/^use[A-Z]/.test(e)}function an(e){return/^[A-Z]/.test(e)}function ei(e){return e.type===F.AST_NODE_TYPES.Identifier?Pe(e.name):e.type===F.AST_NODE_TYPES.MemberExpression&&e.property.type===F.AST_NODE_TYPES.Identifier?Pe(e.property.name):!1}function ln(e,t){return e.type===F.AST_NODE_TYPES.Identifier?e.name===t:e.type===F.AST_NODE_TYPES.MemberExpression&&e.object.type===F.AST_NODE_TYPES.Identifier&&e.property.type===F.AST_NODE_TYPES.Identifier?e.object.name==="React"&&e.property.name===t:!1}function cn(e){return!!(e.parent&&e.parent.type===F.AST_NODE_TYPES.CallExpression&&ln(e.parent.callee,"forwardRef"))}function pn(e){return!!(e.parent&&e.parent.type===F.AST_NODE_TYPES.CallExpression&&ln(e.parent.callee,"memo"))}function dt(e){if(e.type===F.AST_NODE_TYPES.FunctionDeclaration||e.type===F.AST_NODE_TYPES.FunctionExpression&&e.id)return e.id||void 0;if(e.type===F.AST_NODE_TYPES.FunctionExpression||e.type===F.AST_NODE_TYPES.ArrowFunctionExpression){if(e.parent.type===F.AST_NODE_TYPES.VariableDeclarator&&e.parent.init===e)return e.parent.id;if(e.parent.type===F.AST_NODE_TYPES.AssignmentExpression&&e.parent.right===e&&e.parent.operator==="=")return e.parent.left;if(e.parent.type===F.AST_NODE_TYPES.Property&&e.parent.value===e&&!e.parent.computed)return e.parent.key;if(e.parent.type===F.AST_NODE_TYPES.AssignmentPattern&&e.parent.right===e)return e.parent.left}}function ti(e){let t=e.parent,n=!1;for(;t;){if(t.type===F.AST_NODE_TYPES.FunctionDeclaration||t.type===F.AST_NODE_TYPES.FunctionExpression||t.type===F.AST_NODE_TYPES.ArrowFunctionExpression){let r=dt(t);if(r&&r.type===F.AST_NODE_TYPES.Identifier){if(an(r.name)||Pe(r.name))return!n;n=!0}else{if(cn(t)||pn(t))return!n;if(t.parent.type===F.AST_NODE_TYPES.CallExpression){let s=t.parent;ei(s.callee)||(n=!0)}else t.parent.type===F.AST_NODE_TYPES.JSXExpressionContainer||(n=!0)}}t=t.parent}return!1}function un(e){return e.callee.type===F.AST_NODE_TYPES.Identifier?e.callee.name:e.callee.type===F.AST_NODE_TYPES.MemberExpression&&e.callee.property.type===F.AST_NODE_TYPES.Identifier?e.callee.property.name:null}function ni(e,t){if(!t.length)return!1;let n=e.parent;for(;n;){if(n.type===F.AST_NODE_TYPES.FunctionDeclaration||n.type===F.AST_NODE_TYPES.FunctionExpression||n.type===F.AST_NODE_TYPES.ArrowFunctionExpression){let r=dt(n);if(r&&r.type===F.AST_NODE_TYPES.Identifier&&t.includes(r.name))return!0}else if(n.type===F.AST_NODE_TYPES.CallExpression){let r=un(n);if(r&&t.includes(r))return!0}n=n.parent}return!1}function ri(e,t){let n=!1,r=e.parent;for(;r;){if(r.type===F.AST_NODE_TYPES.FunctionDeclaration||r.type===F.AST_NODE_TYPES.FunctionExpression||r.type===F.AST_NODE_TYPES.ArrowFunctionExpression){let s=dt(r);if(s&&s.type===F.AST_NODE_TYPES.Identifier){if(an(s.name)||Pe(s.name)){n=!0;break}}else if(cn(r)||pn(r)){n=!0;break}}r=r.parent}return n?t.length===0?ti(e):!ni(e,t):!1}var yt=ae({name:"prefer-react-hook-alternative",meta:{type:"suggestion",docs:{description:"Prefer hook alternatives for certain functions in React components and hooks"},messages:{preferHookAlternative:"This function should not be used in react{{message}}."},schema:[Qr],hasSuggestions:!0},defaultOptions:[{disallowedFunctions:[]}],create(e,[t]){let{disallowedFunctions:n}=t,r=new Map(n.map(s=>[s.name,s]));return{CallExpression(s){let a=un(s);if(!a)return;let o=r.get(a);if(!o)return;let i=o.allowUseInside||[];ri(s,i)&&e.report({node:s,messageId:"preferHookAlternative",data:{message:o.message?` ${o.message}`:` use ${o.hookAlternative} instead`},suggest:o.hookAlternative?[{messageId:"preferHookAlternative",data:{message:`Replace with ${o.hookAlternative}`,hookAlternative:o.hookAlternative},fix:l=>{let c=o.hookAlternative;return s.callee.type===F.AST_NODE_TYPES.Identifier?l.replaceText(s.callee,c):s.callee.type===F.AST_NODE_TYPES.MemberExpression&&s.callee.property.type===F.AST_NODE_TYPES.Identifier?l.replaceText(s.callee.property,c):null}}]:[]})}}}});var Y=require("@typescript-eslint/utils");var ii=Y.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),mn="prefer-single-line-if",si=j({maxLineLength:O(Q()),maxNonSimpleConditionLength:O(Q())}),oi=ii({name:mn,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[si]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==Y.AST_NODE_TYPES.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let a=r.consequent.body[0];if(a.type===Y.AST_NODE_TYPES.ReturnStatement){if(!yn(a))return}else if(!(a.type===Y.AST_NODE_TYPES.ContinueStatement||a.type===Y.AST_NODE_TYPES.BreakStatement))return;if(r.test.type===Y.AST_NODE_TYPES.LogicalExpression||r.test.type===Y.AST_NODE_TYPES.ConditionalExpression)return;let o;if(t.maxNonSimpleConditionLength){let f=fn(r.test);if(!f&&r.test.type===Y.AST_NODE_TYPES.UnaryExpression&&r.test.operator==="!"){let h=r.test.argument;fn(h)&&(f=!0)}if(f&&(o=n.getText(r.test),o.length>t.maxNonSimpleConditionLength))return}o||(o=n.getText(r.test));let i=n.getText(a);if(o.includes(`
|
|
15
|
+
`))return;let l=n.getTokenAfter(r);if(l&&l.type===Y.AST_TOKEN_TYPES.Punctuator&&l.value==="}"){let f=n.getTokenAfter(l);if(f&&f.type===Y.AST_TOKEN_TYPES.Keyword&&(f.value==="else"||f.value==="catch"))return}let c=ai(n,r),p=`if (${o}) ${i}`;t.maxLineLength&&p.length+c.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:f=>f.replaceText(r,p)})}}}});function fn(e){return e.type===Y.AST_NODE_TYPES.CallExpression||e.type===Y.AST_NODE_TYPES.BinaryExpression||e.type===Y.AST_NODE_TYPES.MemberExpression&&dn(e)}function dn(e){return e.object.type===Y.AST_NODE_TYPES.MemberExpression?dn(e.object):e.object.type!==Y.AST_NODE_TYPES.Identifier}function ai(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function yn(e){if(!e.argument)return!0;let t=e.argument;return t.type===Y.AST_NODE_TYPES.ArrayExpression&&t.elements.length===0||t.type===Y.AST_NODE_TYPES.ObjectExpression&&t.properties.length===0||t.type===Y.AST_NODE_TYPES.Literal||t.type===Y.AST_NODE_TYPES.Identifier||t.type===Y.AST_NODE_TYPES.TemplateLiteral||t.type===Y.AST_NODE_TYPES.TaggedTemplateExpression?!0:t.type===Y.AST_NODE_TYPES.CallExpression?t.arguments.length===0:t.type===Y.AST_NODE_TYPES.UnaryExpression?yn(t):!1}var gt={name:mn,rule:oi};var K=require("@typescript-eslint/utils");var li=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),gn="react-compiler-migration",ci=j({disallowHooks:O(z(j({name:A(),replacement:A()}))),disallowMethods:O(z(j({name:A(),replacement:O(A()),requireTrueProp:O(A())})))}),pi=/eslint +react-compiler\/react-compiler: +\["error/;function ui(e){return e.type===K.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===K.AST_NODE_TYPES.MemberExpression&&e.property.type===K.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var fi=li({name:gn,meta:{type:"suggestion",fixable:"code",docs:{description:"Rules to help migrate to the new React compiler"},messages:{disallowedFunctionOrMethod:"{{functionOrMethod}} is not supported in react compiler. Use {{replacement}} instead.",replace:"Replace with safe alternative {{replacement}}",disallowedMethodWithMissingRequireTrueProp:"{{method}} is should have a prop named {{requireTrueProp}} set to true when used in react compiler."},hasSuggestions:!0,schema:[ci]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(pi.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let s=null,a=null;if(r.callee.type===K.AST_NODE_TYPES.Identifier?(s=r.callee.name,a=r.callee):r.callee.type===K.AST_NODE_TYPES.MemberExpression&&r.callee.property.type===K.AST_NODE_TYPES.Identifier&&(s=r.callee.property.name,a=r.callee.property),s){let o=t.disallowHooks.find(i=>i.name===s);o&&a&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:o.name,replacement:o.replacement},suggest:[{messageId:"replace",data:{replacement:o.replacement},fix:i=>i.replaceText(a,o.replacement)}]})}}if(t.disallowMethods?.length&&ui(r.callee)){for(let s of r.arguments)if(s.type===K.AST_NODE_TYPES.ObjectExpression){for(let a of s.properties)if(a.type===K.AST_NODE_TYPES.Property&&a.key.type===K.AST_NODE_TYPES.Identifier){let o=a.key.name,i=t.disallowMethods.find(l=>l.name===o);if(i){if(i.requireTrueProp){let l=i.requireTrueProp,c=!1;for(let p of s.properties)if(p.type===K.AST_NODE_TYPES.Property&&p.key.type===K.AST_NODE_TYPES.Identifier&&p.key.name===l&&p.value.type===K.AST_NODE_TYPES.Literal&&p.value.value===!0){c=!0;break}if(!c){e.report({node:a,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:i.name,requireTrueProp:l}});continue}}i.replacement&&e.report({node:a,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:i.name,replacement:i.replacement},suggest:[{messageId:"replace",data:{replacement:i.replacement},fix:l=>l.replaceText(a.key,i.replacement)}]})}}}}}}:{}}}),St={name:gn,rule:fi};var Fe=require("@typescript-eslint/utils"),mi=Fe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Sn="require-description",di=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,yi=/^eslint-disable-(next-)?line$/u,gi=mi({name:Sn,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,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let a=Si(s);a!=null&&(r.has(a.kind)||a.description||e.report({loc:hi(s.loc),messageId:"missingDescription"}))}}}}}),Tn={name:Sn,rule:gi};function Si(e){let{text:t,description:n}=Ti(e.value);if(!t)return null;let r=di.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let a=yi.test(s);if(e.type===Fe.TSESTree.AST_TOKEN_TYPES.Line&&!a||a&&e.loc.start.line!==e.loc.end.line)return null;let o=t.slice(r.index+s.length);return{kind:s,value:o.trim(),description:n}}function Ti(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function hi(e){return{start:{line:e.start.line,column:-1},end:e.end}}function bn(e){return/^use[A-Z0-9]/.test(e)}function Ne(e){return e.type==="Identifier"?bn(e.name):e.type==="MemberExpression"&&!e.computed&&Ne(e.property)?e.object.type==="Identifier":!1}function xn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function In(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Cn(e){return!!(e.parent&&e.parent.callee&&In(e.parent.callee,"forwardRef"))}function wn(e){return!!(e.parent&&e.parent.callee&&In(e.parent.callee,"memo"))}function Tt(e){for(;e;){let t=kn(e);if(t&&(xn(t)||Ne(t))||Cn(e)||wn(e))return!0;e=e.parent}return!1}function hn(e){return!1}function ht(e){return!1}var Ei=/eslint +react-compiler\/react-compiler: +\["error/,Rn={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 l of e.sourceCode.getAllComments())if(Ei.test(l.value))return{CallExpression(c){let p=null;c.callee.name==="useMemo"?p="useMemo":c.callee.name==="useCallback"&&(p="useCallback"),p&&e.report({node:c,message:`"${p}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?l=>t(l):l=>e.sourceCode.getText(l),n=typeof e.getScope=="function"?()=>n():l=>e.sourceCode.getScope(l),r=null,s=[],a=[],o=new WeakSet;function i(l){for(let c of l.references){let p=c.identifier.parent;if(p.type==="VariableDeclarator"&&p.init&&p.init.type==="CallExpression"&&p.init.callee&&hn(p.init.callee))for(let f of c.resolved.references)f!==c&&o.add(f.identifier)}}return{onCodePathSegmentStart:l=>a.push(l),onCodePathSegmentEnd:()=>a.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(l,c){let p=s.pop();if(p.size===0)return;let f=new Set;function h(S,k){let{cache:N}=h,L=N.get(S.id),M=new Set(k);if(M.has(S.id)){let R=[...M],V=R.slice(R.indexOf(S.id)+1);for(let q of V)f.add(q);return BigInt("0")}if(M.add(S.id),L!==void 0)return L;if(l.thrownSegments.includes(S))L=BigInt("0");else if(S.prevSegments.length===0)L=BigInt("1");else{L=BigInt("0");for(let R of S.prevSegments)L+=h(R,M)}return S.reachable&&L===BigInt("0")?N.delete(S.id):N.set(S.id,L),L}function m(S,k){let{cache:N}=m,L=N.get(S.id),M=new Set(k);if(M.has(S.id)){let R=Array.from(M),V=R.slice(R.indexOf(S.id)+1);for(let q of V)f.add(q);return BigInt("0")}if(M.add(S.id),L!==void 0)return L;if(l.thrownSegments.includes(S))L=BigInt("0");else if(S.nextSegments.length===0)L=BigInt("1");else{L=BigInt("0");for(let R of S.nextSegments)L+=m(R,M)}return N.set(S.id,L),L}function y(S){let{cache:k}=y,N=k.get(S.id);if(N===null)return 1/0;if(N!==void 0)return N;if(k.set(S.id,null),S.prevSegments.length===0)N=1;else{N=1/0;for(let L of S.prevSegments){let M=y(L);M<N&&(N=M)}N+=1}return k.set(S.id,N),N}h.cache=new Map,m.cache=new Map,y.cache=new Map;let T=m(l.initialSegment),E=kn(c),g=Tt(c),v=E?xn(E)||Ne(E):Cn(c)||wn(c),I=1/0;for(let S of l.finalSegments){if(!S.reachable)continue;let k=y(S);k<I&&(I=k)}for(let[S,k]of p){if(!S.reachable)continue;let N=S.nextSegments.length===0?I<=y(S):I<y(S),L=h(S)*m(S),M=f.has(S.id);for(let R of k)if(M&&!ht(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.`}),v){if(c.async&&e.report({node:R,message:`React Hook "${t(R)}" cannot be called in an async function.`}),!M&&L!==T&&!ht(R)){let q=`React Hook "${t(R)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(N?" Did you accidentally call a React Hook after an early return?":"");e.report({node:R,message:q})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let V=`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:V})}else if(E){let V=`React Hook "${t(R)}" is called in function "${t(E)}" 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:V})}else if(c.type==="Program"){let V=`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:V})}else if(g&&!ht(R)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let q=c.parent;if(q.parent.type==="VariableDeclarator"&&bn(q.parent.id.name))return}let V=`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:V})}}},CallExpression(l){if(Ne(l.callee)){let c=En(s),p=En(a),f=c.get(p);f||(f=[],c.set(p,f)),f.push(l.callee)}l.callee.type==="Identifier"&&(l.callee.name==="useEffect"||hn(l.callee))&&l.arguments.length>0&&(r=l)},Identifier(l){r==null&&o.has(l)&&l.parent.type!=="CallExpression"&&e.report({node:l,message:`\`${t(l)}\` 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"(l){l===r&&(r=null)},FunctionDeclaration(l){Tt(l)&&i(n(l))},ArrowFunctionExpression(l){Tt(l)&&i(n(l))}}}};function kn(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 En(e){return e[e.length-1]}var vn={[ft.name]:ft.rule,[Ge.name]:Ge.rule,[Je.name]:Je.rule,"rules-of-hooks":Rn,"exhaustive-deps":jt,"require-description":Tn.rule,[Ze.name]:Ze.rule,[et.name]:et.rule,[mt.name]:mt.rule,[We.name]:We.rule,[Ke.name]:Ke.rule,[st.name]:st.rule,[gt.name]:gt.rule,[it.name]:it.rule,[Qe.name]:Qe.rule,[Ye.name]:Ye.rule,[St.name]:St.rule,[Ve.name]:Ve.rule,[Xe.name]:Xe.rule,[at.name]:at.rule,[ct.name]:ct.rule,[pt.name]:pt.rule,[lt.name]:lt.rule,[yt.name]:yt.rule};var bi={rules:vn};0&&(module.exports={extendedLintPlugin});
|
package/dist/extended-lint.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{AST_NODE_TYPES as
|
|
2
|
-
`)||n.getCommentsInside(
|
|
3
|
-
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function
|
|
1
|
+
import{AST_NODE_TYPES as q,ESLintUtils as An}from"@typescript-eslint/utils";var Ae=Symbol.for("optional");function O(e){return{...e,[Ae]:!0}}function Te(e,t){return{enum:e,...t}}function ae(e){return{...e,type:"boolean"}}function A(e){return{...e,type:"string"}}function Z(e){return{...e,type:"number"}}function Tt(e){return{...e,type:"integer"}}function Y(e,t){return{...t,type:"array",items:e}}function j(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,s=[];for(r in e)e[r][Ae]?e[r][Ae]=void 0:s.push(r);s.length>0&&(n.required=s)}return n}function Pe(...e){return{anyOf:e}}var Pn=An.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Et="react-compiler-extra",Fn=j({runOnlyWithEnableCompilerDirective:O(ae())}),Nn=/eslint +react-compiler\/react-compiler: +\["error/;function Dn(e){return e.type===q.Identifier?e.name.startsWith("use"):e.type===q.MemberExpression&&e.property.type===q.Identifier?e.property.name.startsWith("use"):!1}var jn=/\bthis[.[]/;function ht(e){return jn.test(e)}var Ln=Pn({name:Et,meta:{type:"suggestion",fixable:"code",docs:{description:"Extra rules to enforce best practices when using the React compiler"},messages:{objectMethodIsNotSupported:"Object methods such as `{ method() {} }` have limited support to optimizations in the React compiler, use a function expression `{ method: () => {} }` instead.",replaceWithFunctionExpression:"Replace with function expression",thisKeywordInMethod:"Object method uses `this` keyword which would have different behavior if converted to an arrow function. Fix this manually."},hasSuggestions:!0,schema:[Fn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let a of e.sourceCode.getAllComments())if(Nn.test(a.value)){n=!0;break}if(!n)return{}}function r(a){for(let o of a.properties)if(o.type===q.Property&&o.method&&o.value.type===q.FunctionExpression){let i=e.sourceCode,l=i.getText(o.key),c=o.value,p=i.getText(c.body);if(ht(p))e.report({node:o,messageId:"thisKeywordInMethod"});else{let f=c.params.map(m=>i.getText(m)).join(", "),h="";c.generator?h=`${l}: function* (${f}) ${p}`:h=`${l}: (${f}) => ${p}`,e.report({node:o,messageId:"objectMethodIsNotSupported",fix:m=>m.replaceText(o,h)})}}}function s(a){for(let o of a.properties)if(o.type===q.Property&&o.value.type===q.ObjectExpression){for(let i of o.value.properties)if(i.type===q.Property&&i.method&&i.value.type===q.FunctionExpression){let c=e.sourceCode.getText(i.value.body);ht(c)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(a){if(Dn(a.callee))for(let o of a.arguments){if(o.type===q.ObjectExpression&&(r(o),s(o)),o.type===q.ArrowFunctionExpression&&(o.body.type===q.ObjectExpression&&(r(o.body),s(o.body)),o.body.type===q.BlockStatement))for(let i of o.body.body)i.type===q.ReturnStatement&&i.argument?.type===q.ObjectExpression&&(r(i.argument),s(i.argument));if(o.type===q.FunctionExpression)for(let i of o.body.body)i.type===q.ReturnStatement&&i.argument?.type===q.ObjectExpression&&(r(i.argument),s(i.argument))}}}}}),Fe={name:Et,rule:Ln};import{AST_NODE_TYPES as Ne}from"@typescript-eslint/utils";import{ESLintUtils as _n}from"@typescript-eslint/utils";function se(e){let n=_n.RuleCreator(r=>`https://github.com/lucasols/extended-lint#${r}`)(e);return{name:e.name,rule:n}}var Mn=j({disallow:O(Y(j({selector:A(),message:A(),replace:O(Pe(A(),j({regex:A(),with:A()}))),replaceType:O(Te(["suggestion","autofix"]))}))),__dev_simulateFileName:O(A()),mustMatchSyntax:O(Y(j({includeRegex:A(),mustCallFn:O(Y(j({anyCall:Y(j({fn:A(),withArgs:Y(j({atIndex:Tt(),literal:Pe(A(),Z(),ae())}))})),message:O(A())}))),mustMatchSelector:O(Y(j({selector:A(),message:A()})))})))}),De=se({name:"advanced-no-restricted-syntax",meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Mn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:s,disallow:a}=t,o=s??e.filename,i=[],l=new Map,c=new Set,p=new Map;for(let{includeRegex:m,mustCallFn:y,mustMatchSelector:T}of r??[]){let E=$n(o,new RegExp(m));if(!E)continue;let g=v=>{let I=v;for(let{name:S,value:k}of E)I=I.replaceAll(S,k);return I};for(let{anyCall:v,message:I}of y??[]){let S=`Expected file to call the function: ${v.map(({fn:k})=>k).join(" or ")}`;c.add(S),i.push(k=>{let{callee:F}=k;if(F.type===Ne.Identifier){for(let{fn:L,withArgs:_}of v)if(F.name===L){c.delete(S);for(let R of _){let M=k.arguments[R.atIndex],B=typeof R.literal=="string"?g(R.literal):R.literal;if(!M){e.report({node:k,messageId:"default",data:{message:`Missing argument with value "${B}" at index ${R.atIndex}${I?`: ${g(I)}`:""}`}});continue}if(M.type!==Ne.Literal){e.report({node:M,messageId:"default",data:{message:`Argument at position ${R.atIndex} should the literal "${B}"${I?`: ${g(I)}`:""}`}});continue}M.value!==B&&e.report({node:M,messageId:"default",data:{message:`Argument should have the value "${B}"${I?`: ${g(I)}`:""}`},fix:de=>de.replaceText(M,typeof B=="string"?`'${B}'`:String(B))})}break}}})}for(let{selector:v,message:I}of T??[])p.set(v,g(I)),l.set(g(v),()=>{p.delete(v)})}function f(m,y){let T=n[m];T?n[m]=E=>{T(E),y(E)}:n[m]=y}for(let{selector:m,message:y,replace:T,replaceType:E="suggestion"}of a??[]){if(m==="CallExpression"){i.push(g=>{h(T,g,y,E)});continue}n[m]=g=>{h(T,g,y,E)}}if(l.size>0)for(let[m,y]of l)f(m,y);return i.length>0&&(n.CallExpression=m=>{if(m.type===Ne.CallExpression)for(let y of i)y(m)}),n["Program:exit"]=m=>{for(let y of c)e.report({node:m,messageId:"default",data:{message:y}});for(let[,y]of p)e.report({node:m,messageId:"default",data:{message:y}})},n;function h(m,y,T,E){let g=v=>{if(!m)return null;if(typeof m=="string")return v.replaceText(y,m);{let I=new RegExp(m.regex),S=e.sourceCode.getText(y);return v.replaceText(y,S.replace(I,m.with))}};e.report({node:y,messageId:"default",data:{message:T},fix:m&&E==="autofix"?g:void 0,suggest:m&&E==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof m=="string"?m:m.with}"`},fix:g}]:void 0})}}});function $n(e,t){let n=[],r=t.exec(e);if(!r)return null;let[s,...a]=r;n.push({name:"$0_lowercase",value:s.toLowerCase()}),n.push({name:"$0_capitalize",value:bt(s)}),n.push({name:"$0_uncapitalize",value:xt(s)}),n.push({name:"$0",value:s});for(let o=0;o<a.length;o++){let i=`$${o+1}`,l=a[o];n.push({name:`${i}_lowercase`,value:l.toLowerCase()}),n.push({name:`${i}_capitalize`,value:bt(l)}),n.push({name:`${i}_uncapitalize`,value:xt(l)}),n.push({name:i,value:l})}return n}function bt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function xt(e){return e.charAt(0).toLowerCase()+e.slice(1)}import{AST_NODE_TYPES as $,AST_TOKEN_TYPES as Un,ESLintUtils as Vn}from"@typescript-eslint/utils";var Wn=Vn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ct="collapse-simple-objs-in-one-line",Hn=j({maxLineLength:O(Z()),maxProperties:O(Z()),nestedObjMaxLineLength:O(Z()),nestedObjMaxProperties:O(Z()),ignoreTypesWithSuffix:O(Y(A()))}),Yn=Wn({name:Ct,meta:{type:"suggestion",fixable:"code",docs:{description:"Format simple objects and types in one line"},messages:{singleLineProp:"Object/type should be written in a single line"},schema:[Hn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],s=t.maxProperties??2,a=t.nestedObjMaxLineLength??t.maxLineLength,o=t.nestedObjMaxProperties??3;function i(c){if(c.type===$.ObjectExpression){let p=c.parent.type===$.Property,f=p?o:s,h=c.properties.length;if(h>f)return!1;if(h===1){let y=c.properties[0];return y.type===$.Property&&y.value.type===$.ObjectExpression||y.type===$.Property&&y.value.type===$.ArrayExpression&&!y.value.elements.every(E=>E&&je(E))?!1:{text:n.getText(y),isNested:p,propsSize:h}}let m=[];for(let y of c.properties){if(y.type===$.Property&&!je(y.value))return!1;m.push(n.getText(y))}return{text:m.join(", "),isNested:p,propsSize:h}}else{let p=c.parent.parent?.type===$.TSPropertySignature,f=p?o:s,h=c.members.length;if(h>f)return!1;if(r.length>0&&c.parent.type===$.TSTypeAliasDeclaration){let y=c.parent.id.name;if(r.some(T=>y.endsWith(T)))return!1}if(h===1){let y=c.members[0];return y.type===$.TSPropertySignature&&y.typeAnnotation?.typeAnnotation.type===$.TSTypeLiteral?!1:{text:n.getText(y),isNested:p,propsSize:1}}if(c.parent.type===$.TSIntersectionType||c.parent.type===$.TSUnionType)return!1;let m=[];for(let y of c.members){if(y.type!==$.TSPropertySignature)return!1;let T=y.typeAnnotation?.typeAnnotation;if(!T||T.type===$.TSTypeLiteral||!It(T))return!1;if(T.type===$.TSTypeReference&&T.typeArguments){if(T.typeArguments.params.length>1)return!1;let g=T.typeArguments.params[0];if(!It(g))return!1}let E=n.getText(y).trim();(E.endsWith(";")||E.endsWith(","))&&(E=E.slice(0,-1)),m.push(E)}return{text:m.join("; "),isNested:p,propsSize:h}}}function l(c){if(c.loc.start.line===c.loc.end.line)return;if(c.parent.type!==$.JSXExpressionContainer){let T=0,E=n.getTokenAfter(c,{filter:g=>g.type!==Un.Punctuator?!0:g.value===","||g.value===";"||g.value===")"||g.value==="}"?(T++,!1):!0});if(T>4||E?.loc.start.line===c.loc.end.line)return}let p=i(c);if(!p)return;let f=p.text;if(f.includes(`
|
|
2
|
+
`)||n.getCommentsInside(c).length>0)return;f.endsWith(";")&&(f=f.slice(0,-1));let h=`{ ${f} }`,m=Bn(n,c),y=p.isNested&&p.propsSize>2?a:t.maxLineLength;y&&h.length+m.length+zn(c,n)>y||e.report({node:c,messageId:"singleLineProp",fix:T=>T.replaceText(c,h)})}return{TSTypeLiteral:l,ObjectExpression:l}}});function It(e){return e.type===$.TSLiteralType||e.type===$.TSTypeReference||e.type===$.TSNumberKeyword||e.type===$.TSStringKeyword||e.type===$.TSBooleanKeyword||e.type===$.TSNullKeyword||e.type===$.TSUndefinedKeyword}function je(e,t){return!!(e.type===$.Literal||e.type===$.Identifier||e.type===$.TemplateLiteral||e.type===$.TaggedTemplateExpression||!t&&e.type===$.ArrayExpression&&e.elements.every(n=>n&&je(n,!0)))}function zn(e,t){let n=t.getLastToken(e);if(!n)return 0;let r=t.text.indexOf(`
|
|
3
|
+
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function Bn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Le={name:Ct,rule:Yn};var qn=/eslint +react-compiler\/react-compiler: +\["error/,Rt={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){let t=!1,n=typeof e.getSource=="function"?g=>n(g):g=>e.sourceCode.getText(g),r=typeof e.getScope=="function"?()=>r():g=>e.sourceCode.getScope(g),s=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,a=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,o={additionalHooks:s,enableDangerousAutofixThisMayCauseInfiniteLoops:a};function i(g){a&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let l=e.getSourceCode().scopeManager,c=new WeakMap,p=new WeakSet,f=new WeakMap,h=new WeakMap,m=new WeakSet;function y(g,v){return function(I){if(v.has(I))return v.get(I);let S=g(I);return v.set(I,S),S}}function T(g,v,I,S,k){k&&g.async&&i({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
|
|
4
4
|
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
async function fetchData() {
|
|
@@ -11,5 +11,5 @@ useEffect(() => {
|
|
|
11
11
|
fetchData();
|
|
12
12
|
}, [someId]); // Or [] if effect doesn't need props or state
|
|
13
13
|
|
|
14
|
-
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let A=o.acquire(g),L=new Set,D=null;{let p=A.upper;for(;p&&(L.add(p),p.type!=="function");)p=p.upper;if(!p)return;D=p}let R=Array.isArray;function j(p){if(!R(p.defs))return!1;let d=p.defs[0];if(d==null||d.node.type!=="VariableDeclarator")return!1;let b=d.node.init;if(b==null)return!1;for(;b.type==="TSAsExpression";)b=b.expression;let x=d.node.parent;if(x==null&&(De(D.block,d.node.id),x=d.node.parent,x==null))return!1;if(x.kind==="const"&&b.type==="Literal"&&(typeof b.value=="string"||typeof b.value=="number"||b.value===null))return!0;if(b.type!=="CallExpression")return!1;let w=b.callee;if(w.type==="MemberExpression"&&w.object.name==="React"&&w.property!=null&&!w.computed&&(w=w.property),w.type!=="Identifier")return!1;let I=d.node.id,{name:k}=w;if(k==="useRef"&&I.type==="Identifier")return!0;if(Vn(w)&&I.type==="Identifier"){for(let P of p.references)P!==I&&m.add(P.identifier);return!0}else if(k==="useState"||k==="useReducer"){if(I.type==="ArrayPattern"&&I.elements.length===2&&R(p.identifiers)){if(I.elements[1]===p.identifiers[0]){if(k==="useState"){let P=p.references,X=0;for(let ee=0;ee<P.length;ee++){if(P[ee].isWrite()&&X++,X>1)return!1;l.set(P[ee].identifier,I.elements[0])}}return!0}else if(I.elements[0]===p.identifiers[0]){if(k==="useState"){let P=p.references;for(let X=0;X<P.length;X++)c.add(P[X].identifier)}return!1}}}else if(k==="useTransition"&&I.type==="ArrayPattern"&&I.elements.length===2&&Array.isArray(p.identifiers)&&I.elements[1]===p.identifiers[0])return!0;return!1}function z(p){if(!R(p.defs))return!1;let d=p.defs[0];if(d==null||d.node==null||d.node.id==null)return!1;let b=d.node,x=D.childScopes,w=null,I;for(I=0;I<x.length;I++){let k=x[I],P=k.block;if(b.type==="FunctionDeclaration"&&P===b||b.type==="VariableDeclarator"&&P.parent===b){w=k;break}}if(w==null)return!1;for(I=0;I<w.through.length;I++){let k=w.through[I];if(k.resolved!=null&&L.has(k.resolved.scope)&&!pe(k.resolved))return!1}return!0}let pe=y(j,f),fn=y(z,h),at=new Map;function mn(p){let d=p.from,b=!1;for(;d.block!==g;)d.type==="function"&&(b=d.block.parent!=null&&d.block.parent.type==="ReturnStatement"),d=d.upper;return b}let K=new Map,Ce=new Map;lt(A);function lt(p){for(let d of p.references){if(!d.resolved||!L.has(d.resolved.scope))continue;let b=De(g,d.identifier),x=bt(b),w=te(x,Ce);if(v&&x.type==="Identifier"&&(x.parent.type==="MemberExpression"||x.parent.type==="OptionalMemberExpression")&&!x.parent.computed&&x.parent.property.type==="Identifier"&&x.parent.property.name==="current"&&mn(d)&&at.set(w,{reference:d,dependencyNode:x}),x.parent.type==="TSTypeQuery"||x.parent.type==="TSTypeReference")continue;let I=d.resolved.defs[0];if(I!=null&&!(I.node!=null&&I.node.init===g.parent)&&I.type!=="TypeParameter")if(K.has(w))K.get(w).references.push(d);else{let k=d.resolved,P=pe(k)||fn(k);K.set(w,{isStable:P,references:[d]})}}for(let d of p.childScopes)lt(d)}at.forEach(({reference:p,dependencyNode:d},b)=>{let x=p.resolved.references,w=!1;for(let I=0;I<x.length;I++){let{identifier:k}=x[I],{parent:P}=k;if(P!=null&&P.type==="MemberExpression"&&!P.computed&&P.property.type==="Identifier"&&P.property.name==="current"&&P.parent.type==="AssignmentExpression"&&P.parent.left===P){w=!0;break}}w||i({node:d.parent.property,message:`The ref value '${b}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${b}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Ie=new Set;function dn(p,d){Ie.has(d)||(Ie.add(d),i({node:p,message:`Assignments to the '${d}' variable from inside React Hook ${n(C)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(C)}.`}))}let fe=new Set;if(K.forEach(({isStable:p,references:d},b)=>{p&&fe.add(b),d.forEach(x=>{x.writeExpr&&dn(x.writeExpr,b)})}),Ie.size>0)return;if(!O){let p=null;if(K.forEach(({isStable:d,references:b},x)=>{p||b.forEach(w=>{if(p)return;let I=w.identifier;if(!l.has(I))return;let P=w.from;for(;P.type!=="function";)P=P.upper;P.block===g&&(p=x)})}),p){let{suggestedDependencies:d}=Le({dependencies:K,declaredDependencies:[],stableDependencies:fe,externalDependencies:new Set,isEffect:!0});i({node:C,message:`React Hook ${S} contains a call to '${p}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+d.join(", ")+`] as a second argument to the ${S} Hook.`,suggest:[{desc:`Add dependencies array: [${d.join(", ")}]`,fix(b){return b.insertTextAfter(g,`, [${d.join(", ")}]`)}}]})}return}let le=[],ce=new Set;O.type!=="ArrayExpression"?i({node:O,message:`React Hook ${n(C)} 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(p=>{if(p===null)return;if(p.type==="SpreadElement"){i({node:p,message:`React Hook ${n(C)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}m.has(p)&&i({node:p,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(p)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(p)}\``,fix(w){return w.removeRange(p.range)}}]});let d;try{d=te(p,Ce)}catch(w){if(/Unsupported node type/.test(w.message)){p.type==="Literal"?K.has(p.value)?i({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. Did you mean to include ${p.value} in the array instead?`}):i({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):i({node:p,message:`React Hook ${n(C)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw w}let b=p;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let x=!D.through.some(w=>w.identifier===b);le.push({key:d,node:p}),x||ce.add(d)});let{suggestedDependencies:yn,unnecessaryDependencies:me,missingDependencies:ne,duplicateDependencies:ct}=Le({dependencies:K,declaredDependencies:le,stableDependencies:fe,externalDependencies:ce,isEffect:v}),de=yn;if(ct.size+ne.size+me.size===0){if(t)return;jn({declaredDependencies:le,declaredDependenciesNode:O,componentScope:D,scope:A}).forEach(({construction:d,isUsedOutsideOfHook:b,depType:x})=>{let w=x==="function"?"useCallback":"useMemo",I=x==="function"?"definition":"initialization",k=`wrap the ${I} of '${d.name.name}' in its own ${w}() Hook.`,P=b?`To fix this, ${k}`:`Move it inside the ${S} callback. Alternatively, ${k}`,X=x==="conditional"||x==="logical expression"?"could make":"makes",ee=`The '${d.name.name}' ${x} ${X} the dependencies of ${S} Hook (at line ${O.loc.start.line}) change on every render. ${P}`,ut;b&&d.type==="Variable"&&x==="function"&&(ut=[{desc:`Wrap the ${I} of '${d.name.name}' in its own ${w}() Hook.`,fix(pt){let[Sn,Tn]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[pt.insertTextBefore(d.node.init,Sn),pt.insertTextAfter(d.node.init,Tn)]}}]),i({node:d.node,message:ee,suggest:ut})});return}!v&&ne.size>0&&(de=Le({dependencies:K,declaredDependencies:[],stableDependencies:fe,externalDependencies:ce,isEffect:v}).suggestedDependencies);function gn(){if(le.length===0)return!0;let p=le.map(b=>b.key),d=p.slice().sort();return p.join(",")===d.join(",")}gn()&&de.sort();function we(p){let d=p.split("."),b="";for(let x=0;x<d.length;x++){if(x!==0){let w=d.slice(0,x+1).join("."),I=Ce.get(w)===!0;b+=I?"?.":"."}b+=d[x]}return b}function Re(p,d,b,x){return p.size===0?null:(p.size>1?"":d+" ")+b+" "+(p.size>1?"dependencies":"dependency")+": "+$n(Array.from(p).sort().map(w=>"'"+we(w)+"'"))+`. Either ${x} ${p.size>1?"them":"it"} or remove the dependency array.`}let Z="";if(me.size>0){let p=null;if(Array.from(me.keys()).forEach(d=>{p===null&&d.endsWith(".current")&&(p=d)}),p!==null)Z=` Mutable values like '${p}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(ce.size>0){let d=Array.from(ce)[0];A.set.has(d)||(Z=` Outer scope values like '${d}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!Z&&ne.has("props")){let p=K.get("props");if(p==null)return;let d=p.references;if(!Array.isArray(d))return;let b=!0;for(let x=0;x<d.length;x++){let w=d[x],I=De(D.block,w.identifier);if(!I){b=!1;break}let k=I.parent;if(k==null){b=!1;break}if(k.type!=="MemberExpression"&&k.type!=="OptionalMemberExpression"){b=!1;break}}b&&(Z=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${S} call and refer to those specific props inside ${n(C)}.`)}if(!Z&&ne.size>0){let p=null;ne.forEach(d=>{if(p)return;let b=D.set.get(d),x=K.get(d);if(x.references[0].resolved!==b)return;let w=b.defs[0];if(w==null||w.name==null||w.type!=="Parameter")return;let I=!1,k;for(let P=0;P<x.references.length;P++)if(k=x.references[P].identifier,k!=null&&k.parent!=null&&(k.parent.type==="CallExpression"||k.parent.type==="OptionalCallExpression")&&k.parent.callee===k){I=!0;break}I&&(p=d)}),p!==null&&(Z=` If '${p}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!Z&&ne.size>0){let p=null;if(ne.forEach(d=>{if(p!==null)return;let x=K.get(d).references,w,I;for(let k=0;k<x.length;k++){for(w=x[k].identifier,I=w.parent;I!=null&&I!==D.block;){if(I.type==="CallExpression"){let P=l.get(I.callee);if(P!=null){if(P.name===d)p={missingDep:d,setter:I.callee.name,form:"updater"};else if(c.has(w))p={missingDep:d,setter:I.callee.name,form:"reducer"};else{let X=x[k].resolved;if(X!=null){let ee=X.defs[0];ee!=null&&ee.type==="Parameter"&&(p={missingDep:d,setter:I.callee.name,form:"inlineReducer"})}}break}}I=I.parent}if(p!==null)break}}),p!==null)switch(p.form){case"reducer":Z=` You can also replace multiple useState variables with useReducer if '${p.setter}' needs the current value of '${p.missingDep}'.`;break;case"inlineReducer":Z=` If '${p.setter}' needs the current value of '${p.missingDep}', you can also switch to useReducer instead of useState and read '${p.missingDep}' in the reducer.`;break;case"updater":Z=` You can also do a functional update '${p.setter}(${p.missingDep.slice(0,1)} => ...)' if you only need '${p.missingDep}' in the '${p.setter}' call.`;break;default:throw new Error("Unknown case.")}}i({node:O,message:`React Hook ${n(C)} has `+(Re(ne,"a","missing","include")||Re(me,"an","unnecessary","exclude")||Re(ct,"a","duplicate","omit"))+Z,suggest:[{desc:`Update the dependencies array to be: [${de.map(we).join(", ")}]`,fix(p){return p.replaceText(O,`[${de.map(we).join(", ")}]`)}}]})}function E(g){let O=Mn(g.callee,u);if(O===-1)return;let C=g.arguments[O],S=g.callee,v=xt(S).name,A=g.arguments[O+1],L=/Effect($|[^a-z])/g.test(v);if(!C){i({node:S,message:`React Hook ${v} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!L)){if(!A&&!L){(v==="useMemo"||v==="useCallback")&&i({node:S,message:`React Hook ${v} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(C.type){case"FunctionExpression":case"ArrowFunctionExpression":T(C,A,S,v,L);return;case"Identifier":if(!A||A.elements&&A.elements.some(j=>j&&j.type==="Identifier"&&j.name===C.name))return;let D=r(g).set.get(C.name);if(D==null||D.defs==null)return;let R=D.defs[0];if(!R||!R.node||R.type!=="Variable"&&R.type!=="FunctionName")break;switch(R.node.type){case"FunctionDeclaration":T(R.node,A,S,v,L);return;case"VariableDeclarator":let j=R.node.init;if(!j)break;switch(j.type){case"ArrowFunctionExpression":case"FunctionExpression":T(j,A,S,v,L);return}break}break;default:i({node:S,message:`React Hook ${v} received a function whose dependencies are unknown. Pass an inline function instead.`});return}i({node:S,message:`React Hook ${v} has a missing dependency: '${C.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${C.name}]`,fix(D){return D.replaceText(A,`[${C.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(Dn.test(g.value))return t=!0,{CallExpression:O=>E(O,!0)}}return{CallExpression:g=>E(g)}}};function Le({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:s}){let a=u();function u(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,E)=>{let g=i(a,E);g.isUsed=!0,o(a,E,O=>{O.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let E=i(a,T);E.isSatisfiedRecursively=!0}),n.forEach(T=>{let E=i(a,T);E.isSatisfiedRecursively=!0});function i(T,E){let g=E.split("."),O=T;for(let C of g){let S=O.children.get(C);S||(S=u(),O.children.set(C,S)),O=S}return O}function o(T,E,g){let O=E.split("."),C=T;for(let S of O){let v=C.children.get(S);if(!v)return;g(v),C=v}}let l=new Set,c=new Set;f(a,l,c,T=>T);function f(T,E,g,O){T.children.forEach((C,S)=>{let v=O(S);if(C.isSatisfiedRecursively){C.isSubtreeUsed&&g.add(v);return}if(C.isUsed){E.add(v);return}f(C,E,g,A=>v+"."+A)})}let h=[],m=new Set,y=new Set;return t.forEach(({key:T})=>{c.has(T)?h.indexOf(T)===-1?h.push(T):y.add(T):m.add(T)}),l.forEach(T=>{h.push(T)}),{suggestedDependencies:h,unnecessaryDependencies:m,duplicateDependencies:y,missingDependencies:l}}function re(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 re(e.consequent)!=null||re(e.alternate)!=null?"conditional":null;case"LogicalExpression":return re(e.left)!=null||re(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return re(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return re(e.expression);case"TSAsExpression":return re(e.expression)}return null}function jn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let s=e.map(({key:u})=>{let i=n.variables.find(l=>l.name===u);if(i==null)return null;let o=i.defs[0];if(o==null)return null;if(o.type==="Variable"&&o.node.type==="VariableDeclarator"&&o.node.id.type==="Identifier"&&o.node.init!=null){let l=re(o.node.init);if(l!=null)return[i,l]}return o.type==="FunctionName"&&o.node.type==="FunctionDeclaration"?[i,"function"]:o.type==="ClassName"&&o.node.type==="ClassDeclaration"?[i,"class"]:null}).filter(Boolean);function a(u){let i=!1;for(let o=0;o<u.references.length;o++){let l=u.references[o];if(l.writeExpr){if(i)return!0;i=!0;continue}let c=l.from;for(;c!==r&&c!=null;)c=c.upper;if(c!==r&&!Ct(t,l.identifier))return!0}return!1}return s.map(([u,i])=>({construction:u.defs[0],depType:i,isUsedOutsideOfHook:a(u)}))}function bt(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)?bt(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function _e(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function te(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=te(e.object,t),r=te(e.property,null),s=`${n}.${r}`;return _e(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=te(e.object,t),r=te(e.property,null),s=`${n}.${r}`;return _e(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=te(n.object,t),s=te(n.property,null),a=`${r}.${s}`;return _e(n,t,a),a}else throw new Error(`Unsupported node type: ${e.type}`)}function xt(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Mn(e,t){let n=xt(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 r;try{r=te(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(r)?0:-1}else return-1}}function De(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Un(r,t))return r;if(Ct(r,t))for(let[s,a]of Object.entries(r))s!=="parent"&&(ht(a)?(a.parent=r,n.push(a)):Array.isArray(a)&&a.forEach(u=>{ht(u)&&(u.parent=r,n.push(u))}))}return null}function $n(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 ht(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Un(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 Ct(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Vn(e){return!1}import{AST_NODE_TYPES as Te,ESLintUtils as wt}from"@typescript-eslint/utils";import q from"typescript";var Wn=wt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),It="improved-no-unnecessary-condition",Hn=_({}),Yn=["string","number","bigint","boolean","symbol","undefined","object","function","never"],zn=new Set(Yn),je={name:It,rule:Wn({name:It,meta:{type:"suggestion",docs:{description:"Extends checks of `no-unnecessary-condition` rule"},messages:{unnecessaryTypeofCondition:'This condition is unnecessary. The type of "{{name}}" is always "{{type}}".',alwaysFalseTypeofCondition:'This condition will always be false. The type of "{{name}}" is "{{actualType}}" so the condition has no overlap with "{{conditionType}}".'},schema:[Hn]},defaultOptions:[{}],create(e){let t=wt.getParserServices(e,!0),n=t.program?.getTypeChecker();if(!n||!t.program)throw new Error("TypeScript services or program not available");function r(i){return i.type===Te.UnaryExpression&&i.operator==="typeof"}function s(i){return i.flags&q.TypeFlags.Any||i.flags&q.TypeFlags.Unknown?null:i.flags&q.TypeFlags.StringLike?["string"]:i.flags&q.TypeFlags.NumberLike?["number"]:i.flags&q.TypeFlags.BigIntLike?["bigint"]:i.flags&q.TypeFlags.BooleanLike?["boolean"]:i.flags&q.TypeFlags.ESSymbolLike?["symbol"]:i.flags&q.TypeFlags.Undefined||i.flags&q.TypeFlags.Void?["undefined"]:i.flags&q.TypeFlags.Null?["object"]:i.getCallSignatures().length>0?["function"]:i.flags&q.TypeFlags.Object?i.getProperties().length===0?["string","number","bigint","boolean","symbol","object","function"]:["object"]:i.flags&q.TypeFlags.NonPrimitive?["object"]:i.flags&q.TypeFlags.Never?["never"]:null}function a(i){if(!n)return null;let o=t.esTreeNodeToTSNodeMap.get(i),l=n.getTypeAtLocation(o.expression);if(l.flags&q.TypeFlags.Any||l.flags&q.TypeFlags.Unknown)return null;let c=[];if(l.isUnion()){for(let h of l.types){let m=s(h);if(m)c.push(...m);else return null}return c}let f=s(l);return f?(c.push(...f),c):null}function u(i){if(!(i.operator==="==="||i.operator==="!=="))return;let l=null,c=null;if(r(i.left)?(l=i.left,c=i.right.type===Te.Literal&&typeof i.right.value=="string"?i.right.value:null):r(i.right)&&(l=i.right,c=i.left.type===Te.Literal&&typeof i.left.value=="string"?i.left.value:null),!l||!c||!Bn(c,zn))return;let f=a(l);if(!f)return;let h=i.operator==="!==",m=f.includes(c);f.length===1?m&&!h?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:se(l,e),type:c}}):!m&&h?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:se(l,e),type:Array.from(f)[0]}}):!m&&!h?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:se(l,e),actualType:Se(f),conditionType:c}}):m&&h&&e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:se(l,e),actualType:Se(f),conditionType:c}}):!m&&!h?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:se(l,e),actualType:Se(f),conditionType:c}}):!m&&h&&e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:se(l,e),type:Se(f)}})}return{BinaryExpression:u}}})};function Se(e){return Array.from(new Set(e)).join(" | ")||"never"}function se(e,t){let n=e.argument;return n.type===Te.Identifier?n.name:t.sourceCode.getText(n)}function Bn(e,t){return t.has(e)}import{AST_NODE_TYPES as qn,ESLintUtils as Kn}from"@typescript-eslint/utils";var Xn=Kn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Rt="no-call-with-explicit-generics",Jn=_({functions:H(N())}),Gn=Xn({name:Rt,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[Jn]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:s}=r;s.type===qn.Identifier&&n.has(s.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),Me={name:Rt,rule:Gn};import{AST_NODE_TYPES as he,ESLintUtils as Zn}from"@typescript-eslint/utils";var Qn=Zn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),vt="no-call-with-inferred-generics",er=Qn({name:vt,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,[t]){let n=new Map(t.functions.map(r=>[r.name,r]));return{CallExpression(r){let{callee:s}=r;if(s.type!==he.Identifier)return;let a=n.get(s.name);if(!a)return;let{minGenerics:u=1,allowAny:i,disallowTypes:o=t.disallowTypes}=a;(r.typeArguments?.params.length||0)<(u||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:u||0}}),!(i&&!o)&&r.typeArguments?.params?.some(c=>!i&&c.type===he.TSAnyKeyword||o&&c.type===he.TSTypeReference&&c.typeName.type===he.Identifier&&o.includes(c.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),$e={name:vt,rule:er};import{ESLintUtils as tr,TSESTree as Ot}from"@typescript-eslint/utils";var nr=tr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),kt="no-commented-out-code",rr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],ir=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],sr=nr({name:kt,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(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of rr)if(r.startsWith(s))return{wrongPattern:s};for(let s of ir)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let s of r)if(s.type===Ot.AST_TOKEN_TYPES.Line||s.type===Ot.AST_TOKEN_TYPES.Block){let a=t(s.value);a&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:a.wrongPattern}})}}}}}),Ue={name:kt,rule:sr};import{ESLintUtils as or,TSESTree as ar}from"@typescript-eslint/utils";var lr=or.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),At="no-default-export",cr=lr({name:At,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.type===ar.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ve={name:At,rule:cr};import{ESLintUtils as ur}from"@typescript-eslint/utils";var pr=ur.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Pt="no-leaked-text-in-jsx",fr=[",",";","[","]","(",")"],mr=pr({name:Pt,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";fr.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),We={name:Pt,rule:mr};import{AST_NODE_TYPES as oe,ESLintUtils as dr}from"@typescript-eslint/utils";var yr=dr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Nt="no-non-camel-case-functions",gr=/^[a-z][a-zA-Z0-9]*$/;function Ft(e){return e.typeName.type===oe.TSQualifiedName&&e.typeName.left.type===oe.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===oe.Identifier&&e.typeName.right.name==="Element"}var Sr=yr({name:Nt,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&&!gr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===oe.TSTypeReference?Ft(n):n.type===oe.TSUnionType&&n.types.some(s=>s.type===oe.TSTypeReference&&Ft(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),He={name:Nt,rule:Sr};import{ESLintUtils as Tr,TSESTree as U}from"@typescript-eslint/utils";import{AST_NODE_TYPES as Lt}from"@typescript-eslint/utils";function ae(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:ae(e.parent,t,n===1/0?n:n-1)}function*Ye(e){yield e,e.parent&&(yield*Ye(e.parent))}function ze(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function _t(e,t,n){let s=n.getDeclaredVariables(e).find(a=>a.name===t||a.identifiers[0]?.parent.type===Lt.Property&&a.identifiers[0]?.parent.key.type===Lt.Identifier&&a.identifiers[0]?.parent.key.name===t);return s?s.references.filter(a=>!a.init):[]}var hr=Tr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Dt="no-optional-root-props",Er=hr({name:Dt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let a=e.sourceCode.getDeclaredVariables(r)[0];if(!a||a.references.length!==1)return!1;let u=a.references[0];if(!u)return!1;for(let i of Ye(u.identifier)){if("returnType"in i||i.type===U.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let o=i.parent;if(!o)return!1;if(o.type===U.AST_NODE_TYPES.TSTypeParameterInstantiation&&o.parent.type===U.AST_NODE_TYPES.TSTypeReference&&o.parent.typeName.type===U.AST_NODE_TYPES.Identifier&&o.parent.typeName.name==="FC"){let c=ae(o.parent.parent,U.AST_NODE_TYPES.VariableDeclaration,4);if(!c)return!1;let f=Ee(c,e.sourceCode);return f?!(f.parent.type===U.AST_NODE_TYPES.CallExpression&&f.parent.callee.type===U.AST_NODE_TYPES.Identifier&&f.parent.callee.name==="memo"):!1}if(i.type===U.AST_NODE_TYPES.AssignmentPattern)return!1;if(o.type===U.AST_NODE_TYPES.ArrowFunctionExpression){let l=ae(o,U.AST_NODE_TYPES.VariableDeclaration);return l?!!Ee(l,e.sourceCode):!1}if(o.type===U.AST_NODE_TYPES.FunctionDeclaration)return!!Ee(o,e.sourceCode)}return!1}function n(r){r.key.type!==U.AST_NODE_TYPES.Identifier||!r.optional||e.report({node:r.key,messageId:"optionalNotAllowed",data:{propertyName:r.key.name},suggest:[{messageId:"suggestion",fix:s=>{let a=ae(r,U.AST_NODE_TYPES.TSPropertySignature);if(!a)return null;let u=e.sourceCode.getText(a);return s.replaceText(a,u.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(r){if(r.typeAnnotation.type===U.AST_NODE_TYPES.TSTypeLiteral&&!(be(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===U.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(be(r)||!t(r)))for(let s of r.body.body)s.type===U.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSTypeReference(r){if(r.typeName.type!==U.AST_NODE_TYPES.Identifier||r.typeName.name!=="FC"||!r.typeArguments?.params[0])return;let s=r.typeArguments.params[0];if(s.type!==U.AST_NODE_TYPES.TSTypeLiteral)return;let a=ae(r.parent,U.AST_NODE_TYPES.VariableDeclaration,4);if(!a)return;let u=Ee(a,e.sourceCode);if(!(!u||u.parent.type===U.AST_NODE_TYPES.CallExpression&&u.parent.callee.type===U.AST_NODE_TYPES.Identifier&&u.parent.callee.name==="memo"))for(let o of s.members)o.type===U.AST_NODE_TYPES.TSPropertySignature&&n(o)}}}});function be(e){return e?e.parent?.type===U.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===U.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function Ee(e,t){if(be(e))return;let n;if(e.type===U.AST_NODE_TYPES.VariableDeclaration){if(e.declarations.length!==1)return;e.declarations[0].id.type===U.AST_NODE_TYPES.Identifier&&(n=e.declarations[0].id)}else{if(!e.id)return;n=e.id}if(!n)return;let r=t.getScope(e);e.type===U.AST_NODE_TYPES.FunctionDeclaration&&r.upper&&(r=r.upper);let s=r.variables.find(u=>u.identifiers.includes(n));if(!s)return;let a=s.references.filter(u=>u.identifier!==n);if(!(a.length!==1||!a[0])&&!be(a[0].identifier.parent.parent))return a[0].identifier}var Be={name:Dt,rule:Er};import{ESLintUtils as br}from"@typescript-eslint/utils";import qe from"node:path";var xr=br.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),jt="no-relative-imports",Cr=_({find:N(),replacement:N()}),Ir=_({aliases:H(Cr),rootDir:F(N()),allowNotFoundAliases:F(ie()),_dev_simulateFileName:F(N())}),wr=xr({name:jt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[Ir]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(u){return u.startsWith(".")||u.startsWith("..")}function s(u,i){let o=qe.dirname(i);return qe.resolve(o,u)}function a(u){let i=t.rootDir??process.cwd(),o=qe.relative(i,u);if(o.startsWith("."))return null;o.startsWith("/")||(o=`/${o}`);for(let{find:l,replacement:c}of t.aliases)if(o.startsWith(c)){let f=o.replace(c,l);return{alias:l,newPath:f}}return null}return{ImportDeclaration(u){let i=u.source.value;if(!r(i))return;let o=s(i,n),l=a(o);!l&&t.allowNotFoundAliases||e.report({node:u,messageId:l?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:l?.alias},fix:l?c=>c.replaceText(u.source,`'${l.newPath}'`):void 0})}}}}),Ke={name:jt,rule:wr};import{AST_NODE_TYPES as ue,ESLintUtils as $t}from"@typescript-eslint/utils";import*as Xe from"typescript";var Rr=$t.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Mt="no-unnecessary-casting",vr=_({additionalCastFunctions:F(H(_({name:N(),expectedType:ye(["string","number"])})))}),Je={name:Mt,rule:Rr({name:Mt,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[vr],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=$t.getParserServices(e,!0),a=s.program?.getTypeChecker();if(!a||!s.program)throw new Error("TypeScript services or program not available");function u(c,f){switch(c.type){case ue.Literal:return f==="number"?typeof c.value=="number":typeof c.value=="string";case ue.TemplateLiteral:return f==="string";case ue.UnaryExpression:return f==="number"?c.operator==="+"||c.operator==="-"||c.operator==="~":!1;default:return!1}}function i(c,f){return f==="number"?!!(c.flags&Xe.TypeFlags.NumberLike):!!(c.flags&Xe.TypeFlags.StringLike)}function o(c,f){return h=>h.replaceText(c,e.sourceCode.getText(f))}function l(c){if(!a||c.arguments.length!==1)return;let f=c.arguments[0];if(!f||f.type===ue.SpreadElement)return;let{callee:h}=c;if(h.type!==ue.Identifier)return;let m=h.name,y=r.find(E=>E.name===m);if(!y)return;if(u(f,y.expectedType)||i(a.getTypeAtLocation(s.esTreeNodeToTSNodeMap.get(f)),y.expectedType)){let E,g;m==="Number"?E="unnecessaryNumberCasting":m==="String"?E="unnecessaryStringCasting":(E="unnecessaryCustomCasting",g={name:y.name,type:y.expectedType}),e.report({node:c,messageId:E,...g?{data:g}:{},fix:o(c,f)})}}return{CallExpression:l}}})};import{AST_NODE_TYPES as W,ESLintUtils as Or}from"@typescript-eslint/utils";var kr=_({selectors:H(_({name:N(),selectorProp:F(N()),selectorArgPos:F(J()),returnProp:F(N())}))}),Ar=Or.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ut="no-unused-selected-values",Ge={name:Ut,rule:Ar({name:Ut,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[kr]},defaultOptions:[{selectors:[]}],create(e,[t]){let{selectors:n=[]}=t,r=new Map(n.map(s=>[s.name,s]));return{VariableDeclarator(s){let a=null;if(s.init?.type===W.CallExpression&&(a=s.init),!a)return;let u=Fr(a);if(!u)return;let i=r.get(u);if(!i)return;let o=Pr(a,i.selectorArgPos??0,i.selectorProp);if(!o)return;let l=Nr(o);if(!l)return;let c=Vt(l.properties,void 0);if(!c)return;if(s.id.type===W.ObjectPattern){let m=Vt(s.id.properties,i.returnProp);if(!m)return;for(let[y,T]of c)m.has(y)||e.report({node:T,messageId:"unusedSelectedValue",data:{name:y}});return}if(s.id.type!==W.Identifier||i.returnProp)return;let f=Lr(s,e.sourceCode);if(f.length===0)return;let h=new Set;for(let m of f){if(m.identifier.parent.type!==W.MemberExpression)return;let y=m.identifier.parent.property;if(y.type!==W.Identifier)return;h.add(y.name)}for(let[m,y]of c)h.has(m)||e.report({node:y,messageId:"unusedSelectedValue",data:{name:m}})}}}})};function Pr(e,t,n){let r=e.arguments[t];if(!r)return null;if(r.type===W.ArrowFunctionExpression||r.type===W.FunctionExpression)return r;if(n&&r.type===W.ObjectExpression){let s=r.properties.find(u=>u.type===W.Property&&u.key.type===W.Identifier&&u.key.name===n);if(s?.type!==W.Property)return null;let a=s.value;if(a.type===W.ArrowFunctionExpression||a.type===W.FunctionExpression)return a}return null}function Fr(e){return e.callee.type===W.Identifier?e.callee.name:e.callee.type===W.MemberExpression&&e.callee.property.type===W.Identifier?e.callee.property.name:null}function Nr(e){if(e.body.type===W.ObjectExpression)return e.body;if(e.body.type===W.BlockStatement){let t=e.body.body.filter(n=>n.type===W.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==W.ObjectExpression?null:t[0].argument}return null}function Vt(e,t){let n=e;if(t){let s=e.find(a=>a.type===W.Property&&a.key.type===W.Identifier&&a.key.name===t);if(s?.type!==W.Property||s.value.type!==W.ObjectPattern)return null;n=s.value.properties}let r=new Map;for(let s of n){if(s.type!==W.Property||s.key.type!==W.Identifier)return null;r.set(s.key.name,s)}return r.size>0?r:null}function Lr(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}import{AST_NODE_TYPES as V}from"@typescript-eslint/utils";var Ze=ge({name:"no-unused-t-state-field",meta:{type:"suggestion",docs:{description:"Prevent declaring unused t-state fields"},messages:{unusedField:'Field "{{name}}" is not being used, you can safely remove it'},schema:[]},defaultOptions:[],create(e){if(!(e.filename.endsWith(".jsx")||e.filename.endsWith(".tsx")))return{};if(!e.sourceCode.ast.body.some(a=>a.type===V.ImportDeclaration&&a.source.value==="t-state-form"))return{};let r=null,s=!1;return{CallExpression(a){if(s)return;if(!r){let i=_r(a);i&&(r=i);return}let u=Dr(a,e.sourceCode);if(u){s=!0;for(let i of u)r.delete(i);if(r.size!==0)for(let[i,o]of r)e.report({node:o,messageId:"unusedField",data:{name:i}})}}}}});function _r(e){if(!(e.callee.type===V.Identifier&&e.callee.name==="useForm"))return null;let n=e.arguments[0];if(!n||n.type!==V.ObjectExpression)return null;let r=ze(n.properties,a=>a.type!==V.Property||a.key.type!==V.Identifier||a.key.name!=="initialConfig"?null:a.value.type===V.ObjectExpression?a.value:a.value.type===V.ArrowFunctionExpression||a.value.type===V.FunctionExpression?jr(a.value):null);if(!r)return null;let s=new Map;for(let a of r.properties)a.type===V.Property&&a.key.type===V.Identifier&&s.set(a.key.name,a);return s}function Dr(e,t){if(!(e.callee.type===V.Identifier&&e.callee.name==="useFormState")||e.parent.type!==V.VariableDeclarator||e.parent.id.type!==V.ObjectPattern||!ze(e.parent.id.properties,u=>u.type===V.Property&&u.key.type===V.Identifier&&u.key.name==="formFields"&&u))return null;let s=_t(e.parent,"formFields",t),a=new Set;for(let{identifier:u}of s){if(u.type!==V.Identifier||u.parent.type===V.Property&&u.parent.parent.type===V.ObjectExpression&&u.parent.parent.parent.type===V.ReturnStatement||u.parent.type===V.ReturnStatement)return null;if(u.parent.type===V.MemberExpression){if(u.parent.object.type!==V.Identifier||u.parent.property.type!==V.Identifier)return null;a.add(u.parent.property.name)}}return a}function jr(e){if(e.body.type===V.ObjectExpression)return e.body;if(e.body.type===V.BlockStatement){let t=e.body.body.filter(n=>n.type===V.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==V.ObjectExpression?null:t[0].argument}return null}import{AST_NODE_TYPES as $,ESLintUtils as Mr}from"@typescript-eslint/utils";var $r=Mr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Wt(e){let t=[];for(let n of e.members)n.type===$.TSPropertySignature&&n.key.type===$.Identifier&&t.push([n.key.name,n]);return t}function Ht(e,...t){for(let n of t)e.set(...n);return e}var Ur=_({forceCheckOnFCPropTypesWithName:F(H(N()))}),Yt="no-unused-type-props-in-args",Qe=null,Vr=$r({name:Yt,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:[Ur],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!Qe&&(Qe=n.map(i=>new RegExp(i)));function r(i,o,l,c,f=!0){let h=l.name,m=e.sourceCode.getScope(o).references.find(E=>E.identifier.name===h)?.resolved,y=i&&Qe?.some(E=>E.test(h));if(!m||!y&&m.references.filter(E=>E.isTypeReference).length>1)return;let T=m?.defs[0]?.node;if(!(f&&T?.parent?.type===$.ExportNamedDeclaration)){if(T?.type===$.TSTypeAliasDeclaration){s(i,o,c,T.typeAnnotation,!0);return}if(T?.type===$.TSInterfaceDeclaration){s(i,o,c,T.body,!0);return}}}function s(i,o,l,c,f){if(c.type===$.TSInterfaceBody){for(let h of c.body)h.type===$.TSPropertySignature&&h.key.type===$.Identifier&&l.set(h.key.name,h);return}if(c.type===$.TSTypeLiteral){Ht(l,...Wt(c));return}if(c.type===$.TSIntersectionType){for(let h of c.types)s(i,o,l,h,!0);return}f||c.type===$.TSTypeReference&&c.typeName.type===$.Identifier&&r(i,o,c.typeName,l)}function a(i,o,l){for(let c of l)if(c.type==="ObjectPattern"&&c.typeAnnotation){let f=new Map;if(s(i,o,f,c.typeAnnotation.typeAnnotation,!1),f.size===0)continue;u(c,f)}else c.type===$.AssignmentPattern&&c.left.type===$.ObjectPattern&&a(i,o,[c.left])}function u(i,o){let l=[];if(i.properties.at(-1)?.type===$.RestElement)return;for(let m of i.properties)m.type===$.Property&&m.key.type===$.Identifier&&l.push(m.key.name);let f=[],h=[];for(let[m,y]of o)l.includes(m)||(h.push(m),f.push({node:y,messageId:"unusedObjectTypeProperty",data:{propertyName:m}}));for(let[m,y]of f.entries())e.report({...y,fix:m===f.length-1?T=>{let E=i.properties.at(-1),g=h.join(", ");return E?E?.type===$.RestElement?null:T.insertTextAfter(E,`, ${g}`):T.insertTextBeforeRange([i.range[0]+1,i.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(i){let o=i.declarations[0];if(!o)return;let l=new Map,c=o.id.type===$.Identifier&&o.id.typeAnnotation?.typeAnnotation.type===$.TSTypeReference&&o.id.typeAnnotation.typeAnnotation.typeName.type===$.Identifier&&o.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&o.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(c){if(c.type===$.TSTypeReference&&c.typeName.type===$.Identifier)r(!0,i,c.typeName,l,!1);else if(c.type===$.TSTypeLiteral)Ht(l,...Wt(c));else if(c.type===$.TSIntersectionType)for(let f of c.types)f.type===$.TSTypeReference&&f.typeName.type===$.Identifier?r(!0,i,f.typeName,l,!1):s(!0,i,l,f,!0);if(l.size!==0&&o.init?.type===$.ArrowFunctionExpression){let f=o.init.params[0];if(!f){e.report({node:o.init,messageId:"missingComponentParam"});return}f.type===$.ObjectPattern&&u(f,l)}}},FunctionDeclaration:function(i){a(!1,i,i.params)},ArrowFunctionExpression(i){a(!1,i,i.params)}}}}),et={name:Yt,rule:Vr};import{AST_NODE_TYPES as tt,ESLintUtils as Wr}from"@typescript-eslint/utils";var Hr=Wr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Bt="prefer-named-functions",zt=new Map,Yr=Hr({name:Bt,meta:{hasSuggestions:!0,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:{suggestion:"Convert to named function",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,[t]){let n=null;if(t.ignoreRegex){let r=zt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),zt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===tt.ArrowFunctionExpression&&r.id.type===tt.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==tt.BlockStatement)return;let a=r.parent,u=r.init.params,i=r.init.body,o=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:l=>l.replaceText(a,`${o.async?"async ":""}function ${s}(${u.map(c=>e.sourceCode.getText(c)).join(", ")||""}) ${e.sourceCode.getText(i)}`)}]})}}}}}),nt={name:Bt,rule:Yr};import{AST_NODE_TYPES as Y,AST_TOKEN_TYPES as qt,ESLintUtils as zr}from"@typescript-eslint/utils";var Br=zr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Xt="prefer-single-line-if",qr=_({maxLineLength:F(J()),maxNonSimpleConditionLength:F(J())}),Kr=Br({name:Xt,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[qr]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==Y.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let a=r.consequent.body[0];if(a.type===Y.ReturnStatement){if(!Gt(a))return}else if(!(a.type===Y.ContinueStatement||a.type===Y.BreakStatement))return;if(r.test.type===Y.LogicalExpression||r.test.type===Y.ConditionalExpression)return;let u;if(t.maxNonSimpleConditionLength){let f=Kt(r.test);if(!f&&r.test.type===Y.UnaryExpression&&r.test.operator==="!"){let h=r.test.argument;Kt(h)&&(f=!0)}if(f&&(u=n.getText(r.test),u.length>t.maxNonSimpleConditionLength))return}u||(u=n.getText(r.test));let i=n.getText(a);if(u.includes(`
|
|
15
|
-
`))return;let o=n.getTokenAfter(r);if(o&&o.type===qt.Punctuator&&o.value==="}"){let f=n.getTokenAfter(o);if(f&&f.type===qt.Keyword&&(f.value==="else"||f.value==="catch"))return}let l=Xr(n,r),c=`if (${u}) ${i}`;t.maxLineLength&&c.length+l.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:f=>f.replaceText(r,c)})}}}});function Kt(e){return e.type===Y.CallExpression||e.type===Y.BinaryExpression||e.type===Y.MemberExpression&&Jt(e)}function Jt(e){return e.object.type===Y.MemberExpression?Jt(e.object):e.object.type!==Y.Identifier}function Xr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function Gt(e){if(!e.argument)return!0;let t=e.argument;return t.type===Y.ArrayExpression&&t.elements.length===0||t.type===Y.ObjectExpression&&t.properties.length===0||t.type===Y.Literal||t.type===Y.Identifier||t.type===Y.TemplateLiteral||t.type===Y.TaggedTemplateExpression?!0:t.type===Y.CallExpression?t.arguments.length===0:t.type===Y.UnaryExpression?Gt(t):!1}var rt={name:Xt,rule:Kr};import{AST_NODE_TYPES as G,ESLintUtils as Jr}from"@typescript-eslint/utils";var Gr=Jr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Zt="react-compiler-migration",Zr=_({disallowHooks:F(H(_({name:N(),replacement:N()}))),disallowMethods:F(H(_({name:N(),replacement:F(N()),requireTrueProp:F(N())})))}),Qr=/eslint +react-compiler\/react-compiler: +\["error/;function ei(e){return e.type===G.Identifier?e.name.startsWith("use"):e.type===G.MemberExpression&&e.property.type===G.Identifier?e.property.name.startsWith("use"):!1}var ti=Gr({name:Zt,meta:{type:"suggestion",fixable:"code",docs:{description:"Rules to help migrate to the new React compiler"},messages:{disallowedFunctionOrMethod:"{{functionOrMethod}} is not supported in react compiler. Use {{replacement}} instead.",replace:"Replace with safe alternative {{replacement}}",disallowedMethodWithMissingRequireTrueProp:"{{method}} is should have a prop named {{requireTrueProp}} set to true when used in react compiler."},hasSuggestions:!0,schema:[Zr]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(Qr.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let s=null,a=null;if(r.callee.type===G.Identifier?(s=r.callee.name,a=r.callee):r.callee.type===G.MemberExpression&&r.callee.property.type===G.Identifier&&(s=r.callee.property.name,a=r.callee.property),s){let u=t.disallowHooks.find(i=>i.name===s);u&&a&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:u.name,replacement:u.replacement},suggest:[{messageId:"replace",data:{replacement:u.replacement},fix:i=>i.replaceText(a,u.replacement)}]})}}if(t.disallowMethods?.length&&ei(r.callee)){for(let s of r.arguments)if(s.type===G.ObjectExpression){for(let a of s.properties)if(a.type===G.Property&&a.key.type===G.Identifier){let u=a.key.name,i=t.disallowMethods.find(o=>o.name===u);if(i){if(i.requireTrueProp){let o=i.requireTrueProp,l=!1;for(let c of s.properties)if(c.type===G.Property&&c.key.type===G.Identifier&&c.key.name===o&&c.value.type===G.Literal&&c.value.value===!0){l=!0;break}if(!l){e.report({node:a,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:i.name,requireTrueProp:o}});continue}}i.replacement&&e.report({node:a,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:i.name,replacement:i.replacement},suggest:[{messageId:"replace",data:{replacement:i.replacement},fix:o=>o.replaceText(a.key,i.replacement)}]})}}}}}}:{}}}),it={name:Zt,rule:ti};import{ESLintUtils as ni,TSESTree as ri}from"@typescript-eslint/utils";var ii=ni.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qt="require-description",si=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,oi=/^eslint-disable-(next-)?line$/u,ai=ii({name:Qt,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,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let a=li(s);a!=null&&(r.has(a.kind)||a.description||e.report({loc:ui(s.loc),messageId:"missingDescription"}))}}}}}),en={name:Qt,rule:ai};function li(e){let{text:t,description:n}=ci(e.value);if(!t)return null;let r=si.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let a=oi.test(s);if(e.type===ri.AST_TOKEN_TYPES.Line&&!a||a&&e.loc.start.line!==e.loc.end.line)return null;let u=t.slice(r.index+s.length);return{kind:s,value:u.trim(),description:n}}function ci(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function ui(e){return{start:{line:e.start.line,column:-1},end:e.end}}function rn(e){return/^use[A-Z0-9]/.test(e)}function xe(e){return e.type==="Identifier"?rn(e.name):e.type==="MemberExpression"&&!e.computed&&xe(e.property)?e.object.type==="Identifier":!1}function sn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function on(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function an(e){return!!(e.parent&&e.parent.callee&&on(e.parent.callee,"forwardRef"))}function ln(e){return!!(e.parent&&e.parent.callee&&on(e.parent.callee,"memo"))}function st(e){for(;e;){let t=un(e);if(t&&(sn(t)||xe(t))||an(e)||ln(e))return!0;e=e.parent}return!1}function tn(e){return!1}function ot(e){return!1}var pi=/eslint +react-compiler\/react-compiler: +\["error/,cn={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 o of e.sourceCode.getAllComments())if(pi.test(o.value))return{CallExpression(l){let c=null;l.callee.name==="useMemo"?c="useMemo":l.callee.name==="useCallback"&&(c="useCallback"),c&&e.report({node:l,message:`"${c}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?o=>t(o):o=>e.sourceCode.getText(o),n=typeof e.getScope=="function"?()=>n():o=>e.sourceCode.getScope(o),r=null,s=[],a=[],u=new WeakSet;function i(o){for(let l of o.references){let c=l.identifier.parent;if(c.type==="VariableDeclarator"&&c.init&&c.init.type==="CallExpression"&&c.init.callee&&tn(c.init.callee))for(let f of l.resolved.references)f!==l&&u.add(f.identifier)}}return{onCodePathSegmentStart:o=>a.push(o),onCodePathSegmentEnd:()=>a.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(o,l){let c=s.pop();if(c.size===0)return;let f=new Set;function h(S,v){let{cache:A}=h,L=A.get(S.id),D=new Set(v);if(D.has(S.id)){let R=[...D],j=R.slice(R.indexOf(S.id)+1);for(let z of j)f.add(z);return BigInt("0")}if(D.add(S.id),L!==void 0)return L;if(o.thrownSegments.includes(S))L=BigInt("0");else if(S.prevSegments.length===0)L=BigInt("1");else{L=BigInt("0");for(let R of S.prevSegments)L+=h(R,D)}return S.reachable&&L===BigInt("0")?A.delete(S.id):A.set(S.id,L),L}function m(S,v){let{cache:A}=m,L=A.get(S.id),D=new Set(v);if(D.has(S.id)){let R=Array.from(D),j=R.slice(R.indexOf(S.id)+1);for(let z of j)f.add(z);return BigInt("0")}if(D.add(S.id),L!==void 0)return L;if(o.thrownSegments.includes(S))L=BigInt("0");else if(S.nextSegments.length===0)L=BigInt("1");else{L=BigInt("0");for(let R of S.nextSegments)L+=m(R,D)}return A.set(S.id,L),L}function y(S){let{cache:v}=y,A=v.get(S.id);if(A===null)return 1/0;if(A!==void 0)return A;if(v.set(S.id,null),S.prevSegments.length===0)A=1;else{A=1/0;for(let L of S.prevSegments){let D=y(L);D<A&&(A=D)}A+=1}return v.set(S.id,A),A}h.cache=new Map,m.cache=new Map,y.cache=new Map;let T=m(o.initialSegment),E=un(l),g=st(l),O=E?sn(E)||xe(E):an(l)||ln(l),C=1/0;for(let S of o.finalSegments){if(!S.reachable)continue;let v=y(S);v<C&&(C=v)}for(let[S,v]of c){if(!S.reachable)continue;let A=S.nextSegments.length===0?C<=y(S):C<y(S),L=h(S)*m(S),D=f.has(S.id);for(let R of v)if(D&&!ot(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.`}),O){if(l.async&&e.report({node:R,message:`React Hook "${t(R)}" cannot be called in an async function.`}),!D&&L!==T&&!ot(R)){let z=`React Hook "${t(R)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(A?" Did you accidentally call a React Hook after an early return?":"");e.report({node:R,message:z})}}else if(l.parent&&(l.parent.type==="MethodDefinition"||l.parent.type==="ClassProperty")&&l.parent.value===l){let j=`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:j})}else if(E){let j=`React Hook "${t(R)}" is called in function "${t(E)}" 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:j})}else if(l.type==="Program"){let j=`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:j})}else if(g&&!ot(R)){if(l.parent.type==="CallExpression"&&l.parent.callee.type==="Identifier"&&l.parent.callee.name==="useCallback"){let z=l.parent;if(z.parent.type==="VariableDeclarator"&&rn(z.parent.id.name))return}let j=`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:j})}}},CallExpression(o){if(xe(o.callee)){let l=nn(s),c=nn(a),f=l.get(c);f||(f=[],l.set(c,f)),f.push(o.callee)}o.callee.type==="Identifier"&&(o.callee.name==="useEffect"||tn(o.callee))&&o.arguments.length>0&&(r=o)},Identifier(o){r==null&&u.has(o)&&o.parent.type!=="CallExpression"&&e.report({node:o,message:`\`${t(o)}\` 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"(o){o===r&&(r=null)},FunctionDeclaration(o){st(o)&&i(n(o))},ArrowFunctionExpression(o){st(o)&&i(n(o))}}}};function un(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 nn(e){return e[e.length-1]}var pn={[et.name]:et.rule,[Ue.name]:Ue.rule,[$e.name]:$e.rule,"rules-of-hooks":cn,"exhaustive-deps":Et,"require-description":en.rule,[Ve.name]:Ve.rule,[He.name]:He.rule,[nt.name]:nt.rule,[Pe.name]:Pe.rule,[Me.name]:Me.rule,[Ke.name]:Ke.rule,[rt.name]:rt.rule,[Be.name]:Be.rule,[We.name]:We.rule,[Ne.name]:Ne.rule,[it.name]:it.rule,[ke.name]:ke.rule,[je.name]:je.rule,[Je.name]:Je.rule,[Ge.name]:Ge.rule,[Ze.name]:Ze.rule};var io={rules:pn};export{io as extendedLintPlugin};
|
|
14
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let F=l.acquire(g),L=new Set,_=null;{let u=F.upper;for(;u&&(L.add(u),u.type!=="function");)u=u.upper;if(!u)return;_=u}let R=Array.isArray;function M(u){if(!R(u.defs))return!1;let d=u.defs[0];if(d==null||d.node.type!=="VariableDeclarator")return!1;let b=d.node.init;if(b==null)return!1;for(;b.type==="TSAsExpression";)b=b.expression;let x=d.node.parent;if(x==null&&($e(_.block,d.node.id),x=d.node.parent,x==null))return!1;if(x.kind==="const"&&b.type==="Literal"&&(typeof b.value=="string"||typeof b.value=="number"||b.value===null))return!0;if(b.type!=="CallExpression")return!1;let w=b.callee;if(w.type==="MemberExpression"&&w.object.name==="React"&&w.property!=null&&!w.computed&&(w=w.property),w.type!=="Identifier")return!1;let C=d.node.id,{name:P}=w;if(P==="useRef"&&C.type==="Identifier")return!0;if(Zn(w)&&C.type==="Identifier"){for(let D of u.references)D!==C&&m.add(D.identifier);return!0}else if(P==="useState"||P==="useReducer"){if(C.type==="ArrayPattern"&&C.elements.length===2&&R(u.identifiers)){if(C.elements[1]===u.identifiers[0]){if(P==="useState"){let D=u.references,G=0;for(let ne=0;ne<D.length;ne++){if(D[ne].isWrite()&&G++,G>1)return!1;c.set(D[ne].identifier,C.elements[0])}}return!0}else if(C.elements[0]===u.identifiers[0]){if(P==="useState"){let D=u.references;for(let G=0;G<D.length;G++)p.add(D[G].identifier)}return!1}}}else if(P==="useTransition"&&C.type==="ArrayPattern"&&C.elements.length===2&&Array.isArray(u.identifiers)&&C.elements[1]===u.identifiers[0])return!0;return!1}function B(u){if(!R(u.defs))return!1;let d=u.defs[0];if(d==null||d.node==null||d.node.id==null)return!1;let b=d.node,x=_.childScopes,w=null,C;for(C=0;C<x.length;C++){let P=x[C],D=P.block;if(b.type==="FunctionDeclaration"&&D===b||b.type==="VariableDeclarator"&&D.parent===b){w=P;break}}if(w==null)return!1;for(C=0;C<w.through.length;C++){let P=w.through[C];if(P.resolved!=null&&L.has(P.resolved.scope)&&!de(P.resolved))return!1}return!0}let de=y(M,f),In=y(B,h),mt=new Map;function Cn(u){let d=u.from,b=!1;for(;d.block!==g;)d.type==="function"&&(b=d.block.parent!=null&&d.block.parent.type==="ReturnStatement"),d=d.upper;return b}let J=new Map,Re=new Map;dt(F);function dt(u){for(let d of u.references){if(!d.resolved||!L.has(d.resolved.scope))continue;let b=$e(g,d.identifier),x=kt(b),w=re(x,Re);if(k&&x.type==="Identifier"&&(x.parent.type==="MemberExpression"||x.parent.type==="OptionalMemberExpression")&&!x.parent.computed&&x.parent.property.type==="Identifier"&&x.parent.property.name==="current"&&Cn(d)&&mt.set(w,{reference:d,dependencyNode:x}),x.parent.type==="TSTypeQuery"||x.parent.type==="TSTypeReference")continue;let C=d.resolved.defs[0];if(C!=null&&!(C.node!=null&&C.node.init===g.parent)&&C.type!=="TypeParameter")if(J.has(w))J.get(w).references.push(d);else{let P=d.resolved,D=de(P)||In(P);J.set(w,{isStable:D,references:[d]})}}for(let d of u.childScopes)dt(d)}mt.forEach(({reference:u,dependencyNode:d},b)=>{let x=u.resolved.references,w=!1;for(let C=0;C<x.length;C++){let{identifier:P}=x[C],{parent:D}=P;if(D!=null&&D.type==="MemberExpression"&&!D.computed&&D.property.type==="Identifier"&&D.property.name==="current"&&D.parent.type==="AssignmentExpression"&&D.parent.left===D){w=!0;break}}w||i({node:d.parent.property,message:`The ref value '${b}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${b}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let ke=new Set;function wn(u,d){ke.has(d)||(ke.add(d),i({node:u,message:`Assignments to the '${d}' variable from inside React Hook ${n(I)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(I)}.`}))}let ye=new Set;if(J.forEach(({isStable:u,references:d},b)=>{u&&ye.add(b),d.forEach(x=>{x.writeExpr&&wn(x.writeExpr,b)})}),ke.size>0)return;if(!v){let u=null;if(J.forEach(({isStable:d,references:b},x)=>{u||b.forEach(w=>{if(u)return;let C=w.identifier;if(!c.has(C))return;let D=w.from;for(;D.type!=="function";)D=D.upper;D.block===g&&(u=x)})}),u){let{suggestedDependencies:d}=_e({dependencies:J,declaredDependencies:[],stableDependencies:ye,externalDependencies:new Set,isEffect:!0});i({node:I,message:`React Hook ${S} contains a call to '${u}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+d.join(", ")+`] as a second argument to the ${S} Hook.`,suggest:[{desc:`Add dependencies array: [${d.join(", ")}]`,fix(b){return b.insertTextAfter(g,`, [${d.join(", ")}]`)}}]})}return}let ue=[],fe=new Set;v.type!=="ArrayExpression"?i({node:v,message:`React Hook ${n(I)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):v.elements.forEach(u=>{if(u===null)return;if(u.type==="SpreadElement"){i({node:u,message:`React Hook ${n(I)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}m.has(u)&&i({node:u,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(u)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(u)}\``,fix(w){return w.removeRange(u.range)}}]});let d;try{d=re(u,Re)}catch(w){if(/Unsupported node type/.test(w.message)){u.type==="Literal"?J.has(u.value)?i({node:u,message:`The ${u.raw} literal is not a valid dependency because it never changes. Did you mean to include ${u.value} in the array instead?`}):i({node:u,message:`The ${u.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):i({node:u,message:`React Hook ${n(I)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw w}let b=u;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let x=!_.through.some(w=>w.identifier===b);ue.push({key:d,node:u}),x||fe.add(d)});let{suggestedDependencies:Rn,unnecessaryDependencies:ge,missingDependencies:ie,duplicateDependencies:yt}=_e({dependencies:J,declaredDependencies:ue,stableDependencies:ye,externalDependencies:fe,isEffect:k}),Se=Rn;if(yt.size+ie.size+ge.size===0){if(t)return;Xn({declaredDependencies:ue,declaredDependenciesNode:v,componentScope:_,scope:F}).forEach(({construction:d,isUsedOutsideOfHook:b,depType:x})=>{let w=x==="function"?"useCallback":"useMemo",C=x==="function"?"definition":"initialization",P=`wrap the ${C} of '${d.name.name}' in its own ${w}() Hook.`,D=b?`To fix this, ${P}`:`Move it inside the ${S} callback. Alternatively, ${P}`,G=x==="conditional"||x==="logical expression"?"could make":"makes",ne=`The '${d.name.name}' ${x} ${G} the dependencies of ${S} Hook (at line ${v.loc.start.line}) change on every render. ${D}`,gt;b&&d.type==="Variable"&&x==="function"&&(gt=[{desc:`Wrap the ${C} of '${d.name.name}' in its own ${w}() Hook.`,fix(St){let[vn,On]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[St.insertTextBefore(d.node.init,vn),St.insertTextAfter(d.node.init,On)]}}]),i({node:d.node,message:ne,suggest:gt})});return}!k&&ie.size>0&&(Se=_e({dependencies:J,declaredDependencies:[],stableDependencies:ye,externalDependencies:fe,isEffect:k}).suggestedDependencies);function kn(){if(ue.length===0)return!0;let u=ue.map(b=>b.key),d=u.slice().sort();return u.join(",")===d.join(",")}kn()&&Se.sort();function ve(u){let d=u.split("."),b="";for(let x=0;x<d.length;x++){if(x!==0){let w=d.slice(0,x+1).join("."),C=Re.get(w)===!0;b+=C?"?.":"."}b+=d[x]}return b}function Oe(u,d,b,x){return u.size===0?null:(u.size>1?"":d+" ")+b+" "+(u.size>1?"dependencies":"dependency")+": "+Jn(Array.from(u).sort().map(w=>"'"+ve(w)+"'"))+`. Either ${x} ${u.size>1?"them":"it"} or remove the dependency array.`}let te="";if(ge.size>0){let u=null;if(Array.from(ge.keys()).forEach(d=>{u===null&&d.endsWith(".current")&&(u=d)}),u!==null)te=` Mutable values like '${u}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(fe.size>0){let d=Array.from(fe)[0];F.set.has(d)||(te=` Outer scope values like '${d}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!te&&ie.has("props")){let u=J.get("props");if(u==null)return;let d=u.references;if(!Array.isArray(d))return;let b=!0;for(let x=0;x<d.length;x++){let w=d[x],C=$e(_.block,w.identifier);if(!C){b=!1;break}let P=C.parent;if(P==null){b=!1;break}if(P.type!=="MemberExpression"&&P.type!=="OptionalMemberExpression"){b=!1;break}}b&&(te=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${S} call and refer to those specific props inside ${n(I)}.`)}if(!te&&ie.size>0){let u=null;ie.forEach(d=>{if(u)return;let b=_.set.get(d),x=J.get(d);if(x.references[0].resolved!==b)return;let w=b.defs[0];if(w==null||w.name==null||w.type!=="Parameter")return;let C=!1,P;for(let D=0;D<x.references.length;D++)if(P=x.references[D].identifier,P!=null&&P.parent!=null&&(P.parent.type==="CallExpression"||P.parent.type==="OptionalCallExpression")&&P.parent.callee===P){C=!0;break}C&&(u=d)}),u!==null&&(te=` If '${u}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!te&&ie.size>0){let u=null;if(ie.forEach(d=>{if(u!==null)return;let x=J.get(d).references,w,C;for(let P=0;P<x.length;P++){for(w=x[P].identifier,C=w.parent;C!=null&&C!==_.block;){if(C.type==="CallExpression"){let D=c.get(C.callee);if(D!=null){if(D.name===d)u={missingDep:d,setter:C.callee.name,form:"updater"};else if(p.has(w))u={missingDep:d,setter:C.callee.name,form:"reducer"};else{let G=x[P].resolved;if(G!=null){let ne=G.defs[0];ne!=null&&ne.type==="Parameter"&&(u={missingDep:d,setter:C.callee.name,form:"inlineReducer"})}}break}}C=C.parent}if(u!==null)break}}),u!==null)switch(u.form){case"reducer":te=` You can also replace multiple useState variables with useReducer if '${u.setter}' needs the current value of '${u.missingDep}'.`;break;case"inlineReducer":te=` If '${u.setter}' needs the current value of '${u.missingDep}', you can also switch to useReducer instead of useState and read '${u.missingDep}' in the reducer.`;break;case"updater":te=` You can also do a functional update '${u.setter}(${u.missingDep.slice(0,1)} => ...)' if you only need '${u.missingDep}' in the '${u.setter}' call.`;break;default:throw new Error("Unknown case.")}}i({node:v,message:`React Hook ${n(I)} has `+(Oe(ie,"a","missing","include")||Oe(ge,"an","unnecessary","exclude")||Oe(yt,"a","duplicate","omit"))+te,suggest:[{desc:`Update the dependencies array to be: [${Se.map(ve).join(", ")}]`,fix(u){return u.replaceText(v,`[${Se.map(ve).join(", ")}]`)}}]})}function E(g){let v=Kn(g.callee,o);if(v===-1)return;let I=g.arguments[v],S=g.callee,k=vt(S).name,F=g.arguments[v+1],L=/Effect($|[^a-z])/g.test(k);if(!I){i({node:S,message:`React Hook ${k} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!L)){if(!F&&!L){(k==="useMemo"||k==="useCallback")&&i({node:S,message:`React Hook ${k} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(I.type){case"FunctionExpression":case"ArrowFunctionExpression":T(I,F,S,k,L);return;case"Identifier":if(!F||F.elements&&F.elements.some(M=>M&&M.type==="Identifier"&&M.name===I.name))return;let _=r(g).set.get(I.name);if(_==null||_.defs==null)return;let R=_.defs[0];if(!R||!R.node||R.type!=="Variable"&&R.type!=="FunctionName")break;switch(R.node.type){case"FunctionDeclaration":T(R.node,F,S,k,L);return;case"VariableDeclarator":let M=R.node.init;if(!M)break;switch(M.type){case"ArrowFunctionExpression":case"FunctionExpression":T(M,F,S,k,L);return}break}break;default:i({node:S,message:`React Hook ${k} received a function whose dependencies are unknown. Pass an inline function instead.`});return}i({node:S,message:`React Hook ${k} has a missing dependency: '${I.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${I.name}]`,fix(_){return _.replaceText(F,`[${I.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(qn.test(g.value))return t=!0,{CallExpression:v=>E(v,!0)}}return{CallExpression:g=>E(g)}}};function _e({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:s}){let a=o();function o(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,E)=>{let g=i(a,E);g.isUsed=!0,l(a,E,v=>{v.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let E=i(a,T);E.isSatisfiedRecursively=!0}),n.forEach(T=>{let E=i(a,T);E.isSatisfiedRecursively=!0});function i(T,E){let g=E.split("."),v=T;for(let I of g){let S=v.children.get(I);S||(S=o(),v.children.set(I,S)),v=S}return v}function l(T,E,g){let v=E.split("."),I=T;for(let S of v){let k=I.children.get(S);if(!k)return;g(k),I=k}}let c=new Set,p=new Set;f(a,c,p,T=>T);function f(T,E,g,v){T.children.forEach((I,S)=>{let k=v(S);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&g.add(k);return}if(I.isUsed){E.add(k);return}f(I,E,g,F=>k+"."+F)})}let h=[],m=new Set,y=new Set;return t.forEach(({key:T})=>{p.has(T)?h.indexOf(T)===-1?h.push(T):y.add(T):m.add(T)}),c.forEach(T=>{h.push(T)}),{suggestedDependencies:h,unnecessaryDependencies:m,duplicateDependencies:y,missingDependencies:c}}function oe(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 oe(e.consequent)!=null||oe(e.alternate)!=null?"conditional":null;case"LogicalExpression":return oe(e.left)!=null||oe(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return oe(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return oe(e.expression);case"TSAsExpression":return oe(e.expression)}return null}function Xn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let s=e.map(({key:o})=>{let i=n.variables.find(c=>c.name===o);if(i==null)return null;let l=i.defs[0];if(l==null)return null;if(l.type==="Variable"&&l.node.type==="VariableDeclarator"&&l.node.id.type==="Identifier"&&l.node.init!=null){let c=oe(l.node.init);if(c!=null)return[i,c]}return l.type==="FunctionName"&&l.node.type==="FunctionDeclaration"?[i,"function"]:l.type==="ClassName"&&l.node.type==="ClassDeclaration"?[i,"class"]:null}).filter(Boolean);function a(o){let i=!1;for(let l=0;l<o.references.length;l++){let c=o.references[l];if(c.writeExpr){if(i)return!0;i=!0;continue}let p=c.from;for(;p!==r&&p!=null;)p=p.upper;if(p!==r&&!Ot(t,c.identifier))return!0}return!1}return s.map(([o,i])=>({construction:o.defs[0],depType:i,isUsedOutsideOfHook:a(o)}))}function kt(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)?kt(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 re(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=re(e.object,t),r=re(e.property,null),s=`${n}.${r}`;return Me(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=re(e.object,t),r=re(e.property,null),s=`${n}.${r}`;return Me(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=re(n.object,t),s=re(n.property,null),a=`${r}.${s}`;return Me(n,t,a),a}else throw new Error(`Unsupported node type: ${e.type}`)}function vt(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Kn(e,t){let n=vt(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 r;try{r=re(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(r)?0:-1}else return-1}}function $e(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Gn(r,t))return r;if(Ot(r,t))for(let[s,a]of Object.entries(r))s!=="parent"&&(wt(a)?(a.parent=r,n.push(a)):Array.isArray(a)&&a.forEach(o=>{wt(o)&&(o.parent=r,n.push(o))}))}return null}function Jn(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 wt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Gn(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 Ot(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Zn(e){return!1}import{AST_NODE_TYPES as Ee,ESLintUtils as Pt}from"@typescript-eslint/utils";import X from"typescript";var Qn=Pt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),At="improved-no-unnecessary-condition",er=j({}),tr=["string","number","bigint","boolean","symbol","undefined","object","function","never"],nr=new Set(tr),Ue={name:At,rule:Qn({name:At,meta:{type:"suggestion",docs:{description:"Extends checks of `no-unnecessary-condition` rule"},messages:{unnecessaryTypeofCondition:'This condition is unnecessary. The type of "{{name}}" is always "{{type}}".',alwaysFalseTypeofCondition:'This condition will always be false. The type of "{{name}}" is "{{actualType}}" so the condition has no overlap with "{{conditionType}}".'},schema:[er]},defaultOptions:[{}],create(e){let t=Pt.getParserServices(e,!0),n=t.program?.getTypeChecker();if(!n||!t.program)throw new Error("TypeScript services or program not available");function r(i){return i.type===Ee.UnaryExpression&&i.operator==="typeof"}function s(i){return i.flags&X.TypeFlags.Any||i.flags&X.TypeFlags.Unknown?null:i.flags&X.TypeFlags.StringLike?["string"]:i.flags&X.TypeFlags.NumberLike?["number"]:i.flags&X.TypeFlags.BigIntLike?["bigint"]:i.flags&X.TypeFlags.BooleanLike?["boolean"]:i.flags&X.TypeFlags.ESSymbolLike?["symbol"]:i.flags&X.TypeFlags.Undefined||i.flags&X.TypeFlags.Void?["undefined"]:i.flags&X.TypeFlags.Null?["object"]:i.getCallSignatures().length>0?["function"]:i.flags&X.TypeFlags.Object?i.getProperties().length===0?["string","number","bigint","boolean","symbol","object","function"]:["object"]:i.flags&X.TypeFlags.NonPrimitive?["object"]:i.flags&X.TypeFlags.Never?["never"]:null}function a(i){if(!n)return null;let l=t.esTreeNodeToTSNodeMap.get(i),c=n.getTypeAtLocation(l.expression);if(c.flags&X.TypeFlags.Any||c.flags&X.TypeFlags.Unknown)return null;let p=[];if(c.isUnion()){for(let h of c.types){let m=s(h);if(m)p.push(...m);else return null}return p}let f=s(c);return f?(p.push(...f),p):null}function o(i){if(!(i.operator==="==="||i.operator==="!=="))return;let c=null,p=null;if(r(i.left)?(c=i.left,p=i.right.type===Ee.Literal&&typeof i.right.value=="string"?i.right.value:null):r(i.right)&&(c=i.right,p=i.left.type===Ee.Literal&&typeof i.left.value=="string"?i.left.value:null),!c||!p||!rr(p,nr))return;let f=a(c);if(!f)return;let h=i.operator==="!==",m=f.includes(p);f.length===1?m&&!h?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:le(c,e),type:p}}):!m&&h?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:le(c,e),type:Array.from(f)[0]}}):!m&&!h?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:le(c,e),actualType:he(f),conditionType:p}}):m&&h&&e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:le(c,e),actualType:he(f),conditionType:p}}):!m&&!h?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:le(c,e),actualType:he(f),conditionType:p}}):!m&&h&&e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:le(c,e),type:he(f)}})}return{BinaryExpression:o}}})};function he(e){return Array.from(new Set(e)).join(" | ")||"never"}function le(e,t){let n=e.argument;return n.type===Ee.Identifier?n.name:t.sourceCode.getText(n)}function rr(e,t){return t.has(e)}import{AST_NODE_TYPES as ir,ESLintUtils as sr}from"@typescript-eslint/utils";var or=sr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ft="no-call-with-explicit-generics",ar=j({functions:Y(A())}),lr=or({name:Ft,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[ar]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:s}=r;s.type===ir.Identifier&&n.has(s.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),Ve={name:Ft,rule:lr};import{AST_NODE_TYPES as be,ESLintUtils as cr}from"@typescript-eslint/utils";var pr=cr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Nt="no-call-with-inferred-generics",ur=pr({name:Nt,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,[t]){let n=new Map(t.functions.map(r=>[r.name,r]));return{CallExpression(r){let{callee:s}=r;if(s.type!==be.Identifier)return;let a=n.get(s.name);if(!a)return;let{minGenerics:o=1,allowAny:i,disallowTypes:l=t.disallowTypes}=a;(r.typeArguments?.params.length||0)<(o||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:o||0}}),!(i&&!l)&&r.typeArguments?.params?.some(p=>!i&&p.type===be.TSAnyKeyword||l&&p.type===be.TSTypeReference&&p.typeName.type===be.Identifier&&l.includes(p.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),We={name:Nt,rule:ur};import{ESLintUtils as fr,TSESTree as Dt}from"@typescript-eslint/utils";var mr=fr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),jt="no-commented-out-code",dr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],yr=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],gr=mr({name:jt,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(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of dr)if(r.startsWith(s))return{wrongPattern:s};for(let s of yr)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let s of r)if(s.type===Dt.AST_TOKEN_TYPES.Line||s.type===Dt.AST_TOKEN_TYPES.Block){let a=t(s.value);a&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:a.wrongPattern}})}}}}}),He={name:jt,rule:gr};import{ESLintUtils as Sr,TSESTree as Tr}from"@typescript-eslint/utils";var hr=Sr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Lt="no-default-export",Er=hr({name:Lt,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.type===Tr.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ye={name:Lt,rule:Er};import{ESLintUtils as br}from"@typescript-eslint/utils";var xr=br.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),_t="no-leaked-text-in-jsx",Ir=[",",";","[","]","(",")"],Cr=xr({name:_t,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";Ir.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),ze={name:_t,rule:Cr};import{AST_NODE_TYPES as ce,ESLintUtils as wr}from"@typescript-eslint/utils";var Rr=wr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="no-non-camel-case-functions",kr=/^[a-z][a-zA-Z0-9]*$/;function Mt(e){return e.typeName.type===ce.TSQualifiedName&&e.typeName.left.type===ce.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===ce.Identifier&&e.typeName.right.name==="Element"}var vr=Rr({name:$t,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&&!kr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ce.TSTypeReference?Mt(n):n.type===ce.TSUnionType&&n.types.some(s=>s.type===ce.TSTypeReference&&Mt(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Be={name:$t,rule:vr};import{ESLintUtils as Or,TSESTree as V}from"@typescript-eslint/utils";import{AST_NODE_TYPES as Ut}from"@typescript-eslint/utils";function pe(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:pe(e.parent,t,n===1/0?n:n-1)}function*qe(e){yield e,e.parent&&(yield*qe(e.parent))}function Xe(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function Vt(e,t,n){let s=n.getDeclaredVariables(e).find(a=>a.name===t||a.identifiers[0]?.parent.type===Ut.Property&&a.identifiers[0]?.parent.key.type===Ut.Identifier&&a.identifiers[0]?.parent.key.name===t);return s?s.references.filter(a=>!a.init):[]}var Ar=Or.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Wt="no-optional-root-props",Pr=Ar({name:Wt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let a=e.sourceCode.getDeclaredVariables(r)[0];if(!a||a.references.length!==1)return!1;let o=a.references[0];if(!o)return!1;for(let i of qe(o.identifier)){if("returnType"in i||i.type===V.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let l=i.parent;if(!l)return!1;if(l.type===V.AST_NODE_TYPES.TSTypeParameterInstantiation&&l.parent.type===V.AST_NODE_TYPES.TSTypeReference&&l.parent.typeName.type===V.AST_NODE_TYPES.Identifier&&l.parent.typeName.name==="FC"){let p=pe(l.parent.parent,V.AST_NODE_TYPES.VariableDeclaration,4);if(!p)return!1;let f=xe(p,e.sourceCode);return f?!(f.parent.type===V.AST_NODE_TYPES.CallExpression&&f.parent.callee.type===V.AST_NODE_TYPES.Identifier&&f.parent.callee.name==="memo"):!1}if(i.type===V.AST_NODE_TYPES.AssignmentPattern)return!1;if(l.type===V.AST_NODE_TYPES.ArrowFunctionExpression){let c=pe(l,V.AST_NODE_TYPES.VariableDeclaration);return c?!!xe(c,e.sourceCode):!1}if(l.type===V.AST_NODE_TYPES.FunctionDeclaration)return!!xe(l,e.sourceCode)}return!1}function n(r){r.key.type!==V.AST_NODE_TYPES.Identifier||!r.optional||e.report({node:r.key,messageId:"optionalNotAllowed",data:{propertyName:r.key.name},suggest:[{messageId:"suggestion",fix:s=>{let a=pe(r,V.AST_NODE_TYPES.TSPropertySignature);if(!a)return null;let o=e.sourceCode.getText(a);return s.replaceText(a,o.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(r){if(r.typeAnnotation.type===V.AST_NODE_TYPES.TSTypeLiteral&&!(Ie(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===V.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(Ie(r)||!t(r)))for(let s of r.body.body)s.type===V.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSTypeReference(r){if(r.typeName.type!==V.AST_NODE_TYPES.Identifier||r.typeName.name!=="FC"||!r.typeArguments?.params[0])return;let s=r.typeArguments.params[0];if(s.type!==V.AST_NODE_TYPES.TSTypeLiteral)return;let a=pe(r.parent,V.AST_NODE_TYPES.VariableDeclaration,4);if(!a)return;let o=xe(a,e.sourceCode);if(!(!o||o.parent.type===V.AST_NODE_TYPES.CallExpression&&o.parent.callee.type===V.AST_NODE_TYPES.Identifier&&o.parent.callee.name==="memo"))for(let l of s.members)l.type===V.AST_NODE_TYPES.TSPropertySignature&&n(l)}}}});function Ie(e){return e?e.parent?.type===V.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===V.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function xe(e,t){if(Ie(e))return;let n;if(e.type===V.AST_NODE_TYPES.VariableDeclaration){if(e.declarations.length!==1)return;e.declarations[0].id.type===V.AST_NODE_TYPES.Identifier&&(n=e.declarations[0].id)}else{if(!e.id)return;n=e.id}if(!n)return;let r=t.getScope(e);e.type===V.AST_NODE_TYPES.FunctionDeclaration&&r.upper&&(r=r.upper);let s=r.variables.find(o=>o.identifiers.includes(n));if(!s)return;let a=s.references.filter(o=>o.identifier!==n);if(!(a.length!==1||!a[0])&&!Ie(a[0].identifier.parent.parent))return a[0].identifier}var Ke={name:Wt,rule:Pr};import{ESLintUtils as Fr}from"@typescript-eslint/utils";import Je from"node:path";var Nr=Fr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ht="no-relative-imports",Dr=j({find:A(),replacement:A()}),jr=j({aliases:Y(Dr),rootDir:O(A()),allowNotFoundAliases:O(ae()),_dev_simulateFileName:O(A())}),Lr=Nr({name:Ht,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[jr]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(o){return o.startsWith(".")||o.startsWith("..")}function s(o,i){let l=Je.dirname(i);return Je.resolve(l,o)}function a(o){let i=t.rootDir??process.cwd(),l=Je.relative(i,o);if(l.startsWith("."))return null;l.startsWith("/")||(l=`/${l}`);for(let{find:c,replacement:p}of t.aliases)if(l.startsWith(p)){let f=l.replace(p,c);return{alias:c,newPath:f}}return null}return{ImportDeclaration(o){let i=o.source.value;if(!r(i))return;let l=s(i,n),c=a(l);!c&&t.allowNotFoundAliases||e.report({node:o,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?p=>p.replaceText(o.source,`'${c.newPath}'`):void 0})}}}}),Ge={name:Ht,rule:Lr};import{AST_NODE_TYPES as me,ESLintUtils as zt}from"@typescript-eslint/utils";import*as Ze from"typescript";var _r=zt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Yt="no-unnecessary-casting",Mr=j({additionalCastFunctions:O(Y(j({name:A(),expectedType:Te(["string","number"])})))}),Qe={name:Yt,rule:_r({name:Yt,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[Mr],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=zt.getParserServices(e,!0),a=s.program?.getTypeChecker();if(!a||!s.program)throw new Error("TypeScript services or program not available");function o(p,f){switch(p.type){case me.Literal:return f==="number"?typeof p.value=="number":typeof p.value=="string";case me.TemplateLiteral:return f==="string";case me.UnaryExpression:return f==="number"?p.operator==="+"||p.operator==="-"||p.operator==="~":!1;default:return!1}}function i(p,f){return f==="number"?!!(p.flags&Ze.TypeFlags.NumberLike):!!(p.flags&Ze.TypeFlags.StringLike)}function l(p,f){return h=>h.replaceText(p,e.sourceCode.getText(f))}function c(p){if(!a||p.arguments.length!==1)return;let f=p.arguments[0];if(!f||f.type===me.SpreadElement)return;let{callee:h}=p;if(h.type!==me.Identifier)return;let m=h.name,y=r.find(E=>E.name===m);if(!y)return;if(o(f,y.expectedType)||i(a.getTypeAtLocation(s.esTreeNodeToTSNodeMap.get(f)),y.expectedType)){let E,g;m==="Number"?E="unnecessaryNumberCasting":m==="String"?E="unnecessaryStringCasting":(E="unnecessaryCustomCasting",g={name:y.name,type:y.expectedType}),e.report({node:p,messageId:E,...g?{data:g}:{},fix:l(p,f)})}}return{CallExpression:c}}})};import{AST_NODE_TYPES as K}from"@typescript-eslint/utils";var et=se({name:"no-unused-obj-props",meta:{type:"suggestion",docs:{description:"Disallow unused properties when it is safe to remove them"},messages:{unusedObjectProperty:'The object property "{{name}}" is not being used',unusedReturnObjectProperty:'The object property "{{name}}" returned by this function is not being used'},schema:[]},defaultOptions:[],create(e){return{VariableDeclarator(t){if(t.id.type===K.ObjectPattern||!t.init||t.init.type!==K.ObjectExpression||t.id.type===K.Identifier&&t.id.typeAnnotation||t.parent.parent.type===K.ExportNamedDeclaration)return;let n=new Map;for(let o of t.init.properties)o.type===K.Property&&o.key.type===K.Identifier&&n.set(o.key.name,o);if(n.size===0||t.id.type!==K.Identifier)return;let r=$r(t,e.sourceCode);if(r.length===0)return;let s=t.init.properties.some(o=>o.type!==K.Property?!1:o.value.type===K.FunctionExpression),a=new Set;for(let o of r){if(o.identifier.parent.type!==K.MemberExpression)return;let i=o.identifier.parent;if(i.object!==o.identifier)return;if(i.computed)if(i.property.type===K.Literal&&typeof i.property.value=="string")a.add(i.property.value);else return;else{if(i.property.type!==K.Identifier)return;a.add(i.property.name)}if(i.parent.type===K.CallExpression&&s)return}for(let[o,i]of n)a.has(o)||e.report({node:i,messageId:"unusedObjectProperty",data:{name:o}})}}}});function $r(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}import{AST_NODE_TYPES as H,ESLintUtils as Ur}from"@typescript-eslint/utils";var Vr=j({selectors:Y(j({name:A(),selectorProp:O(A()),selectorArgPos:O(Z()),returnProp:O(A())}))}),Wr=Ur.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Bt="no-unused-selected-values",tt={name:Bt,rule:Wr({name:Bt,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[Vr]},defaultOptions:[{selectors:[]}],create(e,[t]){let{selectors:n=[]}=t,r=new Map(n.map(s=>[s.name,s]));return{VariableDeclarator(s){let a=null;if(s.init?.type===H.CallExpression&&(a=s.init),!a)return;let o=Yr(a);if(!o)return;let i=r.get(o);if(!i)return;let l=Hr(a,i.selectorArgPos??0,i.selectorProp);if(!l)return;let c=zr(l);if(!c)return;let p=qt(c.properties,void 0);if(!p)return;if(s.id.type===H.ObjectPattern){let m=qt(s.id.properties,i.returnProp);if(!m)return;for(let[y,T]of p)m.has(y)||e.report({node:T,messageId:"unusedSelectedValue",data:{name:y}});return}if(s.id.type!==H.Identifier||i.returnProp)return;let f=Br(s,e.sourceCode);if(f.length===0)return;let h=new Set;for(let m of f){if(m.identifier.parent.type!==H.MemberExpression)return;let y=m.identifier.parent.property;if(y.type!==H.Identifier)return;h.add(y.name)}for(let[m,y]of p)h.has(m)||e.report({node:y,messageId:"unusedSelectedValue",data:{name:m}})}}}})};function Hr(e,t,n){let r=e.arguments[t];if(!r)return null;if(r.type===H.ArrowFunctionExpression||r.type===H.FunctionExpression)return r;if(n&&r.type===H.ObjectExpression){let s=r.properties.find(o=>o.type===H.Property&&o.key.type===H.Identifier&&o.key.name===n);if(s?.type!==H.Property)return null;let a=s.value;if(a.type===H.ArrowFunctionExpression||a.type===H.FunctionExpression)return a}return null}function Yr(e){return e.callee.type===H.Identifier?e.callee.name:e.callee.type===H.MemberExpression&&e.callee.property.type===H.Identifier?e.callee.property.name:null}function zr(e){if(e.body.type===H.ObjectExpression)return e.body;if(e.body.type===H.BlockStatement){let t=e.body.body.filter(n=>n.type===H.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==H.ObjectExpression?null:t[0].argument}return null}function qt(e,t){let n=e;if(t){let s=e.find(a=>a.type===H.Property&&a.key.type===H.Identifier&&a.key.name===t);if(s?.type!==H.Property||s.value.type!==H.ObjectPattern)return null;n=s.value.properties}let r=new Map;for(let s of n){if(s.type!==H.Property||s.key.type!==H.Identifier)return null;r.set(s.key.name,s)}return r.size>0?r:null}function Br(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}import{AST_NODE_TYPES as W}from"@typescript-eslint/utils";var nt=se({name:"no-unused-t-state-field",meta:{type:"suggestion",docs:{description:"Prevent declaring unused t-state fields"},messages:{unusedField:'Field "{{name}}" is not being used, you can safely remove it'},schema:[]},defaultOptions:[],create(e){if(!(e.filename.endsWith(".jsx")||e.filename.endsWith(".tsx")))return{};if(!e.sourceCode.ast.body.some(a=>a.type===W.ImportDeclaration&&a.source.value==="t-state-form"))return{};let r=null,s=!1;return{CallExpression(a){if(s)return;if(!r){let i=qr(a);i&&(r=i);return}let o=Xr(a,e.sourceCode);if(o){s=!0;for(let i of o)r.delete(i);if(r.size!==0)for(let[i,l]of r)e.report({node:l,messageId:"unusedField",data:{name:i}})}}}}});function qr(e){if(!(e.callee.type===W.Identifier&&e.callee.name==="useForm"))return null;let n=e.arguments[0];if(!n||n.type!==W.ObjectExpression)return null;let r=Xe(n.properties,a=>a.type!==W.Property||a.key.type!==W.Identifier||a.key.name!=="initialConfig"?null:a.value.type===W.ObjectExpression?a.value:a.value.type===W.ArrowFunctionExpression||a.value.type===W.FunctionExpression?Kr(a.value):null);if(!r)return null;let s=new Map;for(let a of r.properties)a.type===W.Property&&a.key.type===W.Identifier&&s.set(a.key.name,a);return s}function Xr(e,t){if(!(e.callee.type===W.Identifier&&e.callee.name==="useFormState")||e.parent.type!==W.VariableDeclarator||e.parent.id.type!==W.ObjectPattern||!Xe(e.parent.id.properties,o=>o.type===W.Property&&o.key.type===W.Identifier&&o.key.name==="formFields"&&o))return null;let s=Vt(e.parent,"formFields",t),a=new Set;for(let{identifier:o}of s){if(o.type!==W.Identifier||o.parent.type===W.Property&&o.parent.parent.type===W.ObjectExpression&&o.parent.parent.parent.type===W.ReturnStatement||o.parent.type===W.ReturnStatement)return null;if(o.parent.type===W.MemberExpression){if(o.parent.object.type!==W.Identifier||o.parent.property.type!==W.Identifier)return null;a.add(o.parent.property.name)}}return a}function Kr(e){if(e.body.type===W.ObjectExpression)return e.body;if(e.body.type===W.BlockStatement){let t=e.body.body.filter(n=>n.type===W.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==W.ObjectExpression?null:t[0].argument}return null}import{AST_NODE_TYPES as U,ESLintUtils as Jr}from"@typescript-eslint/utils";var Gr=Jr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Xt(e){let t=[];for(let n of e.members)n.type===U.TSPropertySignature&&n.key.type===U.Identifier&&t.push([n.key.name,n]);return t}function Kt(e,...t){for(let n of t)e.set(...n);return e}var Zr=j({forceCheckOnFCPropTypesWithName:O(Y(A()))}),Jt="no-unused-type-props-in-args",rt=null,Qr=Gr({name:Jt,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:[Zr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!rt&&(rt=n.map(i=>new RegExp(i)));function r(i,l,c,p,f=!0){let h=c.name,m=e.sourceCode.getScope(l).references.find(E=>E.identifier.name===h)?.resolved,y=i&&rt?.some(E=>E.test(h));if(!m||!y&&m.references.filter(E=>E.isTypeReference).length>1)return;let T=m?.defs[0]?.node;if(!(f&&T?.parent?.type===U.ExportNamedDeclaration)){if(T?.type===U.TSTypeAliasDeclaration){s(i,l,p,T.typeAnnotation,!0);return}if(T?.type===U.TSInterfaceDeclaration){s(i,l,p,T.body,!0);return}}}function s(i,l,c,p,f){if(p.type===U.TSInterfaceBody){for(let h of p.body)h.type===U.TSPropertySignature&&h.key.type===U.Identifier&&c.set(h.key.name,h);return}if(p.type===U.TSTypeLiteral){Kt(c,...Xt(p));return}if(p.type===U.TSIntersectionType){for(let h of p.types)s(i,l,c,h,!0);return}f||p.type===U.TSTypeReference&&p.typeName.type===U.Identifier&&r(i,l,p.typeName,c)}function a(i,l,c){for(let p of c)if(p.type==="ObjectPattern"&&p.typeAnnotation){let f=new Map;if(s(i,l,f,p.typeAnnotation.typeAnnotation,!1),f.size===0)continue;o(p,f)}else p.type===U.AssignmentPattern&&p.left.type===U.ObjectPattern&&a(i,l,[p.left])}function o(i,l){let c=[];if(i.properties.at(-1)?.type===U.RestElement)return;for(let m of i.properties)m.type===U.Property&&m.key.type===U.Identifier&&c.push(m.key.name);let f=[],h=[];for(let[m,y]of l)c.includes(m)||(h.push(m),f.push({node:y,messageId:"unusedObjectTypeProperty",data:{propertyName:m}}));for(let[m,y]of f.entries())e.report({...y,fix:m===f.length-1?T=>{let E=i.properties.at(-1),g=h.join(", ");return E?E?.type===U.RestElement?null:T.insertTextAfter(E,`, ${g}`):T.insertTextBeforeRange([i.range[0]+1,i.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(i){let l=i.declarations[0];if(!l)return;let c=new Map,p=l.id.type===U.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===U.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===U.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(p){if(p.type===U.TSTypeReference&&p.typeName.type===U.Identifier)r(!0,i,p.typeName,c,!1);else if(p.type===U.TSTypeLiteral)Kt(c,...Xt(p));else if(p.type===U.TSIntersectionType)for(let f of p.types)f.type===U.TSTypeReference&&f.typeName.type===U.Identifier?r(!0,i,f.typeName,c,!1):s(!0,i,c,f,!0);if(c.size!==0&&l.init?.type===U.ArrowFunctionExpression){let f=l.init.params[0];if(!f){e.report({node:l.init,messageId:"missingComponentParam"});return}f.type===U.ObjectPattern&&o(f,c)}}},FunctionDeclaration:function(i){a(!1,i,i.params)},ArrowFunctionExpression(i){a(!1,i,i.params)}}}}),it={name:Jt,rule:Qr};import{AST_NODE_TYPES as st,ESLintUtils as ei}from"@typescript-eslint/utils";var ti=ei.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Zt="prefer-named-functions",Gt=new Map,ni=ti({name:Zt,meta:{hasSuggestions:!0,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:{suggestion:"Convert to named function",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,[t]){let n=null;if(t.ignoreRegex){let r=Gt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),Gt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===st.ArrowFunctionExpression&&r.id.type===st.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==st.BlockStatement)return;let a=r.parent,o=r.init.params,i=r.init.body,l=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(a,`${l.async?"async ":""}function ${s}(${o.map(p=>e.sourceCode.getText(p)).join(", ")||""}) ${e.sourceCode.getText(i)}`)}]})}}}}}),ot={name:Zt,rule:ni};import{AST_NODE_TYPES as N}from"@typescript-eslint/utils";var ri=j({disallowedFunctions:Y(j({name:A(),hookAlternative:O(A()),message:O(A()),allowUseInside:O(Y(A()))}))});function Ce(e){return/^use[A-Z]/.test(e)}function Qt(e){return/^[A-Z]/.test(e)}function ii(e){return e.type===N.Identifier?Ce(e.name):e.type===N.MemberExpression&&e.property.type===N.Identifier?Ce(e.property.name):!1}function en(e,t){return e.type===N.Identifier?e.name===t:e.type===N.MemberExpression&&e.object.type===N.Identifier&&e.property.type===N.Identifier?e.object.name==="React"&&e.property.name===t:!1}function tn(e){return!!(e.parent&&e.parent.type===N.CallExpression&&en(e.parent.callee,"forwardRef"))}function nn(e){return!!(e.parent&&e.parent.type===N.CallExpression&&en(e.parent.callee,"memo"))}function at(e){if(e.type===N.FunctionDeclaration||e.type===N.FunctionExpression&&e.id)return e.id||void 0;if(e.type===N.FunctionExpression||e.type===N.ArrowFunctionExpression){if(e.parent.type===N.VariableDeclarator&&e.parent.init===e)return e.parent.id;if(e.parent.type===N.AssignmentExpression&&e.parent.right===e&&e.parent.operator==="=")return e.parent.left;if(e.parent.type===N.Property&&e.parent.value===e&&!e.parent.computed)return e.parent.key;if(e.parent.type===N.AssignmentPattern&&e.parent.right===e)return e.parent.left}}function si(e){let t=e.parent,n=!1;for(;t;){if(t.type===N.FunctionDeclaration||t.type===N.FunctionExpression||t.type===N.ArrowFunctionExpression){let r=at(t);if(r&&r.type===N.Identifier){if(Qt(r.name)||Ce(r.name))return!n;n=!0}else{if(tn(t)||nn(t))return!n;if(t.parent.type===N.CallExpression){let s=t.parent;ii(s.callee)||(n=!0)}else t.parent.type===N.JSXExpressionContainer||(n=!0)}}t=t.parent}return!1}function rn(e){return e.callee.type===N.Identifier?e.callee.name:e.callee.type===N.MemberExpression&&e.callee.property.type===N.Identifier?e.callee.property.name:null}function oi(e,t){if(!t.length)return!1;let n=e.parent;for(;n;){if(n.type===N.FunctionDeclaration||n.type===N.FunctionExpression||n.type===N.ArrowFunctionExpression){let r=at(n);if(r&&r.type===N.Identifier&&t.includes(r.name))return!0}else if(n.type===N.CallExpression){let r=rn(n);if(r&&t.includes(r))return!0}n=n.parent}return!1}function ai(e,t){let n=!1,r=e.parent;for(;r;){if(r.type===N.FunctionDeclaration||r.type===N.FunctionExpression||r.type===N.ArrowFunctionExpression){let s=at(r);if(s&&s.type===N.Identifier){if(Qt(s.name)||Ce(s.name)){n=!0;break}}else if(tn(r)||nn(r)){n=!0;break}}r=r.parent}return n?t.length===0?si(e):!oi(e,t):!1}var lt=se({name:"prefer-react-hook-alternative",meta:{type:"suggestion",docs:{description:"Prefer hook alternatives for certain functions in React components and hooks"},messages:{preferHookAlternative:"This function should not be used in react{{message}}."},schema:[ri],hasSuggestions:!0},defaultOptions:[{disallowedFunctions:[]}],create(e,[t]){let{disallowedFunctions:n}=t,r=new Map(n.map(s=>[s.name,s]));return{CallExpression(s){let a=rn(s);if(!a)return;let o=r.get(a);if(!o)return;let i=o.allowUseInside||[];ai(s,i)&&e.report({node:s,messageId:"preferHookAlternative",data:{message:o.message?` ${o.message}`:` use ${o.hookAlternative} instead`},suggest:o.hookAlternative?[{messageId:"preferHookAlternative",data:{message:`Replace with ${o.hookAlternative}`,hookAlternative:o.hookAlternative},fix:l=>{let c=o.hookAlternative;return s.callee.type===N.Identifier?l.replaceText(s.callee,c):s.callee.type===N.MemberExpression&&s.callee.property.type===N.Identifier?l.replaceText(s.callee.property,c):null}}]:[]})}}}});import{AST_NODE_TYPES as z,AST_TOKEN_TYPES as sn,ESLintUtils as li}from"@typescript-eslint/utils";var ci=li.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),an="prefer-single-line-if",pi=j({maxLineLength:O(Z()),maxNonSimpleConditionLength:O(Z())}),ui=ci({name:an,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[pi]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==z.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let a=r.consequent.body[0];if(a.type===z.ReturnStatement){if(!cn(a))return}else if(!(a.type===z.ContinueStatement||a.type===z.BreakStatement))return;if(r.test.type===z.LogicalExpression||r.test.type===z.ConditionalExpression)return;let o;if(t.maxNonSimpleConditionLength){let f=on(r.test);if(!f&&r.test.type===z.UnaryExpression&&r.test.operator==="!"){let h=r.test.argument;on(h)&&(f=!0)}if(f&&(o=n.getText(r.test),o.length>t.maxNonSimpleConditionLength))return}o||(o=n.getText(r.test));let i=n.getText(a);if(o.includes(`
|
|
15
|
+
`))return;let l=n.getTokenAfter(r);if(l&&l.type===sn.Punctuator&&l.value==="}"){let f=n.getTokenAfter(l);if(f&&f.type===sn.Keyword&&(f.value==="else"||f.value==="catch"))return}let c=fi(n,r),p=`if (${o}) ${i}`;t.maxLineLength&&p.length+c.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:f=>f.replaceText(r,p)})}}}});function on(e){return e.type===z.CallExpression||e.type===z.BinaryExpression||e.type===z.MemberExpression&&ln(e)}function ln(e){return e.object.type===z.MemberExpression?ln(e.object):e.object.type!==z.Identifier}function fi(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function cn(e){if(!e.argument)return!0;let t=e.argument;return t.type===z.ArrayExpression&&t.elements.length===0||t.type===z.ObjectExpression&&t.properties.length===0||t.type===z.Literal||t.type===z.Identifier||t.type===z.TemplateLiteral||t.type===z.TaggedTemplateExpression?!0:t.type===z.CallExpression?t.arguments.length===0:t.type===z.UnaryExpression?cn(t):!1}var ct={name:an,rule:ui};import{AST_NODE_TYPES as ee,ESLintUtils as mi}from"@typescript-eslint/utils";var di=mi.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),pn="react-compiler-migration",yi=j({disallowHooks:O(Y(j({name:A(),replacement:A()}))),disallowMethods:O(Y(j({name:A(),replacement:O(A()),requireTrueProp:O(A())})))}),gi=/eslint +react-compiler\/react-compiler: +\["error/;function Si(e){return e.type===ee.Identifier?e.name.startsWith("use"):e.type===ee.MemberExpression&&e.property.type===ee.Identifier?e.property.name.startsWith("use"):!1}var Ti=di({name:pn,meta:{type:"suggestion",fixable:"code",docs:{description:"Rules to help migrate to the new React compiler"},messages:{disallowedFunctionOrMethod:"{{functionOrMethod}} is not supported in react compiler. Use {{replacement}} instead.",replace:"Replace with safe alternative {{replacement}}",disallowedMethodWithMissingRequireTrueProp:"{{method}} is should have a prop named {{requireTrueProp}} set to true when used in react compiler."},hasSuggestions:!0,schema:[yi]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(gi.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let s=null,a=null;if(r.callee.type===ee.Identifier?(s=r.callee.name,a=r.callee):r.callee.type===ee.MemberExpression&&r.callee.property.type===ee.Identifier&&(s=r.callee.property.name,a=r.callee.property),s){let o=t.disallowHooks.find(i=>i.name===s);o&&a&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:o.name,replacement:o.replacement},suggest:[{messageId:"replace",data:{replacement:o.replacement},fix:i=>i.replaceText(a,o.replacement)}]})}}if(t.disallowMethods?.length&&Si(r.callee)){for(let s of r.arguments)if(s.type===ee.ObjectExpression){for(let a of s.properties)if(a.type===ee.Property&&a.key.type===ee.Identifier){let o=a.key.name,i=t.disallowMethods.find(l=>l.name===o);if(i){if(i.requireTrueProp){let l=i.requireTrueProp,c=!1;for(let p of s.properties)if(p.type===ee.Property&&p.key.type===ee.Identifier&&p.key.name===l&&p.value.type===ee.Literal&&p.value.value===!0){c=!0;break}if(!c){e.report({node:a,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:i.name,requireTrueProp:l}});continue}}i.replacement&&e.report({node:a,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:i.name,replacement:i.replacement},suggest:[{messageId:"replace",data:{replacement:i.replacement},fix:l=>l.replaceText(a.key,i.replacement)}]})}}}}}}:{}}}),pt={name:pn,rule:Ti};import{ESLintUtils as hi,TSESTree as Ei}from"@typescript-eslint/utils";var bi=hi.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),un="require-description",xi=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Ii=/^eslint-disable-(next-)?line$/u,Ci=bi({name:un,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,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let a=wi(s);a!=null&&(r.has(a.kind)||a.description||e.report({loc:ki(s.loc),messageId:"missingDescription"}))}}}}}),fn={name:un,rule:Ci};function wi(e){let{text:t,description:n}=Ri(e.value);if(!t)return null;let r=xi.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let a=Ii.test(s);if(e.type===Ei.AST_TOKEN_TYPES.Line&&!a||a&&e.loc.start.line!==e.loc.end.line)return null;let o=t.slice(r.index+s.length);return{kind:s,value:o.trim(),description:n}}function Ri(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function ki(e){return{start:{line:e.start.line,column:-1},end:e.end}}function yn(e){return/^use[A-Z0-9]/.test(e)}function we(e){return e.type==="Identifier"?yn(e.name):e.type==="MemberExpression"&&!e.computed&&we(e.property)?e.object.type==="Identifier":!1}function gn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Sn(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Tn(e){return!!(e.parent&&e.parent.callee&&Sn(e.parent.callee,"forwardRef"))}function hn(e){return!!(e.parent&&e.parent.callee&&Sn(e.parent.callee,"memo"))}function ut(e){for(;e;){let t=bn(e);if(t&&(gn(t)||we(t))||Tn(e)||hn(e))return!0;e=e.parent}return!1}function mn(e){return!1}function ft(e){return!1}var vi=/eslint +react-compiler\/react-compiler: +\["error/,En={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 l of e.sourceCode.getAllComments())if(vi.test(l.value))return{CallExpression(c){let p=null;c.callee.name==="useMemo"?p="useMemo":c.callee.name==="useCallback"&&(p="useCallback"),p&&e.report({node:c,message:`"${p}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?l=>t(l):l=>e.sourceCode.getText(l),n=typeof e.getScope=="function"?()=>n():l=>e.sourceCode.getScope(l),r=null,s=[],a=[],o=new WeakSet;function i(l){for(let c of l.references){let p=c.identifier.parent;if(p.type==="VariableDeclarator"&&p.init&&p.init.type==="CallExpression"&&p.init.callee&&mn(p.init.callee))for(let f of c.resolved.references)f!==c&&o.add(f.identifier)}}return{onCodePathSegmentStart:l=>a.push(l),onCodePathSegmentEnd:()=>a.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(l,c){let p=s.pop();if(p.size===0)return;let f=new Set;function h(S,k){let{cache:F}=h,L=F.get(S.id),_=new Set(k);if(_.has(S.id)){let R=[..._],M=R.slice(R.indexOf(S.id)+1);for(let B of M)f.add(B);return BigInt("0")}if(_.add(S.id),L!==void 0)return L;if(l.thrownSegments.includes(S))L=BigInt("0");else if(S.prevSegments.length===0)L=BigInt("1");else{L=BigInt("0");for(let R of S.prevSegments)L+=h(R,_)}return S.reachable&&L===BigInt("0")?F.delete(S.id):F.set(S.id,L),L}function m(S,k){let{cache:F}=m,L=F.get(S.id),_=new Set(k);if(_.has(S.id)){let R=Array.from(_),M=R.slice(R.indexOf(S.id)+1);for(let B of M)f.add(B);return BigInt("0")}if(_.add(S.id),L!==void 0)return L;if(l.thrownSegments.includes(S))L=BigInt("0");else if(S.nextSegments.length===0)L=BigInt("1");else{L=BigInt("0");for(let R of S.nextSegments)L+=m(R,_)}return F.set(S.id,L),L}function y(S){let{cache:k}=y,F=k.get(S.id);if(F===null)return 1/0;if(F!==void 0)return F;if(k.set(S.id,null),S.prevSegments.length===0)F=1;else{F=1/0;for(let L of S.prevSegments){let _=y(L);_<F&&(F=_)}F+=1}return k.set(S.id,F),F}h.cache=new Map,m.cache=new Map,y.cache=new Map;let T=m(l.initialSegment),E=bn(c),g=ut(c),v=E?gn(E)||we(E):Tn(c)||hn(c),I=1/0;for(let S of l.finalSegments){if(!S.reachable)continue;let k=y(S);k<I&&(I=k)}for(let[S,k]of p){if(!S.reachable)continue;let F=S.nextSegments.length===0?I<=y(S):I<y(S),L=h(S)*m(S),_=f.has(S.id);for(let R of k)if(_&&!ft(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.`}),v){if(c.async&&e.report({node:R,message:`React Hook "${t(R)}" cannot be called in an async function.`}),!_&&L!==T&&!ft(R)){let B=`React Hook "${t(R)}" 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:R,message:B})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let M=`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:M})}else if(E){let M=`React Hook "${t(R)}" is called in function "${t(E)}" 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:M})}else if(c.type==="Program"){let M=`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:M})}else if(g&&!ft(R)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let B=c.parent;if(B.parent.type==="VariableDeclarator"&&yn(B.parent.id.name))return}let M=`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:M})}}},CallExpression(l){if(we(l.callee)){let c=dn(s),p=dn(a),f=c.get(p);f||(f=[],c.set(p,f)),f.push(l.callee)}l.callee.type==="Identifier"&&(l.callee.name==="useEffect"||mn(l.callee))&&l.arguments.length>0&&(r=l)},Identifier(l){r==null&&o.has(l)&&l.parent.type!=="CallExpression"&&e.report({node:l,message:`\`${t(l)}\` 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"(l){l===r&&(r=null)},FunctionDeclaration(l){ut(l)&&i(n(l))},ArrowFunctionExpression(l){ut(l)&&i(n(l))}}}};function bn(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 dn(e){return e[e.length-1]}var xn={[it.name]:it.rule,[He.name]:He.rule,[We.name]:We.rule,"rules-of-hooks":En,"exhaustive-deps":Rt,"require-description":fn.rule,[Ye.name]:Ye.rule,[Be.name]:Be.rule,[ot.name]:ot.rule,[De.name]:De.rule,[Ve.name]:Ve.rule,[Ge.name]:Ge.rule,[ct.name]:ct.rule,[Ke.name]:Ke.rule,[ze.name]:ze.rule,[Le.name]:Le.rule,[pt.name]:pt.rule,[Fe.name]:Fe.rule,[Ue.name]:Ue.rule,[Qe.name]:Qe.rule,[tt.name]:tt.rule,[nt.name]:nt.rule,[et.name]:et.rule,[lt.name]:lt.rule};var No={rules:xn};export{No as extendedLintPlugin};
|