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