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