@ls-stack/extended-lint 0.44.0 → 0.44.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extended-lint.js +4 -4
- package/dist/extended-lint.mjs +4 -4
- package/package.json +1 -1
package/dist/extended-lint.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var Ln=Object.create;var ve=Object.defineProperty;var _n=Object.getOwnPropertyDescriptor;var Mn=Object.getOwnPropertyNames;var $n=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var Vn=(e,t)=>{for(var n in t)ve(e,n,{get:t[n],enumerable:!0})},kt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Mn(t))!Un.call(e,s)&&s!==n&&ve(e,s,{get:()=>t[s],enumerable:!(r=_n(t,s))||r.enumerable});return e};var He=(e,t,n)=>(n=e!=null?Ln($n(e)):{},kt(t||!e||!e.__esModule?ve(n,"default",{value:e,enumerable:!0}):n,e)),Wn=e=>kt(ve({},"__esModule",{value:!0}),e);var Ii={};Vn(Ii,{extendedLintPlugin:()=>xi});module.exports=Wn(Ii);var q=require("@typescript-eslint/utils");var Ye=Symbol.for("optional");function P(e){return{...e,[Ye]:!0}}function ke(e,t){return{enum:e,...t}}function oe(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function Z(e){return{...e,type:"number"}}function ze(e){return{...e,type:"integer"}}function z(e,t){return{...t,type:"array",items:e}}function j(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,s=[];for(r in e)e[r][Ye]?e[r][Ye]=void 0:s.push(r);s.length>0&&(n.required=s)}return n}function Ae(...e){return{anyOf:e}}var Hn=q.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ot="react-compiler-extra",Yn=j({runOnlyWithEnableCompilerDirective:P(oe())}),zn=/eslint +react-compiler\/react-compiler: +\["error/;function Bn(e){return e.type===q.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===q.AST_NODE_TYPES.MemberExpression&&e.property.type===q.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var qn=/\bthis[.[]/;function At(e){return qn.test(e)}var Xn=Hn({name:Ot,meta:{type:"suggestion",fixable:"code",docs:{description:"Extra rules to enforce best practices when using the React compiler"},messages:{objectMethodIsNotSupported:"Object methods such as `{ method() {} }` have limited support to optimizations in the React compiler, use a function expression `{ method: () => {} }` instead.",replaceWithFunctionExpression:"Replace with function expression",thisKeywordInMethod:"Object method uses `this` keyword which would have different behavior if converted to an arrow function. Fix this manually."},hasSuggestions:!0,schema:[Yn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let l of e.sourceCode.getAllComments())if(zn.test(l.value)){n=!0;break}if(!n)return{}}function r(l){for(let o of l.properties)if(o.type===q.AST_NODE_TYPES.Property&&o.method&&o.value.type===q.AST_NODE_TYPES.FunctionExpression){let i=e.sourceCode,a=i.getText(o.key),c=o.value,p=i.getText(c.body);if(At(p))e.report({node:o,messageId:"thisKeywordInMethod"});else{let u=c.params.map(S=>i.getText(S)).join(", "),g="";c.generator?g=`${a}: function* (${u}) ${p}`:g=`${a}: (${u}) => ${p}`,e.report({node:o,messageId:"objectMethodIsNotSupported",fix:S=>S.replaceText(o,g)})}}}function s(l){for(let o of l.properties)if(o.type===q.AST_NODE_TYPES.Property&&o.value.type===q.AST_NODE_TYPES.ObjectExpression){for(let i of o.value.properties)if(i.type===q.AST_NODE_TYPES.Property&&i.method&&i.value.type===q.AST_NODE_TYPES.FunctionExpression){let c=e.sourceCode.getText(i.value.body);At(c)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(l){if(Bn(l.callee))for(let o of l.arguments){if(o.type===q.AST_NODE_TYPES.ObjectExpression&&(r(o),s(o)),o.type===q.AST_NODE_TYPES.ArrowFunctionExpression&&(o.body.type===q.AST_NODE_TYPES.ObjectExpression&&(r(o.body),s(o.body)),o.body.type===q.AST_NODE_TYPES.BlockStatement))for(let i of o.body.body)i.type===q.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===q.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),s(i.argument));if(o.type===q.AST_NODE_TYPES.FunctionExpression)for(let i of o.body.body)i.type===q.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===q.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),s(i.argument))}}}}}),Be={name:Ot,rule:Xn};var Q=require("@typescript-eslint/utils");var Pt=require("@typescript-eslint/utils");function fe(e){let n=Pt.ESLintUtils.RuleCreator(r=>`https://github.com/lucasols/extended-lint#${r}`)(e);return{name:e.name,rule:n}}var Kn=j({disallow:P(z(j({selector:F(),message:F(),replace:P(Ae(F(),j({regex:F(),with:F()}))),replaceType:P(ke(["suggestion","autofix"]))}))),disallowFnCalls:P(z(j({fn:F(),withArgs:P(z(j({atIndex:ze(),value:Ae(F(),Z(),oe())}))),message:F(),replaceWith:P(F()),ignoreRegex:P(F())}))),__dev_simulateFileName:P(F()),mustMatchSyntax:P(z(j({includeRegex:F(),mustCallFn:P(z(j({anyCall:z(j({fn:F(),withArgs:z(j({atIndex:ze(),literal:Ae(F(),Z(),oe())}))})),message:P(F())}))),mustMatchSelector:P(z(j({selector:F(),message:F()})))})))}),qe=fe({name:"advanced-no-restricted-syntax",meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Kn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:s,disallow:l,disallowFnCalls:o}=t,i=s??e.filename,a=[],c=new Map,p=new Set,u=new Map,g=new Map;function S(d){for(let m of d.specifiers)m.type===Q.AST_NODE_TYPES.ImportSpecifier&&m.imported.type===Q.AST_NODE_TYPES.Identifier&&m.local.type===Q.AST_NODE_TYPES.Identifier&&m.imported.name!==m.local.name&&g.set(m.local.name,m.imported.name)}function E(d){d.id.type===Q.AST_NODE_TYPES.Identifier&&d.init?.type===Q.AST_NODE_TYPES.Identifier&&g.set(d.id.name,d.init.name)}function T(d){return g.get(d)??d}function w(d,m){return T(d)===m||d===m}for(let{includeRegex:d,mustCallFn:m,mustMatchSelector:R}of r??[]){let v=Jn(i,new RegExp(d));if(!v)continue;let A=O=>{let x=O;for(let{name:U,value:Y}of v)x=x.replaceAll(U,Y);return x};for(let{anyCall:O,message:x}of m??[]){let U=`Expected file to call the function: ${O.map(({fn:Y})=>Y).join(" or ")}`;p.add(U),a.push(Y=>{let{callee:ie}=Y;if(ie.type===Q.AST_NODE_TYPES.Identifier){for(let{fn:$e,withArgs:xe}of O)if(ie.name===$e){p.delete(U);for(let pe of xe){let X=Y.arguments[pe.atIndex],ne=typeof pe.literal=="string"?A(pe.literal):pe.literal;if(!X){e.report({node:Y,messageId:"default",data:{message:`Missing argument with value "${ne}" at index ${pe.atIndex}${x?`: ${A(x)}`:""}`}});continue}if(X.type!==Q.AST_NODE_TYPES.Literal){e.report({node:X,messageId:"default",data:{message:`Argument at position ${pe.atIndex} should the literal "${ne}"${x?`: ${A(x)}`:""}`}});continue}X.value!==ne&&e.report({node:X,messageId:"default",data:{message:`Argument should have the value "${ne}"${x?`: ${A(x)}`:""}`},fix:Ie=>Ie.replaceText(X,typeof ne=="string"?`'${ne}'`:String(ne))})}break}}})}for(let{selector:O,message:x}of R??[])u.set(O,A(x)),c.set(A(O),()=>{u.delete(O)})}for(let{fn:d,withArgs:m,message:R,replaceWith:v,ignoreRegex:A}of o??[])A&&new RegExp(A).test(i)||a.push(O=>{let{callee:x}=O;if(x.type!==Q.AST_NODE_TYPES.Identifier||!w(x.name,d))return;if(m)for(let Y of m){let ie=O.arguments[Y.atIndex];if(!ie){e.report({node:O,messageId:"default",data:{message:`Missing argument with value "${Y.value}" at index ${Y.atIndex}: ${R}`}});return}if(ie.type!==Q.AST_NODE_TYPES.Literal){e.report({node:ie,messageId:"default",data:{message:`Argument at position ${Y.atIndex} should be the literal "${Y.value}": ${R}`}});return}if(ie.value!==Y.value)return}let U=Y=>v?Y.replaceText(O,v):null;e.report({node:O,messageId:"default",data:{message:R},suggest:v?[{messageId:"default",data:{message:`Replace with "${v}"`},fix:U}]:void 0})});function h(d,m){let R=n[d];R?n[d]=v=>{R(v),m(v)}:n[d]=m}for(let{selector:d,message:m,replace:R,replaceType:v="suggestion"}of l??[]){if(d==="CallExpression"){a.push(A=>{_(R,A,m,v)});continue}n[d]=A=>{_(R,A,m,v)}}if(c.size>0)for(let[d,m]of c)h(d,m);return a.length>0&&(n.CallExpression=d=>{if(d.type===Q.AST_NODE_TYPES.CallExpression)for(let m of a)m(d)}),n.ImportDeclaration=d=>{d.type===Q.AST_NODE_TYPES.ImportDeclaration&&S(d)},n.VariableDeclarator=d=>{d.type===Q.AST_NODE_TYPES.VariableDeclarator&&E(d)},n["Program:exit"]=d=>{for(let m of p)e.report({node:d,messageId:"default",data:{message:m}});for(let[,m]of u)e.report({node:d,messageId:"default",data:{message:m}})},n;function _(d,m,R,v){let A=O=>{if(!d)return null;if(typeof d=="string")return O.replaceText(m,d);{let x=new RegExp(d.regex),U=e.sourceCode.getText(m);return O.replaceText(m,U.replace(x,d.with))}};e.report({node:m,messageId:"default",data:{message:R},fix:d&&v==="autofix"?A:void 0,suggest:d&&v==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof d=="string"?d:d.with}"`},fix:A}]:void 0})}}});function Jn(e,t){let n=[],r=t.exec(e);if(!r)return null;let[s,...l]=r;n.push({name:"$0_lowercase",value:s.toLowerCase()}),n.push({name:"$0_capitalize",value:Ft(s)}),n.push({name:"$0_uncapitalize",value:Nt(s)}),n.push({name:"$0",value:s});for(let o=0;o<l.length;o++){let i=`$${o+1}`,a=l[o];n.push({name:`${i}_lowercase`,value:a.toLowerCase()}),n.push({name:`${i}_capitalize`,value:Ft(a)}),n.push({name:`${i}_uncapitalize`,value:Nt(a)}),n.push({name:i,value:a})}return n}function Ft(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Nt(e){return e.charAt(0).toLowerCase()+e.slice(1)}var M=require("@typescript-eslint/utils");var Gn=M.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),jt="collapse-simple-objs-in-one-line",Zn=j({maxLineLength:P(Z()),maxProperties:P(Z()),nestedObjMaxLineLength:P(Z()),nestedObjMaxProperties:P(Z()),ignoreTypesWithSuffix:P(z(F()))}),Qn=Gn({name:jt,meta:{type:"suggestion",fixable:"code",docs:{description:"Format simple objects and types in one line"},messages:{singleLineProp:"Object/type should be written in a single line"},schema:[Zn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],s=t.maxProperties??2,l=t.nestedObjMaxLineLength??t.maxLineLength,o=t.nestedObjMaxProperties??3;function i(c){if(c.type===M.AST_NODE_TYPES.ObjectExpression){let p=c.parent.type===M.AST_NODE_TYPES.Property,u=p?o:s,g=c.properties.length;if(g>u)return!1;if(g===1){let E=c.properties[0];return E.type===M.AST_NODE_TYPES.Property&&E.value.type===M.AST_NODE_TYPES.ObjectExpression||E.type===M.AST_NODE_TYPES.Property&&E.value.type===M.AST_NODE_TYPES.ArrayExpression&&!E.value.elements.every(w=>w&&Xe(w))?!1:{text:n.getText(E),isNested:p,propsSize:g}}let S=[];for(let E of c.properties){if(E.type===M.AST_NODE_TYPES.Property&&!Xe(E.value))return!1;S.push(n.getText(E))}return{text:S.join(", "),isNested:p,propsSize:g}}else{let p=c.parent.parent?.type===M.AST_NODE_TYPES.TSPropertySignature,u=p?o:s,g=c.members.length;if(g>u)return!1;if(r.length>0&&c.parent.type===M.AST_NODE_TYPES.TSTypeAliasDeclaration){let E=c.parent.id.name;if(r.some(T=>E.endsWith(T)))return!1}if(g===1){let E=c.members[0];return E.type===M.AST_NODE_TYPES.TSPropertySignature&&E.typeAnnotation?.typeAnnotation.type===M.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(E),isNested:p,propsSize:1}}if(c.parent.type===M.AST_NODE_TYPES.TSIntersectionType||c.parent.type===M.AST_NODE_TYPES.TSUnionType)return!1;let S=[];for(let E of c.members){if(E.type!==M.AST_NODE_TYPES.TSPropertySignature)return!1;let T=E.typeAnnotation?.typeAnnotation;if(!T||T.type===M.AST_NODE_TYPES.TSTypeLiteral||!Dt(T))return!1;if(T.type===M.AST_NODE_TYPES.TSTypeReference&&T.typeArguments){if(T.typeArguments.params.length>1)return!1;let h=T.typeArguments.params[0];if(!Dt(h))return!1}let w=n.getText(E).trim();(w.endsWith(";")||w.endsWith(","))&&(w=w.slice(0,-1)),S.push(w)}return{text:S.join("; "),isNested:p,propsSize:g}}}function a(c){if(c.loc.start.line===c.loc.end.line)return;if(c.parent.type!==M.AST_NODE_TYPES.JSXExpressionContainer){let T=0,w=n.getTokenAfter(c,{filter:h=>h.type!==M.AST_TOKEN_TYPES.Punctuator?!0:h.value===","||h.value===";"||h.value===")"||h.value==="}"?(T++,!1):!0});if(T>4||w?.loc.start.line===c.loc.end.line)return}let p=i(c);if(!p)return;let u=p.text;if(u.includes(`
|
|
1
|
+
"use strict";var Ln=Object.create;var ve=Object.defineProperty;var _n=Object.getOwnPropertyDescriptor;var Mn=Object.getOwnPropertyNames;var $n=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var Vn=(e,t)=>{for(var n in t)ve(e,n,{get:t[n],enumerable:!0})},kt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Mn(t))!Un.call(e,s)&&s!==n&&ve(e,s,{get:()=>t[s],enumerable:!(r=_n(t,s))||r.enumerable});return e};var He=(e,t,n)=>(n=e!=null?Ln($n(e)):{},kt(t||!e||!e.__esModule?ve(n,"default",{value:e,enumerable:!0}):n,e)),Wn=e=>kt(ve({},"__esModule",{value:!0}),e);var Ii={};Vn(Ii,{extendedLintPlugin:()=>xi});module.exports=Wn(Ii);var q=require("@typescript-eslint/utils");var Ye=Symbol.for("optional");function P(e){return{...e,[Ye]:!0}}function ke(e,t){return{enum:e,...t}}function oe(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function Z(e){return{...e,type:"number"}}function ze(e){return{...e,type:"integer"}}function Y(e,t){return{...t,type:"array",items:e}}function j(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,s=[];for(r in e)e[r][Ye]?e[r][Ye]=void 0:s.push(r);s.length>0&&(n.required=s)}return n}function Ae(...e){return{anyOf:e}}var Hn=q.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ot="react-compiler-extra",Yn=j({runOnlyWithEnableCompilerDirective:P(oe())}),zn=/eslint +react-compiler\/react-compiler: +\["error/;function Bn(e){return e.type===q.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===q.AST_NODE_TYPES.MemberExpression&&e.property.type===q.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var qn=/\bthis[.[]/;function At(e){return qn.test(e)}var Xn=Hn({name:Ot,meta:{type:"suggestion",fixable:"code",docs:{description:"Extra rules to enforce best practices when using the React compiler"},messages:{objectMethodIsNotSupported:"Object methods such as `{ method() {} }` have limited support to optimizations in the React compiler, use a function expression `{ method: () => {} }` instead.",replaceWithFunctionExpression:"Replace with function expression",thisKeywordInMethod:"Object method uses `this` keyword which would have different behavior if converted to an arrow function. Fix this manually."},hasSuggestions:!0,schema:[Yn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let l of e.sourceCode.getAllComments())if(zn.test(l.value)){n=!0;break}if(!n)return{}}function r(l){for(let o of l.properties)if(o.type===q.AST_NODE_TYPES.Property&&o.method&&o.value.type===q.AST_NODE_TYPES.FunctionExpression){let i=e.sourceCode,a=i.getText(o.key),c=o.value,p=i.getText(c.body);if(At(p))e.report({node:o,messageId:"thisKeywordInMethod"});else{let u=c.params.map(S=>i.getText(S)).join(", "),g="";c.generator?g=`${a}: function* (${u}) ${p}`:g=`${a}: (${u}) => ${p}`,e.report({node:o,messageId:"objectMethodIsNotSupported",fix:S=>S.replaceText(o,g)})}}}function s(l){for(let o of l.properties)if(o.type===q.AST_NODE_TYPES.Property&&o.value.type===q.AST_NODE_TYPES.ObjectExpression){for(let i of o.value.properties)if(i.type===q.AST_NODE_TYPES.Property&&i.method&&i.value.type===q.AST_NODE_TYPES.FunctionExpression){let c=e.sourceCode.getText(i.value.body);At(c)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(l){if(Bn(l.callee))for(let o of l.arguments){if(o.type===q.AST_NODE_TYPES.ObjectExpression&&(r(o),s(o)),o.type===q.AST_NODE_TYPES.ArrowFunctionExpression&&(o.body.type===q.AST_NODE_TYPES.ObjectExpression&&(r(o.body),s(o.body)),o.body.type===q.AST_NODE_TYPES.BlockStatement))for(let i of o.body.body)i.type===q.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===q.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),s(i.argument));if(o.type===q.AST_NODE_TYPES.FunctionExpression)for(let i of o.body.body)i.type===q.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===q.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),s(i.argument))}}}}}),Be={name:Ot,rule:Xn};var Q=require("@typescript-eslint/utils");var Pt=require("@typescript-eslint/utils");function fe(e){let n=Pt.ESLintUtils.RuleCreator(r=>`https://github.com/lucasols/extended-lint#${r}`)(e);return{name:e.name,rule:n}}var Kn=j({disallow:P(Y(j({selector:F(),message:F(),replace:P(Ae(F(),j({regex:F(),with:F()}))),replaceType:P(ke(["suggestion","autofix"]))}))),disallowFnCalls:P(Y(j({fn:F(),withArgs:P(Y(j({atIndex:ze(),value:Ae(F(),Z(),oe())}))),message:F(),replaceWith:P(F()),ignoreRegex:P(F())}))),__dev_simulateFileName:P(F()),mustMatchSyntax:P(Y(j({includeRegex:F(),mustCallFn:P(Y(j({anyCall:Y(j({fn:F(),withArgs:Y(j({atIndex:ze(),literal:Ae(F(),Z(),oe())}))})),message:P(F())}))),mustMatchSelector:P(Y(j({selector:F(),message:F()})))})))}),qe=fe({name:"advanced-no-restricted-syntax",meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Kn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:s,disallow:l,disallowFnCalls:o}=t,i=s??e.filename,a=[],c=new Map,p=new Set,u=new Map,g=new Map;function S(d){for(let m of d.specifiers)m.type===Q.AST_NODE_TYPES.ImportSpecifier&&m.imported.type===Q.AST_NODE_TYPES.Identifier&&m.local.type===Q.AST_NODE_TYPES.Identifier&&m.imported.name!==m.local.name&&g.set(m.local.name,m.imported.name)}function E(d){d.id.type===Q.AST_NODE_TYPES.Identifier&&d.init?.type===Q.AST_NODE_TYPES.Identifier&&g.set(d.id.name,d.init.name)}function T(d){return g.get(d)??d}function w(d,m){return T(d)===m||d===m}for(let{includeRegex:d,mustCallFn:m,mustMatchSelector:v}of r??[]){let R=Jn(i,new RegExp(d));if(!R)continue;let A=O=>{let x=O;for(let{name:U,value:B}of R)x=x.replaceAll(U,B);return x};for(let{anyCall:O,message:x}of m??[]){let U=`Expected file to call the function: ${O.map(({fn:B})=>B).join(" or ")}`;p.add(U),a.push(B=>{let{callee:ie}=B;if(ie.type===Q.AST_NODE_TYPES.Identifier){for(let{fn:$e,withArgs:xe}of O)if(ie.name===$e){p.delete(U);for(let pe of xe){let X=B.arguments[pe.atIndex],ne=typeof pe.literal=="string"?A(pe.literal):pe.literal;if(!X){e.report({node:B,messageId:"default",data:{message:`Missing argument with value "${ne}" at index ${pe.atIndex}${x?`: ${A(x)}`:""}`}});continue}if(X.type!==Q.AST_NODE_TYPES.Literal){e.report({node:X,messageId:"default",data:{message:`Argument at position ${pe.atIndex} should the literal "${ne}"${x?`: ${A(x)}`:""}`}});continue}X.value!==ne&&e.report({node:X,messageId:"default",data:{message:`Argument should have the value "${ne}"${x?`: ${A(x)}`:""}`},fix:Ie=>Ie.replaceText(X,typeof ne=="string"?`'${ne}'`:String(ne))})}break}}})}for(let{selector:O,message:x}of v??[])u.set(O,A(x)),c.set(A(O),()=>{u.delete(O)})}for(let{fn:d,withArgs:m,message:v,replaceWith:R,ignoreRegex:A}of o??[])A&&new RegExp(A).test(i)||a.push(O=>{let{callee:x}=O;if(x.type!==Q.AST_NODE_TYPES.Identifier||!w(x.name,d))return;if(m)for(let B of m){let ie=O.arguments[B.atIndex];if(!ie){e.report({node:O,messageId:"default",data:{message:`Missing argument with value "${B.value}" at index ${B.atIndex}: ${v}`}});return}if(ie.type!==Q.AST_NODE_TYPES.Literal||ie.value!==B.value)return}let U=B=>R?B.replaceText(O,R):null;e.report({node:O,messageId:"default",data:{message:v},suggest:R?[{messageId:"default",data:{message:`Replace with "${R}"`},fix:U}]:void 0})});function h(d,m){let v=n[d];v?n[d]=R=>{v(R),m(R)}:n[d]=m}for(let{selector:d,message:m,replace:v,replaceType:R="suggestion"}of l??[]){if(d==="CallExpression"){a.push(A=>{_(v,A,m,R)});continue}n[d]=A=>{_(v,A,m,R)}}if(c.size>0)for(let[d,m]of c)h(d,m);return a.length>0&&(n.CallExpression=d=>{if(d.type===Q.AST_NODE_TYPES.CallExpression)for(let m of a)m(d)}),n.ImportDeclaration=d=>{d.type===Q.AST_NODE_TYPES.ImportDeclaration&&S(d)},n.VariableDeclarator=d=>{d.type===Q.AST_NODE_TYPES.VariableDeclarator&&E(d)},n["Program:exit"]=d=>{for(let m of p)e.report({node:d,messageId:"default",data:{message:m}});for(let[,m]of u)e.report({node:d,messageId:"default",data:{message:m}})},n;function _(d,m,v,R){let A=O=>{if(!d)return null;if(typeof d=="string")return O.replaceText(m,d);{let x=new RegExp(d.regex),U=e.sourceCode.getText(m);return O.replaceText(m,U.replace(x,d.with))}};e.report({node:m,messageId:"default",data:{message:v},fix:d&&R==="autofix"?A:void 0,suggest:d&&R==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof d=="string"?d:d.with}"`},fix:A}]:void 0})}}});function Jn(e,t){let n=[],r=t.exec(e);if(!r)return null;let[s,...l]=r;n.push({name:"$0_lowercase",value:s.toLowerCase()}),n.push({name:"$0_capitalize",value:Ft(s)}),n.push({name:"$0_uncapitalize",value:Nt(s)}),n.push({name:"$0",value:s});for(let o=0;o<l.length;o++){let i=`$${o+1}`,a=l[o];n.push({name:`${i}_lowercase`,value:a.toLowerCase()}),n.push({name:`${i}_capitalize`,value:Ft(a)}),n.push({name:`${i}_uncapitalize`,value:Nt(a)}),n.push({name:i,value:a})}return n}function Ft(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Nt(e){return e.charAt(0).toLowerCase()+e.slice(1)}var M=require("@typescript-eslint/utils");var Gn=M.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),jt="collapse-simple-objs-in-one-line",Zn=j({maxLineLength:P(Z()),maxProperties:P(Z()),nestedObjMaxLineLength:P(Z()),nestedObjMaxProperties:P(Z()),ignoreTypesWithSuffix:P(Y(F()))}),Qn=Gn({name:jt,meta:{type:"suggestion",fixable:"code",docs:{description:"Format simple objects and types in one line"},messages:{singleLineProp:"Object/type should be written in a single line"},schema:[Zn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],s=t.maxProperties??2,l=t.nestedObjMaxLineLength??t.maxLineLength,o=t.nestedObjMaxProperties??3;function i(c){if(c.type===M.AST_NODE_TYPES.ObjectExpression){let p=c.parent.type===M.AST_NODE_TYPES.Property,u=p?o:s,g=c.properties.length;if(g>u)return!1;if(g===1){let E=c.properties[0];return E.type===M.AST_NODE_TYPES.Property&&E.value.type===M.AST_NODE_TYPES.ObjectExpression||E.type===M.AST_NODE_TYPES.Property&&E.value.type===M.AST_NODE_TYPES.ArrayExpression&&!E.value.elements.every(w=>w&&Xe(w))?!1:{text:n.getText(E),isNested:p,propsSize:g}}let S=[];for(let E of c.properties){if(E.type===M.AST_NODE_TYPES.Property&&!Xe(E.value))return!1;S.push(n.getText(E))}return{text:S.join(", "),isNested:p,propsSize:g}}else{let p=c.parent.parent?.type===M.AST_NODE_TYPES.TSPropertySignature,u=p?o:s,g=c.members.length;if(g>u)return!1;if(r.length>0&&c.parent.type===M.AST_NODE_TYPES.TSTypeAliasDeclaration){let E=c.parent.id.name;if(r.some(T=>E.endsWith(T)))return!1}if(g===1){let E=c.members[0];return E.type===M.AST_NODE_TYPES.TSPropertySignature&&E.typeAnnotation?.typeAnnotation.type===M.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(E),isNested:p,propsSize:1}}if(c.parent.type===M.AST_NODE_TYPES.TSIntersectionType||c.parent.type===M.AST_NODE_TYPES.TSUnionType)return!1;let S=[];for(let E of c.members){if(E.type!==M.AST_NODE_TYPES.TSPropertySignature)return!1;let T=E.typeAnnotation?.typeAnnotation;if(!T||T.type===M.AST_NODE_TYPES.TSTypeLiteral||!Dt(T))return!1;if(T.type===M.AST_NODE_TYPES.TSTypeReference&&T.typeArguments){if(T.typeArguments.params.length>1)return!1;let h=T.typeArguments.params[0];if(!Dt(h))return!1}let w=n.getText(E).trim();(w.endsWith(";")||w.endsWith(","))&&(w=w.slice(0,-1)),S.push(w)}return{text:S.join("; "),isNested:p,propsSize:g}}}function a(c){if(c.loc.start.line===c.loc.end.line)return;if(c.parent.type!==M.AST_NODE_TYPES.JSXExpressionContainer){let T=0,w=n.getTokenAfter(c,{filter:h=>h.type!==M.AST_TOKEN_TYPES.Punctuator?!0:h.value===","||h.value===";"||h.value===")"||h.value==="}"?(T++,!1):!0});if(T>4||w?.loc.start.line===c.loc.end.line)return}let p=i(c);if(!p)return;let u=p.text;if(u.includes(`
|
|
2
2
|
`)||n.getCommentsInside(c).length>0)return;u.endsWith(";")&&(u=u.slice(0,-1));let g=`{ ${u} }`,S=tr(n,c),E=p.isNested&&p.propsSize>2?l:t.maxLineLength;E&&g.length+S.length+er(c,n)>E||e.report({node:c,messageId:"singleLineProp",fix:T=>T.replaceText(c,g)})}return{TSTypeLiteral:a,ObjectExpression:a}}});function Dt(e){return e.type===M.AST_NODE_TYPES.TSLiteralType||e.type===M.AST_NODE_TYPES.TSTypeReference||e.type===M.AST_NODE_TYPES.TSNumberKeyword||e.type===M.AST_NODE_TYPES.TSStringKeyword||e.type===M.AST_NODE_TYPES.TSBooleanKeyword||e.type===M.AST_NODE_TYPES.TSNullKeyword||e.type===M.AST_NODE_TYPES.TSUndefinedKeyword}function Xe(e,t){return!!(e.type===M.AST_NODE_TYPES.Literal||e.type===M.AST_NODE_TYPES.Identifier||e.type===M.AST_NODE_TYPES.TemplateLiteral||e.type===M.AST_NODE_TYPES.TaggedTemplateExpression||!t&&e.type===M.AST_NODE_TYPES.ArrayExpression&&e.elements.every(n=>n&&Xe(n,!0)))}function er(e,t){let n=t.getLastToken(e);if(!n)return 0;let r=t.text.indexOf(`
|
|
3
|
-
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function tr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Ke={name:jt,rule:Qn};var nr=/eslint +react-compiler\/react-compiler: +\["error/,_t={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"?h=>n(h):h=>e.sourceCode.getText(h),r=typeof e.getScope=="function"?()=>r():h=>e.sourceCode.getScope(h),s=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,l=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,o={additionalHooks:s,enableDangerousAutofixThisMayCauseInfiniteLoops:l};function i(h){l&&Array.isArray(h.suggest)&&h.suggest.length>0&&(h.fix=h.suggest[0].fix),e.report(h)}let a=e.getSourceCode().scopeManager,c=new WeakMap,p=new WeakSet,u=new WeakMap,g=new WeakMap,S=new WeakSet;function E(h,_){return function(d){if(_.has(d))return _.get(d);let m=h(d);return _.set(d,m),m}}function T(h,_,d,m,
|
|
3
|
+
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function tr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Ke={name:jt,rule:Qn};var nr=/eslint +react-compiler\/react-compiler: +\["error/,_t={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"?h=>n(h):h=>e.sourceCode.getText(h),r=typeof e.getScope=="function"?()=>r():h=>e.sourceCode.getScope(h),s=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,l=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,o={additionalHooks:s,enableDangerousAutofixThisMayCauseInfiniteLoops:l};function i(h){l&&Array.isArray(h.suggest)&&h.suggest.length>0&&(h.fix=h.suggest[0].fix),e.report(h)}let a=e.getSourceCode().scopeManager,c=new WeakMap,p=new WeakSet,u=new WeakMap,g=new WeakMap,S=new WeakSet;function E(h,_){return function(d){if(_.has(d))return _.get(d);let m=h(d);return _.set(d,m),m}}function T(h,_,d,m,v){v&&h.async&&i({node:h,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
|
|
4
4
|
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
async function fetchData() {
|
|
@@ -11,5 +11,5 @@ useEffect(() => {
|
|
|
11
11
|
fetchData();
|
|
12
12
|
}, [someId]); // Or [] if effect doesn't need props or state
|
|
13
13
|
|
|
14
|
-
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let v=a.acquire(h),A=new Set,O=null;{let f=v.upper;for(;f&&(A.add(f),f.type!=="function");)f=f.upper;if(!f)return;O=f}let x=Array.isArray;function U(f){if(!x(f.defs))return!1;let y=f.defs[0];if(y==null||y.node.type!=="VariableDeclarator")return!1;let b=y.node.init;if(b==null)return!1;for(;b.type==="TSAsExpression";)b=b.expression;let I=y.node.parent;if(I==null&&(Ze(O.block,y.node.id),I=y.node.parent,I==null))return!1;if(I.kind==="const"&&b.type==="Literal"&&(typeof b.value=="string"||typeof b.value=="number"||b.value===null))return!0;if(b.type!=="CallExpression")return!1;let k=b.callee;if(k.type==="MemberExpression"&&k.object.name==="React"&&k.property!=null&&!k.computed&&(k=k.property),k.type!=="Identifier")return!1;let C=y.node.id,{name:D}=k;if(D==="useRef"&&C.type==="Identifier")return!0;if(ar(k)&&C.type==="Identifier"){for(let L of f.references)L!==C&&S.add(L.identifier);return!0}else if(D==="useState"||D==="useReducer"){if(C.type==="ArrayPattern"&&C.elements.length===2&&x(f.identifiers)){if(C.elements[1]===f.identifiers[0]){if(D==="useState"){let L=f.references,ee=0;for(let se=0;se<L.length;se++){if(L[se].isWrite()&&ee++,ee>1)return!1;c.set(L[se].identifier,C.elements[0])}}return!0}else if(C.elements[0]===f.identifiers[0]){if(D==="useState"){let L=f.references;for(let ee=0;ee<L.length;ee++)p.add(L[ee].identifier)}return!1}}}else if(D==="useTransition"&&C.type==="ArrayPattern"&&C.elements.length===2&&Array.isArray(f.identifiers)&&C.elements[1]===f.identifiers[0])return!0;return!1}function Y(f){if(!x(f.defs))return!1;let y=f.defs[0];if(y==null||y.node==null||y.node.id==null)return!1;let b=y.node,I=O.childScopes,k=null,C;for(C=0;C<I.length;C++){let D=I[C],L=D.block;if(b.type==="FunctionDeclaration"&&L===b||b.type==="VariableDeclarator"&&L.parent===b){k=D;break}}if(k==null)return!1;for(C=0;C<k.through.length;C++){let D=k.through[C];if(D.resolved!=null&&A.has(D.resolved.scope)&&!ie(D.resolved))return!1}return!0}let ie=E(U,u),$e=E(Y,g),xe=new Map;function pe(f){let y=f.from,b=!1;for(;y.block!==h;)y.type==="function"&&(b=y.block.parent!=null&&y.block.parent.type==="ReturnStatement"),y=y.upper;return b}let X=new Map,ne=new Map;Ie(v);function Ie(f){for(let y of f.references){if(!y.resolved||!A.has(y.resolved.scope))continue;let b=Ze(h,y.identifier),I=Mt(b),k=ae(I,ne);if(R&&I.type==="Identifier"&&(I.parent.type==="MemberExpression"||I.parent.type==="OptionalMemberExpression")&&!I.parent.computed&&I.parent.property.type==="Identifier"&&I.parent.property.name==="current"&&pe(y)&&xe.set(k,{reference:y,dependencyNode:I}),I.parent.type==="TSTypeQuery"||I.parent.type==="TSTypeReference")continue;let C=y.resolved.defs[0];if(C!=null&&!(C.node!=null&&C.node.init===h.parent)&&C.type!=="TypeParameter")if(X.has(k))X.get(k).references.push(y);else{let D=y.resolved,L=ie(D)||$e(D);X.set(k,{isStable:L,references:[y]})}}for(let y of f.childScopes)Ie(y)}xe.forEach(({reference:f,dependencyNode:y},b)=>{let I=f.resolved.references,k=!1;for(let C=0;C<I.length;C++){let{identifier:D}=I[C],{parent:L}=D;if(L!=null&&L.type==="MemberExpression"&&!L.computed&&L.property.type==="Identifier"&&L.property.name==="current"&&L.parent.type==="AssignmentExpression"&&L.parent.left===L){k=!0;break}}k||i({node:y.parent.property,message:`The ref value '${b}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${b}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Ue=new Set;function Pn(f,y){Ue.has(y)||(Ue.add(y),i({node:f,message:`Assignments to the '${y}' variable from inside React Hook ${n(d)} 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(d)}.`}))}let Ce=new Set;if(X.forEach(({isStable:f,references:y},b)=>{f&&Ce.add(b),y.forEach(I=>{I.writeExpr&&Pn(I.writeExpr,b)})}),Ue.size>0)return;if(!_){let f=null;if(X.forEach(({isStable:y,references:b},I)=>{f||b.forEach(k=>{if(f)return;let C=k.identifier;if(!c.has(C))return;let L=k.from;for(;L.type!=="function";)L=L.upper;L.block===h&&(f=I)})}),f){let{suggestedDependencies:y}=Je({dependencies:X,declaredDependencies:[],stableDependencies:Ce,externalDependencies:new Set,isEffect:!0});i({node:d,message:`React Hook ${m} contains a call to '${f}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+y.join(", ")+`] as a second argument to the ${m} Hook.`,suggest:[{desc:`Add dependencies array: [${y.join(", ")}]`,fix(b){return b.insertTextAfter(h,`, [${y.join(", ")}]`)}}]})}return}let he=[],Ee=new Set;_.type!=="ArrayExpression"?i({node:_,message:`React Hook ${n(d)} 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.`}):_.elements.forEach(f=>{if(f===null)return;if(f.type==="SpreadElement"){i({node:f,message:`React Hook ${n(d)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}S.has(f)&&i({node:f,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(f)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(f)}\``,fix(k){return k.removeRange(f.range)}}]});let y;try{y=ae(f,ne)}catch(k){if(/Unsupported node type/.test(k.message)){f.type==="Literal"?X.has(f.value)?i({node:f,message:`The ${f.raw} literal is not a valid dependency because it never changes. Did you mean to include ${f.value} in the array instead?`}):i({node:f,message:`The ${f.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):i({node:f,message:`React Hook ${n(d)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw k}let b=f;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let I=!O.through.some(k=>k.identifier===b);he.push({key:y,node:f}),I||Ee.add(y)});let{suggestedDependencies:Fn,unnecessaryDependencies:we,missingDependencies:ue,duplicateDependencies:wt}=Je({dependencies:X,declaredDependencies:he,stableDependencies:Ce,externalDependencies:Ee,isEffect:R}),Re=Fn;if(wt.size+ue.size+we.size===0){if(t)return;rr({declaredDependencies:he,declaredDependenciesNode:_,componentScope:O,scope:v}).forEach(({construction:y,isUsedOutsideOfHook:b,depType:I})=>{let k=I==="function"?"useCallback":"useMemo",C=I==="function"?"definition":"initialization",D=`wrap the ${C} of '${y.name.name}' in its own ${k}() Hook.`,L=b?`To fix this, ${D}`:`Move it inside the ${m} callback. Alternatively, ${D}`,ee=I==="conditional"||I==="logical expression"?"could make":"makes",se=`The '${y.name.name}' ${I} ${ee} the dependencies of ${m} Hook (at line ${_.loc.start.line}) change on every render. ${L}`,Rt;b&&y.type==="Variable"&&I==="function"&&(Rt=[{desc:`Wrap the ${C} of '${y.name.name}' in its own ${k}() Hook.`,fix(vt){let[Dn,jn]=k==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[vt.insertTextBefore(y.node.init,Dn),vt.insertTextAfter(y.node.init,jn)]}}]),i({node:y.node,message:se,suggest:Rt})});return}!R&&ue.size>0&&(Re=Je({dependencies:X,declaredDependencies:[],stableDependencies:Ce,externalDependencies:Ee,isEffect:R}).suggestedDependencies);function Nn(){if(he.length===0)return!0;let f=he.map(b=>b.key),y=f.slice().sort();return f.join(",")===y.join(",")}Nn()&&Re.sort();function Ve(f){let y=f.split("."),b="";for(let I=0;I<y.length;I++){if(I!==0){let k=y.slice(0,I+1).join("."),C=ne.get(k)===!0;b+=C?"?.":"."}b+=y[I]}return b}function We(f,y,b,I){return f.size===0?null:(f.size>1?"":y+" ")+b+" "+(f.size>1?"dependencies":"dependency")+": "+sr(Array.from(f).sort().map(k=>"'"+Ve(k)+"'"))+`. Either ${I} ${f.size>1?"them":"it"} or remove the dependency array.`}let re="";if(we.size>0){let f=null;if(Array.from(we.keys()).forEach(y=>{f===null&&y.endsWith(".current")&&(f=y)}),f!==null)re=` Mutable values like '${f}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(Ee.size>0){let y=Array.from(Ee)[0];v.set.has(y)||(re=` Outer scope values like '${y}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!re&&ue.has("props")){let f=X.get("props");if(f==null)return;let y=f.references;if(!Array.isArray(y))return;let b=!0;for(let I=0;I<y.length;I++){let k=y[I],C=Ze(O.block,k.identifier);if(!C){b=!1;break}let D=C.parent;if(D==null){b=!1;break}if(D.type!=="MemberExpression"&&D.type!=="OptionalMemberExpression"){b=!1;break}}b&&(re=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${m} call and refer to those specific props inside ${n(d)}.`)}if(!re&&ue.size>0){let f=null;ue.forEach(y=>{if(f)return;let b=O.set.get(y),I=X.get(y);if(I.references[0].resolved!==b)return;let k=b.defs[0];if(k==null||k.name==null||k.type!=="Parameter")return;let C=!1,D;for(let L=0;L<I.references.length;L++)if(D=I.references[L].identifier,D!=null&&D.parent!=null&&(D.parent.type==="CallExpression"||D.parent.type==="OptionalCallExpression")&&D.parent.callee===D){C=!0;break}C&&(f=y)}),f!==null&&(re=` If '${f}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!re&&ue.size>0){let f=null;if(ue.forEach(y=>{if(f!==null)return;let I=X.get(y).references,k,C;for(let D=0;D<I.length;D++){for(k=I[D].identifier,C=k.parent;C!=null&&C!==O.block;){if(C.type==="CallExpression"){let L=c.get(C.callee);if(L!=null){if(L.name===y)f={missingDep:y,setter:C.callee.name,form:"updater"};else if(p.has(k))f={missingDep:y,setter:C.callee.name,form:"reducer"};else{let ee=I[D].resolved;if(ee!=null){let se=ee.defs[0];se!=null&&se.type==="Parameter"&&(f={missingDep:y,setter:C.callee.name,form:"inlineReducer"})}}break}}C=C.parent}if(f!==null)break}}),f!==null)switch(f.form){case"reducer":re=` You can also replace multiple useState variables with useReducer if '${f.setter}' needs the current value of '${f.missingDep}'.`;break;case"inlineReducer":re=` If '${f.setter}' needs the current value of '${f.missingDep}', you can also switch to useReducer instead of useState and read '${f.missingDep}' in the reducer.`;break;case"updater":re=` You can also do a functional update '${f.setter}(${f.missingDep.slice(0,1)} => ...)' if you only need '${f.missingDep}' in the '${f.setter}' call.`;break;default:throw new Error("Unknown case.")}}i({node:_,message:`React Hook ${n(d)} has `+(We(ue,"a","missing","include")||We(we,"an","unnecessary","exclude")||We(wt,"a","duplicate","omit"))+re,suggest:[{desc:`Update the dependencies array to be: [${Re.map(Ve).join(", ")}]`,fix(f){return f.replaceText(_,`[${Re.map(Ve).join(", ")}]`)}}]})}function w(h){let _=ir(h.callee,o);if(_===-1)return;let d=h.arguments[_],m=h.callee,R=$t(m).name,v=h.arguments[_+1],A=/Effect($|[^a-z])/g.test(R);if(!d){i({node:m,message:`React Hook ${R} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!A)){if(!v&&!A){(R==="useMemo"||R==="useCallback")&&i({node:m,message:`React Hook ${R} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(d.type){case"FunctionExpression":case"ArrowFunctionExpression":T(d,v,m,R,A);return;case"Identifier":if(!v||v.elements&&v.elements.some(U=>U&&U.type==="Identifier"&&U.name===d.name))return;let O=r(h).set.get(d.name);if(O==null||O.defs==null)return;let x=O.defs[0];if(!x||!x.node||x.type!=="Variable"&&x.type!=="FunctionName")break;switch(x.node.type){case"FunctionDeclaration":T(x.node,v,m,R,A);return;case"VariableDeclarator":let U=x.node.init;if(!U)break;switch(U.type){case"ArrowFunctionExpression":case"FunctionExpression":T(U,v,m,R,A);return}break}break;default:i({node:m,message:`React Hook ${R} received a function whose dependencies are unknown. Pass an inline function instead.`});return}i({node:m,message:`React Hook ${R} has a missing dependency: '${d.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${d.name}]`,fix(O){return O.replaceText(v,`[${d.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let h of e.sourceCode.getAllComments())if(nr.test(h.value))return t=!0,{CallExpression:_=>w(_,!0)}}return{CallExpression:h=>w(h)}}};function Je({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:s}){let l=o();function o(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,w)=>{let h=i(l,w);h.isUsed=!0,a(l,w,_=>{_.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let w=i(l,T);w.isSatisfiedRecursively=!0}),n.forEach(T=>{let w=i(l,T);w.isSatisfiedRecursively=!0});function i(T,w){let h=w.split("."),_=T;for(let d of h){let m=_.children.get(d);m||(m=o(),_.children.set(d,m)),_=m}return _}function a(T,w,h){let _=w.split("."),d=T;for(let m of _){let R=d.children.get(m);if(!R)return;h(R),d=R}}let c=new Set,p=new Set;u(l,c,p,T=>T);function u(T,w,h,_){T.children.forEach((d,m)=>{let R=_(m);if(d.isSatisfiedRecursively){d.isSubtreeUsed&&h.add(R);return}if(d.isUsed){w.add(R);return}u(d,w,h,v=>R+"."+v)})}let g=[],S=new Set,E=new Set;return t.forEach(({key:T})=>{p.has(T)?g.indexOf(T)===-1?g.push(T):E.add(T):S.add(T)}),c.forEach(T=>{g.push(T)}),{suggestedDependencies:g,unnecessaryDependencies:S,duplicateDependencies:E,missingDependencies:c}}function me(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 me(e.consequent)!=null||me(e.alternate)!=null?"conditional":null;case"LogicalExpression":return me(e.left)!=null||me(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return me(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return me(e.expression);case"TSAsExpression":return me(e.expression)}return null}function rr({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let s=e.map(({key:o})=>{let i=n.variables.find(c=>c.name===o);if(i==null)return null;let a=i.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 c=me(a.node.init);if(c!=null)return[i,c]}return a.type==="FunctionName"&&a.node.type==="FunctionDeclaration"?[i,"function"]:a.type==="ClassName"&&a.node.type==="ClassDeclaration"?[i,"class"]:null}).filter(Boolean);function l(o){let i=!1;for(let a=0;a<o.references.length;a++){let c=o.references[a];if(c.writeExpr){if(i)return!0;i=!0;continue}let p=c.from;for(;p!==r&&p!=null;)p=p.upper;if(p!==r&&!Ut(t,c.identifier))return!0}return!1}return s.map(([o,i])=>({construction:o.defs[0],depType:i,isUsedOutsideOfHook:l(o)}))}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 Ge(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function ae(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=ae(e.object,t),r=ae(e.property,null),s=`${n}.${r}`;return Ge(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=ae(e.object,t),r=ae(e.property,null),s=`${n}.${r}`;return Ge(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=ae(n.object,t),s=ae(n.property,null),l=`${r}.${s}`;return Ge(n,t,l),l}else throw new Error(`Unsupported node type: ${e.type}`)}function $t(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function ir(e,t){let n=$t(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let r;try{r=ae(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(r)?0:-1}else return-1}}function Ze(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),or(r,t))return r;if(Ut(r,t))for(let[s,l]of Object.entries(r))s!=="parent"&&(Lt(l)?(l.parent=r,n.push(l)):Array.isArray(l)&&l.forEach(o=>{Lt(o)&&(o.parent=r,n.push(o))}))}return null}function sr(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function Lt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function or(e,t){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===t.type&&e.name===t.name&&e.range[0]===t.range[0]&&e.range[1]===t.range[1]}function Ut(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function ar(e){return!1}var de=require("@typescript-eslint/utils");var K=He(require("typescript")),lr=de.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="improved-no-unnecessary-condition",cr=j({}),pr=["string","number","bigint","boolean","symbol","undefined","object","function","never"],ur=new Set(pr),Qe={name:Vt,rule:lr({name:Vt,meta:{type:"suggestion",docs:{description:"Extends checks of `no-unnecessary-condition` rule"},messages:{unnecessaryTypeofCondition:'This condition is unnecessary. The type of "{{name}}" is always "{{type}}".',alwaysFalseTypeofCondition:'This condition will always be false. The type of "{{name}}" is "{{actualType}}" so the condition has no overlap with "{{conditionType}}".'},schema:[cr]},defaultOptions:[{}],create(e){let t=de.ESLintUtils.getParserServices(e,!0),n=t.program?.getTypeChecker();if(!n||!t.program)throw new Error("TypeScript services or program not available");function r(i){return i.type===de.AST_NODE_TYPES.UnaryExpression&&i.operator==="typeof"}function s(i){return i.flags&K.default.TypeFlags.Any||i.flags&K.default.TypeFlags.Unknown?null:i.flags&K.default.TypeFlags.StringLike?["string"]:i.flags&K.default.TypeFlags.NumberLike?["number"]:i.flags&K.default.TypeFlags.BigIntLike?["bigint"]:i.flags&K.default.TypeFlags.BooleanLike?["boolean"]:i.flags&K.default.TypeFlags.ESSymbolLike?["symbol"]:i.flags&K.default.TypeFlags.Undefined||i.flags&K.default.TypeFlags.Void?["undefined"]:i.flags&K.default.TypeFlags.Null?["object"]:i.getCallSignatures().length>0?["function"]:i.flags&K.default.TypeFlags.Object?i.getProperties().length===0?["string","number","bigint","boolean","symbol","object","function"]:["object"]:i.flags&K.default.TypeFlags.NonPrimitive?["object"]:i.flags&K.default.TypeFlags.Never?["never"]:null}function l(i){if(!n)return null;let a=t.esTreeNodeToTSNodeMap.get(i),c=n.getTypeAtLocation(a.expression);if(c.flags&K.default.TypeFlags.Any||c.flags&K.default.TypeFlags.Unknown)return null;let p=[];if(c.isUnion()){for(let g of c.types){let S=s(g);if(S)p.push(...S);else return null}return p}let u=s(c);return u?(p.push(...u),p):null}function o(i){if(!(i.operator==="==="||i.operator==="!=="))return;let c=null,p=null;if(r(i.left)?(c=i.left,p=i.right.type===de.AST_NODE_TYPES.Literal&&typeof i.right.value=="string"?i.right.value:null):r(i.right)&&(c=i.right,p=i.left.type===de.AST_NODE_TYPES.Literal&&typeof i.left.value=="string"?i.left.value:null),!c||!p||!fr(p,ur))return;let u=l(c);if(!u)return;let g=i.operator==="!==",S=u.includes(p);u.length===1?S&&!g?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ge(c,e),type:p}}):!S&&g?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ge(c,e),type:Array.from(u)[0]}}):!S&&!g?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ge(c,e),actualType:Oe(u),conditionType:p}}):S&&g&&e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ge(c,e),actualType:Oe(u),conditionType:p}}):!S&&!g?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ge(c,e),actualType:Oe(u),conditionType:p}}):!S&&g&&e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ge(c,e),type:Oe(u)}})}return{BinaryExpression:o}}})};function Oe(e){return Array.from(new Set(e)).join(" | ")||"never"}function ge(e,t){let n=e.argument;return n.type===de.AST_NODE_TYPES.Identifier?n.name:t.sourceCode.getText(n)}function fr(e,t){return t.has(e)}var Pe=require("@typescript-eslint/utils");var mr=Pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Wt="no-call-with-explicit-generics",dr=j({functions:z(F())}),yr=mr({name:Wt,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[dr]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:s}=r;s.type===Pe.AST_NODE_TYPES.Identifier&&n.has(s.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),et={name:Wt,rule:yr};var ye=require("@typescript-eslint/utils"),gr=ye.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ht="no-call-with-inferred-generics",Sr=gr({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(r=>[r.name,r]));return{CallExpression(r){let{callee:s}=r;if(s.type!==ye.AST_NODE_TYPES.Identifier)return;let l=n.get(s.name);if(!l)return;let{minGenerics:o=1,allowAny:i,disallowTypes:a=t.disallowTypes}=l;(r.typeArguments?.params.length||0)<(o||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:o||0}}),!(i&&!a)&&r.typeArguments?.params?.some(p=>!i&&p.type===ye.AST_NODE_TYPES.TSAnyKeyword||a&&p.type===ye.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===ye.AST_NODE_TYPES.Identifier&&a.includes(p.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),tt={name:Ht,rule:Sr};var be=require("@typescript-eslint/utils"),Tr=be.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Yt="no-commented-out-code",hr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Er=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],br=Tr({name:Yt,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of hr)if(r.startsWith(s))return{wrongPattern:s};for(let s of Er)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let s of r)if(s.type===be.TSESTree.AST_TOKEN_TYPES.Line||s.type===be.TSESTree.AST_TOKEN_TYPES.Block){let l=t(s.value);l&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:l.wrongPattern}})}}}}}),nt={name:Yt,rule:br};var Fe=require("@typescript-eslint/utils"),xr=Fe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),zt="no-default-export",Ir=xr({name:zt,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===Fe.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),rt={name:zt,rule:Ir};var Bt=require("@typescript-eslint/utils"),Cr=Bt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qt="no-leaked-text-in-jsx",wr=[",",";","[","]","(",")"],Rr=Cr({name:qt,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";wr.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),it={name:qt,rule:Rr};var le=require("@typescript-eslint/utils"),vr=le.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Kt="no-non-camel-case-functions",kr=/^[a-z][a-zA-Z0-9]*$/;function Xt(e){return e.typeName.type===le.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===le.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===le.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var Ar=vr({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&&!kr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===le.AST_NODE_TYPES.TSTypeReference?Xt(n):n.type===le.AST_NODE_TYPES.TSUnionType&&n.types.some(s=>s.type===le.AST_NODE_TYPES.TSTypeReference&&Xt(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),st={name:Kt,rule:Ar};var V=require("@typescript-eslint/utils");var ot=require("@typescript-eslint/utils");function Se(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:Se(e.parent,t,n===1/0?n:n-1)}function*at(e){yield e,e.parent&&(yield*at(e.parent))}function lt(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function Jt(e,t,n){let s=n.getDeclaredVariables(e).find(l=>l.name===t||l.identifiers[0]?.parent.type===ot.AST_NODE_TYPES.Property&&l.identifiers[0]?.parent.key.type===ot.AST_NODE_TYPES.Identifier&&l.identifiers[0]?.parent.key.name===t);return s?s.references.filter(l=>!l.init):[]}var Or=V.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Gt="no-optional-root-props",Pr=Or({name:Gt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let l=e.sourceCode.getDeclaredVariables(r)[0];if(!l||l.references.length!==1)return!1;let o=l.references[0];if(!o)return!1;for(let i of at(o.identifier)){if("returnType"in i||i.type===V.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let a=i.parent;if(!a)return!1;if(a.type===V.TSESTree.AST_NODE_TYPES.TSTypeParameterInstantiation&&a.parent.type===V.TSESTree.AST_NODE_TYPES.TSTypeReference&&a.parent.typeName.type===V.TSESTree.AST_NODE_TYPES.Identifier&&a.parent.typeName.name==="FC"){let p=Se(a.parent.parent,V.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!p)return!1;let u=Ne(p,e.sourceCode);return u?!(u.parent.type===V.TSESTree.AST_NODE_TYPES.CallExpression&&u.parent.callee.type===V.TSESTree.AST_NODE_TYPES.Identifier&&u.parent.callee.name==="memo"):!1}if(i.type===V.TSESTree.AST_NODE_TYPES.AssignmentPattern)return!1;if(a.type===V.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression){let c=Se(a,V.TSESTree.AST_NODE_TYPES.VariableDeclaration);return c?!!Ne(c,e.sourceCode):!1}if(a.type===V.TSESTree.AST_NODE_TYPES.FunctionDeclaration)return!!Ne(a,e.sourceCode)}return!1}function n(r){r.key.type!==V.TSESTree.AST_NODE_TYPES.Identifier||!r.optional||e.report({node:r.key,messageId:"optionalNotAllowed",data:{propertyName:r.key.name},suggest:[{messageId:"suggestion",fix:s=>{let l=Se(r,V.TSESTree.AST_NODE_TYPES.TSPropertySignature);if(!l)return null;let o=e.sourceCode.getText(l);return s.replaceText(l,o.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(r){if(r.typeAnnotation.type===V.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(De(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===V.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(De(r)||!t(r)))for(let s of r.body.body)s.type===V.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSTypeReference(r){if(r.typeName.type!==V.TSESTree.AST_NODE_TYPES.Identifier||r.typeName.name!=="FC"||!r.typeArguments?.params[0])return;let s=r.typeArguments.params[0];if(s.type!==V.TSESTree.AST_NODE_TYPES.TSTypeLiteral)return;let l=Se(r.parent,V.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!l)return;let o=Ne(l,e.sourceCode);if(!(!o||o.parent.type===V.TSESTree.AST_NODE_TYPES.CallExpression&&o.parent.callee.type===V.TSESTree.AST_NODE_TYPES.Identifier&&o.parent.callee.name==="memo"))for(let a of s.members)a.type===V.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(a)}}}});function De(e){return e?e.parent?.type===V.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===V.TSESTree.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function Ne(e,t){if(De(e))return;let n;if(e.type===V.TSESTree.AST_NODE_TYPES.VariableDeclaration){if(e.declarations.length!==1)return;e.declarations[0].id.type===V.TSESTree.AST_NODE_TYPES.Identifier&&(n=e.declarations[0].id)}else{if(!e.id)return;n=e.id}if(!n)return;let r=t.getScope(e);e.type===V.TSESTree.AST_NODE_TYPES.FunctionDeclaration&&r.upper&&(r=r.upper);let s=r.variables.find(o=>o.identifiers.includes(n));if(!s)return;let l=s.references.filter(o=>o.identifier!==n);if(!(l.length!==1||!l[0])&&!De(l[0].identifier.parent.parent))return l[0].identifier}var ct={name:Gt,rule:Pr};var Zt=require("@typescript-eslint/utils"),je=He(require("path"));var Fr=Zt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qt="no-relative-imports",Nr=j({find:F(),replacement:F()}),Dr=j({aliases:z(Nr),rootDir:P(F()),allowNotFoundAliases:P(oe()),_dev_simulateFileName:P(F())}),jr=Fr({name:Qt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[Dr]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(o){return o.startsWith(".")||o.startsWith("..")}function s(o,i){let a=je.default.dirname(i);return je.default.resolve(a,o)}function l(o){let i=t.rootDir??process.cwd(),a=je.default.relative(i,o);if(a.startsWith("."))return null;a.startsWith("/")||(a=`/${a}`);for(let{find:c,replacement:p}of t.aliases)if(a.startsWith(p)){let u=a.replace(p,c);return{alias:c,newPath:u}}return null}return{ImportDeclaration(o){let i=o.source.value;if(!r(i))return;let a=s(i,n),c=l(a);!c&&t.allowNotFoundAliases||e.report({node:o,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?p=>p.replaceText(o.source,`'${c.newPath}'`):void 0})}}}}),pt={name:Qt,rule:jr};var ce=require("@typescript-eslint/utils");var ut=He(require("typescript")),Lr=ce.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),en="no-unnecessary-casting",_r=j({additionalCastFunctions:P(z(j({name:F(),expectedType:ke(["string","number"])})))}),ft={name:en,rule:Lr({name:en,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[_r],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=ce.ESLintUtils.getParserServices(e,!0),l=s.program?.getTypeChecker();if(!l||!s.program)throw new Error("TypeScript services or program not available");function o(p,u){switch(p.type){case ce.AST_NODE_TYPES.Literal:return u==="number"?typeof p.value=="number":typeof p.value=="string";case ce.AST_NODE_TYPES.TemplateLiteral:return u==="string";case ce.AST_NODE_TYPES.UnaryExpression:return u==="number"?p.operator==="+"||p.operator==="-"||p.operator==="~":!1;default:return!1}}function i(p,u){return u==="number"?!!(p.flags&ut.TypeFlags.NumberLike):!!(p.flags&ut.TypeFlags.StringLike)}function a(p,u){return g=>g.replaceText(p,e.sourceCode.getText(u))}function c(p){if(!l||p.arguments.length!==1)return;let u=p.arguments[0];if(!u||u.type===ce.AST_NODE_TYPES.SpreadElement)return;let{callee:g}=p;if(g.type!==ce.AST_NODE_TYPES.Identifier)return;let S=g.name,E=r.find(w=>w.name===S);if(!E)return;if(o(u,E.expectedType)||i(l.getTypeAtLocation(s.esTreeNodeToTSNodeMap.get(u)),E.expectedType)){let w,h;S==="Number"?w="unnecessaryNumberCasting":S==="String"?w="unnecessaryStringCasting":(w="unnecessaryCustomCasting",h={name:E.name,type:E.expectedType}),e.report({node:p,messageId:w,...h?{data:h}:{},fix:a(p,u)})}}return{CallExpression:c}}})};var G=require("@typescript-eslint/utils");var mt=fe({name:"no-unused-obj-props",meta:{type:"suggestion",docs:{description:"Disallow unused properties when it is safe to remove them"},messages:{unusedObjectProperty:'The object property "{{name}}" is not being used',unusedReturnObjectProperty:'The object property "{{name}}" returned by this function is not being used'},schema:[]},defaultOptions:[],create(e){return{VariableDeclarator(t){if(t.id.type===G.AST_NODE_TYPES.ObjectPattern||!t.init||t.init.type!==G.AST_NODE_TYPES.ObjectExpression||t.id.type===G.AST_NODE_TYPES.Identifier&&t.id.typeAnnotation||t.parent.parent.type===G.AST_NODE_TYPES.ExportNamedDeclaration)return;let n=new Map;for(let o of t.init.properties)o.type===G.AST_NODE_TYPES.Property&&o.key.type===G.AST_NODE_TYPES.Identifier&&n.set(o.key.name,o);if(n.size===0||t.id.type!==G.AST_NODE_TYPES.Identifier)return;let r=Mr(t,e.sourceCode);if(r.length===0)return;let s=t.init.properties.some(o=>o.type!==G.AST_NODE_TYPES.Property?!1:o.value.type===G.AST_NODE_TYPES.FunctionExpression),l=new Set;for(let o of r){if(o.identifier.parent.type!==G.AST_NODE_TYPES.MemberExpression)return;let i=o.identifier.parent;if(i.object!==o.identifier)return;if(i.computed)if(i.property.type===G.AST_NODE_TYPES.Literal&&typeof i.property.value=="string")l.add(i.property.value);else return;else{if(i.property.type!==G.AST_NODE_TYPES.Identifier)return;l.add(i.property.name)}if(i.parent.type===G.AST_NODE_TYPES.CallExpression&&s)return}for(let[o,i]of n)l.has(o)||e.report({node:i,messageId:"unusedObjectProperty",data:{name:o}})}}}});function Mr(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}var W=require("@typescript-eslint/utils");var $r=j({selectors:z(j({name:F(),selectorProp:P(F()),selectorArgPos:P(Z()),returnProp:P(F())}))}),Ur=W.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),tn="no-unused-selected-values",dt={name:tn,rule:Ur({name:tn,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[$r]},defaultOptions:[{selectors:[]}],create(e,[t]){let{selectors:n=[]}=t,r=new Map(n.map(s=>[s.name,s]));return{VariableDeclarator(s){let l=null;if(s.init?.type===W.AST_NODE_TYPES.CallExpression&&(l=s.init),!l)return;let o=Wr(l);if(!o)return;let i=r.get(o);if(!i)return;let a=Vr(l,i.selectorArgPos??0,i.selectorProp);if(!a)return;let c=Hr(a);if(!c)return;let p=nn(c.properties,void 0);if(!p)return;if(s.id.type===W.AST_NODE_TYPES.ObjectPattern){let S=nn(s.id.properties,i.returnProp);if(!S)return;for(let[E,T]of p)S.has(E)||e.report({node:T,messageId:"unusedSelectedValue",data:{name:E}});return}if(s.id.type!==W.AST_NODE_TYPES.Identifier||i.returnProp)return;let u=Yr(s,e.sourceCode);if(u.length===0)return;let g=new Set;for(let S of u){if(S.identifier.parent.type!==W.AST_NODE_TYPES.MemberExpression)return;let E=S.identifier.parent.property;if(E.type!==W.AST_NODE_TYPES.Identifier)return;g.add(E.name)}for(let[S,E]of p)g.has(S)||e.report({node:E,messageId:"unusedSelectedValue",data:{name:S}})}}}})};function Vr(e,t,n){let r=e.arguments[t];if(!r)return null;if(r.type===W.AST_NODE_TYPES.ArrowFunctionExpression||r.type===W.AST_NODE_TYPES.FunctionExpression)return r;if(n&&r.type===W.AST_NODE_TYPES.ObjectExpression){let s=r.properties.find(o=>o.type===W.AST_NODE_TYPES.Property&&o.key.type===W.AST_NODE_TYPES.Identifier&&o.key.name===n);if(s?.type!==W.AST_NODE_TYPES.Property)return null;let l=s.value;if(l.type===W.AST_NODE_TYPES.ArrowFunctionExpression||l.type===W.AST_NODE_TYPES.FunctionExpression)return l}return null}function Wr(e){return e.callee.type===W.AST_NODE_TYPES.Identifier?e.callee.name:e.callee.type===W.AST_NODE_TYPES.MemberExpression&&e.callee.property.type===W.AST_NODE_TYPES.Identifier?e.callee.property.name:null}function Hr(e){if(e.body.type===W.AST_NODE_TYPES.ObjectExpression)return e.body;if(e.body.type===W.AST_NODE_TYPES.BlockStatement){let t=e.body.body.filter(n=>n.type===W.AST_NODE_TYPES.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==W.AST_NODE_TYPES.ObjectExpression?null:t[0].argument}return null}function nn(e,t){let n=e;if(t){let s=e.find(l=>l.type===W.AST_NODE_TYPES.Property&&l.key.type===W.AST_NODE_TYPES.Identifier&&l.key.name===t);if(s?.type!==W.AST_NODE_TYPES.Property||s.value.type!==W.AST_NODE_TYPES.ObjectPattern)return null;n=s.value.properties}let r=new Map;for(let s of n){if(s.type!==W.AST_NODE_TYPES.Property||s.key.type!==W.AST_NODE_TYPES.Identifier)return null;r.set(s.key.name,s)}return r.size>0?r:null}function Yr(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}var H=require("@typescript-eslint/utils");var yt=fe({name:"no-unused-t-state-field",meta:{type:"suggestion",docs:{description:"Prevent declaring unused t-state fields"},messages:{unusedField:'Field "{{name}}" is not being used, you can safely remove it'},schema:[]},defaultOptions:[],create(e){if(!(e.filename.endsWith(".jsx")||e.filename.endsWith(".tsx")))return{};if(!e.sourceCode.ast.body.some(l=>l.type===H.AST_NODE_TYPES.ImportDeclaration&&l.source.value==="t-state-form"))return{};let r=null,s=!1;return{CallExpression(l){if(s)return;if(!r){let i=zr(l);i&&(r=i);return}let o=Br(l,e.sourceCode);if(o){s=!0;for(let i of o)r.delete(i);if(r.size!==0)for(let[i,a]of r)e.report({node:a,messageId:"unusedField",data:{name:i}})}}}}});function zr(e){if(!(e.callee.type===H.AST_NODE_TYPES.Identifier&&e.callee.name==="useForm"))return null;let n=e.arguments[0];if(!n||n.type!==H.AST_NODE_TYPES.ObjectExpression)return null;let r=lt(n.properties,l=>l.type!==H.AST_NODE_TYPES.Property||l.key.type!==H.AST_NODE_TYPES.Identifier||l.key.name!=="initialConfig"?null:l.value.type===H.AST_NODE_TYPES.ObjectExpression?l.value:l.value.type===H.AST_NODE_TYPES.ArrowFunctionExpression||l.value.type===H.AST_NODE_TYPES.FunctionExpression?qr(l.value):null);if(!r)return null;let s=new Map;for(let l of r.properties)l.type===H.AST_NODE_TYPES.Property&&l.key.type===H.AST_NODE_TYPES.Identifier&&s.set(l.key.name,l);return s}function Br(e,t){if(!(e.callee.type===H.AST_NODE_TYPES.Identifier&&e.callee.name==="useFormState")||e.parent.type!==H.AST_NODE_TYPES.VariableDeclarator||e.parent.id.type!==H.AST_NODE_TYPES.ObjectPattern||!lt(e.parent.id.properties,o=>o.type===H.AST_NODE_TYPES.Property&&o.key.type===H.AST_NODE_TYPES.Identifier&&o.key.name==="formFields"&&o))return null;let s=Jt(e.parent,"formFields",t),l=new Set;for(let{identifier:o}of s){if(o.type!==H.AST_NODE_TYPES.Identifier||o.parent.type===H.AST_NODE_TYPES.Property&&o.parent.parent.type===H.AST_NODE_TYPES.ObjectExpression&&o.parent.parent.parent.type===H.AST_NODE_TYPES.ReturnStatement||o.parent.type===H.AST_NODE_TYPES.ReturnStatement)return null;if(o.parent.type===H.AST_NODE_TYPES.MemberExpression){if(o.parent.object.type!==H.AST_NODE_TYPES.Identifier||o.parent.property.type!==H.AST_NODE_TYPES.Identifier)return null;l.add(o.parent.property.name)}}return l}function qr(e){if(e.body.type===H.AST_NODE_TYPES.ObjectExpression)return e.body;if(e.body.type===H.AST_NODE_TYPES.BlockStatement){let t=e.body.body.filter(n=>n.type===H.AST_NODE_TYPES.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==H.AST_NODE_TYPES.ObjectExpression?null:t[0].argument}return null}var $=require("@typescript-eslint/utils");var Xr=$.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function rn(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 sn(e,...t){for(let n of t)e.set(...n);return e}var Kr=j({forceCheckOnFCPropTypesWithName:P(z(F()))}),on="no-unused-type-props-in-args",gt=null,Jr=Xr({name:on,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Kr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!gt&&(gt=n.map(i=>new RegExp(i)));function r(i,a,c,p,u=!0){let g=c.name,S=e.sourceCode.getScope(a).references.find(w=>w.identifier.name===g)?.resolved,E=i&>?.some(w=>w.test(g));if(!S||!E&&S.references.filter(w=>w.isTypeReference).length>1)return;let T=S?.defs[0]?.node;if(!(u&&T?.parent?.type===$.AST_NODE_TYPES.ExportNamedDeclaration)){if(T?.type===$.AST_NODE_TYPES.TSTypeAliasDeclaration){s(i,a,p,T.typeAnnotation,!0);return}if(T?.type===$.AST_NODE_TYPES.TSInterfaceDeclaration){s(i,a,p,T.body,!0);return}}}function s(i,a,c,p,u){if(p.type===$.AST_NODE_TYPES.TSInterfaceBody){for(let g of p.body)g.type===$.AST_NODE_TYPES.TSPropertySignature&&g.key.type===$.AST_NODE_TYPES.Identifier&&c.set(g.key.name,g);return}if(p.type===$.AST_NODE_TYPES.TSTypeLiteral){sn(c,...rn(p));return}if(p.type===$.AST_NODE_TYPES.TSIntersectionType){for(let g of p.types)s(i,a,c,g,!0);return}u||p.type===$.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===$.AST_NODE_TYPES.Identifier&&r(i,a,p.typeName,c)}function l(i,a,c){for(let p of c)if(p.type==="ObjectPattern"&&p.typeAnnotation){let u=new Map;if(s(i,a,u,p.typeAnnotation.typeAnnotation,!1),u.size===0)continue;o(p,u)}else p.type===$.AST_NODE_TYPES.AssignmentPattern&&p.left.type===$.AST_NODE_TYPES.ObjectPattern&&l(i,a,[p.left])}function o(i,a){let c=[];if(i.properties.at(-1)?.type===$.AST_NODE_TYPES.RestElement)return;for(let S of i.properties)S.type===$.AST_NODE_TYPES.Property&&S.key.type===$.AST_NODE_TYPES.Identifier&&c.push(S.key.name);let u=[],g=[];for(let[S,E]of a)c.includes(S)||(g.push(S),u.push({node:E,messageId:"unusedObjectTypeProperty",data:{propertyName:S}}));for(let[S,E]of u.entries())e.report({...E,fix:S===u.length-1?T=>{let w=i.properties.at(-1),h=g.join(", ");return w?w?.type===$.AST_NODE_TYPES.RestElement?null:T.insertTextAfter(w,`, ${h}`):T.insertTextBeforeRange([i.range[0]+1,i.range[1]],`${h}`)}:void 0})}return{VariableDeclaration(i){let a=i.declarations[0];if(!a)return;let c=new Map,p=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(p){if(p.type===$.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===$.AST_NODE_TYPES.Identifier)r(!0,i,p.typeName,c,!1);else if(p.type===$.AST_NODE_TYPES.TSTypeLiteral)sn(c,...rn(p));else if(p.type===$.AST_NODE_TYPES.TSIntersectionType)for(let u of p.types)u.type===$.AST_NODE_TYPES.TSTypeReference&&u.typeName.type===$.AST_NODE_TYPES.Identifier?r(!0,i,u.typeName,c,!1):s(!0,i,c,u,!0);if(c.size!==0&&a.init?.type===$.AST_NODE_TYPES.ArrowFunctionExpression){let u=a.init.params[0];if(!u){e.report({node:a.init,messageId:"missingComponentParam"});return}u.type===$.AST_NODE_TYPES.ObjectPattern&&o(u,c)}}},FunctionDeclaration:function(i){l(!1,i,i.params)},ArrowFunctionExpression(i){l(!1,i,i.params)}}}}),St={name:on,rule:Jr};var Te=require("@typescript-eslint/utils"),Gr=Te.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ln="prefer-named-functions",an=new Map,Zr=Gr({name:ln,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let r=an.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),an.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===Te.AST_NODE_TYPES.ArrowFunctionExpression&&r.id.type===Te.AST_NODE_TYPES.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==Te.AST_NODE_TYPES.BlockStatement)return;let l=r.parent,o=r.init.params,i=r.init.body,a=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(l,`${a.async?"async ":""}function ${s}(${o.map(p=>e.sourceCode.getText(p)).join(", ")||""}) ${e.sourceCode.getText(i)}`)}]})}}}}}),Tt={name:ln,rule:Zr};var N=require("@typescript-eslint/utils");var Qr=j({disallowedFunctions:z(j({name:F(),allowUsingWithArgs:P(oe()),hookAlternative:P(F()),message:P(F()),allowUseInside:P(z(F()))}))});function Le(e){return/^use[A-Z]/.test(e)}function cn(e){return/^[A-Z]/.test(e)}function ei(e){return e.type===N.AST_NODE_TYPES.Identifier?Le(e.name):e.type===N.AST_NODE_TYPES.MemberExpression&&e.property.type===N.AST_NODE_TYPES.Identifier?Le(e.property.name):!1}function pn(e,t){return e.type===N.AST_NODE_TYPES.Identifier?e.name===t:e.type===N.AST_NODE_TYPES.MemberExpression&&e.object.type===N.AST_NODE_TYPES.Identifier&&e.property.type===N.AST_NODE_TYPES.Identifier?e.object.name==="React"&&e.property.name===t:!1}function un(e){return!!(e.parent&&e.parent.type===N.AST_NODE_TYPES.CallExpression&&pn(e.parent.callee,"forwardRef"))}function fn(e){return!!(e.parent&&e.parent.type===N.AST_NODE_TYPES.CallExpression&&pn(e.parent.callee,"memo"))}function ht(e){if(e.type===N.AST_NODE_TYPES.FunctionDeclaration||e.type===N.AST_NODE_TYPES.FunctionExpression&&e.id)return e.id||void 0;if(e.type===N.AST_NODE_TYPES.FunctionExpression||e.type===N.AST_NODE_TYPES.ArrowFunctionExpression){if(e.parent.type===N.AST_NODE_TYPES.VariableDeclarator&&e.parent.init===e)return e.parent.id;if(e.parent.type===N.AST_NODE_TYPES.AssignmentExpression&&e.parent.right===e&&e.parent.operator==="=")return e.parent.left;if(e.parent.type===N.AST_NODE_TYPES.Property&&e.parent.value===e&&!e.parent.computed)return e.parent.key;if(e.parent.type===N.AST_NODE_TYPES.AssignmentPattern&&e.parent.right===e)return e.parent.left}}function ti(e){let t=e.parent,n=!1;for(;t;){if(t.type===N.AST_NODE_TYPES.FunctionDeclaration||t.type===N.AST_NODE_TYPES.FunctionExpression||t.type===N.AST_NODE_TYPES.ArrowFunctionExpression){let r=ht(t);if(r&&r.type===N.AST_NODE_TYPES.Identifier){if(cn(r.name)||Le(r.name))return!n;n=!0}else{if(un(t)||fn(t))return!n;if(t.parent.type===N.AST_NODE_TYPES.CallExpression){let s=t.parent;ei(s.callee)||(n=!0)}else t.parent.type===N.AST_NODE_TYPES.JSXExpressionContainer||(n=!0)}}t=t.parent}return!1}function mn(e){return e.callee.type===N.AST_NODE_TYPES.Identifier?e.callee.name:e.callee.type===N.AST_NODE_TYPES.MemberExpression&&e.callee.property.type===N.AST_NODE_TYPES.Identifier?e.callee.property.name:null}function ni(e,t){if(!t.length)return!1;let n=e.parent;for(;n;){if(n.type===N.AST_NODE_TYPES.FunctionDeclaration||n.type===N.AST_NODE_TYPES.FunctionExpression||n.type===N.AST_NODE_TYPES.ArrowFunctionExpression){let r=ht(n);if(r&&r.type===N.AST_NODE_TYPES.Identifier&&t.includes(r.name))return!0}else if(n.type===N.AST_NODE_TYPES.CallExpression){let r=mn(n);if(r&&t.includes(r))return!0}n=n.parent}return!1}function ri(e){return e.arguments.length>0&&!e.arguments.every(t=>t.type===N.AST_NODE_TYPES.Identifier&&t.name==="undefined")}function ii(e,t){let n=!1,r=e.parent;for(;r;){if(r.type===N.AST_NODE_TYPES.FunctionDeclaration||r.type===N.AST_NODE_TYPES.FunctionExpression||r.type===N.AST_NODE_TYPES.ArrowFunctionExpression){let s=ht(r);if(s&&s.type===N.AST_NODE_TYPES.Identifier){if(cn(s.name)||Le(s.name)){n=!0;break}}else if(un(r)||fn(r)){n=!0;break}}r=r.parent}return n?t.length===0?ti(e):!ni(e,t):!1}var Et=fe({name:"prefer-react-hook-alternative",meta:{type:"suggestion",docs:{description:"Prefer hook alternatives for certain functions in React components and hooks"},messages:{preferHookAlternative:"This function should not be used in react{{message}}."},schema:[Qr],hasSuggestions:!0},defaultOptions:[{disallowedFunctions:[]}],create(e,[t]){let{disallowedFunctions:n}=t,r=new Map(n.map(s=>[s.name,s]));return{CallExpression(s){let l=mn(s);if(!l)return;let o=r.get(l);if(!o||o.allowUsingWithArgs&&ri(s))return;let i=o.allowUseInside||[];ii(s,i)&&e.report({node:s,messageId:"preferHookAlternative",data:{message:o.message?` ${o.message}`:` use ${o.hookAlternative} instead`},suggest:o.hookAlternative?[{messageId:"preferHookAlternative",data:{message:`Replace with ${o.hookAlternative}`,hookAlternative:o.hookAlternative},fix:a=>{let c=o.hookAlternative;return s.callee.type===N.AST_NODE_TYPES.Identifier?a.replaceText(s.callee,c):s.callee.type===N.AST_NODE_TYPES.MemberExpression&&s.callee.property.type===N.AST_NODE_TYPES.Identifier?a.replaceText(s.callee.property,c):null}}]:[]})}}}});var B=require("@typescript-eslint/utils");var si=B.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),yn="prefer-single-line-if",oi=j({maxLineLength:P(Z()),maxNonSimpleConditionLength:P(Z())}),ai=si({name:yn,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:[oi]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==B.AST_NODE_TYPES.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let l=r.consequent.body[0];if(l.type===B.AST_NODE_TYPES.ReturnStatement){if(!Sn(l))return}else if(!(l.type===B.AST_NODE_TYPES.ContinueStatement||l.type===B.AST_NODE_TYPES.BreakStatement))return;if(r.test.type===B.AST_NODE_TYPES.LogicalExpression||r.test.type===B.AST_NODE_TYPES.ConditionalExpression)return;let o;if(t.maxNonSimpleConditionLength){let u=dn(r.test);if(!u&&r.test.type===B.AST_NODE_TYPES.UnaryExpression&&r.test.operator==="!"){let g=r.test.argument;dn(g)&&(u=!0)}if(u&&(o=n.getText(r.test),o.length>t.maxNonSimpleConditionLength))return}o||(o=n.getText(r.test));let i=n.getText(l);if(o.includes(`
|
|
15
|
-
`))return;let a=n.getTokenAfter(r);if(a&&a.type===B.AST_TOKEN_TYPES.Punctuator&&a.value==="}"){let u=n.getTokenAfter(a);if(u&&u.type===B.AST_TOKEN_TYPES.Keyword&&(u.value==="else"||u.value==="catch"))return}let c=li(n,r),p=`if (${o}) ${i}`;t.maxLineLength&&p.length+c.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:u=>u.replaceText(r,p)})}}}});function dn(e){return e.type===B.AST_NODE_TYPES.CallExpression||e.type===B.AST_NODE_TYPES.BinaryExpression||e.type===B.AST_NODE_TYPES.MemberExpression&&gn(e)}function gn(e){return e.object.type===B.AST_NODE_TYPES.MemberExpression?gn(e.object):e.object.type!==B.AST_NODE_TYPES.Identifier}function li(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function Sn(e){if(!e.argument)return!0;let t=e.argument;return t.type===B.AST_NODE_TYPES.ArrayExpression&&t.elements.length===0||t.type===B.AST_NODE_TYPES.ObjectExpression&&t.properties.length===0||t.type===B.AST_NODE_TYPES.Literal||t.type===B.AST_NODE_TYPES.Identifier||t.type===B.AST_NODE_TYPES.TemplateLiteral||t.type===B.AST_NODE_TYPES.TaggedTemplateExpression?!0:t.type===B.AST_NODE_TYPES.CallExpression?t.arguments.length===0:t.type===B.AST_NODE_TYPES.UnaryExpression?Sn(t):!1}var bt={name:yn,rule:ai};var J=require("@typescript-eslint/utils");var ci=J.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Tn="react-compiler-migration",pi=j({disallowHooks:P(z(j({name:F(),replacement:F()}))),disallowMethods:P(z(j({name:F(),replacement:P(F()),requireTrueProp:P(F())})))}),ui=/eslint +react-compiler\/react-compiler: +\["error/;function fi(e){return e.type===J.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===J.AST_NODE_TYPES.MemberExpression&&e.property.type===J.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var mi=ci({name:Tn,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:[pi]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(ui.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let s=null,l=null;if(r.callee.type===J.AST_NODE_TYPES.Identifier?(s=r.callee.name,l=r.callee):r.callee.type===J.AST_NODE_TYPES.MemberExpression&&r.callee.property.type===J.AST_NODE_TYPES.Identifier&&(s=r.callee.property.name,l=r.callee.property),s){let o=t.disallowHooks.find(i=>i.name===s);o&&l&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:o.name,replacement:o.replacement},suggest:[{messageId:"replace",data:{replacement:o.replacement},fix:i=>i.replaceText(l,o.replacement)}]})}}if(t.disallowMethods?.length&&fi(r.callee)){for(let s of r.arguments)if(s.type===J.AST_NODE_TYPES.ObjectExpression){for(let l of s.properties)if(l.type===J.AST_NODE_TYPES.Property&&l.key.type===J.AST_NODE_TYPES.Identifier){let o=l.key.name,i=t.disallowMethods.find(a=>a.name===o);if(i){if(i.requireTrueProp){let a=i.requireTrueProp,c=!1;for(let p of s.properties)if(p.type===J.AST_NODE_TYPES.Property&&p.key.type===J.AST_NODE_TYPES.Identifier&&p.key.name===a&&p.value.type===J.AST_NODE_TYPES.Literal&&p.value.value===!0){c=!0;break}if(!c){e.report({node:l,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:i.name,requireTrueProp:a}});continue}}i.replacement&&e.report({node:l,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:i.name,replacement:i.replacement},suggest:[{messageId:"replace",data:{replacement:i.replacement},fix:a=>a.replaceText(l.key,i.replacement)}]})}}}}}}:{}}}),xt={name:Tn,rule:mi};var _e=require("@typescript-eslint/utils"),di=_e.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),hn="require-description",yi=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,gi=/^eslint-disable-(next-)?line$/u,Si=di({name:hn,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let l=Ti(s);l!=null&&(r.has(l.kind)||l.description||e.report({loc:Ei(s.loc),messageId:"missingDescription"}))}}}}}),En={name:hn,rule:Si};function Ti(e){let{text:t,description:n}=hi(e.value);if(!t)return null;let r=yi.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let l=gi.test(s);if(e.type===_e.TSESTree.AST_TOKEN_TYPES.Line&&!l||l&&e.loc.start.line!==e.loc.end.line)return null;let o=t.slice(r.index+s.length);return{kind:s,value:o.trim(),description:n}}function hi(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Ei(e){return{start:{line:e.start.line,column:-1},end:e.end}}function In(e){return/^use[A-Z0-9]/.test(e)}function Me(e){return e.type==="Identifier"?In(e.name):e.type==="MemberExpression"&&!e.computed&&Me(e.property)?e.object.type==="Identifier":!1}function Cn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function wn(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Rn(e){return!!(e.parent&&e.parent.callee&&wn(e.parent.callee,"forwardRef"))}function vn(e){return!!(e.parent&&e.parent.callee&&wn(e.parent.callee,"memo"))}function It(e){for(;e;){let t=An(e);if(t&&(Cn(t)||Me(t))||Rn(e)||vn(e))return!0;e=e.parent}return!1}function bn(e){return!1}function Ct(e){return!1}var bi=/eslint +react-compiler\/react-compiler: +\["error/,kn={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(bi.test(a.value))return{CallExpression(c){let p=null;c.callee.name==="useMemo"?p="useMemo":c.callee.name==="useCallback"&&(p="useCallback"),p&&e.report({node:c,message:`"${p}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?a=>t(a):a=>e.sourceCode.getText(a),n=typeof e.getScope=="function"?()=>n():a=>e.sourceCode.getScope(a),r=null,s=[],l=[],o=new WeakSet;function i(a){for(let c of a.references){let p=c.identifier.parent;if(p.type==="VariableDeclarator"&&p.init&&p.init.type==="CallExpression"&&p.init.callee&&bn(p.init.callee))for(let u of c.resolved.references)u!==c&&o.add(u.identifier)}}return{onCodePathSegmentStart:a=>l.push(a),onCodePathSegmentEnd:()=>l.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(a,c){let p=s.pop();if(p.size===0)return;let u=new Set;function g(m,R){let{cache:v}=g,A=v.get(m.id),O=new Set(R);if(O.has(m.id)){let x=[...O],U=x.slice(x.indexOf(m.id)+1);for(let Y of U)u.add(Y);return BigInt("0")}if(O.add(m.id),A!==void 0)return A;if(a.thrownSegments.includes(m))A=BigInt("0");else if(m.prevSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let x of m.prevSegments)A+=g(x,O)}return m.reachable&&A===BigInt("0")?v.delete(m.id):v.set(m.id,A),A}function S(m,R){let{cache:v}=S,A=v.get(m.id),O=new Set(R);if(O.has(m.id)){let x=Array.from(O),U=x.slice(x.indexOf(m.id)+1);for(let Y of U)u.add(Y);return BigInt("0")}if(O.add(m.id),A!==void 0)return A;if(a.thrownSegments.includes(m))A=BigInt("0");else if(m.nextSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let x of m.nextSegments)A+=S(x,O)}return v.set(m.id,A),A}function E(m){let{cache:R}=E,v=R.get(m.id);if(v===null)return 1/0;if(v!==void 0)return v;if(R.set(m.id,null),m.prevSegments.length===0)v=1;else{v=1/0;for(let A of m.prevSegments){let O=E(A);O<v&&(v=O)}v+=1}return R.set(m.id,v),v}g.cache=new Map,S.cache=new Map,E.cache=new Map;let T=S(a.initialSegment),w=An(c),h=It(c),_=w?Cn(w)||Me(w):Rn(c)||vn(c),d=1/0;for(let m of a.finalSegments){if(!m.reachable)continue;let R=E(m);R<d&&(d=R)}for(let[m,R]of p){if(!m.reachable)continue;let v=m.nextSegments.length===0?d<=E(m):d<E(m),A=g(m)*S(m),O=u.has(m.id);for(let x of R)if(O&&!Ct(x)&&e.report({node:x,message:`React Hook "${t(x)}" 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.`}),_){if(c.async&&e.report({node:x,message:`React Hook "${t(x)}" cannot be called in an async function.`}),!O&&A!==T&&!Ct(x)){let Y=`React Hook "${t(x)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(v?" Did you accidentally call a React Hook after an early return?":"");e.report({node:x,message:Y})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let U=`React Hook "${t(x)}" 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:x,message:U})}else if(w){let U=`React Hook "${t(x)}" is called in function "${t(w)}" 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:x,message:U})}else if(c.type==="Program"){let U=`React Hook "${t(x)}" 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:x,message:U})}else if(h&&!Ct(x)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let Y=c.parent;if(Y.parent.type==="VariableDeclarator"&&In(Y.parent.id.name))return}let U=`React Hook "${t(x)}" 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:x,message:U})}}},CallExpression(a){if(Me(a.callee)){let c=xn(s),p=xn(l),u=c.get(p);u||(u=[],c.set(p,u)),u.push(a.callee)}a.callee.type==="Identifier"&&(a.callee.name==="useEffect"||bn(a.callee))&&a.arguments.length>0&&(r=a)},Identifier(a){r==null&&o.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===r&&(r=null)},FunctionDeclaration(a){It(a)&&i(n(a))},ArrowFunctionExpression(a){It(a)&&i(n(a))}}}};function An(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 xn(e){return e[e.length-1]}var On={[St.name]:St.rule,[nt.name]:nt.rule,[tt.name]:tt.rule,"rules-of-hooks":kn,"exhaustive-deps":_t,"require-description":En.rule,[rt.name]:rt.rule,[st.name]:st.rule,[Tt.name]:Tt.rule,[qe.name]:qe.rule,[et.name]:et.rule,[pt.name]:pt.rule,[bt.name]:bt.rule,[ct.name]:ct.rule,[it.name]:it.rule,[Ke.name]:Ke.rule,[xt.name]:xt.rule,[Be.name]:Be.rule,[Qe.name]:Qe.rule,[ft.name]:ft.rule,[dt.name]:dt.rule,[yt.name]:yt.rule,[mt.name]:mt.rule,[Et.name]:Et.rule};var xi={rules:On};0&&(module.exports={extendedLintPlugin});
|
|
14
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let R=a.acquire(h),A=new Set,O=null;{let f=R.upper;for(;f&&(A.add(f),f.type!=="function");)f=f.upper;if(!f)return;O=f}let x=Array.isArray;function U(f){if(!x(f.defs))return!1;let y=f.defs[0];if(y==null||y.node.type!=="VariableDeclarator")return!1;let b=y.node.init;if(b==null)return!1;for(;b.type==="TSAsExpression";)b=b.expression;let I=y.node.parent;if(I==null&&(Ze(O.block,y.node.id),I=y.node.parent,I==null))return!1;if(I.kind==="const"&&b.type==="Literal"&&(typeof b.value=="string"||typeof b.value=="number"||b.value===null))return!0;if(b.type!=="CallExpression")return!1;let k=b.callee;if(k.type==="MemberExpression"&&k.object.name==="React"&&k.property!=null&&!k.computed&&(k=k.property),k.type!=="Identifier")return!1;let C=y.node.id,{name:D}=k;if(D==="useRef"&&C.type==="Identifier")return!0;if(ar(k)&&C.type==="Identifier"){for(let L of f.references)L!==C&&S.add(L.identifier);return!0}else if(D==="useState"||D==="useReducer"){if(C.type==="ArrayPattern"&&C.elements.length===2&&x(f.identifiers)){if(C.elements[1]===f.identifiers[0]){if(D==="useState"){let L=f.references,ee=0;for(let se=0;se<L.length;se++){if(L[se].isWrite()&&ee++,ee>1)return!1;c.set(L[se].identifier,C.elements[0])}}return!0}else if(C.elements[0]===f.identifiers[0]){if(D==="useState"){let L=f.references;for(let ee=0;ee<L.length;ee++)p.add(L[ee].identifier)}return!1}}}else if(D==="useTransition"&&C.type==="ArrayPattern"&&C.elements.length===2&&Array.isArray(f.identifiers)&&C.elements[1]===f.identifiers[0])return!0;return!1}function B(f){if(!x(f.defs))return!1;let y=f.defs[0];if(y==null||y.node==null||y.node.id==null)return!1;let b=y.node,I=O.childScopes,k=null,C;for(C=0;C<I.length;C++){let D=I[C],L=D.block;if(b.type==="FunctionDeclaration"&&L===b||b.type==="VariableDeclarator"&&L.parent===b){k=D;break}}if(k==null)return!1;for(C=0;C<k.through.length;C++){let D=k.through[C];if(D.resolved!=null&&A.has(D.resolved.scope)&&!ie(D.resolved))return!1}return!0}let ie=E(U,u),$e=E(B,g),xe=new Map;function pe(f){let y=f.from,b=!1;for(;y.block!==h;)y.type==="function"&&(b=y.block.parent!=null&&y.block.parent.type==="ReturnStatement"),y=y.upper;return b}let X=new Map,ne=new Map;Ie(R);function Ie(f){for(let y of f.references){if(!y.resolved||!A.has(y.resolved.scope))continue;let b=Ze(h,y.identifier),I=Mt(b),k=ae(I,ne);if(v&&I.type==="Identifier"&&(I.parent.type==="MemberExpression"||I.parent.type==="OptionalMemberExpression")&&!I.parent.computed&&I.parent.property.type==="Identifier"&&I.parent.property.name==="current"&&pe(y)&&xe.set(k,{reference:y,dependencyNode:I}),I.parent.type==="TSTypeQuery"||I.parent.type==="TSTypeReference")continue;let C=y.resolved.defs[0];if(C!=null&&!(C.node!=null&&C.node.init===h.parent)&&C.type!=="TypeParameter")if(X.has(k))X.get(k).references.push(y);else{let D=y.resolved,L=ie(D)||$e(D);X.set(k,{isStable:L,references:[y]})}}for(let y of f.childScopes)Ie(y)}xe.forEach(({reference:f,dependencyNode:y},b)=>{let I=f.resolved.references,k=!1;for(let C=0;C<I.length;C++){let{identifier:D}=I[C],{parent:L}=D;if(L!=null&&L.type==="MemberExpression"&&!L.computed&&L.property.type==="Identifier"&&L.property.name==="current"&&L.parent.type==="AssignmentExpression"&&L.parent.left===L){k=!0;break}}k||i({node:y.parent.property,message:`The ref value '${b}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${b}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Ue=new Set;function Pn(f,y){Ue.has(y)||(Ue.add(y),i({node:f,message:`Assignments to the '${y}' variable from inside React Hook ${n(d)} 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(d)}.`}))}let Ce=new Set;if(X.forEach(({isStable:f,references:y},b)=>{f&&Ce.add(b),y.forEach(I=>{I.writeExpr&&Pn(I.writeExpr,b)})}),Ue.size>0)return;if(!_){let f=null;if(X.forEach(({isStable:y,references:b},I)=>{f||b.forEach(k=>{if(f)return;let C=k.identifier;if(!c.has(C))return;let L=k.from;for(;L.type!=="function";)L=L.upper;L.block===h&&(f=I)})}),f){let{suggestedDependencies:y}=Je({dependencies:X,declaredDependencies:[],stableDependencies:Ce,externalDependencies:new Set,isEffect:!0});i({node:d,message:`React Hook ${m} contains a call to '${f}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+y.join(", ")+`] as a second argument to the ${m} Hook.`,suggest:[{desc:`Add dependencies array: [${y.join(", ")}]`,fix(b){return b.insertTextAfter(h,`, [${y.join(", ")}]`)}}]})}return}let he=[],Ee=new Set;_.type!=="ArrayExpression"?i({node:_,message:`React Hook ${n(d)} 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.`}):_.elements.forEach(f=>{if(f===null)return;if(f.type==="SpreadElement"){i({node:f,message:`React Hook ${n(d)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}S.has(f)&&i({node:f,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(f)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(f)}\``,fix(k){return k.removeRange(f.range)}}]});let y;try{y=ae(f,ne)}catch(k){if(/Unsupported node type/.test(k.message)){f.type==="Literal"?X.has(f.value)?i({node:f,message:`The ${f.raw} literal is not a valid dependency because it never changes. Did you mean to include ${f.value} in the array instead?`}):i({node:f,message:`The ${f.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):i({node:f,message:`React Hook ${n(d)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw k}let b=f;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let I=!O.through.some(k=>k.identifier===b);he.push({key:y,node:f}),I||Ee.add(y)});let{suggestedDependencies:Fn,unnecessaryDependencies:we,missingDependencies:ue,duplicateDependencies:wt}=Je({dependencies:X,declaredDependencies:he,stableDependencies:Ce,externalDependencies:Ee,isEffect:v}),Re=Fn;if(wt.size+ue.size+we.size===0){if(t)return;rr({declaredDependencies:he,declaredDependenciesNode:_,componentScope:O,scope:R}).forEach(({construction:y,isUsedOutsideOfHook:b,depType:I})=>{let k=I==="function"?"useCallback":"useMemo",C=I==="function"?"definition":"initialization",D=`wrap the ${C} of '${y.name.name}' in its own ${k}() Hook.`,L=b?`To fix this, ${D}`:`Move it inside the ${m} callback. Alternatively, ${D}`,ee=I==="conditional"||I==="logical expression"?"could make":"makes",se=`The '${y.name.name}' ${I} ${ee} the dependencies of ${m} Hook (at line ${_.loc.start.line}) change on every render. ${L}`,Rt;b&&y.type==="Variable"&&I==="function"&&(Rt=[{desc:`Wrap the ${C} of '${y.name.name}' in its own ${k}() Hook.`,fix(vt){let[Dn,jn]=k==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[vt.insertTextBefore(y.node.init,Dn),vt.insertTextAfter(y.node.init,jn)]}}]),i({node:y.node,message:se,suggest:Rt})});return}!v&&ue.size>0&&(Re=Je({dependencies:X,declaredDependencies:[],stableDependencies:Ce,externalDependencies:Ee,isEffect:v}).suggestedDependencies);function Nn(){if(he.length===0)return!0;let f=he.map(b=>b.key),y=f.slice().sort();return f.join(",")===y.join(",")}Nn()&&Re.sort();function Ve(f){let y=f.split("."),b="";for(let I=0;I<y.length;I++){if(I!==0){let k=y.slice(0,I+1).join("."),C=ne.get(k)===!0;b+=C?"?.":"."}b+=y[I]}return b}function We(f,y,b,I){return f.size===0?null:(f.size>1?"":y+" ")+b+" "+(f.size>1?"dependencies":"dependency")+": "+sr(Array.from(f).sort().map(k=>"'"+Ve(k)+"'"))+`. Either ${I} ${f.size>1?"them":"it"} or remove the dependency array.`}let re="";if(we.size>0){let f=null;if(Array.from(we.keys()).forEach(y=>{f===null&&y.endsWith(".current")&&(f=y)}),f!==null)re=` Mutable values like '${f}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(Ee.size>0){let y=Array.from(Ee)[0];R.set.has(y)||(re=` Outer scope values like '${y}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!re&&ue.has("props")){let f=X.get("props");if(f==null)return;let y=f.references;if(!Array.isArray(y))return;let b=!0;for(let I=0;I<y.length;I++){let k=y[I],C=Ze(O.block,k.identifier);if(!C){b=!1;break}let D=C.parent;if(D==null){b=!1;break}if(D.type!=="MemberExpression"&&D.type!=="OptionalMemberExpression"){b=!1;break}}b&&(re=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${m} call and refer to those specific props inside ${n(d)}.`)}if(!re&&ue.size>0){let f=null;ue.forEach(y=>{if(f)return;let b=O.set.get(y),I=X.get(y);if(I.references[0].resolved!==b)return;let k=b.defs[0];if(k==null||k.name==null||k.type!=="Parameter")return;let C=!1,D;for(let L=0;L<I.references.length;L++)if(D=I.references[L].identifier,D!=null&&D.parent!=null&&(D.parent.type==="CallExpression"||D.parent.type==="OptionalCallExpression")&&D.parent.callee===D){C=!0;break}C&&(f=y)}),f!==null&&(re=` If '${f}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!re&&ue.size>0){let f=null;if(ue.forEach(y=>{if(f!==null)return;let I=X.get(y).references,k,C;for(let D=0;D<I.length;D++){for(k=I[D].identifier,C=k.parent;C!=null&&C!==O.block;){if(C.type==="CallExpression"){let L=c.get(C.callee);if(L!=null){if(L.name===y)f={missingDep:y,setter:C.callee.name,form:"updater"};else if(p.has(k))f={missingDep:y,setter:C.callee.name,form:"reducer"};else{let ee=I[D].resolved;if(ee!=null){let se=ee.defs[0];se!=null&&se.type==="Parameter"&&(f={missingDep:y,setter:C.callee.name,form:"inlineReducer"})}}break}}C=C.parent}if(f!==null)break}}),f!==null)switch(f.form){case"reducer":re=` You can also replace multiple useState variables with useReducer if '${f.setter}' needs the current value of '${f.missingDep}'.`;break;case"inlineReducer":re=` If '${f.setter}' needs the current value of '${f.missingDep}', you can also switch to useReducer instead of useState and read '${f.missingDep}' in the reducer.`;break;case"updater":re=` You can also do a functional update '${f.setter}(${f.missingDep.slice(0,1)} => ...)' if you only need '${f.missingDep}' in the '${f.setter}' call.`;break;default:throw new Error("Unknown case.")}}i({node:_,message:`React Hook ${n(d)} has `+(We(ue,"a","missing","include")||We(we,"an","unnecessary","exclude")||We(wt,"a","duplicate","omit"))+re,suggest:[{desc:`Update the dependencies array to be: [${Re.map(Ve).join(", ")}]`,fix(f){return f.replaceText(_,`[${Re.map(Ve).join(", ")}]`)}}]})}function w(h){let _=ir(h.callee,o);if(_===-1)return;let d=h.arguments[_],m=h.callee,v=$t(m).name,R=h.arguments[_+1],A=/Effect($|[^a-z])/g.test(v);if(!d){i({node:m,message:`React Hook ${v} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!A)){if(!R&&!A){(v==="useMemo"||v==="useCallback")&&i({node:m,message:`React Hook ${v} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(d.type){case"FunctionExpression":case"ArrowFunctionExpression":T(d,R,m,v,A);return;case"Identifier":if(!R||R.elements&&R.elements.some(U=>U&&U.type==="Identifier"&&U.name===d.name))return;let O=r(h).set.get(d.name);if(O==null||O.defs==null)return;let x=O.defs[0];if(!x||!x.node||x.type!=="Variable"&&x.type!=="FunctionName")break;switch(x.node.type){case"FunctionDeclaration":T(x.node,R,m,v,A);return;case"VariableDeclarator":let U=x.node.init;if(!U)break;switch(U.type){case"ArrowFunctionExpression":case"FunctionExpression":T(U,R,m,v,A);return}break}break;default:i({node:m,message:`React Hook ${v} received a function whose dependencies are unknown. Pass an inline function instead.`});return}i({node:m,message:`React Hook ${v} has a missing dependency: '${d.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${d.name}]`,fix(O){return O.replaceText(R,`[${d.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let h of e.sourceCode.getAllComments())if(nr.test(h.value))return t=!0,{CallExpression:_=>w(_,!0)}}return{CallExpression:h=>w(h)}}};function Je({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:s}){let l=o();function o(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,w)=>{let h=i(l,w);h.isUsed=!0,a(l,w,_=>{_.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let w=i(l,T);w.isSatisfiedRecursively=!0}),n.forEach(T=>{let w=i(l,T);w.isSatisfiedRecursively=!0});function i(T,w){let h=w.split("."),_=T;for(let d of h){let m=_.children.get(d);m||(m=o(),_.children.set(d,m)),_=m}return _}function a(T,w,h){let _=w.split("."),d=T;for(let m of _){let v=d.children.get(m);if(!v)return;h(v),d=v}}let c=new Set,p=new Set;u(l,c,p,T=>T);function u(T,w,h,_){T.children.forEach((d,m)=>{let v=_(m);if(d.isSatisfiedRecursively){d.isSubtreeUsed&&h.add(v);return}if(d.isUsed){w.add(v);return}u(d,w,h,R=>v+"."+R)})}let g=[],S=new Set,E=new Set;return t.forEach(({key:T})=>{p.has(T)?g.indexOf(T)===-1?g.push(T):E.add(T):S.add(T)}),c.forEach(T=>{g.push(T)}),{suggestedDependencies:g,unnecessaryDependencies:S,duplicateDependencies:E,missingDependencies:c}}function me(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 me(e.consequent)!=null||me(e.alternate)!=null?"conditional":null;case"LogicalExpression":return me(e.left)!=null||me(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return me(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return me(e.expression);case"TSAsExpression":return me(e.expression)}return null}function rr({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let s=e.map(({key:o})=>{let i=n.variables.find(c=>c.name===o);if(i==null)return null;let a=i.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 c=me(a.node.init);if(c!=null)return[i,c]}return a.type==="FunctionName"&&a.node.type==="FunctionDeclaration"?[i,"function"]:a.type==="ClassName"&&a.node.type==="ClassDeclaration"?[i,"class"]:null}).filter(Boolean);function l(o){let i=!1;for(let a=0;a<o.references.length;a++){let c=o.references[a];if(c.writeExpr){if(i)return!0;i=!0;continue}let p=c.from;for(;p!==r&&p!=null;)p=p.upper;if(p!==r&&!Ut(t,c.identifier))return!0}return!1}return s.map(([o,i])=>({construction:o.defs[0],depType:i,isUsedOutsideOfHook:l(o)}))}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 Ge(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function ae(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=ae(e.object,t),r=ae(e.property,null),s=`${n}.${r}`;return Ge(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=ae(e.object,t),r=ae(e.property,null),s=`${n}.${r}`;return Ge(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=ae(n.object,t),s=ae(n.property,null),l=`${r}.${s}`;return Ge(n,t,l),l}else throw new Error(`Unsupported node type: ${e.type}`)}function $t(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function ir(e,t){let n=$t(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let r;try{r=ae(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(r)?0:-1}else return-1}}function Ze(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),or(r,t))return r;if(Ut(r,t))for(let[s,l]of Object.entries(r))s!=="parent"&&(Lt(l)?(l.parent=r,n.push(l)):Array.isArray(l)&&l.forEach(o=>{Lt(o)&&(o.parent=r,n.push(o))}))}return null}function sr(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function Lt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function or(e,t){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===t.type&&e.name===t.name&&e.range[0]===t.range[0]&&e.range[1]===t.range[1]}function Ut(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function ar(e){return!1}var de=require("@typescript-eslint/utils");var K=He(require("typescript")),lr=de.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="improved-no-unnecessary-condition",cr=j({}),pr=["string","number","bigint","boolean","symbol","undefined","object","function","never"],ur=new Set(pr),Qe={name:Vt,rule:lr({name:Vt,meta:{type:"suggestion",docs:{description:"Extends checks of `no-unnecessary-condition` rule"},messages:{unnecessaryTypeofCondition:'This condition is unnecessary. The type of "{{name}}" is always "{{type}}".',alwaysFalseTypeofCondition:'This condition will always be false. The type of "{{name}}" is "{{actualType}}" so the condition has no overlap with "{{conditionType}}".'},schema:[cr]},defaultOptions:[{}],create(e){let t=de.ESLintUtils.getParserServices(e,!0),n=t.program?.getTypeChecker();if(!n||!t.program)throw new Error("TypeScript services or program not available");function r(i){return i.type===de.AST_NODE_TYPES.UnaryExpression&&i.operator==="typeof"}function s(i){return i.flags&K.default.TypeFlags.Any||i.flags&K.default.TypeFlags.Unknown?null:i.flags&K.default.TypeFlags.StringLike?["string"]:i.flags&K.default.TypeFlags.NumberLike?["number"]:i.flags&K.default.TypeFlags.BigIntLike?["bigint"]:i.flags&K.default.TypeFlags.BooleanLike?["boolean"]:i.flags&K.default.TypeFlags.ESSymbolLike?["symbol"]:i.flags&K.default.TypeFlags.Undefined||i.flags&K.default.TypeFlags.Void?["undefined"]:i.flags&K.default.TypeFlags.Null?["object"]:i.getCallSignatures().length>0?["function"]:i.flags&K.default.TypeFlags.Object?i.getProperties().length===0?["string","number","bigint","boolean","symbol","object","function"]:["object"]:i.flags&K.default.TypeFlags.NonPrimitive?["object"]:i.flags&K.default.TypeFlags.Never?["never"]:null}function l(i){if(!n)return null;let a=t.esTreeNodeToTSNodeMap.get(i),c=n.getTypeAtLocation(a.expression);if(c.flags&K.default.TypeFlags.Any||c.flags&K.default.TypeFlags.Unknown)return null;let p=[];if(c.isUnion()){for(let g of c.types){let S=s(g);if(S)p.push(...S);else return null}return p}let u=s(c);return u?(p.push(...u),p):null}function o(i){if(!(i.operator==="==="||i.operator==="!=="))return;let c=null,p=null;if(r(i.left)?(c=i.left,p=i.right.type===de.AST_NODE_TYPES.Literal&&typeof i.right.value=="string"?i.right.value:null):r(i.right)&&(c=i.right,p=i.left.type===de.AST_NODE_TYPES.Literal&&typeof i.left.value=="string"?i.left.value:null),!c||!p||!fr(p,ur))return;let u=l(c);if(!u)return;let g=i.operator==="!==",S=u.includes(p);u.length===1?S&&!g?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ge(c,e),type:p}}):!S&&g?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ge(c,e),type:Array.from(u)[0]}}):!S&&!g?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ge(c,e),actualType:Oe(u),conditionType:p}}):S&&g&&e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ge(c,e),actualType:Oe(u),conditionType:p}}):!S&&!g?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:ge(c,e),actualType:Oe(u),conditionType:p}}):!S&&g&&e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:ge(c,e),type:Oe(u)}})}return{BinaryExpression:o}}})};function Oe(e){return Array.from(new Set(e)).join(" | ")||"never"}function ge(e,t){let n=e.argument;return n.type===de.AST_NODE_TYPES.Identifier?n.name:t.sourceCode.getText(n)}function fr(e,t){return t.has(e)}var Pe=require("@typescript-eslint/utils");var mr=Pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Wt="no-call-with-explicit-generics",dr=j({functions:Y(F())}),yr=mr({name:Wt,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[dr]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:s}=r;s.type===Pe.AST_NODE_TYPES.Identifier&&n.has(s.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),et={name:Wt,rule:yr};var ye=require("@typescript-eslint/utils"),gr=ye.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ht="no-call-with-inferred-generics",Sr=gr({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(r=>[r.name,r]));return{CallExpression(r){let{callee:s}=r;if(s.type!==ye.AST_NODE_TYPES.Identifier)return;let l=n.get(s.name);if(!l)return;let{minGenerics:o=1,allowAny:i,disallowTypes:a=t.disallowTypes}=l;(r.typeArguments?.params.length||0)<(o||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:o||0}}),!(i&&!a)&&r.typeArguments?.params?.some(p=>!i&&p.type===ye.AST_NODE_TYPES.TSAnyKeyword||a&&p.type===ye.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===ye.AST_NODE_TYPES.Identifier&&a.includes(p.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),tt={name:Ht,rule:Sr};var be=require("@typescript-eslint/utils"),Tr=be.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Yt="no-commented-out-code",hr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Er=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],br=Tr({name:Yt,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of hr)if(r.startsWith(s))return{wrongPattern:s};for(let s of Er)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let s of r)if(s.type===be.TSESTree.AST_TOKEN_TYPES.Line||s.type===be.TSESTree.AST_TOKEN_TYPES.Block){let l=t(s.value);l&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:l.wrongPattern}})}}}}}),nt={name:Yt,rule:br};var Fe=require("@typescript-eslint/utils"),xr=Fe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),zt="no-default-export",Ir=xr({name:zt,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===Fe.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),rt={name:zt,rule:Ir};var Bt=require("@typescript-eslint/utils"),Cr=Bt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qt="no-leaked-text-in-jsx",wr=[",",";","[","]","(",")"],Rr=Cr({name:qt,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";wr.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),it={name:qt,rule:Rr};var le=require("@typescript-eslint/utils"),vr=le.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Kt="no-non-camel-case-functions",kr=/^[a-z][a-zA-Z0-9]*$/;function Xt(e){return e.typeName.type===le.AST_NODE_TYPES.TSQualifiedName&&e.typeName.left.type===le.AST_NODE_TYPES.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===le.AST_NODE_TYPES.Identifier&&e.typeName.right.name==="Element"}var Ar=vr({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&&!kr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===le.AST_NODE_TYPES.TSTypeReference?Xt(n):n.type===le.AST_NODE_TYPES.TSUnionType&&n.types.some(s=>s.type===le.AST_NODE_TYPES.TSTypeReference&&Xt(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),st={name:Kt,rule:Ar};var V=require("@typescript-eslint/utils");var ot=require("@typescript-eslint/utils");function Se(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:Se(e.parent,t,n===1/0?n:n-1)}function*at(e){yield e,e.parent&&(yield*at(e.parent))}function lt(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function Jt(e,t,n){let s=n.getDeclaredVariables(e).find(l=>l.name===t||l.identifiers[0]?.parent.type===ot.AST_NODE_TYPES.Property&&l.identifiers[0]?.parent.key.type===ot.AST_NODE_TYPES.Identifier&&l.identifiers[0]?.parent.key.name===t);return s?s.references.filter(l=>!l.init):[]}var Or=V.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Gt="no-optional-root-props",Pr=Or({name:Gt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let l=e.sourceCode.getDeclaredVariables(r)[0];if(!l||l.references.length!==1)return!1;let o=l.references[0];if(!o)return!1;for(let i of at(o.identifier)){if("returnType"in i||i.type===V.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let a=i.parent;if(!a)return!1;if(a.type===V.TSESTree.AST_NODE_TYPES.TSTypeParameterInstantiation&&a.parent.type===V.TSESTree.AST_NODE_TYPES.TSTypeReference&&a.parent.typeName.type===V.TSESTree.AST_NODE_TYPES.Identifier&&a.parent.typeName.name==="FC"){let p=Se(a.parent.parent,V.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!p)return!1;let u=Ne(p,e.sourceCode);return u?!(u.parent.type===V.TSESTree.AST_NODE_TYPES.CallExpression&&u.parent.callee.type===V.TSESTree.AST_NODE_TYPES.Identifier&&u.parent.callee.name==="memo"):!1}if(i.type===V.TSESTree.AST_NODE_TYPES.AssignmentPattern)return!1;if(a.type===V.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression){let c=Se(a,V.TSESTree.AST_NODE_TYPES.VariableDeclaration);return c?!!Ne(c,e.sourceCode):!1}if(a.type===V.TSESTree.AST_NODE_TYPES.FunctionDeclaration)return!!Ne(a,e.sourceCode)}return!1}function n(r){r.key.type!==V.TSESTree.AST_NODE_TYPES.Identifier||!r.optional||e.report({node:r.key,messageId:"optionalNotAllowed",data:{propertyName:r.key.name},suggest:[{messageId:"suggestion",fix:s=>{let l=Se(r,V.TSESTree.AST_NODE_TYPES.TSPropertySignature);if(!l)return null;let o=e.sourceCode.getText(l);return s.replaceText(l,o.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(r){if(r.typeAnnotation.type===V.TSESTree.AST_NODE_TYPES.TSTypeLiteral&&!(De(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===V.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(De(r)||!t(r)))for(let s of r.body.body)s.type===V.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSTypeReference(r){if(r.typeName.type!==V.TSESTree.AST_NODE_TYPES.Identifier||r.typeName.name!=="FC"||!r.typeArguments?.params[0])return;let s=r.typeArguments.params[0];if(s.type!==V.TSESTree.AST_NODE_TYPES.TSTypeLiteral)return;let l=Se(r.parent,V.TSESTree.AST_NODE_TYPES.VariableDeclaration,4);if(!l)return;let o=Ne(l,e.sourceCode);if(!(!o||o.parent.type===V.TSESTree.AST_NODE_TYPES.CallExpression&&o.parent.callee.type===V.TSESTree.AST_NODE_TYPES.Identifier&&o.parent.callee.name==="memo"))for(let a of s.members)a.type===V.TSESTree.AST_NODE_TYPES.TSPropertySignature&&n(a)}}}});function De(e){return e?e.parent?.type===V.TSESTree.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===V.TSESTree.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function Ne(e,t){if(De(e))return;let n;if(e.type===V.TSESTree.AST_NODE_TYPES.VariableDeclaration){if(e.declarations.length!==1)return;e.declarations[0].id.type===V.TSESTree.AST_NODE_TYPES.Identifier&&(n=e.declarations[0].id)}else{if(!e.id)return;n=e.id}if(!n)return;let r=t.getScope(e);e.type===V.TSESTree.AST_NODE_TYPES.FunctionDeclaration&&r.upper&&(r=r.upper);let s=r.variables.find(o=>o.identifiers.includes(n));if(!s)return;let l=s.references.filter(o=>o.identifier!==n);if(!(l.length!==1||!l[0])&&!De(l[0].identifier.parent.parent))return l[0].identifier}var ct={name:Gt,rule:Pr};var Zt=require("@typescript-eslint/utils"),je=He(require("path"));var Fr=Zt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Qt="no-relative-imports",Nr=j({find:F(),replacement:F()}),Dr=j({aliases:Y(Nr),rootDir:P(F()),allowNotFoundAliases:P(oe()),_dev_simulateFileName:P(F())}),jr=Fr({name:Qt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[Dr]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(o){return o.startsWith(".")||o.startsWith("..")}function s(o,i){let a=je.default.dirname(i);return je.default.resolve(a,o)}function l(o){let i=t.rootDir??process.cwd(),a=je.default.relative(i,o);if(a.startsWith("."))return null;a.startsWith("/")||(a=`/${a}`);for(let{find:c,replacement:p}of t.aliases)if(a.startsWith(p)){let u=a.replace(p,c);return{alias:c,newPath:u}}return null}return{ImportDeclaration(o){let i=o.source.value;if(!r(i))return;let a=s(i,n),c=l(a);!c&&t.allowNotFoundAliases||e.report({node:o,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?p=>p.replaceText(o.source,`'${c.newPath}'`):void 0})}}}}),pt={name:Qt,rule:jr};var ce=require("@typescript-eslint/utils");var ut=He(require("typescript")),Lr=ce.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),en="no-unnecessary-casting",_r=j({additionalCastFunctions:P(Y(j({name:F(),expectedType:ke(["string","number"])})))}),ft={name:en,rule:Lr({name:en,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[_r],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=ce.ESLintUtils.getParserServices(e,!0),l=s.program?.getTypeChecker();if(!l||!s.program)throw new Error("TypeScript services or program not available");function o(p,u){switch(p.type){case ce.AST_NODE_TYPES.Literal:return u==="number"?typeof p.value=="number":typeof p.value=="string";case ce.AST_NODE_TYPES.TemplateLiteral:return u==="string";case ce.AST_NODE_TYPES.UnaryExpression:return u==="number"?p.operator==="+"||p.operator==="-"||p.operator==="~":!1;default:return!1}}function i(p,u){return u==="number"?!!(p.flags&ut.TypeFlags.NumberLike):!!(p.flags&ut.TypeFlags.StringLike)}function a(p,u){return g=>g.replaceText(p,e.sourceCode.getText(u))}function c(p){if(!l||p.arguments.length!==1)return;let u=p.arguments[0];if(!u||u.type===ce.AST_NODE_TYPES.SpreadElement)return;let{callee:g}=p;if(g.type!==ce.AST_NODE_TYPES.Identifier)return;let S=g.name,E=r.find(w=>w.name===S);if(!E)return;if(o(u,E.expectedType)||i(l.getTypeAtLocation(s.esTreeNodeToTSNodeMap.get(u)),E.expectedType)){let w,h;S==="Number"?w="unnecessaryNumberCasting":S==="String"?w="unnecessaryStringCasting":(w="unnecessaryCustomCasting",h={name:E.name,type:E.expectedType}),e.report({node:p,messageId:w,...h?{data:h}:{},fix:a(p,u)})}}return{CallExpression:c}}})};var G=require("@typescript-eslint/utils");var mt=fe({name:"no-unused-obj-props",meta:{type:"suggestion",docs:{description:"Disallow unused properties when it is safe to remove them"},messages:{unusedObjectProperty:'The object property "{{name}}" is not being used',unusedReturnObjectProperty:'The object property "{{name}}" returned by this function is not being used'},schema:[]},defaultOptions:[],create(e){return{VariableDeclarator(t){if(t.id.type===G.AST_NODE_TYPES.ObjectPattern||!t.init||t.init.type!==G.AST_NODE_TYPES.ObjectExpression||t.id.type===G.AST_NODE_TYPES.Identifier&&t.id.typeAnnotation||t.parent.parent.type===G.AST_NODE_TYPES.ExportNamedDeclaration)return;let n=new Map;for(let o of t.init.properties)o.type===G.AST_NODE_TYPES.Property&&o.key.type===G.AST_NODE_TYPES.Identifier&&n.set(o.key.name,o);if(n.size===0||t.id.type!==G.AST_NODE_TYPES.Identifier)return;let r=Mr(t,e.sourceCode);if(r.length===0)return;let s=t.init.properties.some(o=>o.type!==G.AST_NODE_TYPES.Property?!1:o.value.type===G.AST_NODE_TYPES.FunctionExpression),l=new Set;for(let o of r){if(o.identifier.parent.type!==G.AST_NODE_TYPES.MemberExpression)return;let i=o.identifier.parent;if(i.object!==o.identifier)return;if(i.computed)if(i.property.type===G.AST_NODE_TYPES.Literal&&typeof i.property.value=="string")l.add(i.property.value);else return;else{if(i.property.type!==G.AST_NODE_TYPES.Identifier)return;l.add(i.property.name)}if(i.parent.type===G.AST_NODE_TYPES.CallExpression&&s)return}for(let[o,i]of n)l.has(o)||e.report({node:i,messageId:"unusedObjectProperty",data:{name:o}})}}}});function Mr(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}var W=require("@typescript-eslint/utils");var $r=j({selectors:Y(j({name:F(),selectorProp:P(F()),selectorArgPos:P(Z()),returnProp:P(F())}))}),Ur=W.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),tn="no-unused-selected-values",dt={name:tn,rule:Ur({name:tn,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[$r]},defaultOptions:[{selectors:[]}],create(e,[t]){let{selectors:n=[]}=t,r=new Map(n.map(s=>[s.name,s]));return{VariableDeclarator(s){let l=null;if(s.init?.type===W.AST_NODE_TYPES.CallExpression&&(l=s.init),!l)return;let o=Wr(l);if(!o)return;let i=r.get(o);if(!i)return;let a=Vr(l,i.selectorArgPos??0,i.selectorProp);if(!a)return;let c=Hr(a);if(!c)return;let p=nn(c.properties,void 0);if(!p)return;if(s.id.type===W.AST_NODE_TYPES.ObjectPattern){let S=nn(s.id.properties,i.returnProp);if(!S)return;for(let[E,T]of p)S.has(E)||e.report({node:T,messageId:"unusedSelectedValue",data:{name:E}});return}if(s.id.type!==W.AST_NODE_TYPES.Identifier||i.returnProp)return;let u=Yr(s,e.sourceCode);if(u.length===0)return;let g=new Set;for(let S of u){if(S.identifier.parent.type!==W.AST_NODE_TYPES.MemberExpression)return;let E=S.identifier.parent.property;if(E.type!==W.AST_NODE_TYPES.Identifier)return;g.add(E.name)}for(let[S,E]of p)g.has(S)||e.report({node:E,messageId:"unusedSelectedValue",data:{name:S}})}}}})};function Vr(e,t,n){let r=e.arguments[t];if(!r)return null;if(r.type===W.AST_NODE_TYPES.ArrowFunctionExpression||r.type===W.AST_NODE_TYPES.FunctionExpression)return r;if(n&&r.type===W.AST_NODE_TYPES.ObjectExpression){let s=r.properties.find(o=>o.type===W.AST_NODE_TYPES.Property&&o.key.type===W.AST_NODE_TYPES.Identifier&&o.key.name===n);if(s?.type!==W.AST_NODE_TYPES.Property)return null;let l=s.value;if(l.type===W.AST_NODE_TYPES.ArrowFunctionExpression||l.type===W.AST_NODE_TYPES.FunctionExpression)return l}return null}function Wr(e){return e.callee.type===W.AST_NODE_TYPES.Identifier?e.callee.name:e.callee.type===W.AST_NODE_TYPES.MemberExpression&&e.callee.property.type===W.AST_NODE_TYPES.Identifier?e.callee.property.name:null}function Hr(e){if(e.body.type===W.AST_NODE_TYPES.ObjectExpression)return e.body;if(e.body.type===W.AST_NODE_TYPES.BlockStatement){let t=e.body.body.filter(n=>n.type===W.AST_NODE_TYPES.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==W.AST_NODE_TYPES.ObjectExpression?null:t[0].argument}return null}function nn(e,t){let n=e;if(t){let s=e.find(l=>l.type===W.AST_NODE_TYPES.Property&&l.key.type===W.AST_NODE_TYPES.Identifier&&l.key.name===t);if(s?.type!==W.AST_NODE_TYPES.Property||s.value.type!==W.AST_NODE_TYPES.ObjectPattern)return null;n=s.value.properties}let r=new Map;for(let s of n){if(s.type!==W.AST_NODE_TYPES.Property||s.key.type!==W.AST_NODE_TYPES.Identifier)return null;r.set(s.key.name,s)}return r.size>0?r:null}function Yr(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}var H=require("@typescript-eslint/utils");var yt=fe({name:"no-unused-t-state-field",meta:{type:"suggestion",docs:{description:"Prevent declaring unused t-state fields"},messages:{unusedField:'Field "{{name}}" is not being used, you can safely remove it'},schema:[]},defaultOptions:[],create(e){if(!(e.filename.endsWith(".jsx")||e.filename.endsWith(".tsx")))return{};if(!e.sourceCode.ast.body.some(l=>l.type===H.AST_NODE_TYPES.ImportDeclaration&&l.source.value==="t-state-form"))return{};let r=null,s=!1;return{CallExpression(l){if(s)return;if(!r){let i=zr(l);i&&(r=i);return}let o=Br(l,e.sourceCode);if(o){s=!0;for(let i of o)r.delete(i);if(r.size!==0)for(let[i,a]of r)e.report({node:a,messageId:"unusedField",data:{name:i}})}}}}});function zr(e){if(!(e.callee.type===H.AST_NODE_TYPES.Identifier&&e.callee.name==="useForm"))return null;let n=e.arguments[0];if(!n||n.type!==H.AST_NODE_TYPES.ObjectExpression)return null;let r=lt(n.properties,l=>l.type!==H.AST_NODE_TYPES.Property||l.key.type!==H.AST_NODE_TYPES.Identifier||l.key.name!=="initialConfig"?null:l.value.type===H.AST_NODE_TYPES.ObjectExpression?l.value:l.value.type===H.AST_NODE_TYPES.ArrowFunctionExpression||l.value.type===H.AST_NODE_TYPES.FunctionExpression?qr(l.value):null);if(!r)return null;let s=new Map;for(let l of r.properties)l.type===H.AST_NODE_TYPES.Property&&l.key.type===H.AST_NODE_TYPES.Identifier&&s.set(l.key.name,l);return s}function Br(e,t){if(!(e.callee.type===H.AST_NODE_TYPES.Identifier&&e.callee.name==="useFormState")||e.parent.type!==H.AST_NODE_TYPES.VariableDeclarator||e.parent.id.type!==H.AST_NODE_TYPES.ObjectPattern||!lt(e.parent.id.properties,o=>o.type===H.AST_NODE_TYPES.Property&&o.key.type===H.AST_NODE_TYPES.Identifier&&o.key.name==="formFields"&&o))return null;let s=Jt(e.parent,"formFields",t),l=new Set;for(let{identifier:o}of s){if(o.type!==H.AST_NODE_TYPES.Identifier||o.parent.type===H.AST_NODE_TYPES.Property&&o.parent.parent.type===H.AST_NODE_TYPES.ObjectExpression&&o.parent.parent.parent.type===H.AST_NODE_TYPES.ReturnStatement||o.parent.type===H.AST_NODE_TYPES.ReturnStatement)return null;if(o.parent.type===H.AST_NODE_TYPES.MemberExpression){if(o.parent.object.type!==H.AST_NODE_TYPES.Identifier||o.parent.property.type!==H.AST_NODE_TYPES.Identifier)return null;l.add(o.parent.property.name)}}return l}function qr(e){if(e.body.type===H.AST_NODE_TYPES.ObjectExpression)return e.body;if(e.body.type===H.AST_NODE_TYPES.BlockStatement){let t=e.body.body.filter(n=>n.type===H.AST_NODE_TYPES.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==H.AST_NODE_TYPES.ObjectExpression?null:t[0].argument}return null}var $=require("@typescript-eslint/utils");var Xr=$.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function rn(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 sn(e,...t){for(let n of t)e.set(...n);return e}var Kr=j({forceCheckOnFCPropTypesWithName:P(Y(F()))}),on="no-unused-type-props-in-args",gt=null,Jr=Xr({name:on,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Kr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!gt&&(gt=n.map(i=>new RegExp(i)));function r(i,a,c,p,u=!0){let g=c.name,S=e.sourceCode.getScope(a).references.find(w=>w.identifier.name===g)?.resolved,E=i&>?.some(w=>w.test(g));if(!S||!E&&S.references.filter(w=>w.isTypeReference).length>1)return;let T=S?.defs[0]?.node;if(!(u&&T?.parent?.type===$.AST_NODE_TYPES.ExportNamedDeclaration)){if(T?.type===$.AST_NODE_TYPES.TSTypeAliasDeclaration){s(i,a,p,T.typeAnnotation,!0);return}if(T?.type===$.AST_NODE_TYPES.TSInterfaceDeclaration){s(i,a,p,T.body,!0);return}}}function s(i,a,c,p,u){if(p.type===$.AST_NODE_TYPES.TSInterfaceBody){for(let g of p.body)g.type===$.AST_NODE_TYPES.TSPropertySignature&&g.key.type===$.AST_NODE_TYPES.Identifier&&c.set(g.key.name,g);return}if(p.type===$.AST_NODE_TYPES.TSTypeLiteral){sn(c,...rn(p));return}if(p.type===$.AST_NODE_TYPES.TSIntersectionType){for(let g of p.types)s(i,a,c,g,!0);return}u||p.type===$.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===$.AST_NODE_TYPES.Identifier&&r(i,a,p.typeName,c)}function l(i,a,c){for(let p of c)if(p.type==="ObjectPattern"&&p.typeAnnotation){let u=new Map;if(s(i,a,u,p.typeAnnotation.typeAnnotation,!1),u.size===0)continue;o(p,u)}else p.type===$.AST_NODE_TYPES.AssignmentPattern&&p.left.type===$.AST_NODE_TYPES.ObjectPattern&&l(i,a,[p.left])}function o(i,a){let c=[];if(i.properties.at(-1)?.type===$.AST_NODE_TYPES.RestElement)return;for(let S of i.properties)S.type===$.AST_NODE_TYPES.Property&&S.key.type===$.AST_NODE_TYPES.Identifier&&c.push(S.key.name);let u=[],g=[];for(let[S,E]of a)c.includes(S)||(g.push(S),u.push({node:E,messageId:"unusedObjectTypeProperty",data:{propertyName:S}}));for(let[S,E]of u.entries())e.report({...E,fix:S===u.length-1?T=>{let w=i.properties.at(-1),h=g.join(", ");return w?w?.type===$.AST_NODE_TYPES.RestElement?null:T.insertTextAfter(w,`, ${h}`):T.insertTextBeforeRange([i.range[0]+1,i.range[1]],`${h}`)}:void 0})}return{VariableDeclaration(i){let a=i.declarations[0];if(!a)return;let c=new Map,p=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(p){if(p.type===$.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===$.AST_NODE_TYPES.Identifier)r(!0,i,p.typeName,c,!1);else if(p.type===$.AST_NODE_TYPES.TSTypeLiteral)sn(c,...rn(p));else if(p.type===$.AST_NODE_TYPES.TSIntersectionType)for(let u of p.types)u.type===$.AST_NODE_TYPES.TSTypeReference&&u.typeName.type===$.AST_NODE_TYPES.Identifier?r(!0,i,u.typeName,c,!1):s(!0,i,c,u,!0);if(c.size!==0&&a.init?.type===$.AST_NODE_TYPES.ArrowFunctionExpression){let u=a.init.params[0];if(!u){e.report({node:a.init,messageId:"missingComponentParam"});return}u.type===$.AST_NODE_TYPES.ObjectPattern&&o(u,c)}}},FunctionDeclaration:function(i){l(!1,i,i.params)},ArrowFunctionExpression(i){l(!1,i,i.params)}}}}),St={name:on,rule:Jr};var Te=require("@typescript-eslint/utils"),Gr=Te.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ln="prefer-named-functions",an=new Map,Zr=Gr({name:ln,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let r=an.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),an.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===Te.AST_NODE_TYPES.ArrowFunctionExpression&&r.id.type===Te.AST_NODE_TYPES.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==Te.AST_NODE_TYPES.BlockStatement)return;let l=r.parent,o=r.init.params,i=r.init.body,a=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(l,`${a.async?"async ":""}function ${s}(${o.map(p=>e.sourceCode.getText(p)).join(", ")||""}) ${e.sourceCode.getText(i)}`)}]})}}}}}),Tt={name:ln,rule:Zr};var N=require("@typescript-eslint/utils");var Qr=j({disallowedFunctions:Y(j({name:F(),allowUsingWithArgs:P(oe()),hookAlternative:P(F()),message:P(F()),allowUseInside:P(Y(F()))}))});function Le(e){return/^use[A-Z]/.test(e)}function cn(e){return/^[A-Z]/.test(e)}function ei(e){return e.type===N.AST_NODE_TYPES.Identifier?Le(e.name):e.type===N.AST_NODE_TYPES.MemberExpression&&e.property.type===N.AST_NODE_TYPES.Identifier?Le(e.property.name):!1}function pn(e,t){return e.type===N.AST_NODE_TYPES.Identifier?e.name===t:e.type===N.AST_NODE_TYPES.MemberExpression&&e.object.type===N.AST_NODE_TYPES.Identifier&&e.property.type===N.AST_NODE_TYPES.Identifier?e.object.name==="React"&&e.property.name===t:!1}function un(e){return!!(e.parent&&e.parent.type===N.AST_NODE_TYPES.CallExpression&&pn(e.parent.callee,"forwardRef"))}function fn(e){return!!(e.parent&&e.parent.type===N.AST_NODE_TYPES.CallExpression&&pn(e.parent.callee,"memo"))}function ht(e){if(e.type===N.AST_NODE_TYPES.FunctionDeclaration||e.type===N.AST_NODE_TYPES.FunctionExpression&&e.id)return e.id||void 0;if(e.type===N.AST_NODE_TYPES.FunctionExpression||e.type===N.AST_NODE_TYPES.ArrowFunctionExpression){if(e.parent.type===N.AST_NODE_TYPES.VariableDeclarator&&e.parent.init===e)return e.parent.id;if(e.parent.type===N.AST_NODE_TYPES.AssignmentExpression&&e.parent.right===e&&e.parent.operator==="=")return e.parent.left;if(e.parent.type===N.AST_NODE_TYPES.Property&&e.parent.value===e&&!e.parent.computed)return e.parent.key;if(e.parent.type===N.AST_NODE_TYPES.AssignmentPattern&&e.parent.right===e)return e.parent.left}}function ti(e){let t=e.parent,n=!1;for(;t;){if(t.type===N.AST_NODE_TYPES.FunctionDeclaration||t.type===N.AST_NODE_TYPES.FunctionExpression||t.type===N.AST_NODE_TYPES.ArrowFunctionExpression){let r=ht(t);if(r&&r.type===N.AST_NODE_TYPES.Identifier){if(cn(r.name)||Le(r.name))return!n;n=!0}else{if(un(t)||fn(t))return!n;if(t.parent.type===N.AST_NODE_TYPES.CallExpression){let s=t.parent;ei(s.callee)||(n=!0)}else t.parent.type===N.AST_NODE_TYPES.JSXExpressionContainer||(n=!0)}}t=t.parent}return!1}function mn(e){return e.callee.type===N.AST_NODE_TYPES.Identifier?e.callee.name:e.callee.type===N.AST_NODE_TYPES.MemberExpression&&e.callee.property.type===N.AST_NODE_TYPES.Identifier?e.callee.property.name:null}function ni(e,t){if(!t.length)return!1;let n=e.parent;for(;n;){if(n.type===N.AST_NODE_TYPES.FunctionDeclaration||n.type===N.AST_NODE_TYPES.FunctionExpression||n.type===N.AST_NODE_TYPES.ArrowFunctionExpression){let r=ht(n);if(r&&r.type===N.AST_NODE_TYPES.Identifier&&t.includes(r.name))return!0}else if(n.type===N.AST_NODE_TYPES.CallExpression){let r=mn(n);if(r&&t.includes(r))return!0}n=n.parent}return!1}function ri(e){return e.arguments.length>0&&!e.arguments.every(t=>t.type===N.AST_NODE_TYPES.Identifier&&t.name==="undefined")}function ii(e,t){let n=!1,r=e.parent;for(;r;){if(r.type===N.AST_NODE_TYPES.FunctionDeclaration||r.type===N.AST_NODE_TYPES.FunctionExpression||r.type===N.AST_NODE_TYPES.ArrowFunctionExpression){let s=ht(r);if(s&&s.type===N.AST_NODE_TYPES.Identifier){if(cn(s.name)||Le(s.name)){n=!0;break}}else if(un(r)||fn(r)){n=!0;break}}r=r.parent}return n?t.length===0?ti(e):!ni(e,t):!1}var Et=fe({name:"prefer-react-hook-alternative",meta:{type:"suggestion",docs:{description:"Prefer hook alternatives for certain functions in React components and hooks"},messages:{preferHookAlternative:"This function should not be used in react{{message}}."},schema:[Qr],hasSuggestions:!0},defaultOptions:[{disallowedFunctions:[]}],create(e,[t]){let{disallowedFunctions:n}=t,r=new Map(n.map(s=>[s.name,s]));return{CallExpression(s){let l=mn(s);if(!l)return;let o=r.get(l);if(!o||o.allowUsingWithArgs&&ri(s))return;let i=o.allowUseInside||[];ii(s,i)&&e.report({node:s,messageId:"preferHookAlternative",data:{message:o.message?` ${o.message}`:` use ${o.hookAlternative} instead`},suggest:o.hookAlternative?[{messageId:"preferHookAlternative",data:{message:`Replace with ${o.hookAlternative}`,hookAlternative:o.hookAlternative},fix:a=>{let c=o.hookAlternative;return s.callee.type===N.AST_NODE_TYPES.Identifier?a.replaceText(s.callee,c):s.callee.type===N.AST_NODE_TYPES.MemberExpression&&s.callee.property.type===N.AST_NODE_TYPES.Identifier?a.replaceText(s.callee.property,c):null}}]:[]})}}}});var z=require("@typescript-eslint/utils");var si=z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),yn="prefer-single-line-if",oi=j({maxLineLength:P(Z()),maxNonSimpleConditionLength:P(Z())}),ai=si({name:yn,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:[oi]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==z.AST_NODE_TYPES.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let l=r.consequent.body[0];if(l.type===z.AST_NODE_TYPES.ReturnStatement){if(!Sn(l))return}else if(!(l.type===z.AST_NODE_TYPES.ContinueStatement||l.type===z.AST_NODE_TYPES.BreakStatement))return;if(r.test.type===z.AST_NODE_TYPES.LogicalExpression||r.test.type===z.AST_NODE_TYPES.ConditionalExpression)return;let o;if(t.maxNonSimpleConditionLength){let u=dn(r.test);if(!u&&r.test.type===z.AST_NODE_TYPES.UnaryExpression&&r.test.operator==="!"){let g=r.test.argument;dn(g)&&(u=!0)}if(u&&(o=n.getText(r.test),o.length>t.maxNonSimpleConditionLength))return}o||(o=n.getText(r.test));let i=n.getText(l);if(o.includes(`
|
|
15
|
+
`))return;let a=n.getTokenAfter(r);if(a&&a.type===z.AST_TOKEN_TYPES.Punctuator&&a.value==="}"){let u=n.getTokenAfter(a);if(u&&u.type===z.AST_TOKEN_TYPES.Keyword&&(u.value==="else"||u.value==="catch"))return}let c=li(n,r),p=`if (${o}) ${i}`;t.maxLineLength&&p.length+c.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:u=>u.replaceText(r,p)})}}}});function dn(e){return e.type===z.AST_NODE_TYPES.CallExpression||e.type===z.AST_NODE_TYPES.BinaryExpression||e.type===z.AST_NODE_TYPES.MemberExpression&&gn(e)}function gn(e){return e.object.type===z.AST_NODE_TYPES.MemberExpression?gn(e.object):e.object.type!==z.AST_NODE_TYPES.Identifier}function li(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function Sn(e){if(!e.argument)return!0;let t=e.argument;return t.type===z.AST_NODE_TYPES.ArrayExpression&&t.elements.length===0||t.type===z.AST_NODE_TYPES.ObjectExpression&&t.properties.length===0||t.type===z.AST_NODE_TYPES.Literal||t.type===z.AST_NODE_TYPES.Identifier||t.type===z.AST_NODE_TYPES.TemplateLiteral||t.type===z.AST_NODE_TYPES.TaggedTemplateExpression?!0:t.type===z.AST_NODE_TYPES.CallExpression?t.arguments.length===0:t.type===z.AST_NODE_TYPES.UnaryExpression?Sn(t):!1}var bt={name:yn,rule:ai};var J=require("@typescript-eslint/utils");var ci=J.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Tn="react-compiler-migration",pi=j({disallowHooks:P(Y(j({name:F(),replacement:F()}))),disallowMethods:P(Y(j({name:F(),replacement:P(F()),requireTrueProp:P(F())})))}),ui=/eslint +react-compiler\/react-compiler: +\["error/;function fi(e){return e.type===J.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===J.AST_NODE_TYPES.MemberExpression&&e.property.type===J.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var mi=ci({name:Tn,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:[pi]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(ui.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let s=null,l=null;if(r.callee.type===J.AST_NODE_TYPES.Identifier?(s=r.callee.name,l=r.callee):r.callee.type===J.AST_NODE_TYPES.MemberExpression&&r.callee.property.type===J.AST_NODE_TYPES.Identifier&&(s=r.callee.property.name,l=r.callee.property),s){let o=t.disallowHooks.find(i=>i.name===s);o&&l&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:o.name,replacement:o.replacement},suggest:[{messageId:"replace",data:{replacement:o.replacement},fix:i=>i.replaceText(l,o.replacement)}]})}}if(t.disallowMethods?.length&&fi(r.callee)){for(let s of r.arguments)if(s.type===J.AST_NODE_TYPES.ObjectExpression){for(let l of s.properties)if(l.type===J.AST_NODE_TYPES.Property&&l.key.type===J.AST_NODE_TYPES.Identifier){let o=l.key.name,i=t.disallowMethods.find(a=>a.name===o);if(i){if(i.requireTrueProp){let a=i.requireTrueProp,c=!1;for(let p of s.properties)if(p.type===J.AST_NODE_TYPES.Property&&p.key.type===J.AST_NODE_TYPES.Identifier&&p.key.name===a&&p.value.type===J.AST_NODE_TYPES.Literal&&p.value.value===!0){c=!0;break}if(!c){e.report({node:l,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:i.name,requireTrueProp:a}});continue}}i.replacement&&e.report({node:l,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:i.name,replacement:i.replacement},suggest:[{messageId:"replace",data:{replacement:i.replacement},fix:a=>a.replaceText(l.key,i.replacement)}]})}}}}}}:{}}}),xt={name:Tn,rule:mi};var _e=require("@typescript-eslint/utils"),di=_e.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),hn="require-description",yi=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,gi=/^eslint-disable-(next-)?line$/u,Si=di({name:hn,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let l=Ti(s);l!=null&&(r.has(l.kind)||l.description||e.report({loc:Ei(s.loc),messageId:"missingDescription"}))}}}}}),En={name:hn,rule:Si};function Ti(e){let{text:t,description:n}=hi(e.value);if(!t)return null;let r=yi.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let l=gi.test(s);if(e.type===_e.TSESTree.AST_TOKEN_TYPES.Line&&!l||l&&e.loc.start.line!==e.loc.end.line)return null;let o=t.slice(r.index+s.length);return{kind:s,value:o.trim(),description:n}}function hi(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Ei(e){return{start:{line:e.start.line,column:-1},end:e.end}}function In(e){return/^use[A-Z0-9]/.test(e)}function Me(e){return e.type==="Identifier"?In(e.name):e.type==="MemberExpression"&&!e.computed&&Me(e.property)?e.object.type==="Identifier":!1}function Cn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function wn(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Rn(e){return!!(e.parent&&e.parent.callee&&wn(e.parent.callee,"forwardRef"))}function vn(e){return!!(e.parent&&e.parent.callee&&wn(e.parent.callee,"memo"))}function It(e){for(;e;){let t=An(e);if(t&&(Cn(t)||Me(t))||Rn(e)||vn(e))return!0;e=e.parent}return!1}function bn(e){return!1}function Ct(e){return!1}var bi=/eslint +react-compiler\/react-compiler: +\["error/,kn={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(bi.test(a.value))return{CallExpression(c){let p=null;c.callee.name==="useMemo"?p="useMemo":c.callee.name==="useCallback"&&(p="useCallback"),p&&e.report({node:c,message:`"${p}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?a=>t(a):a=>e.sourceCode.getText(a),n=typeof e.getScope=="function"?()=>n():a=>e.sourceCode.getScope(a),r=null,s=[],l=[],o=new WeakSet;function i(a){for(let c of a.references){let p=c.identifier.parent;if(p.type==="VariableDeclarator"&&p.init&&p.init.type==="CallExpression"&&p.init.callee&&bn(p.init.callee))for(let u of c.resolved.references)u!==c&&o.add(u.identifier)}}return{onCodePathSegmentStart:a=>l.push(a),onCodePathSegmentEnd:()=>l.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(a,c){let p=s.pop();if(p.size===0)return;let u=new Set;function g(m,v){let{cache:R}=g,A=R.get(m.id),O=new Set(v);if(O.has(m.id)){let x=[...O],U=x.slice(x.indexOf(m.id)+1);for(let B of U)u.add(B);return BigInt("0")}if(O.add(m.id),A!==void 0)return A;if(a.thrownSegments.includes(m))A=BigInt("0");else if(m.prevSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let x of m.prevSegments)A+=g(x,O)}return m.reachable&&A===BigInt("0")?R.delete(m.id):R.set(m.id,A),A}function S(m,v){let{cache:R}=S,A=R.get(m.id),O=new Set(v);if(O.has(m.id)){let x=Array.from(O),U=x.slice(x.indexOf(m.id)+1);for(let B of U)u.add(B);return BigInt("0")}if(O.add(m.id),A!==void 0)return A;if(a.thrownSegments.includes(m))A=BigInt("0");else if(m.nextSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let x of m.nextSegments)A+=S(x,O)}return R.set(m.id,A),A}function E(m){let{cache:v}=E,R=v.get(m.id);if(R===null)return 1/0;if(R!==void 0)return R;if(v.set(m.id,null),m.prevSegments.length===0)R=1;else{R=1/0;for(let A of m.prevSegments){let O=E(A);O<R&&(R=O)}R+=1}return v.set(m.id,R),R}g.cache=new Map,S.cache=new Map,E.cache=new Map;let T=S(a.initialSegment),w=An(c),h=It(c),_=w?Cn(w)||Me(w):Rn(c)||vn(c),d=1/0;for(let m of a.finalSegments){if(!m.reachable)continue;let v=E(m);v<d&&(d=v)}for(let[m,v]of p){if(!m.reachable)continue;let R=m.nextSegments.length===0?d<=E(m):d<E(m),A=g(m)*S(m),O=u.has(m.id);for(let x of v)if(O&&!Ct(x)&&e.report({node:x,message:`React Hook "${t(x)}" 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.`}),_){if(c.async&&e.report({node:x,message:`React Hook "${t(x)}" cannot be called in an async function.`}),!O&&A!==T&&!Ct(x)){let B=`React Hook "${t(x)}" 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:x,message:B})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let U=`React Hook "${t(x)}" 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:x,message:U})}else if(w){let U=`React Hook "${t(x)}" is called in function "${t(w)}" 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:x,message:U})}else if(c.type==="Program"){let U=`React Hook "${t(x)}" 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:x,message:U})}else if(h&&!Ct(x)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let B=c.parent;if(B.parent.type==="VariableDeclarator"&&In(B.parent.id.name))return}let U=`React Hook "${t(x)}" 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:x,message:U})}}},CallExpression(a){if(Me(a.callee)){let c=xn(s),p=xn(l),u=c.get(p);u||(u=[],c.set(p,u)),u.push(a.callee)}a.callee.type==="Identifier"&&(a.callee.name==="useEffect"||bn(a.callee))&&a.arguments.length>0&&(r=a)},Identifier(a){r==null&&o.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===r&&(r=null)},FunctionDeclaration(a){It(a)&&i(n(a))},ArrowFunctionExpression(a){It(a)&&i(n(a))}}}};function An(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 xn(e){return e[e.length-1]}var On={[St.name]:St.rule,[nt.name]:nt.rule,[tt.name]:tt.rule,"rules-of-hooks":kn,"exhaustive-deps":_t,"require-description":En.rule,[rt.name]:rt.rule,[st.name]:st.rule,[Tt.name]:Tt.rule,[qe.name]:qe.rule,[et.name]:et.rule,[pt.name]:pt.rule,[bt.name]:bt.rule,[ct.name]:ct.rule,[it.name]:it.rule,[Ke.name]:Ke.rule,[xt.name]:xt.rule,[Be.name]:Be.rule,[Qe.name]:Qe.rule,[ft.name]:ft.rule,[dt.name]:dt.rule,[yt.name]:yt.rule,[mt.name]:mt.rule,[Et.name]:Et.rule};var xi={rules:On};0&&(module.exports={extendedLintPlugin});
|
package/dist/extended-lint.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{AST_NODE_TYPES as X,ESLintUtils as On}from"@typescript-eslint/utils";var Le=Symbol.for("optional");function P(e){return{...e,[Le]:!0}}function Ie(e,t){return{enum:e,...t}}function oe(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function J(e){return{...e,type:"number"}}function _e(e){return{...e,type:"integer"}}function W(e,t){return{...t,type:"array",items:e}}function D(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,s=[];for(r in e)e[r][Le]?e[r][Le]=void 0:s.push(r);s.length>0&&(n.required=s)}return n}function Ce(...e){return{anyOf:e}}var Pn=On.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),xt="react-compiler-extra",Fn=D({runOnlyWithEnableCompilerDirective:P(oe())}),Nn=/eslint +react-compiler\/react-compiler: +\["error/;function Dn(e){return e.type===X.Identifier?e.name.startsWith("use"):e.type===X.MemberExpression&&e.property.type===X.Identifier?e.property.name.startsWith("use"):!1}var jn=/\bthis[.[]/;function bt(e){return jn.test(e)}var Ln=Pn({name:xt,meta:{type:"suggestion",fixable:"code",docs:{description:"Extra rules to enforce best practices when using the React compiler"},messages:{objectMethodIsNotSupported:"Object methods such as `{ method() {} }` have limited support to optimizations in the React compiler, use a function expression `{ method: () => {} }` instead.",replaceWithFunctionExpression:"Replace with function expression",thisKeywordInMethod:"Object method uses `this` keyword which would have different behavior if converted to an arrow function. Fix this manually."},hasSuggestions:!0,schema:[Fn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let l of e.sourceCode.getAllComments())if(Nn.test(l.value)){n=!0;break}if(!n)return{}}function r(l){for(let o of l.properties)if(o.type===X.Property&&o.method&&o.value.type===X.FunctionExpression){let i=e.sourceCode,a=i.getText(o.key),c=o.value,p=i.getText(c.body);if(bt(p))e.report({node:o,messageId:"thisKeywordInMethod"});else{let u=c.params.map(S=>i.getText(S)).join(", "),g="";c.generator?g=`${a}: function* (${u}) ${p}`:g=`${a}: (${u}) => ${p}`,e.report({node:o,messageId:"objectMethodIsNotSupported",fix:S=>S.replaceText(o,g)})}}}function s(l){for(let o of l.properties)if(o.type===X.Property&&o.value.type===X.ObjectExpression){for(let i of o.value.properties)if(i.type===X.Property&&i.method&&i.value.type===X.FunctionExpression){let c=e.sourceCode.getText(i.value.body);bt(c)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(l){if(Dn(l.callee))for(let o of l.arguments){if(o.type===X.ObjectExpression&&(r(o),s(o)),o.type===X.ArrowFunctionExpression&&(o.body.type===X.ObjectExpression&&(r(o.body),s(o.body)),o.body.type===X.BlockStatement))for(let i of o.body.body)i.type===X.ReturnStatement&&i.argument?.type===X.ObjectExpression&&(r(i.argument),s(i.argument));if(o.type===X.FunctionExpression)for(let i of o.body.body)i.type===X.ReturnStatement&&i.argument?.type===X.ObjectExpression&&(r(i.argument),s(i.argument))}}}}}),Me={name:xt,rule:Ln};import{AST_NODE_TYPES as ee}from"@typescript-eslint/utils";import{ESLintUtils as _n}from"@typescript-eslint/utils";function pe(e){let n=_n.RuleCreator(r=>`https://github.com/lucasols/extended-lint#${r}`)(e);return{name:e.name,rule:n}}var Mn=D({disallow:P(W(D({selector:F(),message:F(),replace:P(Ce(F(),D({regex:F(),with:F()}))),replaceType:P(Ie(["suggestion","autofix"]))}))),disallowFnCalls:P(W(D({fn:F(),withArgs:P(W(D({atIndex:_e(),value:Ce(F(),J(),oe())}))),message:F(),replaceWith:P(F()),ignoreRegex:P(F())}))),__dev_simulateFileName:P(F()),mustMatchSyntax:P(W(D({includeRegex:F(),mustCallFn:P(W(D({anyCall:W(D({fn:F(),withArgs:W(D({atIndex:_e(),literal:Ce(F(),J(),oe())}))})),message:P(F())}))),mustMatchSelector:P(W(D({selector:F(),message:F()})))})))}),$e=pe({name:"advanced-no-restricted-syntax",meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Mn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:s,disallow:l,disallowFnCalls:o}=t,i=s??e.filename,a=[],c=new Map,p=new Set,u=new Map,g=new Map;function S(d){for(let m of d.specifiers)m.type===ee.ImportSpecifier&&m.imported.type===ee.Identifier&&m.local.type===ee.Identifier&&m.imported.name!==m.local.name&&g.set(m.local.name,m.imported.name)}function E(d){d.id.type===ee.Identifier&&d.init?.type===ee.Identifier&&g.set(d.id.name,d.init.name)}function T(d){return g.get(d)??d}function w(d,m){return T(d)===m||d===m}for(let{includeRegex:d,mustCallFn:m,mustMatchSelector:R}of r??[]){let v=$n(i,new RegExp(d));if(!v)continue;let A=O=>{let x=O;for(let{name:M,value:V}of v)x=x.replaceAll(M,V);return x};for(let{anyCall:O,message:x}of m??[]){let M=`Expected file to call the function: ${O.map(({fn:V})=>V).join(" or ")}`;p.add(M),a.push(V=>{let{callee:ie}=V;if(ie.type===ee.Identifier){for(let{fn:Fe,withArgs:Te}of O)if(ie.name===Fe){p.delete(M);for(let le of Te){let q=V.arguments[le.atIndex],ne=typeof le.literal=="string"?A(le.literal):le.literal;if(!q){e.report({node:V,messageId:"default",data:{message:`Missing argument with value "${ne}" at index ${le.atIndex}${x?`: ${A(x)}`:""}`}});continue}if(q.type!==ee.Literal){e.report({node:q,messageId:"default",data:{message:`Argument at position ${le.atIndex} should the literal "${ne}"${x?`: ${A(x)}`:""}`}});continue}q.value!==ne&&e.report({node:q,messageId:"default",data:{message:`Argument should have the value "${ne}"${x?`: ${A(x)}`:""}`},fix:he=>he.replaceText(q,typeof ne=="string"?`'${ne}'`:String(ne))})}break}}})}for(let{selector:O,message:x}of R??[])u.set(O,A(x)),c.set(A(O),()=>{u.delete(O)})}for(let{fn:d,withArgs:m,message:R,replaceWith:v,ignoreRegex:A}of o??[])A&&new RegExp(A).test(i)||a.push(O=>{let{callee:x}=O;if(x.type!==ee.Identifier||!w(x.name,d))return;if(m)for(let V of m){let ie=O.arguments[V.atIndex];if(!ie){e.report({node:O,messageId:"default",data:{message:`Missing argument with value "${V.value}" at index ${V.atIndex}: ${R}`}});return}if(ie.type!==ee.Literal){e.report({node:ie,messageId:"default",data:{message:`Argument at position ${V.atIndex} should be the literal "${V.value}": ${R}`}});return}if(ie.value!==V.value)return}let M=V=>v?V.replaceText(O,v):null;e.report({node:O,messageId:"default",data:{message:R},suggest:v?[{messageId:"default",data:{message:`Replace with "${v}"`},fix:M}]:void 0})});function h(d,m){let R=n[d];R?n[d]=v=>{R(v),m(v)}:n[d]=m}for(let{selector:d,message:m,replace:R,replaceType:v="suggestion"}of l??[]){if(d==="CallExpression"){a.push(A=>{_(R,A,m,v)});continue}n[d]=A=>{_(R,A,m,v)}}if(c.size>0)for(let[d,m]of c)h(d,m);return a.length>0&&(n.CallExpression=d=>{if(d.type===ee.CallExpression)for(let m of a)m(d)}),n.ImportDeclaration=d=>{d.type===ee.ImportDeclaration&&S(d)},n.VariableDeclarator=d=>{d.type===ee.VariableDeclarator&&E(d)},n["Program:exit"]=d=>{for(let m of p)e.report({node:d,messageId:"default",data:{message:m}});for(let[,m]of u)e.report({node:d,messageId:"default",data:{message:m}})},n;function _(d,m,R,v){let A=O=>{if(!d)return null;if(typeof d=="string")return O.replaceText(m,d);{let x=new RegExp(d.regex),M=e.sourceCode.getText(m);return O.replaceText(m,M.replace(x,d.with))}};e.report({node:m,messageId:"default",data:{message:R},fix:d&&v==="autofix"?A:void 0,suggest:d&&v==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof d=="string"?d:d.with}"`},fix:A}]:void 0})}}});function $n(e,t){let n=[],r=t.exec(e);if(!r)return null;let[s,...l]=r;n.push({name:"$0_lowercase",value:s.toLowerCase()}),n.push({name:"$0_capitalize",value:It(s)}),n.push({name:"$0_uncapitalize",value:Ct(s)}),n.push({name:"$0",value:s});for(let o=0;o<l.length;o++){let i=`$${o+1}`,a=l[o];n.push({name:`${i}_lowercase`,value:a.toLowerCase()}),n.push({name:`${i}_capitalize`,value:It(a)}),n.push({name:`${i}_uncapitalize`,value:Ct(a)}),n.push({name:i,value:a})}return n}function It(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ct(e){return e.charAt(0).toLowerCase()+e.slice(1)}import{AST_NODE_TYPES as $,AST_TOKEN_TYPES as Un,ESLintUtils as Vn}from"@typescript-eslint/utils";var Wn=Vn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Rt="collapse-simple-objs-in-one-line",Hn=D({maxLineLength:P(J()),maxProperties:P(J()),nestedObjMaxLineLength:P(J()),nestedObjMaxProperties:P(J()),ignoreTypesWithSuffix:P(W(F()))}),Yn=Wn({name:Rt,meta:{type:"suggestion",fixable:"code",docs:{description:"Format simple objects and types in one line"},messages:{singleLineProp:"Object/type should be written in a single line"},schema:[Hn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],s=t.maxProperties??2,l=t.nestedObjMaxLineLength??t.maxLineLength,o=t.nestedObjMaxProperties??3;function i(c){if(c.type===$.ObjectExpression){let p=c.parent.type===$.Property,u=p?o:s,g=c.properties.length;if(g>u)return!1;if(g===1){let E=c.properties[0];return E.type===$.Property&&E.value.type===$.ObjectExpression||E.type===$.Property&&E.value.type===$.ArrayExpression&&!E.value.elements.every(w=>w&&Ue(w))?!1:{text:n.getText(E),isNested:p,propsSize:g}}let S=[];for(let E of c.properties){if(E.type===$.Property&&!Ue(E.value))return!1;S.push(n.getText(E))}return{text:S.join(", "),isNested:p,propsSize:g}}else{let p=c.parent.parent?.type===$.TSPropertySignature,u=p?o:s,g=c.members.length;if(g>u)return!1;if(r.length>0&&c.parent.type===$.TSTypeAliasDeclaration){let E=c.parent.id.name;if(r.some(T=>E.endsWith(T)))return!1}if(g===1){let E=c.members[0];return E.type===$.TSPropertySignature&&E.typeAnnotation?.typeAnnotation.type===$.TSTypeLiteral?!1:{text:n.getText(E),isNested:p,propsSize:1}}if(c.parent.type===$.TSIntersectionType||c.parent.type===$.TSUnionType)return!1;let S=[];for(let E of c.members){if(E.type!==$.TSPropertySignature)return!1;let T=E.typeAnnotation?.typeAnnotation;if(!T||T.type===$.TSTypeLiteral||!wt(T))return!1;if(T.type===$.TSTypeReference&&T.typeArguments){if(T.typeArguments.params.length>1)return!1;let h=T.typeArguments.params[0];if(!wt(h))return!1}let w=n.getText(E).trim();(w.endsWith(";")||w.endsWith(","))&&(w=w.slice(0,-1)),S.push(w)}return{text:S.join("; "),isNested:p,propsSize:g}}}function a(c){if(c.loc.start.line===c.loc.end.line)return;if(c.parent.type!==$.JSXExpressionContainer){let T=0,w=n.getTokenAfter(c,{filter:h=>h.type!==Un.Punctuator?!0:h.value===","||h.value===";"||h.value===")"||h.value==="}"?(T++,!1):!0});if(T>4||w?.loc.start.line===c.loc.end.line)return}let p=i(c);if(!p)return;let u=p.text;if(u.includes(`
|
|
1
|
+
import{AST_NODE_TYPES as X,ESLintUtils as On}from"@typescript-eslint/utils";var Le=Symbol.for("optional");function P(e){return{...e,[Le]:!0}}function Ie(e,t){return{enum:e,...t}}function oe(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function J(e){return{...e,type:"number"}}function _e(e){return{...e,type:"integer"}}function V(e,t){return{...t,type:"array",items:e}}function D(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,s=[];for(r in e)e[r][Le]?e[r][Le]=void 0:s.push(r);s.length>0&&(n.required=s)}return n}function Ce(...e){return{anyOf:e}}var Pn=On.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),xt="react-compiler-extra",Fn=D({runOnlyWithEnableCompilerDirective:P(oe())}),Nn=/eslint +react-compiler\/react-compiler: +\["error/;function Dn(e){return e.type===X.Identifier?e.name.startsWith("use"):e.type===X.MemberExpression&&e.property.type===X.Identifier?e.property.name.startsWith("use"):!1}var jn=/\bthis[.[]/;function bt(e){return jn.test(e)}var Ln=Pn({name:xt,meta:{type:"suggestion",fixable:"code",docs:{description:"Extra rules to enforce best practices when using the React compiler"},messages:{objectMethodIsNotSupported:"Object methods such as `{ method() {} }` have limited support to optimizations in the React compiler, use a function expression `{ method: () => {} }` instead.",replaceWithFunctionExpression:"Replace with function expression",thisKeywordInMethod:"Object method uses `this` keyword which would have different behavior if converted to an arrow function. Fix this manually."},hasSuggestions:!0,schema:[Fn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let l of e.sourceCode.getAllComments())if(Nn.test(l.value)){n=!0;break}if(!n)return{}}function r(l){for(let o of l.properties)if(o.type===X.Property&&o.method&&o.value.type===X.FunctionExpression){let i=e.sourceCode,a=i.getText(o.key),c=o.value,p=i.getText(c.body);if(bt(p))e.report({node:o,messageId:"thisKeywordInMethod"});else{let u=c.params.map(S=>i.getText(S)).join(", "),g="";c.generator?g=`${a}: function* (${u}) ${p}`:g=`${a}: (${u}) => ${p}`,e.report({node:o,messageId:"objectMethodIsNotSupported",fix:S=>S.replaceText(o,g)})}}}function s(l){for(let o of l.properties)if(o.type===X.Property&&o.value.type===X.ObjectExpression){for(let i of o.value.properties)if(i.type===X.Property&&i.method&&i.value.type===X.FunctionExpression){let c=e.sourceCode.getText(i.value.body);bt(c)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(l){if(Dn(l.callee))for(let o of l.arguments){if(o.type===X.ObjectExpression&&(r(o),s(o)),o.type===X.ArrowFunctionExpression&&(o.body.type===X.ObjectExpression&&(r(o.body),s(o.body)),o.body.type===X.BlockStatement))for(let i of o.body.body)i.type===X.ReturnStatement&&i.argument?.type===X.ObjectExpression&&(r(i.argument),s(i.argument));if(o.type===X.FunctionExpression)for(let i of o.body.body)i.type===X.ReturnStatement&&i.argument?.type===X.ObjectExpression&&(r(i.argument),s(i.argument))}}}}}),Me={name:xt,rule:Ln};import{AST_NODE_TYPES as ee}from"@typescript-eslint/utils";import{ESLintUtils as _n}from"@typescript-eslint/utils";function pe(e){let n=_n.RuleCreator(r=>`https://github.com/lucasols/extended-lint#${r}`)(e);return{name:e.name,rule:n}}var Mn=D({disallow:P(V(D({selector:F(),message:F(),replace:P(Ce(F(),D({regex:F(),with:F()}))),replaceType:P(Ie(["suggestion","autofix"]))}))),disallowFnCalls:P(V(D({fn:F(),withArgs:P(V(D({atIndex:_e(),value:Ce(F(),J(),oe())}))),message:F(),replaceWith:P(F()),ignoreRegex:P(F())}))),__dev_simulateFileName:P(F()),mustMatchSyntax:P(V(D({includeRegex:F(),mustCallFn:P(V(D({anyCall:V(D({fn:F(),withArgs:V(D({atIndex:_e(),literal:Ce(F(),J(),oe())}))})),message:P(F())}))),mustMatchSelector:P(V(D({selector:F(),message:F()})))})))}),$e=pe({name:"advanced-no-restricted-syntax",meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Mn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:s,disallow:l,disallowFnCalls:o}=t,i=s??e.filename,a=[],c=new Map,p=new Set,u=new Map,g=new Map;function S(d){for(let m of d.specifiers)m.type===ee.ImportSpecifier&&m.imported.type===ee.Identifier&&m.local.type===ee.Identifier&&m.imported.name!==m.local.name&&g.set(m.local.name,m.imported.name)}function E(d){d.id.type===ee.Identifier&&d.init?.type===ee.Identifier&&g.set(d.id.name,d.init.name)}function T(d){return g.get(d)??d}function w(d,m){return T(d)===m||d===m}for(let{includeRegex:d,mustCallFn:m,mustMatchSelector:v}of r??[]){let R=$n(i,new RegExp(d));if(!R)continue;let A=O=>{let x=O;for(let{name:M,value:z}of R)x=x.replaceAll(M,z);return x};for(let{anyCall:O,message:x}of m??[]){let M=`Expected file to call the function: ${O.map(({fn:z})=>z).join(" or ")}`;p.add(M),a.push(z=>{let{callee:ie}=z;if(ie.type===ee.Identifier){for(let{fn:Fe,withArgs:Te}of O)if(ie.name===Fe){p.delete(M);for(let le of Te){let q=z.arguments[le.atIndex],ne=typeof le.literal=="string"?A(le.literal):le.literal;if(!q){e.report({node:z,messageId:"default",data:{message:`Missing argument with value "${ne}" at index ${le.atIndex}${x?`: ${A(x)}`:""}`}});continue}if(q.type!==ee.Literal){e.report({node:q,messageId:"default",data:{message:`Argument at position ${le.atIndex} should the literal "${ne}"${x?`: ${A(x)}`:""}`}});continue}q.value!==ne&&e.report({node:q,messageId:"default",data:{message:`Argument should have the value "${ne}"${x?`: ${A(x)}`:""}`},fix:he=>he.replaceText(q,typeof ne=="string"?`'${ne}'`:String(ne))})}break}}})}for(let{selector:O,message:x}of v??[])u.set(O,A(x)),c.set(A(O),()=>{u.delete(O)})}for(let{fn:d,withArgs:m,message:v,replaceWith:R,ignoreRegex:A}of o??[])A&&new RegExp(A).test(i)||a.push(O=>{let{callee:x}=O;if(x.type!==ee.Identifier||!w(x.name,d))return;if(m)for(let z of m){let ie=O.arguments[z.atIndex];if(!ie){e.report({node:O,messageId:"default",data:{message:`Missing argument with value "${z.value}" at index ${z.atIndex}: ${v}`}});return}if(ie.type!==ee.Literal||ie.value!==z.value)return}let M=z=>R?z.replaceText(O,R):null;e.report({node:O,messageId:"default",data:{message:v},suggest:R?[{messageId:"default",data:{message:`Replace with "${R}"`},fix:M}]:void 0})});function h(d,m){let v=n[d];v?n[d]=R=>{v(R),m(R)}:n[d]=m}for(let{selector:d,message:m,replace:v,replaceType:R="suggestion"}of l??[]){if(d==="CallExpression"){a.push(A=>{_(v,A,m,R)});continue}n[d]=A=>{_(v,A,m,R)}}if(c.size>0)for(let[d,m]of c)h(d,m);return a.length>0&&(n.CallExpression=d=>{if(d.type===ee.CallExpression)for(let m of a)m(d)}),n.ImportDeclaration=d=>{d.type===ee.ImportDeclaration&&S(d)},n.VariableDeclarator=d=>{d.type===ee.VariableDeclarator&&E(d)},n["Program:exit"]=d=>{for(let m of p)e.report({node:d,messageId:"default",data:{message:m}});for(let[,m]of u)e.report({node:d,messageId:"default",data:{message:m}})},n;function _(d,m,v,R){let A=O=>{if(!d)return null;if(typeof d=="string")return O.replaceText(m,d);{let x=new RegExp(d.regex),M=e.sourceCode.getText(m);return O.replaceText(m,M.replace(x,d.with))}};e.report({node:m,messageId:"default",data:{message:v},fix:d&&R==="autofix"?A:void 0,suggest:d&&R==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof d=="string"?d:d.with}"`},fix:A}]:void 0})}}});function $n(e,t){let n=[],r=t.exec(e);if(!r)return null;let[s,...l]=r;n.push({name:"$0_lowercase",value:s.toLowerCase()}),n.push({name:"$0_capitalize",value:It(s)}),n.push({name:"$0_uncapitalize",value:Ct(s)}),n.push({name:"$0",value:s});for(let o=0;o<l.length;o++){let i=`$${o+1}`,a=l[o];n.push({name:`${i}_lowercase`,value:a.toLowerCase()}),n.push({name:`${i}_capitalize`,value:It(a)}),n.push({name:`${i}_uncapitalize`,value:Ct(a)}),n.push({name:i,value:a})}return n}function It(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ct(e){return e.charAt(0).toLowerCase()+e.slice(1)}import{AST_NODE_TYPES as $,AST_TOKEN_TYPES as Un,ESLintUtils as Vn}from"@typescript-eslint/utils";var Wn=Vn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Rt="collapse-simple-objs-in-one-line",Hn=D({maxLineLength:P(J()),maxProperties:P(J()),nestedObjMaxLineLength:P(J()),nestedObjMaxProperties:P(J()),ignoreTypesWithSuffix:P(V(F()))}),Yn=Wn({name:Rt,meta:{type:"suggestion",fixable:"code",docs:{description:"Format simple objects and types in one line"},messages:{singleLineProp:"Object/type should be written in a single line"},schema:[Hn]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],s=t.maxProperties??2,l=t.nestedObjMaxLineLength??t.maxLineLength,o=t.nestedObjMaxProperties??3;function i(c){if(c.type===$.ObjectExpression){let p=c.parent.type===$.Property,u=p?o:s,g=c.properties.length;if(g>u)return!1;if(g===1){let E=c.properties[0];return E.type===$.Property&&E.value.type===$.ObjectExpression||E.type===$.Property&&E.value.type===$.ArrayExpression&&!E.value.elements.every(w=>w&&Ue(w))?!1:{text:n.getText(E),isNested:p,propsSize:g}}let S=[];for(let E of c.properties){if(E.type===$.Property&&!Ue(E.value))return!1;S.push(n.getText(E))}return{text:S.join(", "),isNested:p,propsSize:g}}else{let p=c.parent.parent?.type===$.TSPropertySignature,u=p?o:s,g=c.members.length;if(g>u)return!1;if(r.length>0&&c.parent.type===$.TSTypeAliasDeclaration){let E=c.parent.id.name;if(r.some(T=>E.endsWith(T)))return!1}if(g===1){let E=c.members[0];return E.type===$.TSPropertySignature&&E.typeAnnotation?.typeAnnotation.type===$.TSTypeLiteral?!1:{text:n.getText(E),isNested:p,propsSize:1}}if(c.parent.type===$.TSIntersectionType||c.parent.type===$.TSUnionType)return!1;let S=[];for(let E of c.members){if(E.type!==$.TSPropertySignature)return!1;let T=E.typeAnnotation?.typeAnnotation;if(!T||T.type===$.TSTypeLiteral||!wt(T))return!1;if(T.type===$.TSTypeReference&&T.typeArguments){if(T.typeArguments.params.length>1)return!1;let h=T.typeArguments.params[0];if(!wt(h))return!1}let w=n.getText(E).trim();(w.endsWith(";")||w.endsWith(","))&&(w=w.slice(0,-1)),S.push(w)}return{text:S.join("; "),isNested:p,propsSize:g}}}function a(c){if(c.loc.start.line===c.loc.end.line)return;if(c.parent.type!==$.JSXExpressionContainer){let T=0,w=n.getTokenAfter(c,{filter:h=>h.type!==Un.Punctuator?!0:h.value===","||h.value===";"||h.value===")"||h.value==="}"?(T++,!1):!0});if(T>4||w?.loc.start.line===c.loc.end.line)return}let p=i(c);if(!p)return;let u=p.text;if(u.includes(`
|
|
2
2
|
`)||n.getCommentsInside(c).length>0)return;u.endsWith(";")&&(u=u.slice(0,-1));let g=`{ ${u} }`,S=Bn(n,c),E=p.isNested&&p.propsSize>2?l:t.maxLineLength;E&&g.length+S.length+zn(c,n)>E||e.report({node:c,messageId:"singleLineProp",fix:T=>T.replaceText(c,g)})}return{TSTypeLiteral:a,ObjectExpression:a}}});function wt(e){return e.type===$.TSLiteralType||e.type===$.TSTypeReference||e.type===$.TSNumberKeyword||e.type===$.TSStringKeyword||e.type===$.TSBooleanKeyword||e.type===$.TSNullKeyword||e.type===$.TSUndefinedKeyword}function Ue(e,t){return!!(e.type===$.Literal||e.type===$.Identifier||e.type===$.TemplateLiteral||e.type===$.TaggedTemplateExpression||!t&&e.type===$.ArrayExpression&&e.elements.every(n=>n&&Ue(n,!0)))}function zn(e,t){let n=t.getLastToken(e);if(!n)return 0;let r=t.text.indexOf(`
|
|
3
|
-
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function Bn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Ve={name:Rt,rule:Yn};var qn=/eslint +react-compiler\/react-compiler: +\["error/,kt={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"?h=>n(h):h=>e.sourceCode.getText(h),r=typeof e.getScope=="function"?()=>r():h=>e.sourceCode.getScope(h),s=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,l=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,o={additionalHooks:s,enableDangerousAutofixThisMayCauseInfiniteLoops:l};function i(h){l&&Array.isArray(h.suggest)&&h.suggest.length>0&&(h.fix=h.suggest[0].fix),e.report(h)}let a=e.getSourceCode().scopeManager,c=new WeakMap,p=new WeakSet,u=new WeakMap,g=new WeakMap,S=new WeakSet;function E(h,_){return function(d){if(_.has(d))return _.get(d);let m=h(d);return _.set(d,m),m}}function T(h,_,d,m,
|
|
3
|
+
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function Bn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Ve={name:Rt,rule:Yn};var qn=/eslint +react-compiler\/react-compiler: +\["error/,kt={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"?h=>n(h):h=>e.sourceCode.getText(h),r=typeof e.getScope=="function"?()=>r():h=>e.sourceCode.getScope(h),s=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,l=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,o={additionalHooks:s,enableDangerousAutofixThisMayCauseInfiniteLoops:l};function i(h){l&&Array.isArray(h.suggest)&&h.suggest.length>0&&(h.fix=h.suggest[0].fix),e.report(h)}let a=e.getSourceCode().scopeManager,c=new WeakMap,p=new WeakSet,u=new WeakMap,g=new WeakMap,S=new WeakSet;function E(h,_){return function(d){if(_.has(d))return _.get(d);let m=h(d);return _.set(d,m),m}}function T(h,_,d,m,v){v&&h.async&&i({node:h,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
|
|
4
4
|
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
async function fetchData() {
|
|
@@ -11,5 +11,5 @@ useEffect(() => {
|
|
|
11
11
|
fetchData();
|
|
12
12
|
}, [someId]); // Or [] if effect doesn't need props or state
|
|
13
13
|
|
|
14
|
-
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let v=a.acquire(h),A=new Set,O=null;{let f=v.upper;for(;f&&(A.add(f),f.type!=="function");)f=f.upper;if(!f)return;O=f}let x=Array.isArray;function M(f){if(!x(f.defs))return!1;let y=f.defs[0];if(y==null||y.node.type!=="VariableDeclarator")return!1;let b=y.node.init;if(b==null)return!1;for(;b.type==="TSAsExpression";)b=b.expression;let I=y.node.parent;if(I==null&&(Ye(O.block,y.node.id),I=y.node.parent,I==null))return!1;if(I.kind==="const"&&b.type==="Literal"&&(typeof b.value=="string"||typeof b.value=="number"||b.value===null))return!0;if(b.type!=="CallExpression")return!1;let k=b.callee;if(k.type==="MemberExpression"&&k.object.name==="React"&&k.property!=null&&!k.computed&&(k=k.property),k.type!=="Identifier")return!1;let C=y.node.id,{name:N}=k;if(N==="useRef"&&C.type==="Identifier")return!0;if(Zn(k)&&C.type==="Identifier"){for(let L of f.references)L!==C&&S.add(L.identifier);return!0}else if(N==="useState"||N==="useReducer"){if(C.type==="ArrayPattern"&&C.elements.length===2&&x(f.identifiers)){if(C.elements[1]===f.identifiers[0]){if(N==="useState"){let L=f.references,Z=0;for(let se=0;se<L.length;se++){if(L[se].isWrite()&&Z++,Z>1)return!1;c.set(L[se].identifier,C.elements[0])}}return!0}else if(C.elements[0]===f.identifiers[0]){if(N==="useState"){let L=f.references;for(let Z=0;Z<L.length;Z++)p.add(L[Z].identifier)}return!1}}}else if(N==="useTransition"&&C.type==="ArrayPattern"&&C.elements.length===2&&Array.isArray(f.identifiers)&&C.elements[1]===f.identifiers[0])return!0;return!1}function V(f){if(!x(f.defs))return!1;let y=f.defs[0];if(y==null||y.node==null||y.node.id==null)return!1;let b=y.node,I=O.childScopes,k=null,C;for(C=0;C<I.length;C++){let N=I[C],L=N.block;if(b.type==="FunctionDeclaration"&&L===b||b.type==="VariableDeclarator"&&L.parent===b){k=N;break}}if(k==null)return!1;for(C=0;C<k.through.length;C++){let N=k.through[C];if(N.resolved!=null&&A.has(N.resolved.scope)&&!ie(N.resolved))return!1}return!0}let ie=E(M,u),Fe=E(V,g),Te=new Map;function le(f){let y=f.from,b=!1;for(;y.block!==h;)y.type==="function"&&(b=y.block.parent!=null&&y.block.parent.type==="ReturnStatement"),y=y.upper;return b}let q=new Map,ne=new Map;he(v);function he(f){for(let y of f.references){if(!y.resolved||!A.has(y.resolved.scope))continue;let b=Ye(h,y.identifier),I=At(b),k=ae(I,ne);if(R&&I.type==="Identifier"&&(I.parent.type==="MemberExpression"||I.parent.type==="OptionalMemberExpression")&&!I.parent.computed&&I.parent.property.type==="Identifier"&&I.parent.property.name==="current"&&le(y)&&Te.set(k,{reference:y,dependencyNode:I}),I.parent.type==="TSTypeQuery"||I.parent.type==="TSTypeReference")continue;let C=y.resolved.defs[0];if(C!=null&&!(C.node!=null&&C.node.init===h.parent)&&C.type!=="TypeParameter")if(q.has(k))q.get(k).references.push(y);else{let N=y.resolved,L=ie(N)||Fe(N);q.set(k,{isStable:L,references:[y]})}}for(let y of f.childScopes)he(y)}Te.forEach(({reference:f,dependencyNode:y},b)=>{let I=f.resolved.references,k=!1;for(let C=0;C<I.length;C++){let{identifier:N}=I[C],{parent:L}=N;if(L!=null&&L.type==="MemberExpression"&&!L.computed&&L.property.type==="Identifier"&&L.property.name==="current"&&L.parent.type==="AssignmentExpression"&&L.parent.left===L){k=!0;break}}k||i({node:y.parent.property,message:`The ref value '${b}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${b}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Ne=new Set;function wn(f,y){Ne.has(y)||(Ne.add(y),i({node:f,message:`Assignments to the '${y}' variable from inside React Hook ${n(d)} 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(d)}.`}))}let Ee=new Set;if(q.forEach(({isStable:f,references:y},b)=>{f&&Ee.add(b),y.forEach(I=>{I.writeExpr&&wn(I.writeExpr,b)})}),Ne.size>0)return;if(!_){let f=null;if(q.forEach(({isStable:y,references:b},I)=>{f||b.forEach(k=>{if(f)return;let C=k.identifier;if(!c.has(C))return;let L=k.from;for(;L.type!=="function";)L=L.upper;L.block===h&&(f=I)})}),f){let{suggestedDependencies:y}=We({dependencies:q,declaredDependencies:[],stableDependencies:Ee,externalDependencies:new Set,isEffect:!0});i({node:d,message:`React Hook ${m} contains a call to '${f}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+y.join(", ")+`] as a second argument to the ${m} Hook.`,suggest:[{desc:`Add dependencies array: [${y.join(", ")}]`,fix(b){return b.insertTextAfter(h,`, [${y.join(", ")}]`)}}]})}return}let ye=[],ge=new Set;_.type!=="ArrayExpression"?i({node:_,message:`React Hook ${n(d)} 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.`}):_.elements.forEach(f=>{if(f===null)return;if(f.type==="SpreadElement"){i({node:f,message:`React Hook ${n(d)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}S.has(f)&&i({node:f,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(f)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(f)}\``,fix(k){return k.removeRange(f.range)}}]});let y;try{y=ae(f,ne)}catch(k){if(/Unsupported node type/.test(k.message)){f.type==="Literal"?q.has(f.value)?i({node:f,message:`The ${f.raw} literal is not a valid dependency because it never changes. Did you mean to include ${f.value} in the array instead?`}):i({node:f,message:`The ${f.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):i({node:f,message:`React Hook ${n(d)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw k}let b=f;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let I=!O.through.some(k=>k.identifier===b);ye.push({key:y,node:f}),I||ge.add(y)});let{suggestedDependencies:Rn,unnecessaryDependencies:be,missingDependencies:ce,duplicateDependencies:Tt}=We({dependencies:q,declaredDependencies:ye,stableDependencies:Ee,externalDependencies:ge,isEffect:R}),xe=Rn;if(Tt.size+ce.size+be.size===0){if(t)return;Xn({declaredDependencies:ye,declaredDependenciesNode:_,componentScope:O,scope:v}).forEach(({construction:y,isUsedOutsideOfHook:b,depType:I})=>{let k=I==="function"?"useCallback":"useMemo",C=I==="function"?"definition":"initialization",N=`wrap the ${C} of '${y.name.name}' in its own ${k}() Hook.`,L=b?`To fix this, ${N}`:`Move it inside the ${m} callback. Alternatively, ${N}`,Z=I==="conditional"||I==="logical expression"?"could make":"makes",se=`The '${y.name.name}' ${I} ${Z} the dependencies of ${m} Hook (at line ${_.loc.start.line}) change on every render. ${L}`,ht;b&&y.type==="Variable"&&I==="function"&&(ht=[{desc:`Wrap the ${C} of '${y.name.name}' in its own ${k}() Hook.`,fix(Et){let[kn,An]=k==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Et.insertTextBefore(y.node.init,kn),Et.insertTextAfter(y.node.init,An)]}}]),i({node:y.node,message:se,suggest:ht})});return}!R&&ce.size>0&&(xe=We({dependencies:q,declaredDependencies:[],stableDependencies:Ee,externalDependencies:ge,isEffect:R}).suggestedDependencies);function vn(){if(ye.length===0)return!0;let f=ye.map(b=>b.key),y=f.slice().sort();return f.join(",")===y.join(",")}vn()&&xe.sort();function De(f){let y=f.split("."),b="";for(let I=0;I<y.length;I++){if(I!==0){let k=y.slice(0,I+1).join("."),C=ne.get(k)===!0;b+=C?"?.":"."}b+=y[I]}return b}function je(f,y,b,I){return f.size===0?null:(f.size>1?"":y+" ")+b+" "+(f.size>1?"dependencies":"dependency")+": "+Jn(Array.from(f).sort().map(k=>"'"+De(k)+"'"))+`. Either ${I} ${f.size>1?"them":"it"} or remove the dependency array.`}let re="";if(be.size>0){let f=null;if(Array.from(be.keys()).forEach(y=>{f===null&&y.endsWith(".current")&&(f=y)}),f!==null)re=` Mutable values like '${f}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(ge.size>0){let y=Array.from(ge)[0];v.set.has(y)||(re=` Outer scope values like '${y}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!re&&ce.has("props")){let f=q.get("props");if(f==null)return;let y=f.references;if(!Array.isArray(y))return;let b=!0;for(let I=0;I<y.length;I++){let k=y[I],C=Ye(O.block,k.identifier);if(!C){b=!1;break}let N=C.parent;if(N==null){b=!1;break}if(N.type!=="MemberExpression"&&N.type!=="OptionalMemberExpression"){b=!1;break}}b&&(re=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${m} call and refer to those specific props inside ${n(d)}.`)}if(!re&&ce.size>0){let f=null;ce.forEach(y=>{if(f)return;let b=O.set.get(y),I=q.get(y);if(I.references[0].resolved!==b)return;let k=b.defs[0];if(k==null||k.name==null||k.type!=="Parameter")return;let C=!1,N;for(let L=0;L<I.references.length;L++)if(N=I.references[L].identifier,N!=null&&N.parent!=null&&(N.parent.type==="CallExpression"||N.parent.type==="OptionalCallExpression")&&N.parent.callee===N){C=!0;break}C&&(f=y)}),f!==null&&(re=` If '${f}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!re&&ce.size>0){let f=null;if(ce.forEach(y=>{if(f!==null)return;let I=q.get(y).references,k,C;for(let N=0;N<I.length;N++){for(k=I[N].identifier,C=k.parent;C!=null&&C!==O.block;){if(C.type==="CallExpression"){let L=c.get(C.callee);if(L!=null){if(L.name===y)f={missingDep:y,setter:C.callee.name,form:"updater"};else if(p.has(k))f={missingDep:y,setter:C.callee.name,form:"reducer"};else{let Z=I[N].resolved;if(Z!=null){let se=Z.defs[0];se!=null&&se.type==="Parameter"&&(f={missingDep:y,setter:C.callee.name,form:"inlineReducer"})}}break}}C=C.parent}if(f!==null)break}}),f!==null)switch(f.form){case"reducer":re=` You can also replace multiple useState variables with useReducer if '${f.setter}' needs the current value of '${f.missingDep}'.`;break;case"inlineReducer":re=` If '${f.setter}' needs the current value of '${f.missingDep}', you can also switch to useReducer instead of useState and read '${f.missingDep}' in the reducer.`;break;case"updater":re=` You can also do a functional update '${f.setter}(${f.missingDep.slice(0,1)} => ...)' if you only need '${f.missingDep}' in the '${f.setter}' call.`;break;default:throw new Error("Unknown case.")}}i({node:_,message:`React Hook ${n(d)} has `+(je(ce,"a","missing","include")||je(be,"an","unnecessary","exclude")||je(Tt,"a","duplicate","omit"))+re,suggest:[{desc:`Update the dependencies array to be: [${xe.map(De).join(", ")}]`,fix(f){return f.replaceText(_,`[${xe.map(De).join(", ")}]`)}}]})}function w(h){let _=Kn(h.callee,o);if(_===-1)return;let d=h.arguments[_],m=h.callee,R=Ot(m).name,v=h.arguments[_+1],A=/Effect($|[^a-z])/g.test(R);if(!d){i({node:m,message:`React Hook ${R} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!A)){if(!v&&!A){(R==="useMemo"||R==="useCallback")&&i({node:m,message:`React Hook ${R} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(d.type){case"FunctionExpression":case"ArrowFunctionExpression":T(d,v,m,R,A);return;case"Identifier":if(!v||v.elements&&v.elements.some(M=>M&&M.type==="Identifier"&&M.name===d.name))return;let O=r(h).set.get(d.name);if(O==null||O.defs==null)return;let x=O.defs[0];if(!x||!x.node||x.type!=="Variable"&&x.type!=="FunctionName")break;switch(x.node.type){case"FunctionDeclaration":T(x.node,v,m,R,A);return;case"VariableDeclarator":let M=x.node.init;if(!M)break;switch(M.type){case"ArrowFunctionExpression":case"FunctionExpression":T(M,v,m,R,A);return}break}break;default:i({node:m,message:`React Hook ${R} received a function whose dependencies are unknown. Pass an inline function instead.`});return}i({node:m,message:`React Hook ${R} has a missing dependency: '${d.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${d.name}]`,fix(O){return O.replaceText(v,`[${d.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let h of e.sourceCode.getAllComments())if(qn.test(h.value))return t=!0,{CallExpression:_=>w(_,!0)}}return{CallExpression:h=>w(h)}}};function We({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:s}){let l=o();function o(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,w)=>{let h=i(l,w);h.isUsed=!0,a(l,w,_=>{_.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let w=i(l,T);w.isSatisfiedRecursively=!0}),n.forEach(T=>{let w=i(l,T);w.isSatisfiedRecursively=!0});function i(T,w){let h=w.split("."),_=T;for(let d of h){let m=_.children.get(d);m||(m=o(),_.children.set(d,m)),_=m}return _}function a(T,w,h){let _=w.split("."),d=T;for(let m of _){let R=d.children.get(m);if(!R)return;h(R),d=R}}let c=new Set,p=new Set;u(l,c,p,T=>T);function u(T,w,h,_){T.children.forEach((d,m)=>{let R=_(m);if(d.isSatisfiedRecursively){d.isSubtreeUsed&&h.add(R);return}if(d.isUsed){w.add(R);return}u(d,w,h,v=>R+"."+v)})}let g=[],S=new Set,E=new Set;return t.forEach(({key:T})=>{p.has(T)?g.indexOf(T)===-1?g.push(T):E.add(T):S.add(T)}),c.forEach(T=>{g.push(T)}),{suggestedDependencies:g,unnecessaryDependencies:S,duplicateDependencies:E,missingDependencies:c}}function ue(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 ue(e.consequent)!=null||ue(e.alternate)!=null?"conditional":null;case"LogicalExpression":return ue(e.left)!=null||ue(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return ue(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return ue(e.expression);case"TSAsExpression":return ue(e.expression)}return null}function Xn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let s=e.map(({key:o})=>{let i=n.variables.find(c=>c.name===o);if(i==null)return null;let a=i.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 c=ue(a.node.init);if(c!=null)return[i,c]}return a.type==="FunctionName"&&a.node.type==="FunctionDeclaration"?[i,"function"]:a.type==="ClassName"&&a.node.type==="ClassDeclaration"?[i,"class"]:null}).filter(Boolean);function l(o){let i=!1;for(let a=0;a<o.references.length;a++){let c=o.references[a];if(c.writeExpr){if(i)return!0;i=!0;continue}let p=c.from;for(;p!==r&&p!=null;)p=p.upper;if(p!==r&&!Pt(t,c.identifier))return!0}return!1}return s.map(([o,i])=>({construction:o.defs[0],depType:i,isUsedOutsideOfHook:l(o)}))}function At(e){return(e.parent.type==="MemberExpression"||e.parent.type==="OptionalMemberExpression")&&e.parent.object===e&&e.parent.property.name!=="current"&&!e.parent.computed&&!(e.parent.parent!=null&&(e.parent.parent.type==="CallExpression"||e.parent.parent.type==="OptionalCallExpression")&&e.parent.parent.callee===e.parent)?At(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function He(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function ae(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=ae(e.object,t),r=ae(e.property,null),s=`${n}.${r}`;return He(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=ae(e.object,t),r=ae(e.property,null),s=`${n}.${r}`;return He(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=ae(n.object,t),s=ae(n.property,null),l=`${r}.${s}`;return He(n,t,l),l}else throw new Error(`Unsupported node type: ${e.type}`)}function Ot(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=Ot(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let r;try{r=ae(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(r)?0:-1}else return-1}}function Ye(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Gn(r,t))return r;if(Pt(r,t))for(let[s,l]of Object.entries(r))s!=="parent"&&(vt(l)?(l.parent=r,n.push(l)):Array.isArray(l)&&l.forEach(o=>{vt(o)&&(o.parent=r,n.push(o))}))}return null}function Jn(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function vt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Gn(e,t){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===t.type&&e.name===t.name&&e.range[0]===t.range[0]&&e.range[1]===t.range[1]}function Pt(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Zn(e){return!1}import{AST_NODE_TYPES as Re,ESLintUtils as Nt}from"@typescript-eslint/utils";import K from"typescript";var Qn=Nt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ft="improved-no-unnecessary-condition",er=D({}),tr=["string","number","bigint","boolean","symbol","undefined","object","function","never"],nr=new Set(tr),ze={name:Ft,rule:Qn({name:Ft,meta:{type:"suggestion",docs:{description:"Extends checks of `no-unnecessary-condition` rule"},messages:{unnecessaryTypeofCondition:'This condition is unnecessary. The type of "{{name}}" is always "{{type}}".',alwaysFalseTypeofCondition:'This condition will always be false. The type of "{{name}}" is "{{actualType}}" so the condition has no overlap with "{{conditionType}}".'},schema:[er]},defaultOptions:[{}],create(e){let t=Nt.getParserServices(e,!0),n=t.program?.getTypeChecker();if(!n||!t.program)throw new Error("TypeScript services or program not available");function r(i){return i.type===Re.UnaryExpression&&i.operator==="typeof"}function s(i){return i.flags&K.TypeFlags.Any||i.flags&K.TypeFlags.Unknown?null:i.flags&K.TypeFlags.StringLike?["string"]:i.flags&K.TypeFlags.NumberLike?["number"]:i.flags&K.TypeFlags.BigIntLike?["bigint"]:i.flags&K.TypeFlags.BooleanLike?["boolean"]:i.flags&K.TypeFlags.ESSymbolLike?["symbol"]:i.flags&K.TypeFlags.Undefined||i.flags&K.TypeFlags.Void?["undefined"]:i.flags&K.TypeFlags.Null?["object"]:i.getCallSignatures().length>0?["function"]:i.flags&K.TypeFlags.Object?i.getProperties().length===0?["string","number","bigint","boolean","symbol","object","function"]:["object"]:i.flags&K.TypeFlags.NonPrimitive?["object"]:i.flags&K.TypeFlags.Never?["never"]:null}function l(i){if(!n)return null;let a=t.esTreeNodeToTSNodeMap.get(i),c=n.getTypeAtLocation(a.expression);if(c.flags&K.TypeFlags.Any||c.flags&K.TypeFlags.Unknown)return null;let p=[];if(c.isUnion()){for(let g of c.types){let S=s(g);if(S)p.push(...S);else return null}return p}let u=s(c);return u?(p.push(...u),p):null}function o(i){if(!(i.operator==="==="||i.operator==="!=="))return;let c=null,p=null;if(r(i.left)?(c=i.left,p=i.right.type===Re.Literal&&typeof i.right.value=="string"?i.right.value:null):r(i.right)&&(c=i.right,p=i.left.type===Re.Literal&&typeof i.left.value=="string"?i.left.value:null),!c||!p||!rr(p,nr))return;let u=l(c);if(!u)return;let g=i.operator==="!==",S=u.includes(p);u.length===1?S&&!g?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:p}}):!S&&g?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:Array.from(u)[0]}}):!S&&!g?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(u),conditionType:p}}):S&&g&&e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(u),conditionType:p}}):!S&&!g?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(u),conditionType:p}}):!S&&g&&e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:we(u)}})}return{BinaryExpression:o}}})};function we(e){return Array.from(new Set(e)).join(" | ")||"never"}function fe(e,t){let n=e.argument;return n.type===Re.Identifier?n.name:t.sourceCode.getText(n)}function rr(e,t){return t.has(e)}import{AST_NODE_TYPES as ir,ESLintUtils as sr}from"@typescript-eslint/utils";var or=sr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Dt="no-call-with-explicit-generics",ar=D({functions:W(F())}),lr=or({name:Dt,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[ar]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:s}=r;s.type===ir.Identifier&&n.has(s.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),Be={name:Dt,rule:lr};import{AST_NODE_TYPES as ve,ESLintUtils as cr}from"@typescript-eslint/utils";var pr=cr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),jt="no-call-with-inferred-generics",ur=pr({name:jt,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Map(t.functions.map(r=>[r.name,r]));return{CallExpression(r){let{callee:s}=r;if(s.type!==ve.Identifier)return;let l=n.get(s.name);if(!l)return;let{minGenerics:o=1,allowAny:i,disallowTypes:a=t.disallowTypes}=l;(r.typeArguments?.params.length||0)<(o||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:o||0}}),!(i&&!a)&&r.typeArguments?.params?.some(p=>!i&&p.type===ve.TSAnyKeyword||a&&p.type===ve.TSTypeReference&&p.typeName.type===ve.Identifier&&a.includes(p.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),qe={name:jt,rule:ur};import{ESLintUtils as fr,TSESTree as Lt}from"@typescript-eslint/utils";var mr=fr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),_t="no-commented-out-code",dr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],yr=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],gr=mr({name:_t,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of dr)if(r.startsWith(s))return{wrongPattern:s};for(let s of yr)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let s of r)if(s.type===Lt.AST_TOKEN_TYPES.Line||s.type===Lt.AST_TOKEN_TYPES.Block){let l=t(s.value);l&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:l.wrongPattern}})}}}}}),Xe={name:_t,rule:gr};import{ESLintUtils as Sr,TSESTree as Tr}from"@typescript-eslint/utils";var hr=Sr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Mt="no-default-export",Er=hr({name:Mt,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.type===Tr.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ke={name:Mt,rule:Er};import{ESLintUtils as br}from"@typescript-eslint/utils";var xr=br.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="no-leaked-text-in-jsx",Ir=[",",";","[","]","(",")"],Cr=xr({name:$t,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";Ir.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Je={name:$t,rule:Cr};import{AST_NODE_TYPES as me,ESLintUtils as wr}from"@typescript-eslint/utils";var Rr=wr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="no-non-camel-case-functions",vr=/^[a-z][a-zA-Z0-9]*$/;function Ut(e){return e.typeName.type===me.TSQualifiedName&&e.typeName.left.type===me.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===me.Identifier&&e.typeName.right.name==="Element"}var kr=Rr({name:Vt,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!vr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===me.TSTypeReference?Ut(n):n.type===me.TSUnionType&&n.types.some(s=>s.type===me.TSTypeReference&&Ut(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Ge={name:Vt,rule:kr};import{ESLintUtils as Ar,TSESTree as H}from"@typescript-eslint/utils";import{AST_NODE_TYPES as Wt}from"@typescript-eslint/utils";function de(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:de(e.parent,t,n===1/0?n:n-1)}function*Ze(e){yield e,e.parent&&(yield*Ze(e.parent))}function Qe(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function Ht(e,t,n){let s=n.getDeclaredVariables(e).find(l=>l.name===t||l.identifiers[0]?.parent.type===Wt.Property&&l.identifiers[0]?.parent.key.type===Wt.Identifier&&l.identifiers[0]?.parent.key.name===t);return s?s.references.filter(l=>!l.init):[]}var Or=Ar.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Yt="no-optional-root-props",Pr=Or({name:Yt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let l=e.sourceCode.getDeclaredVariables(r)[0];if(!l||l.references.length!==1)return!1;let o=l.references[0];if(!o)return!1;for(let i of Ze(o.identifier)){if("returnType"in i||i.type===H.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let a=i.parent;if(!a)return!1;if(a.type===H.AST_NODE_TYPES.TSTypeParameterInstantiation&&a.parent.type===H.AST_NODE_TYPES.TSTypeReference&&a.parent.typeName.type===H.AST_NODE_TYPES.Identifier&&a.parent.typeName.name==="FC"){let p=de(a.parent.parent,H.AST_NODE_TYPES.VariableDeclaration,4);if(!p)return!1;let u=ke(p,e.sourceCode);return u?!(u.parent.type===H.AST_NODE_TYPES.CallExpression&&u.parent.callee.type===H.AST_NODE_TYPES.Identifier&&u.parent.callee.name==="memo"):!1}if(i.type===H.AST_NODE_TYPES.AssignmentPattern)return!1;if(a.type===H.AST_NODE_TYPES.ArrowFunctionExpression){let c=de(a,H.AST_NODE_TYPES.VariableDeclaration);return c?!!ke(c,e.sourceCode):!1}if(a.type===H.AST_NODE_TYPES.FunctionDeclaration)return!!ke(a,e.sourceCode)}return!1}function n(r){r.key.type!==H.AST_NODE_TYPES.Identifier||!r.optional||e.report({node:r.key,messageId:"optionalNotAllowed",data:{propertyName:r.key.name},suggest:[{messageId:"suggestion",fix:s=>{let l=de(r,H.AST_NODE_TYPES.TSPropertySignature);if(!l)return null;let o=e.sourceCode.getText(l);return s.replaceText(l,o.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(r){if(r.typeAnnotation.type===H.AST_NODE_TYPES.TSTypeLiteral&&!(Ae(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===H.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(Ae(r)||!t(r)))for(let s of r.body.body)s.type===H.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSTypeReference(r){if(r.typeName.type!==H.AST_NODE_TYPES.Identifier||r.typeName.name!=="FC"||!r.typeArguments?.params[0])return;let s=r.typeArguments.params[0];if(s.type!==H.AST_NODE_TYPES.TSTypeLiteral)return;let l=de(r.parent,H.AST_NODE_TYPES.VariableDeclaration,4);if(!l)return;let o=ke(l,e.sourceCode);if(!(!o||o.parent.type===H.AST_NODE_TYPES.CallExpression&&o.parent.callee.type===H.AST_NODE_TYPES.Identifier&&o.parent.callee.name==="memo"))for(let a of s.members)a.type===H.AST_NODE_TYPES.TSPropertySignature&&n(a)}}}});function Ae(e){return e?e.parent?.type===H.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===H.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function ke(e,t){if(Ae(e))return;let n;if(e.type===H.AST_NODE_TYPES.VariableDeclaration){if(e.declarations.length!==1)return;e.declarations[0].id.type===H.AST_NODE_TYPES.Identifier&&(n=e.declarations[0].id)}else{if(!e.id)return;n=e.id}if(!n)return;let r=t.getScope(e);e.type===H.AST_NODE_TYPES.FunctionDeclaration&&r.upper&&(r=r.upper);let s=r.variables.find(o=>o.identifiers.includes(n));if(!s)return;let l=s.references.filter(o=>o.identifier!==n);if(!(l.length!==1||!l[0])&&!Ae(l[0].identifier.parent.parent))return l[0].identifier}var et={name:Yt,rule:Pr};import{ESLintUtils as Fr}from"@typescript-eslint/utils";import tt from"node:path";var Nr=Fr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),zt="no-relative-imports",Dr=D({find:F(),replacement:F()}),jr=D({aliases:W(Dr),rootDir:P(F()),allowNotFoundAliases:P(oe()),_dev_simulateFileName:P(F())}),Lr=Nr({name:zt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[jr]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(o){return o.startsWith(".")||o.startsWith("..")}function s(o,i){let a=tt.dirname(i);return tt.resolve(a,o)}function l(o){let i=t.rootDir??process.cwd(),a=tt.relative(i,o);if(a.startsWith("."))return null;a.startsWith("/")||(a=`/${a}`);for(let{find:c,replacement:p}of t.aliases)if(a.startsWith(p)){let u=a.replace(p,c);return{alias:c,newPath:u}}return null}return{ImportDeclaration(o){let i=o.source.value;if(!r(i))return;let a=s(i,n),c=l(a);!c&&t.allowNotFoundAliases||e.report({node:o,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?p=>p.replaceText(o.source,`'${c.newPath}'`):void 0})}}}}),nt={name:zt,rule:Lr};import{AST_NODE_TYPES as Se,ESLintUtils as qt}from"@typescript-eslint/utils";import*as rt from"typescript";var _r=qt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Bt="no-unnecessary-casting",Mr=D({additionalCastFunctions:P(W(D({name:F(),expectedType:Ie(["string","number"])})))}),it={name:Bt,rule:_r({name:Bt,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[Mr],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=qt.getParserServices(e,!0),l=s.program?.getTypeChecker();if(!l||!s.program)throw new Error("TypeScript services or program not available");function o(p,u){switch(p.type){case Se.Literal:return u==="number"?typeof p.value=="number":typeof p.value=="string";case Se.TemplateLiteral:return u==="string";case Se.UnaryExpression:return u==="number"?p.operator==="+"||p.operator==="-"||p.operator==="~":!1;default:return!1}}function i(p,u){return u==="number"?!!(p.flags&rt.TypeFlags.NumberLike):!!(p.flags&rt.TypeFlags.StringLike)}function a(p,u){return g=>g.replaceText(p,e.sourceCode.getText(u))}function c(p){if(!l||p.arguments.length!==1)return;let u=p.arguments[0];if(!u||u.type===Se.SpreadElement)return;let{callee:g}=p;if(g.type!==Se.Identifier)return;let S=g.name,E=r.find(w=>w.name===S);if(!E)return;if(o(u,E.expectedType)||i(l.getTypeAtLocation(s.esTreeNodeToTSNodeMap.get(u)),E.expectedType)){let w,h;S==="Number"?w="unnecessaryNumberCasting":S==="String"?w="unnecessaryStringCasting":(w="unnecessaryCustomCasting",h={name:E.name,type:E.expectedType}),e.report({node:p,messageId:w,...h?{data:h}:{},fix:a(p,u)})}}return{CallExpression:c}}})};import{AST_NODE_TYPES as G}from"@typescript-eslint/utils";var st=pe({name:"no-unused-obj-props",meta:{type:"suggestion",docs:{description:"Disallow unused properties when it is safe to remove them"},messages:{unusedObjectProperty:'The object property "{{name}}" is not being used',unusedReturnObjectProperty:'The object property "{{name}}" returned by this function is not being used'},schema:[]},defaultOptions:[],create(e){return{VariableDeclarator(t){if(t.id.type===G.ObjectPattern||!t.init||t.init.type!==G.ObjectExpression||t.id.type===G.Identifier&&t.id.typeAnnotation||t.parent.parent.type===G.ExportNamedDeclaration)return;let n=new Map;for(let o of t.init.properties)o.type===G.Property&&o.key.type===G.Identifier&&n.set(o.key.name,o);if(n.size===0||t.id.type!==G.Identifier)return;let r=$r(t,e.sourceCode);if(r.length===0)return;let s=t.init.properties.some(o=>o.type!==G.Property?!1:o.value.type===G.FunctionExpression),l=new Set;for(let o of r){if(o.identifier.parent.type!==G.MemberExpression)return;let i=o.identifier.parent;if(i.object!==o.identifier)return;if(i.computed)if(i.property.type===G.Literal&&typeof i.property.value=="string")l.add(i.property.value);else return;else{if(i.property.type!==G.Identifier)return;l.add(i.property.name)}if(i.parent.type===G.CallExpression&&s)return}for(let[o,i]of n)l.has(o)||e.report({node:i,messageId:"unusedObjectProperty",data:{name:o}})}}}});function $r(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}import{AST_NODE_TYPES as z,ESLintUtils as Ur}from"@typescript-eslint/utils";var Vr=D({selectors:W(D({name:F(),selectorProp:P(F()),selectorArgPos:P(J()),returnProp:P(F())}))}),Wr=Ur.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Xt="no-unused-selected-values",ot={name:Xt,rule:Wr({name:Xt,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[Vr]},defaultOptions:[{selectors:[]}],create(e,[t]){let{selectors:n=[]}=t,r=new Map(n.map(s=>[s.name,s]));return{VariableDeclarator(s){let l=null;if(s.init?.type===z.CallExpression&&(l=s.init),!l)return;let o=Yr(l);if(!o)return;let i=r.get(o);if(!i)return;let a=Hr(l,i.selectorArgPos??0,i.selectorProp);if(!a)return;let c=zr(a);if(!c)return;let p=Kt(c.properties,void 0);if(!p)return;if(s.id.type===z.ObjectPattern){let S=Kt(s.id.properties,i.returnProp);if(!S)return;for(let[E,T]of p)S.has(E)||e.report({node:T,messageId:"unusedSelectedValue",data:{name:E}});return}if(s.id.type!==z.Identifier||i.returnProp)return;let u=Br(s,e.sourceCode);if(u.length===0)return;let g=new Set;for(let S of u){if(S.identifier.parent.type!==z.MemberExpression)return;let E=S.identifier.parent.property;if(E.type!==z.Identifier)return;g.add(E.name)}for(let[S,E]of p)g.has(S)||e.report({node:E,messageId:"unusedSelectedValue",data:{name:S}})}}}})};function Hr(e,t,n){let r=e.arguments[t];if(!r)return null;if(r.type===z.ArrowFunctionExpression||r.type===z.FunctionExpression)return r;if(n&&r.type===z.ObjectExpression){let s=r.properties.find(o=>o.type===z.Property&&o.key.type===z.Identifier&&o.key.name===n);if(s?.type!==z.Property)return null;let l=s.value;if(l.type===z.ArrowFunctionExpression||l.type===z.FunctionExpression)return l}return null}function Yr(e){return e.callee.type===z.Identifier?e.callee.name:e.callee.type===z.MemberExpression&&e.callee.property.type===z.Identifier?e.callee.property.name:null}function zr(e){if(e.body.type===z.ObjectExpression)return e.body;if(e.body.type===z.BlockStatement){let t=e.body.body.filter(n=>n.type===z.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==z.ObjectExpression?null:t[0].argument}return null}function Kt(e,t){let n=e;if(t){let s=e.find(l=>l.type===z.Property&&l.key.type===z.Identifier&&l.key.name===t);if(s?.type!==z.Property||s.value.type!==z.ObjectPattern)return null;n=s.value.properties}let r=new Map;for(let s of n){if(s.type!==z.Property||s.key.type!==z.Identifier)return null;r.set(s.key.name,s)}return r.size>0?r:null}function Br(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}import{AST_NODE_TYPES as Y}from"@typescript-eslint/utils";var at=pe({name:"no-unused-t-state-field",meta:{type:"suggestion",docs:{description:"Prevent declaring unused t-state fields"},messages:{unusedField:'Field "{{name}}" is not being used, you can safely remove it'},schema:[]},defaultOptions:[],create(e){if(!(e.filename.endsWith(".jsx")||e.filename.endsWith(".tsx")))return{};if(!e.sourceCode.ast.body.some(l=>l.type===Y.ImportDeclaration&&l.source.value==="t-state-form"))return{};let r=null,s=!1;return{CallExpression(l){if(s)return;if(!r){let i=qr(l);i&&(r=i);return}let o=Xr(l,e.sourceCode);if(o){s=!0;for(let i of o)r.delete(i);if(r.size!==0)for(let[i,a]of r)e.report({node:a,messageId:"unusedField",data:{name:i}})}}}}});function qr(e){if(!(e.callee.type===Y.Identifier&&e.callee.name==="useForm"))return null;let n=e.arguments[0];if(!n||n.type!==Y.ObjectExpression)return null;let r=Qe(n.properties,l=>l.type!==Y.Property||l.key.type!==Y.Identifier||l.key.name!=="initialConfig"?null:l.value.type===Y.ObjectExpression?l.value:l.value.type===Y.ArrowFunctionExpression||l.value.type===Y.FunctionExpression?Kr(l.value):null);if(!r)return null;let s=new Map;for(let l of r.properties)l.type===Y.Property&&l.key.type===Y.Identifier&&s.set(l.key.name,l);return s}function Xr(e,t){if(!(e.callee.type===Y.Identifier&&e.callee.name==="useFormState")||e.parent.type!==Y.VariableDeclarator||e.parent.id.type!==Y.ObjectPattern||!Qe(e.parent.id.properties,o=>o.type===Y.Property&&o.key.type===Y.Identifier&&o.key.name==="formFields"&&o))return null;let s=Ht(e.parent,"formFields",t),l=new Set;for(let{identifier:o}of s){if(o.type!==Y.Identifier||o.parent.type===Y.Property&&o.parent.parent.type===Y.ObjectExpression&&o.parent.parent.parent.type===Y.ReturnStatement||o.parent.type===Y.ReturnStatement)return null;if(o.parent.type===Y.MemberExpression){if(o.parent.object.type!==Y.Identifier||o.parent.property.type!==Y.Identifier)return null;l.add(o.parent.property.name)}}return l}function Kr(e){if(e.body.type===Y.ObjectExpression)return e.body;if(e.body.type===Y.BlockStatement){let t=e.body.body.filter(n=>n.type===Y.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==Y.ObjectExpression?null:t[0].argument}return null}import{AST_NODE_TYPES as U,ESLintUtils as Jr}from"@typescript-eslint/utils";var Gr=Jr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Jt(e){let t=[];for(let n of e.members)n.type===U.TSPropertySignature&&n.key.type===U.Identifier&&t.push([n.key.name,n]);return t}function Gt(e,...t){for(let n of t)e.set(...n);return e}var Zr=D({forceCheckOnFCPropTypesWithName:P(W(F()))}),Zt="no-unused-type-props-in-args",lt=null,Qr=Gr({name:Zt,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Zr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!lt&&(lt=n.map(i=>new RegExp(i)));function r(i,a,c,p,u=!0){let g=c.name,S=e.sourceCode.getScope(a).references.find(w=>w.identifier.name===g)?.resolved,E=i&<?.some(w=>w.test(g));if(!S||!E&&S.references.filter(w=>w.isTypeReference).length>1)return;let T=S?.defs[0]?.node;if(!(u&&T?.parent?.type===U.ExportNamedDeclaration)){if(T?.type===U.TSTypeAliasDeclaration){s(i,a,p,T.typeAnnotation,!0);return}if(T?.type===U.TSInterfaceDeclaration){s(i,a,p,T.body,!0);return}}}function s(i,a,c,p,u){if(p.type===U.TSInterfaceBody){for(let g of p.body)g.type===U.TSPropertySignature&&g.key.type===U.Identifier&&c.set(g.key.name,g);return}if(p.type===U.TSTypeLiteral){Gt(c,...Jt(p));return}if(p.type===U.TSIntersectionType){for(let g of p.types)s(i,a,c,g,!0);return}u||p.type===U.TSTypeReference&&p.typeName.type===U.Identifier&&r(i,a,p.typeName,c)}function l(i,a,c){for(let p of c)if(p.type==="ObjectPattern"&&p.typeAnnotation){let u=new Map;if(s(i,a,u,p.typeAnnotation.typeAnnotation,!1),u.size===0)continue;o(p,u)}else p.type===U.AssignmentPattern&&p.left.type===U.ObjectPattern&&l(i,a,[p.left])}function o(i,a){let c=[];if(i.properties.at(-1)?.type===U.RestElement)return;for(let S of i.properties)S.type===U.Property&&S.key.type===U.Identifier&&c.push(S.key.name);let u=[],g=[];for(let[S,E]of a)c.includes(S)||(g.push(S),u.push({node:E,messageId:"unusedObjectTypeProperty",data:{propertyName:S}}));for(let[S,E]of u.entries())e.report({...E,fix:S===u.length-1?T=>{let w=i.properties.at(-1),h=g.join(", ");return w?w?.type===U.RestElement?null:T.insertTextAfter(w,`, ${h}`):T.insertTextBeforeRange([i.range[0]+1,i.range[1]],`${h}`)}:void 0})}return{VariableDeclaration(i){let a=i.declarations[0];if(!a)return;let c=new Map,p=a.id.type===U.Identifier&&a.id.typeAnnotation?.typeAnnotation.type===U.TSTypeReference&&a.id.typeAnnotation.typeAnnotation.typeName.type===U.Identifier&&a.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&a.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(p){if(p.type===U.TSTypeReference&&p.typeName.type===U.Identifier)r(!0,i,p.typeName,c,!1);else if(p.type===U.TSTypeLiteral)Gt(c,...Jt(p));else if(p.type===U.TSIntersectionType)for(let u of p.types)u.type===U.TSTypeReference&&u.typeName.type===U.Identifier?r(!0,i,u.typeName,c,!1):s(!0,i,c,u,!0);if(c.size!==0&&a.init?.type===U.ArrowFunctionExpression){let u=a.init.params[0];if(!u){e.report({node:a.init,messageId:"missingComponentParam"});return}u.type===U.ObjectPattern&&o(u,c)}}},FunctionDeclaration:function(i){l(!1,i,i.params)},ArrowFunctionExpression(i){l(!1,i,i.params)}}}}),ct={name:Zt,rule:Qr};import{AST_NODE_TYPES as pt,ESLintUtils as ei}from"@typescript-eslint/utils";var ti=ei.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),en="prefer-named-functions",Qt=new Map,ni=ti({name:en,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let r=Qt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),Qt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===pt.ArrowFunctionExpression&&r.id.type===pt.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==pt.BlockStatement)return;let l=r.parent,o=r.init.params,i=r.init.body,a=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(l,`${a.async?"async ":""}function ${s}(${o.map(p=>e.sourceCode.getText(p)).join(", ")||""}) ${e.sourceCode.getText(i)}`)}]})}}}}}),ut={name:en,rule:ni};import{AST_NODE_TYPES as j}from"@typescript-eslint/utils";var ri=D({disallowedFunctions:W(D({name:F(),allowUsingWithArgs:P(oe()),hookAlternative:P(F()),message:P(F()),allowUseInside:P(W(F()))}))});function Oe(e){return/^use[A-Z]/.test(e)}function tn(e){return/^[A-Z]/.test(e)}function ii(e){return e.type===j.Identifier?Oe(e.name):e.type===j.MemberExpression&&e.property.type===j.Identifier?Oe(e.property.name):!1}function nn(e,t){return e.type===j.Identifier?e.name===t:e.type===j.MemberExpression&&e.object.type===j.Identifier&&e.property.type===j.Identifier?e.object.name==="React"&&e.property.name===t:!1}function rn(e){return!!(e.parent&&e.parent.type===j.CallExpression&&nn(e.parent.callee,"forwardRef"))}function sn(e){return!!(e.parent&&e.parent.type===j.CallExpression&&nn(e.parent.callee,"memo"))}function ft(e){if(e.type===j.FunctionDeclaration||e.type===j.FunctionExpression&&e.id)return e.id||void 0;if(e.type===j.FunctionExpression||e.type===j.ArrowFunctionExpression){if(e.parent.type===j.VariableDeclarator&&e.parent.init===e)return e.parent.id;if(e.parent.type===j.AssignmentExpression&&e.parent.right===e&&e.parent.operator==="=")return e.parent.left;if(e.parent.type===j.Property&&e.parent.value===e&&!e.parent.computed)return e.parent.key;if(e.parent.type===j.AssignmentPattern&&e.parent.right===e)return e.parent.left}}function si(e){let t=e.parent,n=!1;for(;t;){if(t.type===j.FunctionDeclaration||t.type===j.FunctionExpression||t.type===j.ArrowFunctionExpression){let r=ft(t);if(r&&r.type===j.Identifier){if(tn(r.name)||Oe(r.name))return!n;n=!0}else{if(rn(t)||sn(t))return!n;if(t.parent.type===j.CallExpression){let s=t.parent;ii(s.callee)||(n=!0)}else t.parent.type===j.JSXExpressionContainer||(n=!0)}}t=t.parent}return!1}function on(e){return e.callee.type===j.Identifier?e.callee.name:e.callee.type===j.MemberExpression&&e.callee.property.type===j.Identifier?e.callee.property.name:null}function oi(e,t){if(!t.length)return!1;let n=e.parent;for(;n;){if(n.type===j.FunctionDeclaration||n.type===j.FunctionExpression||n.type===j.ArrowFunctionExpression){let r=ft(n);if(r&&r.type===j.Identifier&&t.includes(r.name))return!0}else if(n.type===j.CallExpression){let r=on(n);if(r&&t.includes(r))return!0}n=n.parent}return!1}function ai(e){return e.arguments.length>0&&!e.arguments.every(t=>t.type===j.Identifier&&t.name==="undefined")}function li(e,t){let n=!1,r=e.parent;for(;r;){if(r.type===j.FunctionDeclaration||r.type===j.FunctionExpression||r.type===j.ArrowFunctionExpression){let s=ft(r);if(s&&s.type===j.Identifier){if(tn(s.name)||Oe(s.name)){n=!0;break}}else if(rn(r)||sn(r)){n=!0;break}}r=r.parent}return n?t.length===0?si(e):!oi(e,t):!1}var mt=pe({name:"prefer-react-hook-alternative",meta:{type:"suggestion",docs:{description:"Prefer hook alternatives for certain functions in React components and hooks"},messages:{preferHookAlternative:"This function should not be used in react{{message}}."},schema:[ri],hasSuggestions:!0},defaultOptions:[{disallowedFunctions:[]}],create(e,[t]){let{disallowedFunctions:n}=t,r=new Map(n.map(s=>[s.name,s]));return{CallExpression(s){let l=on(s);if(!l)return;let o=r.get(l);if(!o||o.allowUsingWithArgs&&ai(s))return;let i=o.allowUseInside||[];li(s,i)&&e.report({node:s,messageId:"preferHookAlternative",data:{message:o.message?` ${o.message}`:` use ${o.hookAlternative} instead`},suggest:o.hookAlternative?[{messageId:"preferHookAlternative",data:{message:`Replace with ${o.hookAlternative}`,hookAlternative:o.hookAlternative},fix:a=>{let c=o.hookAlternative;return s.callee.type===j.Identifier?a.replaceText(s.callee,c):s.callee.type===j.MemberExpression&&s.callee.property.type===j.Identifier?a.replaceText(s.callee.property,c):null}}]:[]})}}}});import{AST_NODE_TYPES as B,AST_TOKEN_TYPES as an,ESLintUtils as ci}from"@typescript-eslint/utils";var pi=ci.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),cn="prefer-single-line-if",ui=D({maxLineLength:P(J()),maxNonSimpleConditionLength:P(J())}),fi=pi({name:cn,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:[ui]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==B.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let l=r.consequent.body[0];if(l.type===B.ReturnStatement){if(!un(l))return}else if(!(l.type===B.ContinueStatement||l.type===B.BreakStatement))return;if(r.test.type===B.LogicalExpression||r.test.type===B.ConditionalExpression)return;let o;if(t.maxNonSimpleConditionLength){let u=ln(r.test);if(!u&&r.test.type===B.UnaryExpression&&r.test.operator==="!"){let g=r.test.argument;ln(g)&&(u=!0)}if(u&&(o=n.getText(r.test),o.length>t.maxNonSimpleConditionLength))return}o||(o=n.getText(r.test));let i=n.getText(l);if(o.includes(`
|
|
15
|
-
`))return;let a=n.getTokenAfter(r);if(a&&a.type===an.Punctuator&&a.value==="}"){let u=n.getTokenAfter(a);if(u&&u.type===an.Keyword&&(u.value==="else"||u.value==="catch"))return}let c=mi(n,r),p=`if (${o}) ${i}`;t.maxLineLength&&p.length+c.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:u=>u.replaceText(r,p)})}}}});function ln(e){return e.type===B.CallExpression||e.type===B.BinaryExpression||e.type===B.MemberExpression&&pn(e)}function pn(e){return e.object.type===B.MemberExpression?pn(e.object):e.object.type!==B.Identifier}function mi(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function un(e){if(!e.argument)return!0;let t=e.argument;return t.type===B.ArrayExpression&&t.elements.length===0||t.type===B.ObjectExpression&&t.properties.length===0||t.type===B.Literal||t.type===B.Identifier||t.type===B.TemplateLiteral||t.type===B.TaggedTemplateExpression?!0:t.type===B.CallExpression?t.arguments.length===0:t.type===B.UnaryExpression?un(t):!1}var dt={name:cn,rule:fi};import{AST_NODE_TYPES as te,ESLintUtils as di}from"@typescript-eslint/utils";var yi=di.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),fn="react-compiler-migration",gi=D({disallowHooks:P(W(D({name:F(),replacement:F()}))),disallowMethods:P(W(D({name:F(),replacement:P(F()),requireTrueProp:P(F())})))}),Si=/eslint +react-compiler\/react-compiler: +\["error/;function Ti(e){return e.type===te.Identifier?e.name.startsWith("use"):e.type===te.MemberExpression&&e.property.type===te.Identifier?e.property.name.startsWith("use"):!1}var hi=yi({name:fn,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:[gi]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(Si.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let s=null,l=null;if(r.callee.type===te.Identifier?(s=r.callee.name,l=r.callee):r.callee.type===te.MemberExpression&&r.callee.property.type===te.Identifier&&(s=r.callee.property.name,l=r.callee.property),s){let o=t.disallowHooks.find(i=>i.name===s);o&&l&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:o.name,replacement:o.replacement},suggest:[{messageId:"replace",data:{replacement:o.replacement},fix:i=>i.replaceText(l,o.replacement)}]})}}if(t.disallowMethods?.length&&Ti(r.callee)){for(let s of r.arguments)if(s.type===te.ObjectExpression){for(let l of s.properties)if(l.type===te.Property&&l.key.type===te.Identifier){let o=l.key.name,i=t.disallowMethods.find(a=>a.name===o);if(i){if(i.requireTrueProp){let a=i.requireTrueProp,c=!1;for(let p of s.properties)if(p.type===te.Property&&p.key.type===te.Identifier&&p.key.name===a&&p.value.type===te.Literal&&p.value.value===!0){c=!0;break}if(!c){e.report({node:l,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:i.name,requireTrueProp:a}});continue}}i.replacement&&e.report({node:l,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:i.name,replacement:i.replacement},suggest:[{messageId:"replace",data:{replacement:i.replacement},fix:a=>a.replaceText(l.key,i.replacement)}]})}}}}}}:{}}}),yt={name:fn,rule:hi};import{ESLintUtils as Ei,TSESTree as bi}from"@typescript-eslint/utils";var xi=Ei.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),mn="require-description",Ii=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Ci=/^eslint-disable-(next-)?line$/u,wi=xi({name:mn,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let l=Ri(s);l!=null&&(r.has(l.kind)||l.description||e.report({loc:ki(s.loc),messageId:"missingDescription"}))}}}}}),dn={name:mn,rule:wi};function Ri(e){let{text:t,description:n}=vi(e.value);if(!t)return null;let r=Ii.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let l=Ci.test(s);if(e.type===bi.AST_TOKEN_TYPES.Line&&!l||l&&e.loc.start.line!==e.loc.end.line)return null;let o=t.slice(r.index+s.length);return{kind:s,value:o.trim(),description:n}}function vi(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function ki(e){return{start:{line:e.start.line,column:-1},end:e.end}}function Sn(e){return/^use[A-Z0-9]/.test(e)}function Pe(e){return e.type==="Identifier"?Sn(e.name):e.type==="MemberExpression"&&!e.computed&&Pe(e.property)?e.object.type==="Identifier":!1}function Tn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function hn(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function En(e){return!!(e.parent&&e.parent.callee&&hn(e.parent.callee,"forwardRef"))}function bn(e){return!!(e.parent&&e.parent.callee&&hn(e.parent.callee,"memo"))}function gt(e){for(;e;){let t=In(e);if(t&&(Tn(t)||Pe(t))||En(e)||bn(e))return!0;e=e.parent}return!1}function yn(e){return!1}function St(e){return!1}var Ai=/eslint +react-compiler\/react-compiler: +\["error/,xn={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(Ai.test(a.value))return{CallExpression(c){let p=null;c.callee.name==="useMemo"?p="useMemo":c.callee.name==="useCallback"&&(p="useCallback"),p&&e.report({node:c,message:`"${p}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?a=>t(a):a=>e.sourceCode.getText(a),n=typeof e.getScope=="function"?()=>n():a=>e.sourceCode.getScope(a),r=null,s=[],l=[],o=new WeakSet;function i(a){for(let c of a.references){let p=c.identifier.parent;if(p.type==="VariableDeclarator"&&p.init&&p.init.type==="CallExpression"&&p.init.callee&&yn(p.init.callee))for(let u of c.resolved.references)u!==c&&o.add(u.identifier)}}return{onCodePathSegmentStart:a=>l.push(a),onCodePathSegmentEnd:()=>l.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(a,c){let p=s.pop();if(p.size===0)return;let u=new Set;function g(m,R){let{cache:v}=g,A=v.get(m.id),O=new Set(R);if(O.has(m.id)){let x=[...O],M=x.slice(x.indexOf(m.id)+1);for(let V of M)u.add(V);return BigInt("0")}if(O.add(m.id),A!==void 0)return A;if(a.thrownSegments.includes(m))A=BigInt("0");else if(m.prevSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let x of m.prevSegments)A+=g(x,O)}return m.reachable&&A===BigInt("0")?v.delete(m.id):v.set(m.id,A),A}function S(m,R){let{cache:v}=S,A=v.get(m.id),O=new Set(R);if(O.has(m.id)){let x=Array.from(O),M=x.slice(x.indexOf(m.id)+1);for(let V of M)u.add(V);return BigInt("0")}if(O.add(m.id),A!==void 0)return A;if(a.thrownSegments.includes(m))A=BigInt("0");else if(m.nextSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let x of m.nextSegments)A+=S(x,O)}return v.set(m.id,A),A}function E(m){let{cache:R}=E,v=R.get(m.id);if(v===null)return 1/0;if(v!==void 0)return v;if(R.set(m.id,null),m.prevSegments.length===0)v=1;else{v=1/0;for(let A of m.prevSegments){let O=E(A);O<v&&(v=O)}v+=1}return R.set(m.id,v),v}g.cache=new Map,S.cache=new Map,E.cache=new Map;let T=S(a.initialSegment),w=In(c),h=gt(c),_=w?Tn(w)||Pe(w):En(c)||bn(c),d=1/0;for(let m of a.finalSegments){if(!m.reachable)continue;let R=E(m);R<d&&(d=R)}for(let[m,R]of p){if(!m.reachable)continue;let v=m.nextSegments.length===0?d<=E(m):d<E(m),A=g(m)*S(m),O=u.has(m.id);for(let x of R)if(O&&!St(x)&&e.report({node:x,message:`React Hook "${t(x)}" 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.`}),_){if(c.async&&e.report({node:x,message:`React Hook "${t(x)}" cannot be called in an async function.`}),!O&&A!==T&&!St(x)){let V=`React Hook "${t(x)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(v?" Did you accidentally call a React Hook after an early return?":"");e.report({node:x,message:V})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let M=`React Hook "${t(x)}" 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:x,message:M})}else if(w){let M=`React Hook "${t(x)}" is called in function "${t(w)}" 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:x,message:M})}else if(c.type==="Program"){let M=`React Hook "${t(x)}" 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:x,message:M})}else if(h&&!St(x)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let V=c.parent;if(V.parent.type==="VariableDeclarator"&&Sn(V.parent.id.name))return}let M=`React Hook "${t(x)}" 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:x,message:M})}}},CallExpression(a){if(Pe(a.callee)){let c=gn(s),p=gn(l),u=c.get(p);u||(u=[],c.set(p,u)),u.push(a.callee)}a.callee.type==="Identifier"&&(a.callee.name==="useEffect"||yn(a.callee))&&a.arguments.length>0&&(r=a)},Identifier(a){r==null&&o.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===r&&(r=null)},FunctionDeclaration(a){gt(a)&&i(n(a))},ArrowFunctionExpression(a){gt(a)&&i(n(a))}}}};function In(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 gn(e){return e[e.length-1]}var Cn={[ct.name]:ct.rule,[Xe.name]:Xe.rule,[qe.name]:qe.rule,"rules-of-hooks":xn,"exhaustive-deps":kt,"require-description":dn.rule,[Ke.name]:Ke.rule,[Ge.name]:Ge.rule,[ut.name]:ut.rule,[$e.name]:$e.rule,[Be.name]:Be.rule,[nt.name]:nt.rule,[dt.name]:dt.rule,[et.name]:et.rule,[Je.name]:Je.rule,[Ve.name]:Ve.rule,[yt.name]:yt.rule,[Me.name]:Me.rule,[ze.name]:ze.rule,[it.name]:it.rule,[ot.name]:ot.rule,[at.name]:at.rule,[st.name]:st.rule,[mt.name]:mt.rule};var Do={rules:Cn};export{Do as extendedLintPlugin};
|
|
14
|
+
Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let R=a.acquire(h),A=new Set,O=null;{let f=R.upper;for(;f&&(A.add(f),f.type!=="function");)f=f.upper;if(!f)return;O=f}let x=Array.isArray;function M(f){if(!x(f.defs))return!1;let y=f.defs[0];if(y==null||y.node.type!=="VariableDeclarator")return!1;let b=y.node.init;if(b==null)return!1;for(;b.type==="TSAsExpression";)b=b.expression;let I=y.node.parent;if(I==null&&(Ye(O.block,y.node.id),I=y.node.parent,I==null))return!1;if(I.kind==="const"&&b.type==="Literal"&&(typeof b.value=="string"||typeof b.value=="number"||b.value===null))return!0;if(b.type!=="CallExpression")return!1;let k=b.callee;if(k.type==="MemberExpression"&&k.object.name==="React"&&k.property!=null&&!k.computed&&(k=k.property),k.type!=="Identifier")return!1;let C=y.node.id,{name:N}=k;if(N==="useRef"&&C.type==="Identifier")return!0;if(Zn(k)&&C.type==="Identifier"){for(let L of f.references)L!==C&&S.add(L.identifier);return!0}else if(N==="useState"||N==="useReducer"){if(C.type==="ArrayPattern"&&C.elements.length===2&&x(f.identifiers)){if(C.elements[1]===f.identifiers[0]){if(N==="useState"){let L=f.references,Z=0;for(let se=0;se<L.length;se++){if(L[se].isWrite()&&Z++,Z>1)return!1;c.set(L[se].identifier,C.elements[0])}}return!0}else if(C.elements[0]===f.identifiers[0]){if(N==="useState"){let L=f.references;for(let Z=0;Z<L.length;Z++)p.add(L[Z].identifier)}return!1}}}else if(N==="useTransition"&&C.type==="ArrayPattern"&&C.elements.length===2&&Array.isArray(f.identifiers)&&C.elements[1]===f.identifiers[0])return!0;return!1}function z(f){if(!x(f.defs))return!1;let y=f.defs[0];if(y==null||y.node==null||y.node.id==null)return!1;let b=y.node,I=O.childScopes,k=null,C;for(C=0;C<I.length;C++){let N=I[C],L=N.block;if(b.type==="FunctionDeclaration"&&L===b||b.type==="VariableDeclarator"&&L.parent===b){k=N;break}}if(k==null)return!1;for(C=0;C<k.through.length;C++){let N=k.through[C];if(N.resolved!=null&&A.has(N.resolved.scope)&&!ie(N.resolved))return!1}return!0}let ie=E(M,u),Fe=E(z,g),Te=new Map;function le(f){let y=f.from,b=!1;for(;y.block!==h;)y.type==="function"&&(b=y.block.parent!=null&&y.block.parent.type==="ReturnStatement"),y=y.upper;return b}let q=new Map,ne=new Map;he(R);function he(f){for(let y of f.references){if(!y.resolved||!A.has(y.resolved.scope))continue;let b=Ye(h,y.identifier),I=At(b),k=ae(I,ne);if(v&&I.type==="Identifier"&&(I.parent.type==="MemberExpression"||I.parent.type==="OptionalMemberExpression")&&!I.parent.computed&&I.parent.property.type==="Identifier"&&I.parent.property.name==="current"&&le(y)&&Te.set(k,{reference:y,dependencyNode:I}),I.parent.type==="TSTypeQuery"||I.parent.type==="TSTypeReference")continue;let C=y.resolved.defs[0];if(C!=null&&!(C.node!=null&&C.node.init===h.parent)&&C.type!=="TypeParameter")if(q.has(k))q.get(k).references.push(y);else{let N=y.resolved,L=ie(N)||Fe(N);q.set(k,{isStable:L,references:[y]})}}for(let y of f.childScopes)he(y)}Te.forEach(({reference:f,dependencyNode:y},b)=>{let I=f.resolved.references,k=!1;for(let C=0;C<I.length;C++){let{identifier:N}=I[C],{parent:L}=N;if(L!=null&&L.type==="MemberExpression"&&!L.computed&&L.property.type==="Identifier"&&L.property.name==="current"&&L.parent.type==="AssignmentExpression"&&L.parent.left===L){k=!0;break}}k||i({node:y.parent.property,message:`The ref value '${b}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${b}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Ne=new Set;function wn(f,y){Ne.has(y)||(Ne.add(y),i({node:f,message:`Assignments to the '${y}' variable from inside React Hook ${n(d)} 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(d)}.`}))}let Ee=new Set;if(q.forEach(({isStable:f,references:y},b)=>{f&&Ee.add(b),y.forEach(I=>{I.writeExpr&&wn(I.writeExpr,b)})}),Ne.size>0)return;if(!_){let f=null;if(q.forEach(({isStable:y,references:b},I)=>{f||b.forEach(k=>{if(f)return;let C=k.identifier;if(!c.has(C))return;let L=k.from;for(;L.type!=="function";)L=L.upper;L.block===h&&(f=I)})}),f){let{suggestedDependencies:y}=We({dependencies:q,declaredDependencies:[],stableDependencies:Ee,externalDependencies:new Set,isEffect:!0});i({node:d,message:`React Hook ${m} contains a call to '${f}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+y.join(", ")+`] as a second argument to the ${m} Hook.`,suggest:[{desc:`Add dependencies array: [${y.join(", ")}]`,fix(b){return b.insertTextAfter(h,`, [${y.join(", ")}]`)}}]})}return}let ye=[],ge=new Set;_.type!=="ArrayExpression"?i({node:_,message:`React Hook ${n(d)} 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.`}):_.elements.forEach(f=>{if(f===null)return;if(f.type==="SpreadElement"){i({node:f,message:`React Hook ${n(d)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}S.has(f)&&i({node:f,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(f)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(f)}\``,fix(k){return k.removeRange(f.range)}}]});let y;try{y=ae(f,ne)}catch(k){if(/Unsupported node type/.test(k.message)){f.type==="Literal"?q.has(f.value)?i({node:f,message:`The ${f.raw} literal is not a valid dependency because it never changes. Did you mean to include ${f.value} in the array instead?`}):i({node:f,message:`The ${f.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):i({node:f,message:`React Hook ${n(d)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw k}let b=f;for(;b.type==="MemberExpression"||b.type==="OptionalMemberExpression"||b.type==="ChainExpression";)b=b.object||b.expression.object;let I=!O.through.some(k=>k.identifier===b);ye.push({key:y,node:f}),I||ge.add(y)});let{suggestedDependencies:Rn,unnecessaryDependencies:be,missingDependencies:ce,duplicateDependencies:Tt}=We({dependencies:q,declaredDependencies:ye,stableDependencies:Ee,externalDependencies:ge,isEffect:v}),xe=Rn;if(Tt.size+ce.size+be.size===0){if(t)return;Xn({declaredDependencies:ye,declaredDependenciesNode:_,componentScope:O,scope:R}).forEach(({construction:y,isUsedOutsideOfHook:b,depType:I})=>{let k=I==="function"?"useCallback":"useMemo",C=I==="function"?"definition":"initialization",N=`wrap the ${C} of '${y.name.name}' in its own ${k}() Hook.`,L=b?`To fix this, ${N}`:`Move it inside the ${m} callback. Alternatively, ${N}`,Z=I==="conditional"||I==="logical expression"?"could make":"makes",se=`The '${y.name.name}' ${I} ${Z} the dependencies of ${m} Hook (at line ${_.loc.start.line}) change on every render. ${L}`,ht;b&&y.type==="Variable"&&I==="function"&&(ht=[{desc:`Wrap the ${C} of '${y.name.name}' in its own ${k}() Hook.`,fix(Et){let[kn,An]=k==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[Et.insertTextBefore(y.node.init,kn),Et.insertTextAfter(y.node.init,An)]}}]),i({node:y.node,message:se,suggest:ht})});return}!v&&ce.size>0&&(xe=We({dependencies:q,declaredDependencies:[],stableDependencies:Ee,externalDependencies:ge,isEffect:v}).suggestedDependencies);function vn(){if(ye.length===0)return!0;let f=ye.map(b=>b.key),y=f.slice().sort();return f.join(",")===y.join(",")}vn()&&xe.sort();function De(f){let y=f.split("."),b="";for(let I=0;I<y.length;I++){if(I!==0){let k=y.slice(0,I+1).join("."),C=ne.get(k)===!0;b+=C?"?.":"."}b+=y[I]}return b}function je(f,y,b,I){return f.size===0?null:(f.size>1?"":y+" ")+b+" "+(f.size>1?"dependencies":"dependency")+": "+Jn(Array.from(f).sort().map(k=>"'"+De(k)+"'"))+`. Either ${I} ${f.size>1?"them":"it"} or remove the dependency array.`}let re="";if(be.size>0){let f=null;if(Array.from(be.keys()).forEach(y=>{f===null&&y.endsWith(".current")&&(f=y)}),f!==null)re=` Mutable values like '${f}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(ge.size>0){let y=Array.from(ge)[0];R.set.has(y)||(re=` Outer scope values like '${y}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!re&&ce.has("props")){let f=q.get("props");if(f==null)return;let y=f.references;if(!Array.isArray(y))return;let b=!0;for(let I=0;I<y.length;I++){let k=y[I],C=Ye(O.block,k.identifier);if(!C){b=!1;break}let N=C.parent;if(N==null){b=!1;break}if(N.type!=="MemberExpression"&&N.type!=="OptionalMemberExpression"){b=!1;break}}b&&(re=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${m} call and refer to those specific props inside ${n(d)}.`)}if(!re&&ce.size>0){let f=null;ce.forEach(y=>{if(f)return;let b=O.set.get(y),I=q.get(y);if(I.references[0].resolved!==b)return;let k=b.defs[0];if(k==null||k.name==null||k.type!=="Parameter")return;let C=!1,N;for(let L=0;L<I.references.length;L++)if(N=I.references[L].identifier,N!=null&&N.parent!=null&&(N.parent.type==="CallExpression"||N.parent.type==="OptionalCallExpression")&&N.parent.callee===N){C=!0;break}C&&(f=y)}),f!==null&&(re=` If '${f}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!re&&ce.size>0){let f=null;if(ce.forEach(y=>{if(f!==null)return;let I=q.get(y).references,k,C;for(let N=0;N<I.length;N++){for(k=I[N].identifier,C=k.parent;C!=null&&C!==O.block;){if(C.type==="CallExpression"){let L=c.get(C.callee);if(L!=null){if(L.name===y)f={missingDep:y,setter:C.callee.name,form:"updater"};else if(p.has(k))f={missingDep:y,setter:C.callee.name,form:"reducer"};else{let Z=I[N].resolved;if(Z!=null){let se=Z.defs[0];se!=null&&se.type==="Parameter"&&(f={missingDep:y,setter:C.callee.name,form:"inlineReducer"})}}break}}C=C.parent}if(f!==null)break}}),f!==null)switch(f.form){case"reducer":re=` You can also replace multiple useState variables with useReducer if '${f.setter}' needs the current value of '${f.missingDep}'.`;break;case"inlineReducer":re=` If '${f.setter}' needs the current value of '${f.missingDep}', you can also switch to useReducer instead of useState and read '${f.missingDep}' in the reducer.`;break;case"updater":re=` You can also do a functional update '${f.setter}(${f.missingDep.slice(0,1)} => ...)' if you only need '${f.missingDep}' in the '${f.setter}' call.`;break;default:throw new Error("Unknown case.")}}i({node:_,message:`React Hook ${n(d)} has `+(je(ce,"a","missing","include")||je(be,"an","unnecessary","exclude")||je(Tt,"a","duplicate","omit"))+re,suggest:[{desc:`Update the dependencies array to be: [${xe.map(De).join(", ")}]`,fix(f){return f.replaceText(_,`[${xe.map(De).join(", ")}]`)}}]})}function w(h){let _=Kn(h.callee,o);if(_===-1)return;let d=h.arguments[_],m=h.callee,v=Ot(m).name,R=h.arguments[_+1],A=/Effect($|[^a-z])/g.test(v);if(!d){i({node:m,message:`React Hook ${v} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!(t&&!A)){if(!R&&!A){(v==="useMemo"||v==="useCallback")&&i({node:m,message:`React Hook ${v} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(d.type){case"FunctionExpression":case"ArrowFunctionExpression":T(d,R,m,v,A);return;case"Identifier":if(!R||R.elements&&R.elements.some(M=>M&&M.type==="Identifier"&&M.name===d.name))return;let O=r(h).set.get(d.name);if(O==null||O.defs==null)return;let x=O.defs[0];if(!x||!x.node||x.type!=="Variable"&&x.type!=="FunctionName")break;switch(x.node.type){case"FunctionDeclaration":T(x.node,R,m,v,A);return;case"VariableDeclarator":let M=x.node.init;if(!M)break;switch(M.type){case"ArrowFunctionExpression":case"FunctionExpression":T(M,R,m,v,A);return}break}break;default:i({node:m,message:`React Hook ${v} received a function whose dependencies are unknown. Pass an inline function instead.`});return}i({node:m,message:`React Hook ${v} has a missing dependency: '${d.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${d.name}]`,fix(O){return O.replaceText(R,`[${d.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let h of e.sourceCode.getAllComments())if(qn.test(h.value))return t=!0,{CallExpression:_=>w(_,!0)}}return{CallExpression:h=>w(h)}}};function We({dependencies:e,declaredDependencies:t,stableDependencies:n,externalDependencies:r,isEffect:s}){let l=o();function o(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach((T,w)=>{let h=i(l,w);h.isUsed=!0,a(l,w,_=>{_.isSubtreeUsed=!0})}),t.forEach(({key:T})=>{let w=i(l,T);w.isSatisfiedRecursively=!0}),n.forEach(T=>{let w=i(l,T);w.isSatisfiedRecursively=!0});function i(T,w){let h=w.split("."),_=T;for(let d of h){let m=_.children.get(d);m||(m=o(),_.children.set(d,m)),_=m}return _}function a(T,w,h){let _=w.split("."),d=T;for(let m of _){let v=d.children.get(m);if(!v)return;h(v),d=v}}let c=new Set,p=new Set;u(l,c,p,T=>T);function u(T,w,h,_){T.children.forEach((d,m)=>{let v=_(m);if(d.isSatisfiedRecursively){d.isSubtreeUsed&&h.add(v);return}if(d.isUsed){w.add(v);return}u(d,w,h,R=>v+"."+R)})}let g=[],S=new Set,E=new Set;return t.forEach(({key:T})=>{p.has(T)?g.indexOf(T)===-1?g.push(T):E.add(T):S.add(T)}),c.forEach(T=>{g.push(T)}),{suggestedDependencies:g,unnecessaryDependencies:S,duplicateDependencies:E,missingDependencies:c}}function ue(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 ue(e.consequent)!=null||ue(e.alternate)!=null?"conditional":null;case"LogicalExpression":return ue(e.left)!=null||ue(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return ue(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return ue(e.expression);case"TSAsExpression":return ue(e.expression)}return null}function Xn({declaredDependencies:e,declaredDependenciesNode:t,componentScope:n,scope:r}){let s=e.map(({key:o})=>{let i=n.variables.find(c=>c.name===o);if(i==null)return null;let a=i.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 c=ue(a.node.init);if(c!=null)return[i,c]}return a.type==="FunctionName"&&a.node.type==="FunctionDeclaration"?[i,"function"]:a.type==="ClassName"&&a.node.type==="ClassDeclaration"?[i,"class"]:null}).filter(Boolean);function l(o){let i=!1;for(let a=0;a<o.references.length;a++){let c=o.references[a];if(c.writeExpr){if(i)return!0;i=!0;continue}let p=c.from;for(;p!==r&&p!=null;)p=p.upper;if(p!==r&&!Pt(t,c.identifier))return!0}return!1}return s.map(([o,i])=>({construction:o.defs[0],depType:i,isUsedOutsideOfHook:l(o)}))}function At(e){return(e.parent.type==="MemberExpression"||e.parent.type==="OptionalMemberExpression")&&e.parent.object===e&&e.parent.property.name!=="current"&&!e.parent.computed&&!(e.parent.parent!=null&&(e.parent.parent.type==="CallExpression"||e.parent.parent.type==="OptionalCallExpression")&&e.parent.parent.callee===e.parent)?At(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function He(e,t,n){t&&(e.optional?t.has(n)||t.set(n,!0):t.has(n)||t.set(n,!1))}function ae(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=ae(e.object,t),r=ae(e.property,null),s=`${n}.${r}`;return He(e,t,s),s}else if(e.type==="OptionalMemberExpression"&&!e.computed){let n=ae(e.object,t),r=ae(e.property,null),s=`${n}.${r}`;return He(e,t,s),s}else if(e.type==="ChainExpression"&&!e.computed){let n=e.expression;if(n.type==="CallExpression")throw new Error(`Unsupported node type: ${n.type}`);let r=ae(n.object,t),s=ae(n.property,null),l=`${r}.${s}`;return He(n,t,l),l}else throw new Error(`Unsupported node type: ${e.type}`)}function Ot(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=Ot(e);if(n.type!=="Identifier")return-1;switch(n.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(n===e&&t&&t.additionalHooks){let r;try{r=ae(n,null)}catch(s){if(/Unsupported node type/.test(s.message))return 0;throw s}return t.additionalHooks.test(r)?0:-1}else return-1}}function Ye(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Gn(r,t))return r;if(Pt(r,t))for(let[s,l]of Object.entries(r))s!=="parent"&&(vt(l)?(l.parent=r,n.push(l)):Array.isArray(l)&&l.forEach(o=>{vt(o)&&(o.parent=r,n.push(o))}))}return null}function Jn(e){let t="";for(let n=0;n<e.length;n++)t+=e[n],n===0&&e.length===2?t+=" and ":n===e.length-2&&e.length>2?t+=", and ":n<e.length-1&&(t+=", ");return t}function vt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Gn(e,t){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===t.type&&e.name===t.name&&e.range[0]===t.range[0]&&e.range[1]===t.range[1]}function Pt(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Zn(e){return!1}import{AST_NODE_TYPES as Re,ESLintUtils as Nt}from"@typescript-eslint/utils";import K from"typescript";var Qn=Nt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ft="improved-no-unnecessary-condition",er=D({}),tr=["string","number","bigint","boolean","symbol","undefined","object","function","never"],nr=new Set(tr),ze={name:Ft,rule:Qn({name:Ft,meta:{type:"suggestion",docs:{description:"Extends checks of `no-unnecessary-condition` rule"},messages:{unnecessaryTypeofCondition:'This condition is unnecessary. The type of "{{name}}" is always "{{type}}".',alwaysFalseTypeofCondition:'This condition will always be false. The type of "{{name}}" is "{{actualType}}" so the condition has no overlap with "{{conditionType}}".'},schema:[er]},defaultOptions:[{}],create(e){let t=Nt.getParserServices(e,!0),n=t.program?.getTypeChecker();if(!n||!t.program)throw new Error("TypeScript services or program not available");function r(i){return i.type===Re.UnaryExpression&&i.operator==="typeof"}function s(i){return i.flags&K.TypeFlags.Any||i.flags&K.TypeFlags.Unknown?null:i.flags&K.TypeFlags.StringLike?["string"]:i.flags&K.TypeFlags.NumberLike?["number"]:i.flags&K.TypeFlags.BigIntLike?["bigint"]:i.flags&K.TypeFlags.BooleanLike?["boolean"]:i.flags&K.TypeFlags.ESSymbolLike?["symbol"]:i.flags&K.TypeFlags.Undefined||i.flags&K.TypeFlags.Void?["undefined"]:i.flags&K.TypeFlags.Null?["object"]:i.getCallSignatures().length>0?["function"]:i.flags&K.TypeFlags.Object?i.getProperties().length===0?["string","number","bigint","boolean","symbol","object","function"]:["object"]:i.flags&K.TypeFlags.NonPrimitive?["object"]:i.flags&K.TypeFlags.Never?["never"]:null}function l(i){if(!n)return null;let a=t.esTreeNodeToTSNodeMap.get(i),c=n.getTypeAtLocation(a.expression);if(c.flags&K.TypeFlags.Any||c.flags&K.TypeFlags.Unknown)return null;let p=[];if(c.isUnion()){for(let g of c.types){let S=s(g);if(S)p.push(...S);else return null}return p}let u=s(c);return u?(p.push(...u),p):null}function o(i){if(!(i.operator==="==="||i.operator==="!=="))return;let c=null,p=null;if(r(i.left)?(c=i.left,p=i.right.type===Re.Literal&&typeof i.right.value=="string"?i.right.value:null):r(i.right)&&(c=i.right,p=i.left.type===Re.Literal&&typeof i.left.value=="string"?i.left.value:null),!c||!p||!rr(p,nr))return;let u=l(c);if(!u)return;let g=i.operator==="!==",S=u.includes(p);u.length===1?S&&!g?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:p}}):!S&&g?e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:Array.from(u)[0]}}):!S&&!g?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(u),conditionType:p}}):S&&g&&e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(u),conditionType:p}}):!S&&!g?e.report({node:i,messageId:"alwaysFalseTypeofCondition",data:{name:fe(c,e),actualType:we(u),conditionType:p}}):!S&&g&&e.report({node:i,messageId:"unnecessaryTypeofCondition",data:{name:fe(c,e),type:we(u)}})}return{BinaryExpression:o}}})};function we(e){return Array.from(new Set(e)).join(" | ")||"never"}function fe(e,t){let n=e.argument;return n.type===Re.Identifier?n.name:t.sourceCode.getText(n)}function rr(e,t){return t.has(e)}import{AST_NODE_TYPES as ir,ESLintUtils as sr}from"@typescript-eslint/utils";var or=sr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Dt="no-call-with-explicit-generics",ar=D({functions:V(F())}),lr=or({name:Dt,meta:{type:"problem",docs:{description:"Enforce calling configured functions with inferred generics only"},messages:{noExplicitGenerics:"Function '{{ functionName }}' should be called with inferred generics (remove the explicit type parameters)"},schema:[ar]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Set(t.functions);return{CallExpression(r){let{callee:s}=r;s.type===ir.Identifier&&n.has(s.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:s.name}})}}}}),Be={name:Dt,rule:lr};import{AST_NODE_TYPES as ve,ESLintUtils as cr}from"@typescript-eslint/utils";var pr=cr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),jt="no-call-with-inferred-generics",ur=pr({name:jt,meta:{type:"problem",docs:{description:"Disable calling configured functions with infered generics"},messages:{missingGenericDeclaration:"Function '{{ functionName }}' should be called with at least {{ minGenerics }} generic(s) (ex: `fn<Generic>()`) defined",anyUsedInGenerics:"Function '{{ functionName }}' should not be called with 'any' in generics"},schema:[{type:"object",properties:{functions:{type:"array",items:{type:"object",properties:{name:{type:"string"},minGenerics:{type:"number"},allowAny:{type:"boolean"},disallowTypes:{type:"array",items:{type:"string"}}},required:["name"]}},anyAliases:{type:"array",items:{type:"string"}}},required:["functions"]}]},defaultOptions:[{functions:[]}],create(e,[t]){let n=new Map(t.functions.map(r=>[r.name,r]));return{CallExpression(r){let{callee:s}=r;if(s.type!==ve.Identifier)return;let l=n.get(s.name);if(!l)return;let{minGenerics:o=1,allowAny:i,disallowTypes:a=t.disallowTypes}=l;(r.typeArguments?.params.length||0)<(o||0)&&e.report({node:r,messageId:"missingGenericDeclaration",data:{functionName:s.name,minGenerics:o||0}}),!(i&&!a)&&r.typeArguments?.params?.some(p=>!i&&p.type===ve.TSAnyKeyword||a&&p.type===ve.TSTypeReference&&p.typeName.type===ve.Identifier&&a.includes(p.typeName.name))&&e.report({node:r,messageId:"anyUsedInGenerics",data:{functionName:s.name}})}}}}),qe={name:jt,rule:ur};import{ESLintUtils as fr,TSESTree as Lt}from"@typescript-eslint/utils";var mr=fr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),_t="no-commented-out-code",dr=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],yr=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],gr=mr({name:_t,meta:{type:"problem",docs:{description:"Disallow commented code"},messages:{commentedOutCode:"Commented code is not allowed. Detected pattern: `{{ wrongPattern }}` Use a comment starting with `INFO:` if you want to keep this code commented out."},schema:[]},defaultOptions:[],create(e){function t(n){if(n.startsWith("/"))return!1;let r=n.trimStart();if(n.startsWith("*")||r.startsWith("INFO:")||r.startsWith("TODO:")||r.startsWith("DOCS:")||r.startsWith("FIX:")||r.startsWith("eslint-disable")||n.includes("@deprecated")||n.includes("@example"))return!1;for(let s of dr)if(r.startsWith(s))return{wrongPattern:s};for(let s of yr)if(typeof s=="string"){if(n.includes(s))return{wrongPattern:s}}else if(s.test(n))return{wrongPattern:`regex(${s.toString()})`};return!1}return{Program(){let r=e.sourceCode.getAllComments();for(let s of r)if(s.type===Lt.AST_TOKEN_TYPES.Line||s.type===Lt.AST_TOKEN_TYPES.Block){let l=t(s.value);l&&e.report({node:s,messageId:"commentedOutCode",data:{wrongPattern:l.wrongPattern}})}}}}}),Xe={name:_t,rule:gr};import{ESLintUtils as Sr,TSESTree as Tr}from"@typescript-eslint/utils";var hr=Sr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Mt="no-default-export",Er=hr({name:Mt,meta:{type:"problem",docs:{description:"Disallow default exports"},schema:[],messages:{noDefaultExport:"Default exports are not allowed, use named exports instead."}},defaultOptions:[],create(e){return{ExportDefaultDeclaration(t){e.report({node:t,messageId:"noDefaultExport"})},ExportNamedDeclaration(t){for(let n of t.specifiers)n.exported.type===Tr.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ke={name:Mt,rule:Er};import{ESLintUtils as br}from"@typescript-eslint/utils";var xr=br.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="no-leaked-text-in-jsx",Ir=[",",";","[","]","(",")"],Cr=xr({name:$t,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";Ir.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Je={name:$t,rule:Cr};import{AST_NODE_TYPES as me,ESLintUtils as wr}from"@typescript-eslint/utils";var Rr=wr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="no-non-camel-case-functions",vr=/^[a-z][a-zA-Z0-9]*$/;function Ut(e){return e.typeName.type===me.TSQualifiedName&&e.typeName.left.type===me.Identifier&&e.typeName.left.name==="JSX"&&e.typeName.right.type===me.Identifier&&e.typeName.right.name==="Element"}var kr=Rr({name:Vt,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!vr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===me.TSTypeReference?Ut(n):n.type===me.TSUnionType&&n.types.some(s=>s.type===me.TSTypeReference&&Ut(s))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Ge={name:Vt,rule:kr};import{ESLintUtils as Ar,TSESTree as W}from"@typescript-eslint/utils";import{AST_NODE_TYPES as Wt}from"@typescript-eslint/utils";function de(e,t,n=1/0){if(n!==0&&e.parent)return e.type===t?e:de(e.parent,t,n===1/0?n:n-1)}function*Ze(e){yield e,e.parent&&(yield*Ze(e.parent))}function Qe(e,t){for(let n of e){let r=t(n);if(r!=null&&r!==!1)return r}}function Ht(e,t,n){let s=n.getDeclaredVariables(e).find(l=>l.name===t||l.identifiers[0]?.parent.type===Wt.Property&&l.identifiers[0]?.parent.key.type===Wt.Identifier&&l.identifiers[0]?.parent.key.name===t);return s?s.references.filter(l=>!l.init):[]}var Or=Ar.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Yt="no-optional-root-props",Pr=Or({name:Yt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let l=e.sourceCode.getDeclaredVariables(r)[0];if(!l||l.references.length!==1)return!1;let o=l.references[0];if(!o)return!1;for(let i of Ze(o.identifier)){if("returnType"in i||i.type===W.AST_NODE_TYPES.ExportNamedDeclaration)return!1;let a=i.parent;if(!a)return!1;if(a.type===W.AST_NODE_TYPES.TSTypeParameterInstantiation&&a.parent.type===W.AST_NODE_TYPES.TSTypeReference&&a.parent.typeName.type===W.AST_NODE_TYPES.Identifier&&a.parent.typeName.name==="FC"){let p=de(a.parent.parent,W.AST_NODE_TYPES.VariableDeclaration,4);if(!p)return!1;let u=ke(p,e.sourceCode);return u?!(u.parent.type===W.AST_NODE_TYPES.CallExpression&&u.parent.callee.type===W.AST_NODE_TYPES.Identifier&&u.parent.callee.name==="memo"):!1}if(i.type===W.AST_NODE_TYPES.AssignmentPattern)return!1;if(a.type===W.AST_NODE_TYPES.ArrowFunctionExpression){let c=de(a,W.AST_NODE_TYPES.VariableDeclaration);return c?!!ke(c,e.sourceCode):!1}if(a.type===W.AST_NODE_TYPES.FunctionDeclaration)return!!ke(a,e.sourceCode)}return!1}function n(r){r.key.type!==W.AST_NODE_TYPES.Identifier||!r.optional||e.report({node:r.key,messageId:"optionalNotAllowed",data:{propertyName:r.key.name},suggest:[{messageId:"suggestion",fix:s=>{let l=de(r,W.AST_NODE_TYPES.TSPropertySignature);if(!l)return null;let o=e.sourceCode.getText(l);return s.replaceText(l,o.replace("?:",": undefined |"))}}]})}return{TSTypeAliasDeclaration(r){if(r.typeAnnotation.type===W.AST_NODE_TYPES.TSTypeLiteral&&!(Ae(r)||!t(r)))for(let s of r.typeAnnotation.members)s.type===W.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSInterfaceDeclaration(r){if(!(Ae(r)||!t(r)))for(let s of r.body.body)s.type===W.AST_NODE_TYPES.TSPropertySignature&&n(s)},TSTypeReference(r){if(r.typeName.type!==W.AST_NODE_TYPES.Identifier||r.typeName.name!=="FC"||!r.typeArguments?.params[0])return;let s=r.typeArguments.params[0];if(s.type!==W.AST_NODE_TYPES.TSTypeLiteral)return;let l=de(r.parent,W.AST_NODE_TYPES.VariableDeclaration,4);if(!l)return;let o=ke(l,e.sourceCode);if(!(!o||o.parent.type===W.AST_NODE_TYPES.CallExpression&&o.parent.callee.type===W.AST_NODE_TYPES.Identifier&&o.parent.callee.name==="memo"))for(let a of s.members)a.type===W.AST_NODE_TYPES.TSPropertySignature&&n(a)}}}});function Ae(e){return e?e.parent?.type===W.AST_NODE_TYPES.ExportNamedDeclaration||e.parent?.type===W.AST_NODE_TYPES.ExportDefaultDeclaration:!1}function ke(e,t){if(Ae(e))return;let n;if(e.type===W.AST_NODE_TYPES.VariableDeclaration){if(e.declarations.length!==1)return;e.declarations[0].id.type===W.AST_NODE_TYPES.Identifier&&(n=e.declarations[0].id)}else{if(!e.id)return;n=e.id}if(!n)return;let r=t.getScope(e);e.type===W.AST_NODE_TYPES.FunctionDeclaration&&r.upper&&(r=r.upper);let s=r.variables.find(o=>o.identifiers.includes(n));if(!s)return;let l=s.references.filter(o=>o.identifier!==n);if(!(l.length!==1||!l[0])&&!Ae(l[0].identifier.parent.parent))return l[0].identifier}var et={name:Yt,rule:Pr};import{ESLintUtils as Fr}from"@typescript-eslint/utils";import tt from"node:path";var Nr=Fr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),zt="no-relative-imports",Dr=D({find:F(),replacement:F()}),jr=D({aliases:V(Dr),rootDir:P(F()),allowNotFoundAliases:P(oe()),_dev_simulateFileName:P(F())}),Lr=Nr({name:zt,meta:{type:"problem",fixable:"code",docs:{description:"Prevent relative imports and auto-fix them using configured aliases"},messages:{noRelativeImports:"Relative imports are not allowed. Use one of the valid aliases in tsconfig.json instead.",noRelativeImportsWithAlias:'Relative imports are not allowed. Use the "{{ alias }}" alias instead.'},schema:[jr]},defaultOptions:[{aliases:[],rootDir:void 0}],create(e,[t]){let n=t._dev_simulateFileName??e.filename;function r(o){return o.startsWith(".")||o.startsWith("..")}function s(o,i){let a=tt.dirname(i);return tt.resolve(a,o)}function l(o){let i=t.rootDir??process.cwd(),a=tt.relative(i,o);if(a.startsWith("."))return null;a.startsWith("/")||(a=`/${a}`);for(let{find:c,replacement:p}of t.aliases)if(a.startsWith(p)){let u=a.replace(p,c);return{alias:c,newPath:u}}return null}return{ImportDeclaration(o){let i=o.source.value;if(!r(i))return;let a=s(i,n),c=l(a);!c&&t.allowNotFoundAliases||e.report({node:o,messageId:c?"noRelativeImportsWithAlias":"noRelativeImports",data:{alias:c?.alias},fix:c?p=>p.replaceText(o.source,`'${c.newPath}'`):void 0})}}}}),nt={name:zt,rule:Lr};import{AST_NODE_TYPES as Se,ESLintUtils as qt}from"@typescript-eslint/utils";import*as rt from"typescript";var _r=qt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Bt="no-unnecessary-casting",Mr=D({additionalCastFunctions:P(V(D({name:F(),expectedType:Ie(["string","number"])})))}),it={name:Bt,rule:_r({name:Bt,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[Mr],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],s=qt.getParserServices(e,!0),l=s.program?.getTypeChecker();if(!l||!s.program)throw new Error("TypeScript services or program not available");function o(p,u){switch(p.type){case Se.Literal:return u==="number"?typeof p.value=="number":typeof p.value=="string";case Se.TemplateLiteral:return u==="string";case Se.UnaryExpression:return u==="number"?p.operator==="+"||p.operator==="-"||p.operator==="~":!1;default:return!1}}function i(p,u){return u==="number"?!!(p.flags&rt.TypeFlags.NumberLike):!!(p.flags&rt.TypeFlags.StringLike)}function a(p,u){return g=>g.replaceText(p,e.sourceCode.getText(u))}function c(p){if(!l||p.arguments.length!==1)return;let u=p.arguments[0];if(!u||u.type===Se.SpreadElement)return;let{callee:g}=p;if(g.type!==Se.Identifier)return;let S=g.name,E=r.find(w=>w.name===S);if(!E)return;if(o(u,E.expectedType)||i(l.getTypeAtLocation(s.esTreeNodeToTSNodeMap.get(u)),E.expectedType)){let w,h;S==="Number"?w="unnecessaryNumberCasting":S==="String"?w="unnecessaryStringCasting":(w="unnecessaryCustomCasting",h={name:E.name,type:E.expectedType}),e.report({node:p,messageId:w,...h?{data:h}:{},fix:a(p,u)})}}return{CallExpression:c}}})};import{AST_NODE_TYPES as G}from"@typescript-eslint/utils";var st=pe({name:"no-unused-obj-props",meta:{type:"suggestion",docs:{description:"Disallow unused properties when it is safe to remove them"},messages:{unusedObjectProperty:'The object property "{{name}}" is not being used',unusedReturnObjectProperty:'The object property "{{name}}" returned by this function is not being used'},schema:[]},defaultOptions:[],create(e){return{VariableDeclarator(t){if(t.id.type===G.ObjectPattern||!t.init||t.init.type!==G.ObjectExpression||t.id.type===G.Identifier&&t.id.typeAnnotation||t.parent.parent.type===G.ExportNamedDeclaration)return;let n=new Map;for(let o of t.init.properties)o.type===G.Property&&o.key.type===G.Identifier&&n.set(o.key.name,o);if(n.size===0||t.id.type!==G.Identifier)return;let r=$r(t,e.sourceCode);if(r.length===0)return;let s=t.init.properties.some(o=>o.type!==G.Property?!1:o.value.type===G.FunctionExpression),l=new Set;for(let o of r){if(o.identifier.parent.type!==G.MemberExpression)return;let i=o.identifier.parent;if(i.object!==o.identifier)return;if(i.computed)if(i.property.type===G.Literal&&typeof i.property.value=="string")l.add(i.property.value);else return;else{if(i.property.type!==G.Identifier)return;l.add(i.property.name)}if(i.parent.type===G.CallExpression&&s)return}for(let[o,i]of n)l.has(o)||e.report({node:i,messageId:"unusedObjectProperty",data:{name:o}})}}}});function $r(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}import{AST_NODE_TYPES as Y,ESLintUtils as Ur}from"@typescript-eslint/utils";var Vr=D({selectors:V(D({name:F(),selectorProp:P(F()),selectorArgPos:P(J()),returnProp:P(F())}))}),Wr=Ur.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Xt="no-unused-selected-values",ot={name:Xt,rule:Wr({name:Xt,meta:{type:"suggestion",docs:{description:"Disallow unused values in selector objects"},messages:{unusedSelectedValue:'The selected value "{{name}}" is not being used'},schema:[Vr]},defaultOptions:[{selectors:[]}],create(e,[t]){let{selectors:n=[]}=t,r=new Map(n.map(s=>[s.name,s]));return{VariableDeclarator(s){let l=null;if(s.init?.type===Y.CallExpression&&(l=s.init),!l)return;let o=Yr(l);if(!o)return;let i=r.get(o);if(!i)return;let a=Hr(l,i.selectorArgPos??0,i.selectorProp);if(!a)return;let c=zr(a);if(!c)return;let p=Kt(c.properties,void 0);if(!p)return;if(s.id.type===Y.ObjectPattern){let S=Kt(s.id.properties,i.returnProp);if(!S)return;for(let[E,T]of p)S.has(E)||e.report({node:T,messageId:"unusedSelectedValue",data:{name:E}});return}if(s.id.type!==Y.Identifier||i.returnProp)return;let u=Br(s,e.sourceCode);if(u.length===0)return;let g=new Set;for(let S of u){if(S.identifier.parent.type!==Y.MemberExpression)return;let E=S.identifier.parent.property;if(E.type!==Y.Identifier)return;g.add(E.name)}for(let[S,E]of p)g.has(S)||e.report({node:E,messageId:"unusedSelectedValue",data:{name:S}})}}}})};function Hr(e,t,n){let r=e.arguments[t];if(!r)return null;if(r.type===Y.ArrowFunctionExpression||r.type===Y.FunctionExpression)return r;if(n&&r.type===Y.ObjectExpression){let s=r.properties.find(o=>o.type===Y.Property&&o.key.type===Y.Identifier&&o.key.name===n);if(s?.type!==Y.Property)return null;let l=s.value;if(l.type===Y.ArrowFunctionExpression||l.type===Y.FunctionExpression)return l}return null}function Yr(e){return e.callee.type===Y.Identifier?e.callee.name:e.callee.type===Y.MemberExpression&&e.callee.property.type===Y.Identifier?e.callee.property.name:null}function zr(e){if(e.body.type===Y.ObjectExpression)return e.body;if(e.body.type===Y.BlockStatement){let t=e.body.body.filter(n=>n.type===Y.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==Y.ObjectExpression?null:t[0].argument}return null}function Kt(e,t){let n=e;if(t){let s=e.find(l=>l.type===Y.Property&&l.key.type===Y.Identifier&&l.key.name===t);if(s?.type!==Y.Property||s.value.type!==Y.ObjectPattern)return null;n=s.value.properties}let r=new Map;for(let s of n){if(s.type!==Y.Property||s.key.type!==Y.Identifier)return null;r.set(s.key.name,s)}return r.size>0?r:null}function Br(e,t){let n=t.getDeclaredVariables(e);if(n.length!==1)return[];let r=n[0];return r?r.references.filter(s=>s.identifier!==e.id):[]}import{AST_NODE_TYPES as H}from"@typescript-eslint/utils";var at=pe({name:"no-unused-t-state-field",meta:{type:"suggestion",docs:{description:"Prevent declaring unused t-state fields"},messages:{unusedField:'Field "{{name}}" is not being used, you can safely remove it'},schema:[]},defaultOptions:[],create(e){if(!(e.filename.endsWith(".jsx")||e.filename.endsWith(".tsx")))return{};if(!e.sourceCode.ast.body.some(l=>l.type===H.ImportDeclaration&&l.source.value==="t-state-form"))return{};let r=null,s=!1;return{CallExpression(l){if(s)return;if(!r){let i=qr(l);i&&(r=i);return}let o=Xr(l,e.sourceCode);if(o){s=!0;for(let i of o)r.delete(i);if(r.size!==0)for(let[i,a]of r)e.report({node:a,messageId:"unusedField",data:{name:i}})}}}}});function qr(e){if(!(e.callee.type===H.Identifier&&e.callee.name==="useForm"))return null;let n=e.arguments[0];if(!n||n.type!==H.ObjectExpression)return null;let r=Qe(n.properties,l=>l.type!==H.Property||l.key.type!==H.Identifier||l.key.name!=="initialConfig"?null:l.value.type===H.ObjectExpression?l.value:l.value.type===H.ArrowFunctionExpression||l.value.type===H.FunctionExpression?Kr(l.value):null);if(!r)return null;let s=new Map;for(let l of r.properties)l.type===H.Property&&l.key.type===H.Identifier&&s.set(l.key.name,l);return s}function Xr(e,t){if(!(e.callee.type===H.Identifier&&e.callee.name==="useFormState")||e.parent.type!==H.VariableDeclarator||e.parent.id.type!==H.ObjectPattern||!Qe(e.parent.id.properties,o=>o.type===H.Property&&o.key.type===H.Identifier&&o.key.name==="formFields"&&o))return null;let s=Ht(e.parent,"formFields",t),l=new Set;for(let{identifier:o}of s){if(o.type!==H.Identifier||o.parent.type===H.Property&&o.parent.parent.type===H.ObjectExpression&&o.parent.parent.parent.type===H.ReturnStatement||o.parent.type===H.ReturnStatement)return null;if(o.parent.type===H.MemberExpression){if(o.parent.object.type!==H.Identifier||o.parent.property.type!==H.Identifier)return null;l.add(o.parent.property.name)}}return l}function Kr(e){if(e.body.type===H.ObjectExpression)return e.body;if(e.body.type===H.BlockStatement){let t=e.body.body.filter(n=>n.type===H.ReturnStatement);return t.length!==1||!t[0]||t[0].argument?.type!==H.ObjectExpression?null:t[0].argument}return null}import{AST_NODE_TYPES as U,ESLintUtils as Jr}from"@typescript-eslint/utils";var Gr=Jr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Jt(e){let t=[];for(let n of e.members)n.type===U.TSPropertySignature&&n.key.type===U.Identifier&&t.push([n.key.name,n]);return t}function Gt(e,...t){for(let n of t)e.set(...n);return e}var Zr=D({forceCheckOnFCPropTypesWithName:P(V(F()))}),Zt="no-unused-type-props-in-args",lt=null,Qr=Gr({name:Zt,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[Zr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!lt&&(lt=n.map(i=>new RegExp(i)));function r(i,a,c,p,u=!0){let g=c.name,S=e.sourceCode.getScope(a).references.find(w=>w.identifier.name===g)?.resolved,E=i&<?.some(w=>w.test(g));if(!S||!E&&S.references.filter(w=>w.isTypeReference).length>1)return;let T=S?.defs[0]?.node;if(!(u&&T?.parent?.type===U.ExportNamedDeclaration)){if(T?.type===U.TSTypeAliasDeclaration){s(i,a,p,T.typeAnnotation,!0);return}if(T?.type===U.TSInterfaceDeclaration){s(i,a,p,T.body,!0);return}}}function s(i,a,c,p,u){if(p.type===U.TSInterfaceBody){for(let g of p.body)g.type===U.TSPropertySignature&&g.key.type===U.Identifier&&c.set(g.key.name,g);return}if(p.type===U.TSTypeLiteral){Gt(c,...Jt(p));return}if(p.type===U.TSIntersectionType){for(let g of p.types)s(i,a,c,g,!0);return}u||p.type===U.TSTypeReference&&p.typeName.type===U.Identifier&&r(i,a,p.typeName,c)}function l(i,a,c){for(let p of c)if(p.type==="ObjectPattern"&&p.typeAnnotation){let u=new Map;if(s(i,a,u,p.typeAnnotation.typeAnnotation,!1),u.size===0)continue;o(p,u)}else p.type===U.AssignmentPattern&&p.left.type===U.ObjectPattern&&l(i,a,[p.left])}function o(i,a){let c=[];if(i.properties.at(-1)?.type===U.RestElement)return;for(let S of i.properties)S.type===U.Property&&S.key.type===U.Identifier&&c.push(S.key.name);let u=[],g=[];for(let[S,E]of a)c.includes(S)||(g.push(S),u.push({node:E,messageId:"unusedObjectTypeProperty",data:{propertyName:S}}));for(let[S,E]of u.entries())e.report({...E,fix:S===u.length-1?T=>{let w=i.properties.at(-1),h=g.join(", ");return w?w?.type===U.RestElement?null:T.insertTextAfter(w,`, ${h}`):T.insertTextBeforeRange([i.range[0]+1,i.range[1]],`${h}`)}:void 0})}return{VariableDeclaration(i){let a=i.declarations[0];if(!a)return;let c=new Map,p=a.id.type===U.Identifier&&a.id.typeAnnotation?.typeAnnotation.type===U.TSTypeReference&&a.id.typeAnnotation.typeAnnotation.typeName.type===U.Identifier&&a.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&a.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(p){if(p.type===U.TSTypeReference&&p.typeName.type===U.Identifier)r(!0,i,p.typeName,c,!1);else if(p.type===U.TSTypeLiteral)Gt(c,...Jt(p));else if(p.type===U.TSIntersectionType)for(let u of p.types)u.type===U.TSTypeReference&&u.typeName.type===U.Identifier?r(!0,i,u.typeName,c,!1):s(!0,i,c,u,!0);if(c.size!==0&&a.init?.type===U.ArrowFunctionExpression){let u=a.init.params[0];if(!u){e.report({node:a.init,messageId:"missingComponentParam"});return}u.type===U.ObjectPattern&&o(u,c)}}},FunctionDeclaration:function(i){l(!1,i,i.params)},ArrowFunctionExpression(i){l(!1,i,i.params)}}}}),ct={name:Zt,rule:Qr};import{AST_NODE_TYPES as pt,ESLintUtils as ei}from"@typescript-eslint/utils";var ti=ei.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),en="prefer-named-functions",Qt=new Map,ni=ti({name:en,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let r=Qt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),Qt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===pt.ArrowFunctionExpression&&r.id.type===pt.Identifier){let s=r.id.name;if(r.id.typeAnnotation||n&&n.test(s)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==pt.BlockStatement)return;let l=r.parent,o=r.init.params,i=r.init.body,a=r.init;e.report({node:r.id,messageId:n?"withIgnoreRegex":"default",data:{functionName:s,ignoreRegex:t.ignoreRegex},suggest:[{messageId:"suggestion",fix:c=>c.replaceText(l,`${a.async?"async ":""}function ${s}(${o.map(p=>e.sourceCode.getText(p)).join(", ")||""}) ${e.sourceCode.getText(i)}`)}]})}}}}}),ut={name:en,rule:ni};import{AST_NODE_TYPES as j}from"@typescript-eslint/utils";var ri=D({disallowedFunctions:V(D({name:F(),allowUsingWithArgs:P(oe()),hookAlternative:P(F()),message:P(F()),allowUseInside:P(V(F()))}))});function Oe(e){return/^use[A-Z]/.test(e)}function tn(e){return/^[A-Z]/.test(e)}function ii(e){return e.type===j.Identifier?Oe(e.name):e.type===j.MemberExpression&&e.property.type===j.Identifier?Oe(e.property.name):!1}function nn(e,t){return e.type===j.Identifier?e.name===t:e.type===j.MemberExpression&&e.object.type===j.Identifier&&e.property.type===j.Identifier?e.object.name==="React"&&e.property.name===t:!1}function rn(e){return!!(e.parent&&e.parent.type===j.CallExpression&&nn(e.parent.callee,"forwardRef"))}function sn(e){return!!(e.parent&&e.parent.type===j.CallExpression&&nn(e.parent.callee,"memo"))}function ft(e){if(e.type===j.FunctionDeclaration||e.type===j.FunctionExpression&&e.id)return e.id||void 0;if(e.type===j.FunctionExpression||e.type===j.ArrowFunctionExpression){if(e.parent.type===j.VariableDeclarator&&e.parent.init===e)return e.parent.id;if(e.parent.type===j.AssignmentExpression&&e.parent.right===e&&e.parent.operator==="=")return e.parent.left;if(e.parent.type===j.Property&&e.parent.value===e&&!e.parent.computed)return e.parent.key;if(e.parent.type===j.AssignmentPattern&&e.parent.right===e)return e.parent.left}}function si(e){let t=e.parent,n=!1;for(;t;){if(t.type===j.FunctionDeclaration||t.type===j.FunctionExpression||t.type===j.ArrowFunctionExpression){let r=ft(t);if(r&&r.type===j.Identifier){if(tn(r.name)||Oe(r.name))return!n;n=!0}else{if(rn(t)||sn(t))return!n;if(t.parent.type===j.CallExpression){let s=t.parent;ii(s.callee)||(n=!0)}else t.parent.type===j.JSXExpressionContainer||(n=!0)}}t=t.parent}return!1}function on(e){return e.callee.type===j.Identifier?e.callee.name:e.callee.type===j.MemberExpression&&e.callee.property.type===j.Identifier?e.callee.property.name:null}function oi(e,t){if(!t.length)return!1;let n=e.parent;for(;n;){if(n.type===j.FunctionDeclaration||n.type===j.FunctionExpression||n.type===j.ArrowFunctionExpression){let r=ft(n);if(r&&r.type===j.Identifier&&t.includes(r.name))return!0}else if(n.type===j.CallExpression){let r=on(n);if(r&&t.includes(r))return!0}n=n.parent}return!1}function ai(e){return e.arguments.length>0&&!e.arguments.every(t=>t.type===j.Identifier&&t.name==="undefined")}function li(e,t){let n=!1,r=e.parent;for(;r;){if(r.type===j.FunctionDeclaration||r.type===j.FunctionExpression||r.type===j.ArrowFunctionExpression){let s=ft(r);if(s&&s.type===j.Identifier){if(tn(s.name)||Oe(s.name)){n=!0;break}}else if(rn(r)||sn(r)){n=!0;break}}r=r.parent}return n?t.length===0?si(e):!oi(e,t):!1}var mt=pe({name:"prefer-react-hook-alternative",meta:{type:"suggestion",docs:{description:"Prefer hook alternatives for certain functions in React components and hooks"},messages:{preferHookAlternative:"This function should not be used in react{{message}}."},schema:[ri],hasSuggestions:!0},defaultOptions:[{disallowedFunctions:[]}],create(e,[t]){let{disallowedFunctions:n}=t,r=new Map(n.map(s=>[s.name,s]));return{CallExpression(s){let l=on(s);if(!l)return;let o=r.get(l);if(!o||o.allowUsingWithArgs&&ai(s))return;let i=o.allowUseInside||[];li(s,i)&&e.report({node:s,messageId:"preferHookAlternative",data:{message:o.message?` ${o.message}`:` use ${o.hookAlternative} instead`},suggest:o.hookAlternative?[{messageId:"preferHookAlternative",data:{message:`Replace with ${o.hookAlternative}`,hookAlternative:o.hookAlternative},fix:a=>{let c=o.hookAlternative;return s.callee.type===j.Identifier?a.replaceText(s.callee,c):s.callee.type===j.MemberExpression&&s.callee.property.type===j.Identifier?a.replaceText(s.callee.property,c):null}}]:[]})}}}});import{AST_NODE_TYPES as B,AST_TOKEN_TYPES as an,ESLintUtils as ci}from"@typescript-eslint/utils";var pi=ci.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),cn="prefer-single-line-if",ui=D({maxLineLength:P(J()),maxNonSimpleConditionLength:P(J())}),fi=pi({name:cn,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:[ui]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode;return{IfStatement(r){if(r.consequent.type!==B.BlockStatement||r.loc.start.line===r.loc.end.line||n.getCommentsInside(r.consequent).length>0||r.alternate||r.consequent.body.length!==1)return;let l=r.consequent.body[0];if(l.type===B.ReturnStatement){if(!un(l))return}else if(!(l.type===B.ContinueStatement||l.type===B.BreakStatement))return;if(r.test.type===B.LogicalExpression||r.test.type===B.ConditionalExpression)return;let o;if(t.maxNonSimpleConditionLength){let u=ln(r.test);if(!u&&r.test.type===B.UnaryExpression&&r.test.operator==="!"){let g=r.test.argument;ln(g)&&(u=!0)}if(u&&(o=n.getText(r.test),o.length>t.maxNonSimpleConditionLength))return}o||(o=n.getText(r.test));let i=n.getText(l);if(o.includes(`
|
|
15
|
+
`))return;let a=n.getTokenAfter(r);if(a&&a.type===an.Punctuator&&a.value==="}"){let u=n.getTokenAfter(a);if(u&&u.type===an.Keyword&&(u.value==="else"||u.value==="catch"))return}let c=mi(n,r),p=`if (${o}) ${i}`;t.maxLineLength&&p.length+c.length>t.maxLineLength||e.report({node:r,messageId:"noSingleLineCurly",fix:u=>u.replaceText(r,p)})}}}});function ln(e){return e.type===B.CallExpression||e.type===B.BinaryExpression||e.type===B.MemberExpression&&pn(e)}function pn(e){return e.object.type===B.MemberExpression?pn(e.object):e.object.type!==B.Identifier}function mi(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function un(e){if(!e.argument)return!0;let t=e.argument;return t.type===B.ArrayExpression&&t.elements.length===0||t.type===B.ObjectExpression&&t.properties.length===0||t.type===B.Literal||t.type===B.Identifier||t.type===B.TemplateLiteral||t.type===B.TaggedTemplateExpression?!0:t.type===B.CallExpression?t.arguments.length===0:t.type===B.UnaryExpression?un(t):!1}var dt={name:cn,rule:fi};import{AST_NODE_TYPES as te,ESLintUtils as di}from"@typescript-eslint/utils";var yi=di.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),fn="react-compiler-migration",gi=D({disallowHooks:P(V(D({name:F(),replacement:F()}))),disallowMethods:P(V(D({name:F(),replacement:P(F()),requireTrueProp:P(F())})))}),Si=/eslint +react-compiler\/react-compiler: +\["error/;function Ti(e){return e.type===te.Identifier?e.name.startsWith("use"):e.type===te.MemberExpression&&e.property.type===te.Identifier?e.property.name.startsWith("use"):!1}var hi=yi({name:fn,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:[gi]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(Si.test(r.value)){n=!0;break}return n?{CallExpression(r){if(t.disallowHooks?.length){let s=null,l=null;if(r.callee.type===te.Identifier?(s=r.callee.name,l=r.callee):r.callee.type===te.MemberExpression&&r.callee.property.type===te.Identifier&&(s=r.callee.property.name,l=r.callee.property),s){let o=t.disallowHooks.find(i=>i.name===s);o&&l&&e.report({node:r,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:o.name,replacement:o.replacement},suggest:[{messageId:"replace",data:{replacement:o.replacement},fix:i=>i.replaceText(l,o.replacement)}]})}}if(t.disallowMethods?.length&&Ti(r.callee)){for(let s of r.arguments)if(s.type===te.ObjectExpression){for(let l of s.properties)if(l.type===te.Property&&l.key.type===te.Identifier){let o=l.key.name,i=t.disallowMethods.find(a=>a.name===o);if(i){if(i.requireTrueProp){let a=i.requireTrueProp,c=!1;for(let p of s.properties)if(p.type===te.Property&&p.key.type===te.Identifier&&p.key.name===a&&p.value.type===te.Literal&&p.value.value===!0){c=!0;break}if(!c){e.report({node:l,messageId:"disallowedMethodWithMissingRequireTrueProp",data:{method:i.name,requireTrueProp:a}});continue}}i.replacement&&e.report({node:l,messageId:"disallowedFunctionOrMethod",data:{functionOrMethod:i.name,replacement:i.replacement},suggest:[{messageId:"replace",data:{replacement:i.replacement},fix:a=>a.replaceText(l.key,i.replacement)}]})}}}}}}:{}}}),yt={name:fn,rule:hi};import{ESLintUtils as Ei,TSESTree as bi}from"@typescript-eslint/utils";var xi=Ei.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),mn="require-description",Ii=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Ci=/^eslint-disable-(next-)?line$/u,wi=xi({name:mn,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let s of n.getAllComments()){let l=Ri(s);l!=null&&(r.has(l.kind)||l.description||e.report({loc:ki(s.loc),messageId:"missingDescription"}))}}}}}),dn={name:mn,rule:wi};function Ri(e){let{text:t,description:n}=vi(e.value);if(!t)return null;let r=Ii.exec(t);if(!r)return null;let s=r[1];if(!s)return null;let l=Ci.test(s);if(e.type===bi.AST_TOKEN_TYPES.Line&&!l||l&&e.loc.start.line!==e.loc.end.line)return null;let o=t.slice(r.index+s.length);return{kind:s,value:o.trim(),description:n}}function vi(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function ki(e){return{start:{line:e.start.line,column:-1},end:e.end}}function Sn(e){return/^use[A-Z0-9]/.test(e)}function Pe(e){return e.type==="Identifier"?Sn(e.name):e.type==="MemberExpression"&&!e.computed&&Pe(e.property)?e.object.type==="Identifier":!1}function Tn(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function hn(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function En(e){return!!(e.parent&&e.parent.callee&&hn(e.parent.callee,"forwardRef"))}function bn(e){return!!(e.parent&&e.parent.callee&&hn(e.parent.callee,"memo"))}function gt(e){for(;e;){let t=In(e);if(t&&(Tn(t)||Pe(t))||En(e)||bn(e))return!0;e=e.parent}return!1}function yn(e){return!1}function St(e){return!1}var Ai=/eslint +react-compiler\/react-compiler: +\["error/,xn={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(Ai.test(a.value))return{CallExpression(c){let p=null;c.callee.name==="useMemo"?p="useMemo":c.callee.name==="useCallback"&&(p="useCallback"),p&&e.report({node:c,message:`"${p}" is not necessary when using React Compiler.`})}}}let t=typeof e.getSource=="function"?a=>t(a):a=>e.sourceCode.getText(a),n=typeof e.getScope=="function"?()=>n():a=>e.sourceCode.getScope(a),r=null,s=[],l=[],o=new WeakSet;function i(a){for(let c of a.references){let p=c.identifier.parent;if(p.type==="VariableDeclarator"&&p.init&&p.init.type==="CallExpression"&&p.init.callee&&yn(p.init.callee))for(let u of c.resolved.references)u!==c&&o.add(u.identifier)}}return{onCodePathSegmentStart:a=>l.push(a),onCodePathSegmentEnd:()=>l.pop(),onCodePathStart:()=>s.push(new Map),onCodePathEnd(a,c){let p=s.pop();if(p.size===0)return;let u=new Set;function g(m,v){let{cache:R}=g,A=R.get(m.id),O=new Set(v);if(O.has(m.id)){let x=[...O],M=x.slice(x.indexOf(m.id)+1);for(let z of M)u.add(z);return BigInt("0")}if(O.add(m.id),A!==void 0)return A;if(a.thrownSegments.includes(m))A=BigInt("0");else if(m.prevSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let x of m.prevSegments)A+=g(x,O)}return m.reachable&&A===BigInt("0")?R.delete(m.id):R.set(m.id,A),A}function S(m,v){let{cache:R}=S,A=R.get(m.id),O=new Set(v);if(O.has(m.id)){let x=Array.from(O),M=x.slice(x.indexOf(m.id)+1);for(let z of M)u.add(z);return BigInt("0")}if(O.add(m.id),A!==void 0)return A;if(a.thrownSegments.includes(m))A=BigInt("0");else if(m.nextSegments.length===0)A=BigInt("1");else{A=BigInt("0");for(let x of m.nextSegments)A+=S(x,O)}return R.set(m.id,A),A}function E(m){let{cache:v}=E,R=v.get(m.id);if(R===null)return 1/0;if(R!==void 0)return R;if(v.set(m.id,null),m.prevSegments.length===0)R=1;else{R=1/0;for(let A of m.prevSegments){let O=E(A);O<R&&(R=O)}R+=1}return v.set(m.id,R),R}g.cache=new Map,S.cache=new Map,E.cache=new Map;let T=S(a.initialSegment),w=In(c),h=gt(c),_=w?Tn(w)||Pe(w):En(c)||bn(c),d=1/0;for(let m of a.finalSegments){if(!m.reachable)continue;let v=E(m);v<d&&(d=v)}for(let[m,v]of p){if(!m.reachable)continue;let R=m.nextSegments.length===0?d<=E(m):d<E(m),A=g(m)*S(m),O=u.has(m.id);for(let x of v)if(O&&!St(x)&&e.report({node:x,message:`React Hook "${t(x)}" 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.`}),_){if(c.async&&e.report({node:x,message:`React Hook "${t(x)}" cannot be called in an async function.`}),!O&&A!==T&&!St(x)){let z=`React Hook "${t(x)}" 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:x,message:z})}}else if(c.parent&&(c.parent.type==="MethodDefinition"||c.parent.type==="ClassProperty")&&c.parent.value===c){let M=`React Hook "${t(x)}" 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:x,message:M})}else if(w){let M=`React Hook "${t(x)}" is called in function "${t(w)}" 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:x,message:M})}else if(c.type==="Program"){let M=`React Hook "${t(x)}" 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:x,message:M})}else if(h&&!St(x)){if(c.parent.type==="CallExpression"&&c.parent.callee.type==="Identifier"&&c.parent.callee.name==="useCallback"){let z=c.parent;if(z.parent.type==="VariableDeclarator"&&Sn(z.parent.id.name))return}let M=`React Hook "${t(x)}" 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:x,message:M})}}},CallExpression(a){if(Pe(a.callee)){let c=gn(s),p=gn(l),u=c.get(p);u||(u=[],c.set(p,u)),u.push(a.callee)}a.callee.type==="Identifier"&&(a.callee.name==="useEffect"||yn(a.callee))&&a.arguments.length>0&&(r=a)},Identifier(a){r==null&&o.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===r&&(r=null)},FunctionDeclaration(a){gt(a)&&i(n(a))},ArrowFunctionExpression(a){gt(a)&&i(n(a))}}}};function In(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 gn(e){return e[e.length-1]}var Cn={[ct.name]:ct.rule,[Xe.name]:Xe.rule,[qe.name]:qe.rule,"rules-of-hooks":xn,"exhaustive-deps":kt,"require-description":dn.rule,[Ke.name]:Ke.rule,[Ge.name]:Ge.rule,[ut.name]:ut.rule,[$e.name]:$e.rule,[Be.name]:Be.rule,[nt.name]:nt.rule,[dt.name]:dt.rule,[et.name]:et.rule,[Je.name]:Je.rule,[Ve.name]:Ve.rule,[yt.name]:yt.rule,[Me.name]:Me.rule,[ze.name]:ze.rule,[it.name]:it.rule,[ot.name]:ot.rule,[at.name]:at.rule,[st.name]:st.rule,[mt.name]:mt.rule};var Do={rules:Cn};export{Do as extendedLintPlugin};
|