@ls-stack/extended-lint 0.42.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 Pn=Object.create;var xe=Object.defineProperty;var Fn=Object.getOwnPropertyDescriptor;var Nn=Object.getOwnPropertyNames;var jn=Object.getPrototypeOf,Dn=Object.prototype.hasOwnProperty;var Ln=(e,t)=>{for(var n in t)xe(e,n,{get:t[n],enumerable:!0})},It=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Nn(t))!Dn.call(e,s)&&s!==n&&xe(e,s,{get:()=>t[s],enumerable:!(r=Fn(t,s))||r.enumerable});return e};var _e=(e,t,n)=>(n=e!=null?Pn(jn(e)):{},It(t||!e||!e.__esModule?xe(n,"default",{value:e,enumerable:!0}):n,e)),_n=e=>It(xe({},"__esModule",{value:!0}),e);var Ei={};Ln(Ei,{extendedLintPlugin:()=>hi});module.exports=_n(Ei);var B=require("@typescript-eslint/utils");var Me=Symbol.for("optional");function N(e){return{...e,[Me]:!0}}function Ce(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 wt(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][Me]?e[r][Me]=void 0:s.push(r);s.length>0&&(n.required=s)}return n}function $e(...e){return{anyOf:e}}var Mn=B.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),vt="react-compiler-extra",$n=j({runOnlyWithEnableCompilerDirective:N(ue())}),Un=/eslint +react-compiler\/react-compiler: +\["error/;function Vn(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 Wn=/\bthis[.[]/;function Rt(e){return Wn.test(e)}var Hn=Mn({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:[$n]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let a of e.sourceCode.getAllComments())if(Un.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(Rt(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);Rt(c)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(a){if(Vn(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))}}}}}),Ue={name:vt,rule:Hn};var Ie=require("@typescript-eslint/utils");var kt=require("@typescript-eslint/utils");function ae(e){let n=kt.ESLintUtils.RuleCreator(r=>`https://github.com/lucasols/extended-lint#${r}`)(e);return{name:e.name,rule:n}}var Yn=j({disallow:N(z(j({selector:A(),message:A(),replace:N($e(A(),j({regex:A(),with:A()}))),replaceType:N(Ce(["suggestion","autofix"]))}))),__dev_simulateFileName:N(A()),mustMatchSyntax:N(z(j({includeRegex:A(),mustCallFn:N(z(j({anyCall:z(j({fn:A(),withArgs:z(j({atIndex:wt(),literal:$e(A(),Q(),ue())}))})),message:N(A())}))),mustMatchSelector:N(z(j({selector:A(),message:A()})))})))}),Ve=ae({name:"advanced-no-restricted-syntax",meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Yn],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=zn(o,new RegExp(m));if(!E)continue;let g=k=>{let C=k;for(let{name:S,value:v}of E)C=C.replaceAll(S,v);return C};for(let{anyCall:k,message:C}of y??[]){let S=`Expected file to call the function: ${k.map(({fn:v})=>v).join(" or ")}`;c.add(S),i.push(v=>{let{callee:P}=v;if(P.type===Ie.AST_NODE_TYPES.Identifier){for(let{fn:D,withArgs:_}of k)if(P.name===D){c.delete(S);for(let R of _){let V=v.arguments[R.atIndex],q=typeof R.literal=="string"?g(R.literal):R.literal;if(!V){e.report({node:v,messageId:"default",data:{message:`Missing argument with value "${q}" at index ${R.atIndex}${C?`: ${g(C)}`:""}`}});continue}if(V.type!==Ie.AST_NODE_TYPES.Literal){e.report({node:V,messageId:"default",data:{message:`Argument at position ${R.atIndex} should the literal "${q}"${C?`: ${g(C)}`:""}`}});continue}V.value!==q&&e.report({node:V,messageId:"default",data:{message:`Argument should have the value "${q}"${C?`: ${g(C)}`:""}`},fix:Te=>Te.replaceText(V,typeof q=="string"?`'${q}'`:String(q))})}break}}})}for(let{selector:k,message:C}of T??[])p.set(k,g(C)),l.set(g(k),()=>{p.delete(k)})}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===Ie.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=k=>{if(!m)return null;if(typeof m=="string")return k.replaceText(y,m);{let C=new RegExp(m.regex),S=e.sourceCode.getText(y);return k.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 zn(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:Ot(s)}),n.push({name:"$0_uncapitalize",value:At(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:Ot(l)}),n.push({name:`${i}_uncapitalize`,value:At(l)}),n.push({name:i,value:l})}return n}function Ot(e){return e.charAt(0).toUpperCase()+e.slice(1)}function At(e){return e.charAt(0).toLowerCase()+e.slice(1)}var L=require("@typescript-eslint/utils");var Bn=L.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ft="collapse-simple-objs-in-one-line",qn=j({maxLineLength:N(Q()),maxProperties:N(Q()),nestedObjMaxLineLength:N(Q()),nestedObjMaxProperties:N(Q()),ignoreTypesWithSuffix:N(z(A()))}),Xn=Bn({name:Ft,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:[qn]},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===L.AST_NODE_TYPES.ObjectExpression){let p=c.parent.type===L.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===L.AST_NODE_TYPES.Property&&y.value.type===L.AST_NODE_TYPES.ObjectExpression||y.type===L.AST_NODE_TYPES.Property&&y.value.type===L.AST_NODE_TYPES.ArrayExpression&&!y.value.elements.every(E=>E&&We(E))?!1:{text:n.getText(y),isNested:p,propsSize:h}}let m=[];for(let y of c.properties){if(y.type===L.AST_NODE_TYPES.Property&&!We(y.value))return!1;m.push(n.getText(y))}return{text:m.join(", "),isNested:p,propsSize:h}}else{let p=c.parent.parent?.type===L.AST_NODE_TYPES.TSPropertySignature,f=p?o:s,h=c.members.length;if(h>f)return!1;if(r.length>0&&c.parent.type===L.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===L.AST_NODE_TYPES.TSPropertySignature&&y.typeAnnotation?.typeAnnotation.type===L.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(y),isNested:p,propsSize:1}}if(c.parent.type===L.AST_NODE_TYPES.TSIntersectionType||c.parent.type===L.AST_NODE_TYPES.TSUnionType)return!1;let m=[];for(let y of c.members){if(y.type!==L.AST_NODE_TYPES.TSPropertySignature)return!1;let T=y.typeAnnotation?.typeAnnotation;if(!T||T.type===L.AST_NODE_TYPES.TSTypeLiteral||!Pt(T))return!1;if(T.type===L.AST_NODE_TYPES.TSTypeReference&&T.typeArguments){if(T.typeArguments.params.length>1)return!1;let g=T.typeArguments.params[0];if(!Pt(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!==L.AST_NODE_TYPES.JSXExpressionContainer){let T=0,E=n.getTokenAfter(c,{filter:g=>g.type!==L.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=
|
|
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 P=l.acquire(g),D=new Set,_=null;{let u=P.upper;for(;u&&(D.add(u),u.type!=="function");)u=u.upper;if(!u)return;_=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&&(Be(_.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:O}=w;if(O==="useRef"&&I.type==="Identifier")return!0;if(nr(w)&&I.type==="Identifier"){for(let F of u.references)F!==I&&m.add(F.identifier);return!0}else if(O==="useState"||O==="useReducer"){if(I.type==="ArrayPattern"&&I.elements.length===2&&R(u.identifiers)){if(I.elements[1]===u.identifiers[0]){if(O==="useState"){let F=u.references,Z=0;for(let ne=0;ne<F.length;ne++){if(F[ne].isWrite()&&Z++,Z>1)return!1;c.set(F[ne].identifier,I.elements[0])}}return!0}else if(I.elements[0]===u.identifiers[0]){if(O==="useState"){let F=u.references;for(let Z=0;Z<F.length;Z++)p.add(F[Z].identifier)}return!1}}}else if(O==="useTransition"&&I.type==="ArrayPattern"&&I.elements.length===2&&Array.isArray(u.identifiers)&&I.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=_.childScopes,w=null,I;for(I=0;I<x.length;I++){let O=x[I],F=O.block;if(b.type==="FunctionDeclaration"&&F===b||b.type==="VariableDeclarator"&&F.parent===b){w=O;break}}if(w==null)return!1;for(I=0;I<w.through.length;I++){let O=w.through[I];if(O.resolved!=null&&D.has(O.resolved.scope)&&!Te(O.resolved))return!1}return!0}let Te=y(V,f),In=y(q,h),ht=new Map;function wn(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,Ne=new Map;Et(P);function Et(u){for(let d of u.references){if(!d.resolved||!D.has(d.resolved.scope))continue;let b=Be(g,d.identifier),x=Dt(b),w=re(x,Ne);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"&&wn(d)&&ht.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(G.has(w))G.get(w).references.push(d);else{let O=d.resolved,F=Te(O)||In(O);G.set(w,{isStable:F,references:[d]})}}for(let d of u.childScopes)Et(d)}ht.forEach(({reference:u,dependencyNode:d},b)=>{let x=u.resolved.references,w=!1;for(let I=0;I<x.length;I++){let{identifier:O}=x[I],{parent:F}=O;if(F!=null&&F.type==="MemberExpression"&&!F.computed&&F.property.type==="Identifier"&&F.property.name==="current"&&F.parent.type==="AssignmentExpression"&&F.parent.left===F){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 Rn(u,d){je.has(d)||(je.add(d),i({node:u,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 he=new Set;if(G.forEach(({isStable:u,references:d},b)=>{u&&he.add(b),d.forEach(x=>{x.writeExpr&&Rn(x.writeExpr,b)})}),je.size>0)return;if(!k){let u=null;if(G.forEach(({isStable:d,references:b},x)=>{u||b.forEach(w=>{if(u)return;let I=w.identifier;if(!c.has(I))return;let F=w.from;for(;F.type!=="function";)F=F.upper;F.block===g&&(u=x)})}),u){let{suggestedDependencies:d}=Ye({dependencies:G,declaredDependencies:[],stableDependencies:he,externalDependencies:new Set,isEffect:!0});i({node:C,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;k.type!=="ArrayExpression"?i({node:k,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.`}):k.elements.forEach(u=>{if(u===null)return;if(u.type==="SpreadElement"){i({node:u,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(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,Ne)}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(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=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);ye.push({key:d,node:u}),x||ge.add(d)});let{suggestedDependencies:vn,unnecessaryDependencies:Ee,missingDependencies:oe,duplicateDependencies:bt}=Ye({dependencies:G,declaredDependencies:ye,stableDependencies:he,externalDependencies:ge,isEffect:v}),be=vn;if(bt.size+oe.size+Ee.size===0){if(t)return;Zn({declaredDependencies:ye,declaredDependenciesNode:k,componentScope:_,scope:P}).forEach(({construction:d,isUsedOutsideOfHook:b,depType:x})=>{let w=x==="function"?"useCallback":"useMemo",I=x==="function"?"definition":"initialization",O=`wrap the ${I} of '${d.name.name}' in its own ${w}() Hook.`,F=b?`To fix this, ${O}`:`Move it inside the ${S} callback. Alternatively, ${O}`,Z=x==="conditional"||x==="logical expression"?"could make":"makes",ne=`The '${d.name.name}' ${x} ${Z} the dependencies of ${S} Hook (at line ${k.loc.start.line}) change on every render. ${F}`,xt;b&&d.type==="Variable"&&x==="function"&&(xt=[{desc:`Wrap the ${I} of '${d.name.name}' in its own ${w}() Hook.`,fix(Ct){let[On,An]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Ct.insertTextBefore(d.node.init,On),Ct.insertTextAfter(d.node.init,An)]}}]),i({node:d.node,message:ne,suggest:xt})});return}!v&&oe.size>0&&(be=Ye({dependencies:G,declaredDependencies:[],stableDependencies:he,externalDependencies:ge,isEffect:v}).suggestedDependencies);function kn(){if(ye.length===0)return!0;let u=ye.map(b=>b.key),d=u.slice().sort();return u.join(",")===d.join(",")}kn()&&be.sort();function De(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("."),I=Ne.get(w)===!0;b+=I?"?.":"."}b+=d[x]}return b}function Le(u,d,b,x){return u.size===0?null:(u.size>1?"":d+" ")+b+" "+(u.size>1?"dependencies":"dependency")+": "+er(Array.from(u).sort().map(w=>"'"+De(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];P.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],I=Be(_.block,w.identifier);if(!I){b=!1;break}let O=I.parent;if(O==null){b=!1;break}if(O.type!=="MemberExpression"&&O.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(C)}.`)}if(!te&&oe.size>0){let u=null;oe.forEach(d=>{if(u)return;let b=_.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 I=!1,O;for(let F=0;F<x.references.length;F++)if(O=x.references[F].identifier,O!=null&&O.parent!=null&&(O.parent.type==="CallExpression"||O.parent.type==="OptionalCallExpression")&&O.parent.callee===O){I=!0;break}I&&(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,I;for(let O=0;O<x.length;O++){for(w=x[O].identifier,I=w.parent;I!=null&&I!==_.block;){if(I.type==="CallExpression"){let F=c.get(I.callee);if(F!=null){if(F.name===d)u={missingDep:d,setter:I.callee.name,form:"updater"};else if(p.has(w))u={missingDep:d,setter:I.callee.name,form:"reducer"};else{let Z=x[O].resolved;if(Z!=null){let ne=Z.defs[0];ne!=null&&ne.type==="Parameter"&&(u={missingDep:d,setter:I.callee.name,form:"inlineReducer"})}}break}}I=I.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:k,message:`React Hook ${n(C)} has `+(Le(oe,"a","missing","include")||Le(Ee,"an","unnecessary","exclude")||Le(bt,"a","duplicate","omit"))+te,suggest:[{desc:`Update the dependencies array to be: [${be.map(De).join(", ")}]`,fix(u){return u.replaceText(k,`[${be.map(De).join(", ")}]`)}}]})}function E(g){let k=Qn(g.callee,o);if(k===-1)return;let C=g.arguments[k],S=g.callee,v=Lt(S).name,P=g.arguments[k+1],D=/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&&!D)){if(!P&&!D){(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,P,S,v,D);return;case"Identifier":if(!P||P.elements&&P.elements.some(V=>V&&V.type==="Identifier"&&V.name===C.name))return;let _=r(g).set.get(C.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,P,S,v,D);return;case"VariableDeclarator":let V=R.node.init;if(!V)break;switch(V.type){case"ArrowFunctionExpression":case"FunctionExpression":T(V,P,S,v,D);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(_){return _.replaceText(P,`[${C.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(Gn.test(g.value))return t=!0,{CallExpression:k=>E(k,!0)}}return{CallExpression:g=>E(g)}}};function Ye({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,k=>{k.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("."),k=T;for(let C of g){let S=k.children.get(C);S||(S=o(),k.children.set(C,S)),k=S}return k}function l(T,E,g){let k=E.split("."),C=T;for(let S of k){let v=C.children.get(S);if(!v)return;g(v),C=v}}let c=new Set,p=new Set;f(a,c,p,T=>T);function f(T,E,g,k){T.children.forEach((C,S)=>{let v=k(S);if(C.isSatisfiedRecursively){C.isSubtreeUsed&&g.add(v);return}if(C.isUsed){E.add(v);return}f(C,E,g,P=>v+"."+P)})}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 Zn({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&&!_t(t,c.identifier))return!0}return!1}return s.map(([o,i])=>({construction:o.defs[0],depType:i,isUsedOutsideOfHook:a(o)}))}function Dt(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)?Dt(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function ze(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 ze(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 ze(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 ze(n,t,a),a}else throw new Error(`Unsupported node type: ${e.type}`)}function Lt(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=Lt(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 Be(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),tr(r,t))return r;if(_t(r,t))for(let[s,a]of Object.entries(r))s!=="parent"&&(Nt(a)?(a.parent=r,n.push(a)):Array.isArray(a)&&a.forEach(o=>{Nt(o)&&(o.parent=r,n.push(o))}))}return null}function er(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 Nt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function tr(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 _t(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function nr(e){return!1}var ce=require("@typescript-eslint/utils");var X=_e(require("typescript")),rr=ce.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Mt="improved-no-unnecessary-condition",ir=j({}),sr=["string","number","bigint","boolean","symbol","undefined","object","function","never"],or=new Set(sr),qe={name:Mt,rule:rr({name:Mt,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:[ir]},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||!ar(p,or))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 ar(e,t){return t.has(e)}var Re=require("@typescript-eslint/utils");var lr=Re.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="no-call-with-explicit-generics",cr=j({functions:z(A())}),pr=lr({name:$t,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:[cr]},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}})}}}}),Xe={name:$t,rule:pr};var pe=require("@typescript-eslint/utils"),ur=pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ut="no-call-with-inferred-generics",fr=ur({name:Ut,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}})}}}}),Ke={name:Ut,rule:fr};var Se=require("@typescript-eslint/utils"),mr=Se.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="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:Vt,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===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}})}}}}}),Je={name:Vt,rule:gr};var ve=require("@typescript-eslint/utils"),Sr=ve.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Wt="no-default-export",Tr=Sr({name:Wt,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===ve.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ge={name:Wt,rule:Tr};var Ht=require("@typescript-eslint/utils"),hr=Ht.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Yt="no-leaked-text-in-jsx",Er=[",",";","[","]","(",")"],br=hr({name:Yt,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="";Er.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:Yt,rule:br};var ie=require("@typescript-eslint/utils"),xr=ie.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Bt="no-non-camel-case-functions",Cr=/^[a-z][a-zA-Z0-9]*$/;function zt(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 Ir=xr({name:Bt,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&&!Cr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ie.AST_NODE_TYPES.TSTypeReference?zt(n):n.type===ie.AST_NODE_TYPES.TSUnionType&&n.types.some(s=>s.type===ie.AST_NODE_TYPES.TSTypeReference&&zt(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Qe={name:Bt,rule:Ir};var $=require("@typescript-eslint/utils");var et=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*tt(e){yield e,e.parent&&(yield*tt(e.parent))}function nt(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function qt(e,t,n){let s=n.getDeclaredVariables(e).find(a=>a.name===t||a.identifiers[0]?.parent.type===et.AST_NODE_TYPES.Property&&a.identifiers[0]?.parent.key.type===et.AST_NODE_TYPES.Identifier&&a.identifiers[0]?.parent.key.name===t);return s?s.references.filter(a=>!a.init):[]}var wr=$.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Xt="no-optional-root-props",Rr=wr({name:Xt,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 tt(o.identifier)){if("returnType"in i||i.type===$.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let l=i.parent;if(!l)return!1;if(l.type===$.TSESTree.AST_NODE_TYPES.TSTypeParameterInstantiation&&l.parent.type===$.TSESTree.AST_NODE_TYPES.TSTypeReference&&l.parent.typeName.type===$.TSESTree.AST_NODE_TYPES.Identifier&&l.parent.typeName.name==="FC"){let p=me(l.parent.parent,$.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!p)return!1;let f=ke(p,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(l.type===$.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression){let c=me(l,$.TSESTree.AST_NODE_TYPES.VariableDeclaration);return c?!!ke(c,e.sourceCode):!1}if(l.type===$.TSESTree.AST_NODE_TYPES.FunctionDeclaration)return!!ke(l,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=me(r,$.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===$.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(Oe(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===$.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(Oe(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=me(r.parent,$.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!a)return;let o=ke(a,e.sourceCode);if(!(!o||o.parent.type===$.TSESTree.AST_NODE_TYPES.CallExpression&&o.parent.callee.type===$.TSESTree.AST_NODE_TYPES.Identifier&&o.parent.callee.name==="memo"))for(let l of s.members)l.type===$.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(l)}}}});function Oe(e){return e?e.parent?.type===$.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===$.TSESTree.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function ke(e,t){if(Oe(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(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 rt={name:Xt,rule:Rr};var Kt=require("@typescript-eslint/utils"),Ae=_e(require("path"));var vr=Kt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Jt="no-relative-imports",kr=j({find:A(),replacement:A()}),Or=j({aliases:z(kr),rootDir:N(A()),allowNotFoundAliases:N(ue()),_dev_simulateFileName:N(A())}),Ar=vr({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:[Or]},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})}}}}),it={name:Jt,rule:Ar};var se=require("@typescript-eslint/utils");var st=_e(require("typescript")),Pr=se.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Gt="no-unnecessary-casting",Fr=j({additionalCastFunctions:N(z(j({name:A(),expectedType:Ce(["string","number"])})))}),ot={name:Gt,rule:Pr({name:Gt,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:[Fr],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&st.TypeFlags.NumberLike):!!(p.flags&st.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 at=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=Nr(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 Nr(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 jr=j({selectors:z(j({name:A(),selectorProp:N(A()),selectorArgPos:N(Q()),returnProp:N(A())}))}),Dr=W.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Zt="no-unused-selected-values",lt={name:Zt,rule:Dr({name:Zt,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[jr]},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=_r(a);if(!o)return;let i=r.get(o);if(!i)return;let l=Lr(a,i.selectorArgPos??0,i.selectorProp);if(!l)return;let c=Mr(l);if(!c)return;let p=Qt(c.properties,void 0);if(!p)return;if(s.id.type===W.AST_NODE_TYPES.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!==W.AST_NODE_TYPES.Identifier||i.returnProp)return;let f=$r(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 Lr(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 _r(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 Mr(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 Qt(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 $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):[]}var H=require("@typescript-eslint/utils");var ct=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=Ur(a);i&&(r=i);return}let o=Vr(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 Ur(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=nt(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?Wr(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 Vr(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||!nt(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=qt(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 Wr(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 M=require("@typescript-eslint/utils");var Hr=M.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function en(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 tn(e,...t){for(let n of t)e.set(...n);return e}var Yr=j({forceCheckOnFCPropTypesWithName:N(z(A()))}),nn="no-unused-type-props-in-args",pt=null,zr=Hr({name:nn,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:[Yr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!pt&&(pt=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&&pt?.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,l,p,T.typeAnnotation,!0);return}if(T?.type===M.AST_NODE_TYPES.TSInterfaceDeclaration){s(i,l,p,T.body,!0);return}}}function s(i,l,c,p,f){if(p.type===M.AST_NODE_TYPES.TSInterfaceBody){for(let h of p.body)h.type===M.AST_NODE_TYPES.TSPropertySignature&&h.key.type===M.AST_NODE_TYPES.Identifier&&c.set(h.key.name,h);return}if(p.type===M.AST_NODE_TYPES.TSTypeLiteral){tn(c,...en(p));return}if(p.type===M.AST_NODE_TYPES.TSIntersectionType){for(let h of p.types)s(i,l,c,h,!0);return}f||p.type===M.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===M.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===M.AST_NODE_TYPES.AssignmentPattern&&p.left.type===M.AST_NODE_TYPES.ObjectPattern&&a(i,l,[p.left])}function o(i,l){let c=[];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&&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===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 l=i.declarations[0];if(!l)return;let c=new Map,p=l.id.type===M.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===M.AST_NODE_TYPES.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===M.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(p){if(p.type===M.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===M.AST_NODE_TYPES.Identifier)r(!0,i,p.typeName,c,!1);else if(p.type===M.AST_NODE_TYPES.TSTypeLiteral)tn(c,...en(p));else if(p.type===M.AST_NODE_TYPES.TSIntersectionType)for(let f of p.types)f.type===M.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===M.AST_NODE_TYPES.Identifier?r(!0,i,f.typeName,c,!1):s(!0,i,c,f,!0);if(c.size!==0&&l.init?.type===M.AST_NODE_TYPES.ArrowFunctionExpression){let f=l.init.params[0];if(!f){e.report({node:l.init,messageId:"missingComponentParam"});return}f.type===M.AST_NODE_TYPES.ObjectPattern&&o(f,c)}}},FunctionDeclaration:function(i){a(!1,i,i.params)},ArrowFunctionExpression(i){a(!1,i,i.params)}}}}),ut={name:nn,rule:zr};var de=require("@typescript-eslint/utils"),Br=de.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),sn="prefer-named-functions",rn=new Map,qr=Br({name:sn,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=rn.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),rn.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)}`)}]})}}}}}),ft={name:sn,rule:qr};var U=require("@typescript-eslint/utils");var Xr=j({disallowedFunctions:z(j({name:A(),hookAlternative:A()}))});function mt(e){return/^use[A-Z]/.test(e)}function Kr(e){return/^[A-Z]/.test(e)}function Jr(e){return e.type===U.AST_NODE_TYPES.Identifier?mt(e.name):e.type===U.AST_NODE_TYPES.MemberExpression&&e.property.type===U.AST_NODE_TYPES.Identifier?mt(e.property.name):!1}function on(e,t){return e.type===U.AST_NODE_TYPES.Identifier?e.name===t:e.type===U.AST_NODE_TYPES.MemberExpression&&e.object.type===U.AST_NODE_TYPES.Identifier&&e.property.type===U.AST_NODE_TYPES.Identifier?e.object.name==="React"&&e.property.name===t:!1}function Gr(e){return!!(e.parent&&e.parent.type===U.AST_NODE_TYPES.CallExpression&&on(e.parent.callee,"forwardRef"))}function Zr(e){return!!(e.parent&&e.parent.type===U.AST_NODE_TYPES.CallExpression&&on(e.parent.callee,"memo"))}function Qr(e){if(e.type===U.AST_NODE_TYPES.FunctionDeclaration||e.type===U.AST_NODE_TYPES.FunctionExpression&&e.id)return e.id||void 0;if(e.type===U.AST_NODE_TYPES.FunctionExpression||e.type===U.AST_NODE_TYPES.ArrowFunctionExpression){if(e.parent.type===U.AST_NODE_TYPES.VariableDeclarator&&e.parent.init===e)return e.parent.id;if(e.parent.type===U.AST_NODE_TYPES.AssignmentExpression&&e.parent.right===e&&e.parent.operator==="=")return e.parent.left;if(e.parent.type===U.AST_NODE_TYPES.Property&&e.parent.value===e&&!e.parent.computed)return e.parent.key;if(e.parent.type===U.AST_NODE_TYPES.AssignmentPattern&&e.parent.right===e)return e.parent.left}}function ei(e){let t=e.parent,n=!1;for(;t;){if(t.type===U.AST_NODE_TYPES.FunctionDeclaration||t.type===U.AST_NODE_TYPES.FunctionExpression||t.type===U.AST_NODE_TYPES.ArrowFunctionExpression){let r=Qr(t);if(r&&r.type===U.AST_NODE_TYPES.Identifier){if(Kr(r.name)||mt(r.name))return!n;n=!0}else{if(Gr(t)||Zr(t))return!n;if(t.parent.type===U.AST_NODE_TYPES.CallExpression){let s=t.parent;Jr(s.callee)||(n=!0)}else t.parent.type===U.AST_NODE_TYPES.JSXExpressionContainer||(n=!0)}}t=t.parent}return!1}function ti(e){return e.callee.type===U.AST_NODE_TYPES.Identifier?e.callee.name:e.callee.type===U.AST_NODE_TYPES.MemberExpression&&e.callee.property.type===U.AST_NODE_TYPES.Identifier?e.callee.property.name:null}var dt=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 use the hook {{hookAlternative}} instead."},schema:[Xr],hasSuggestions:!0},defaultOptions:[{disallowedFunctions:[]}],create(e,[t]){let{disallowedFunctions:n}=t,r=new Map(n.map(s=>[s.name,s]));return{CallExpression(s){if(!ei(s))return;let a=ti(s);if(!a)return;let o=r.get(a);o&&e.report({node:s,messageId:"preferHookAlternative",data:{hookAlternative:o.hookAlternative},suggest:[{messageId:"preferHookAlternative",data:{message:`Replace with ${o.hookAlternative}`,hookAlternative:o.hookAlternative},fix:i=>s.callee.type===U.AST_NODE_TYPES.Identifier?i.replaceText(s.callee,o.hookAlternative):s.callee.type===U.AST_NODE_TYPES.MemberExpression&&s.callee.property.type===U.AST_NODE_TYPES.Identifier?i.replaceText(s.callee.property,o.hookAlternative):null}]})}}}});var Y=require("@typescript-eslint/utils");var ni=Y.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ln="prefer-single-line-if",ri=j({maxLineLength:N(Q()),maxNonSimpleConditionLength:N(Q())}),ii=ni({name:ln,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:[ri]},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(!pn(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=an(r.test);if(!f&&r.test.type===Y.AST_NODE_TYPES.UnaryExpression&&r.test.operator==="!"){let h=r.test.argument;an(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=si(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 an(e){return e.type===Y.AST_NODE_TYPES.CallExpression||e.type===Y.AST_NODE_TYPES.BinaryExpression||e.type===Y.AST_NODE_TYPES.MemberExpression&&cn(e)}function cn(e){return e.object.type===Y.AST_NODE_TYPES.MemberExpression?cn(e.object):e.object.type!==Y.AST_NODE_TYPES.Identifier}function si(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function pn(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?pn(t):!1}var yt={name:ln,rule:ii};var K=require("@typescript-eslint/utils");var oi=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),un="react-compiler-migration",ai=j({disallowHooks:N(z(j({name:A(),replacement:A()}))),disallowMethods:N(z(j({name:A(),replacement:N(A()),requireTrueProp:N(A())})))}),li=/eslint +react-compiler\/react-compiler: +\["error/;function ci(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 pi=oi({name:un,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:[ai]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(li.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&&ci(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)}]})}}}}}}:{}}}),gt={name:un,rule:pi};var Pe=require("@typescript-eslint/utils"),ui=Pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),fn="require-description",fi=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,mi=/^eslint-disable-(next-)?line$/u,di=ui({name:fn,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=yi(s);a!=null&&(r.has(a.kind)||a.description||e.report({loc:Si(s.loc),messageId:"missingDescription"}))}}}}}),mn={name:fn,rule:di};function yi(e){let{text:t,description:n}=gi(e.value);if(!t)return null;let r=fi.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let a=mi.test(s);if(e.type===Pe.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 gi(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Si(e){return{start:{line:e.start.line,column:-1},end:e.end}}function gn(e){return/^use[A-Z0-9]/.test(e)}function Fe(e){return e.type==="Identifier"?gn(e.name):e.type==="MemberExpression"&&!e.computed&&Fe(e.property)?e.object.type==="Identifier":!1}function Sn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Tn(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function hn(e){return!!(e.parent&&e.parent.callee&&Tn(e.parent.callee,"forwardRef"))}function En(e){return!!(e.parent&&e.parent.callee&&Tn(e.parent.callee,"memo"))}function St(e){for(;e;){let t=xn(e);if(t&&(Sn(t)||Fe(t))||hn(e)||En(e))return!0;e=e.parent}return!1}function dn(e){return!1}function Tt(e){return!1}var Ti=/eslint +react-compiler\/react-compiler: +\["error/,bn={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(Ti.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&&dn(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,v){let{cache:P}=h,D=P.get(S.id),_=new Set(v);if(_.has(S.id)){let R=[..._],V=R.slice(R.indexOf(S.id)+1);for(let q of V)f.add(q);return BigInt("0")}if(_.add(S.id),D!==void 0)return D;if(l.thrownSegments.includes(S))D=BigInt("0");else if(S.prevSegments.length===0)D=BigInt("1");else{D=BigInt("0");for(let R of S.prevSegments)D+=h(R,_)}return S.reachable&&D===BigInt("0")?P.delete(S.id):P.set(S.id,D),D}function m(S,v){let{cache:P}=m,D=P.get(S.id),_=new Set(v);if(_.has(S.id)){let R=Array.from(_),V=R.slice(R.indexOf(S.id)+1);for(let q of V)f.add(q);return BigInt("0")}if(_.add(S.id),D!==void 0)return D;if(l.thrownSegments.includes(S))D=BigInt("0");else if(S.nextSegments.length===0)D=BigInt("1");else{D=BigInt("0");for(let R of S.nextSegments)D+=m(R,_)}return P.set(S.id,D),D}function y(S){let{cache:v}=y,P=v.get(S.id);if(P===null)return 1/0;if(P!==void 0)return P;if(v.set(S.id,null),S.prevSegments.length===0)P=1;else{P=1/0;for(let D of S.prevSegments){let _=y(D);_<P&&(P=_)}P+=1}return v.set(S.id,P),P}h.cache=new Map,m.cache=new Map,y.cache=new Map;let T=m(l.initialSegment),E=xn(c),g=St(c),k=E?Sn(E)||Fe(E):hn(c)||En(c),C=1/0;for(let S of l.finalSegments){if(!S.reachable)continue;let v=y(S);v<C&&(C=v)}for(let[S,v]of p){if(!S.reachable)continue;let P=S.nextSegments.length===0?C<=y(S):C<y(S),D=h(S)*m(S),_=f.has(S.id);for(let R of v)if(_&&!Tt(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.`}),k){if(c.async&&e.report({node:R,message:`React Hook "${t(R)}" cannot be called in an async function.`}),!_&&D!==T&&!Tt(R)){let q=`React Hook "${t(R)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(P?" 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&&!Tt(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"&&gn(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(Fe(l.callee)){let c=yn(s),p=yn(a),f=c.get(p);f||(f=[],c.set(p,f)),f.push(l.callee)}l.callee.type==="Identifier"&&(l.callee.name==="useEffect"||dn(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){St(l)&&i(n(l))},ArrowFunctionExpression(l){St(l)&&i(n(l))}}}};function xn(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 yn(e){return e[e.length-1]}var Cn={[ut.name]:ut.rule,[Je.name]:Je.rule,[Ke.name]:Ke.rule,"rules-of-hooks":bn,"exhaustive-deps":jt,"require-description":mn.rule,[Ge.name]:Ge.rule,[Qe.name]:Qe.rule,[ft.name]:ft.rule,[Ve.name]:Ve.rule,[Xe.name]:Xe.rule,[it.name]:it.rule,[yt.name]:yt.rule,[rt.name]:rt.rule,[Ze.name]:Ze.rule,[He.name]:He.rule,[gt.name]:gt.rule,[Ue.name]:Ue.rule,[qe.name]:qe.rule,[ot.name]:ot.rule,[lt.name]:lt.rule,[ct.name]:ct.rule,[at.name]:at.rule,[dt.name]:dt.rule};var hi={rules:Cn};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 q,ESLintUtils as
|
|
2
|
-
`)||n.getCommentsInside(c).length>0)return;f.endsWith(";")&&(f=f.slice(0,-1));let h=`{ ${f} }`,m=
|
|
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 P=l.acquire(g),D=new Set,L=null;{let u=P.upper;for(;u&&(D.add(u),u.type!=="function");)u=u.upper;if(!u)return;L=u}let R=Array.isArray;function _(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&&(Me(L.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:O}=w;if(O==="useRef"&&I.type==="Identifier")return!0;if(qn(w)&&I.type==="Identifier"){for(let F of u.references)F!==I&&m.add(F.identifier);return!0}else if(O==="useState"||O==="useReducer"){if(I.type==="ArrayPattern"&&I.elements.length===2&&R(u.identifiers)){if(I.elements[1]===u.identifiers[0]){if(O==="useState"){let F=u.references,G=0;for(let ne=0;ne<F.length;ne++){if(F[ne].isWrite()&&G++,G>1)return!1;c.set(F[ne].identifier,I.elements[0])}}return!0}else if(I.elements[0]===u.identifiers[0]){if(O==="useState"){let F=u.references;for(let G=0;G<F.length;G++)p.add(F[G].identifier)}return!1}}}else if(O==="useTransition"&&I.type==="ArrayPattern"&&I.elements.length===2&&Array.isArray(u.identifiers)&&I.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=L.childScopes,w=null,I;for(I=0;I<x.length;I++){let O=x[I],F=O.block;if(b.type==="FunctionDeclaration"&&F===b||b.type==="VariableDeclarator"&&F.parent===b){w=O;break}}if(w==null)return!1;for(I=0;I<w.through.length;I++){let O=w.through[I];if(O.resolved!=null&&D.has(O.resolved.scope)&&!de(O.resolved))return!1}return!0}let de=y(_,f),Tn=y(B,h),ft=new Map;function hn(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,we=new Map;mt(P);function mt(u){for(let d of u.references){if(!d.resolved||!D.has(d.resolved.scope))continue;let b=Me(g,d.identifier),x=Rt(b),w=re(x,we);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)&&ft.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(J.has(w))J.get(w).references.push(d);else{let O=d.resolved,F=de(O)||Tn(O);J.set(w,{isStable:F,references:[d]})}}for(let d of u.childScopes)mt(d)}ft.forEach(({reference:u,dependencyNode:d},b)=>{let x=u.resolved.references,w=!1;for(let I=0;I<x.length;I++){let{identifier:O}=x[I],{parent:F}=O;if(F!=null&&F.type==="MemberExpression"&&!F.computed&&F.property.type==="Identifier"&&F.property.name==="current"&&F.parent.type==="AssignmentExpression"&&F.parent.left===F){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 Re=new Set;function En(u,d){Re.has(d)||(Re.add(d),i({node:u,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 ye=new Set;if(J.forEach(({isStable:u,references:d},b)=>{u&&ye.add(b),d.forEach(x=>{x.writeExpr&&En(x.writeExpr,b)})}),Re.size>0)return;if(!k){let u=null;if(J.forEach(({isStable:d,references:b},x)=>{u||b.forEach(w=>{if(u)return;let I=w.identifier;if(!c.has(I))return;let F=w.from;for(;F.type!=="function";)F=F.upper;F.block===g&&(u=x)})}),u){let{suggestedDependencies:d}=Le({dependencies:J,declaredDependencies:[],stableDependencies:ye,externalDependencies:new Set,isEffect:!0});i({node:C,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;k.type!=="ArrayExpression"?i({node:k,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.`}):k.elements.forEach(u=>{if(u===null)return;if(u.type==="SpreadElement"){i({node:u,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(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,we)}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(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=u;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let x=!L.through.some(w=>w.identifier===b);ue.push({key:d,node:u}),x||fe.add(d)});let{suggestedDependencies:bn,unnecessaryDependencies:ge,missingDependencies:ie,duplicateDependencies:dt}=Le({dependencies:J,declaredDependencies:ue,stableDependencies:ye,externalDependencies:fe,isEffect:v}),Se=bn;if(dt.size+ie.size+ge.size===0){if(t)return;Hn({declaredDependencies:ue,declaredDependenciesNode:k,componentScope:L,scope:P}).forEach(({construction:d,isUsedOutsideOfHook:b,depType:x})=>{let w=x==="function"?"useCallback":"useMemo",I=x==="function"?"definition":"initialization",O=`wrap the ${I} of '${d.name.name}' in its own ${w}() Hook.`,F=b?`To fix this, ${O}`:`Move it inside the ${S} callback. Alternatively, ${O}`,G=x==="conditional"||x==="logical expression"?"could make":"makes",ne=`The '${d.name.name}' ${x} ${G} the dependencies of ${S} Hook (at line ${k.loc.start.line}) change on every render. ${F}`,yt;b&&d.type==="Variable"&&x==="function"&&(yt=[{desc:`Wrap the ${I} of '${d.name.name}' in its own ${w}() Hook.`,fix(gt){let[Cn,In]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[gt.insertTextBefore(d.node.init,Cn),gt.insertTextAfter(d.node.init,In)]}}]),i({node:d.node,message:ne,suggest:yt})});return}!v&&ie.size>0&&(Se=Le({dependencies:J,declaredDependencies:[],stableDependencies:ye,externalDependencies:fe,isEffect:v}).suggestedDependencies);function xn(){if(ue.length===0)return!0;let u=ue.map(b=>b.key),d=u.slice().sort();return u.join(",")===d.join(",")}xn()&&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("."),I=we.get(w)===!0;b+=I?"?.":"."}b+=d[x]}return b}function ke(u,d,b,x){return u.size===0?null:(u.size>1?"":d+" ")+b+" "+(u.size>1?"dependencies":"dependency")+": "+zn(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];P.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],I=Me(L.block,w.identifier);if(!I){b=!1;break}let O=I.parent;if(O==null){b=!1;break}if(O.type!=="MemberExpression"&&O.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(C)}.`)}if(!te&&ie.size>0){let u=null;ie.forEach(d=>{if(u)return;let b=L.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 I=!1,O;for(let F=0;F<x.references.length;F++)if(O=x.references[F].identifier,O!=null&&O.parent!=null&&(O.parent.type==="CallExpression"||O.parent.type==="OptionalCallExpression")&&O.parent.callee===O){I=!0;break}I&&(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,I;for(let O=0;O<x.length;O++){for(w=x[O].identifier,I=w.parent;I!=null&&I!==L.block;){if(I.type==="CallExpression"){let F=c.get(I.callee);if(F!=null){if(F.name===d)u={missingDep:d,setter:I.callee.name,form:"updater"};else if(p.has(w))u={missingDep:d,setter:I.callee.name,form:"reducer"};else{let G=x[O].resolved;if(G!=null){let ne=G.defs[0];ne!=null&&ne.type==="Parameter"&&(u={missingDep:d,setter:I.callee.name,form:"inlineReducer"})}}break}}I=I.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:k,message:`React Hook ${n(C)} has `+(ke(ie,"a","missing","include")||ke(ge,"an","unnecessary","exclude")||ke(dt,"a","duplicate","omit"))+te,suggest:[{desc:`Update the dependencies array to be: [${Se.map(ve).join(", ")}]`,fix(u){return u.replaceText(k,`[${Se.map(ve).join(", ")}]`)}}]})}function E(g){let k=Yn(g.callee,o);if(k===-1)return;let C=g.arguments[k],S=g.callee,v=vt(S).name,P=g.arguments[k+1],D=/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&&!D)){if(!P&&!D){(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,P,S,v,D);return;case"Identifier":if(!P||P.elements&&P.elements.some(_=>_&&_.type==="Identifier"&&_.name===C.name))return;let L=r(g).set.get(C.name);if(L==null||L.defs==null)return;let R=L.defs[0];if(!R||!R.node||R.type!=="Variable"&&R.type!=="FunctionName")break;switch(R.node.type){case"FunctionDeclaration":T(R.node,P,S,v,D);return;case"VariableDeclarator":let _=R.node.init;if(!_)break;switch(_.type){case"ArrowFunctionExpression":case"FunctionExpression":T(_,P,S,v,D);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(L){return L.replaceText(P,`[${C.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(Wn.test(g.value))return t=!0,{CallExpression:k=>E(k,!0)}}return{CallExpression:g=>E(g)}}};function Le({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,k=>{k.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("."),k=T;for(let C of g){let S=k.children.get(C);S||(S=o(),k.children.set(C,S)),k=S}return k}function l(T,E,g){let k=E.split("."),C=T;for(let S of k){let v=C.children.get(S);if(!v)return;g(v),C=v}}let c=new Set,p=new Set;f(a,c,p,T=>T);function f(T,E,g,k){T.children.forEach((C,S)=>{let v=k(S);if(C.isSatisfiedRecursively){C.isSubtreeUsed&&g.add(v);return}if(C.isUsed){E.add(v);return}f(C,E,g,P=>v+"."+P)})}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 Hn({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&&!kt(t,c.identifier))return!0}return!1}return s.map(([o,i])=>({construction:o.defs[0],depType:i,isUsedOutsideOfHook:a(o)}))}function Rt(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)?Rt(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 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 _e(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 _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=re(n.object,t),s=re(n.property,null),a=`${r}.${s}`;return _e(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 Yn(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 Me(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Bn(r,t))return r;if(kt(r,t))for(let[s,a]of Object.entries(r))s!=="parent"&&(It(a)?(a.parent=r,n.push(a)):Array.isArray(a)&&a.forEach(o=>{It(o)&&(o.parent=r,n.push(o))}))}return null}function zn(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 It(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Bn(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 kt(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function qn(e){return!1}import{AST_NODE_TYPES as Ee,ESLintUtils as At}from"@typescript-eslint/utils";import X from"typescript";var Xn=At.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ot="improved-no-unnecessary-condition",Kn=j({}),Jn=["string","number","bigint","boolean","symbol","undefined","object","function","never"],Gn=new Set(Jn),$e={name:Ot,rule:Xn({name:Ot,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:[Kn]},defaultOptions:[{}],create(e){let t=At.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||!Zn(p,Gn))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 Zn(e,t){return t.has(e)}import{AST_NODE_TYPES as Qn,ESLintUtils as er}from"@typescript-eslint/utils";var tr=er.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Pt="no-call-with-explicit-generics",nr=j({functions:Y(A())}),rr=tr({name:Pt,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:[nr]},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}})}}}}),Ue={name:Pt,rule:rr};import{AST_NODE_TYPES as be,ESLintUtils as ir}from"@typescript-eslint/utils";var sr=ir.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ft="no-call-with-inferred-generics",or=sr({name:Ft,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}})}}}}),Ve={name:Ft,rule:or};import{ESLintUtils as ar,TSESTree as Nt}from"@typescript-eslint/utils";var lr=ar.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),jt="no-commented-out-code",cr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],pr=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],ur=lr({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 cr)if(r.startsWith(s))return{wrongPattern:s};for(let s of pr)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===Nt.AST_TOKEN_TYPES.Line||s.type===Nt.AST_TOKEN_TYPES.Block){let a=t(s.value);a&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:a.wrongPattern}})}}}}}),We={name:jt,rule:ur};import{ESLintUtils as fr,TSESTree as mr}from"@typescript-eslint/utils";var dr=fr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Dt="no-default-export",yr=dr({name:Dt,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===mr.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),He={name:Dt,rule:yr};import{ESLintUtils as gr}from"@typescript-eslint/utils";var Sr=gr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Lt="no-leaked-text-in-jsx",Tr=[",",";","[","]","(",")"],hr=Sr({name:Lt,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="";Tr.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Ye={name:Lt,rule:hr};import{AST_NODE_TYPES as ce,ESLintUtils as Er}from"@typescript-eslint/utils";var br=Er.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Mt="no-non-camel-case-functions",xr=/^[a-z][a-zA-Z0-9]*$/;function _t(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 Cr=br({name:Mt,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&&!xr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ce.TSTypeReference?_t(n):n.type===ce.TSUnionType&&n.types.some(s=>s.type===ce.TSTypeReference&&_t(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),ze={name:Mt,rule:Cr};import{ESLintUtils as Ir,TSESTree as V}from"@typescript-eslint/utils";import{AST_NODE_TYPES as $t}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*Be(e){yield e,e.parent&&(yield*Be(e.parent))}function qe(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function Ut(e,t,n){let s=n.getDeclaredVariables(e).find(a=>a.name===t||a.identifiers[0]?.parent.type===$t.Property&&a.identifiers[0]?.parent.key.type===$t.Identifier&&a.identifiers[0]?.parent.key.name===t);return s?s.references.filter(a=>!a.init):[]}var wr=Ir.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="no-optional-root-props",Rr=wr({name:Vt,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 Be(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&&!(Ce(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===V.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(Ce(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 Ce(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(Ce(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])&&!Ce(a[0].identifier.parent.parent))return a[0].identifier}var Xe={name:Vt,rule:Rr};import{ESLintUtils as vr}from"@typescript-eslint/utils";import Ke from"node:path";var kr=vr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Wt="no-relative-imports",Or=j({find:A(),replacement:A()}),Ar=j({aliases:Y(Or),rootDir:N(A()),allowNotFoundAliases:N(ae()),_dev_simulateFileName:N(A())}),Pr=kr({name:Wt,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:[Ar]},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=Ke.dirname(i);return Ke.resolve(l,o)}function a(o){let i=t.rootDir??process.cwd(),l=Ke.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})}}}}),Je={name:Wt,rule:Pr};import{AST_NODE_TYPES as me,ESLintUtils as Yt}from"@typescript-eslint/utils";import*as Ge from"typescript";var Fr=Yt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ht="no-unnecessary-casting",Nr=j({additionalCastFunctions:N(Y(j({name:A(),expectedType:Te(["string","number"])})))}),Ze={name:Ht,rule:Fr({name:Ht,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:[Nr],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=Yt.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&Ge.TypeFlags.NumberLike):!!(p.flags&Ge.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 Qe=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=jr(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 jr(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 Dr}from"@typescript-eslint/utils";var Lr=j({selectors:Y(j({name:A(),selectorProp:N(A()),selectorArgPos:N(Z()),returnProp:N(A())}))}),_r=Dr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),zt="no-unused-selected-values",et={name:zt,rule:_r({name:zt,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[Lr]},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=$r(a);if(!o)return;let i=r.get(o);if(!i)return;let l=Mr(a,i.selectorArgPos??0,i.selectorProp);if(!l)return;let c=Ur(l);if(!c)return;let p=Bt(c.properties,void 0);if(!p)return;if(s.id.type===H.ObjectPattern){let m=Bt(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=Vr(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 Mr(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 $r(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 Ur(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 Bt(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 Vr(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 tt=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=Wr(a);i&&(r=i);return}let o=Hr(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 Wr(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=qe(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?Yr(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 Hr(e,t){if(!(e.callee.type===W.Identifier&&e.callee.name==="useFormState")||e.parent.type!==W.VariableDeclarator||e.parent.id.type!==W.ObjectPattern||!qe(e.parent.id.properties,o=>o.type===W.Property&&o.key.type===W.Identifier&&o.key.name==="formFields"&&o))return null;let s=Ut(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 Yr(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 $,ESLintUtils as zr}from"@typescript-eslint/utils";var Br=zr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function qt(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 Xt(e,...t){for(let n of t)e.set(...n);return e}var qr=j({forceCheckOnFCPropTypesWithName:N(Y(A()))}),Kt="no-unused-type-props-in-args",nt=null,Xr=Br({name:Kt,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:[qr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!nt&&(nt=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&&nt?.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,l,p,T.typeAnnotation,!0);return}if(T?.type===$.TSInterfaceDeclaration){s(i,l,p,T.body,!0);return}}}function s(i,l,c,p,f){if(p.type===$.TSInterfaceBody){for(let h of p.body)h.type===$.TSPropertySignature&&h.key.type===$.Identifier&&c.set(h.key.name,h);return}if(p.type===$.TSTypeLiteral){Xt(c,...qt(p));return}if(p.type===$.TSIntersectionType){for(let h of p.types)s(i,l,c,h,!0);return}f||p.type===$.TSTypeReference&&p.typeName.type===$.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===$.AssignmentPattern&&p.left.type===$.ObjectPattern&&a(i,l,[p.left])}function o(i,l){let c=[];if(i.properties.at(-1)?.type===$.RestElement)return;for(let m of i.properties)m.type===$.Property&&m.key.type===$.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===$.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===$.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===$.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===$.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(p){if(p.type===$.TSTypeReference&&p.typeName.type===$.Identifier)r(!0,i,p.typeName,c,!1);else if(p.type===$.TSTypeLiteral)Xt(c,...qt(p));else if(p.type===$.TSIntersectionType)for(let f of p.types)f.type===$.TSTypeReference&&f.typeName.type===$.Identifier?r(!0,i,f.typeName,c,!1):s(!0,i,c,f,!0);if(c.size!==0&&l.init?.type===$.ArrowFunctionExpression){let f=l.init.params[0];if(!f){e.report({node:l.init,messageId:"missingComponentParam"});return}f.type===$.ObjectPattern&&o(f,c)}}},FunctionDeclaration:function(i){a(!1,i,i.params)},ArrowFunctionExpression(i){a(!1,i,i.params)}}}}),rt={name:Kt,rule:Xr};import{AST_NODE_TYPES as it,ESLintUtils as Kr}from"@typescript-eslint/utils";var Jr=Kr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Gt="prefer-named-functions",Jt=new Map,Gr=Jr({name:Gt,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=Jt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),Jt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===it.ArrowFunctionExpression&&r.id.type===it.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==it.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)}`)}]})}}}}}),st={name:Gt,rule:Gr};import{AST_NODE_TYPES as U}from"@typescript-eslint/utils";var Zr=j({disallowedFunctions:Y(j({name:A(),hookAlternative:A()}))});function ot(e){return/^use[A-Z]/.test(e)}function Qr(e){return/^[A-Z]/.test(e)}function ei(e){return e.type===U.Identifier?ot(e.name):e.type===U.MemberExpression&&e.property.type===U.Identifier?ot(e.property.name):!1}function Zt(e,t){return e.type===U.Identifier?e.name===t:e.type===U.MemberExpression&&e.object.type===U.Identifier&&e.property.type===U.Identifier?e.object.name==="React"&&e.property.name===t:!1}function ti(e){return!!(e.parent&&e.parent.type===U.CallExpression&&Zt(e.parent.callee,"forwardRef"))}function ni(e){return!!(e.parent&&e.parent.type===U.CallExpression&&Zt(e.parent.callee,"memo"))}function ri(e){if(e.type===U.FunctionDeclaration||e.type===U.FunctionExpression&&e.id)return e.id||void 0;if(e.type===U.FunctionExpression||e.type===U.ArrowFunctionExpression){if(e.parent.type===U.VariableDeclarator&&e.parent.init===e)return e.parent.id;if(e.parent.type===U.AssignmentExpression&&e.parent.right===e&&e.parent.operator==="=")return e.parent.left;if(e.parent.type===U.Property&&e.parent.value===e&&!e.parent.computed)return e.parent.key;if(e.parent.type===U.AssignmentPattern&&e.parent.right===e)return e.parent.left}}function ii(e){let t=e.parent,n=!1;for(;t;){if(t.type===U.FunctionDeclaration||t.type===U.FunctionExpression||t.type===U.ArrowFunctionExpression){let r=ri(t);if(r&&r.type===U.Identifier){if(Qr(r.name)||ot(r.name))return!n;n=!0}else{if(ti(t)||ni(t))return!n;if(t.parent.type===U.CallExpression){let s=t.parent;ei(s.callee)||(n=!0)}else t.parent.type===U.JSXExpressionContainer||(n=!0)}}t=t.parent}return!1}function si(e){return e.callee.type===U.Identifier?e.callee.name:e.callee.type===U.MemberExpression&&e.callee.property.type===U.Identifier?e.callee.property.name:null}var at=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 use the hook {{hookAlternative}} instead."},schema:[Zr],hasSuggestions:!0},defaultOptions:[{disallowedFunctions:[]}],create(e,[t]){let{disallowedFunctions:n}=t,r=new Map(n.map(s=>[s.name,s]));return{CallExpression(s){if(!ii(s))return;let a=si(s);if(!a)return;let o=r.get(a);o&&e.report({node:s,messageId:"preferHookAlternative",data:{hookAlternative:o.hookAlternative},suggest:[{messageId:"preferHookAlternative",data:{message:`Replace with ${o.hookAlternative}`,hookAlternative:o.hookAlternative},fix:i=>s.callee.type===U.Identifier?i.replaceText(s.callee,o.hookAlternative):s.callee.type===U.MemberExpression&&s.callee.property.type===U.Identifier?i.replaceText(s.callee.property,o.hookAlternative):null}]})}}}});import{AST_NODE_TYPES as z,AST_TOKEN_TYPES as Qt,ESLintUtils as oi}from"@typescript-eslint/utils";var ai=oi.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),tn="prefer-single-line-if",li=j({maxLineLength:N(Z()),maxNonSimpleConditionLength:N(Z())}),ci=ai({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:[li]},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(!rn(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=en(r.test);if(!f&&r.test.type===z.UnaryExpression&&r.test.operator==="!"){let h=r.test.argument;en(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===Qt.Punctuator&&l.value==="}"){let f=n.getTokenAfter(l);if(f&&f.type===Qt.Keyword&&(f.value==="else"||f.value==="catch"))return}let c=pi(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 en(e){return e.type===z.CallExpression||e.type===z.BinaryExpression||e.type===z.MemberExpression&&nn(e)}function nn(e){return e.object.type===z.MemberExpression?nn(e.object):e.object.type!==z.Identifier}function pi(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===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?rn(t):!1}var lt={name:tn,rule:ci};import{AST_NODE_TYPES as ee,ESLintUtils as ui}from"@typescript-eslint/utils";var fi=ui.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),sn="react-compiler-migration",mi=j({disallowHooks:N(Y(j({name:A(),replacement:A()}))),disallowMethods:N(Y(j({name:A(),replacement:N(A()),requireTrueProp:N(A())})))}),di=/eslint +react-compiler\/react-compiler: +\["error/;function yi(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 gi=fi({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:[mi]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(di.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&&yi(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)}]})}}}}}}:{}}}),ct={name:sn,rule:gi};import{ESLintUtils as Si,TSESTree as Ti}from"@typescript-eslint/utils";var hi=Si.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),on="require-description",Ei=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,bi=/^eslint-disable-(next-)?line$/u,xi=hi({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=Ci(s);a!=null&&(r.has(a.kind)||a.description||e.report({loc:wi(s.loc),messageId:"missingDescription"}))}}}}}),an={name:on,rule:xi};function Ci(e){let{text:t,description:n}=Ii(e.value);if(!t)return null;let r=Ei.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let a=bi.test(s);if(e.type===Ti.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 Ii(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function wi(e){return{start:{line:e.start.line,column:-1},end:e.end}}function pn(e){return/^use[A-Z0-9]/.test(e)}function Ie(e){return e.type==="Identifier"?pn(e.name):e.type==="MemberExpression"&&!e.computed&&Ie(e.property)?e.object.type==="Identifier":!1}function un(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 pt(e){for(;e;){let t=gn(e);if(t&&(un(t)||Ie(t))||mn(e)||dn(e))return!0;e=e.parent}return!1}function ln(e){return!1}function ut(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 l of e.sourceCode.getAllComments())if(Ri.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&&ln(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,v){let{cache:P}=h,D=P.get(S.id),L=new Set(v);if(L.has(S.id)){let R=[...L],_=R.slice(R.indexOf(S.id)+1);for(let B of _)f.add(B);return BigInt("0")}if(L.add(S.id),D!==void 0)return D;if(l.thrownSegments.includes(S))D=BigInt("0");else if(S.prevSegments.length===0)D=BigInt("1");else{D=BigInt("0");for(let R of S.prevSegments)D+=h(R,L)}return S.reachable&&D===BigInt("0")?P.delete(S.id):P.set(S.id,D),D}function m(S,v){let{cache:P}=m,D=P.get(S.id),L=new Set(v);if(L.has(S.id)){let R=Array.from(L),_=R.slice(R.indexOf(S.id)+1);for(let B of _)f.add(B);return BigInt("0")}if(L.add(S.id),D!==void 0)return D;if(l.thrownSegments.includes(S))D=BigInt("0");else if(S.nextSegments.length===0)D=BigInt("1");else{D=BigInt("0");for(let R of S.nextSegments)D+=m(R,L)}return P.set(S.id,D),D}function y(S){let{cache:v}=y,P=v.get(S.id);if(P===null)return 1/0;if(P!==void 0)return P;if(v.set(S.id,null),S.prevSegments.length===0)P=1;else{P=1/0;for(let D of S.prevSegments){let L=y(D);L<P&&(P=L)}P+=1}return v.set(S.id,P),P}h.cache=new Map,m.cache=new Map,y.cache=new Map;let T=m(l.initialSegment),E=gn(c),g=pt(c),k=E?un(E)||Ie(E):mn(c)||dn(c),C=1/0;for(let S of l.finalSegments){if(!S.reachable)continue;let v=y(S);v<C&&(C=v)}for(let[S,v]of p){if(!S.reachable)continue;let P=S.nextSegments.length===0?C<=y(S):C<y(S),D=h(S)*m(S),L=f.has(S.id);for(let R of v)if(L&&!ut(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.`}),k){if(c.async&&e.report({node:R,message:`React Hook "${t(R)}" cannot be called in an async function.`}),!L&&D!==T&&!ut(R)){let B=`React Hook "${t(R)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(P?" 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 _=`React Hook "${t(R)}" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:R,message:_})}else if(E){let _=`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:_})}else if(c.type==="Program"){let _=`React Hook "${t(R)}" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:R,message:_})}else if(g&&!ut(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"&&pn(B.parent.id.name))return}let _=`React Hook "${t(R)}" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.`;e.report({node:R,message:_})}}},CallExpression(l){if(Ie(l.callee)){let c=cn(s),p=cn(a),f=c.get(p);f||(f=[],c.set(p,f)),f.push(l.callee)}l.callee.type==="Identifier"&&(l.callee.name==="useEffect"||ln(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){pt(l)&&i(n(l))},ArrowFunctionExpression(l){pt(l)&&i(n(l))}}}};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={[rt.name]:rt.rule,[We.name]:We.rule,[Ve.name]:Ve.rule,"rules-of-hooks":yn,"exhaustive-deps":wt,"require-description":an.rule,[He.name]:He.rule,[ze.name]:ze.rule,[st.name]:st.rule,[Ne.name]:Ne.rule,[Ue.name]:Ue.rule,[Je.name]:Je.rule,[lt.name]:lt.rule,[Xe.name]:Xe.rule,[Ye.name]:Ye.rule,[De.name]:De.rule,[ct.name]:ct.rule,[Pe.name]:Pe.rule,[$e.name]:$e.rule,[Ze.name]:Ze.rule,[et.name]:et.rule,[tt.name]:tt.rule,[Qe.name]:Qe.rule,[at.name]:at.rule};var Po={rules:Sn};export{Po 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};
|