@ls-stack/extended-lint 0.36.1 → 0.38.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 +2 -2
package/dist/extended-lint.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var dn=Object.create;var he=Object.defineProperty;var yn=Object.getOwnPropertyDescriptor;var gn=Object.getOwnPropertyNames;var hn=Object.getPrototypeOf,Tn=Object.prototype.hasOwnProperty;var Sn=(e,t)=>{for(var n in t)he(e,n,{get:t[n],enumerable:!0})},ut=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of gn(t))!Tn.call(e,l)&&l!==n&&he(e,l,{get:()=>t[l],enumerable:!(r=yn(t,l))||r.enumerable});return e};var Pe=(e,t,n)=>(n=e!=null?dn(hn(e)):{},ut(t||!e||!e.__esModule?he(n,"default",{value:e,enumerable:!0}):n,e)),En=e=>ut(he({},"__esModule",{value:!0}),e);var Wr={};Sn(Wr,{extendedLintPlugin:()=>Ur});module.exports=En(Wr);var H=require("@typescript-eslint/utils");var Ne=Symbol.for("optional");function $(e){return{...e,[Ne]:!0}}function Te(e,t){return{enum:e,...t}}function oe(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function J(e){return{...e,type:"number"}}function ft(e){return{...e,type:"integer"}}function V(e,t){return{...t,type:"array",items:e}}function j(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,l=[];for(r in e)e[r][Ne]?e[r][Ne]=void 0:l.push(r);l.length>0&&(n.required=l)}return n}function _e(...e){return{anyOf:e}}var bn=H.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),dt="react-compiler-extra",xn=j({runOnlyWithEnableCompilerDirective:$(oe())}),Cn=/eslint +react-compiler\/react-compiler: +\["error/;function In(e){return e.type===H.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===H.AST_NODE_TYPES.MemberExpression&&e.property.type===H.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var wn=/\bthis[.[]/;function mt(e){return wn.test(e)}var Rn=bn({name:dt,meta:{type:"suggestion",fixable:"code",docs:{description:"Extra rules to enforce best practices when using the React compiler"},messages:{objectMethodIsNotSupported:"Object methods such as `{ method() {} }` have limited support to optimizations in the React compiler, use a function expression `{ method: () => {} }` instead.",replaceWithFunctionExpression:"Replace with function expression",thisKeywordInMethod:"Object method uses `this` keyword which would have different behavior if converted to an arrow function. Fix this manually."},hasSuggestions:!0,schema:[xn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let f of e.sourceCode.getAllComments())if(Cn.test(f.value)){n=!0;break}if(!n)return{}}function r(f){for(let p of f.properties)if(p.type===H.AST_NODE_TYPES.Property&&p.method&&p.value.type===H.AST_NODE_TYPES.FunctionExpression){let i=e.sourceCode,o=i.getText(p.key),a=p.value,s=i.getText(a.body);if(mt(s))e.report({node:p,messageId:"thisKeywordInMethod"});else{let c=a.params.map(T=>i.getText(T)).join(", "),g="";a.generator?g=`${o}: function* (${c}) ${s}`:g=`${o}: (${c}) => ${s}`,e.report({node:p,messageId:"objectMethodIsNotSupported",fix:T=>T.replaceText(p,g)})}}}function l(f){for(let p of f.properties)if(p.type===H.AST_NODE_TYPES.Property&&p.value.type===H.AST_NODE_TYPES.ObjectExpression){for(let i of p.value.properties)if(i.type===H.AST_NODE_TYPES.Property&&i.method&&i.value.type===H.AST_NODE_TYPES.FunctionExpression){let a=e.sourceCode.getText(i.value.body);mt(a)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(f){if(In(f.callee))for(let p of f.arguments){if(p.type===H.AST_NODE_TYPES.ObjectExpression&&(r(p),l(p)),p.type===H.AST_NODE_TYPES.ArrowFunctionExpression&&(p.body.type===H.AST_NODE_TYPES.ObjectExpression&&(r(p.body),l(p.body)),p.body.type===H.AST_NODE_TYPES.BlockStatement))for(let i of p.body.body)i.type===H.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===H.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),l(i.argument));if(p.type===H.AST_NODE_TYPES.FunctionExpression)for(let i of p.body.body)i.type===H.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===H.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),l(i.argument))}}}}}),De={name:dt,rule:Rn};var ae=require("@typescript-eslint/utils");var vn=ae.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),kn=j({disallow:$(V(j({selector:F(),message:F(),replace:$(_e(F(),j({regex:F(),with:F()}))),replaceType:$(Te(["suggestion","autofix"]))}))),__dev_simulateFileName:$(F()),mustMatchSyntax:$(V(j({includeRegex:F(),mustCallFn:V(j({anyCall:V(j({fn:F(),withArgs:V(j({atIndex:ft(),literal:_e(F(),J(),oe())}))})),message:$(F())}))})))}),ht="advanced-no-restricted-syntax",An=vn({name:ht,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[kn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:l,disallow:f}=t,p=l??e.filename,i=[],o=new Set;for(let{includeRegex:s,mustCallFn:c}of r??[]){let g=On(p,new RegExp(s));if(!g)continue;let T=S=>{let d=S;for(let{name:b,value:y}of g)d=d.replaceAll(b,y);return d};for(let{anyCall:S,message:d}of c){let b=`Expected file to call the function: ${S.map(({fn:y})=>y).join(" or ")}`;o.add(b),i.push(y=>{let{callee:N}=y;if(N.type===ae.AST_NODE_TYPES.Identifier){for(let{fn:v,withArgs:h}of S)if(N.name===v){o.delete(b);for(let w of h){let R=y.arguments[w.atIndex],k=typeof w.literal=="string"?T(w.literal):w.literal;if(!R){e.report({node:y,messageId:"default",data:{message:`Missing argument with value "${k}" at index ${w.atIndex}${d?`: ${T(d)}`:""}`}});continue}if(R.type!==ae.AST_NODE_TYPES.Literal){e.report({node:R,messageId:"default",data:{message:`Argument at position ${w.atIndex} should the literal "${k}"${d?`: ${T(d)}`:""}`}});continue}R.value!==k&&e.report({node:R,messageId:"default",data:{message:`Argument should have the value "${k}"${d?`: ${T(d)}`:""}`},fix:_=>_.replaceText(R,typeof k=="string"?`'${k}'`:String(k))})}break}}})}}for(let{selector:s,message:c,replace:g,replaceType:T="suggestion"}of f??[]){if(s==="CallExpression"){i.push(S=>{a(g,S,c,T)});continue}n[s]=S=>{a(g,S,c,T)}}return i.length>0&&(n.CallExpression=s=>{if(s.type===ae.AST_NODE_TYPES.CallExpression)for(let c of i)c(s)}),n["Program:exit"]=s=>{for(let c of o)e.report({node:s,messageId:"default",data:{message:`${c}`}})},n;function a(s,c,g,T){let S=d=>{if(!s)return null;if(typeof s=="string")return d.replaceText(c,s);{let b=new RegExp(s.regex),y=e.sourceCode.getText(c);return d.replaceText(c,y.replace(b,s.with))}};e.report({node:c,messageId:"default",data:{message:g},fix:s&&T==="autofix"?S:void 0,suggest:s&&T==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof s=="string"?s:s.with}"`},fix:S}]:void 0})}}});function On(e,t){let n=[],r=t.exec(e);if(!r)return null;let[l,...f]=r;n.push({name:"$0_lowercase",value:l.toLowerCase()}),n.push({name:"$0_capitalize",value:yt(l)}),n.push({name:"$0_uncapitalize",value:gt(l)}),n.push({name:"$0",value:l});for(let p=0;p<f.length;p++){let i=`$${p+1}`,o=f[p];n.push({name:`${i}_lowercase`,value:o.toLowerCase()}),n.push({name:`${i}_capitalize`,value:yt(o)}),n.push({name:`${i}_uncapitalize`,value:gt(o)}),n.push({name:i,value:o})}return n}function yt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function gt(e){return e.charAt(0).toLowerCase()+e.slice(1)}var Le={name:ht,rule:An};var D=require("@typescript-eslint/utils");var Pn=D.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),St="collapse-simple-objs-in-one-line",Nn=j({maxLineLength:$(J()),maxProperties:$(J()),nestedObjMaxLineLength:$(J()),nestedObjMaxProperties:$(J()),ignoreTypesWithSuffix:$(V(F()))}),_n=Pn({name:St,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??[],l=t.maxProperties??2,f=t.nestedObjMaxLineLength??t.maxLineLength,p=t.nestedObjMaxProperties??3;function i(a){if(a.type===D.AST_NODE_TYPES.ObjectExpression){let s=a.parent.type===D.AST_NODE_TYPES.Property,c=s?p:l,g=a.properties.length;if(g>c)return!1;if(g===1){let S=a.properties[0];return S.type===D.AST_NODE_TYPES.Property&&(S.value.type===D.AST_NODE_TYPES.ObjectExpression||S.value.type===D.AST_NODE_TYPES.ArrayExpression)?!1:{text:n.getText(S),isNested:s,propsSize:g}}let T=[];for(let S of a.properties){if(S.type===D.AST_NODE_TYPES.Property){let d=S.value.type;if(!(d===D.AST_NODE_TYPES.Literal||d===D.AST_NODE_TYPES.Identifier||d===D.AST_NODE_TYPES.TemplateLiteral||d===D.AST_NODE_TYPES.TaggedTemplateExpression))return!1}T.push(n.getText(S))}return{text:T.join(", "),isNested:s,propsSize:g}}else{let s=a.parent.parent?.type===D.AST_NODE_TYPES.TSPropertySignature,c=s?p:l,g=a.members.length;if(g>c)return!1;if(r.length>0&&a.parent.type===D.AST_NODE_TYPES.TSTypeAliasDeclaration){let S=a.parent.id.name;if(r.some(d=>S.endsWith(d)))return!1}if(g===1){let S=a.members[0];return S.type===D.AST_NODE_TYPES.TSPropertySignature&&S.typeAnnotation?.typeAnnotation.type===D.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(S),isNested:s,propsSize:1}}if(a.parent.type===D.AST_NODE_TYPES.TSIntersectionType||a.parent.type===D.AST_NODE_TYPES.TSUnionType)return!1;let T=[];for(let S of a.members){if(S.type!==D.AST_NODE_TYPES.TSPropertySignature)return!1;let d=S.typeAnnotation?.typeAnnotation;if(!d||d.type===D.AST_NODE_TYPES.TSTypeLiteral||!Tt(d.type))return!1;if(d.type===D.AST_NODE_TYPES.TSTypeReference&&d.typeArguments){if(d.typeArguments.params.length>1)return!1;let y=d.typeArguments.params[0];if(!Tt(y.type))return!1}let b=n.getText(S).trim();(b.endsWith(";")||b.endsWith(","))&&(b=b.slice(0,-1)),T.push(b)}return{text:T.join("; "),isNested:s,propsSize:g}}}function o(a){if(a.loc.start.line===a.loc.end.line)return;if(a.parent.type!==D.AST_NODE_TYPES.JSXExpressionContainer){let d=0,b=n.getTokenAfter(a,{filter:y=>y.type!==D.AST_TOKEN_TYPES.Punctuator?!0:y.value===","||y.value===";"||y.value===")"||y.value==="}"?(d++,!1):!0});if(d>2||b?.loc.start.line===a.loc.end.line)return}let s=i(a);if(!s)return;let c=s.text;if(c.includes(`
|
|
2
|
-
`)||n.getCommentsInside(a).length>0)return;c.endsWith(";")&&(c=c.slice(0,-1));let g=`{ ${c} }`,T
|
|
3
|
-
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function
|
|
1
|
+
"use strict";var yn=Object.create;var he=Object.defineProperty;var gn=Object.getOwnPropertyDescriptor;var hn=Object.getOwnPropertyNames;var Tn=Object.getPrototypeOf,Sn=Object.prototype.hasOwnProperty;var En=(e,t)=>{for(var n in t)he(e,n,{get:t[n],enumerable:!0})},ft=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of hn(t))!Sn.call(e,l)&&l!==n&&he(e,l,{get:()=>t[l],enumerable:!(r=gn(t,l))||r.enumerable});return e};var Pe=(e,t,n)=>(n=e!=null?yn(Tn(e)):{},ft(t||!e||!e.__esModule?he(n,"default",{value:e,enumerable:!0}):n,e)),bn=e=>ft(he({},"__esModule",{value:!0}),e);var Vr={};En(Vr,{extendedLintPlugin:()=>Wr});module.exports=bn(Vr);var V=require("@typescript-eslint/utils");var Ne=Symbol.for("optional");function $(e){return{...e,[Ne]:!0}}function Te(e,t){return{enum:e,...t}}function oe(e){return{...e,type:"boolean"}}function F(e){return{...e,type:"string"}}function J(e){return{...e,type:"number"}}function mt(e){return{...e,type:"integer"}}function H(e,t){return{...t,type:"array",items:e}}function j(e,t){let n={...t,type:"object",properties:e};if(e&&(n.additionalProperties||=!1,!n.required)){let r,l=[];for(r in e)e[r][Ne]?e[r][Ne]=void 0:l.push(r);l.length>0&&(n.required=l)}return n}function _e(...e){return{anyOf:e}}var xn=V.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),yt="react-compiler-extra",Cn=j({runOnlyWithEnableCompilerDirective:$(oe())}),In=/eslint +react-compiler\/react-compiler: +\["error/;function wn(e){return e.type===V.AST_NODE_TYPES.Identifier?e.name.startsWith("use"):e.type===V.AST_NODE_TYPES.MemberExpression&&e.property.type===V.AST_NODE_TYPES.Identifier?e.property.name.startsWith("use"):!1}var Rn=/\bthis[.[]/;function dt(e){return Rn.test(e)}var vn=xn({name:yt,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:[Cn]},defaultOptions:[{}],create(e,[t]){let n=!1;if(t.runOnlyWithEnableCompilerDirective){for(let f of e.sourceCode.getAllComments())if(In.test(f.value)){n=!0;break}if(!n)return{}}function r(f){for(let p of f.properties)if(p.type===V.AST_NODE_TYPES.Property&&p.method&&p.value.type===V.AST_NODE_TYPES.FunctionExpression){let i=e.sourceCode,o=i.getText(p.key),a=p.value,s=i.getText(a.body);if(dt(s))e.report({node:p,messageId:"thisKeywordInMethod"});else{let c=a.params.map(T=>i.getText(T)).join(", "),g="";a.generator?g=`${o}: function* (${c}) ${s}`:g=`${o}: (${c}) => ${s}`,e.report({node:p,messageId:"objectMethodIsNotSupported",fix:T=>T.replaceText(p,g)})}}}function l(f){for(let p of f.properties)if(p.type===V.AST_NODE_TYPES.Property&&p.value.type===V.AST_NODE_TYPES.ObjectExpression){for(let i of p.value.properties)if(i.type===V.AST_NODE_TYPES.Property&&i.method&&i.value.type===V.AST_NODE_TYPES.FunctionExpression){let a=e.sourceCode.getText(i.value.body);dt(a)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(f){if(wn(f.callee))for(let p of f.arguments){if(p.type===V.AST_NODE_TYPES.ObjectExpression&&(r(p),l(p)),p.type===V.AST_NODE_TYPES.ArrowFunctionExpression&&(p.body.type===V.AST_NODE_TYPES.ObjectExpression&&(r(p.body),l(p.body)),p.body.type===V.AST_NODE_TYPES.BlockStatement))for(let i of p.body.body)i.type===V.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===V.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),l(i.argument));if(p.type===V.AST_NODE_TYPES.FunctionExpression)for(let i of p.body.body)i.type===V.AST_NODE_TYPES.ReturnStatement&&i.argument?.type===V.AST_NODE_TYPES.ObjectExpression&&(r(i.argument),l(i.argument))}}}}}),De={name:yt,rule:vn};var ae=require("@typescript-eslint/utils");var kn=ae.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),An=j({disallow:$(H(j({selector:F(),message:F(),replace:$(_e(F(),j({regex:F(),with:F()}))),replaceType:$(Te(["suggestion","autofix"]))}))),__dev_simulateFileName:$(F()),mustMatchSyntax:$(H(j({includeRegex:F(),mustCallFn:H(j({anyCall:H(j({fn:F(),withArgs:H(j({atIndex:mt(),literal:_e(F(),J(),oe())}))})),message:$(F())}))})))}),Tt="advanced-no-restricted-syntax",On=kn({name:Tt,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[An],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:l,disallow:f}=t,p=l??e.filename,i=[],o=new Set;for(let{includeRegex:s,mustCallFn:c}of r??[]){let g=Pn(p,new RegExp(s));if(!g)continue;let T=S=>{let d=S;for(let{name:b,value:y}of g)d=d.replaceAll(b,y);return d};for(let{anyCall:S,message:d}of c){let b=`Expected file to call the function: ${S.map(({fn:y})=>y).join(" or ")}`;o.add(b),i.push(y=>{let{callee:N}=y;if(N.type===ae.AST_NODE_TYPES.Identifier){for(let{fn:v,withArgs:h}of S)if(N.name===v){o.delete(b);for(let w of h){let R=y.arguments[w.atIndex],k=typeof w.literal=="string"?T(w.literal):w.literal;if(!R){e.report({node:y,messageId:"default",data:{message:`Missing argument with value "${k}" at index ${w.atIndex}${d?`: ${T(d)}`:""}`}});continue}if(R.type!==ae.AST_NODE_TYPES.Literal){e.report({node:R,messageId:"default",data:{message:`Argument at position ${w.atIndex} should the literal "${k}"${d?`: ${T(d)}`:""}`}});continue}R.value!==k&&e.report({node:R,messageId:"default",data:{message:`Argument should have the value "${k}"${d?`: ${T(d)}`:""}`},fix:D=>D.replaceText(R,typeof k=="string"?`'${k}'`:String(k))})}break}}})}}for(let{selector:s,message:c,replace:g,replaceType:T="suggestion"}of f??[]){if(s==="CallExpression"){i.push(S=>{a(g,S,c,T)});continue}n[s]=S=>{a(g,S,c,T)}}return i.length>0&&(n.CallExpression=s=>{if(s.type===ae.AST_NODE_TYPES.CallExpression)for(let c of i)c(s)}),n["Program:exit"]=s=>{for(let c of o)e.report({node:s,messageId:"default",data:{message:`${c}`}})},n;function a(s,c,g,T){let S=d=>{if(!s)return null;if(typeof s=="string")return d.replaceText(c,s);{let b=new RegExp(s.regex),y=e.sourceCode.getText(c);return d.replaceText(c,y.replace(b,s.with))}};e.report({node:c,messageId:"default",data:{message:g},fix:s&&T==="autofix"?S:void 0,suggest:s&&T==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof s=="string"?s:s.with}"`},fix:S}]:void 0})}}});function Pn(e,t){let n=[],r=t.exec(e);if(!r)return null;let[l,...f]=r;n.push({name:"$0_lowercase",value:l.toLowerCase()}),n.push({name:"$0_capitalize",value:gt(l)}),n.push({name:"$0_uncapitalize",value:ht(l)}),n.push({name:"$0",value:l});for(let p=0;p<f.length;p++){let i=`$${p+1}`,o=f[p];n.push({name:`${i}_lowercase`,value:o.toLowerCase()}),n.push({name:`${i}_capitalize`,value:gt(o)}),n.push({name:`${i}_uncapitalize`,value:ht(o)}),n.push({name:i,value:o})}return n}function gt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ht(e){return e.charAt(0).toLowerCase()+e.slice(1)}var Le={name:Tt,rule:On};var _=require("@typescript-eslint/utils");var Nn=_.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Et="collapse-simple-objs-in-one-line",_n=j({maxLineLength:$(J()),maxProperties:$(J()),nestedObjMaxLineLength:$(J()),nestedObjMaxProperties:$(J()),ignoreTypesWithSuffix:$(H(F()))}),Dn=Nn({name:Et,meta:{type:"suggestion",fixable:"code",docs:{description:"Format simple objects and types in one line"},messages:{singleLineProp:"Object/type should be written in a single line"},schema:[_n]},defaultOptions:[{}],create(e,[t]){let n=e.sourceCode,r=t.ignoreTypesWithSuffix??[],l=t.maxProperties??2,f=t.nestedObjMaxLineLength??t.maxLineLength,p=t.nestedObjMaxProperties??3;function i(a){if(a.type===_.AST_NODE_TYPES.ObjectExpression){let s=a.parent.type===_.AST_NODE_TYPES.Property,c=s?p:l,g=a.properties.length;if(g>c)return!1;if(g===1){let S=a.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:s,propsSize:g}}let T=[];for(let S of a.properties){if(S.type===_.AST_NODE_TYPES.Property&&!$e(S.value))return!1;T.push(n.getText(S))}return{text:T.join(", "),isNested:s,propsSize:g}}else{let s=a.parent.parent?.type===_.AST_NODE_TYPES.TSPropertySignature,c=s?p:l,g=a.members.length;if(g>c)return!1;if(r.length>0&&a.parent.type===_.AST_NODE_TYPES.TSTypeAliasDeclaration){let S=a.parent.id.name;if(r.some(d=>S.endsWith(d)))return!1}if(g===1){let S=a.members[0];return S.type===_.AST_NODE_TYPES.TSPropertySignature&&S.typeAnnotation?.typeAnnotation.type===_.AST_NODE_TYPES.TSTypeLiteral?!1:{text:n.getText(S),isNested:s,propsSize:1}}if(a.parent.type===_.AST_NODE_TYPES.TSIntersectionType||a.parent.type===_.AST_NODE_TYPES.TSUnionType)return!1;let T=[];for(let S of a.members){if(S.type!==_.AST_NODE_TYPES.TSPropertySignature)return!1;let d=S.typeAnnotation?.typeAnnotation;if(!d||d.type===_.AST_NODE_TYPES.TSTypeLiteral||!St(d))return!1;if(d.type===_.AST_NODE_TYPES.TSTypeReference&&d.typeArguments){if(d.typeArguments.params.length>1)return!1;let y=d.typeArguments.params[0];if(!St(y))return!1}let b=n.getText(S).trim();(b.endsWith(";")||b.endsWith(","))&&(b=b.slice(0,-1)),T.push(b)}return{text:T.join("; "),isNested:s,propsSize:g}}}function o(a){if(a.loc.start.line===a.loc.end.line)return;if(a.parent.type!==_.AST_NODE_TYPES.JSXExpressionContainer){let d=0,b=n.getTokenAfter(a,{filter:y=>y.type!==_.AST_TOKEN_TYPES.Punctuator?!0:y.value===","||y.value===";"||y.value===")"||y.value==="}"?(d++,!1):!0});if(d>4||b?.loc.start.line===a.loc.end.line)return}let s=i(a);if(!s)return;let c=s.text;if(c.includes(`
|
|
2
|
+
`)||n.getCommentsInside(a).length>0)return;c.endsWith(";")&&(c=c.slice(0,-1));let g=`{ ${c} }`,T=$n(n,a),S=s.isNested&&s.propsSize>2?f:t.maxLineLength;S&&g.length+T.length+Ln(a,n)>S||e.report({node:a,messageId:"singleLineProp",fix:d=>d.replaceText(a,g)})}return{TSTypeLiteral:o,ObjectExpression:o}}});function St(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 Ln(e,t){let n=t.getLastToken(e);if(!n)return 0;let r=t.text.indexOf(`
|
|
3
|
+
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function $n(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Fe={name:Et,rule:Dn};var Fn=/eslint +react-compiler\/react-compiler: +\["error/,xt={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"?y=>n(y):y=>e.sourceCode.getText(y),r=typeof e.getScope=="function"?()=>r():y=>e.sourceCode.getScope(y),l=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,f=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,p={additionalHooks:l,enableDangerousAutofixThisMayCauseInfiniteLoops:f};function i(y){f&&Array.isArray(y.suggest)&&y.suggest.length>0&&(y.fix=y.suggest[0].fix),e.report(y)}let o=e.getSourceCode().scopeManager,a=new WeakMap,s=new WeakSet,c=new WeakMap,g=new WeakMap,T=new WeakSet;function S(y,N){return function(v){if(N.has(v))return N.get(v);let h=y(v);return N.set(v,h),h}}function d(y,N,v,h,w){w&&y.async&&i({node:y,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 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&&(Me(_.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(Wn(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=_.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)&&!st(O.resolved))return!1}return!0}let st=S(W,c),an=S(X,g),ot=new Map;function ln(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;at(R);function at(u){for(let m of u.references){if(!m.resolved||!k.has(m.resolved.scope))continue;let E=Me(y,m.identifier),x=xt(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"&&ln(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===y.parent)&&C.type!=="TypeParameter")if(B.has(I))B.get(I).references.push(m);else{let O=m.resolved,P=st(O)||an(O);B.set(I,{isStable:P,references:[m]})}}for(let m of u.childScopes)at(m)}ot.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 cn(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&&cn(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}=Fe({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=!_.through.some(I=>I.identifier===E);ue.push({key:m,node:u}),x||fe.add(m)});let{suggestedDependencies:pn,unnecessaryDependencies:ye,missingDependencies:ne,duplicateDependencies:lt}=Fe({dependencies:B,declaredDependencies:ue,stableDependencies:de,externalDependencies:fe,isEffect:w}),ge=pn;if(lt.size+ne.size+ye.size===0){if(t)return;Fn({declaredDependencies:ue,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}`,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}`,ct;E&&m.type==="Variable"&&x==="function"&&(ct=[{desc:`Wrap the ${C} of '${m.name.name}' in its own ${I}() Hook.`,fix(pt){let[fn,mn]=I==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[pt.insertTextBefore(m.node.init,fn),pt.insertTextAfter(m.node.init,mn)]}}]),i({node:m.node,message:Z,suggest:ct})});return}!w&&ne.size>0&&(ge=Fe({dependencies:B,declaredDependencies:[],stableDependencies:de,externalDependencies:fe,isEffect:w}).suggestedDependencies);function un(){if(ue.length===0)return!0;let u=ue.map(E=>E.key),m=u.slice().sort();return u.join(",")===m.join(",")}un()&&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")+": "+Mn(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=Me(_.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=_.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!==_.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(lt,"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=jn(y.callee,p);if(N===-1)return;let v=y.arguments[N],h=y.callee,w=Ct(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 _=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 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(_){return _.replaceText(R,`[${v.name}]`)}}]})}}if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let y of e.sourceCode.getAllComments())if($n.test(y.value))return t=!0,{CallExpression:N=>b(N,!0)}}return{CallExpression:y=>b(y)}}};function Fe({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 Fn({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&&!It(t,a.identifier))return!0}return!1}return l.map(([p,i])=>({construction:p.defs[0],depType:i,isUsedOutsideOfHook:f(p)}))}function xt(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)?xt(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function je(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 je(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 je(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 je(n,t,f),f}else throw new Error(`Unsupported node type: ${e.type}`)}function Ct(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function jn(e,t){let n=Ct(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 Me(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Un(r,t))return r;if(It(r,t))for(let[l,f]of Object.entries(r))l!=="parent"&&(Et(f)?(f.parent=r,n.push(f)):Array.isArray(f)&&f.forEach(p=>{Et(p)&&(p.parent=r,n.push(p))}))}return null}function Mn(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 Et(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Un(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 It(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function Wn(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}`),wt="improved-no-unnecessary-condition",Vn=j({}),Yn=["string","number","bigint","boolean","symbol","undefined","object","function","never"],zn=new Set(Yn),Ue={name:wt,rule:Hn({name:wt,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:[Vn]},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||!Bn(s,zn))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 Bn(e,t){return t.has(e)}var Ee=require("@typescript-eslint/utils");var qn=Ee.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Rt="no-call-with-explicit-generics",Kn=j({functions:V(F())}),Xn=qn({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:[Kn]},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}})}}}}),We={name:Rt,rule:Xn};var se=require("@typescript-eslint/utils"),Jn=se.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),vt="no-call-with-inferred-generics",Gn=Jn({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: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:vt,rule:Gn};var me=require("@typescript-eslint/utils"),Zn=me.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),kt="no-commented-out-code",Qn=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],er=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],tr=Zn({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 l of Qn)if(r.startsWith(l))return{wrongPattern:l};for(let l of er)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}})}}}}}),Ve={name:kt,rule:tr};var be=require("@typescript-eslint/utils"),nr=be.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),At="no-default-export",rr=nr({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===be.TSESTree.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),Ye={name:At,rule:rr};var Ot=require("@typescript-eslint/utils"),ir=Ot.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Pt="no-leaked-text-in-jsx",sr=[",",";","[","]","(",")"],or=ir({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="";sr.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),ze={name:Pt,rule:or};var ee=require("@typescript-eslint/utils"),ar=ee.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),_t="no-non-camel-case-functions",lr=/^[a-z][a-zA-Z0-9]*$/;function Nt(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 cr=ar({name:_t,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&&!lr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ee.AST_NODE_TYPES.TSTypeReference?Nt(n):n.type===ee.AST_NODE_TYPES.TSUnionType&&n.types.some(l=>l.type===ee.AST_NODE_TYPES.TSTypeReference&&Nt(l))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),Be={name:_t,rule:cr};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*qe(e){yield e,e.parent&&(yield*qe(e.parent))}var pr=M.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Dt="no-optional-root-props",ur=pr({name:Dt,meta:{type:"problem",docs:{description:"Prevents usage of optional properties at the root of a type if that type is a local type alias or interface referenced only once"},messages:{optionalNotAllowed:'Optional property "{{ propertyName }}" is not allowed on a local type used only once. Use `prop: undefined | ...` instead.',suggestion:"Use `prop: undefined | ...` instead."},hasSuggestions:!0,schema:[]},defaultOptions:[],create(e){function t(r){let 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 qe(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 Ke={name:Dt,rule:ur};var Lt=require("@typescript-eslint/utils"),Ie=Pe(require("path"));var fr=Lt.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="no-relative-imports",mr=j({find:F(),replacement:F()}),dr=j({aliases:V(mr),rootDir:$(F()),allowNotFoundAliases:$(oe()),_dev_simulateFileName:$(F())}),yr=fr({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:[dr]},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})}}}}),Xe={name:$t,rule:yr};var te=require("@typescript-eslint/utils");var Je=Pe(require("typescript")),gr=te.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ft="no-unnecessary-casting",hr=j({additionalCastFunctions:$(V(j({name:F(),expectedType:Te(["string","number"])})))}),Ge={name:Ft,rule:gr({name:Ft,meta:{type:"suggestion",docs:{description:"Prevents unnecessary Number and String castings"},messages:{unnecessaryNumberCasting:"Unnecessary Number() casting on a value already of number type",unnecessaryStringCasting:"Unnecessary String() casting on a value already of string type",unnecessaryCustomCasting:"Unnecessary {{name}}() casting on a value already of {{type}} type"},schema:[hr],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],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&Je.TypeFlags.NumberLike):!!(s.flags&Je.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 Tr=L.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function jt(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 Mt(e,...t){for(let n of t)e.set(...n);return e}var Sr=j({forceCheckOnFCPropTypesWithName:$(V(F()))}),Ut="no-unused-type-props-in-args",Ze=null,Er=Tr({name:Ut,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:[Sr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!Ze&&(Ze=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&&Ze?.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){Mt(a,...jt(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)Mt(a,...jt(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)}}}}),Qe={name:Ut,rule:Er};var pe=require("@typescript-eslint/utils"),br=pe.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ht="prefer-named-functions",Wt=new Map,xr=br({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=Wt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),Wt.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)}`)}]})}}}}}),et={name:Ht,rule:xr};var U=require("@typescript-eslint/utils");var Cr=U.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Yt="prefer-single-line-if",Ir=j({maxLineLength:$(J()),maxNonSimpleConditionLength:$(J())}),wr=Cr({name:Yt,meta:{type:"suggestion",fixable:"code",docs:{description:"Enforce single-line if in simple if statements"},messages:{noSingleLineCurly:"If return statement with single statement body should be written in a single line"},schema:[Ir]},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(!Bt(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=Vt(r.test);if(!c&&r.test.type===U.AST_NODE_TYPES.UnaryExpression&&r.test.operator==="!"){let g=r.test.argument;Vt(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=Rr(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 Vt(e){return e.type===U.AST_NODE_TYPES.CallExpression||e.type===U.AST_NODE_TYPES.BinaryExpression||e.type===U.AST_NODE_TYPES.MemberExpression&&zt(e)}function zt(e){return e.object.type===U.AST_NODE_TYPES.MemberExpression?zt(e.object):e.object.type!==U.AST_NODE_TYPES.Identifier}function Rr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function Bt(e){if(!e.argument)return!0;let t=e.argument;return t.type===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?Bt(t):!1}var tt={name:Yt,rule:wr};var z=require("@typescript-eslint/utils");var vr=z.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),qt="react-compiler-migration",kr=j({disallowHooks:$(V(j({name:F(),replacement:F()}))),disallowMethods:$(V(j({name:F(),replacement:$(F()),requireTrueProp:$(F())})))}),Ar=/eslint +react-compiler\/react-compiler: +\["error/;function Or(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 Pr=vr({name:qt,meta:{type:"suggestion",fixable:"code",docs:{description:"Rules to help migrate to the new React compiler"},messages:{disallowedFunctionOrMethod:"{{functionOrMethod}} is not supported in react compiler. Use {{replacement}} instead.",replace:"Replace with safe alternative {{replacement}}",disallowedMethodWithMissingRequireTrueProp:"{{method}} is should have a prop named {{requireTrueProp}} set to true when used in react compiler."},hasSuggestions:!0,schema:[kr]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(Ar.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&&Or(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)}]})}}}}}}:{}}}),nt={name:qt,rule:Pr};var we=require("@typescript-eslint/utils"),Nr=we.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Kt="require-description",_r=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Dr=/^eslint-disable-(next-)?line$/u,Lr=Nr({name:Kt,meta:{type:"problem",docs:{description:"Require descriptions for eslint directives."},messages:{missingDescription:"Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary."},schema:[{type:"object",properties:{ignore:{type:"array",items:{type:"string",enum:["eslint","eslint-disable","eslint-disable-line","eslint-disable-next-line","eslint-enable","eslint-env","exported","global","globals"]},additionalItems:!1,uniqueItems:!0}},additionalProperties:!1}]},defaultOptions:[{ignore:[]}],create(e,[t]){let n=e.sourceCode,r=new Set(t.ignore||[]);return{Program(){for(let l of n.getAllComments()){let f=$r(l);f!=null&&(r.has(f.kind)||f.description||e.report({loc:jr(l.loc),messageId:"missingDescription"}))}}}}}),Xt={name:Kt,rule:Lr};function $r(e){let{text:t,description:n}=Fr(e.value);if(!t)return null;let r=_r.exec(t);if(!r)return null;let l=r[1];if(!l)return null;let f=Dr.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 Fr(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function jr(e){return{start:{line:e.start.line,column:-1},end:e.end}}function Zt(e){return/^use[A-Z0-9]/.test(e)}function Re(e){return e.type==="Identifier"?Zt(e.name):e.type==="MemberExpression"&&!e.computed&&Re(e.property)?e.object.type==="Identifier":!1}function Qt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function en(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function tn(e){return!!(e.parent&&e.parent.callee&&en(e.parent.callee,"forwardRef"))}function nn(e){return!!(e.parent&&e.parent.callee&&en(e.parent.callee,"memo"))}function rt(e){for(;e;){let t=sn(e);if(t&&(Qt(t)||Re(t))||tn(e)||nn(e))return!0;e=e.parent}return!1}function Jt(e){return!1}function it(e){return!1}var Mr=/eslint +react-compiler\/react-compiler: +\["error/,rn={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"},schema:[{type:"object",ignoreIfReactCompilerIsEnabled:!1,properties:{ignoreIfReactCompilerIsEnabled:{type:"boolean"}}}]},create(e){if(e.options[0]?.ignoreIfReactCompilerIsEnabled){for(let o of e.sourceCode.getAllComments())if(Mr.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&&Jt(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=[..._],W=A.slice(A.indexOf(h.id)+1);for(let X of W)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(_),W=A.slice(A.indexOf(h.id)+1);for(let X of W)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=sn(a),y=rt(a),N=b?Qt(b)||Re(b):tn(a)||nn(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(_&&!it(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&&!it(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&&!it(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"&&Zt(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=Gt(l),s=Gt(f),c=a.get(s);c||(c=[],a.set(s,c)),c.push(o.callee)}o.callee.type==="Identifier"&&(o.callee.name==="useEffect"||Jt(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){rt(o)&&i(n(o))},ArrowFunctionExpression(o){rt(o)&&i(n(o))}}}};function sn(e){return e.type==="FunctionDeclaration"||e.type==="FunctionExpression"&&e.id?e.id:e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"?e.parent.type==="VariableDeclarator"&&e.parent.init===e?e.parent.id:e.parent.type==="AssignmentExpression"&&e.parent.right===e&&e.parent.operator==="="?e.parent.left:e.parent.type==="Property"&&e.parent.value===e&&!e.parent.computed?e.parent.key:e.parent.type==="AssignmentPattern"&&e.parent.right===e&&!e.parent.computed?e.parent.left:void 0:void 0}function Gt(e){return e[e.length-1]}var on={[Qe.name]:Qe.rule,[Ve.name]:Ve.rule,[He.name]:He.rule,"rules-of-hooks":rn,"exhaustive-deps":bt,"require-description":Xt.rule,[Ye.name]:Ye.rule,[Be.name]:Be.rule,[et.name]:et.rule,[Le.name]:Le.rule,[We.name]:We.rule,[Xe.name]:Xe.rule,[tt.name]:tt.rule,[Ke.name]:Ke.rule,[ze.name]:ze.rule,[$e.name]:$e.rule,[nt.name]:nt.rule,[De.name]:De.rule,[Ue.name]:Ue.rule,[Ge.name]:Ge.rule};var Ur={rules:on};0&&(module.exports={extendedLintPlugin});
|
|
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});
|
package/dist/extended-lint.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{AST_NODE_TYPES as
|
|
2
|
-
`)||n.getCommentsInside(a).length>0)return;c.endsWith(";")&&(c=c.slice(0,-1));let g=`{ ${c} }`,T=
|
|
3
|
-
`,n.range[1]);return(r!==-1?r:t.text.length)-n.range[1]}function
|
|
1
|
+
import{AST_NODE_TYPES as H,ESLintUtils as pn}from"@typescript-eslint/utils";var Ce=Symbol.for("optional");function D(e){return{...e,[Ce]:!0}}function fe(e,t){return{enum:e,...t}}function ne(e){return{...e,type:"boolean"}}function L(e){return{...e,type:"string"}}function J(e){return{...e,type:"number"}}function ot(e){return{...e,type:"integer"}}function V(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,l=[];for(r in e)e[r][Ce]?e[r][Ce]=void 0:l.push(r);l.length>0&&(n.required=l)}return n}function Ie(...e){return{anyOf:e}}var un=pn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),lt="react-compiler-extra",fn=$({runOnlyWithEnableCompilerDirective:D(ne())}),mn=/eslint +react-compiler\/react-compiler: +\["error/;function dn(e){return e.type===H.Identifier?e.name.startsWith("use"):e.type===H.MemberExpression&&e.property.type===H.Identifier?e.property.name.startsWith("use"):!1}var yn=/\bthis[.[]/;function at(e){return yn.test(e)}var gn=un({name:lt,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 f of e.sourceCode.getAllComments())if(mn.test(f.value)){n=!0;break}if(!n)return{}}function r(f){for(let p of f.properties)if(p.type===H.Property&&p.method&&p.value.type===H.FunctionExpression){let i=e.sourceCode,o=i.getText(p.key),a=p.value,s=i.getText(a.body);if(at(s))e.report({node:p,messageId:"thisKeywordInMethod"});else{let c=a.params.map(T=>i.getText(T)).join(", "),g="";a.generator?g=`${o}: function* (${c}) ${s}`:g=`${o}: (${c}) => ${s}`,e.report({node:p,messageId:"objectMethodIsNotSupported",fix:T=>T.replaceText(p,g)})}}}function l(f){for(let p of f.properties)if(p.type===H.Property&&p.value.type===H.ObjectExpression){for(let i of p.value.properties)if(i.type===H.Property&&i.method&&i.value.type===H.FunctionExpression){let a=e.sourceCode.getText(i.value.body);at(a)&&e.report({node:i,messageId:"thisKeywordInMethod"})}}}return{CallExpression(f){if(dn(f.callee))for(let p of f.arguments){if(p.type===H.ObjectExpression&&(r(p),l(p)),p.type===H.ArrowFunctionExpression&&(p.body.type===H.ObjectExpression&&(r(p.body),l(p.body)),p.body.type===H.BlockStatement))for(let i of p.body.body)i.type===H.ReturnStatement&&i.argument?.type===H.ObjectExpression&&(r(i.argument),l(i.argument));if(p.type===H.FunctionExpression)for(let i of p.body.body)i.type===H.ReturnStatement&&i.argument?.type===H.ObjectExpression&&(r(i.argument),l(i.argument))}}}}}),we={name:lt,rule:gn};import{AST_NODE_TYPES as Re,ESLintUtils as hn}from"@typescript-eslint/utils";var Tn=hn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Sn=$({disallow:D(V($({selector:L(),message:L(),replace:D(Ie(L(),$({regex:L(),with:L()}))),replaceType:D(fe(["suggestion","autofix"]))}))),__dev_simulateFileName:D(L()),mustMatchSyntax:D(V($({includeRegex:L(),mustCallFn:V($({anyCall:V($({fn:L(),withArgs:V($({atIndex:ot(),literal:Ie(L(),J(),ne())}))})),message:D(L())}))})))}),ut="advanced-no-restricted-syntax",En=Tn({name:ut,meta:{type:"suggestion",docs:{description:"Disallow specific syntax patterns"},schema:[Sn],messages:{default:"{{message}}"},fixable:"code",hasSuggestions:!0},defaultOptions:[{disallow:[]}],create(e,[t]){let n={},{mustMatchSyntax:r,__dev_simulateFileName:l,disallow:f}=t,p=l??e.filename,i=[],o=new Set;for(let{includeRegex:s,mustCallFn:c}of r??[]){let g=bn(p,new RegExp(s));if(!g)continue;let T=S=>{let d=S;for(let{name:b,value:y}of g)d=d.replaceAll(b,y);return d};for(let{anyCall:S,message:d}of c){let b=`Expected file to call the function: ${S.map(({fn:y})=>y).join(" or ")}`;o.add(b),i.push(y=>{let{callee:N}=y;if(N.type===Re.Identifier){for(let{fn:v,withArgs:h}of S)if(N.name===v){o.delete(b);for(let w of h){let R=y.arguments[w.atIndex],k=typeof w.literal=="string"?T(w.literal):w.literal;if(!R){e.report({node:y,messageId:"default",data:{message:`Missing argument with value "${k}" at index ${w.atIndex}${d?`: ${T(d)}`:""}`}});continue}if(R.type!==Re.Literal){e.report({node:R,messageId:"default",data:{message:`Argument at position ${w.atIndex} should the literal "${k}"${d?`: ${T(d)}`:""}`}});continue}R.value!==k&&e.report({node:R,messageId:"default",data:{message:`Argument should have the value "${k}"${d?`: ${T(d)}`:""}`},fix:_=>_.replaceText(R,typeof k=="string"?`'${k}'`:String(k))})}break}}})}}for(let{selector:s,message:c,replace:g,replaceType:T="suggestion"}of f??[]){if(s==="CallExpression"){i.push(S=>{a(g,S,c,T)});continue}n[s]=S=>{a(g,S,c,T)}}return i.length>0&&(n.CallExpression=s=>{if(s.type===Re.CallExpression)for(let c of i)c(s)}),n["Program:exit"]=s=>{for(let c of o)e.report({node:s,messageId:"default",data:{message:`${c}`}})},n;function a(s,c,g,T){let S=d=>{if(!s)return null;if(typeof s=="string")return d.replaceText(c,s);{let b=new RegExp(s.regex),y=e.sourceCode.getText(c);return d.replaceText(c,y.replace(b,s.with))}};e.report({node:c,messageId:"default",data:{message:g},fix:s&&T==="autofix"?S:void 0,suggest:s&&T==="suggestion"?[{messageId:"default",data:{message:`Replace with "${typeof s=="string"?s:s.with}"`},fix:S}]:void 0})}}});function bn(e,t){let n=[],r=t.exec(e);if(!r)return null;let[l,...f]=r;n.push({name:"$0_lowercase",value:l.toLowerCase()}),n.push({name:"$0_capitalize",value:ct(l)}),n.push({name:"$0_uncapitalize",value:pt(l)}),n.push({name:"$0",value:l});for(let p=0;p<f.length;p++){let i=`$${p+1}`,o=f[p];n.push({name:`${i}_lowercase`,value:o.toLowerCase()}),n.push({name:`${i}_capitalize`,value:ct(o)}),n.push({name:`${i}_uncapitalize`,value:pt(o)}),n.push({name:i,value:o})}return n}function ct(e){return e.charAt(0).toUpperCase()+e.slice(1)}function pt(e){return e.charAt(0).toLowerCase()+e.slice(1)}var ve={name:ut,rule:En};import{AST_NODE_TYPES as F,AST_TOKEN_TYPES as xn,ESLintUtils as Cn}from"@typescript-eslint/utils";var In=Cn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),mt="collapse-simple-objs-in-one-line",wn=$({maxLineLength:D(J()),maxProperties:D(J()),nestedObjMaxLineLength:D(J()),nestedObjMaxProperties:D(J()),ignoreTypesWithSuffix:D(V(L()))}),Rn=In({name:mt,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??[],l=t.maxProperties??2,f=t.nestedObjMaxLineLength??t.maxLineLength,p=t.nestedObjMaxProperties??3;function i(a){if(a.type===F.ObjectExpression){let s=a.parent.type===F.Property,c=s?p:l,g=a.properties.length;if(g>c)return!1;if(g===1){let S=a.properties[0];return S.type===F.Property&&S.value.type===F.ObjectExpression||S.type===F.Property&&S.value.type===F.ArrayExpression&&!S.value.elements.every(b=>b&&ke(b))?!1:{text:n.getText(S),isNested:s,propsSize:g}}let T=[];for(let S of a.properties){if(S.type===F.Property&&!ke(S.value))return!1;T.push(n.getText(S))}return{text:T.join(", "),isNested:s,propsSize:g}}else{let s=a.parent.parent?.type===F.TSPropertySignature,c=s?p:l,g=a.members.length;if(g>c)return!1;if(r.length>0&&a.parent.type===F.TSTypeAliasDeclaration){let S=a.parent.id.name;if(r.some(d=>S.endsWith(d)))return!1}if(g===1){let S=a.members[0];return S.type===F.TSPropertySignature&&S.typeAnnotation?.typeAnnotation.type===F.TSTypeLiteral?!1:{text:n.getText(S),isNested:s,propsSize:1}}if(a.parent.type===F.TSIntersectionType||a.parent.type===F.TSUnionType)return!1;let T=[];for(let S of a.members){if(S.type!==F.TSPropertySignature)return!1;let d=S.typeAnnotation?.typeAnnotation;if(!d||d.type===F.TSTypeLiteral||!ft(d))return!1;if(d.type===F.TSTypeReference&&d.typeArguments){if(d.typeArguments.params.length>1)return!1;let y=d.typeArguments.params[0];if(!ft(y))return!1}let b=n.getText(S).trim();(b.endsWith(";")||b.endsWith(","))&&(b=b.slice(0,-1)),T.push(b)}return{text:T.join("; "),isNested:s,propsSize:g}}}function o(a){if(a.loc.start.line===a.loc.end.line)return;if(a.parent.type!==F.JSXExpressionContainer){let d=0,b=n.getTokenAfter(a,{filter:y=>y.type!==xn.Punctuator?!0:y.value===","||y.value===";"||y.value===")"||y.value==="}"?(d++,!1):!0});if(d>4||b?.loc.start.line===a.loc.end.line)return}let s=i(a);if(!s)return;let c=s.text;if(c.includes(`
|
|
2
|
+
`)||n.getCommentsInside(a).length>0)return;c.endsWith(";")&&(c=c.slice(0,-1));let g=`{ ${c} }`,T=kn(n,a),S=s.isNested&&s.propsSize>2?f:t.maxLineLength;S&&g.length+T.length+vn(a,n)>S||e.report({node:a,messageId:"singleLineProp",fix:d=>d.replaceText(a,g)})}return{TSTypeLiteral:o,ObjectExpression:o}}});function ft(e){return e.type===F.TSLiteralType||e.type===F.TSTypeReference||e.type===F.TSNumberKeyword||e.type===F.TSStringKeyword||e.type===F.TSBooleanKeyword||e.type===F.TSNullKeyword||e.type===F.TSUndefinedKeyword}function ke(e,t){return!!(e.type===F.Literal||e.type===F.Identifier||e.type===F.TemplateLiteral||e.type===F.TaggedTemplateExpression||!t&&e.type===F.ArrayExpression&&e.elements.every(n=>n&&ke(n,!0)))}function vn(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 kn(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}var Ae={name:mt,rule:Rn};var An=/eslint +react-compiler\/react-compiler: +\["error/,yt={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"?y=>n(y):y=>e.sourceCode.getText(y),r=typeof e.getScope=="function"?()=>r():y=>e.sourceCode.getScope(y),l=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,f=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,p={additionalHooks:l,enableDangerousAutofixThisMayCauseInfiniteLoops:f};function i(y){f&&Array.isArray(y.suggest)&&y.suggest.length>0&&(y.fix=y.suggest[0].fix),e.report(y)}let o=e.getSourceCode().scopeManager,a=new WeakMap,s=new WeakSet,c=new WeakMap,g=new WeakMap,T=new WeakSet;function S(y,N){return function(v){if(N.has(v))return N.get(v);let h=y(v);return N.set(v,h),h}}function d(y,N,v,h,w){w&&y.async&&i({node:y,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&&(Pe(_.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(_n(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)&&!Qe(O.resolved))return!1}return!0}let Qe=S(U,c),tn=S(X,g),et=new Map;function nn(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;tt(R);function tt(u){for(let m of u.references){if(!m.resolved||!k.has(m.resolved.scope))continue;let E=Pe(y,m.identifier),x=yt(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"&&nn(m)&&et.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=Qe(O)||tn(O);z.set(I,{isStable:P,references:[m]})}}for(let m of u.childScopes)tt(m)}et.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 rn(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&&rn(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}=Ae({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:sn,unnecessaryDependencies:pe,missingDependencies:ee,duplicateDependencies:nt}=Ae({dependencies:z,declaredDependencies:oe,stableDependencies:ce,externalDependencies:ae,isEffect:w}),ue=sn;if(nt.size+ee.size+pe.size===0){if(t)return;An({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}`,rt;E&&m.type==="Variable"&&x==="function"&&(rt=[{desc:`Wrap the ${C} of '${m.name.name}' in its own ${I}() Hook.`,fix(it){let[an,ln]=I==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[it.insertTextBefore(m.node.init,an),it.insertTextAfter(m.node.init,ln)]}}]),i({node:m.node,message:Z,suggest:rt})});return}!w&&ee.size>0&&(ue=Ae({dependencies:z,declaredDependencies:[],stableDependencies:ce,externalDependencies:ae,isEffect:w}).suggestedDependencies);function on(){if(oe.length===0)return!0;let u=oe.map(E=>E.key),m=u.slice().sort();return u.join(",")===m.join(",")}on()&&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")+": "+Pn(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=Pe(_.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(nt,"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=On(y.callee,p);if(N===-1)return;let v=y.arguments[N],h=y.callee,w=gt(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(kn.test(y.value))return t=!0,{CallExpression:N=>b(N,!0)}}return{CallExpression:y=>b(y)}}};function Ae({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 An({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&&!ht(t,a.identifier))return!0}return!1}return l.map(([p,i])=>({construction:p.defs[0],depType:i,isUsedOutsideOfHook:f(p)}))}function yt(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)?yt(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function Oe(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 Oe(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 Oe(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 Oe(n,t,f),f}else throw new Error(`Unsupported node type: ${e.type}`)}function gt(e,t){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function On(e,t){let n=gt(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 Pe(e,t){let n=[e],r=null;for(;n.length;){if(r=n.shift(),Nn(r,t))return r;if(ht(r,t))for(let[l,f]of Object.entries(r))l!=="parent"&&(mt(f)?(f.parent=r,n.push(f)):Array.isArray(f)&&f.forEach(p=>{mt(p)&&(p.parent=r,n.push(p))}))}return null}function Pn(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 mt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Nn(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 ht(e,t){return e.range[0]<=t.range[0]&&e.range[1]>=t.range[1]}function _n(e){return!1}import{AST_NODE_TYPES as de,ESLintUtils as St}from"@typescript-eslint/utils";import Y from"typescript";var Dn=St.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Tt="improved-no-unnecessary-condition",Ln=$({}),$n=["string","number","bigint","boolean","symbol","undefined","object","function","never"],Fn=new Set($n),Ne={name:Tt,rule:Dn({name:Tt,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:[Ln]},defaultOptions:[{}],create(e){let t=St.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||!jn(s,Fn))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 jn(e,t){return t.has(e)}import{AST_NODE_TYPES as Mn,ESLintUtils as Un}from"@typescript-eslint/utils";var Wn=Un.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Et="no-call-with-explicit-generics",Hn=$({functions:H(L())}),Vn=Wn({name:Et,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===Mn.Identifier&&n.has(l.name)&&r.typeArguments&&e.report({node:r,messageId:"noExplicitGenerics",data:{functionName:l.name}})}}}}),_e={name:Et,rule:Vn};import{AST_NODE_TYPES as ye,ESLintUtils as Yn}from"@typescript-eslint/utils";var zn=Yn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),bt="no-call-with-inferred-generics",Bn=zn({name:bt,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}})}}}}),De={name:bt,rule:Bn};import{ESLintUtils as qn,TSESTree as xt}from"@typescript-eslint/utils";var Kn=qn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ct="no-commented-out-code",Xn=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Jn=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],Gn=Kn({name:Ct,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 Xn)if(r.startsWith(l))return{wrongPattern:l};for(let l of Jn)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===xt.AST_TOKEN_TYPES.Line||l.type===xt.AST_TOKEN_TYPES.Block){let f=t(l.value);f&&e.report({node:l,messageId:"commentedOutCode",data:{wrongPattern:f.wrongPattern}})}}}}}),Le={name:Ct,rule:Gn};import{ESLintUtils as Zn,TSESTree as Qn}from"@typescript-eslint/utils";var er=Zn.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),It="no-default-export",tr=er({name:It,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===Qn.AST_NODE_TYPES.Identifier&&n.exported.name==="default"&&e.report({node:t,messageId:"noDefaultExport"})}}}}),$e={name:It,rule:tr};import{ESLintUtils as nr}from"@typescript-eslint/utils";var rr=nr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),wt="no-leaked-text-in-jsx",ir=[",",";","[","]","(",")"],sr=rr({name:wt,meta:{type:"problem",docs:{description:"Prevents leaking of text in JSX that should be wrapped in an expression container"},messages:{leakedTextInJSX:'Text "{{ text }}" should be wrapped in a JSX expression container.'},schema:[],fixable:"code"},defaultOptions:[],create(e){return{JSXText(t){let n=t.value.trim();if(!n)return;let r="";ir.includes(n)?r=n:n.includes("&&")?r="&&":n.includes("||")?r="||":n.endsWith("? (")&&(r="? ("),r&&e.report({node:t,messageId:"leakedTextInJSX",data:{text:r}})}}}}),Fe={name:wt,rule:sr};import{AST_NODE_TYPES as ie,ESLintUtils as or}from"@typescript-eslint/utils";var ar=or.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),vt="no-non-camel-case-functions",lr=/^[a-z][a-zA-Z0-9]*$/;function Rt(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 cr=ar({name:vt,meta:{type:"suggestion",docs:{description:"Enforce camelCase naming convention for function declarations"},schema:[],messages:{nonCamelCaseFunction:'Function name "{{functionName}}" should be in camelCase format. If this fn is a React component and can\'t use the `FC` type, add a explicit "JSX.Element" return type to it'}},defaultOptions:[],create(e){return{FunctionDeclaration(t){if(t.id&&!lr.test(t.id.name)){let n=t.returnType?.typeAnnotation;if(n&&(n.type===ie.TSTypeReference?Rt(n):n.type===ie.TSUnionType&&n.types.some(l=>l.type===ie.TSTypeReference&&Rt(l))))return;e.report({node:t.id,messageId:"nonCamelCaseFunction",data:{functionName:t.id.name}})}}}}}),je={name:vt,rule:cr};import{ESLintUtils as pr,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*Me(e){yield e,e.parent&&(yield*Me(e.parent))}var ur=pr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),kt="no-optional-root-props",fr=ur({name:kt,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 Me(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 Ue={name:kt,rule:fr};import{ESLintUtils as mr}from"@typescript-eslint/utils";import We from"node:path";var dr=mr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),At="no-relative-imports",yr=$({find:L(),replacement:L()}),gr=$({aliases:H(yr),rootDir:D(L()),allowNotFoundAliases:D(ne()),_dev_simulateFileName:D(L())}),hr=dr({name:At,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:[gr]},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=We.dirname(i);return We.resolve(o,p)}function f(p){let i=t.rootDir??process.cwd(),o=We.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:At,rule:hr};import{AST_NODE_TYPES as le,ESLintUtils as Pt}from"@typescript-eslint/utils";import*as Ve from"typescript";var Tr=Pt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ot="no-unnecessary-casting",Sr=$({additionalCastFunctions:D(H($({name:L(),expectedType:fe(["string","number"])})))}),Ye={name:Ot,rule:Tr({name:Ot,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:[Sr],fixable:"code"},defaultOptions:[{}],create(e){let n=e.options[0].additionalCastFunctions||[],r=[{name:"Number",expectedType:"number"},{name:"String",expectedType:"string"},...n],l=Pt.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&Ve.TypeFlags.NumberLike):!!(s.flags&Ve.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 F,ESLintUtils as Er}from"@typescript-eslint/utils";var br=Er.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function Nt(e){let t=[];for(let n of e.members)n.type===F.TSPropertySignature&&n.key.type===F.Identifier&&t.push([n.key.name,n]);return t}function _t(e,...t){for(let n of t)e.set(...n);return e}var xr=$({forceCheckOnFCPropTypesWithName:D(H(L()))}),Dt="no-unused-type-props-in-args",ze=null,Cr=br({name:Dt,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used",missingComponentParam:"Component has declared props but no props are used"},schema:[xr],fixable:"code"},defaultOptions:[{}],create(e,[t]){let{forceCheckOnFCPropTypesWithName:n}=t;n&&!ze&&(ze=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&&ze?.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===F.ExportNamedDeclaration)){if(d?.type===F.TSTypeAliasDeclaration){l(i,o,s,d.typeAnnotation,!0);return}if(d?.type===F.TSInterfaceDeclaration){l(i,o,s,d.body,!0);return}}}function l(i,o,a,s,c){if(s.type===F.TSInterfaceBody){for(let g of s.body)g.type===F.TSPropertySignature&&g.key.type===F.Identifier&&a.set(g.key.name,g);return}if(s.type===F.TSTypeLiteral){_t(a,...Nt(s));return}if(s.type===F.TSIntersectionType){for(let g of s.types)l(i,o,a,g,!0);return}c||s.type===F.TSTypeReference&&s.typeName.type===F.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===F.AssignmentPattern&&s.left.type===F.ObjectPattern&&f(i,o,[s.left])}function p(i,o){let a=[];if(i.properties.at(-1)?.type===F.RestElement)return;for(let T of i.properties)T.type===F.Property&&T.key.type===F.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===F.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===F.Identifier&&o.id.typeAnnotation?.typeAnnotation.type===F.TSTypeReference&&o.id.typeAnnotation.typeAnnotation.typeName.type===F.Identifier&&o.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&o.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===F.TSTypeReference&&s.typeName.type===F.Identifier)r(!0,i,s.typeName,a,!1);else if(s.type===F.TSTypeLiteral)_t(a,...Nt(s));else if(s.type===F.TSIntersectionType)for(let c of s.types)c.type===F.TSTypeReference&&c.typeName.type===F.Identifier?r(!0,i,c.typeName,a,!1):l(!0,i,a,c,!0);if(a.size!==0&&o.init?.type===F.ArrowFunctionExpression){let c=o.init.params[0];if(!c){e.report({node:o.init,messageId:"missingComponentParam"});return}c.type===F.ObjectPattern&&p(c,a)}}},FunctionDeclaration:function(i){f(!1,i,i.params)},ArrowFunctionExpression(i){f(!1,i,i.params)}}}}),Be={name:Dt,rule:Cr};import{AST_NODE_TYPES as qe,ESLintUtils as Ir}from"@typescript-eslint/utils";var wr=Ir.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),$t="prefer-named-functions",Lt=new Map,Rr=wr({name:$t,meta:{hasSuggestions:!0,type:"suggestion",docs:{description:"Prevent using arrow functions when a named function can be used instead"},schema:[{type:"object",properties:{ignoreRegex:{type:"string"},disallowArrowFnWithImplicitReturns:{type:"boolean"}}}],messages:{suggestion:"Convert to named function",default:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}" instead of an arrow function',withIgnoreRegex:'Function {{functionName}} should be defined as a named function "function {{functionName}} () {}", if not possible to use `function` you can also use a name that matches the rule ignore regex'}},defaultOptions:[{}],create(e,[t]){let n=null;if(t.ignoreRegex){let r=Lt.get(t.ignoreRegex);r?n=r:(n=new RegExp(t.ignoreRegex),Lt.set(t.ignoreRegex,n))}return{VariableDeclarator(r){if(r.init&&r.init.type===qe.ArrowFunctionExpression&&r.id.type===qe.Identifier){let l=r.id.name;if(r.id.typeAnnotation||n&&n.test(l)||!t.disallowArrowFnWithImplicitReturns&&r.init.body.type!==qe.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)}`)}]})}}}}}),Ke={name:$t,rule:Rr};import{AST_NODE_TYPES as W,AST_TOKEN_TYPES as Ft,ESLintUtils as vr}from"@typescript-eslint/utils";var kr=vr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Mt="prefer-single-line-if",Ar=$({maxLineLength:D(J()),maxNonSimpleConditionLength:D(J())}),Or=kr({name:Mt,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:[Ar]},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(!Wt(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=jt(r.test);if(!c&&r.test.type===W.UnaryExpression&&r.test.operator==="!"){let g=r.test.argument;jt(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===Ft.Punctuator&&o.value==="}"){let c=n.getTokenAfter(o);if(c&&c.type===Ft.Keyword&&(c.value==="else"||c.value==="catch"))return}let a=Pr(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 jt(e){return e.type===W.CallExpression||e.type===W.BinaryExpression||e.type===W.MemberExpression&&Ut(e)}function Ut(e){return e.object.type===W.MemberExpression?Ut(e.object):e.object.type!==W.Identifier}function Pr(e,t){return e.text.slice(t.range[0]-t.loc.start.column,t.range[0])}function Wt(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?Wt(t):!1}var Xe={name:Mt,rule:Or};import{AST_NODE_TYPES as q,ESLintUtils as Nr}from"@typescript-eslint/utils";var _r=Nr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Ht="react-compiler-migration",Dr=$({disallowHooks:D(H($({name:L(),replacement:L()}))),disallowMethods:D(H($({name:L(),replacement:D(L()),requireTrueProp:D(L())})))}),Lr=/eslint +react-compiler\/react-compiler: +\["error/;function $r(e){return e.type===q.Identifier?e.name.startsWith("use"):e.type===q.MemberExpression&&e.property.type===q.Identifier?e.property.name.startsWith("use"):!1}var Fr=_r({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:[Dr]},defaultOptions:[{}],create(e,[t]){let n=!1;for(let r of e.sourceCode.getAllComments())if(Lr.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&&$r(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)}]})}}}}}}:{}}}),Je={name:Ht,rule:Fr};import{ESLintUtils as jr,TSESTree as Mr}from"@typescript-eslint/utils";var Ur=jr.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Vt="require-description",Wr=/^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u,Hr=/^eslint-disable-(next-)?line$/u,Vr=Ur({name:Vt,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=Yr(l);f!=null&&(r.has(f.kind)||f.description||e.report({loc:Br(l.loc),messageId:"missingDescription"}))}}}}}),Yt={name:Vt,rule:Vr};function Yr(e){let{text:t,description:n}=zr(e.value);if(!t)return null;let r=Wr.exec(t);if(!r)return null;let l=r[1];if(!l)return null;let f=Hr.test(l);if(e.type===Mr.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 zr(e){let t=e.split(/\s-{2,}\s/u);return{text:t[0]?.trim(),description:t.length>1?t[1]?.trim()??null:null}}function Br(e){return{start:{line:e.start.line,column:-1},end:e.end}}function qt(e){return/^use[A-Z0-9]/.test(e)}function Te(e){return e.type==="Identifier"?qt(e.name):e.type==="MemberExpression"&&!e.computed&&Te(e.property)?e.object.type==="Identifier":!1}function Kt(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function Xt(e,t){return e.name===t||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===t}function Jt(e){return!!(e.parent&&e.parent.callee&&Xt(e.parent.callee,"forwardRef"))}function Gt(e){return!!(e.parent&&e.parent.callee&&Xt(e.parent.callee,"memo"))}function Ge(e){for(;e;){let t=Qt(e);if(t&&(Kt(t)||Te(t))||Jt(e)||Gt(e))return!0;e=e.parent}return!1}function zt(e){return!1}function Ze(e){return!1}var qr=/eslint +react-compiler\/react-compiler: +\["error/,Zt={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(qr.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&&zt(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=Qt(a),y=Ge(a),N=b?Kt(b)||Te(b):Jt(a)||Gt(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(_&&!Ze(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&&!Ze(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&&!Ze(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 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=Bt(l),s=Bt(f),c=a.get(s);c||(c=[],a.set(s,c)),c.push(o.callee)}o.callee.type==="Identifier"&&(o.callee.name==="useEffect"||zt(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){Ge(o)&&i(n(o))},ArrowFunctionExpression(o){Ge(o)&&i(n(o))}}}};function Qt(e){return e.type==="FunctionDeclaration"||e.type==="FunctionExpression"&&e.id?e.id:e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"?e.parent.type==="VariableDeclarator"&&e.parent.init===e?e.parent.id:e.parent.type==="AssignmentExpression"&&e.parent.right===e&&e.parent.operator==="="?e.parent.left:e.parent.type==="Property"&&e.parent.value===e&&!e.parent.computed?e.parent.key:e.parent.type==="AssignmentPattern"&&e.parent.right===e&&!e.parent.computed?e.parent.left:void 0:void 0}function Bt(e){return e[e.length-1]}var en={[Be.name]:Be.rule,[Le.name]:Le.rule,[De.name]:De.rule,"rules-of-hooks":Zt,"exhaustive-deps":dt,"require-description":Yt.rule,[$e.name]:$e.rule,[je.name]:je.rule,[Ke.name]:Ke.rule,[ve.name]:ve.rule,[_e.name]:_e.rule,[He.name]:He.rule,[Xe.name]:Xe.rule,[Ue.name]:Ue.rule,[Fe.name]:Fe.rule,[ke.name]:ke.rule,[Je.name]:Je.rule,[we.name]:we.rule,[Ne.name]:Ne.rule,[Ye.name]:Ye.rule};var bs={rules:en};export{bs as extendedLintPlugin};
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/extended-lint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"tsup": "^8.3.6",
|
|
33
33
|
"vite": "^6.0.11",
|
|
34
34
|
"vitest": "^3.0.4",
|
|
35
|
-
"typescript": "^5.
|
|
35
|
+
"typescript": "^5.8.2"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@typescript-eslint/utils": "^8.22.0",
|