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