@ls-stack/extended-lint 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extended-lint.js +4 -4
- package/dist/extended-lint.mjs +4 -4
- package/package.json +1 -1
package/dist/extended-lint.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var en=Object.create;var me=Object.defineProperty;var tn=Object.getOwnPropertyDescriptor;var nn=Object.getOwnPropertyNames;var rn=Object.getPrototypeOf,sn=Object.prototype.hasOwnProperty;var on=(e,t)=>{for(var n in t)me(e,n,{get:t[n],enumerable:!0})},Qe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of nn(t))!sn.call(e,a)&&a!==n&&me(e,a,{get:()=>t[a],enumerable:!(r=tn(t,a))||r.enumerable});return e};var an=(e,t,n)=>(n=e!=null?en(rn(e)):{},Qe(t||!e||!e.__esModule?me(n,"default",{value:e,enumerable:!0}):n,e)),ln=e=>Qe(me({},"__esModule",{value:!0}),e);var xr={};on(xr,{extendedLintPlugin:()=>br});module.exports=ln(xr);var U=require("@typescript-eslint/utils");var Ie=Symbol.for("optional");function M(e){return{...e,[Ie]:!0}}function et(e,t){return{enum:e,...t}}function re(e){return{...e,type:"boolean"}}function L(e){return{...e,type:"string"}}function X(e){return{...e,type:"number"}}function tt(e){return{...e,type:"integer"}}function Y(e,t){return{...t,type:"array",items:e}}function F(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,a=[];for(r in e)e[r][Ie]?e[r][Ie]=void 0:a.push(r);a.length>0&&(n.required=a)}return n}function we(...e){return{anyOf:e}}var cn=U.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),rt="react-compiler-extra",pn=F({runOnlyWithEnableCompilerDirective:M(re())}),un=/eslint +react-compiler\/react-compiler: +\["error/;function fn(e){return e.type===U.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===U.AST_NODE_TYPES.MemberExpression&&e.property.type===U.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var mn=/\bthis[.[]/;function nt(e){return mn.test(e)}var dn=cn({name:rt,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:[pn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let u of e.sourceCode.getAllComments())if(un.test(u.value)){n=!0;break}if(!n)return{}}function r(u){for(let c of u.properties)if(c.type===U.AST_NODE_TYPES.Property&&c.method&&c.value.type===U.AST_NODE_TYPES.FunctionExpression){let l=e.sourceCode,s=l.getText(c.key),o=c.value,i=l.getText(o.body);if(nt(i))e.report({node:c,messageId:"thisKeywordInMethod"});else{let f=o.params.map(I=>l.getText(I)).join(", "),T="";o.generator?T=`${s}: function* (${f}) ${i}`:T=`${s}: (${f}) => ${i}`,e.report({node:c,messageId:"objectMethodIsNotSupported",fix:I=>I.replaceText(c,T)})}}}function a(u){for(let c of u.properties)if(c.type===U.AST_NODE_TYPES.Property&&c.value.type===U.AST_NODE_TYPES.ObjectExpression){for(let l of c.value.properties)if(l.type===U.AST_NODE_TYPES.Property&&l.method&&l.value.type===U.AST_NODE_TYPES.FunctionExpression){let o=e.sourceCode.getText(l.value.body);nt(o)&&e.report({node:l,messageId:"thisKeywordInMethod"})}}}return{CallExpression(u){if(fn(u.callee))for(let c of u.arguments){if(c.type===U.AST_NODE_TYPES.ObjectExpression&&(r(c),a(c)),c.type===U.AST_NODE_TYPES.ArrowFunctionExpression&&(c.body.type===U.AST_NODE_TYPES.ObjectExpression&&(r(c.body),a(c.body)),c.body.type===U.AST_NODE_TYPES.BlockStatement))for(let l of c.body.body)l.type===U.AST_NODE_TYPES.ReturnStatement&&l.argument?.type===U.AST_NODE_TYPES.ObjectExpression&&(r(l.argument),a(l.argument));if(c.type===U.AST_NODE_TYPES.FunctionExpression)for(let l of c.body.body)l.type===U.AST_NODE_TYPES.ReturnStatement&&l.argument?.type===U.AST_NODE_TYPES.ObjectExpression&&(r(l.argument),a(l.argument))}}}}}),Ce={name:rt,rule:dn};var ie=require("@typescript-eslint/utils");var yn=ie.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),gn=F({disallow:M(Y(F({selector:L(),message:L(),replace:M(we(L(),F({regex:L(),with:L()}))),replaceType:M(et(["suggestion","autofix"]))}))),__dev_simulateFileName:M(L()),mustMatchSyntax:M(Y(F({includeRegex:L(),mustCallFn:Y(F({anyCall:Y(F({fn:L(),withArgs:Y(F({atIndex:tt(),literal:we(L(),X(),re())}))})),message:M(L())}))})))}),ot="advanced-no-restricted-syntax",hn=yn({name:ot,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[gn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:a,disallow:u}=t,c=a??e.filename,l=[],s=new Set;for(let{includeRegex:i,mustCallFn:f}of r??[]){let T=Sn(c,new RegExp(i));if(!T)continue;let I=b=>{let d=b;for(let{name:x,value:g}of T)d=d.replaceAll(x,g);return d};for(let{anyCall:b,message:d}of f){let x=`Expected file to call the function: ${b.map(({fn:g})=>g).join(" or ")}`;s.add(x),l.push(g=>{let{callee:D}=g;if(D.type===ie.AST_NODE_TYPES.Identifier){for(let{fn:v,withArgs:y}of b)if(D.name===v){s.delete(x);for(let C of y){let R=g.arguments[C.atIndex],k=typeof C.literal=="string"?I(C.literal):C.literal;if(!R){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${k}" at index ${C.atIndex}${d?`: ${I(d)}`:""}`}});continue}if(R.type!==ie.AST_NODE_TYPES.Literal){e.report({node:R,messageId:"default",data:{message:`Argument at position ${C.atIndex} should the literal "${k}"${d?`: ${I(d)}`:""}`}});continue}R.value!==k&&e.report({node:R,messageId:"default",data:{message:`Argument should have the value "${k}"${d?`: ${I(d)}`:""}`},fix:$=>$.replaceText(R,typeof k=="string"?`'${k}'`:String(k))})}break}}})}}for(let{selector:i,message:f,replace:T,replaceType:I="suggestion"}of u??[]){if(i==="CallExpression"){l.push(b=>{o(T,b,f,I)});continue}n[i]=b=>{o(T,b,f,I)}}return l.length>0&&(n.CallExpression=i=>{if(i.type===ie.AST_NODE_TYPES.CallExpression)for(let f of l)f(i)}),n["Program:exit"]=i=>{for(let f of s)e.report({node:i,messageId:"default",data:{message:`${f}`}})},n;function o(i,f,T,I){let b=d=>{if(!i)return null;if(typeof i=="string")return d.replaceText(f,i);{let x=new RegExp(i.regex),g=e.sourceCode.getText(f);return d.replaceText(f,g.replace(x,i.with))}};e.report({node:f,messageId:"default",data:{message:T},fix:i&&I==="autofix"?b:void 0,suggest:i&&I==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof i=="string"?i:i.with}"`},fix:b}]:void 0})}}});function Sn(e,t){let n=[],r=t.exec(e);if(!r)return null;let[a,...u]=r;n.push({name:"$0_lowercase",value:a.toLowerCase()}),n.push({name:"$0_capitalize",value:it(a)}),n.push({name:"$0_uncapitalize",value:st(a)}),n.push({name:"$0",value:a});for(let c=0;c<u.length;c++){let l=`$${c+1}`,s=u[c];n.push({name:`${l}_lowercase`,value:s.toLowerCase()}),n.push({name:`${l}_capitalize`,value:it(s)}),n.push({name:`${l}_uncapitalize`,value:st(s)}),n.push({name:l,value:s})}return n}function it(e){return e.charAt(0).toUpperCase()+e.slice(1)}function st(e){return e.charAt(0).toLowerCase()+e.slice(1)}var Re={name:ot,rule:hn};var _=require("@typescript-eslint/utils");var Tn=_.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),lt="collapse-simple-objs-in-one-line",En=F({maxLineLength:M(X()),maxProperties:M(X()),nestedObjMaxLineLength:M(X()),nestedObjMaxProperties:M(X()),ignoreTypesWithSuffix:M(Y(L()))}),bn=Tn({name:lt,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:[En]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],a=t.maxProperties??2,u=t.nestedObjMaxLineLength??t.maxLineLength,c=t.nestedObjMaxProperties??3;function l(o){if(o.type===_.AST_NODE_TYPES.ObjectExpression){let i=o.parent.type===_.AST_NODE_TYPES.Property,f=i?c:a,T=o.properties.length;if(T>f)return!1;if(T===1){let b=o.properties[0];return b.type===_.AST_NODE_TYPES.Property&&(b.value.type===_.AST_NODE_TYPES.ObjectExpression||b.value.type===_.AST_NODE_TYPES.ArrayExpression)?!1:{text:n.getText(b),isNested:i,propsSize:T}}let I=[];for(let b of o.properties){if(b.type===_.AST_NODE_TYPES.Property){let d=b.value.type;if(!(d===_.AST_NODE_TYPES.Literal||d===_.AST_NODE_TYPES.Identifier||d===_.AST_NODE_TYPES.TemplateLiteral||d===_.AST_NODE_TYPES.TaggedTemplateExpression))return!1}I.push(n.getText(b))}return{text:I.join(", "),isNested:i,propsSize:T}}else{let i=o.parent.parent?.type===_.AST_NODE_TYPES.TSPropertySignature,f=i?c:a,T=o.members.length;if(T>f)return!1;if(r.length>0&&o.parent.type===_.AST_NODE_TYPES.TSTypeAliasDeclaration){let b=o.parent.id.name;if(r.some(d=>b.endsWith(d)))return!1}if(T===1){let b=o.members[0];return b.type===_.AST_NODE_TYPES.TSPropertySignature&&b.typeAnnotation?.typeAnnotation.type===_.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(b),isNested:i,propsSize:1}}if(o.parent.type===_.AST_NODE_TYPES.TSIntersectionType||o.parent.type===_.AST_NODE_TYPES.TSUnionType)return!1;let I=[];for(let b of o.members){if(b.type!==_.AST_NODE_TYPES.TSPropertySignature)return!1;let d=b.typeAnnotation?.typeAnnotation;if(!d||d.type===_.AST_NODE_TYPES.TSTypeLiteral||!at(d.type))return!1;if(d.type===_.AST_NODE_TYPES.TSTypeReference&&d.typeArguments){if(d.typeArguments.params.length>1)return!1;let g=d.typeArguments.params[0];if(!at(g.type))return!1}let x=n.getText(b).trim();(x.endsWith(";")||x.endsWith(","))&&(x=x.slice(0,-1)),I.push(x)}return{text:I.join("; "),isNested:i,propsSize:T}}}function s(o){if(o.loc.start.line===o.loc.end.line||o.parent.type!==_.AST_NODE_TYPES.JSXExpressionContainer&&n.getTokenAfter(o,{filter:x=>{let g=x.type===_.AST_TOKEN_TYPES.Punctuator&&x.value===",",D=x.type===_.AST_TOKEN_TYPES.Punctuator&&x.value===";";return!g&&!D}})?.loc.start.line===o.loc.end.line)return;let i=l(o);if(!i)return;let f=i.text;if(f.includes(`
|
|
2
|
-
`)||n.getCommentsInside(o).length>0)return;f.endsWith(";")&&(f=f.slice(0,-1));let T=`{ ${f} }`,I=In(n,o),
|
|
1
|
+
"use strict";var en=Object.create;var me=Object.defineProperty;var tn=Object.getOwnPropertyDescriptor;var nn=Object.getOwnPropertyNames;var rn=Object.getPrototypeOf,sn=Object.prototype.hasOwnProperty;var on=(e,t)=>{for(var n in t)me(e,n,{get:t[n],enumerable:!0})},Qe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of nn(t))!sn.call(e,a)&&a!==n&&me(e,a,{get:()=>t[a],enumerable:!(r=tn(t,a))||r.enumerable});return e};var an=(e,t,n)=>(n=e!=null?en(rn(e)):{},Qe(t||!e||!e.__esModule?me(n,"default",{value:e,enumerable:!0}):n,e)),ln=e=>Qe(me({},"__esModule",{value:!0}),e);var Ir={};on(Ir,{extendedLintPlugin:()=>br});module.exports=ln(Ir);var U=require("@typescript-eslint/utils");var Ie=Symbol.for("optional");function L(e){return{...e,[Ie]:!0}}function et(e,t){return{enum:e,...t}}function re(e){return{...e,type:"boolean"}}function M(e){return{...e,type:"string"}}function X(e){return{...e,type:"number"}}function tt(e){return{...e,type:"integer"}}function Y(e,t){return{...t,type:"array",items:e}}function W(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,a=[];for(r in e)e[r][Ie]?e[r][Ie]=void 0:a.push(r);a.length>0&&(n.required=a)}return n}function we(...e){return{anyOf:e}}var cn=U.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),rt="react-compiler-extra",pn=W({runOnlyWithEnableCompilerDirective:L(re())}),un=/eslint +react-compiler\/react-compiler: +\["error/;function fn(e){return e.type===U.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===U.AST_NODE_TYPES.MemberExpression&&e.property.type===U.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var mn=/\bthis[.[]/;function nt(e){return mn.test(e)}var dn=cn({name:rt,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:[pn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let u of e.sourceCode.getAllComments())if(un.test(u.value)){n=!0;break}if(!n)return{}}function r(u){for(let c of u.properties)if(c.type===U.AST_NODE_TYPES.Property&&c.method&&c.value.type===U.AST_NODE_TYPES.FunctionExpression){let l=e.sourceCode,s=l.getText(c.key),o=c.value,i=l.getText(o.body);if(nt(i))e.report({node:c,messageId:"thisKeywordInMethod"});else{let f=o.params.map(I=>l.getText(I)).join(", "),T="";o.generator?T=`${s}: function* (${f}) ${i}`:T=`${s}: (${f}) => ${i}`,e.report({node:c,messageId:"objectMethodIsNotSupported",fix:I=>I.replaceText(c,T)})}}}function a(u){for(let c of u.properties)if(c.type===U.AST_NODE_TYPES.Property&&c.value.type===U.AST_NODE_TYPES.ObjectExpression){for(let l of c.value.properties)if(l.type===U.AST_NODE_TYPES.Property&&l.method&&l.value.type===U.AST_NODE_TYPES.FunctionExpression){let o=e.sourceCode.getText(l.value.body);nt(o)&&e.report({node:l,messageId:"thisKeywordInMethod"})}}}return{CallExpression(u){if(fn(u.callee))for(let c of u.arguments){if(c.type===U.AST_NODE_TYPES.ObjectExpression&&(r(c),a(c)),c.type===U.AST_NODE_TYPES.ArrowFunctionExpression&&(c.body.type===U.AST_NODE_TYPES.ObjectExpression&&(r(c.body),a(c.body)),c.body.type===U.AST_NODE_TYPES.BlockStatement))for(let l of c.body.body)l.type===U.AST_NODE_TYPES.ReturnStatement&&l.argument?.type===U.AST_NODE_TYPES.ObjectExpression&&(r(l.argument),a(l.argument));if(c.type===U.AST_NODE_TYPES.FunctionExpression)for(let l of c.body.body)l.type===U.AST_NODE_TYPES.ReturnStatement&&l.argument?.type===U.AST_NODE_TYPES.ObjectExpression&&(r(l.argument),a(l.argument))}}}}}),Ce={name:rt,rule:dn};var ie=require("@typescript-eslint/utils");var yn=ie.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),gn=W({disallow:L(Y(W({selector:M(),message:M(),replace:L(we(M(),W({regex:M(),with:M()}))),replaceType:L(et(["suggestion","autofix"]))}))),__dev_simulateFileName:L(M()),mustMatchSyntax:L(Y(W({includeRegex:M(),mustCallFn:Y(W({anyCall:Y(W({fn:M(),withArgs:Y(W({atIndex:tt(),literal:we(M(),X(),re())}))})),message:L(M())}))})))}),ot="advanced-no-restricted-syntax",hn=yn({name:ot,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[gn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:a,disallow:u}=t,c=a??e.filename,l=[],s=new Set;for(let{includeRegex:i,mustCallFn:f}of r??[]){let T=Sn(c,new RegExp(i));if(!T)continue;let I=x=>{let d=x;for(let{name:b,value:g}of T)d=d.replaceAll(b,g);return d};for(let{anyCall:x,message:d}of f){let b=`Expected file to call the function: ${x.map(({fn:g})=>g).join(" or ")}`;s.add(b),l.push(g=>{let{callee:D}=g;if(D.type===ie.AST_NODE_TYPES.Identifier){for(let{fn:v,withArgs:y}of x)if(D.name===v){s.delete(b);for(let C of y){let R=g.arguments[C.atIndex],k=typeof C.literal=="string"?I(C.literal):C.literal;if(!R){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${k}" at index ${C.atIndex}${d?`: ${I(d)}`:""}`}});continue}if(R.type!==ie.AST_NODE_TYPES.Literal){e.report({node:R,messageId:"default",data:{message:`Argument at position ${C.atIndex} should the literal "${k}"${d?`: ${I(d)}`:""}`}});continue}R.value!==k&&e.report({node:R,messageId:"default",data:{message:`Argument should have the value "${k}"${d?`: ${I(d)}`:""}`},fix:$=>$.replaceText(R,typeof k=="string"?`'${k}'`:String(k))})}break}}})}}for(let{selector:i,message:f,replace:T,replaceType:I="suggestion"}of u??[]){if(i==="CallExpression"){l.push(x=>{o(T,x,f,I)});continue}n[i]=x=>{o(T,x,f,I)}}return l.length>0&&(n.CallExpression=i=>{if(i.type===ie.AST_NODE_TYPES.CallExpression)for(let f of l)f(i)}),n["Program:exit"]=i=>{for(let f of s)e.report({node:i,messageId:"default",data:{message:`${f}`}})},n;function o(i,f,T,I){let x=d=>{if(!i)return null;if(typeof i=="string")return d.replaceText(f,i);{let b=new RegExp(i.regex),g=e.sourceCode.getText(f);return d.replaceText(f,g.replace(b,i.with))}};e.report({node:f,messageId:"default",data:{message:T},fix:i&&I==="autofix"?x:void 0,suggest:i&&I==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof i=="string"?i:i.with}"`},fix:x}]:void 0})}}});function Sn(e,t){let n=[],r=t.exec(e);if(!r)return null;let[a,...u]=r;n.push({name:"$0_lowercase",value:a.toLowerCase()}),n.push({name:"$0_capitalize",value:it(a)}),n.push({name:"$0_uncapitalize",value:st(a)}),n.push({name:"$0",value:a});for(let c=0;c<u.length;c++){let l=`$${c+1}`,s=u[c];n.push({name:`${l}_lowercase`,value:s.toLowerCase()}),n.push({name:`${l}_capitalize`,value:it(s)}),n.push({name:`${l}_uncapitalize`,value:st(s)}),n.push({name:l,value:s})}return n}function it(e){return e.charAt(0).toUpperCase()+e.slice(1)}function st(e){return e.charAt(0).toLowerCase()+e.slice(1)}var Re={name:ot,rule:hn};var _=require("@typescript-eslint/utils");var Tn=_.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),lt="collapse-simple-objs-in-one-line",En=W({maxLineLength:L(X()),maxProperties:L(X()),nestedObjMaxLineLength:L(X()),nestedObjMaxProperties:L(X()),ignoreTypesWithSuffix:L(Y(M()))}),xn=Tn({name:lt,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:[En]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],a=t.maxProperties??2,u=t.nestedObjMaxLineLength??t.maxLineLength,c=t.nestedObjMaxProperties??3;function l(o){if(o.type===_.AST_NODE_TYPES.ObjectExpression){let i=o.parent.type===_.AST_NODE_TYPES.Property,f=i?c:a,T=o.properties.length;if(T>f)return!1;if(T===1){let x=o.properties[0];return x.type===_.AST_NODE_TYPES.Property&&(x.value.type===_.AST_NODE_TYPES.ObjectExpression||x.value.type===_.AST_NODE_TYPES.ArrayExpression)?!1:{text:n.getText(x),isNested:i,propsSize:T}}let I=[];for(let x of o.properties){if(x.type===_.AST_NODE_TYPES.Property){let d=x.value.type;if(!(d===_.AST_NODE_TYPES.Literal||d===_.AST_NODE_TYPES.Identifier||d===_.AST_NODE_TYPES.TemplateLiteral||d===_.AST_NODE_TYPES.TaggedTemplateExpression))return!1}I.push(n.getText(x))}return{text:I.join(", "),isNested:i,propsSize:T}}else{let i=o.parent.parent?.type===_.AST_NODE_TYPES.TSPropertySignature,f=i?c:a,T=o.members.length;if(T>f)return!1;if(r.length>0&&o.parent.type===_.AST_NODE_TYPES.TSTypeAliasDeclaration){let x=o.parent.id.name;if(r.some(d=>x.endsWith(d)))return!1}if(T===1){let x=o.members[0];return x.type===_.AST_NODE_TYPES.TSPropertySignature&&x.typeAnnotation?.typeAnnotation.type===_.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(x),isNested:i,propsSize:1}}if(o.parent.type===_.AST_NODE_TYPES.TSIntersectionType||o.parent.type===_.AST_NODE_TYPES.TSUnionType)return!1;let I=[];for(let x of o.members){if(x.type!==_.AST_NODE_TYPES.TSPropertySignature)return!1;let d=x.typeAnnotation?.typeAnnotation;if(!d||d.type===_.AST_NODE_TYPES.TSTypeLiteral||!at(d.type))return!1;if(d.type===_.AST_NODE_TYPES.TSTypeReference&&d.typeArguments){if(d.typeArguments.params.length>1)return!1;let g=d.typeArguments.params[0];if(!at(g.type))return!1}let b=n.getText(x).trim();(b.endsWith(";")||b.endsWith(","))&&(b=b.slice(0,-1)),I.push(b)}return{text:I.join("; "),isNested:i,propsSize:T}}}function s(o){if(o.loc.start.line===o.loc.end.line||o.parent.type!==_.AST_NODE_TYPES.JSXExpressionContainer&&n.getTokenAfter(o,{filter:b=>{let g=b.type===_.AST_TOKEN_TYPES.Punctuator&&b.value===",",D=b.type===_.AST_TOKEN_TYPES.Punctuator&&b.value===";";return!g&&!D}})?.loc.start.line===o.loc.end.line)return;let i=l(o);if(!i)return;let f=i.text;if(f.includes(`
|
|
2
|
+
`)||n.getCommentsInside(o).length>0)return;f.endsWith(";")&&(f=f.slice(0,-1));let T=`{ ${f} }`,I=In(n,o),x=i.isNested&&i.propsSize>2?u:t.maxLineLength;x&&T.length+I.length+(bn(o,n)?1:0)>x||e.report({node:o,messageId:"singleLineProp",fix:d=>d.replaceText(o,T)})}return{TSTypeLiteral:s,ObjectExpression:s}}});function at(e){return e===_.AST_NODE_TYPES.TSLiteralType||e===_.AST_NODE_TYPES.TSTypeReference||e===_.AST_NODE_TYPES.TSNumberKeyword||e===_.AST_NODE_TYPES.TSStringKeyword||e===_.AST_NODE_TYPES.TSBooleanKeyword||e===_.AST_NODE_TYPES.TSNullKeyword||e===_.AST_NODE_TYPES.TSUndefinedKeyword}function bn(e,t){let n=t.getTokenAfter(e);return n?.type===_.AST_TOKEN_TYPES.Punctuator&&(n.value===","||n.value===";"||n.value==="}")&&n.loc.start.line===e.loc.end.line}function In(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var ve={name:lt,rule:xn};var wn=/eslint +react-compiler\/react-compiler: +\["error/,pt={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),a=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,u=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,c={additionalHooks:a,enableDangerousAutofixThisMayCauseInfiniteLoops:u};function l(g){u&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let s=e.getSourceCode().scopeManager,o=new WeakMap,i=new WeakSet,f=new WeakMap,T=new WeakMap,I=new WeakSet;function x(g,D){return function(v){if(D.has(v))return D.get(v);let y=g(v);return D.set(v,y),y}}function d(g,D,v,y,C){C&&g.async&&l({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
|
|
3
3
|
|
|
4
4
|
useEffect(() => {
|
|
5
5
|
async function fetchData() {
|
|
@@ -10,5 +10,5 @@ useEffect(() => {
|
|
|
10
10
|
fetchData();
|
|
11
11
|
}, [someId]); // Or [] if effect doesn't need props or state
|
|
12
12
|
|
|
13
|
-
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let R=s.acquire(g),k=new Set,$=null;{let p=R.upper;for(;p&&(k.add(p),p.type!=="function");)p=p.upper;if(!p)return;$=p}let A=Array.isArray;function W(p){if(!A(p.defs))return!1;let m=p.defs[0];if(m==null||m.node.type!=="VariableDeclarator")return!1;let h=m.node.init;if(h==null)return!1;for(;h.type==="TSAsExpression";)h=h.expression;let S=m.node.parent;if(S==null&&(Oe($.block,m.node.id),S=m.node.parent,S==null))return!1;if(S.kind==="const"&&h.type==="Literal"&&(typeof h.value=="string"||typeof h.value=="number"||h.value===null))return!0;if(h.type!=="CallExpression")return!1;let w=h.callee;if(w.type==="MemberExpression"&&w.object.name==="React"&&w.property!=null&&!w.computed&&(w=w.property),w.type!=="Identifier")return!1;let E=m.node.id,{name:O}=w;if(O==="useRef"&&E.type==="Identifier")return!0;if(An(w)&&E.type==="Identifier"){for(let P of p.references)P!==E&&I.add(P.identifier);return!0}else if(O==="useState"||O==="useReducer"){if(E.type==="ArrayPattern"&&E.elements.length===2&&A(p.identifiers)){if(E.elements[1]===p.identifiers[0]){if(O==="useState"){let P=p.references,q=0;for(let J=0;J<P.length;J++){if(P[J].isWrite()&&q++,q>1)return!1;o.set(P[J].identifier,E.elements[0])}}return!0}else if(E.elements[0]===p.identifiers[0]){if(O==="useState"){let P=p.references;for(let q=0;q<P.length;q++)i.add(P[q].identifier)}return!1}}}else if(O==="useTransition"&&E.type==="ArrayPattern"&&E.elements.length===2&&Array.isArray(p.identifiers)&&E.elements[1]===p.identifiers[0])return!0;return!1}function K(p){if(!A(p.defs))return!1;let m=p.defs[0];if(m==null||m.node==null||m.node.id==null)return!1;let h=m.node,S=$.childScopes,w=null,E;for(E=0;E<S.length;E++){let O=S[E],P=O.block;if(h.type==="FunctionDeclaration"&&P===h||h.type==="VariableDeclarator"&&P.parent===h){w=O;break}}if(w==null)return!1;for(E=0;E<w.through.length;E++){let O=w.through[E];if(O.resolved!=null&&k.has(O.resolved.scope)&&!Be(O.resolved))return!1}return!0}let Be=b(W,f),Bt=b(K,T),Ke=new Map;function Kt(p){let m=p.from,h=!1;for(;m.block!==g;)m.type==="function"&&(h=m.block.parent!=null&&m.block.parent.type==="ReturnStatement"),m=m.upper;return h}let z=new Map,Te=new Map;Xe(R);function Xe(p){for(let m of p.references){if(!m.resolved||!k.has(m.resolved.scope))continue;let h=Oe(g,m.identifier),S=ut(h),w=G(S,Te);if(C&&S.type==="Identifier"&&(S.parent.type==="MemberExpression"||S.parent.type==="OptionalMemberExpression")&&!S.parent.computed&&S.parent.property.type==="Identifier"&&S.parent.property.name==="current"&&Kt(m)&&Ke.set(w,{reference:m,dependencyNode:S}),S.parent.type==="TSTypeQuery"||S.parent.type==="TSTypeReference")continue;let E=m.resolved.defs[0];if(E!=null&&!(E.node!=null&&E.node.init===g.parent)&&E.type!=="TypeParameter")if(z.has(w))z.get(w).references.push(m);else{let O=m.resolved,P=Be(O)||Bt(O);z.set(w,{isStable:P,references:[m]})}}for(let m of p.childScopes)Xe(m)}Ke.forEach(({reference:p,dependencyNode:m},h)=>{let S=p.resolved.references,w=!1;for(let E=0;E<S.length;E++){let{identifier:O}=S[E],{parent:P}=O;if(P!=null&&P.type==="MemberExpression"&&!P.computed&&P.property.type==="Identifier"&&P.property.name==="current"&&P.parent.type==="AssignmentExpression"&&P.parent.left===P){w=!0;break}}w||l({node:m.parent.property,message:`The ref value '${h}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${h}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Ee=new Set;function Xt(p,m){Ee.has(m)||(Ee.add(m),l({node:p,message:`Assignments to the '${m}' variable from inside React Hook ${n(v)} 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(v)}.`}))}let pe=new Set;if(z.forEach(({isStable:p,references:m},h)=>{p&&pe.add(h),m.forEach(S=>{S.writeExpr&&Xt(S.writeExpr,h)})}),Ee.size>0)return;if(!D){let p=null;if(z.forEach(({isStable:m,references:h},S)=>{p||h.forEach(w=>{if(p)return;let E=w.identifier;if(!o.has(E))return;let P=w.from;for(;P.type!=="function";)P=P.upper;P.block===g&&(p=S)})}),p){let{suggestedDependencies:m}=ke({dependencies:z,declaredDependencies:[],stableDependencies:pe,externalDependencies:new Set,isEffect:!0});l({node:v,message:`React Hook ${y} contains a call to '${p}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+m.join(", ")+`] as a second argument to the ${y} Hook.`,suggest:[{desc:`Add dependencies array: [${m.join(", ")}]`,fix(h){return h.insertTextAfter(g,`, [${m.join(", ")}]`)}}]})}return}let ae=[],le=new Set;D.type!=="ArrayExpression"?l({node:D,message:`React Hook ${n(v)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(p=>{if(p===null)return;if(p.type==="SpreadElement"){l({node:p,message:`React Hook ${n(v)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}I.has(p)&&l({node:p,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(p)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(p)}\``,fix(w){return w.removeRange(p.range)}}]});let m;try{m=G(p,Te)}catch(w){if(/Unsupported node type/.test(w.message)){p.type==="Literal"?z.has(p.value)?l({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. Did you mean to include ${p.value} in the array instead?`}):l({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:p,message:`React Hook ${n(v)} 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 h=p;for(;h.type==="MemberExpression"||h.type==="OptionalMemberExpression"||h.type==="ChainExpression";)h=h.object||h.expression.object;let S=!$.through.some(w=>w.identifier===h);ae.push({key:m,node:p}),S||le.add(m)});let{suggestedDependencies:Jt,unnecessaryDependencies:ue,missingDependencies:Q,duplicateDependencies:Je}=ke({dependencies:z,declaredDependencies:ae,stableDependencies:pe,externalDependencies:le,isEffect:C}),fe=Jt;if(Je.size+Q.size+ue.size===0){if(t)return;Cn({declaredDependencies:ae,declaredDependenciesNode:D,componentScope:$,scope:R}).forEach(({construction:m,isUsedOutsideOfHook:h,depType:S})=>{let w=S==="function"?"useCallback":"useMemo",E=S==="function"?"definition":"initialization",O=`wrap the ${E} of '${m.name.name}' in its own ${w}() Hook.`,P=h?`To fix this, ${O}`:`Move it inside the ${y} callback. Alternatively, ${O}`,q=S==="conditional"||S==="logical expression"?"could make":"makes",J=`The '${m.name.name}' ${S} ${q} the dependencies of ${y} Hook (at line ${D.loc.start.line}) change on every render. ${P}`,Ge;h&&m.type==="Variable"&&S==="function"&&(Ge=[{desc:`Wrap the ${E} of '${m.name.name}' in its own ${w}() Hook.`,fix(Ze){let[Zt,Qt]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Ze.insertTextBefore(m.node.init,Zt),Ze.insertTextAfter(m.node.init,Qt)]}}]),l({node:m.node,message:J,suggest:Ge})});return}!C&&Q.size>0&&(fe=ke({dependencies:z,declaredDependencies:[],stableDependencies:pe,externalDependencies:le,isEffect:C}).suggestedDependencies);function Gt(){if(ae.length===0)return!0;let p=ae.map(h=>h.key),m=p.slice().sort();return p.join(",")===m.join(",")}Gt()&&fe.sort();function be(p){let m=p.split("."),h="";for(let S=0;S<m.length;S++){if(S!==0){let w=m.slice(0,S+1).join("."),E=Te.get(w)===!0;h+=E?"?.":"."}h+=m[S]}return h}function xe(p,m,h,S){return p.size===0?null:(p.size>1?"":m+" ")+h+" "+(p.size>1?"dependencies":"dependency")+": "+vn(Array.from(p).sort().map(w=>"'"+be(w)+"'"))+`. Either ${S} ${p.size>1?"them":"it"} or remove the dependency array.`}let B="";if(ue.size>0){let p=null;if(Array.from(ue.keys()).forEach(m=>{p===null&&m.endsWith(".current")&&(p=m)}),p!==null)B=` Mutable values like '${p}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(le.size>0){let m=Array.from(le)[0];R.set.has(m)||(B=` Outer scope values like '${m}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!B&&Q.has("props")){let p=z.get("props");if(p==null)return;let m=p.references;if(!Array.isArray(m))return;let h=!0;for(let S=0;S<m.length;S++){let w=m[S],E=Oe($.block,w.identifier);if(!E){h=!1;break}let O=E.parent;if(O==null){h=!1;break}if(O.type!=="MemberExpression"&&O.type!=="OptionalMemberExpression"){h=!1;break}}h&&(B=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${y} call and refer to those specific props inside ${n(v)}.`)}if(!B&&Q.size>0){let p=null;Q.forEach(m=>{if(p)return;let h=$.set.get(m),S=z.get(m);if(S.references[0].resolved!==h)return;let w=h.defs[0];if(w==null||w.name==null||w.type!=="Parameter")return;let E=!1,O;for(let P=0;P<S.references.length;P++)if(O=S.references[P].identifier,O!=null&&O.parent!=null&&(O.parent.type==="CallExpression"||O.parent.type==="OptionalCallExpression")&&O.parent.callee===O){E=!0;break}E&&(p=m)}),p!==null&&(B=` If '${p}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!B&&Q.size>0){let p=null;if(Q.forEach(m=>{if(p!==null)return;let S=z.get(m).references,w,E;for(let O=0;O<S.length;O++){for(w=S[O].identifier,E=w.parent;E!=null&&E!==$.block;){if(E.type==="CallExpression"){let P=o.get(E.callee);if(P!=null){if(P.name===m)p={missingDep:m,setter:E.callee.name,form:"updater"};else if(i.has(w))p={missingDep:m,setter:E.callee.name,form:"reducer"};else{let q=S[O].resolved;if(q!=null){let J=q.defs[0];J!=null&&J.type==="Parameter"&&(p={missingDep:m,setter:E.callee.name,form:"inlineReducer"})}}break}}E=E.parent}if(p!==null)break}}),p!==null)switch(p.form){case"reducer":B=` You can also replace multiple useState variables with useReducer if '${p.setter}' needs the current value of '${p.missingDep}'.`;break;case"inlineReducer":B=` If '${p.setter}' needs the current value of '${p.missingDep}', you can also switch to useReducer instead of useState and read '${p.missingDep}' in the reducer.`;break;case"updater":B=` You can also do a functional update '${p.setter}(${p.missingDep.slice(0,1)} => ...)' if you only need '${p.missingDep}' in the '${p.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:D,message:`React Hook ${n(v)} has `+(xe(Q,"a","missing","include")||xe(ue,"an","unnecessary","exclude")||xe(Je,"a","duplicate","omit"))+B,suggest:[{desc:`Update the dependencies array to be: [${fe.map(be).join(", ")}]`,fix(p){return p.replaceText(D,`[${fe.map(be).join(", ")}]`)}}]})}function x(g){let D=Rn(g.callee,c);if(D===-1)return;let v=g.arguments[D],y=g.callee,C=ft(y).name,R=g.arguments[D+1],k=/Effect($|[^a-z])/g.test(C);if(!v){l({node:y,message:`React Hook ${C} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!k)){if(!R&&!k){(C==="useMemo"||C==="useCallback")&&l({node:y,message:`React Hook ${C} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(v.type){case"FunctionExpression":case"ArrowFunctionExpression":d(v,R,y,C,k);return;case"Identifier":if(!R||R.elements&&R.elements.some(W=>W&&W.type==="Identifier"&&W.name===v.name))return;let $=r(g).set.get(v.name);if($==null||$.defs==null)return;let A=$.defs[0];if(!A||!A.node||A.type!=="Variable"&&A.type!=="FunctionName")break;switch(A.node.type){case"FunctionDeclaration":d(A.node,R,y,C,k);return;case"VariableDeclarator":let W=A.node.init;if(!W)break;switch(W.type){case"ArrowFunctionExpression":case"FunctionExpression":d(W,R,y,C,k);return}break}break;default:l({node:y,message:`React Hook ${C} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:y,message:`React Hook ${C} has a missing dependency: '${v.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${v.name}]`,fix($){return $.replaceText(R,`[${v.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(wn.test(g.value))return t=!0,{CallExpression:D=>x(D,!0)}}return{CallExpression:g=>x(g)}}};function ke({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:a}){let u=c();function c(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((d,x)=>{let g=l(u,x);g.isUsed=!0,s(u,x,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:d})=>{let x=l(u,d);x.isSatisfiedRecursively=!0}),n.forEach(d=>{let x=l(u,d);x.isSatisfiedRecursively=!0});function l(d,x){let g=x.split("."),D=d;for(let v of g){let y=D.children.get(v);y||(y=c(),D.children.set(v,y)),D=y}return D}function s(d,x,g){let D=x.split("."),v=d;for(let y of D){let C=v.children.get(y);if(!C)return;g(C),v=C}}let o=new Set,i=new Set;f(u,o,i,d=>d);function f(d,x,g,D){d.children.forEach((v,y)=>{let C=D(y);if(v.isSatisfiedRecursively){v.isSubtreeUsed&&g.add(C);return}if(v.isUsed){x.add(C);return}f(v,x,g,R=>C+"."+R)})}let T=[],I=new Set,b=new Set;return t.forEach(({key:d})=>{i.has(d)?T.indexOf(d)===-1?T.push(d):b.add(d):I.add(d)}),o.forEach(d=>{T.push(d)}),{suggestedDependencies:T,unnecessaryDependencies:I,duplicateDependencies:b,missingDependencies:o}}function te(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 te(e.consequent)!=null||te(e.alternate)!=null?"conditional":null;case"LogicalExpression":return te(e.left)!=null||te(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return te(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return te(e.expression);case"TSAsExpression":return te(e.expression)}return null}function Cn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let a=e.map(({key:c})=>{let l=n.variables.find(o=>o.name===c);if(l==null)return null;let s=l.defs[0];if(s==null)return null;if(s.type==="Variable"&&s.node.type==="VariableDeclarator"&&s.node.id.type==="Identifier"&&s.node.init!=null){let o=te(s.node.init);if(o!=null)return[l,o]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[l,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[l,"class"]:null}).filter(Boolean);function u(c){let l=!1;for(let s=0;s<c.references.length;s++){let o=c.references[s];if(o.writeExpr){if(l)return!0;l=!0;continue}let i=o.from;for(;i!==r&&i!=null;)i=i.upper;if(i!==r&&!mt(t,o.identifier))return!0}return!1}return a.map(([c,l])=>({construction:c.defs[0],depType:l,isUsedOutsideOfHook:u(c)}))}function ut(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)?ut(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function Ae(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function G(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=G(e.object,t),r=G(e.property,null),a=`${n}.${r}`;return Ae(e,t,a),a}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=G(e.object,t),r=G(e.property,null),a=`${n}.${r}`;return Ae(e,t,a),a}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=G(n.object,t),a=G(n.property,null),u=`${r}.${a}`;return Ae(n,t,u),u}else throw new Error(`Unsupported node type: ${e.type}`)}function ft(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Rn(e,t){let n=ft(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=G(n,null)}catch(a){if(/Unsupported node type/.test(a.message))return 0;throw a}return t.additionalHooks.test(r)?0:-1}else return-1}}function Oe(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),kn(r,t))return r;if(mt(r,t))for(let[a,u]of Object.entries(r))a!=="parent"&&(ct(u)?(u.parent=r,n.push(u)):Array.isArray(u)&&u.forEach(c=>{ct(c)&&(c.parent=r,n.push(c))}))}return null}function vn(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 ct(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function kn(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 An(e){return!1}var de=require("@typescript-eslint/utils");var On=de.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),dt="no-call-with-explicit-generics",Pn=F({functions:Y(L())}),Dn=On({name:dt,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:[Pn]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:a}=r;a.type===de.AST_NODE_TYPES.Identifier&&n.has(a.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:a.name}})}}}}),Pe={name:dt,rule:Dn};var ne=require("@typescript-eslint/utils"),_n=ne.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),yt="no-call-with-inferred-generics",$n=_n({name:yt,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:a}=r;if(a.type!==ne.AST_NODE_TYPES.Identifier)return;let u=n.get(a.name);if(!u)return;let{minGenerics:c=1,allowAny:l,disallowTypes:s=t.disallowTypes}=u;(r.typeArguments?.params.length||0)<(c||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:a.name,minGenerics:c||0}}),!(l&&!s)&&r.typeArguments?.params?.some(i=>!l&&i.type===ne.AST_NODE_TYPES.TSAnyKeyword||s&&i.type===ne.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===ne.AST_NODE_TYPES.Identifier&&s.includes(i.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:a.name}})}}}}),De={name:yt,rule:$n};var ce=require("@typescript-eslint/utils"),Nn=ce.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),gt="no-commented-out-code",Mn=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Ln=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],jn=Nn({name:gt,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 a of Mn)if(r.startsWith(a))return{wrongPattern:a};for(let a of Ln)if(typeof a=="string"){if(n.includes(a))return{wrongPattern:a}}else if(a.test(n))return{wrongPattern:`regex(${a.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let a of r)if(a.type===ce.TSESTree.AST_TOKEN_TYPES.Line||a.type===ce.TSESTree.AST_TOKEN_TYPES.Block){let u=t(a.value);u&&e.report({node:a,messageId:"commentedOutCode",data:{wrongPattern:u.wrongPattern}})}}}}}),_e={name:gt,rule:jn};var ye=require("@typescript-eslint/utils"),Fn=ye.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ht="no-default-export",Wn=Fn({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===ye.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),$e={name:ht,rule:Wn};var St=require("@typescript-eslint/utils"),Hn=St.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Tt="no-leaked-text-in-jsx",Un=[",",";","[","]","(",")"],Yn=Hn({name:Tt,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="";Un.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Ne={name:Tt,rule:Yn};var Z=require("@typescript-eslint/utils"),Vn=Z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),bt="no-non-camel-case-functions",zn=/^[a-z][a-zA-Z0-9]*$/;function Et(e){return e.typeName.type===Z.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===Z.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===Z.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var qn=Vn({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&&!zn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===Z.AST_NODE_TYPES.TSTypeReference?Et(n):n.type===Z.AST_NODE_TYPES.TSUnionType&&n.types.some(a=>a.type===Z.AST_NODE_TYPES.TSTypeReference&&Et(a))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Me={name:bt,rule:qn};var j=require("@typescript-eslint/utils");function se(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:se(e.parent,t,n===1/0?n:n-1)}function*Le(e){yield e,e.parent&&(yield*Le(e.parent))}var Bn=j.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),xt="no-optional-root-props",Kn=Bn({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(a){return a?a.parent?.type===j.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration||a.parent?.type===j.TSESTree.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function n(a){let c=e.sourceCode.getDeclaredVariables(a)[0];if(!c||c.references.length!==1)return!1;let l=c.references[0];if(!l)return!1;for(let s of Le(l.identifier)){if("returnType"in s||s.type===j.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let o=s.parent;if(!o)return!1;if(o.type===j.TSESTree.AST_NODE_TYPES.TSTypeParameterInstantiation&&o.parent.type===j.TSESTree.AST_NODE_TYPES.TSTypeReference&&o.parent.typeName.type===j.TSESTree.AST_NODE_TYPES.Identifier&&o.parent.typeName.name==="FC"){let f=se(o.parent.parent,j.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(f)return!(t(f)||e.sourceCode.getScope(f).references.some(I=>t(I.identifier.parent.parent)))}if(s.type===j.TSESTree.AST_NODE_TYPES.AssignmentPattern)return!1;if(o.type===j.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression){let i=se(o,j.TSESTree.AST_NODE_TYPES.VariableDeclaration);return i&&t(i)||i&&e.sourceCode.getScope(i).references.some(T=>T.identifier.parent.parent?.parent?.type===j.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)?!1:o.params.some(f=>f===s)}if(o.type===j.TSESTree.AST_NODE_TYPES.FunctionDeclaration)return t(o)||e.sourceCode.getScope(o).upper?.references.some(f=>t(f.identifier.parent.parent))?!1:o.params.some(f=>f===s)}return!1}function r(a){a.key.type!==j.TSESTree.AST_NODE_TYPES.Identifier||!a.optional||e.report({node:a.key,messageId:"optionalNotAllowed",data:{propertyName:a.key.name},suggest:[{messageId:"suggestion",fix:u=>{let c=se(a,j.TSESTree.AST_NODE_TYPES.TSPropertySignature);if(!c)return null;let l=e.sourceCode.getText(c);return u.replaceText(c,l.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(a){if(a.typeAnnotation.type===j.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(t(a)||!n(a)))for(let u of a.typeAnnotation.members)u.type===j.TSESTree.AST_NODE_TYPES.TSPropertySignature&&r(u)},TSInterfaceDeclaration(a){if(!(t(a)||!n(a)))for(let u of a.body.body)u.type===j.TSESTree.AST_NODE_TYPES.TSPropertySignature&&r(u)},TSTypeReference(a){if(a.typeName.type!==j.TSESTree.AST_NODE_TYPES.Identifier||a.typeName.name!=="FC"||!a.typeArguments?.params[0])return;let u=a.typeArguments.params[0];if(u.type!==j.TSESTree.AST_NODE_TYPES.TSTypeLiteral)return;let c=se(a.parent,j.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!c||t(c)||e.sourceCode.getScope(c).references.some(i=>i.identifier.parent.parent?.parent?.type===j.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration))return;let s=c.declarations[0].id.type===j.TSESTree.AST_NODE_TYPES.Identifier?c.declarations[0].id:null,o=e.sourceCode.getScope(c).variables.find(i=>i.name===s?.name)?.references.filter(i=>i.identifier!==s);if(!(o&&o.length>1))for(let i of u.members)i.type===j.TSESTree.AST_NODE_TYPES.TSPropertySignature&&r(i)}}}}),je={name:xt,rule:Kn};var It=require("@typescript-eslint/utils"),ge=an(require("path"));var Xn=It.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),wt="no-relative-imports",Jn=F({find:L(),replacement:L()}),Gn=F({aliases:Y(Jn),rootDir:M(L()),allowNotFoundAliases:M(re()),_dev_simulateFileName:M(L())}),Zn=Xn({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:[Gn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(c){return c.startsWith(".")||c.startsWith("..")}function a(c,l){let s=ge.default.dirname(l);return ge.default.resolve(s,c)}function u(c){let l=t.rootDir??process.cwd(),s=ge.default.relative(l,c);if(s.startsWith("."))return null;s.startsWith("/")||(s=`/${s}`);for(let{find:o,replacement:i}of t.aliases)if(s.startsWith(i)){let f=s.replace(i,o);return{alias:o,newPath:f}}return null}return{ImportDeclaration(c){let l=c.source.value;if(!r(l))return;let s=a(l,n),o=u(s);!o&&t.allowNotFoundAliases||e.report({node:c,messageId:o?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:o?.alias},fix:o?i=>i.replaceText(c.source,`'${o.newPath}'`):void 0})}}}}),Fe={name:wt,rule:Zn};var N=require("@typescript-eslint/utils");var Qn=N.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Ct(e){let t=[];for(let n of e.members)n.type===N.AST_NODE_TYPES.TSPropertySignature&&n.key.type===N.AST_NODE_TYPES.Identifier&&t.push([n.key.name,n]);return t}function Rt(e,...t){for(let n of t)e.set(...n);return e}var er=F({forceCheckOnFCPropTypesWithName:M(Y(L()))}),vt="no-unused-type-props-in-args",We=null,tr=Qn({name:vt,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:[er],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!We&&(We=n.map(l=>new RegExp(l)));function r(l,s,o,i,f=!0){let T=o.name,I=e.sourceCode.getScope(s).references.find(x=>x.identifier.name===T)?.resolved,b=l&&We?.some(x=>x.test(T));if(!I||!b&&I.references.filter(x=>x.isTypeReference).length>1)return;let d=I?.defs[0]?.node;if(!(f&&d?.parent?.type===N.AST_NODE_TYPES.ExportNamedDeclaration)){if(d?.type===N.AST_NODE_TYPES.TSTypeAliasDeclaration){a(l,s,i,d.typeAnnotation,!0);return}if(d?.type===N.AST_NODE_TYPES.TSInterfaceDeclaration){a(l,s,i,d.body,!0);return}}}function a(l,s,o,i,f){if(i.type===N.AST_NODE_TYPES.TSInterfaceBody){for(let T of i.body)T.type===N.AST_NODE_TYPES.TSPropertySignature&&T.key.type===N.AST_NODE_TYPES.Identifier&&o.set(T.key.name,T);return}if(i.type===N.AST_NODE_TYPES.TSTypeLiteral){Rt(o,...Ct(i));return}if(i.type===N.AST_NODE_TYPES.TSIntersectionType){for(let T of i.types)a(l,s,o,T,!0);return}f||i.type===N.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===N.AST_NODE_TYPES.Identifier&&r(l,s,i.typeName,o)}function u(l,s,o){for(let i of o)if(i.type==="ObjectPattern"&&i.typeAnnotation){let f=new Map;if(a(l,s,f,i.typeAnnotation.typeAnnotation,!1),f.size===0)continue;c(i,f)}else i.type===N.AST_NODE_TYPES.AssignmentPattern&&i.left.type===N.AST_NODE_TYPES.ObjectPattern&&u(l,s,[i.left])}function c(l,s){let o=[];if(l.properties.at(-1)?.type===N.AST_NODE_TYPES.RestElement)return;for(let I of l.properties)I.type===N.AST_NODE_TYPES.Property&&I.key.type===N.AST_NODE_TYPES.Identifier&&o.push(I.key.name);let f=[],T=[];for(let[I,b]of s)o.includes(I)||(T.push(I),f.push({node:b,messageId:"unusedObjectTypeProperty",data:{propertyName:I}}));for(let[I,b]of f.entries())e.report({...b,fix:I===f.length-1?d=>{let x=l.properties.at(-1),g=T.join(", ");return x?x?.type===N.AST_NODE_TYPES.RestElement?null:d.insertTextAfter(x,`, ${g}`):d.insertTextBeforeRange([l.range[0]+1,l.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(l){let s=l.declarations[0];if(!s)return;let o=new Map,i=s.id.type===N.AST_NODE_TYPES.Identifier&&s.id.typeAnnotation?.typeAnnotation.type===N.AST_NODE_TYPES.TSTypeReference&&s.id.typeAnnotation.typeAnnotation.typeName.type===N.AST_NODE_TYPES.Identifier&&s.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&s.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(i){if(i.type===N.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===N.AST_NODE_TYPES.Identifier)r(!0,l,i.typeName,o,!1);else if(i.type===N.AST_NODE_TYPES.TSTypeLiteral)Rt(o,...Ct(i));else if(i.type===N.AST_NODE_TYPES.TSIntersectionType)for(let f of i.types)f.type===N.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===N.AST_NODE_TYPES.Identifier?r(!0,l,f.typeName,o,!1):a(!0,l,o,f,!0);if(o.size!==0&&s.init?.type===N.AST_NODE_TYPES.ArrowFunctionExpression){let f=s.init.params[0];if(!f){e.report({node:s.init,messageId:"missingComponentParam"});return}f.type===N.AST_NODE_TYPES.ObjectPattern&&c(f,o)}}},FunctionDeclaration:function(l){u(!1,l,l.params)},ArrowFunctionExpression(l){u(!1,l,l.params)}}}}),He={name:vt,rule:tr};var oe=require("@typescript-eslint/utils"),nr=oe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),At="prefer-named-functions",kt=new Map,rr=nr({name:At,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=kt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),kt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===oe.AST_NODE_TYPES.ArrowFunctionExpression&&r.id.type===oe.AST_NODE_TYPES.Identifier){let a=r.id.name;if(r.id.typeAnnotation||n&&n.test(a)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==oe.AST_NODE_TYPES.BlockStatement)return;let u=r.parent,c=r.init.params,l=r.init.body,s=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:a,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:o=>o.replaceText(u,`${s.async?"async ":""}function ${a}(${c.map(i=>e.sourceCode.getText(i)).join(", ")||""}) ${e.sourceCode.getText(l)}`)}]})}}}}}),Ue={name:At,rule:rr};var H=require("@typescript-eslint/utils");var ir=H.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Pt="prefer-single-line-if",sr=F({maxLineLength:M(X()),maxNonSimpleConditionLength:M(X())}),or=ir({name:Pt,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:[sr]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==H.AST_NODE_TYPES.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let u=r.consequent.body[0];if(u.type===H.AST_NODE_TYPES.ReturnStatement){if(!_t(u))return}else if(!(u.type===H.AST_NODE_TYPES.ContinueStatement||u.type===H.AST_NODE_TYPES.BreakStatement))return;if(r.test.type===H.AST_NODE_TYPES.LogicalExpression||r.test.type===H.AST_NODE_TYPES.ConditionalExpression)return;let c;if(t.maxNonSimpleConditionLength){let f=Ot(r.test);if(!f&&r.test.type===H.AST_NODE_TYPES.UnaryExpression&&r.test.operator==="!"){let T=r.test.argument;Ot(T)&&(f=!0)}if(f&&(c=n.getText(r.test),c.length>t.maxNonSimpleConditionLength))return}c||(c=n.getText(r.test));let l=n.getText(u);if(c.includes(`
|
|
14
|
-
`))return;let s=n.getTokenAfter(r);if(s&&s.type===H.AST_TOKEN_TYPES.Punctuator&&s.value==="}"){let f=n.getTokenAfter(s);if(f&&f.type===H.AST_TOKEN_TYPES.Keyword&&(f.value==="else"||f.value==="catch"))return}let o=ar(n,r),i=`if (${c}) ${l}`;t.maxLineLength&&i.length+o.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:f=>f.replaceText(r,i)})}}}});function Ot(e){return e.type===H.AST_NODE_TYPES.CallExpression||e.type===H.AST_NODE_TYPES.BinaryExpression||e.type===H.AST_NODE_TYPES.MemberExpression&&Dt(e)}function Dt(e){return e.object.type===H.AST_NODE_TYPES.MemberExpression?Dt(e.object):e.object.type!==H.AST_NODE_TYPES.Identifier}function ar(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function _t(e){return!e.argument||e.argument.type===H.AST_NODE_TYPES.Literal||e.argument.type===H.AST_NODE_TYPES.Identifier?!0:e.argument.type===H.AST_NODE_TYPES.CallExpression?e.argument.arguments.length===0:e.argument.type===H.AST_NODE_TYPES.UnaryExpression?_t(e.argument):!1}var Ye={name:Pt,rule:or};var V=require("@typescript-eslint/utils");var lr=V.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="react-compiler-migration",cr=F({disallowHooks:M(Y(F({name:L(),replacement:L()}))),disallowMethods:M(Y(F({name:L(),replacement:M(L()),requireTrueProp:M(L())})))}),pr=/eslint +react-compiler\/react-compiler: +\["error/;function ur(e){return e.type===V.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===V.AST_NODE_TYPES.MemberExpression&&e.property.type===V.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var fr=lr({name:$t,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:[cr]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(pr.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let a=null,u=null;if(r.callee.type===V.AST_NODE_TYPES.Identifier?(a=r.callee.name,u=r.callee):r.callee.type===V.AST_NODE_TYPES.MemberExpression&&r.callee.property.type===V.AST_NODE_TYPES.Identifier&&(a=r.callee.property.name,u=r.callee.property),a){let c=t.disallowHooks.find(l=>l.name===a);c&&u&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:c.name,replacement:c.replacement},suggest:[{messageId:"replace",data:{replacement:c.replacement},fix:l=>l.replaceText(u,c.replacement)}]})}}if(t.disallowMethods?.length&&ur(r.callee)){for(let a of r.arguments)if(a.type===V.AST_NODE_TYPES.ObjectExpression){for(let u of a.properties)if(u.type===V.AST_NODE_TYPES.Property&&u.key.type===V.AST_NODE_TYPES.Identifier){let c=u.key.name,l=t.disallowMethods.find(s=>s.name===c);if(l){if(l.requireTrueProp){let s=l.requireTrueProp,o=!1;for(let i of a.properties)if(i.type===V.AST_NODE_TYPES.Property&&i.key.type===V.AST_NODE_TYPES.Identifier&&i.key.name===s&&i.value.type===V.AST_NODE_TYPES.Literal&&i.value.value===!0){o=!0;break}if(!o){e.report({node:u,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:l.name,requireTrueProp:s}});continue}}l.replacement&&e.report({node:u,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:l.name,replacement:l.replacement},suggest:[{messageId:"replace",data:{replacement:l.replacement},fix:s=>s.replaceText(u.key,l.replacement)}]})}}}}}}:{}}}),Ve={name:$t,rule:fr};var he=require("@typescript-eslint/utils"),mr=he.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Nt="require-description",dr=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,yr=/^eslint-disable-(next-)?line$/u,gr=mr({name:Nt,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 a of n.getAllComments()){let u=hr(a);u!=null&&(r.has(u.kind)||u.description||e.report({loc:Tr(a.loc),messageId:"missingDescription"}))}}}}}),Mt={name:Nt,rule:gr};function hr(e){let{text:t,description:n}=Sr(e.value);if(!t)return null;let r=dr.exec(t);if(!r)return null;let a=r[1];if(!a)return null;let u=yr.test(a);if(e.type===he.TSESTree.AST_TOKEN_TYPES.Line&&!u||u&&e.loc.start.line!==e.loc.end.line)return null;let c=t.slice(r.index+a.length);return{kind:a,value:c.trim(),description:n}}function Sr(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Tr(e){return{start:{line:e.start.line,column:-1},end:e.end}}function Ft(e){return/^use[A-Z0-9]/.test(e)}function Se(e){return e.type==="Identifier"?Ft(e.name):e.type==="MemberExpression"&&!e.computed&&Se(e.property)?e.object.type==="Identifier":!1}function Wt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Ht(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Ut(e){return!!(e.parent&&e.parent.callee&&Ht(e.parent.callee,"forwardRef"))}function Yt(e){return!!(e.parent&&e.parent.callee&&Ht(e.parent.callee,"memo"))}function ze(e){for(;e;){let t=zt(e);if(t&&(Wt(t)||Se(t))||Ut(e)||Yt(e))return!0;e=e.parent}return!1}function Lt(e){return!1}function qe(e){return!1}var Er=/eslint +react-compiler\/react-compiler: +\["error/,Vt={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let s of e.sourceCode.getAllComments())if(Er.test(s.value))return{CallExpression(o){let i=null;o.callee.name==="useMemo"?i="useMemo":o.callee.name==="useCallback"&&(i="useCallback"),i&&e.report({node:o,message:`"${i}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?s=>t(s):s=>e.sourceCode.getText(s),n=typeof e.getScope=="function"?()=>n():s=>e.sourceCode.getScope(s),r=null,a=[],u=[],c=new WeakSet;function l(s){for(let o of s.references){let i=o.identifier.parent;if(i.type==="VariableDeclarator"&&i.init&&i.init.type==="CallExpression"&&i.init.callee&&Lt(i.init.callee))for(let f of o.resolved.references)f!==o&&c.add(f.identifier)}}return{onCodePathSegmentStart:s=>u.push(s),onCodePathSegmentEnd:()=>u.pop(),onCodePathStart:()=>a.push(new Map),onCodePathEnd(s,o){let i=a.pop();if(i.size===0)return;let f=new Set;function T(y,C){let{cache:R}=T,k=R.get(y.id),$=new Set(C);if($.has(y.id)){let A=[...$],W=A.slice(A.indexOf(y.id)+1);for(let K of W)f.add(K);return BigInt("0")}if($.add(y.id),k!==void 0)return k;if(s.thrownSegments.includes(y))k=BigInt("0");else if(y.prevSegments.length===0)k=BigInt("1");else{k=BigInt("0");for(let A of y.prevSegments)k+=T(A,$)}return y.reachable&&k===BigInt("0")?R.delete(y.id):R.set(y.id,k),k}function I(y,C){let{cache:R}=I,k=R.get(y.id),$=new Set(C);if($.has(y.id)){let A=Array.from($),W=A.slice(A.indexOf(y.id)+1);for(let K of W)f.add(K);return BigInt("0")}if($.add(y.id),k!==void 0)return k;if(s.thrownSegments.includes(y))k=BigInt("0");else if(y.nextSegments.length===0)k=BigInt("1");else{k=BigInt("0");for(let A of y.nextSegments)k+=I(A,$)}return R.set(y.id,k),k}function b(y){let{cache:C}=b,R=C.get(y.id);if(R===null)return 1/0;if(R!==void 0)return R;if(C.set(y.id,null),y.prevSegments.length===0)R=1;else{R=1/0;for(let k of y.prevSegments){let $=b(k);$<R&&(R=$)}R+=1}return C.set(y.id,R),R}T.cache=new Map,I.cache=new Map,b.cache=new Map;let d=I(s.initialSegment),x=zt(o),g=ze(o),D=x?Wt(x)||Se(x):Ut(o)||Yt(o),v=1/0;for(let y of s.finalSegments){if(!y.reachable)continue;let C=b(y);C<v&&(v=C)}for(let[y,C]of i){if(!y.reachable)continue;let R=y.nextSegments.length===0?v<=b(y):v<b(y),k=T(y)*I(y),$=f.has(y.id);for(let A of C)if($&&!qe(A)&&e.report({node:A,message:`React Hook "${t(A)}" 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.`}),D){if(o.async&&e.report({node:A,message:`React Hook "${t(A)}" cannot be called in an async function.`}),!$&&k!==d&&!qe(A)){let K=`React Hook "${t(A)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(R?" Did you accidentally call a React Hook after an early return?":"");e.report({node:A,message:K})}}else if(o.parent&&(o.parent.type==="MethodDefinition"||o.parent.type==="ClassProperty")&&o.parent.value===o){let W=`React Hook "${t(A)}" 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:A,message:W})}else if(x){let W=`React Hook "${t(A)}" is called in function "${t(x)}" 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:A,message:W})}else if(o.type==="Program"){let W=`React Hook "${t(A)}" 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:A,message:W})}else if(g&&!qe(A)){if(o.parent.type==="CallExpression"&&o.parent.callee.type==="Identifier"&&o.parent.callee.name==="useCallback"){let K=o.parent;if(K.parent.type==="VariableDeclarator"&&Ft(K.parent.id.name))return}let W=`React Hook "${t(A)}" 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:A,message:W})}}},CallExpression(s){if(Se(s.callee)){let o=jt(a),i=jt(u),f=o.get(i);f||(f=[],o.set(i,f)),f.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Lt(s.callee))&&s.arguments.length>0&&(r=s)},Identifier(s){r==null&&c.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${t(s)}\` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.`})},"CallExpression:exit"(s){s===r&&(r=null)},FunctionDeclaration(s){ze(s)&&l(n(s))},ArrowFunctionExpression(s){ze(s)&&l(n(s))}}}};function zt(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 jt(e){return e[e.length-1]}var qt={[He.name]:He.rule,[_e.name]:_e.rule,[De.name]:De.rule,"rules-of-hooks":Vt,"exhaustive-deps":pt,"require-description":Mt.rule,[$e.name]:$e.rule,[Me.name]:Me.rule,[Ue.name]:Ue.rule,[Re.name]:Re.rule,[Pe.name]:Pe.rule,[Fe.name]:Fe.rule,[Ye.name]:Ye.rule,[je.name]:je.rule,[Ne.name]:Ne.rule,[ve.name]:ve.rule,[Ve.name]:Ve.rule,[Ce.name]:Ce.rule};var br={rules:qt};0&&(module.exports={extendedLintPlugin});
|
|
13
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let R=s.acquire(g),k=new Set,$=null;{let p=R.upper;for(;p&&(k.add(p),p.type!=="function");)p=p.upper;if(!p)return;$=p}let A=Array.isArray;function H(p){if(!A(p.defs))return!1;let m=p.defs[0];if(m==null||m.node.type!=="VariableDeclarator")return!1;let h=m.node.init;if(h==null)return!1;for(;h.type==="TSAsExpression";)h=h.expression;let S=m.node.parent;if(S==null&&(Oe($.block,m.node.id),S=m.node.parent,S==null))return!1;if(S.kind==="const"&&h.type==="Literal"&&(typeof h.value=="string"||typeof h.value=="number"||h.value===null))return!0;if(h.type!=="CallExpression")return!1;let w=h.callee;if(w.type==="MemberExpression"&&w.object.name==="React"&&w.property!=null&&!w.computed&&(w=w.property),w.type!=="Identifier")return!1;let E=m.node.id,{name:O}=w;if(O==="useRef"&&E.type==="Identifier")return!0;if(An(w)&&E.type==="Identifier"){for(let P of p.references)P!==E&&I.add(P.identifier);return!0}else if(O==="useState"||O==="useReducer"){if(E.type==="ArrayPattern"&&E.elements.length===2&&A(p.identifiers)){if(E.elements[1]===p.identifiers[0]){if(O==="useState"){let P=p.references,q=0;for(let J=0;J<P.length;J++){if(P[J].isWrite()&&q++,q>1)return!1;o.set(P[J].identifier,E.elements[0])}}return!0}else if(E.elements[0]===p.identifiers[0]){if(O==="useState"){let P=p.references;for(let q=0;q<P.length;q++)i.add(P[q].identifier)}return!1}}}else if(O==="useTransition"&&E.type==="ArrayPattern"&&E.elements.length===2&&Array.isArray(p.identifiers)&&E.elements[1]===p.identifiers[0])return!0;return!1}function K(p){if(!A(p.defs))return!1;let m=p.defs[0];if(m==null||m.node==null||m.node.id==null)return!1;let h=m.node,S=$.childScopes,w=null,E;for(E=0;E<S.length;E++){let O=S[E],P=O.block;if(h.type==="FunctionDeclaration"&&P===h||h.type==="VariableDeclarator"&&P.parent===h){w=O;break}}if(w==null)return!1;for(E=0;E<w.through.length;E++){let O=w.through[E];if(O.resolved!=null&&k.has(O.resolved.scope)&&!Be(O.resolved))return!1}return!0}let Be=x(H,f),Bt=x(K,T),Ke=new Map;function Kt(p){let m=p.from,h=!1;for(;m.block!==g;)m.type==="function"&&(h=m.block.parent!=null&&m.block.parent.type==="ReturnStatement"),m=m.upper;return h}let z=new Map,Te=new Map;Xe(R);function Xe(p){for(let m of p.references){if(!m.resolved||!k.has(m.resolved.scope))continue;let h=Oe(g,m.identifier),S=ut(h),w=G(S,Te);if(C&&S.type==="Identifier"&&(S.parent.type==="MemberExpression"||S.parent.type==="OptionalMemberExpression")&&!S.parent.computed&&S.parent.property.type==="Identifier"&&S.parent.property.name==="current"&&Kt(m)&&Ke.set(w,{reference:m,dependencyNode:S}),S.parent.type==="TSTypeQuery"||S.parent.type==="TSTypeReference")continue;let E=m.resolved.defs[0];if(E!=null&&!(E.node!=null&&E.node.init===g.parent)&&E.type!=="TypeParameter")if(z.has(w))z.get(w).references.push(m);else{let O=m.resolved,P=Be(O)||Bt(O);z.set(w,{isStable:P,references:[m]})}}for(let m of p.childScopes)Xe(m)}Ke.forEach(({reference:p,dependencyNode:m},h)=>{let S=p.resolved.references,w=!1;for(let E=0;E<S.length;E++){let{identifier:O}=S[E],{parent:P}=O;if(P!=null&&P.type==="MemberExpression"&&!P.computed&&P.property.type==="Identifier"&&P.property.name==="current"&&P.parent.type==="AssignmentExpression"&&P.parent.left===P){w=!0;break}}w||l({node:m.parent.property,message:`The ref value '${h}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${h}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Ee=new Set;function Xt(p,m){Ee.has(m)||(Ee.add(m),l({node:p,message:`Assignments to the '${m}' variable from inside React Hook ${n(v)} 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(v)}.`}))}let pe=new Set;if(z.forEach(({isStable:p,references:m},h)=>{p&&pe.add(h),m.forEach(S=>{S.writeExpr&&Xt(S.writeExpr,h)})}),Ee.size>0)return;if(!D){let p=null;if(z.forEach(({isStable:m,references:h},S)=>{p||h.forEach(w=>{if(p)return;let E=w.identifier;if(!o.has(E))return;let P=w.from;for(;P.type!=="function";)P=P.upper;P.block===g&&(p=S)})}),p){let{suggestedDependencies:m}=ke({dependencies:z,declaredDependencies:[],stableDependencies:pe,externalDependencies:new Set,isEffect:!0});l({node:v,message:`React Hook ${y} contains a call to '${p}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+m.join(", ")+`] as a second argument to the ${y} Hook.`,suggest:[{desc:`Add dependencies array: [${m.join(", ")}]`,fix(h){return h.insertTextAfter(g,`, [${m.join(", ")}]`)}}]})}return}let ae=[],le=new Set;D.type!=="ArrayExpression"?l({node:D,message:`React Hook ${n(v)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(p=>{if(p===null)return;if(p.type==="SpreadElement"){l({node:p,message:`React Hook ${n(v)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}I.has(p)&&l({node:p,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(p)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(p)}\``,fix(w){return w.removeRange(p.range)}}]});let m;try{m=G(p,Te)}catch(w){if(/Unsupported node type/.test(w.message)){p.type==="Literal"?z.has(p.value)?l({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. Did you mean to include ${p.value} in the array instead?`}):l({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:p,message:`React Hook ${n(v)} 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 h=p;for(;h.type==="MemberExpression"||h.type==="OptionalMemberExpression"||h.type==="ChainExpression";)h=h.object||h.expression.object;let S=!$.through.some(w=>w.identifier===h);ae.push({key:m,node:p}),S||le.add(m)});let{suggestedDependencies:Jt,unnecessaryDependencies:ue,missingDependencies:Q,duplicateDependencies:Je}=ke({dependencies:z,declaredDependencies:ae,stableDependencies:pe,externalDependencies:le,isEffect:C}),fe=Jt;if(Je.size+Q.size+ue.size===0){if(t)return;Cn({declaredDependencies:ae,declaredDependenciesNode:D,componentScope:$,scope:R}).forEach(({construction:m,isUsedOutsideOfHook:h,depType:S})=>{let w=S==="function"?"useCallback":"useMemo",E=S==="function"?"definition":"initialization",O=`wrap the ${E} of '${m.name.name}' in its own ${w}() Hook.`,P=h?`To fix this, ${O}`:`Move it inside the ${y} callback. Alternatively, ${O}`,q=S==="conditional"||S==="logical expression"?"could make":"makes",J=`The '${m.name.name}' ${S} ${q} the dependencies of ${y} Hook (at line ${D.loc.start.line}) change on every render. ${P}`,Ge;h&&m.type==="Variable"&&S==="function"&&(Ge=[{desc:`Wrap the ${E} of '${m.name.name}' in its own ${w}() Hook.`,fix(Ze){let[Zt,Qt]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Ze.insertTextBefore(m.node.init,Zt),Ze.insertTextAfter(m.node.init,Qt)]}}]),l({node:m.node,message:J,suggest:Ge})});return}!C&&Q.size>0&&(fe=ke({dependencies:z,declaredDependencies:[],stableDependencies:pe,externalDependencies:le,isEffect:C}).suggestedDependencies);function Gt(){if(ae.length===0)return!0;let p=ae.map(h=>h.key),m=p.slice().sort();return p.join(",")===m.join(",")}Gt()&&fe.sort();function xe(p){let m=p.split("."),h="";for(let S=0;S<m.length;S++){if(S!==0){let w=m.slice(0,S+1).join("."),E=Te.get(w)===!0;h+=E?"?.":"."}h+=m[S]}return h}function be(p,m,h,S){return p.size===0?null:(p.size>1?"":m+" ")+h+" "+(p.size>1?"dependencies":"dependency")+": "+vn(Array.from(p).sort().map(w=>"'"+xe(w)+"'"))+`. Either ${S} ${p.size>1?"them":"it"} or remove the dependency array.`}let B="";if(ue.size>0){let p=null;if(Array.from(ue.keys()).forEach(m=>{p===null&&m.endsWith(".current")&&(p=m)}),p!==null)B=` Mutable values like '${p}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(le.size>0){let m=Array.from(le)[0];R.set.has(m)||(B=` Outer scope values like '${m}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!B&&Q.has("props")){let p=z.get("props");if(p==null)return;let m=p.references;if(!Array.isArray(m))return;let h=!0;for(let S=0;S<m.length;S++){let w=m[S],E=Oe($.block,w.identifier);if(!E){h=!1;break}let O=E.parent;if(O==null){h=!1;break}if(O.type!=="MemberExpression"&&O.type!=="OptionalMemberExpression"){h=!1;break}}h&&(B=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${y} call and refer to those specific props inside ${n(v)}.`)}if(!B&&Q.size>0){let p=null;Q.forEach(m=>{if(p)return;let h=$.set.get(m),S=z.get(m);if(S.references[0].resolved!==h)return;let w=h.defs[0];if(w==null||w.name==null||w.type!=="Parameter")return;let E=!1,O;for(let P=0;P<S.references.length;P++)if(O=S.references[P].identifier,O!=null&&O.parent!=null&&(O.parent.type==="CallExpression"||O.parent.type==="OptionalCallExpression")&&O.parent.callee===O){E=!0;break}E&&(p=m)}),p!==null&&(B=` If '${p}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!B&&Q.size>0){let p=null;if(Q.forEach(m=>{if(p!==null)return;let S=z.get(m).references,w,E;for(let O=0;O<S.length;O++){for(w=S[O].identifier,E=w.parent;E!=null&&E!==$.block;){if(E.type==="CallExpression"){let P=o.get(E.callee);if(P!=null){if(P.name===m)p={missingDep:m,setter:E.callee.name,form:"updater"};else if(i.has(w))p={missingDep:m,setter:E.callee.name,form:"reducer"};else{let q=S[O].resolved;if(q!=null){let J=q.defs[0];J!=null&&J.type==="Parameter"&&(p={missingDep:m,setter:E.callee.name,form:"inlineReducer"})}}break}}E=E.parent}if(p!==null)break}}),p!==null)switch(p.form){case"reducer":B=` You can also replace multiple useState variables with useReducer if '${p.setter}' needs the current value of '${p.missingDep}'.`;break;case"inlineReducer":B=` If '${p.setter}' needs the current value of '${p.missingDep}', you can also switch to useReducer instead of useState and read '${p.missingDep}' in the reducer.`;break;case"updater":B=` You can also do a functional update '${p.setter}(${p.missingDep.slice(0,1)} => ...)' if you only need '${p.missingDep}' in the '${p.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:D,message:`React Hook ${n(v)} has `+(be(Q,"a","missing","include")||be(ue,"an","unnecessary","exclude")||be(Je,"a","duplicate","omit"))+B,suggest:[{desc:`Update the dependencies array to be: [${fe.map(xe).join(", ")}]`,fix(p){return p.replaceText(D,`[${fe.map(xe).join(", ")}]`)}}]})}function b(g){let D=Rn(g.callee,c);if(D===-1)return;let v=g.arguments[D],y=g.callee,C=ft(y).name,R=g.arguments[D+1],k=/Effect($|[^a-z])/g.test(C);if(!v){l({node:y,message:`React Hook ${C} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!k)){if(!R&&!k){(C==="useMemo"||C==="useCallback")&&l({node:y,message:`React Hook ${C} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(v.type){case"FunctionExpression":case"ArrowFunctionExpression":d(v,R,y,C,k);return;case"Identifier":if(!R||R.elements&&R.elements.some(H=>H&&H.type==="Identifier"&&H.name===v.name))return;let $=r(g).set.get(v.name);if($==null||$.defs==null)return;let A=$.defs[0];if(!A||!A.node||A.type!=="Variable"&&A.type!=="FunctionName")break;switch(A.node.type){case"FunctionDeclaration":d(A.node,R,y,C,k);return;case"VariableDeclarator":let H=A.node.init;if(!H)break;switch(H.type){case"ArrowFunctionExpression":case"FunctionExpression":d(H,R,y,C,k);return}break}break;default:l({node:y,message:`React Hook ${C} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:y,message:`React Hook ${C} has a missing dependency: '${v.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${v.name}]`,fix($){return $.replaceText(R,`[${v.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(wn.test(g.value))return t=!0,{CallExpression:D=>b(D,!0)}}return{CallExpression:g=>b(g)}}};function ke({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:a}){let u=c();function c(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((d,b)=>{let g=l(u,b);g.isUsed=!0,s(u,b,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:d})=>{let b=l(u,d);b.isSatisfiedRecursively=!0}),n.forEach(d=>{let b=l(u,d);b.isSatisfiedRecursively=!0});function l(d,b){let g=b.split("."),D=d;for(let v of g){let y=D.children.get(v);y||(y=c(),D.children.set(v,y)),D=y}return D}function s(d,b,g){let D=b.split("."),v=d;for(let y of D){let C=v.children.get(y);if(!C)return;g(C),v=C}}let o=new Set,i=new Set;f(u,o,i,d=>d);function f(d,b,g,D){d.children.forEach((v,y)=>{let C=D(y);if(v.isSatisfiedRecursively){v.isSubtreeUsed&&g.add(C);return}if(v.isUsed){b.add(C);return}f(v,b,g,R=>C+"."+R)})}let T=[],I=new Set,x=new Set;return t.forEach(({key:d})=>{i.has(d)?T.indexOf(d)===-1?T.push(d):x.add(d):I.add(d)}),o.forEach(d=>{T.push(d)}),{suggestedDependencies:T,unnecessaryDependencies:I,duplicateDependencies:x,missingDependencies:o}}function te(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 te(e.consequent)!=null||te(e.alternate)!=null?"conditional":null;case"LogicalExpression":return te(e.left)!=null||te(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return te(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return te(e.expression);case"TSAsExpression":return te(e.expression)}return null}function Cn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let a=e.map(({key:c})=>{let l=n.variables.find(o=>o.name===c);if(l==null)return null;let s=l.defs[0];if(s==null)return null;if(s.type==="Variable"&&s.node.type==="VariableDeclarator"&&s.node.id.type==="Identifier"&&s.node.init!=null){let o=te(s.node.init);if(o!=null)return[l,o]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[l,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[l,"class"]:null}).filter(Boolean);function u(c){let l=!1;for(let s=0;s<c.references.length;s++){let o=c.references[s];if(o.writeExpr){if(l)return!0;l=!0;continue}let i=o.from;for(;i!==r&&i!=null;)i=i.upper;if(i!==r&&!mt(t,o.identifier))return!0}return!1}return a.map(([c,l])=>({construction:c.defs[0],depType:l,isUsedOutsideOfHook:u(c)}))}function ut(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)?ut(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function Ae(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function G(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=G(e.object,t),r=G(e.property,null),a=`${n}.${r}`;return Ae(e,t,a),a}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=G(e.object,t),r=G(e.property,null),a=`${n}.${r}`;return Ae(e,t,a),a}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=G(n.object,t),a=G(n.property,null),u=`${r}.${a}`;return Ae(n,t,u),u}else throw new Error(`Unsupported node type: ${e.type}`)}function ft(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function Rn(e,t){let n=ft(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=G(n,null)}catch(a){if(/Unsupported node type/.test(a.message))return 0;throw a}return t.additionalHooks.test(r)?0:-1}else return-1}}function Oe(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),kn(r,t))return r;if(mt(r,t))for(let[a,u]of Object.entries(r))a!=="parent"&&(ct(u)?(u.parent=r,n.push(u)):Array.isArray(u)&&u.forEach(c=>{ct(c)&&(c.parent=r,n.push(c))}))}return null}function vn(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 ct(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function kn(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 An(e){return!1}var de=require("@typescript-eslint/utils");var On=de.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),dt="no-call-with-explicit-generics",Pn=W({functions:Y(M())}),Dn=On({name:dt,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:[Pn]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:a}=r;a.type===de.AST_NODE_TYPES.Identifier&&n.has(a.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:a.name}})}}}}),Pe={name:dt,rule:Dn};var ne=require("@typescript-eslint/utils"),_n=ne.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),yt="no-call-with-inferred-generics",$n=_n({name:yt,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:a}=r;if(a.type!==ne.AST_NODE_TYPES.Identifier)return;let u=n.get(a.name);if(!u)return;let{minGenerics:c=1,allowAny:l,disallowTypes:s=t.disallowTypes}=u;(r.typeArguments?.params.length||0)<(c||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:a.name,minGenerics:c||0}}),!(l&&!s)&&r.typeArguments?.params?.some(i=>!l&&i.type===ne.AST_NODE_TYPES.TSAnyKeyword||s&&i.type===ne.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===ne.AST_NODE_TYPES.Identifier&&s.includes(i.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:a.name}})}}}}),De={name:yt,rule:$n};var ce=require("@typescript-eslint/utils"),Nn=ce.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),gt="no-commented-out-code",Ln=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Mn=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],jn=Nn({name:gt,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 a of Ln)if(r.startsWith(a))return{wrongPattern:a};for(let a of Mn)if(typeof a=="string"){if(n.includes(a))return{wrongPattern:a}}else if(a.test(n))return{wrongPattern:`regex(${a.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let a of r)if(a.type===ce.TSESTree.AST_TOKEN_TYPES.Line||a.type===ce.TSESTree.AST_TOKEN_TYPES.Block){let u=t(a.value);u&&e.report({node:a,messageId:"commentedOutCode",data:{wrongPattern:u.wrongPattern}})}}}}}),_e={name:gt,rule:jn};var ye=require("@typescript-eslint/utils"),Fn=ye.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ht="no-default-export",Wn=Fn({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===ye.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),$e={name:ht,rule:Wn};var St=require("@typescript-eslint/utils"),Hn=St.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Tt="no-leaked-text-in-jsx",Un=[",",";","[","]","(",")"],Yn=Hn({name:Tt,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="";Un.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Ne={name:Tt,rule:Yn};var Z=require("@typescript-eslint/utils"),Vn=Z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),xt="no-non-camel-case-functions",zn=/^[a-z][a-zA-Z0-9]*$/;function Et(e){return e.typeName.type===Z.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===Z.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===Z.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var qn=Vn({name:xt,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&&!zn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===Z.AST_NODE_TYPES.TSTypeReference?Et(n):n.type===Z.AST_NODE_TYPES.TSUnionType&&n.types.some(a=>a.type===Z.AST_NODE_TYPES.TSTypeReference&&Et(a))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Le={name:xt,rule:qn};var F=require("@typescript-eslint/utils");function se(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:se(e.parent,t,n===1/0?n:n-1)}function*Me(e){yield e,e.parent&&(yield*Me(e.parent))}var Bn=F.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),bt="no-optional-root-props",Kn=Bn({name:bt,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(a){return a?a.parent?.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration||a.parent?.type===F.TSESTree.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function n(a){let c=e.sourceCode.getDeclaredVariables(a)[0];if(!c||c.references.length!==1)return!1;let l=c.references[0];if(!l)return!1;for(let s of Me(l.identifier)){if("returnType"in s||s.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let o=s.parent;if(!o)return!1;if(o.type===F.TSESTree.AST_NODE_TYPES.TSTypeParameterInstantiation&&o.parent.type===F.TSESTree.AST_NODE_TYPES.TSTypeReference&&o.parent.typeName.type===F.TSESTree.AST_NODE_TYPES.Identifier&&o.parent.typeName.name==="FC"){let f=se(o.parent.parent,F.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(f)return!(t(f)||e.sourceCode.getScope(f).references.some(I=>t(I.identifier.parent.parent)))}if(s.type===F.TSESTree.AST_NODE_TYPES.AssignmentPattern)return!1;if(o.type===F.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression){let i=se(o,F.TSESTree.AST_NODE_TYPES.VariableDeclaration);return i&&t(i)||i&&e.sourceCode.getScope(i).references.some(T=>T.identifier.parent.parent?.parent?.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)?!1:o.params.some(f=>f===s)}if(o.type===F.TSESTree.AST_NODE_TYPES.FunctionDeclaration)return t(o)||e.sourceCode.getScope(o).upper?.references.some(f=>t(f.identifier.parent.parent))?!1:o.params.some(f=>f===s)}return!1}function r(a){a.key.type!==F.TSESTree.AST_NODE_TYPES.Identifier||!a.optional||e.report({node:a.key,messageId:"optionalNotAllowed",data:{propertyName:a.key.name},suggest:[{messageId:"suggestion",fix:u=>{let c=se(a,F.TSESTree.AST_NODE_TYPES.TSPropertySignature);if(!c)return null;let l=e.sourceCode.getText(c);return u.replaceText(c,l.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(a){if(a.typeAnnotation.type===F.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(t(a)||!n(a)))for(let u of a.typeAnnotation.members)u.type===F.TSESTree.AST_NODE_TYPES.TSPropertySignature&&r(u)},TSInterfaceDeclaration(a){if(!(t(a)||!n(a)))for(let u of a.body.body)u.type===F.TSESTree.AST_NODE_TYPES.TSPropertySignature&&r(u)},TSTypeReference(a){if(a.typeName.type!==F.TSESTree.AST_NODE_TYPES.Identifier||a.typeName.name!=="FC"||!a.typeArguments?.params[0])return;let u=a.typeArguments.params[0];if(u.type!==F.TSESTree.AST_NODE_TYPES.TSTypeLiteral)return;let c=se(a.parent,F.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!c||t(c)||e.sourceCode.getScope(c).references.some(i=>i.identifier.parent.parent?.parent?.type===F.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration))return;let s=c.declarations[0].id.type===F.TSESTree.AST_NODE_TYPES.Identifier?c.declarations[0].id:null,o=e.sourceCode.getScope(c).variables.find(i=>i.name===s?.name)?.references.filter(i=>i.identifier!==s);if(!(o&&o.length>1))for(let i of u.members)i.type===F.TSESTree.AST_NODE_TYPES.TSPropertySignature&&r(i)}}}}),je={name:bt,rule:Kn};var It=require("@typescript-eslint/utils"),ge=an(require("path"));var Xn=It.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),wt="no-relative-imports",Jn=W({find:M(),replacement:M()}),Gn=W({aliases:Y(Jn),rootDir:L(M()),allowNotFoundAliases:L(re()),_dev_simulateFileName:L(M())}),Zn=Xn({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:[Gn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(c){return c.startsWith(".")||c.startsWith("..")}function a(c,l){let s=ge.default.dirname(l);return ge.default.resolve(s,c)}function u(c){let l=t.rootDir??process.cwd(),s=ge.default.relative(l,c);if(s.startsWith("."))return null;s.startsWith("/")||(s=`/${s}`);for(let{find:o,replacement:i}of t.aliases)if(s.startsWith(i)){let f=s.replace(i,o);return{alias:o,newPath:f}}return null}return{ImportDeclaration(c){let l=c.source.value;if(!r(l))return;let s=a(l,n),o=u(s);!o&&t.allowNotFoundAliases||e.report({node:c,messageId:o?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:o?.alias},fix:o?i=>i.replaceText(c.source,`'${o.newPath}'`):void 0})}}}}),Fe={name:wt,rule:Zn};var N=require("@typescript-eslint/utils");var Qn=N.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Ct(e){let t=[];for(let n of e.members)n.type===N.AST_NODE_TYPES.TSPropertySignature&&n.key.type===N.AST_NODE_TYPES.Identifier&&t.push([n.key.name,n]);return t}function Rt(e,...t){for(let n of t)e.set(...n);return e}var er=W({forceCheckOnFCPropTypesWithName:L(Y(M()))}),vt="no-unused-type-props-in-args",We=null,tr=Qn({name:vt,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:[er],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!We&&(We=n.map(l=>new RegExp(l)));function r(l,s,o,i,f=!0){let T=o.name,I=e.sourceCode.getScope(s).references.find(b=>b.identifier.name===T)?.resolved,x=l&&We?.some(b=>b.test(T));if(!I||!x&&I.references.filter(b=>b.isTypeReference).length>1)return;let d=I?.defs[0]?.node;if(!(f&&d?.parent?.type===N.AST_NODE_TYPES.ExportNamedDeclaration)){if(d?.type===N.AST_NODE_TYPES.TSTypeAliasDeclaration){a(l,s,i,d.typeAnnotation,!0);return}if(d?.type===N.AST_NODE_TYPES.TSInterfaceDeclaration){a(l,s,i,d.body,!0);return}}}function a(l,s,o,i,f){if(i.type===N.AST_NODE_TYPES.TSInterfaceBody){for(let T of i.body)T.type===N.AST_NODE_TYPES.TSPropertySignature&&T.key.type===N.AST_NODE_TYPES.Identifier&&o.set(T.key.name,T);return}if(i.type===N.AST_NODE_TYPES.TSTypeLiteral){Rt(o,...Ct(i));return}if(i.type===N.AST_NODE_TYPES.TSIntersectionType){for(let T of i.types)a(l,s,o,T,!0);return}f||i.type===N.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===N.AST_NODE_TYPES.Identifier&&r(l,s,i.typeName,o)}function u(l,s,o){for(let i of o)if(i.type==="ObjectPattern"&&i.typeAnnotation){let f=new Map;if(a(l,s,f,i.typeAnnotation.typeAnnotation,!1),f.size===0)continue;c(i,f)}else i.type===N.AST_NODE_TYPES.AssignmentPattern&&i.left.type===N.AST_NODE_TYPES.ObjectPattern&&u(l,s,[i.left])}function c(l,s){let o=[];if(l.properties.at(-1)?.type===N.AST_NODE_TYPES.RestElement)return;for(let I of l.properties)I.type===N.AST_NODE_TYPES.Property&&I.key.type===N.AST_NODE_TYPES.Identifier&&o.push(I.key.name);let f=[],T=[];for(let[I,x]of s)o.includes(I)||(T.push(I),f.push({node:x,messageId:"unusedObjectTypeProperty",data:{propertyName:I}}));for(let[I,x]of f.entries())e.report({...x,fix:I===f.length-1?d=>{let b=l.properties.at(-1),g=T.join(", ");return b?b?.type===N.AST_NODE_TYPES.RestElement?null:d.insertTextAfter(b,`, ${g}`):d.insertTextBeforeRange([l.range[0]+1,l.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(l){let s=l.declarations[0];if(!s)return;let o=new Map,i=s.id.type===N.AST_NODE_TYPES.Identifier&&s.id.typeAnnotation?.typeAnnotation.type===N.AST_NODE_TYPES.TSTypeReference&&s.id.typeAnnotation.typeAnnotation.typeName.type===N.AST_NODE_TYPES.Identifier&&s.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&s.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(i){if(i.type===N.AST_NODE_TYPES.TSTypeReference&&i.typeName.type===N.AST_NODE_TYPES.Identifier)r(!0,l,i.typeName,o,!1);else if(i.type===N.AST_NODE_TYPES.TSTypeLiteral)Rt(o,...Ct(i));else if(i.type===N.AST_NODE_TYPES.TSIntersectionType)for(let f of i.types)f.type===N.AST_NODE_TYPES.TSTypeReference&&f.typeName.type===N.AST_NODE_TYPES.Identifier?r(!0,l,f.typeName,o,!1):a(!0,l,o,f,!0);if(o.size!==0&&s.init?.type===N.AST_NODE_TYPES.ArrowFunctionExpression){let f=s.init.params[0];if(!f){e.report({node:s.init,messageId:"missingComponentParam"});return}f.type===N.AST_NODE_TYPES.ObjectPattern&&c(f,o)}}},FunctionDeclaration:function(l){u(!1,l,l.params)},ArrowFunctionExpression(l){u(!1,l,l.params)}}}}),He={name:vt,rule:tr};var oe=require("@typescript-eslint/utils"),nr=oe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),At="prefer-named-functions",kt=new Map,rr=nr({name:At,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=kt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),kt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===oe.AST_NODE_TYPES.ArrowFunctionExpression&&r.id.type===oe.AST_NODE_TYPES.Identifier){let a=r.id.name;if(r.id.typeAnnotation||n&&n.test(a)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==oe.AST_NODE_TYPES.BlockStatement)return;let u=r.parent,c=r.init.params,l=r.init.body,s=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:a,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:o=>o.replaceText(u,`${s.async?"async ":""}function ${a}(${c.map(i=>e.sourceCode.getText(i)).join(", ")||""}) ${e.sourceCode.getText(l)}`)}]})}}}}}),Ue={name:At,rule:rr};var j=require("@typescript-eslint/utils");var ir=j.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Pt="prefer-single-line-if",sr=W({maxLineLength:L(X()),maxNonSimpleConditionLength:L(X())}),or=ir({name:Pt,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:[sr]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==j.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 u=r.consequent.body[0];if(u.type===j.AST_NODE_TYPES.ReturnStatement){if(!_t(u))return}else if(!(u.type===j.AST_NODE_TYPES.ContinueStatement||u.type===j.AST_NODE_TYPES.BreakStatement||u.type===j.AST_NODE_TYPES.ExpressionStatement&&lr(u)))return;if(r.test.type===j.AST_NODE_TYPES.LogicalExpression||r.test.type===j.AST_NODE_TYPES.ConditionalExpression)return;let c;if(t.maxNonSimpleConditionLength){let f=Ot(r.test);if(!f&&r.test.type===j.AST_NODE_TYPES.UnaryExpression&&r.test.operator==="!"){let T=r.test.argument;Ot(T)&&(f=!0)}if(f&&(c=n.getText(r.test),c.length>t.maxNonSimpleConditionLength))return}c||(c=n.getText(r.test));let l=n.getText(u);if(c.includes(`
|
|
14
|
+
`))return;let s=n.getTokenAfter(r);if(s&&s.type===j.AST_TOKEN_TYPES.Punctuator&&s.value==="}"){let f=n.getTokenAfter(s);if(f&&f.type===j.AST_TOKEN_TYPES.Keyword&&(f.value==="else"||f.value==="catch"))return}let o=ar(n,r),i=`if (${c}) ${l}`;t.maxLineLength&&i.length+o.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:f=>f.replaceText(r,i)})}}}});function Ot(e){return e.type===j.AST_NODE_TYPES.CallExpression||e.type===j.AST_NODE_TYPES.BinaryExpression||e.type===j.AST_NODE_TYPES.MemberExpression&&Dt(e)}function Dt(e){return e.object.type===j.AST_NODE_TYPES.MemberExpression?Dt(e.object):e.object.type!==j.AST_NODE_TYPES.Identifier}function ar(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function _t(e){if(!e.argument)return!0;let t=e.argument;return t.type===j.AST_NODE_TYPES.ArrayExpression&&t.elements.length===0||t.type===j.AST_NODE_TYPES.ObjectExpression&&t.properties.length===0||t.type===j.AST_NODE_TYPES.Literal||t.type===j.AST_NODE_TYPES.Identifier||t.type===j.AST_NODE_TYPES.TemplateLiteral||t.type===j.AST_NODE_TYPES.TaggedTemplateExpression?!0:t.type===j.AST_NODE_TYPES.CallExpression?t.arguments.length===0:t.type===j.AST_NODE_TYPES.UnaryExpression?_t(t):!1}function lr(e){return e.expression.type===j.AST_NODE_TYPES.CallExpression?e.expression.arguments.length===0:!1}var Ye={name:Pt,rule:or};var V=require("@typescript-eslint/utils");var cr=V.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="react-compiler-migration",pr=W({disallowHooks:L(Y(W({name:M(),replacement:M()}))),disallowMethods:L(Y(W({name:M(),replacement:L(M()),requireTrueProp:L(M())})))}),ur=/eslint +react-compiler\/react-compiler: +\["error/;function fr(e){return e.type===V.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===V.AST_NODE_TYPES.MemberExpression&&e.property.type===V.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var mr=cr({name:$t,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:[pr]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(ur.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let a=null,u=null;if(r.callee.type===V.AST_NODE_TYPES.Identifier?(a=r.callee.name,u=r.callee):r.callee.type===V.AST_NODE_TYPES.MemberExpression&&r.callee.property.type===V.AST_NODE_TYPES.Identifier&&(a=r.callee.property.name,u=r.callee.property),a){let c=t.disallowHooks.find(l=>l.name===a);c&&u&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:c.name,replacement:c.replacement},suggest:[{messageId:"replace",data:{replacement:c.replacement},fix:l=>l.replaceText(u,c.replacement)}]})}}if(t.disallowMethods?.length&&fr(r.callee)){for(let a of r.arguments)if(a.type===V.AST_NODE_TYPES.ObjectExpression){for(let u of a.properties)if(u.type===V.AST_NODE_TYPES.Property&&u.key.type===V.AST_NODE_TYPES.Identifier){let c=u.key.name,l=t.disallowMethods.find(s=>s.name===c);if(l){if(l.requireTrueProp){let s=l.requireTrueProp,o=!1;for(let i of a.properties)if(i.type===V.AST_NODE_TYPES.Property&&i.key.type===V.AST_NODE_TYPES.Identifier&&i.key.name===s&&i.value.type===V.AST_NODE_TYPES.Literal&&i.value.value===!0){o=!0;break}if(!o){e.report({node:u,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:l.name,requireTrueProp:s}});continue}}l.replacement&&e.report({node:u,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:l.name,replacement:l.replacement},suggest:[{messageId:"replace",data:{replacement:l.replacement},fix:s=>s.replaceText(u.key,l.replacement)}]})}}}}}}:{}}}),Ve={name:$t,rule:mr};var he=require("@typescript-eslint/utils"),dr=he.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Nt="require-description",yr=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,gr=/^eslint-disable-(next-)?line$/u,hr=dr({name:Nt,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 a of n.getAllComments()){let u=Sr(a);u!=null&&(r.has(u.kind)||u.description||e.report({loc:Er(a.loc),messageId:"missingDescription"}))}}}}}),Lt={name:Nt,rule:hr};function Sr(e){let{text:t,description:n}=Tr(e.value);if(!t)return null;let r=yr.exec(t);if(!r)return null;let a=r[1];if(!a)return null;let u=gr.test(a);if(e.type===he.TSESTree.AST_TOKEN_TYPES.Line&&!u||u&&e.loc.start.line!==e.loc.end.line)return null;let c=t.slice(r.index+a.length);return{kind:a,value:c.trim(),description:n}}function Tr(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Er(e){return{start:{line:e.start.line,column:-1},end:e.end}}function Ft(e){return/^use[A-Z0-9]/.test(e)}function Se(e){return e.type==="Identifier"?Ft(e.name):e.type==="MemberExpression"&&!e.computed&&Se(e.property)?e.object.type==="Identifier":!1}function Wt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Ht(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Ut(e){return!!(e.parent&&e.parent.callee&&Ht(e.parent.callee,"forwardRef"))}function Yt(e){return!!(e.parent&&e.parent.callee&&Ht(e.parent.callee,"memo"))}function ze(e){for(;e;){let t=zt(e);if(t&&(Wt(t)||Se(t))||Ut(e)||Yt(e))return!0;e=e.parent}return!1}function Mt(e){return!1}function qe(e){return!1}var xr=/eslint +react-compiler\/react-compiler: +\["error/,Vt={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let s of e.sourceCode.getAllComments())if(xr.test(s.value))return{CallExpression(o){let i=null;o.callee.name==="useMemo"?i="useMemo":o.callee.name==="useCallback"&&(i="useCallback"),i&&e.report({node:o,message:`"${i}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?s=>t(s):s=>e.sourceCode.getText(s),n=typeof e.getScope=="function"?()=>n():s=>e.sourceCode.getScope(s),r=null,a=[],u=[],c=new WeakSet;function l(s){for(let o of s.references){let i=o.identifier.parent;if(i.type==="VariableDeclarator"&&i.init&&i.init.type==="CallExpression"&&i.init.callee&&Mt(i.init.callee))for(let f of o.resolved.references)f!==o&&c.add(f.identifier)}}return{onCodePathSegmentStart:s=>u.push(s),onCodePathSegmentEnd:()=>u.pop(),onCodePathStart:()=>a.push(new Map),onCodePathEnd(s,o){let i=a.pop();if(i.size===0)return;let f=new Set;function T(y,C){let{cache:R}=T,k=R.get(y.id),$=new Set(C);if($.has(y.id)){let A=[...$],H=A.slice(A.indexOf(y.id)+1);for(let K of H)f.add(K);return BigInt("0")}if($.add(y.id),k!==void 0)return k;if(s.thrownSegments.includes(y))k=BigInt("0");else if(y.prevSegments.length===0)k=BigInt("1");else{k=BigInt("0");for(let A of y.prevSegments)k+=T(A,$)}return y.reachable&&k===BigInt("0")?R.delete(y.id):R.set(y.id,k),k}function I(y,C){let{cache:R}=I,k=R.get(y.id),$=new Set(C);if($.has(y.id)){let A=Array.from($),H=A.slice(A.indexOf(y.id)+1);for(let K of H)f.add(K);return BigInt("0")}if($.add(y.id),k!==void 0)return k;if(s.thrownSegments.includes(y))k=BigInt("0");else if(y.nextSegments.length===0)k=BigInt("1");else{k=BigInt("0");for(let A of y.nextSegments)k+=I(A,$)}return R.set(y.id,k),k}function x(y){let{cache:C}=x,R=C.get(y.id);if(R===null)return 1/0;if(R!==void 0)return R;if(C.set(y.id,null),y.prevSegments.length===0)R=1;else{R=1/0;for(let k of y.prevSegments){let $=x(k);$<R&&(R=$)}R+=1}return C.set(y.id,R),R}T.cache=new Map,I.cache=new Map,x.cache=new Map;let d=I(s.initialSegment),b=zt(o),g=ze(o),D=b?Wt(b)||Se(b):Ut(o)||Yt(o),v=1/0;for(let y of s.finalSegments){if(!y.reachable)continue;let C=x(y);C<v&&(v=C)}for(let[y,C]of i){if(!y.reachable)continue;let R=y.nextSegments.length===0?v<=x(y):v<x(y),k=T(y)*I(y),$=f.has(y.id);for(let A of C)if($&&!qe(A)&&e.report({node:A,message:`React Hook "${t(A)}" 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.`}),D){if(o.async&&e.report({node:A,message:`React Hook "${t(A)}" cannot be called in an async function.`}),!$&&k!==d&&!qe(A)){let K=`React Hook "${t(A)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(R?" Did you accidentally call a React Hook after an early return?":"");e.report({node:A,message:K})}}else if(o.parent&&(o.parent.type==="MethodDefinition"||o.parent.type==="ClassProperty")&&o.parent.value===o){let H=`React Hook "${t(A)}" 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:A,message:H})}else if(b){let H=`React Hook "${t(A)}" is called in function "${t(b)}" 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:A,message:H})}else if(o.type==="Program"){let H=`React Hook "${t(A)}" 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:A,message:H})}else if(g&&!qe(A)){if(o.parent.type==="CallExpression"&&o.parent.callee.type==="Identifier"&&o.parent.callee.name==="useCallback"){let K=o.parent;if(K.parent.type==="VariableDeclarator"&&Ft(K.parent.id.name))return}let H=`React Hook "${t(A)}" 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:A,message:H})}}},CallExpression(s){if(Se(s.callee)){let o=jt(a),i=jt(u),f=o.get(i);f||(f=[],o.set(i,f)),f.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Mt(s.callee))&&s.arguments.length>0&&(r=s)},Identifier(s){r==null&&c.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${t(s)}\` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.`})},"CallExpression:exit"(s){s===r&&(r=null)},FunctionDeclaration(s){ze(s)&&l(n(s))},ArrowFunctionExpression(s){ze(s)&&l(n(s))}}}};function zt(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 jt(e){return e[e.length-1]}var qt={[He.name]:He.rule,[_e.name]:_e.rule,[De.name]:De.rule,"rules-of-hooks":Vt,"exhaustive-deps":pt,"require-description":Lt.rule,[$e.name]:$e.rule,[Le.name]:Le.rule,[Ue.name]:Ue.rule,[Re.name]:Re.rule,[Pe.name]:Pe.rule,[Fe.name]:Fe.rule,[Ye.name]:Ye.rule,[je.name]:je.rule,[Ne.name]:Ne.rule,[ve.name]:ve.rule,[Ve.name]:Ve.rule,[Ce.name]:Ce.rule};var br={rules:qt};0&&(module.exports={extendedLintPlugin});
|
package/dist/extended-lint.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{AST_NODE_TYPES as
|
|
2
|
-
`)||n.getCommentsInside(o).length>0)return;f.endsWith(";")&&(f=f.slice(0,-1));let T=`{ ${f} }`,I=mn(n,o),
|
|
1
|
+
import{AST_NODE_TYPES as U,ESLintUtils as Xt}from"@typescript-eslint/utils";var ye=Symbol.for("optional");function $(e){return{...e,[ye]:!0}}function Xe(e,t){return{enum:e,...t}}function te(e){return{...e,type:"boolean"}}function L(e){return{...e,type:"string"}}function X(e){return{...e,type:"number"}}function Je(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,l=[];for(r in e)e[r][ye]?e[r][ye]=void 0:l.push(r);l.length>0&&(n.required=l)}return n}function ge(...e){return{anyOf:e}}var Jt=Xt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ze="react-compiler-extra",Gt=j({runOnlyWithEnableCompilerDirective:$(te())}),Zt=/eslint +react-compiler\/react-compiler: +\["error/;function Qt(e){return e.type===U.Identifier?e.name.startsWith("use"):e.type===U.MemberExpression&&e.property.type===U.Identifier?e.property.name.startsWith("use"):!1}var en=/\bthis[.[]/;function Ge(e){return en.test(e)}var tn=Jt({name:Ze,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:[Gt]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let u of e.sourceCode.getAllComments())if(Zt.test(u.value)){n=!0;break}if(!n)return{}}function r(u){for(let c of u.properties)if(c.type===U.Property&&c.method&&c.value.type===U.FunctionExpression){let a=e.sourceCode,s=a.getText(c.key),o=c.value,i=a.getText(o.body);if(Ge(i))e.report({node:c,messageId:"thisKeywordInMethod"});else{let f=o.params.map(I=>a.getText(I)).join(", "),T="";o.generator?T=`${s}: function* (${f}) ${i}`:T=`${s}: (${f}) => ${i}`,e.report({node:c,messageId:"objectMethodIsNotSupported",fix:I=>I.replaceText(c,T)})}}}function l(u){for(let c of u.properties)if(c.type===U.Property&&c.value.type===U.ObjectExpression){for(let a of c.value.properties)if(a.type===U.Property&&a.method&&a.value.type===U.FunctionExpression){let o=e.sourceCode.getText(a.value.body);Ge(o)&&e.report({node:a,messageId:"thisKeywordInMethod"})}}}return{CallExpression(u){if(Qt(u.callee))for(let c of u.arguments){if(c.type===U.ObjectExpression&&(r(c),l(c)),c.type===U.ArrowFunctionExpression&&(c.body.type===U.ObjectExpression&&(r(c.body),l(c.body)),c.body.type===U.BlockStatement))for(let a of c.body.body)a.type===U.ReturnStatement&&a.argument?.type===U.ObjectExpression&&(r(a.argument),l(a.argument));if(c.type===U.FunctionExpression)for(let a of c.body.body)a.type===U.ReturnStatement&&a.argument?.type===U.ObjectExpression&&(r(a.argument),l(a.argument))}}}}}),he={name:Ze,rule:tn};import{AST_NODE_TYPES as Se,ESLintUtils as nn}from"@typescript-eslint/utils";var rn=nn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),sn=j({disallow:$(Y(j({selector:L(),message:L(),replace:$(ge(L(),j({regex:L(),with:L()}))),replaceType:$(Xe(["suggestion","autofix"]))}))),__dev_simulateFileName:$(L()),mustMatchSyntax:$(Y(j({includeRegex:L(),mustCallFn:Y(j({anyCall:Y(j({fn:L(),withArgs:Y(j({atIndex:Je(),literal:ge(L(),X(),te())}))})),message:$(L())}))})))}),tt="advanced-no-restricted-syntax",on=rn({name:tt,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[sn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:l,disallow:u}=t,c=l??e.filename,a=[],s=new Set;for(let{includeRegex:i,mustCallFn:f}of r??[]){let T=an(c,new RegExp(i));if(!T)continue;let I=x=>{let d=x;for(let{name:b,value:g}of T)d=d.replaceAll(b,g);return d};for(let{anyCall:x,message:d}of f){let b=`Expected file to call the function: ${x.map(({fn:g})=>g).join(" or ")}`;s.add(b),a.push(g=>{let{callee:D}=g;if(D.type===Se.Identifier){for(let{fn:v,withArgs:y}of x)if(D.name===v){s.delete(b);for(let C of y){let R=g.arguments[C.atIndex],k=typeof C.literal=="string"?I(C.literal):C.literal;if(!R){e.report({node:g,messageId:"default",data:{message:`Missing argument with value "${k}" at index ${C.atIndex}${d?`: ${I(d)}`:""}`}});continue}if(R.type!==Se.Literal){e.report({node:R,messageId:"default",data:{message:`Argument at position ${C.atIndex} should the literal "${k}"${d?`: ${I(d)}`:""}`}});continue}R.value!==k&&e.report({node:R,messageId:"default",data:{message:`Argument should have the value "${k}"${d?`: ${I(d)}`:""}`},fix:_=>_.replaceText(R,typeof k=="string"?`'${k}'`:String(k))})}break}}})}}for(let{selector:i,message:f,replace:T,replaceType:I="suggestion"}of u??[]){if(i==="CallExpression"){a.push(x=>{o(T,x,f,I)});continue}n[i]=x=>{o(T,x,f,I)}}return a.length>0&&(n.CallExpression=i=>{if(i.type===Se.CallExpression)for(let f of a)f(i)}),n["Program:exit"]=i=>{for(let f of s)e.report({node:i,messageId:"default",data:{message:`${f}`}})},n;function o(i,f,T,I){let x=d=>{if(!i)return null;if(typeof i=="string")return d.replaceText(f,i);{let b=new RegExp(i.regex),g=e.sourceCode.getText(f);return d.replaceText(f,g.replace(b,i.with))}};e.report({node:f,messageId:"default",data:{message:T},fix:i&&I==="autofix"?x:void 0,suggest:i&&I==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof i=="string"?i:i.with}"`},fix:x}]:void 0})}}});function an(e,t){let n=[],r=t.exec(e);if(!r)return null;let[l,...u]=r;n.push({name:"$0_lowercase",value:l.toLowerCase()}),n.push({name:"$0_capitalize",value:Qe(l)}),n.push({name:"$0_uncapitalize",value:et(l)}),n.push({name:"$0",value:l});for(let c=0;c<u.length;c++){let a=`$${c+1}`,s=u[c];n.push({name:`${a}_lowercase`,value:s.toLowerCase()}),n.push({name:`${a}_capitalize`,value:Qe(s)}),n.push({name:`${a}_uncapitalize`,value:et(s)}),n.push({name:a,value:s})}return n}function Qe(e){return e.charAt(0).toUpperCase()+e.slice(1)}function et(e){return e.charAt(0).toLowerCase()+e.slice(1)}var Te={name:tt,rule:on};import{AST_NODE_TYPES as M,AST_TOKEN_TYPES as Ee,ESLintUtils as ln}from"@typescript-eslint/utils";var cn=ln.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),rt="collapse-simple-objs-in-one-line",pn=j({maxLineLength:$(X()),maxProperties:$(X()),nestedObjMaxLineLength:$(X()),nestedObjMaxProperties:$(X()),ignoreTypesWithSuffix:$(Y(L()))}),un=cn({name:rt,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:[pn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],l=t.maxProperties??2,u=t.nestedObjMaxLineLength??t.maxLineLength,c=t.nestedObjMaxProperties??3;function a(o){if(o.type===M.ObjectExpression){let i=o.parent.type===M.Property,f=i?c:l,T=o.properties.length;if(T>f)return!1;if(T===1){let x=o.properties[0];return x.type===M.Property&&(x.value.type===M.ObjectExpression||x.value.type===M.ArrayExpression)?!1:{text:n.getText(x),isNested:i,propsSize:T}}let I=[];for(let x of o.properties){if(x.type===M.Property){let d=x.value.type;if(!(d===M.Literal||d===M.Identifier||d===M.TemplateLiteral||d===M.TaggedTemplateExpression))return!1}I.push(n.getText(x))}return{text:I.join(", "),isNested:i,propsSize:T}}else{let i=o.parent.parent?.type===M.TSPropertySignature,f=i?c:l,T=o.members.length;if(T>f)return!1;if(r.length>0&&o.parent.type===M.TSTypeAliasDeclaration){let x=o.parent.id.name;if(r.some(d=>x.endsWith(d)))return!1}if(T===1){let x=o.members[0];return x.type===M.TSPropertySignature&&x.typeAnnotation?.typeAnnotation.type===M.TSTypeLiteral?!1:{text:n.getText(x),isNested:i,propsSize:1}}if(o.parent.type===M.TSIntersectionType||o.parent.type===M.TSUnionType)return!1;let I=[];for(let x of o.members){if(x.type!==M.TSPropertySignature)return!1;let d=x.typeAnnotation?.typeAnnotation;if(!d||d.type===M.TSTypeLiteral||!nt(d.type))return!1;if(d.type===M.TSTypeReference&&d.typeArguments){if(d.typeArguments.params.length>1)return!1;let g=d.typeArguments.params[0];if(!nt(g.type))return!1}let b=n.getText(x).trim();(b.endsWith(";")||b.endsWith(","))&&(b=b.slice(0,-1)),I.push(b)}return{text:I.join("; "),isNested:i,propsSize:T}}}function s(o){if(o.loc.start.line===o.loc.end.line||o.parent.type!==M.JSXExpressionContainer&&n.getTokenAfter(o,{filter:b=>{let g=b.type===Ee.Punctuator&&b.value===",",D=b.type===Ee.Punctuator&&b.value===";";return!g&&!D}})?.loc.start.line===o.loc.end.line)return;let i=a(o);if(!i)return;let f=i.text;if(f.includes(`
|
|
2
|
+
`)||n.getCommentsInside(o).length>0)return;f.endsWith(";")&&(f=f.slice(0,-1));let T=`{ ${f} }`,I=mn(n,o),x=i.isNested&&i.propsSize>2?u:t.maxLineLength;x&&T.length+I.length+(fn(o,n)?1:0)>x||e.report({node:o,messageId:"singleLineProp",fix:d=>d.replaceText(o,T)})}return{TSTypeLiteral:s,ObjectExpression:s}}});function nt(e){return e===M.TSLiteralType||e===M.TSTypeReference||e===M.TSNumberKeyword||e===M.TSStringKeyword||e===M.TSBooleanKeyword||e===M.TSNullKeyword||e===M.TSUndefinedKeyword}function fn(e,t){let n=t.getTokenAfter(e);return n?.type===Ee.Punctuator&&(n.value===","||n.value===";"||n.value==="}")&&n.loc.start.line===e.loc.end.line}function mn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var xe={name:rt,rule:un};var dn=/eslint +react-compiler\/react-compiler: +\["error/,st={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),l=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,u=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,c={additionalHooks:l,enableDangerousAutofixThisMayCauseInfiniteLoops:u};function a(g){u&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let s=e.getSourceCode().scopeManager,o=new WeakMap,i=new WeakSet,f=new WeakMap,T=new WeakMap,I=new WeakSet;function x(g,D){return function(v){if(D.has(v))return D.get(v);let y=g(v);return D.set(v,y),y}}function d(g,D,v,y,C){C&&g.async&&a({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
|
|
3
3
|
|
|
4
4
|
useEffect(() => {
|
|
5
5
|
async function fetchData() {
|
|
@@ -10,5 +10,5 @@ useEffect(() => {
|
|
|
10
10
|
fetchData();
|
|
11
11
|
}, [someId]); // Or [] if effect doesn't need props or state
|
|
12
12
|
|
|
13
|
-
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let R=s.acquire(g),k=new Set,_=null;{let p=R.upper;for(;p&&(k.add(p),p.type!=="function");)p=p.upper;if(!p)return;_=p}let A=Array.isArray;function W(p){if(!A(p.defs))return!1;let m=p.defs[0];if(m==null||m.node.type!=="VariableDeclarator")return!1;let h=m.node.init;if(h==null)return!1;for(;h.type==="TSAsExpression";)h=h.expression;let S=m.node.parent;if(S==null&&(we(_.block,m.node.id),S=m.node.parent,S==null))return!1;if(S.kind==="const"&&h.type==="Literal"&&(typeof h.value=="string"||typeof h.value=="number"||h.value===null))return!0;if(h.type!=="CallExpression")return!1;let w=h.callee;if(w.type==="MemberExpression"&&w.object.name==="React"&&w.property!=null&&!w.computed&&(w=w.property),w.type!=="Identifier")return!1;let E=m.node.id,{name:O}=w;if(O==="useRef"&&E.type==="Identifier")return!0;if(Tn(w)&&E.type==="Identifier"){for(let P of p.references)P!==E&&I.add(P.identifier);return!0}else if(O==="useState"||O==="useReducer"){if(E.type==="ArrayPattern"&&E.elements.length===2&&A(p.identifiers)){if(E.elements[1]===p.identifiers[0]){if(O==="useState"){let P=p.references,z=0;for(let J=0;J<P.length;J++){if(P[J].isWrite()&&z++,z>1)return!1;o.set(P[J].identifier,E.elements[0])}}return!0}else if(E.elements[0]===p.identifiers[0]){if(O==="useState"){let P=p.references;for(let z=0;z<P.length;z++)i.add(P[z].identifier)}return!1}}}else if(O==="useTransition"&&E.type==="ArrayPattern"&&E.elements.length===2&&Array.isArray(p.identifiers)&&E.elements[1]===p.identifiers[0])return!0;return!1}function K(p){if(!A(p.defs))return!1;let m=p.defs[0];if(m==null||m.node==null||m.node.id==null)return!1;let h=m.node,S=_.childScopes,w=null,E;for(E=0;E<S.length;E++){let O=S[E],P=O.block;if(h.type==="FunctionDeclaration"&&P===h||h.type==="VariableDeclarator"&&P.parent===h){w=O;break}}if(w==null)return!1;for(E=0;E<w.through.length;E++){let O=w.through[E];if(O.resolved!=null&&k.has(O.resolved.scope)&&!Ye(O.resolved))return!1}return!0}let Ye=b(W,f),Ut=b(K,T),Ve=new Map;function Yt(p){let m=p.from,h=!1;for(;m.block!==g;)m.type==="function"&&(h=m.block.parent!=null&&m.block.parent.type==="ReturnStatement"),m=m.upper;return h}let V=new Map,ue=new Map;ze(R);function ze(p){for(let m of p.references){if(!m.resolved||!k.has(m.resolved.scope))continue;let h=we(g,m.identifier),S=ot(h),w=G(S,ue);if(C&&S.type==="Identifier"&&(S.parent.type==="MemberExpression"||S.parent.type==="OptionalMemberExpression")&&!S.parent.computed&&S.parent.property.type==="Identifier"&&S.parent.property.name==="current"&&Yt(m)&&Ve.set(w,{reference:m,dependencyNode:S}),S.parent.type==="TSTypeQuery"||S.parent.type==="TSTypeReference")continue;let E=m.resolved.defs[0];if(E!=null&&!(E.node!=null&&E.node.init===g.parent)&&E.type!=="TypeParameter")if(V.has(w))V.get(w).references.push(m);else{let O=m.resolved,P=Ye(O)||Ut(O);V.set(w,{isStable:P,references:[m]})}}for(let m of p.childScopes)ze(m)}Ve.forEach(({reference:p,dependencyNode:m},h)=>{let S=p.resolved.references,w=!1;for(let E=0;E<S.length;E++){let{identifier:O}=S[E],{parent:P}=O;if(P!=null&&P.type==="MemberExpression"&&!P.computed&&P.property.type==="Identifier"&&P.property.name==="current"&&P.parent.type==="AssignmentExpression"&&P.parent.left===P){w=!0;break}}w||a({node:m.parent.property,message:`The ref value '${h}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${h}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let fe=new Set;function Vt(p,m){fe.has(m)||(fe.add(m),a({node:p,message:`Assignments to the '${m}' variable from inside React Hook ${n(v)} 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(v)}.`}))}let oe=new Set;if(V.forEach(({isStable:p,references:m},h)=>{p&&oe.add(h),m.forEach(S=>{S.writeExpr&&Vt(S.writeExpr,h)})}),fe.size>0)return;if(!D){let p=null;if(V.forEach(({isStable:m,references:h},S)=>{p||h.forEach(w=>{if(p)return;let E=w.identifier;if(!o.has(E))return;let P=w.from;for(;P.type!=="function";)P=P.upper;P.block===g&&(p=S)})}),p){let{suggestedDependencies:m}=xe({dependencies:V,declaredDependencies:[],stableDependencies:oe,externalDependencies:new Set,isEffect:!0});a({node:v,message:`React Hook ${y} contains a call to '${p}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+m.join(", ")+`] as a second argument to the ${y} Hook.`,suggest:[{desc:`Add dependencies array: [${m.join(", ")}]`,fix(h){return h.insertTextAfter(g,`, [${m.join(", ")}]`)}}]})}return}let ie=[],se=new Set;D.type!=="ArrayExpression"?a({node:D,message:`React Hook ${n(v)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(p=>{if(p===null)return;if(p.type==="SpreadElement"){a({node:p,message:`React Hook ${n(v)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}I.has(p)&&a({node:p,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(p)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(p)}\``,fix(w){return w.removeRange(p.range)}}]});let m;try{m=G(p,ue)}catch(w){if(/Unsupported node type/.test(w.message)){p.type==="Literal"?V.has(p.value)?a({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. Did you mean to include ${p.value} in the array instead?`}):a({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):a({node:p,message:`React Hook ${n(v)} 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 h=p;for(;h.type==="MemberExpression"||h.type==="OptionalMemberExpression"||h.type==="ChainExpression";)h=h.object||h.expression.object;let S=!_.through.some(w=>w.identifier===h);ie.push({key:m,node:p}),S||se.add(m)});let{suggestedDependencies:zt,unnecessaryDependencies:ae,missingDependencies:Z,duplicateDependencies:qe}=xe({dependencies:V,declaredDependencies:ie,stableDependencies:oe,externalDependencies:se,isEffect:C}),le=zt;if(qe.size+Z.size+ae.size===0){if(t)return;yn({declaredDependencies:ie,declaredDependenciesNode:D,componentScope:_,scope:R}).forEach(({construction:m,isUsedOutsideOfHook:h,depType:S})=>{let w=S==="function"?"useCallback":"useMemo",E=S==="function"?"definition":"initialization",O=`wrap the ${E} of '${m.name.name}' in its own ${w}() Hook.`,P=h?`To fix this, ${O}`:`Move it inside the ${y} callback. Alternatively, ${O}`,z=S==="conditional"||S==="logical expression"?"could make":"makes",J=`The '${m.name.name}' ${S} ${z} the dependencies of ${y} Hook (at line ${D.loc.start.line}) change on every render. ${P}`,Be;h&&m.type==="Variable"&&S==="function"&&(Be=[{desc:`Wrap the ${E} of '${m.name.name}' in its own ${w}() Hook.`,fix(Ke){let[Bt,Kt]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Ke.insertTextBefore(m.node.init,Bt),Ke.insertTextAfter(m.node.init,Kt)]}}]),a({node:m.node,message:J,suggest:Be})});return}!C&&Z.size>0&&(le=xe({dependencies:V,declaredDependencies:[],stableDependencies:oe,externalDependencies:se,isEffect:C}).suggestedDependencies);function qt(){if(ie.length===0)return!0;let p=ie.map(h=>h.key),m=p.slice().sort();return p.join(",")===m.join(",")}qt()&&le.sort();function me(p){let m=p.split("."),h="";for(let S=0;S<m.length;S++){if(S!==0){let w=m.slice(0,S+1).join("."),E=ue.get(w)===!0;h+=E?"?.":"."}h+=m[S]}return h}function de(p,m,h,S){return p.size===0?null:(p.size>1?"":m+" ")+h+" "+(p.size>1?"dependencies":"dependency")+": "+hn(Array.from(p).sort().map(w=>"'"+me(w)+"'"))+`. Either ${S} ${p.size>1?"them":"it"} or remove the dependency array.`}let B="";if(ae.size>0){let p=null;if(Array.from(ae.keys()).forEach(m=>{p===null&&m.endsWith(".current")&&(p=m)}),p!==null)B=` Mutable values like '${p}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(se.size>0){let m=Array.from(se)[0];R.set.has(m)||(B=` Outer scope values like '${m}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!B&&Z.has("props")){let p=V.get("props");if(p==null)return;let m=p.references;if(!Array.isArray(m))return;let h=!0;for(let S=0;S<m.length;S++){let w=m[S],E=we(_.block,w.identifier);if(!E){h=!1;break}let O=E.parent;if(O==null){h=!1;break}if(O.type!=="MemberExpression"&&O.type!=="OptionalMemberExpression"){h=!1;break}}h&&(B=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${y} call and refer to those specific props inside ${n(v)}.`)}if(!B&&Z.size>0){let p=null;Z.forEach(m=>{if(p)return;let h=_.set.get(m),S=V.get(m);if(S.references[0].resolved!==h)return;let w=h.defs[0];if(w==null||w.name==null||w.type!=="Parameter")return;let E=!1,O;for(let P=0;P<S.references.length;P++)if(O=S.references[P].identifier,O!=null&&O.parent!=null&&(O.parent.type==="CallExpression"||O.parent.type==="OptionalCallExpression")&&O.parent.callee===O){E=!0;break}E&&(p=m)}),p!==null&&(B=` If '${p}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!B&&Z.size>0){let p=null;if(Z.forEach(m=>{if(p!==null)return;let S=V.get(m).references,w,E;for(let O=0;O<S.length;O++){for(w=S[O].identifier,E=w.parent;E!=null&&E!==_.block;){if(E.type==="CallExpression"){let P=o.get(E.callee);if(P!=null){if(P.name===m)p={missingDep:m,setter:E.callee.name,form:"updater"};else if(i.has(w))p={missingDep:m,setter:E.callee.name,form:"reducer"};else{let z=S[O].resolved;if(z!=null){let J=z.defs[0];J!=null&&J.type==="Parameter"&&(p={missingDep:m,setter:E.callee.name,form:"inlineReducer"})}}break}}E=E.parent}if(p!==null)break}}),p!==null)switch(p.form){case"reducer":B=` You can also replace multiple useState variables with useReducer if '${p.setter}' needs the current value of '${p.missingDep}'.`;break;case"inlineReducer":B=` If '${p.setter}' needs the current value of '${p.missingDep}', you can also switch to useReducer instead of useState and read '${p.missingDep}' in the reducer.`;break;case"updater":B=` You can also do a functional update '${p.setter}(${p.missingDep.slice(0,1)} => ...)' if you only need '${p.missingDep}' in the '${p.setter}' call.`;break;default:throw new Error("Unknown case.")}}a({node:D,message:`React Hook ${n(v)} has `+(de(Z,"a","missing","include")||de(ae,"an","unnecessary","exclude")||de(qe,"a","duplicate","omit"))+B,suggest:[{desc:`Update the dependencies array to be: [${le.map(me).join(", ")}]`,fix(p){return p.replaceText(D,`[${le.map(me).join(", ")}]`)}}]})}function x(g){let D=gn(g.callee,c);if(D===-1)return;let v=g.arguments[D],y=g.callee,C=at(y).name,R=g.arguments[D+1],k=/Effect($|[^a-z])/g.test(C);if(!v){a({node:y,message:`React Hook ${C} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!k)){if(!R&&!k){(C==="useMemo"||C==="useCallback")&&a({node:y,message:`React Hook ${C} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(v.type){case"FunctionExpression":case"ArrowFunctionExpression":d(v,R,y,C,k);return;case"Identifier":if(!R||R.elements&&R.elements.some(W=>W&&W.type==="Identifier"&&W.name===v.name))return;let _=r(g).set.get(v.name);if(_==null||_.defs==null)return;let A=_.defs[0];if(!A||!A.node||A.type!=="Variable"&&A.type!=="FunctionName")break;switch(A.node.type){case"FunctionDeclaration":d(A.node,R,y,C,k);return;case"VariableDeclarator":let W=A.node.init;if(!W)break;switch(W.type){case"ArrowFunctionExpression":case"FunctionExpression":d(W,R,y,C,k);return}break}break;default:a({node:y,message:`React Hook ${C} received a function whose dependencies are unknown. Pass an inline function instead.`});return}a({node:y,message:`React Hook ${C} has a missing dependency: '${v.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${v.name}]`,fix(_){return _.replaceText(R,`[${v.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(dn.test(g.value))return t=!0,{CallExpression:D=>x(D,!0)}}return{CallExpression:g=>x(g)}}};function xe({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:l}){let u=c();function c(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((d,x)=>{let g=a(u,x);g.isUsed=!0,s(u,x,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:d})=>{let x=a(u,d);x.isSatisfiedRecursively=!0}),n.forEach(d=>{let x=a(u,d);x.isSatisfiedRecursively=!0});function a(d,x){let g=x.split("."),D=d;for(let v of g){let y=D.children.get(v);y||(y=c(),D.children.set(v,y)),D=y}return D}function s(d,x,g){let D=x.split("."),v=d;for(let y of D){let C=v.children.get(y);if(!C)return;g(C),v=C}}let o=new Set,i=new Set;f(u,o,i,d=>d);function f(d,x,g,D){d.children.forEach((v,y)=>{let C=D(y);if(v.isSatisfiedRecursively){v.isSubtreeUsed&&g.add(C);return}if(v.isUsed){x.add(C);return}f(v,x,g,R=>C+"."+R)})}let T=[],I=new Set,b=new Set;return t.forEach(({key:d})=>{i.has(d)?T.indexOf(d)===-1?T.push(d):b.add(d):I.add(d)}),o.forEach(d=>{T.push(d)}),{suggestedDependencies:T,unnecessaryDependencies:I,duplicateDependencies:b,missingDependencies:o}}function ee(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 ee(e.consequent)!=null||ee(e.alternate)!=null?"conditional":null;case"LogicalExpression":return ee(e.left)!=null||ee(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return ee(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return ee(e.expression);case"TSAsExpression":return ee(e.expression)}return null}function yn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let l=e.map(({key:c})=>{let a=n.variables.find(o=>o.name===c);if(a==null)return null;let s=a.defs[0];if(s==null)return null;if(s.type==="Variable"&&s.node.type==="VariableDeclarator"&&s.node.id.type==="Identifier"&&s.node.init!=null){let o=ee(s.node.init);if(o!=null)return[a,o]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[a,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[a,"class"]:null}).filter(Boolean);function u(c){let a=!1;for(let s=0;s<c.references.length;s++){let o=c.references[s];if(o.writeExpr){if(a)return!0;a=!0;continue}let i=o.from;for(;i!==r&&i!=null;)i=i.upper;if(i!==r&&!lt(t,o.identifier))return!0}return!1}return l.map(([c,a])=>({construction:c.defs[0],depType:a,isUsedOutsideOfHook:u(c)}))}function ot(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)?ot(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function Ie(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function G(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=G(e.object,t),r=G(e.property,null),l=`${n}.${r}`;return Ie(e,t,l),l}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=G(e.object,t),r=G(e.property,null),l=`${n}.${r}`;return Ie(e,t,l),l}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=G(n.object,t),l=G(n.property,null),u=`${r}.${l}`;return Ie(n,t,u),u}else throw new Error(`Unsupported node type: ${e.type}`)}function at(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function gn(e,t){let n=at(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=G(n,null)}catch(l){if(/Unsupported node type/.test(l.message))return 0;throw l}return t.additionalHooks.test(r)?0:-1}else return-1}}function we(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Sn(r,t))return r;if(lt(r,t))for(let[l,u]of Object.entries(r))l!=="parent"&&(it(u)?(u.parent=r,n.push(u)):Array.isArray(u)&&u.forEach(c=>{it(c)&&(c.parent=r,n.push(c))}))}return null}function hn(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 Sn(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 lt(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Tn(e){return!1}import{AST_NODE_TYPES as En,ESLintUtils as bn}from"@typescript-eslint/utils";var xn=bn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ct="no-call-with-explicit-generics",In=j({functions:U(M())}),wn=xn({name:ct,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:[In]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:l}=r;l.type===En.Identifier&&n.has(l.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:l.name}})}}}}),Ce={name:ct,rule:wn};import{AST_NODE_TYPES as ce,ESLintUtils as Cn}from"@typescript-eslint/utils";var Rn=Cn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),pt="no-call-with-inferred-generics",vn=Rn({name:pt,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:l}=r;if(l.type!==ce.Identifier)return;let u=n.get(l.name);if(!u)return;let{minGenerics:c=1,allowAny:a,disallowTypes:s=t.disallowTypes}=u;(r.typeArguments?.params.length||0)<(c||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:l.name,minGenerics:c||0}}),!(a&&!s)&&r.typeArguments?.params?.some(i=>!a&&i.type===ce.TSAnyKeyword||s&&i.type===ce.TSTypeReference&&i.typeName.type===ce.Identifier&&s.includes(i.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:l.name}})}}}}),Re={name:pt,rule:vn};import{ESLintUtils as kn,TSESTree as ut}from"@typescript-eslint/utils";var An=kn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ft="no-commented-out-code",On=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Pn=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Dn=An({name:ft,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 l of On)if(r.startsWith(l))return{wrongPattern:l};for(let l of Pn)if(typeof l=="string"){if(n.includes(l))return{wrongPattern:l}}else if(l.test(n))return{wrongPattern:`regex(${l.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let l of r)if(l.type===ut.AST_TOKEN_TYPES.Line||l.type===ut.AST_TOKEN_TYPES.Block){let u=t(l.value);u&&e.report({node:l,messageId:"commentedOutCode",data:{wrongPattern:u.wrongPattern}})}}}}}),ve={name:ft,rule:Dn};import{ESLintUtils as _n,TSESTree as $n}from"@typescript-eslint/utils";var Nn=_n.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),mt="no-default-export",Mn=Nn({name:mt,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===$n.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),ke={name:mt,rule:Mn};import{ESLintUtils as Ln}from"@typescript-eslint/utils";var jn=Ln.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),dt="no-leaked-text-in-jsx",Fn=[",",";","[","]","(",")"],Wn=jn({name:dt,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="";Fn.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Ae={name:dt,rule:Wn};import{AST_NODE_TYPES as ne,ESLintUtils as Hn}from"@typescript-eslint/utils";var Un=Hn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),gt="no-non-camel-case-functions",Yn=/^[a-z][a-zA-Z0-9]*$/;function yt(e){return e.typeName.type===ne.TSQualifiedName&&e.typeName.left.type===ne.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===ne.Identifier&&e.typeName.right.name==="Element"}var Vn=Un({name:gt,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&&!Yn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ne.TSTypeReference?yt(n):n.type===ne.TSUnionType&&n.types.some(l=>l.type===ne.TSTypeReference&&yt(l))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Oe={name:gt,rule:Vn};import{ESLintUtils as zn,TSESTree as F}from"@typescript-eslint/utils";function re(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:re(e.parent,t,n===1/0?n:n-1)}function*Pe(e){yield e,e.parent&&(yield*Pe(e.parent))}var qn=zn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ht="no-optional-root-props",Bn=qn({name:ht,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(l){return l?l.parent?.type===F.AST_NODE_TYPES.ExportNamedDeclaration||l.parent?.type===F.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function n(l){let c=e.sourceCode.getDeclaredVariables(l)[0];if(!c||c.references.length!==1)return!1;let a=c.references[0];if(!a)return!1;for(let s of Pe(a.identifier)){if("returnType"in s||s.type===F.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let o=s.parent;if(!o)return!1;if(o.type===F.AST_NODE_TYPES.TSTypeParameterInstantiation&&o.parent.type===F.AST_NODE_TYPES.TSTypeReference&&o.parent.typeName.type===F.AST_NODE_TYPES.Identifier&&o.parent.typeName.name==="FC"){let f=re(o.parent.parent,F.AST_NODE_TYPES.VariableDeclaration,4);if(f)return!(t(f)||e.sourceCode.getScope(f).references.some(I=>t(I.identifier.parent.parent)))}if(s.type===F.AST_NODE_TYPES.AssignmentPattern)return!1;if(o.type===F.AST_NODE_TYPES.ArrowFunctionExpression){let i=re(o,F.AST_NODE_TYPES.VariableDeclaration);return i&&t(i)||i&&e.sourceCode.getScope(i).references.some(T=>T.identifier.parent.parent?.parent?.type===F.AST_NODE_TYPES.ExportNamedDeclaration)?!1:o.params.some(f=>f===s)}if(o.type===F.AST_NODE_TYPES.FunctionDeclaration)return t(o)||e.sourceCode.getScope(o).upper?.references.some(f=>t(f.identifier.parent.parent))?!1:o.params.some(f=>f===s)}return!1}function r(l){l.key.type!==F.AST_NODE_TYPES.Identifier||!l.optional||e.report({node:l.key,messageId:"optionalNotAllowed",data:{propertyName:l.key.name},suggest:[{messageId:"suggestion",fix:u=>{let c=re(l,F.AST_NODE_TYPES.TSPropertySignature);if(!c)return null;let a=e.sourceCode.getText(c);return u.replaceText(c,a.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(l){if(l.typeAnnotation.type===F.AST_NODE_TYPES.TSTypeLiteral&&!(t(l)||!n(l)))for(let u of l.typeAnnotation.members)u.type===F.AST_NODE_TYPES.TSPropertySignature&&r(u)},TSInterfaceDeclaration(l){if(!(t(l)||!n(l)))for(let u of l.body.body)u.type===F.AST_NODE_TYPES.TSPropertySignature&&r(u)},TSTypeReference(l){if(l.typeName.type!==F.AST_NODE_TYPES.Identifier||l.typeName.name!=="FC"||!l.typeArguments?.params[0])return;let u=l.typeArguments.params[0];if(u.type!==F.AST_NODE_TYPES.TSTypeLiteral)return;let c=re(l.parent,F.AST_NODE_TYPES.VariableDeclaration,4);if(!c||t(c)||e.sourceCode.getScope(c).references.some(i=>i.identifier.parent.parent?.parent?.type===F.AST_NODE_TYPES.ExportNamedDeclaration))return;let s=c.declarations[0].id.type===F.AST_NODE_TYPES.Identifier?c.declarations[0].id:null,o=e.sourceCode.getScope(c).variables.find(i=>i.name===s?.name)?.references.filter(i=>i.identifier!==s);if(!(o&&o.length>1))for(let i of u.members)i.type===F.AST_NODE_TYPES.TSPropertySignature&&r(i)}}}}),De={name:ht,rule:Bn};import{ESLintUtils as Kn}from"@typescript-eslint/utils";import _e from"node:path";var Xn=Kn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),St="no-relative-imports",Jn=j({find:M(),replacement:M()}),Gn=j({aliases:U(Jn),rootDir:$(M()),allowNotFoundAliases:$(te()),_dev_simulateFileName:$(M())}),Zn=Xn({name:St,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:[Gn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(c){return c.startsWith(".")||c.startsWith("..")}function l(c,a){let s=_e.dirname(a);return _e.resolve(s,c)}function u(c){let a=t.rootDir??process.cwd(),s=_e.relative(a,c);if(s.startsWith("."))return null;s.startsWith("/")||(s=`/${s}`);for(let{find:o,replacement:i}of t.aliases)if(s.startsWith(i)){let f=s.replace(i,o);return{alias:o,newPath:f}}return null}return{ImportDeclaration(c){let a=c.source.value;if(!r(a))return;let s=l(a,n),o=u(s);!o&&t.allowNotFoundAliases||e.report({node:c,messageId:o?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:o?.alias},fix:o?i=>i.replaceText(c.source,`'${o.newPath}'`):void 0})}}}}),$e={name:St,rule:Zn};import{AST_NODE_TYPES as N,ESLintUtils as Qn}from"@typescript-eslint/utils";var er=Qn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Tt(e){let t=[];for(let n of e.members)n.type===N.TSPropertySignature&&n.key.type===N.Identifier&&t.push([n.key.name,n]);return t}function Et(e,...t){for(let n of t)e.set(...n);return e}var tr=j({forceCheckOnFCPropTypesWithName:$(U(M()))}),bt="no-unused-type-props-in-args",Ne=null,nr=er({name:bt,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:[tr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!Ne&&(Ne=n.map(a=>new RegExp(a)));function r(a,s,o,i,f=!0){let T=o.name,I=e.sourceCode.getScope(s).references.find(x=>x.identifier.name===T)?.resolved,b=a&&Ne?.some(x=>x.test(T));if(!I||!b&&I.references.filter(x=>x.isTypeReference).length>1)return;let d=I?.defs[0]?.node;if(!(f&&d?.parent?.type===N.ExportNamedDeclaration)){if(d?.type===N.TSTypeAliasDeclaration){l(a,s,i,d.typeAnnotation,!0);return}if(d?.type===N.TSInterfaceDeclaration){l(a,s,i,d.body,!0);return}}}function l(a,s,o,i,f){if(i.type===N.TSInterfaceBody){for(let T of i.body)T.type===N.TSPropertySignature&&T.key.type===N.Identifier&&o.set(T.key.name,T);return}if(i.type===N.TSTypeLiteral){Et(o,...Tt(i));return}if(i.type===N.TSIntersectionType){for(let T of i.types)l(a,s,o,T,!0);return}f||i.type===N.TSTypeReference&&i.typeName.type===N.Identifier&&r(a,s,i.typeName,o)}function u(a,s,o){for(let i of o)if(i.type==="ObjectPattern"&&i.typeAnnotation){let f=new Map;if(l(a,s,f,i.typeAnnotation.typeAnnotation,!1),f.size===0)continue;c(i,f)}else i.type===N.AssignmentPattern&&i.left.type===N.ObjectPattern&&u(a,s,[i.left])}function c(a,s){let o=[];if(a.properties.at(-1)?.type===N.RestElement)return;for(let I of a.properties)I.type===N.Property&&I.key.type===N.Identifier&&o.push(I.key.name);let f=[],T=[];for(let[I,b]of s)o.includes(I)||(T.push(I),f.push({node:b,messageId:"unusedObjectTypeProperty",data:{propertyName:I}}));for(let[I,b]of f.entries())e.report({...b,fix:I===f.length-1?d=>{let x=a.properties.at(-1),g=T.join(", ");return x?x?.type===N.RestElement?null:d.insertTextAfter(x,`, ${g}`):d.insertTextBeforeRange([a.range[0]+1,a.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(a){let s=a.declarations[0];if(!s)return;let o=new Map,i=s.id.type===N.Identifier&&s.id.typeAnnotation?.typeAnnotation.type===N.TSTypeReference&&s.id.typeAnnotation.typeAnnotation.typeName.type===N.Identifier&&s.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&s.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(i){if(i.type===N.TSTypeReference&&i.typeName.type===N.Identifier)r(!0,a,i.typeName,o,!1);else if(i.type===N.TSTypeLiteral)Et(o,...Tt(i));else if(i.type===N.TSIntersectionType)for(let f of i.types)f.type===N.TSTypeReference&&f.typeName.type===N.Identifier?r(!0,a,f.typeName,o,!1):l(!0,a,o,f,!0);if(o.size!==0&&s.init?.type===N.ArrowFunctionExpression){let f=s.init.params[0];if(!f){e.report({node:s.init,messageId:"missingComponentParam"});return}f.type===N.ObjectPattern&&c(f,o)}}},FunctionDeclaration:function(a){u(!1,a,a.params)},ArrowFunctionExpression(a){u(!1,a,a.params)}}}}),Me={name:bt,rule:nr};import{AST_NODE_TYPES as Le,ESLintUtils as rr}from"@typescript-eslint/utils";var ir=rr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),It="prefer-named-functions",xt=new Map,sr=ir({name:It,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=xt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),xt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===Le.ArrowFunctionExpression&&r.id.type===Le.Identifier){let l=r.id.name;if(r.id.typeAnnotation||n&&n.test(l)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==Le.BlockStatement)return;let u=r.parent,c=r.init.params,a=r.init.body,s=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:l,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:o=>o.replaceText(u,`${s.async?"async ":""}function ${l}(${c.map(i=>e.sourceCode.getText(i)).join(", ")||""}) ${e.sourceCode.getText(a)}`)}]})}}}}}),je={name:It,rule:sr};import{AST_NODE_TYPES as Y,AST_TOKEN_TYPES as wt,ESLintUtils as or}from"@typescript-eslint/utils";var ar=or.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Rt="prefer-single-line-if",lr=j({maxLineLength:$(X()),maxNonSimpleConditionLength:$(X())}),cr=ar({name:Rt,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:[lr]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==Y.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let u=r.consequent.body[0];if(u.type===Y.ReturnStatement){if(!kt(u))return}else if(!(u.type===Y.ContinueStatement||u.type===Y.BreakStatement))return;if(r.test.type===Y.LogicalExpression||r.test.type===Y.ConditionalExpression)return;let c;if(t.maxNonSimpleConditionLength){let f=Ct(r.test);if(!f&&r.test.type===Y.UnaryExpression&&r.test.operator==="!"){let T=r.test.argument;Ct(T)&&(f=!0)}if(f&&(c=n.getText(r.test),c.length>t.maxNonSimpleConditionLength))return}c||(c=n.getText(r.test));let a=n.getText(u);if(c.includes(`
|
|
14
|
-
`))return;let s=n.getTokenAfter(r);if(s&&s.type===wt.Punctuator&&s.value==="}"){let f=n.getTokenAfter(s);if(f&&f.type===wt.Keyword&&(f.value==="else"||f.value==="catch"))return}let o=pr(n,r),i=`if (${c}) ${a}`;t.maxLineLength&&i.length+o.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:f=>f.replaceText(r,i)})}}}});function Ct(e){return e.type===Y.CallExpression||e.type===Y.BinaryExpression||e.type===Y.MemberExpression&&vt(e)}function vt(e){return e.object.type===Y.MemberExpression?vt(e.object):e.object.type!==Y.Identifier}function pr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function kt(e){return!e.argument||e.argument.type===Y.Literal||e.argument.type===Y.Identifier?!0:e.argument.type===Y.CallExpression?e.argument.arguments.length===0:e.argument.type===Y.UnaryExpression?kt(e.argument):!1}var Fe={name:Rt,rule:cr};import{AST_NODE_TYPES as q,ESLintUtils as ur}from"@typescript-eslint/utils";var fr=ur.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),At="react-compiler-migration",mr=j({disallowHooks:$(U(j({name:M(),replacement:M()}))),disallowMethods:$(U(j({name:M(),replacement:$(M()),requireTrueProp:$(M())})))}),dr=/eslint +react-compiler\/react-compiler: +\["error/;function yr(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 gr=fr({name:At,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:[mr]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(dr.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let l=null,u=null;if(r.callee.type===q.Identifier?(l=r.callee.name,u=r.callee):r.callee.type===q.MemberExpression&&r.callee.property.type===q.Identifier&&(l=r.callee.property.name,u=r.callee.property),l){let c=t.disallowHooks.find(a=>a.name===l);c&&u&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:c.name,replacement:c.replacement},suggest:[{messageId:"replace",data:{replacement:c.replacement},fix:a=>a.replaceText(u,c.replacement)}]})}}if(t.disallowMethods?.length&&yr(r.callee)){for(let l of r.arguments)if(l.type===q.ObjectExpression){for(let u of l.properties)if(u.type===q.Property&&u.key.type===q.Identifier){let c=u.key.name,a=t.disallowMethods.find(s=>s.name===c);if(a){if(a.requireTrueProp){let s=a.requireTrueProp,o=!1;for(let i of l.properties)if(i.type===q.Property&&i.key.type===q.Identifier&&i.key.name===s&&i.value.type===q.Literal&&i.value.value===!0){o=!0;break}if(!o){e.report({node:u,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:a.name,requireTrueProp:s}});continue}}a.replacement&&e.report({node:u,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:a.name,replacement:a.replacement},suggest:[{messageId:"replace",data:{replacement:a.replacement},fix:s=>s.replaceText(u.key,a.replacement)}]})}}}}}}:{}}}),We={name:At,rule:gr};import{ESLintUtils as hr,TSESTree as Sr}from"@typescript-eslint/utils";var Tr=hr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ot="require-description",Er=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,br=/^eslint-disable-(next-)?line$/u,xr=Tr({name:Ot,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 l of n.getAllComments()){let u=Ir(l);u!=null&&(r.has(u.kind)||u.description||e.report({loc:Cr(l.loc),messageId:"missingDescription"}))}}}}}),Pt={name:Ot,rule:xr};function Ir(e){let{text:t,description:n}=wr(e.value);if(!t)return null;let r=Er.exec(t);if(!r)return null;let l=r[1];if(!l)return null;let u=br.test(l);if(e.type===Sr.AST_TOKEN_TYPES.Line&&!u||u&&e.loc.start.line!==e.loc.end.line)return null;let c=t.slice(r.index+l.length);return{kind:l,value:c.trim(),description:n}}function wr(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Cr(e){return{start:{line:e.start.line,column:-1},end:e.end}}function $t(e){return/^use[A-Z0-9]/.test(e)}function pe(e){return e.type==="Identifier"?$t(e.name):e.type==="MemberExpression"&&!e.computed&&pe(e.property)?e.object.type==="Identifier":!1}function Nt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Mt(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Lt(e){return!!(e.parent&&e.parent.callee&&Mt(e.parent.callee,"forwardRef"))}function jt(e){return!!(e.parent&&e.parent.callee&&Mt(e.parent.callee,"memo"))}function He(e){for(;e;){let t=Wt(e);if(t&&(Nt(t)||pe(t))||Lt(e)||jt(e))return!0;e=e.parent}return!1}function Dt(e){return!1}function Ue(e){return!1}var Rr=/eslint +react-compiler\/react-compiler: +\["error/,Ft={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let s of e.sourceCode.getAllComments())if(Rr.test(s.value))return{CallExpression(o){let i=null;o.callee.name==="useMemo"?i="useMemo":o.callee.name==="useCallback"&&(i="useCallback"),i&&e.report({node:o,message:`"${i}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?s=>t(s):s=>e.sourceCode.getText(s),n=typeof e.getScope=="function"?()=>n():s=>e.sourceCode.getScope(s),r=null,l=[],u=[],c=new WeakSet;function a(s){for(let o of s.references){let i=o.identifier.parent;if(i.type==="VariableDeclarator"&&i.init&&i.init.type==="CallExpression"&&i.init.callee&&Dt(i.init.callee))for(let f of o.resolved.references)f!==o&&c.add(f.identifier)}}return{onCodePathSegmentStart:s=>u.push(s),onCodePathSegmentEnd:()=>u.pop(),onCodePathStart:()=>l.push(new Map),onCodePathEnd(s,o){let i=l.pop();if(i.size===0)return;let f=new Set;function T(y,C){let{cache:R}=T,k=R.get(y.id),_=new Set(C);if(_.has(y.id)){let A=[..._],W=A.slice(A.indexOf(y.id)+1);for(let K of W)f.add(K);return BigInt("0")}if(_.add(y.id),k!==void 0)return k;if(s.thrownSegments.includes(y))k=BigInt("0");else if(y.prevSegments.length===0)k=BigInt("1");else{k=BigInt("0");for(let A of y.prevSegments)k+=T(A,_)}return y.reachable&&k===BigInt("0")?R.delete(y.id):R.set(y.id,k),k}function I(y,C){let{cache:R}=I,k=R.get(y.id),_=new Set(C);if(_.has(y.id)){let A=Array.from(_),W=A.slice(A.indexOf(y.id)+1);for(let K of W)f.add(K);return BigInt("0")}if(_.add(y.id),k!==void 0)return k;if(s.thrownSegments.includes(y))k=BigInt("0");else if(y.nextSegments.length===0)k=BigInt("1");else{k=BigInt("0");for(let A of y.nextSegments)k+=I(A,_)}return R.set(y.id,k),k}function b(y){let{cache:C}=b,R=C.get(y.id);if(R===null)return 1/0;if(R!==void 0)return R;if(C.set(y.id,null),y.prevSegments.length===0)R=1;else{R=1/0;for(let k of y.prevSegments){let _=b(k);_<R&&(R=_)}R+=1}return C.set(y.id,R),R}T.cache=new Map,I.cache=new Map,b.cache=new Map;let d=I(s.initialSegment),x=Wt(o),g=He(o),D=x?Nt(x)||pe(x):Lt(o)||jt(o),v=1/0;for(let y of s.finalSegments){if(!y.reachable)continue;let C=b(y);C<v&&(v=C)}for(let[y,C]of i){if(!y.reachable)continue;let R=y.nextSegments.length===0?v<=b(y):v<b(y),k=T(y)*I(y),_=f.has(y.id);for(let A of C)if(_&&!Ue(A)&&e.report({node:A,message:`React Hook "${t(A)}" 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.`}),D){if(o.async&&e.report({node:A,message:`React Hook "${t(A)}" cannot be called in an async function.`}),!_&&k!==d&&!Ue(A)){let K=`React Hook "${t(A)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(R?" Did you accidentally call a React Hook after an early return?":"");e.report({node:A,message:K})}}else if(o.parent&&(o.parent.type==="MethodDefinition"||o.parent.type==="ClassProperty")&&o.parent.value===o){let W=`React Hook "${t(A)}" 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:A,message:W})}else if(x){let W=`React Hook "${t(A)}" is called in function "${t(x)}" 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:A,message:W})}else if(o.type==="Program"){let W=`React Hook "${t(A)}" 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:A,message:W})}else if(g&&!Ue(A)){if(o.parent.type==="CallExpression"&&o.parent.callee.type==="Identifier"&&o.parent.callee.name==="useCallback"){let K=o.parent;if(K.parent.type==="VariableDeclarator"&&$t(K.parent.id.name))return}let W=`React Hook "${t(A)}" 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:A,message:W})}}},CallExpression(s){if(pe(s.callee)){let o=_t(l),i=_t(u),f=o.get(i);f||(f=[],o.set(i,f)),f.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Dt(s.callee))&&s.arguments.length>0&&(r=s)},Identifier(s){r==null&&c.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${t(s)}\` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.`})},"CallExpression:exit"(s){s===r&&(r=null)},FunctionDeclaration(s){He(s)&&a(n(s))},ArrowFunctionExpression(s){He(s)&&a(n(s))}}}};function Wt(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 _t(e){return e[e.length-1]}var Ht={[Me.name]:Me.rule,[ve.name]:ve.rule,[Re.name]:Re.rule,"rules-of-hooks":Ft,"exhaustive-deps":st,"require-description":Pt.rule,[ke.name]:ke.rule,[Oe.name]:Oe.rule,[je.name]:je.rule,[Te.name]:Te.rule,[Ce.name]:Ce.rule,[$e.name]:$e.rule,[Fe.name]:Fe.rule,[De.name]:De.rule,[Ae.name]:Ae.rule,[be.name]:be.rule,[We.name]:We.rule,[he.name]:he.rule};var Ui={rules:Ht};export{Ui as extendedLintPlugin};
|
|
13
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let R=s.acquire(g),k=new Set,_=null;{let p=R.upper;for(;p&&(k.add(p),p.type!=="function");)p=p.upper;if(!p)return;_=p}let A=Array.isArray;function W(p){if(!A(p.defs))return!1;let m=p.defs[0];if(m==null||m.node.type!=="VariableDeclarator")return!1;let h=m.node.init;if(h==null)return!1;for(;h.type==="TSAsExpression";)h=h.expression;let S=m.node.parent;if(S==null&&(we(_.block,m.node.id),S=m.node.parent,S==null))return!1;if(S.kind==="const"&&h.type==="Literal"&&(typeof h.value=="string"||typeof h.value=="number"||h.value===null))return!0;if(h.type!=="CallExpression")return!1;let w=h.callee;if(w.type==="MemberExpression"&&w.object.name==="React"&&w.property!=null&&!w.computed&&(w=w.property),w.type!=="Identifier")return!1;let E=m.node.id,{name:O}=w;if(O==="useRef"&&E.type==="Identifier")return!0;if(Tn(w)&&E.type==="Identifier"){for(let P of p.references)P!==E&&I.add(P.identifier);return!0}else if(O==="useState"||O==="useReducer"){if(E.type==="ArrayPattern"&&E.elements.length===2&&A(p.identifiers)){if(E.elements[1]===p.identifiers[0]){if(O==="useState"){let P=p.references,z=0;for(let J=0;J<P.length;J++){if(P[J].isWrite()&&z++,z>1)return!1;o.set(P[J].identifier,E.elements[0])}}return!0}else if(E.elements[0]===p.identifiers[0]){if(O==="useState"){let P=p.references;for(let z=0;z<P.length;z++)i.add(P[z].identifier)}return!1}}}else if(O==="useTransition"&&E.type==="ArrayPattern"&&E.elements.length===2&&Array.isArray(p.identifiers)&&E.elements[1]===p.identifiers[0])return!0;return!1}function K(p){if(!A(p.defs))return!1;let m=p.defs[0];if(m==null||m.node==null||m.node.id==null)return!1;let h=m.node,S=_.childScopes,w=null,E;for(E=0;E<S.length;E++){let O=S[E],P=O.block;if(h.type==="FunctionDeclaration"&&P===h||h.type==="VariableDeclarator"&&P.parent===h){w=O;break}}if(w==null)return!1;for(E=0;E<w.through.length;E++){let O=w.through[E];if(O.resolved!=null&&k.has(O.resolved.scope)&&!Ye(O.resolved))return!1}return!0}let Ye=x(W,f),Ut=x(K,T),Ve=new Map;function Yt(p){let m=p.from,h=!1;for(;m.block!==g;)m.type==="function"&&(h=m.block.parent!=null&&m.block.parent.type==="ReturnStatement"),m=m.upper;return h}let V=new Map,ue=new Map;ze(R);function ze(p){for(let m of p.references){if(!m.resolved||!k.has(m.resolved.scope))continue;let h=we(g,m.identifier),S=ot(h),w=G(S,ue);if(C&&S.type==="Identifier"&&(S.parent.type==="MemberExpression"||S.parent.type==="OptionalMemberExpression")&&!S.parent.computed&&S.parent.property.type==="Identifier"&&S.parent.property.name==="current"&&Yt(m)&&Ve.set(w,{reference:m,dependencyNode:S}),S.parent.type==="TSTypeQuery"||S.parent.type==="TSTypeReference")continue;let E=m.resolved.defs[0];if(E!=null&&!(E.node!=null&&E.node.init===g.parent)&&E.type!=="TypeParameter")if(V.has(w))V.get(w).references.push(m);else{let O=m.resolved,P=Ye(O)||Ut(O);V.set(w,{isStable:P,references:[m]})}}for(let m of p.childScopes)ze(m)}Ve.forEach(({reference:p,dependencyNode:m},h)=>{let S=p.resolved.references,w=!1;for(let E=0;E<S.length;E++){let{identifier:O}=S[E],{parent:P}=O;if(P!=null&&P.type==="MemberExpression"&&!P.computed&&P.property.type==="Identifier"&&P.property.name==="current"&&P.parent.type==="AssignmentExpression"&&P.parent.left===P){w=!0;break}}w||a({node:m.parent.property,message:`The ref value '${h}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${h}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let fe=new Set;function Vt(p,m){fe.has(m)||(fe.add(m),a({node:p,message:`Assignments to the '${m}' variable from inside React Hook ${n(v)} 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(v)}.`}))}let oe=new Set;if(V.forEach(({isStable:p,references:m},h)=>{p&&oe.add(h),m.forEach(S=>{S.writeExpr&&Vt(S.writeExpr,h)})}),fe.size>0)return;if(!D){let p=null;if(V.forEach(({isStable:m,references:h},S)=>{p||h.forEach(w=>{if(p)return;let E=w.identifier;if(!o.has(E))return;let P=w.from;for(;P.type!=="function";)P=P.upper;P.block===g&&(p=S)})}),p){let{suggestedDependencies:m}=be({dependencies:V,declaredDependencies:[],stableDependencies:oe,externalDependencies:new Set,isEffect:!0});a({node:v,message:`React Hook ${y} contains a call to '${p}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+m.join(", ")+`] as a second argument to the ${y} Hook.`,suggest:[{desc:`Add dependencies array: [${m.join(", ")}]`,fix(h){return h.insertTextAfter(g,`, [${m.join(", ")}]`)}}]})}return}let ie=[],se=new Set;D.type!=="ArrayExpression"?a({node:D,message:`React Hook ${n(v)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):D.elements.forEach(p=>{if(p===null)return;if(p.type==="SpreadElement"){a({node:p,message:`React Hook ${n(v)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}I.has(p)&&a({node:p,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(p)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(p)}\``,fix(w){return w.removeRange(p.range)}}]});let m;try{m=G(p,ue)}catch(w){if(/Unsupported node type/.test(w.message)){p.type==="Literal"?V.has(p.value)?a({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. Did you mean to include ${p.value} in the array instead?`}):a({node:p,message:`The ${p.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):a({node:p,message:`React Hook ${n(v)} 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 h=p;for(;h.type==="MemberExpression"||h.type==="OptionalMemberExpression"||h.type==="ChainExpression";)h=h.object||h.expression.object;let S=!_.through.some(w=>w.identifier===h);ie.push({key:m,node:p}),S||se.add(m)});let{suggestedDependencies:zt,unnecessaryDependencies:ae,missingDependencies:Z,duplicateDependencies:qe}=be({dependencies:V,declaredDependencies:ie,stableDependencies:oe,externalDependencies:se,isEffect:C}),le=zt;if(qe.size+Z.size+ae.size===0){if(t)return;yn({declaredDependencies:ie,declaredDependenciesNode:D,componentScope:_,scope:R}).forEach(({construction:m,isUsedOutsideOfHook:h,depType:S})=>{let w=S==="function"?"useCallback":"useMemo",E=S==="function"?"definition":"initialization",O=`wrap the ${E} of '${m.name.name}' in its own ${w}() Hook.`,P=h?`To fix this, ${O}`:`Move it inside the ${y} callback. Alternatively, ${O}`,z=S==="conditional"||S==="logical expression"?"could make":"makes",J=`The '${m.name.name}' ${S} ${z} the dependencies of ${y} Hook (at line ${D.loc.start.line}) change on every render. ${P}`,Be;h&&m.type==="Variable"&&S==="function"&&(Be=[{desc:`Wrap the ${E} of '${m.name.name}' in its own ${w}() Hook.`,fix(Ke){let[Bt,Kt]=w==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Ke.insertTextBefore(m.node.init,Bt),Ke.insertTextAfter(m.node.init,Kt)]}}]),a({node:m.node,message:J,suggest:Be})});return}!C&&Z.size>0&&(le=be({dependencies:V,declaredDependencies:[],stableDependencies:oe,externalDependencies:se,isEffect:C}).suggestedDependencies);function qt(){if(ie.length===0)return!0;let p=ie.map(h=>h.key),m=p.slice().sort();return p.join(",")===m.join(",")}qt()&&le.sort();function me(p){let m=p.split("."),h="";for(let S=0;S<m.length;S++){if(S!==0){let w=m.slice(0,S+1).join("."),E=ue.get(w)===!0;h+=E?"?.":"."}h+=m[S]}return h}function de(p,m,h,S){return p.size===0?null:(p.size>1?"":m+" ")+h+" "+(p.size>1?"dependencies":"dependency")+": "+hn(Array.from(p).sort().map(w=>"'"+me(w)+"'"))+`. Either ${S} ${p.size>1?"them":"it"} or remove the dependency array.`}let B="";if(ae.size>0){let p=null;if(Array.from(ae.keys()).forEach(m=>{p===null&&m.endsWith(".current")&&(p=m)}),p!==null)B=` Mutable values like '${p}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(se.size>0){let m=Array.from(se)[0];R.set.has(m)||(B=` Outer scope values like '${m}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!B&&Z.has("props")){let p=V.get("props");if(p==null)return;let m=p.references;if(!Array.isArray(m))return;let h=!0;for(let S=0;S<m.length;S++){let w=m[S],E=we(_.block,w.identifier);if(!E){h=!1;break}let O=E.parent;if(O==null){h=!1;break}if(O.type!=="MemberExpression"&&O.type!=="OptionalMemberExpression"){h=!1;break}}h&&(B=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${y} call and refer to those specific props inside ${n(v)}.`)}if(!B&&Z.size>0){let p=null;Z.forEach(m=>{if(p)return;let h=_.set.get(m),S=V.get(m);if(S.references[0].resolved!==h)return;let w=h.defs[0];if(w==null||w.name==null||w.type!=="Parameter")return;let E=!1,O;for(let P=0;P<S.references.length;P++)if(O=S.references[P].identifier,O!=null&&O.parent!=null&&(O.parent.type==="CallExpression"||O.parent.type==="OptionalCallExpression")&&O.parent.callee===O){E=!0;break}E&&(p=m)}),p!==null&&(B=` If '${p}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!B&&Z.size>0){let p=null;if(Z.forEach(m=>{if(p!==null)return;let S=V.get(m).references,w,E;for(let O=0;O<S.length;O++){for(w=S[O].identifier,E=w.parent;E!=null&&E!==_.block;){if(E.type==="CallExpression"){let P=o.get(E.callee);if(P!=null){if(P.name===m)p={missingDep:m,setter:E.callee.name,form:"updater"};else if(i.has(w))p={missingDep:m,setter:E.callee.name,form:"reducer"};else{let z=S[O].resolved;if(z!=null){let J=z.defs[0];J!=null&&J.type==="Parameter"&&(p={missingDep:m,setter:E.callee.name,form:"inlineReducer"})}}break}}E=E.parent}if(p!==null)break}}),p!==null)switch(p.form){case"reducer":B=` You can also replace multiple useState variables with useReducer if '${p.setter}' needs the current value of '${p.missingDep}'.`;break;case"inlineReducer":B=` If '${p.setter}' needs the current value of '${p.missingDep}', you can also switch to useReducer instead of useState and read '${p.missingDep}' in the reducer.`;break;case"updater":B=` You can also do a functional update '${p.setter}(${p.missingDep.slice(0,1)} => ...)' if you only need '${p.missingDep}' in the '${p.setter}' call.`;break;default:throw new Error("Unknown case.")}}a({node:D,message:`React Hook ${n(v)} has `+(de(Z,"a","missing","include")||de(ae,"an","unnecessary","exclude")||de(qe,"a","duplicate","omit"))+B,suggest:[{desc:`Update the dependencies array to be: [${le.map(me).join(", ")}]`,fix(p){return p.replaceText(D,`[${le.map(me).join(", ")}]`)}}]})}function b(g){let D=gn(g.callee,c);if(D===-1)return;let v=g.arguments[D],y=g.callee,C=at(y).name,R=g.arguments[D+1],k=/Effect($|[^a-z])/g.test(C);if(!v){a({node:y,message:`React Hook ${C} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!k)){if(!R&&!k){(C==="useMemo"||C==="useCallback")&&a({node:y,message:`React Hook ${C} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(v.type){case"FunctionExpression":case"ArrowFunctionExpression":d(v,R,y,C,k);return;case"Identifier":if(!R||R.elements&&R.elements.some(W=>W&&W.type==="Identifier"&&W.name===v.name))return;let _=r(g).set.get(v.name);if(_==null||_.defs==null)return;let A=_.defs[0];if(!A||!A.node||A.type!=="Variable"&&A.type!=="FunctionName")break;switch(A.node.type){case"FunctionDeclaration":d(A.node,R,y,C,k);return;case"VariableDeclarator":let W=A.node.init;if(!W)break;switch(W.type){case"ArrowFunctionExpression":case"FunctionExpression":d(W,R,y,C,k);return}break}break;default:a({node:y,message:`React Hook ${C} received a function whose dependencies are unknown. Pass an inline function instead.`});return}a({node:y,message:`React Hook ${C} has a missing dependency: '${v.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${v.name}]`,fix(_){return _.replaceText(R,`[${v.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let g of e.sourceCode.getAllComments())if(dn.test(g.value))return t=!0,{CallExpression:D=>b(D,!0)}}return{CallExpression:g=>b(g)}}};function be({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:l}){let u=c();function c(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((d,b)=>{let g=a(u,b);g.isUsed=!0,s(u,b,D=>{D.isSubtreeUsed=!0})}),t.forEach(({key:d})=>{let b=a(u,d);b.isSatisfiedRecursively=!0}),n.forEach(d=>{let b=a(u,d);b.isSatisfiedRecursively=!0});function a(d,b){let g=b.split("."),D=d;for(let v of g){let y=D.children.get(v);y||(y=c(),D.children.set(v,y)),D=y}return D}function s(d,b,g){let D=b.split("."),v=d;for(let y of D){let C=v.children.get(y);if(!C)return;g(C),v=C}}let o=new Set,i=new Set;f(u,o,i,d=>d);function f(d,b,g,D){d.children.forEach((v,y)=>{let C=D(y);if(v.isSatisfiedRecursively){v.isSubtreeUsed&&g.add(C);return}if(v.isUsed){b.add(C);return}f(v,b,g,R=>C+"."+R)})}let T=[],I=new Set,x=new Set;return t.forEach(({key:d})=>{i.has(d)?T.indexOf(d)===-1?T.push(d):x.add(d):I.add(d)}),o.forEach(d=>{T.push(d)}),{suggestedDependencies:T,unnecessaryDependencies:I,duplicateDependencies:x,missingDependencies:o}}function ee(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 ee(e.consequent)!=null||ee(e.alternate)!=null?"conditional":null;case"LogicalExpression":return ee(e.left)!=null||ee(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return ee(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return ee(e.expression);case"TSAsExpression":return ee(e.expression)}return null}function yn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let l=e.map(({key:c})=>{let a=n.variables.find(o=>o.name===c);if(a==null)return null;let s=a.defs[0];if(s==null)return null;if(s.type==="Variable"&&s.node.type==="VariableDeclarator"&&s.node.id.type==="Identifier"&&s.node.init!=null){let o=ee(s.node.init);if(o!=null)return[a,o]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[a,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[a,"class"]:null}).filter(Boolean);function u(c){let a=!1;for(let s=0;s<c.references.length;s++){let o=c.references[s];if(o.writeExpr){if(a)return!0;a=!0;continue}let i=o.from;for(;i!==r&&i!=null;)i=i.upper;if(i!==r&&!lt(t,o.identifier))return!0}return!1}return l.map(([c,a])=>({construction:c.defs[0],depType:a,isUsedOutsideOfHook:u(c)}))}function ot(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)?ot(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function Ie(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function G(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=G(e.object,t),r=G(e.property,null),l=`${n}.${r}`;return Ie(e,t,l),l}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=G(e.object,t),r=G(e.property,null),l=`${n}.${r}`;return Ie(e,t,l),l}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=G(n.object,t),l=G(n.property,null),u=`${r}.${l}`;return Ie(n,t,u),u}else throw new Error(`Unsupported node type: ${e.type}`)}function at(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function gn(e,t){let n=at(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=G(n,null)}catch(l){if(/Unsupported node type/.test(l.message))return 0;throw l}return t.additionalHooks.test(r)?0:-1}else return-1}}function we(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Sn(r,t))return r;if(lt(r,t))for(let[l,u]of Object.entries(r))l!=="parent"&&(it(u)?(u.parent=r,n.push(u)):Array.isArray(u)&&u.forEach(c=>{it(c)&&(c.parent=r,n.push(c))}))}return null}function hn(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 Sn(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 lt(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Tn(e){return!1}import{AST_NODE_TYPES as En,ESLintUtils as xn}from"@typescript-eslint/utils";var bn=xn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ct="no-call-with-explicit-generics",In=j({functions:Y(L())}),wn=bn({name:ct,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:[In]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:l}=r;l.type===En.Identifier&&n.has(l.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:l.name}})}}}}),Ce={name:ct,rule:wn};import{AST_NODE_TYPES as ce,ESLintUtils as Cn}from"@typescript-eslint/utils";var Rn=Cn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),pt="no-call-with-inferred-generics",vn=Rn({name:pt,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:l}=r;if(l.type!==ce.Identifier)return;let u=n.get(l.name);if(!u)return;let{minGenerics:c=1,allowAny:a,disallowTypes:s=t.disallowTypes}=u;(r.typeArguments?.params.length||0)<(c||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:l.name,minGenerics:c||0}}),!(a&&!s)&&r.typeArguments?.params?.some(i=>!a&&i.type===ce.TSAnyKeyword||s&&i.type===ce.TSTypeReference&&i.typeName.type===ce.Identifier&&s.includes(i.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:l.name}})}}}}),Re={name:pt,rule:vn};import{ESLintUtils as kn,TSESTree as ut}from"@typescript-eslint/utils";var An=kn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ft="no-commented-out-code",On=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Pn=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Dn=An({name:ft,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 l of On)if(r.startsWith(l))return{wrongPattern:l};for(let l of Pn)if(typeof l=="string"){if(n.includes(l))return{wrongPattern:l}}else if(l.test(n))return{wrongPattern:`regex(${l.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let l of r)if(l.type===ut.AST_TOKEN_TYPES.Line||l.type===ut.AST_TOKEN_TYPES.Block){let u=t(l.value);u&&e.report({node:l,messageId:"commentedOutCode",data:{wrongPattern:u.wrongPattern}})}}}}}),ve={name:ft,rule:Dn};import{ESLintUtils as _n,TSESTree as $n}from"@typescript-eslint/utils";var Nn=_n.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),mt="no-default-export",Ln=Nn({name:mt,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===$n.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),ke={name:mt,rule:Ln};import{ESLintUtils as Mn}from"@typescript-eslint/utils";var jn=Mn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),dt="no-leaked-text-in-jsx",Fn=[",",";","[","]","(",")"],Wn=jn({name:dt,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="";Fn.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Ae={name:dt,rule:Wn};import{AST_NODE_TYPES as ne,ESLintUtils as Hn}from"@typescript-eslint/utils";var Un=Hn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),gt="no-non-camel-case-functions",Yn=/^[a-z][a-zA-Z0-9]*$/;function yt(e){return e.typeName.type===ne.TSQualifiedName&&e.typeName.left.type===ne.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===ne.Identifier&&e.typeName.right.name==="Element"}var Vn=Un({name:gt,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&&!Yn.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ne.TSTypeReference?yt(n):n.type===ne.TSUnionType&&n.types.some(l=>l.type===ne.TSTypeReference&&yt(l))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Oe={name:gt,rule:Vn};import{ESLintUtils as zn,TSESTree as F}from"@typescript-eslint/utils";function re(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:re(e.parent,t,n===1/0?n:n-1)}function*Pe(e){yield e,e.parent&&(yield*Pe(e.parent))}var qn=zn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ht="no-optional-root-props",Bn=qn({name:ht,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(l){return l?l.parent?.type===F.AST_NODE_TYPES.ExportNamedDeclaration||l.parent?.type===F.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function n(l){let c=e.sourceCode.getDeclaredVariables(l)[0];if(!c||c.references.length!==1)return!1;let a=c.references[0];if(!a)return!1;for(let s of Pe(a.identifier)){if("returnType"in s||s.type===F.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let o=s.parent;if(!o)return!1;if(o.type===F.AST_NODE_TYPES.TSTypeParameterInstantiation&&o.parent.type===F.AST_NODE_TYPES.TSTypeReference&&o.parent.typeName.type===F.AST_NODE_TYPES.Identifier&&o.parent.typeName.name==="FC"){let f=re(o.parent.parent,F.AST_NODE_TYPES.VariableDeclaration,4);if(f)return!(t(f)||e.sourceCode.getScope(f).references.some(I=>t(I.identifier.parent.parent)))}if(s.type===F.AST_NODE_TYPES.AssignmentPattern)return!1;if(o.type===F.AST_NODE_TYPES.ArrowFunctionExpression){let i=re(o,F.AST_NODE_TYPES.VariableDeclaration);return i&&t(i)||i&&e.sourceCode.getScope(i).references.some(T=>T.identifier.parent.parent?.parent?.type===F.AST_NODE_TYPES.ExportNamedDeclaration)?!1:o.params.some(f=>f===s)}if(o.type===F.AST_NODE_TYPES.FunctionDeclaration)return t(o)||e.sourceCode.getScope(o).upper?.references.some(f=>t(f.identifier.parent.parent))?!1:o.params.some(f=>f===s)}return!1}function r(l){l.key.type!==F.AST_NODE_TYPES.Identifier||!l.optional||e.report({node:l.key,messageId:"optionalNotAllowed",data:{propertyName:l.key.name},suggest:[{messageId:"suggestion",fix:u=>{let c=re(l,F.AST_NODE_TYPES.TSPropertySignature);if(!c)return null;let a=e.sourceCode.getText(c);return u.replaceText(c,a.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(l){if(l.typeAnnotation.type===F.AST_NODE_TYPES.TSTypeLiteral&&!(t(l)||!n(l)))for(let u of l.typeAnnotation.members)u.type===F.AST_NODE_TYPES.TSPropertySignature&&r(u)},TSInterfaceDeclaration(l){if(!(t(l)||!n(l)))for(let u of l.body.body)u.type===F.AST_NODE_TYPES.TSPropertySignature&&r(u)},TSTypeReference(l){if(l.typeName.type!==F.AST_NODE_TYPES.Identifier||l.typeName.name!=="FC"||!l.typeArguments?.params[0])return;let u=l.typeArguments.params[0];if(u.type!==F.AST_NODE_TYPES.TSTypeLiteral)return;let c=re(l.parent,F.AST_NODE_TYPES.VariableDeclaration,4);if(!c||t(c)||e.sourceCode.getScope(c).references.some(i=>i.identifier.parent.parent?.parent?.type===F.AST_NODE_TYPES.ExportNamedDeclaration))return;let s=c.declarations[0].id.type===F.AST_NODE_TYPES.Identifier?c.declarations[0].id:null,o=e.sourceCode.getScope(c).variables.find(i=>i.name===s?.name)?.references.filter(i=>i.identifier!==s);if(!(o&&o.length>1))for(let i of u.members)i.type===F.AST_NODE_TYPES.TSPropertySignature&&r(i)}}}}),De={name:ht,rule:Bn};import{ESLintUtils as Kn}from"@typescript-eslint/utils";import _e from"node:path";var Xn=Kn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),St="no-relative-imports",Jn=j({find:L(),replacement:L()}),Gn=j({aliases:Y(Jn),rootDir:$(L()),allowNotFoundAliases:$(te()),_dev_simulateFileName:$(L())}),Zn=Xn({name:St,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:[Gn]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(c){return c.startsWith(".")||c.startsWith("..")}function l(c,a){let s=_e.dirname(a);return _e.resolve(s,c)}function u(c){let a=t.rootDir??process.cwd(),s=_e.relative(a,c);if(s.startsWith("."))return null;s.startsWith("/")||(s=`/${s}`);for(let{find:o,replacement:i}of t.aliases)if(s.startsWith(i)){let f=s.replace(i,o);return{alias:o,newPath:f}}return null}return{ImportDeclaration(c){let a=c.source.value;if(!r(a))return;let s=l(a,n),o=u(s);!o&&t.allowNotFoundAliases||e.report({node:c,messageId:o?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:o?.alias},fix:o?i=>i.replaceText(c.source,`'${o.newPath}'`):void 0})}}}}),$e={name:St,rule:Zn};import{AST_NODE_TYPES as N,ESLintUtils as Qn}from"@typescript-eslint/utils";var er=Qn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Tt(e){let t=[];for(let n of e.members)n.type===N.TSPropertySignature&&n.key.type===N.Identifier&&t.push([n.key.name,n]);return t}function Et(e,...t){for(let n of t)e.set(...n);return e}var tr=j({forceCheckOnFCPropTypesWithName:$(Y(L()))}),xt="no-unused-type-props-in-args",Ne=null,nr=er({name:xt,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:[tr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!Ne&&(Ne=n.map(a=>new RegExp(a)));function r(a,s,o,i,f=!0){let T=o.name,I=e.sourceCode.getScope(s).references.find(b=>b.identifier.name===T)?.resolved,x=a&&Ne?.some(b=>b.test(T));if(!I||!x&&I.references.filter(b=>b.isTypeReference).length>1)return;let d=I?.defs[0]?.node;if(!(f&&d?.parent?.type===N.ExportNamedDeclaration)){if(d?.type===N.TSTypeAliasDeclaration){l(a,s,i,d.typeAnnotation,!0);return}if(d?.type===N.TSInterfaceDeclaration){l(a,s,i,d.body,!0);return}}}function l(a,s,o,i,f){if(i.type===N.TSInterfaceBody){for(let T of i.body)T.type===N.TSPropertySignature&&T.key.type===N.Identifier&&o.set(T.key.name,T);return}if(i.type===N.TSTypeLiteral){Et(o,...Tt(i));return}if(i.type===N.TSIntersectionType){for(let T of i.types)l(a,s,o,T,!0);return}f||i.type===N.TSTypeReference&&i.typeName.type===N.Identifier&&r(a,s,i.typeName,o)}function u(a,s,o){for(let i of o)if(i.type==="ObjectPattern"&&i.typeAnnotation){let f=new Map;if(l(a,s,f,i.typeAnnotation.typeAnnotation,!1),f.size===0)continue;c(i,f)}else i.type===N.AssignmentPattern&&i.left.type===N.ObjectPattern&&u(a,s,[i.left])}function c(a,s){let o=[];if(a.properties.at(-1)?.type===N.RestElement)return;for(let I of a.properties)I.type===N.Property&&I.key.type===N.Identifier&&o.push(I.key.name);let f=[],T=[];for(let[I,x]of s)o.includes(I)||(T.push(I),f.push({node:x,messageId:"unusedObjectTypeProperty",data:{propertyName:I}}));for(let[I,x]of f.entries())e.report({...x,fix:I===f.length-1?d=>{let b=a.properties.at(-1),g=T.join(", ");return b?b?.type===N.RestElement?null:d.insertTextAfter(b,`, ${g}`):d.insertTextBeforeRange([a.range[0]+1,a.range[1]],`${g}`)}:void 0})}return{VariableDeclaration(a){let s=a.declarations[0];if(!s)return;let o=new Map,i=s.id.type===N.Identifier&&s.id.typeAnnotation?.typeAnnotation.type===N.TSTypeReference&&s.id.typeAnnotation.typeAnnotation.typeName.type===N.Identifier&&s.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&s.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(i){if(i.type===N.TSTypeReference&&i.typeName.type===N.Identifier)r(!0,a,i.typeName,o,!1);else if(i.type===N.TSTypeLiteral)Et(o,...Tt(i));else if(i.type===N.TSIntersectionType)for(let f of i.types)f.type===N.TSTypeReference&&f.typeName.type===N.Identifier?r(!0,a,f.typeName,o,!1):l(!0,a,o,f,!0);if(o.size!==0&&s.init?.type===N.ArrowFunctionExpression){let f=s.init.params[0];if(!f){e.report({node:s.init,messageId:"missingComponentParam"});return}f.type===N.ObjectPattern&&c(f,o)}}},FunctionDeclaration:function(a){u(!1,a,a.params)},ArrowFunctionExpression(a){u(!1,a,a.params)}}}}),Le={name:xt,rule:nr};import{AST_NODE_TYPES as Me,ESLintUtils as rr}from"@typescript-eslint/utils";var ir=rr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),It="prefer-named-functions",bt=new Map,sr=ir({name:It,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=bt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),bt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===Me.ArrowFunctionExpression&&r.id.type===Me.Identifier){let l=r.id.name;if(r.id.typeAnnotation||n&&n.test(l)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==Me.BlockStatement)return;let u=r.parent,c=r.init.params,a=r.init.body,s=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:l,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:o=>o.replaceText(u,`${s.async?"async ":""}function ${l}(${c.map(i=>e.sourceCode.getText(i)).join(", ")||""}) ${e.sourceCode.getText(a)}`)}]})}}}}}),je={name:It,rule:sr};import{AST_NODE_TYPES as H,AST_TOKEN_TYPES as wt,ESLintUtils as or}from"@typescript-eslint/utils";var ar=or.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Rt="prefer-single-line-if",lr=j({maxLineLength:$(X()),maxNonSimpleConditionLength:$(X())}),cr=ar({name:Rt,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:[lr]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==H.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let u=r.consequent.body[0];if(u.type===H.ReturnStatement){if(!kt(u))return}else if(!(u.type===H.ContinueStatement||u.type===H.BreakStatement||u.type===H.ExpressionStatement&&ur(u)))return;if(r.test.type===H.LogicalExpression||r.test.type===H.ConditionalExpression)return;let c;if(t.maxNonSimpleConditionLength){let f=Ct(r.test);if(!f&&r.test.type===H.UnaryExpression&&r.test.operator==="!"){let T=r.test.argument;Ct(T)&&(f=!0)}if(f&&(c=n.getText(r.test),c.length>t.maxNonSimpleConditionLength))return}c||(c=n.getText(r.test));let a=n.getText(u);if(c.includes(`
|
|
14
|
+
`))return;let s=n.getTokenAfter(r);if(s&&s.type===wt.Punctuator&&s.value==="}"){let f=n.getTokenAfter(s);if(f&&f.type===wt.Keyword&&(f.value==="else"||f.value==="catch"))return}let o=pr(n,r),i=`if (${c}) ${a}`;t.maxLineLength&&i.length+o.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:f=>f.replaceText(r,i)})}}}});function Ct(e){return e.type===H.CallExpression||e.type===H.BinaryExpression||e.type===H.MemberExpression&&vt(e)}function vt(e){return e.object.type===H.MemberExpression?vt(e.object):e.object.type!==H.Identifier}function pr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function kt(e){if(!e.argument)return!0;let t=e.argument;return t.type===H.ArrayExpression&&t.elements.length===0||t.type===H.ObjectExpression&&t.properties.length===0||t.type===H.Literal||t.type===H.Identifier||t.type===H.TemplateLiteral||t.type===H.TaggedTemplateExpression?!0:t.type===H.CallExpression?t.arguments.length===0:t.type===H.UnaryExpression?kt(t):!1}function ur(e){return e.expression.type===H.CallExpression?e.expression.arguments.length===0:!1}var Fe={name:Rt,rule:cr};import{AST_NODE_TYPES as q,ESLintUtils as fr}from"@typescript-eslint/utils";var mr=fr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),At="react-compiler-migration",dr=j({disallowHooks:$(Y(j({name:L(),replacement:L()}))),disallowMethods:$(Y(j({name:L(),replacement:$(L()),requireTrueProp:$(L())})))}),yr=/eslint +react-compiler\/react-compiler: +\["error/;function gr(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 hr=mr({name:At,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:[dr]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(yr.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let l=null,u=null;if(r.callee.type===q.Identifier?(l=r.callee.name,u=r.callee):r.callee.type===q.MemberExpression&&r.callee.property.type===q.Identifier&&(l=r.callee.property.name,u=r.callee.property),l){let c=t.disallowHooks.find(a=>a.name===l);c&&u&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:c.name,replacement:c.replacement},suggest:[{messageId:"replace",data:{replacement:c.replacement},fix:a=>a.replaceText(u,c.replacement)}]})}}if(t.disallowMethods?.length&&gr(r.callee)){for(let l of r.arguments)if(l.type===q.ObjectExpression){for(let u of l.properties)if(u.type===q.Property&&u.key.type===q.Identifier){let c=u.key.name,a=t.disallowMethods.find(s=>s.name===c);if(a){if(a.requireTrueProp){let s=a.requireTrueProp,o=!1;for(let i of l.properties)if(i.type===q.Property&&i.key.type===q.Identifier&&i.key.name===s&&i.value.type===q.Literal&&i.value.value===!0){o=!0;break}if(!o){e.report({node:u,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:a.name,requireTrueProp:s}});continue}}a.replacement&&e.report({node:u,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:a.name,replacement:a.replacement},suggest:[{messageId:"replace",data:{replacement:a.replacement},fix:s=>s.replaceText(u.key,a.replacement)}]})}}}}}}:{}}}),We={name:At,rule:hr};import{ESLintUtils as Sr,TSESTree as Tr}from"@typescript-eslint/utils";var Er=Sr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ot="require-description",xr=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,br=/^eslint-disable-(next-)?line$/u,Ir=Er({name:Ot,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 l of n.getAllComments()){let u=wr(l);u!=null&&(r.has(u.kind)||u.description||e.report({loc:Rr(l.loc),messageId:"missingDescription"}))}}}}}),Pt={name:Ot,rule:Ir};function wr(e){let{text:t,description:n}=Cr(e.value);if(!t)return null;let r=xr.exec(t);if(!r)return null;let l=r[1];if(!l)return null;let u=br.test(l);if(e.type===Tr.AST_TOKEN_TYPES.Line&&!u||u&&e.loc.start.line!==e.loc.end.line)return null;let c=t.slice(r.index+l.length);return{kind:l,value:c.trim(),description:n}}function Cr(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Rr(e){return{start:{line:e.start.line,column:-1},end:e.end}}function $t(e){return/^use[A-Z0-9]/.test(e)}function pe(e){return e.type==="Identifier"?$t(e.name):e.type==="MemberExpression"&&!e.computed&&pe(e.property)?e.object.type==="Identifier":!1}function Nt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Lt(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Mt(e){return!!(e.parent&&e.parent.callee&&Lt(e.parent.callee,"forwardRef"))}function jt(e){return!!(e.parent&&e.parent.callee&&Lt(e.parent.callee,"memo"))}function He(e){for(;e;){let t=Wt(e);if(t&&(Nt(t)||pe(t))||Mt(e)||jt(e))return!0;e=e.parent}return!1}function Dt(e){return!1}function Ue(e){return!1}var vr=/eslint +react-compiler\/react-compiler: +\["error/,Ft={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let s of e.sourceCode.getAllComments())if(vr.test(s.value))return{CallExpression(o){let i=null;o.callee.name==="useMemo"?i="useMemo":o.callee.name==="useCallback"&&(i="useCallback"),i&&e.report({node:o,message:`"${i}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?s=>t(s):s=>e.sourceCode.getText(s),n=typeof e.getScope=="function"?()=>n():s=>e.sourceCode.getScope(s),r=null,l=[],u=[],c=new WeakSet;function a(s){for(let o of s.references){let i=o.identifier.parent;if(i.type==="VariableDeclarator"&&i.init&&i.init.type==="CallExpression"&&i.init.callee&&Dt(i.init.callee))for(let f of o.resolved.references)f!==o&&c.add(f.identifier)}}return{onCodePathSegmentStart:s=>u.push(s),onCodePathSegmentEnd:()=>u.pop(),onCodePathStart:()=>l.push(new Map),onCodePathEnd(s,o){let i=l.pop();if(i.size===0)return;let f=new Set;function T(y,C){let{cache:R}=T,k=R.get(y.id),_=new Set(C);if(_.has(y.id)){let A=[..._],W=A.slice(A.indexOf(y.id)+1);for(let K of W)f.add(K);return BigInt("0")}if(_.add(y.id),k!==void 0)return k;if(s.thrownSegments.includes(y))k=BigInt("0");else if(y.prevSegments.length===0)k=BigInt("1");else{k=BigInt("0");for(let A of y.prevSegments)k+=T(A,_)}return y.reachable&&k===BigInt("0")?R.delete(y.id):R.set(y.id,k),k}function I(y,C){let{cache:R}=I,k=R.get(y.id),_=new Set(C);if(_.has(y.id)){let A=Array.from(_),W=A.slice(A.indexOf(y.id)+1);for(let K of W)f.add(K);return BigInt("0")}if(_.add(y.id),k!==void 0)return k;if(s.thrownSegments.includes(y))k=BigInt("0");else if(y.nextSegments.length===0)k=BigInt("1");else{k=BigInt("0");for(let A of y.nextSegments)k+=I(A,_)}return R.set(y.id,k),k}function x(y){let{cache:C}=x,R=C.get(y.id);if(R===null)return 1/0;if(R!==void 0)return R;if(C.set(y.id,null),y.prevSegments.length===0)R=1;else{R=1/0;for(let k of y.prevSegments){let _=x(k);_<R&&(R=_)}R+=1}return C.set(y.id,R),R}T.cache=new Map,I.cache=new Map,x.cache=new Map;let d=I(s.initialSegment),b=Wt(o),g=He(o),D=b?Nt(b)||pe(b):Mt(o)||jt(o),v=1/0;for(let y of s.finalSegments){if(!y.reachable)continue;let C=x(y);C<v&&(v=C)}for(let[y,C]of i){if(!y.reachable)continue;let R=y.nextSegments.length===0?v<=x(y):v<x(y),k=T(y)*I(y),_=f.has(y.id);for(let A of C)if(_&&!Ue(A)&&e.report({node:A,message:`React Hook "${t(A)}" 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.`}),D){if(o.async&&e.report({node:A,message:`React Hook "${t(A)}" cannot be called in an async function.`}),!_&&k!==d&&!Ue(A)){let K=`React Hook "${t(A)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(R?" Did you accidentally call a React Hook after an early return?":"");e.report({node:A,message:K})}}else if(o.parent&&(o.parent.type==="MethodDefinition"||o.parent.type==="ClassProperty")&&o.parent.value===o){let W=`React Hook "${t(A)}" 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:A,message:W})}else if(b){let W=`React Hook "${t(A)}" is called in function "${t(b)}" 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:A,message:W})}else if(o.type==="Program"){let W=`React Hook "${t(A)}" 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:A,message:W})}else if(g&&!Ue(A)){if(o.parent.type==="CallExpression"&&o.parent.callee.type==="Identifier"&&o.parent.callee.name==="useCallback"){let K=o.parent;if(K.parent.type==="VariableDeclarator"&&$t(K.parent.id.name))return}let W=`React Hook "${t(A)}" 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:A,message:W})}}},CallExpression(s){if(pe(s.callee)){let o=_t(l),i=_t(u),f=o.get(i);f||(f=[],o.set(i,f)),f.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Dt(s.callee))&&s.arguments.length>0&&(r=s)},Identifier(s){r==null&&c.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${t(s)}\` is a function created with React Hook "useEffectEvent", and can only be called from the same component. They cannot be assigned to variables or passed down.`})},"CallExpression:exit"(s){s===r&&(r=null)},FunctionDeclaration(s){He(s)&&a(n(s))},ArrowFunctionExpression(s){He(s)&&a(n(s))}}}};function Wt(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 _t(e){return e[e.length-1]}var Ht={[Le.name]:Le.rule,[ve.name]:ve.rule,[Re.name]:Re.rule,"rules-of-hooks":Ft,"exhaustive-deps":st,"require-description":Pt.rule,[ke.name]:ke.rule,[Oe.name]:Oe.rule,[je.name]:je.rule,[Te.name]:Te.rule,[Ce.name]:Ce.rule,[$e.name]:$e.rule,[Fe.name]:Fe.rule,[De.name]:De.rule,[Ae.name]:Ae.rule,[xe.name]:xe.rule,[We.name]:We.rule,[he.name]:he.rule};var Yi={rules:Ht};export{Yi as extendedLintPlugin};
|