@ls-stack/extended-lint 0.1.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/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Extended rules for eslint
2
+
3
+ To use any of these rules, you need to install the package:
4
+
5
+ ```sh
6
+ pnpm add -D @lucasols/eslint-plugin-extended-lint
7
+ ```
8
+
9
+ And then configure it in your eslint config:
10
+
11
+ ```json
12
+ {
13
+ "plugins": ["@lucasols/extended-lint"],
14
+ "rules": {
15
+ "@lucasols/extended-lint/no-unused-type-props-in-args": "error"
16
+ }
17
+ }
18
+ ```
19
+
20
+ ## `no-unused-type-props-in-args`
21
+
22
+ Checks if there are unused type props in function arguments.
23
+
24
+ Examples
25
+
26
+ Bad
27
+
28
+ ```ts
29
+ function foo({ a }: { a: string; b: string }) {
30
+ /* ^ b is declared but not used in the function */
31
+ // ...
32
+ }
33
+ ```
34
+
35
+ Good
36
+
37
+ ```ts
38
+ function foo({ a, b }: { a: string; b: string }) {
39
+ // ...
40
+ }
41
+ ```
42
+
43
+ It will also work with the react `FC` type:
44
+
45
+ Bad
46
+
47
+ ```ts
48
+ const Foo: FC<{ a: string; b: string }> = ({ a }) => {
49
+ /* ^ b is declared but not used in the component */
50
+ // ...
51
+ }
52
+ ```
53
+
54
+ Good
55
+
56
+ ```
57
+ const Foo: FC<{ a: string; b: string }> = ({ a, b }) => {
58
+ // ...
59
+ }
60
+ ```
61
+
62
+ - This rule will not work in all situations, as it does not checks all possible usages of referenced types.
63
+
64
+ ## `no-commented-out-code`
65
+
66
+ Checks if there are commented code. Block comments are ignored.
67
+
68
+ Examples
69
+
70
+ Bad:
71
+
72
+ ```ts
73
+ // function foo() {
74
+ // // ...
75
+ // }
76
+ ```
77
+
78
+ Good:
79
+
80
+ ```ts
81
+ /*
82
+ function foo() {
83
+ // ...
84
+ }
85
+ */
86
+ ```
87
+
88
+ - This rule will not detect all possible commented code, and can give false negatives.
89
+
90
+ ## `no-call-with-infered-generics`
91
+
92
+ This rule disallows calling functions with inferred generics.
93
+
94
+ The rule options types are as follows:
95
+
96
+ ````ts
97
+ type Options = [
98
+ {
99
+ functions: Array<{
100
+ name: string;
101
+ minGenerics?: number;
102
+ allowAny?: boolean;
103
+ disallowTypes?: string[];
104
+ }>;
105
+ anyAliases?: string[];
106
+ }
107
+ ];
108
+
109
+ Examples:
110
+
111
+ Bad:
112
+
113
+ ```ts
114
+ // @typescript-eslint/no-call-with-inferred-generics: ["error", { functions: ["foo"] }]
115
+
116
+ function foo<T>(arg: T) {
117
+ // ...
118
+ }
119
+
120
+ foo('bar') // Error: Generics must be defined explicitly
121
+ foo<any>('bar') // Error: 'any' is not allowed in generics
122
+ ````
123
+
124
+ Good:
125
+
126
+ ```ts
127
+ // @typescript-eslint/no-call-with-inferred-generics: ["error", { functions: ["foo"] }]
128
+ function foo<T>(arg: T) {
129
+ // ...
130
+ }
131
+
132
+ foo<string>('bar') // OK
133
+ ```
134
+
135
+ ## `rules-of-hooks`
136
+
137
+ A fork of the `eslint-plugin-react-hooks` `rules-of-hooks` rule, but with the following changes:
138
+
139
+ - Identifies hooks in camelCase namespaced functions (e.g. `test.useFoo()`)
@@ -0,0 +1,5 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const extendedLintPlugin: TSESLint.FlatConfig.Config;
4
+
5
+ export { extendedLintPlugin };
@@ -0,0 +1,5 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+
3
+ declare const extendedLintPlugin: TSESLint.FlatConfig.Config;
4
+
5
+ export { extendedLintPlugin };
@@ -0,0 +1,12 @@
1
+ "use strict";var ne=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Xe=(e,n)=>{for(var i in n)ne(e,i,{get:n[i],enumerable:!0})},Ke=(e,n,i,m)=>{if(n&&typeof n=="object"||typeof n=="function")for(let y of Be(n))!Ge.call(e,y)&&y!==i&&ne(e,y,{get:()=>n[y],enumerable:!(m=ze(n,y))||m.enumerable});return e};var Ne=e=>Ke(ne({},"__esModule",{value:!0}),e);var lt={};Xe(lt,{extendedLintPlugin:()=>ct});module.exports=Ne(lt);var ge={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,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let n=typeof e.getSource=="function"?g=>n(g):g=>e.sourceCode.getText(g),i=typeof e.getScope=="function"?()=>i():g=>e.sourceCode.getScope(g),m=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,y=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,f={additionalHooks:m,enableDangerousAutofixThisMayCauseInfiniteLoops:y};function l(g){y&&Array.isArray(g.suggest)&&g.suggest.length>0&&(g.fix=g.suggest[0].fix),e.report(g)}let p=e.getSourceCode().scopeManager,s=new WeakMap,a=new WeakSet,w=new WeakMap,R=new WeakMap,D=new WeakSet;function O(g,v){return function(k){if(v.has(k))return v.get(k);let I=g(k);return v.set(k,I),I}}function P(g,v,k,I,o){o&&g.async&&l({node:g,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
2
+
3
+ useEffect(() => {
4
+ async function fetchData() {
5
+ // You can await here
6
+ const response = await MyAPI.getData(someId);
7
+ // ...
8
+ }
9
+ fetchData();
10
+ }, [someId]); // Or [] if effect doesn't need props or state
11
+
12
+ Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=p.acquire(g),C=new Set,S=null;{let t=x.upper;for(;t&&(C.add(t),t.type!=="function");)t=t.upper;if(!t)return;S=t}let M=Array.isArray;function E(t){if(!M(t.defs))return!1;let r=t.defs[0];if(r==null||r.node.type!=="VariableDeclarator")return!1;let c=r.node.init;if(c==null)return!1;for(;c.type==="TSAsExpression";)c=c.expression;let u=r.node.parent;if(u==null&&(ie(S.block,r.node.id),u=r.node.parent,u==null))return!1;if(u.kind==="const"&&c.type==="Literal"&&(typeof c.value=="string"||typeof c.value=="number"||c.value===null))return!0;if(c.type!=="CallExpression")return!1;let h=c.callee;if(h.type==="MemberExpression"&&h.object.name==="React"&&h.property!=null&&!h.computed&&(h=h.property),h.type!=="Identifier")return!1;let d=r.node.id,{name:b}=h;if(b==="useRef"&&d.type==="Identifier")return!0;if(Qe(h)&&d.type==="Identifier"){for(let T of t.references)T!==d&&D.add(T.identifier);return!0}else if(b==="useState"||b==="useReducer"){if(d.type==="ArrayPattern"&&d.elements.length===2&&M(t.identifiers)){if(d.elements[1]===t.identifiers[0]){if(b==="useState"){let T=t.references,j=0;for(let _=0;_<T.length;_++){if(T[_].isWrite()&&j++,j>1)return!1;s.set(T[_].identifier,d.elements[0])}}return!0}else if(d.elements[0]===t.identifiers[0]){if(b==="useState"){let T=t.references;for(let j=0;j<T.length;j++)a.add(T[j].identifier)}return!1}}}else if(b==="useTransition"&&d.type==="ArrayPattern"&&d.elements.length===2&&Array.isArray(t.identifiers)&&d.elements[1]===t.identifiers[0])return!0;return!1}function H(t){if(!M(t.defs))return!1;let r=t.defs[0];if(r==null||r.node==null||r.node.id==null)return!1;let c=r.node,u=S.childScopes,h=null,d;for(d=0;d<u.length;d++){let b=u[d],T=b.block;if(c.type==="FunctionDeclaration"&&T===c||c.type==="VariableDeclarator"&&T.parent===c){h=b;break}}if(h==null)return!1;for(d=0;d<h.through.length;d++){let b=h.through[d];if(b.resolved!=null&&C.has(b.resolved.scope)&&!L(b.resolved))return!1}return!0}let L=O(E,w),Fe=O(H,R),ue=new Map;function je(t){let r=t.from,c=!1;for(;r.block!==g;)r.type==="function"&&(c=r.block.parent!=null&&r.block.parent.type==="ReturnStatement"),r=r.upper;return c}let F=new Map,Z=new Map;pe(x);function pe(t){for(let r of t.references){if(!r.resolved||!C.has(r.resolved.scope))continue;let c=ie(g,r.identifier),u=be(c),h=U(u,Z);if(o&&u.type==="Identifier"&&(u.parent.type==="MemberExpression"||u.parent.type==="OptionalMemberExpression")&&!u.parent.computed&&u.parent.property.type==="Identifier"&&u.parent.property.name==="current"&&je(r)&&ue.set(h,{reference:r,dependencyNode:u}),u.parent.type==="TSTypeQuery"||u.parent.type==="TSTypeReference")continue;let d=r.resolved.defs[0];if(d!=null&&!(d.node!=null&&d.node.init===g.parent)&&d.type!=="TypeParameter")if(F.has(h))F.get(h).references.push(r);else{let b=r.resolved,T=L(b)||Fe(b);F.set(h,{isStable:T,references:[r]})}}for(let r of t.childScopes)pe(r)}ue.forEach(({reference:t,dependencyNode:r},c)=>{let u=t.resolved.references,h=!1;for(let d=0;d<u.length;d++){let{identifier:b}=u[d],{parent:T}=b;if(T!=null&&T.type==="MemberExpression"&&!T.computed&&T.property.type==="Identifier"&&T.property.name==="current"&&T.parent.type==="AssignmentExpression"&&T.parent.left===T){h=!0;break}}h||l({node:r.parent.property,message:`The ref value '${c}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${c}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Q=new Set;function Le(t,r){Q.has(r)||(Q.add(r),l({node:t,message:`Assignments to the '${r}' variable from inside React Hook ${n(k)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(k)}.`}))}let N=new Set;if(F.forEach(({isStable:t,references:r},c)=>{t&&N.add(c),r.forEach(u=>{u.writeExpr&&Le(u.writeExpr,c)})}),Q.size>0)return;if(!v){let t=null;if(F.forEach(({isStable:r,references:c},u)=>{t||c.forEach(h=>{if(t)return;let d=h.identifier;if(!s.has(d))return;let T=h.from;for(;T.type!=="function";)T=T.upper;T.block===g&&(t=u)})}),t){let{suggestedDependencies:r}=re({dependencies:F,declaredDependencies:[],stableDependencies:N,externalDependencies:new Set,isEffect:!0});l({node:k,message:`React Hook ${I} contains a call to '${t}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+r.join(", ")+`] as a second argument to the ${I} Hook.`,suggest:[{desc:`Add dependencies array: [${r.join(", ")}]`,fix(c){return c.insertTextAfter(g,`, [${r.join(", ")}]`)}}]})}return}let G=[],X=new Set;v.type!=="ArrayExpression"?l({node:v,message:`React Hook ${n(k)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):v.elements.forEach(t=>{if(t===null)return;if(t.type==="SpreadElement"){l({node:t,message:`React Hook ${n(k)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}D.has(t)&&l({node:t,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(t)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(t)}\``,fix(h){return h.removeRange(t.range)}}]});let r;try{r=U(t,Z)}catch(h){if(/Unsupported node type/.test(h.message)){t.type==="Literal"?F.has(t.value)?l({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. Did you mean to include ${t.value} in the array instead?`}):l({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:t,message:`React Hook ${n(k)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw h}let c=t;for(;c.type==="MemberExpression"||c.type==="OptionalMemberExpression"||c.type==="ChainExpression";)c=c.object||c.expression.object;let u=!S.through.some(h=>h.identifier===c);G.push({key:r,node:t}),u||X.add(r)});let{suggestedDependencies:We,unnecessaryDependencies:Y,missingDependencies:V,duplicateDependencies:de}=re({dependencies:F,declaredDependencies:G,stableDependencies:N,externalDependencies:X,isEffect:o}),q=We;if(de.size+V.size+Y.size===0){Ye({declaredDependencies:G,declaredDependenciesNode:v,componentScope:S,scope:x}).forEach(({construction:r,isUsedOutsideOfHook:c,depType:u})=>{let h=u==="function"?"useCallback":"useMemo",d=u==="function"?"definition":"initialization",b=`wrap the ${d} of '${r.name.name}' in its own ${h}() Hook.`,T=c?`To fix this, ${b}`:`Move it inside the ${I} callback. Alternatively, ${b}`,j=u==="conditional"||u==="logical expression"?"could make":"makes",_=`The '${r.name.name}' ${u} ${j} the dependencies of ${I} Hook (at line ${v.loc.start.line}) change on every render. ${T}`,me;c&&r.type==="Variable"&&u==="function"&&(me=[{desc:`Wrap the ${d} of '${r.name.name}' in its own ${h}() Hook.`,fix(ye){let[Ue,Ve]=h==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[ye.insertTextBefore(r.node.init,Ue),ye.insertTextAfter(r.node.init,Ve)]}}]),l({node:r.node,message:_,suggest:me})});return}!o&&V.size>0&&(q=re({dependencies:F,declaredDependencies:[],stableDependencies:N,externalDependencies:X,isEffect:o}).suggestedDependencies);function _e(){if(G.length===0)return!0;let t=G.map(c=>c.key),r=t.slice().sort();return t.join(",")===r.join(",")}_e()&&q.sort();function ee(t){let r=t.split("."),c="";for(let u=0;u<r.length;u++){if(u!==0){let h=r.slice(0,u+1).join("."),d=Z.get(h)===!0;c+=d?"?.":"."}c+=r[u]}return c}function te(t,r,c,u){return t.size===0?null:(t.size>1?"":r+" ")+c+" "+(t.size>1?"dependencies":"dependency")+": "+Je(Array.from(t).sort().map(h=>"'"+ee(h)+"'"))+`. Either ${u} ${t.size>1?"them":"it"} or remove the dependency array.`}let W="";if(Y.size>0){let t=null;if(Array.from(Y.keys()).forEach(r=>{t===null&&r.endsWith(".current")&&(t=r)}),t!==null)W=` Mutable values like '${t}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(X.size>0){let r=Array.from(X)[0];x.set.has(r)||(W=` Outer scope values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!W&&V.has("props")){let t=F.get("props");if(t==null)return;let r=t.references;if(!Array.isArray(r))return;let c=!0;for(let u=0;u<r.length;u++){let h=r[u],d=ie(S.block,h.identifier);if(!d){c=!1;break}let b=d.parent;if(b==null){c=!1;break}if(b.type!=="MemberExpression"&&b.type!=="OptionalMemberExpression"){c=!1;break}}c&&(W=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${I} call and refer to those specific props inside ${n(k)}.`)}if(!W&&V.size>0){let t=null;V.forEach(r=>{if(t)return;let c=S.set.get(r),u=F.get(r);if(u.references[0].resolved!==c)return;let h=c.defs[0];if(h==null||h.name==null||h.type!=="Parameter")return;let d=!1,b;for(let T=0;T<u.references.length;T++)if(b=u.references[T].identifier,b!=null&&b.parent!=null&&(b.parent.type==="CallExpression"||b.parent.type==="OptionalCallExpression")&&b.parent.callee===b){d=!0;break}d&&(t=r)}),t!==null&&(W=` If '${t}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!W&&V.size>0){let t=null;if(V.forEach(r=>{if(t!==null)return;let u=F.get(r).references,h,d;for(let b=0;b<u.length;b++){for(h=u[b].identifier,d=h.parent;d!=null&&d!==S.block;){if(d.type==="CallExpression"){let T=s.get(d.callee);if(T!=null){if(T.name===r)t={missingDep:r,setter:d.callee.name,form:"updater"};else if(a.has(h))t={missingDep:r,setter:d.callee.name,form:"reducer"};else{let j=u[b].resolved;if(j!=null){let _=j.defs[0];_!=null&&_.type==="Parameter"&&(t={missingDep:r,setter:d.callee.name,form:"inlineReducer"})}}break}}d=d.parent}if(t!==null)break}}),t!==null)switch(t.form){case"reducer":W=` You can also replace multiple useState variables with useReducer if '${t.setter}' needs the current value of '${t.missingDep}'.`;break;case"inlineReducer":W=` If '${t.setter}' needs the current value of '${t.missingDep}', you can also switch to useReducer instead of useState and read '${t.missingDep}' in the reducer.`;break;case"updater":W=` You can also do a functional update '${t.setter}(${t.missingDep.slice(0,1)} => ...)' if you only need '${t.missingDep}' in the '${t.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:v,message:`React Hook ${n(k)} has `+(te(V,"a","missing","include")||te(Y,"an","unnecessary","exclude")||te(de,"a","duplicate","omit"))+W,suggest:[{desc:`Update the dependencies array to be: [${q.map(ee).join(", ")}]`,fix(t){return t.replaceText(v,`[${q.map(ee).join(", ")}]`)}}]})}function $(g){let v=qe(g.callee,f);if(v===-1)return;let k=g.arguments[v],I=g.callee,o=Se(I).name,x=g.arguments[v+1],C=/Effect($|[^a-z])/g.test(o);if(!k){l({node:I,message:`React Hook ${o} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!x&&!C){(o==="useMemo"||o==="useCallback")&&l({node:I,message:`React Hook ${o} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(k.type){case"FunctionExpression":case"ArrowFunctionExpression":P(k,x,I,o,C);return;case"Identifier":if(!x||x.elements&&x.elements.some(E=>E&&E.type==="Identifier"&&E.name===k.name))return;let S=i(g).set.get(k.name);if(S==null||S.defs==null)return;let M=S.defs[0];if(!M||!M.node||M.type!=="Variable"&&M.type!=="FunctionName")break;switch(M.node.type){case"FunctionDeclaration":P(M.node,x,I,o,C);return;case"VariableDeclarator":let E=M.node.init;if(!E)break;switch(E.type){case"ArrowFunctionExpression":case"FunctionExpression":P(E,x,I,o,C);return}break}break;default:l({node:I,message:`React Hook ${o} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:I,message:`React Hook ${o} has a missing dependency: '${k.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${k.name}]`,fix(S){return S.replaceText(x,`[${k.name}]`)}}]})}return{CallExpression:$}}};function re({dependencies:e,declaredDependencies:n,stableDependencies:i,externalDependencies:m,isEffect:y}){let f=l();function l(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach(($,g)=>{let v=p(f,g);v.isUsed=!0,s(f,g,k=>{k.isSubtreeUsed=!0})}),n.forEach(({key:$})=>{let g=p(f,$);g.isSatisfiedRecursively=!0}),i.forEach($=>{let g=p(f,$);g.isSatisfiedRecursively=!0});function p($,g){let v=g.split("."),k=$;for(let I of v){let o=k.children.get(I);o||(o=l(),k.children.set(I,o)),k=o}return k}function s($,g,v){let k=g.split("."),I=$;for(let o of k){let x=I.children.get(o);if(!x)return;v(x),I=x}}let a=new Set,w=new Set;R(f,a,w,$=>$);function R($,g,v,k){$.children.forEach((I,o)=>{let x=k(o);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&v.add(x);return}if(I.isUsed){g.add(x);return}R(I,g,v,C=>x+"."+C)})}let D=[],O=new Set,P=new Set;return n.forEach(({key:$})=>{w.has($)?D.indexOf($)===-1?D.push($):P.add($):O.add($)}),a.forEach($=>{D.push($)}),{suggestedDependencies:D,unnecessaryDependencies:O,duplicateDependencies:P,missingDependencies:a}}function z(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 z(e.consequent)!=null||z(e.alternate)!=null?"conditional":null;case"LogicalExpression":return z(e.left)!=null||z(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return z(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return z(e.expression);case"TSAsExpression":return z(e.expression)}return null}function Ye({declaredDependencies:e,declaredDependenciesNode:n,componentScope:i,scope:m}){let y=e.map(({key:l})=>{let p=i.variables.find(a=>a.name===l);if(p==null)return null;let s=p.defs[0];if(s==null)return null;if(s.type==="Variable"&&s.node.type==="VariableDeclarator"&&s.node.id.type==="Identifier"&&s.node.init!=null){let a=z(s.node.init);if(a!=null)return[p,a]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[p,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[p,"class"]:null}).filter(Boolean);function f(l){let p=!1;for(let s=0;s<l.references.length;s++){let a=l.references[s];if(a.writeExpr){if(p)return!0;p=!0;continue}let w=a.from;for(;w!==m&&w!=null;)w=w.upper;if(w!==m&&!Ee(n,a.identifier))return!0}return!1}return y.map(([l,p])=>({construction:l.defs[0],depType:p,isUsedOutsideOfHook:f(l)}))}function be(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)?be(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function se(e,n,i){n&&(e.optional?n.has(i)||n.set(i,!0):n.has(i)||n.set(i,!1))}function U(e,n){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let i=e.name;return n&&n.set(i,!1),i}else if(e.type==="MemberExpression"&&!e.computed){let i=U(e.object,n),m=U(e.property,null),y=`${i}.${m}`;return se(e,n,y),y}else if(e.type==="OptionalMemberExpression"&&!e.computed){let i=U(e.object,n),m=U(e.property,null),y=`${i}.${m}`;return se(e,n,y),y}else if(e.type==="ChainExpression"&&!e.computed){let i=e.expression;if(i.type==="CallExpression")throw new Error(`Unsupported node type: ${i.type}`);let m=U(i.object,n),y=U(i.property,null),f=`${m}.${y}`;return se(i,n,f),f}else throw new Error(`Unsupported node type: ${e.type}`)}function Se(e,n){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function qe(e,n){let i=Se(e);if(i.type!=="Identifier")return-1;switch(i.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(i===e&&n&&n.additionalHooks){let m;try{m=U(i,null)}catch(y){if(/Unsupported node type/.test(y.message))return 0;throw y}return n.additionalHooks.test(m)?0:-1}else return-1}}function ie(e,n){let i=[e],m=null;for(;i.length;){if(m=i.shift(),Ze(m,n))return m;if(Ee(m,n))for(let[y,f]of Object.entries(m))y!=="parent"&&(he(f)?(f.parent=m,i.push(f)):Array.isArray(f)&&f.forEach(l=>{he(l)&&(l.parent=m,i.push(l))}))}return null}function Je(e){let n="";for(let i=0;i<e.length;i++)n+=e[i],i===0&&e.length===2?n+=" and ":i===e.length-2&&e.length>2?n+=", and ":i<e.length-1&&(n+=", ");return n}function he(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ze(e,n){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===n.type&&e.name===n.name&&e.range[0]===n.range[0]&&e.range[1]===n.range[1]}function Ee(e,n){return e.range[0]<=n.range[0]&&e.range[1]>=n.range[1]}function Qe(e){return!1}var B=require("@typescript-eslint/utils"),et=B.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Te="no-call-with-infered-generics",tt=et({name:Te,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){let n=e.options[0],i=new Map(n.functions.map(m=>[m.name,m]));return{CallExpression(m){let{callee:y}=m;if(y.type!==B.AST_NODE_TYPES.Identifier)return;let f=i.get(y.name);if(!f)return;let{minGenerics:l=1,allowAny:p,disallowTypes:s=n.disallowTypes}=f;(m.typeArguments?.params.length||0)<(l||0)&&e.report({node:m,messageId:"missingGenericDeclaration",data:{functionName:y.name,minGenerics:l||0}}),!(p&&!s)&&m.typeArguments?.params?.some(w=>!p&&w.type===B.AST_NODE_TYPES.TSAnyKeyword||s&&w.type===B.AST_NODE_TYPES.TSTypeReference&&w.typeName.type===B.AST_NODE_TYPES.Identifier&&s.includes(w.typeName.name))&&e.report({node:m,messageId:"anyUsedInGenerics",data:{functionName:y.name}})}}}}),oe={name:Te,rule:tt};var K=require("@typescript-eslint/utils"),nt=K.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),ke="no-commented-out-code",rt=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],st=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],it=nt({name:ke,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:function(e){function n(i){if(i.startsWith("/"))return!1;let m=i.trimStart();if(i.startsWith("*")||m.startsWith("INFO:")||m.startsWith("TODO:")||m.startsWith("FIX:")||m.startsWith("eslint-disable")||i.includes("@deprecated")||i.includes("@example"))return!1;for(let y of rt)if(m.startsWith(y))return{wrongPattern:y};for(let y of st)if(typeof y=="string"){if(i.includes(y))return{wrongPattern:y}}else if(y.test(i))return{wrongPattern:`regex(${y.toString()})`};return!1}return{Program(){let m=e.sourceCode.getAllComments();for(let y of m)if(y.type===K.TSESTree.AST_TOKEN_TYPES.Line||y.type===K.TSESTree.AST_TOKEN_TYPES.Block){let f=n(y.value);f&&e.report({node:y,messageId:"commentedOutCode",data:{wrongPattern:f.wrongPattern}})}}}}}),ae={name:ke,rule:it};var A=require("@typescript-eslint/utils"),ot=A.ESLintUtils.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function we(e){let n=[];for(let i of e.members)i.type===A.AST_NODE_TYPES.TSPropertySignature&&i.key.type===A.AST_NODE_TYPES.Identifier&&n.push([i.key.name,i]);return n}function xe(e,...n){for(let i of n)e.set(...i);return e}var Ie="no-unused-type-props-in-args",at=ot({name:Ie,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used"},schema:[],fixable:"code"},defaultOptions:[],create:function(e){function n(f,l,p,s=!0){let a=l.name,w=e.sourceCode.getScope(f).references.find(D=>D.identifier.name===a)?.resolved;if(!w||w.references.filter(D=>D.isTypeReference).length>1)return;let R=w?.defs[0]?.node;if(!(s&&R?.parent?.type===A.AST_NODE_TYPES.ExportNamedDeclaration)){if(R?.type===A.AST_NODE_TYPES.TSTypeAliasDeclaration){i(f,p,R.typeAnnotation,!0);return}if(R?.type===A.AST_NODE_TYPES.TSInterfaceDeclaration){i(f,p,R.body,!0);return}}}function i(f,l,p,s){if(p.type===A.AST_NODE_TYPES.TSInterfaceBody){for(let a of p.body)a.type===A.AST_NODE_TYPES.TSPropertySignature&&a.key.type===A.AST_NODE_TYPES.Identifier&&l.set(a.key.name,a);return}if(p.type===A.AST_NODE_TYPES.TSTypeLiteral){xe(l,...we(p));return}if(p.type===A.AST_NODE_TYPES.TSIntersectionType){for(let a of p.types)i(f,l,a,!0);return}s||p.type===A.AST_NODE_TYPES.TSTypeReference&&p.typeName.type===A.AST_NODE_TYPES.Identifier&&n(f,p.typeName,l)}function m(f,l){for(let p of l)if(p.type==="ObjectPattern"&&p.typeAnnotation){let s=new Map;if(i(f,s,p.typeAnnotation.typeAnnotation,!1),s.size===0)continue;y(p,s)}else p.type===A.AST_NODE_TYPES.AssignmentPattern&&p.left.type===A.AST_NODE_TYPES.ObjectPattern&&m(f,[p.left])}function y(f,l){let p=[];if(f.properties.at(-1)?.type===A.AST_NODE_TYPES.RestElement)return;for(let R of f.properties)R.type===A.AST_NODE_TYPES.Property&&R.key.type===A.AST_NODE_TYPES.Identifier&&p.push(R.key.name);let a=[],w=[];for(let[R,D]of l)p.includes(R)||(w.push(R),a.push({node:D,messageId:"unusedObjectTypeProperty",data:{propertyName:R}}));for(let[R,D]of a.entries())e.report({...D,fix:R===a.length-1?O=>{let P=f.properties.at(-1),$=w.join(", ");return P?P?.type===A.AST_NODE_TYPES.RestElement?null:O.insertTextAfter(P,`, ${$}`):O.insertTextBeforeRange([f.range[0]+1,f.range[1]],`${$}`)}:void 0})}return{VariableDeclaration:function(f){let l=f.declarations[0];if(!l)return;let p=new Map,s=l.id.type===A.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===A.AST_NODE_TYPES.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===A.AST_NODE_TYPES.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===A.AST_NODE_TYPES.TSTypeReference&&s.typeName.type===A.AST_NODE_TYPES.Identifier)n(f,s.typeName,p,!1);else if(s.type===A.AST_NODE_TYPES.TSTypeLiteral)xe(p,...we(s));else if(s.type===A.AST_NODE_TYPES.TSIntersectionType)for(let a of s.types)a.type===A.AST_NODE_TYPES.TSTypeReference&&a.typeName.type===A.AST_NODE_TYPES.Identifier?n(f,a.typeName,p,!1):i(f,p,a,!0);if(p.size!==0&&l.init?.type===A.AST_NODE_TYPES.ArrowFunctionExpression){let a=l.init.params[0];a&&a.type===A.AST_NODE_TYPES.ObjectPattern&&y(a,p)}}},FunctionDeclaration:function(f){m(f,f.params)},ArrowFunctionExpression:function(f){m(f,f.params)}}}}),ce={name:Ie,rule:at};function Ce(e){return/^use[A-Z0-9]/.test(e)}function J(e){return e.type==="Identifier"?Ce(e.name):e.type==="MemberExpression"&&!e.computed&&J(e.property)?e.object.type==="Identifier":!1}function $e(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function ve(e,n){return e.name===n||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===n}function Me(e){return!!(e.parent&&e.parent.callee&&ve(e.parent.callee,"forwardRef"))}function De(e){return!!(e.parent&&e.parent.callee&&ve(e.parent.callee,"memo"))}function le(e){for(;e;){let n=Oe(e);if(n&&($e(n)||J(n))||Me(e)||De(e))return!0;e=e.parent}return!1}function Re(e){return!1}function fe(e){return!1}var Pe={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"}},create(e){let n=typeof e.getSource=="function"?s=>n(s):s=>e.sourceCode.getText(s),i=typeof e.getScope=="function"?()=>i():s=>e.sourceCode.getScope(s),m=null,y=[],f=[],l=new WeakSet;function p(s){for(let a of s.references){let w=a.identifier.parent;if(w.type==="VariableDeclarator"&&w.init&&w.init.type==="CallExpression"&&w.init.callee&&Re(w.init.callee))for(let R of a.resolved.references)R!==a&&l.add(R.identifier)}}return{onCodePathSegmentStart:s=>f.push(s),onCodePathSegmentEnd:()=>f.pop(),onCodePathStart:()=>y.push(new Map),onCodePathEnd(s,a){let w=y.pop();if(w.size===0)return;let R=new Set;function D(o,x){let{cache:C}=D,S=C.get(o.id),M=new Set(x);if(M.has(o.id)){let E=[...M],H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(M.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.prevSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.prevSegments)S+=D(E,M)}return o.reachable&&S===BigInt("0")?C.delete(o.id):C.set(o.id,S),S}function O(o,x){let{cache:C}=O,S=C.get(o.id),M=new Set(x);if(M.has(o.id)){let E=Array.from(M),H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(M.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.nextSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.nextSegments)S+=O(E,M)}return C.set(o.id,S),S}function P(o){let{cache:x}=P,C=x.get(o.id);if(C===null)return 1/0;if(C!==void 0)return C;if(x.set(o.id,null),o.prevSegments.length===0)C=1;else{C=1/0;for(let S of o.prevSegments){let M=P(S);M<C&&(C=M)}C+=1}return x.set(o.id,C),C}D.cache=new Map,O.cache=new Map,P.cache=new Map;let $=O(s.initialSegment),g=Oe(a),v=le(a),k=g?$e(g)||J(g):Me(a)||De(a),I=1/0;for(let o of s.finalSegments){if(!o.reachable)continue;let x=P(o);x<I&&(I=x)}for(let[o,x]of w){if(!o.reachable)continue;let C=o.nextSegments.length===0?I<=P(o):I<P(o),S=D(o)*O(o),M=R.has(o.id);for(let E of x)if(M&&!fe(E)&&e.report({node:E,message:`React Hook "${n(E)}" 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.`}),k){if(a.async&&e.report({node:E,message:`React Hook "${n(E)}" cannot be called in an async function.`}),!M&&S!==$&&!fe(E)){let L=`React Hook "${n(E)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(C?" Did you accidentally call a React Hook after an early return?":"");e.report({node:E,message:L})}}else if(a.parent&&(a.parent.type==="MethodDefinition"||a.parent.type==="ClassProperty")&&a.parent.value===a){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(g){let H=`React Hook "${n(E)}" is called in function "${n(g)}" 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:E,message:H})}else if(a.type==="Program"){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(v&&!fe(E)){if(a.parent.type==="CallExpression"&&a.parent.callee.type==="Identifier"&&a.parent.callee.name==="useCallback"){let L=a.parent;if(L.parent.type==="VariableDeclarator"&&Ce(L.parent.id.name))return}let H=`React Hook "${n(E)}" 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:E,message:H})}}},CallExpression(s){if(J(s.callee)){let a=Ae(y),w=Ae(f),R=a.get(w);R||(R=[],a.set(w,R)),R.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Re(s.callee))&&s.arguments.length>0&&(m=s)},Identifier(s){m==null&&l.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${n(s)}\` 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"(s){s===m&&(m=null)},FunctionDeclaration(s){le(s)&&p(i(s))},ArrowFunctionExpression(s){le(s)&&p(i(s))}}}};function Oe(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 Ae(e){return e[e.length-1]}var He={[ce.name]:ce.rule,[ae.name]:ae.rule,[oe.name]:oe.rule,"rules-of-hooks":Pe,"exhaustive-deps":ge};var ct={rules:He};0&&(module.exports={extendedLintPlugin});
@@ -0,0 +1,12 @@
1
+ var ye={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,enableDangerousAutofixThisMayCauseInfiniteLoops:!1,properties:{additionalHooks:{type:"string"},enableDangerousAutofixThisMayCauseInfiniteLoops:{type:"boolean"}}}]},create(e){let n=typeof e.getSource=="function"?h=>n(h):h=>e.sourceCode.getText(h),i=typeof e.getScope=="function"?()=>i():h=>e.sourceCode.getScope(h),y=e.options&&e.options[0]&&e.options[0].additionalHooks?new RegExp(e.options[0].additionalHooks):void 0,g=e.options&&e.options[0]&&e.options[0].enableDangerousAutofixThisMayCauseInfiniteLoops||!1,f={additionalHooks:y,enableDangerousAutofixThisMayCauseInfiniteLoops:g};function l(h){g&&Array.isArray(h.suggest)&&h.suggest.length>0&&(h.fix=h.suggest[0].fix),e.report(h)}let p=e.getSourceCode().scopeManager,s=new WeakMap,a=new WeakSet,w=new WeakMap,R=new WeakMap,D=new WeakSet;function O(h,v){return function(k){if(v.has(k))return v.get(k);let I=h(k);return v.set(k,I),I}}function P(h,v,k,I,o){o&&h.async&&l({node:h,message:`Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
2
+
3
+ useEffect(() => {
4
+ async function fetchData() {
5
+ // You can await here
6
+ const response = await MyAPI.getData(someId);
7
+ // ...
8
+ }
9
+ fetchData();
10
+ }, [someId]); // Or [] if effect doesn't need props or state
11
+
12
+ Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching`});let x=p.acquire(h),A=new Set,S=null;{let t=x.upper;for(;t&&(A.add(t),t.type!=="function");)t=t.upper;if(!t)return;S=t}let M=Array.isArray;function E(t){if(!M(t.defs))return!1;let r=t.defs[0];if(r==null||r.node.type!=="VariableDeclarator")return!1;let c=r.node.init;if(c==null)return!1;for(;c.type==="TSAsExpression";)c=c.expression;let u=r.node.parent;if(u==null&&(re(S.block,r.node.id),u=r.node.parent,u==null))return!1;if(u.kind==="const"&&c.type==="Literal"&&(typeof c.value=="string"||typeof c.value=="number"||c.value===null))return!0;if(c.type!=="CallExpression")return!1;let m=c.callee;if(m.type==="MemberExpression"&&m.object.name==="React"&&m.property!=null&&!m.computed&&(m=m.property),m.type!=="Identifier")return!1;let d=r.node.id,{name:b}=m;if(b==="useRef"&&d.type==="Identifier")return!0;if(Xe(m)&&d.type==="Identifier"){for(let T of t.references)T!==d&&D.add(T.identifier);return!0}else if(b==="useState"||b==="useReducer"){if(d.type==="ArrayPattern"&&d.elements.length===2&&M(t.identifiers)){if(d.elements[1]===t.identifiers[0]){if(b==="useState"){let T=t.references,j=0;for(let _=0;_<T.length;_++){if(T[_].isWrite()&&j++,j>1)return!1;s.set(T[_].identifier,d.elements[0])}}return!0}else if(d.elements[0]===t.identifiers[0]){if(b==="useState"){let T=t.references;for(let j=0;j<T.length;j++)a.add(T[j].identifier)}return!1}}}else if(b==="useTransition"&&d.type==="ArrayPattern"&&d.elements.length===2&&Array.isArray(t.identifiers)&&d.elements[1]===t.identifiers[0])return!0;return!1}function H(t){if(!M(t.defs))return!1;let r=t.defs[0];if(r==null||r.node==null||r.node.id==null)return!1;let c=r.node,u=S.childScopes,m=null,d;for(d=0;d<u.length;d++){let b=u[d],T=b.block;if(c.type==="FunctionDeclaration"&&T===c||c.type==="VariableDeclarator"&&T.parent===c){m=b;break}}if(m==null)return!1;for(d=0;d<m.through.length;d++){let b=m.through[d];if(b.resolved!=null&&A.has(b.resolved.scope)&&!L(b.resolved))return!1}return!0}let L=O(E,w),He=O(H,R),le=new Map;function Fe(t){let r=t.from,c=!1;for(;r.block!==h;)r.type==="function"&&(c=r.block.parent!=null&&r.block.parent.type==="ReturnStatement"),r=r.upper;return c}let F=new Map,J=new Map;fe(x);function fe(t){for(let r of t.references){if(!r.resolved||!A.has(r.resolved.scope))continue;let c=re(h,r.identifier),u=he(c),m=U(u,J);if(o&&u.type==="Identifier"&&(u.parent.type==="MemberExpression"||u.parent.type==="OptionalMemberExpression")&&!u.parent.computed&&u.parent.property.type==="Identifier"&&u.parent.property.name==="current"&&Fe(r)&&le.set(m,{reference:r,dependencyNode:u}),u.parent.type==="TSTypeQuery"||u.parent.type==="TSTypeReference")continue;let d=r.resolved.defs[0];if(d!=null&&!(d.node!=null&&d.node.init===h.parent)&&d.type!=="TypeParameter")if(F.has(m))F.get(m).references.push(r);else{let b=r.resolved,T=L(b)||He(b);F.set(m,{isStable:T,references:[r]})}}for(let r of t.childScopes)fe(r)}le.forEach(({reference:t,dependencyNode:r},c)=>{let u=t.resolved.references,m=!1;for(let d=0;d<u.length;d++){let{identifier:b}=u[d],{parent:T}=b;if(T!=null&&T.type==="MemberExpression"&&!T.computed&&T.property.type==="Identifier"&&T.property.name==="current"&&T.parent.type==="AssignmentExpression"&&T.parent.left===T){m=!0;break}}m||l({node:r.parent.property,message:`The ref value '${c}.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '${c}.current' to a variable inside the effect, and use that variable in the cleanup function.`})});let Z=new Set;function je(t,r){Z.has(r)||(Z.add(r),l({node:t,message:`Assignments to the '${r}' variable from inside React Hook ${n(k)} will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ${n(k)}.`}))}let X=new Set;if(F.forEach(({isStable:t,references:r},c)=>{t&&X.add(c),r.forEach(u=>{u.writeExpr&&je(u.writeExpr,c)})}),Z.size>0)return;if(!v){let t=null;if(F.forEach(({isStable:r,references:c},u)=>{t||c.forEach(m=>{if(t)return;let d=m.identifier;if(!s.has(d))return;let T=m.from;for(;T.type!=="function";)T=T.upper;T.block===h&&(t=u)})}),t){let{suggestedDependencies:r}=te({dependencies:F,declaredDependencies:[],stableDependencies:X,externalDependencies:new Set,isEffect:!0});l({node:k,message:`React Hook ${I} contains a call to '${t}'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [`+r.join(", ")+`] as a second argument to the ${I} Hook.`,suggest:[{desc:`Add dependencies array: [${r.join(", ")}]`,fix(c){return c.insertTextAfter(h,`, [${r.join(", ")}]`)}}]})}return}let B=[],G=new Set;v.type!=="ArrayExpression"?l({node:v,message:`React Hook ${n(k)} was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies.`}):v.elements.forEach(t=>{if(t===null)return;if(t.type==="SpreadElement"){l({node:t,message:`React Hook ${n(k)} has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies.`});return}D.has(t)&&l({node:t,message:`Functions returned from \`useEffectEvent\` must not be included in the dependency array. Remove \`${n(t)}\` from the list.`,suggest:[{desc:`Remove the dependency \`${n(t)}\``,fix(m){return m.removeRange(t.range)}}]});let r;try{r=U(t,J)}catch(m){if(/Unsupported node type/.test(m.message)){t.type==="Literal"?F.has(t.value)?l({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. Did you mean to include ${t.value} in the array instead?`}):l({node:t,message:`The ${t.raw} literal is not a valid dependency because it never changes. You can safely remove it.`}):l({node:t,message:`React Hook ${n(k)} has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.`});return}else throw m}let c=t;for(;c.type==="MemberExpression"||c.type==="OptionalMemberExpression"||c.type==="ChainExpression";)c=c.object||c.expression.object;let u=!S.through.some(m=>m.identifier===c);B.push({key:r,node:t}),u||G.add(r)});let{suggestedDependencies:Le,unnecessaryDependencies:K,missingDependencies:V,duplicateDependencies:ue}=te({dependencies:F,declaredDependencies:B,stableDependencies:X,externalDependencies:G,isEffect:o}),N=Le;if(ue.size+V.size+K.size===0){Ve({declaredDependencies:B,declaredDependenciesNode:v,componentScope:S,scope:x}).forEach(({construction:r,isUsedOutsideOfHook:c,depType:u})=>{let m=u==="function"?"useCallback":"useMemo",d=u==="function"?"definition":"initialization",b=`wrap the ${d} of '${r.name.name}' in its own ${m}() Hook.`,T=c?`To fix this, ${b}`:`Move it inside the ${I} callback. Alternatively, ${b}`,j=u==="conditional"||u==="logical expression"?"could make":"makes",_=`The '${r.name.name}' ${u} ${j} the dependencies of ${I} Hook (at line ${v.loc.start.line}) change on every render. ${T}`,pe;c&&r.type==="Variable"&&u==="function"&&(pe=[{desc:`Wrap the ${d} of '${r.name.name}' in its own ${m}() Hook.`,fix(de){let[_e,Ue]=m==="useMemo"?["useMemo(() => { return ","; })"]:["useCallback(",")"];return[de.insertTextBefore(r.node.init,_e),de.insertTextAfter(r.node.init,Ue)]}}]),l({node:r.node,message:_,suggest:pe})});return}!o&&V.size>0&&(N=te({dependencies:F,declaredDependencies:[],stableDependencies:X,externalDependencies:G,isEffect:o}).suggestedDependencies);function We(){if(B.length===0)return!0;let t=B.map(c=>c.key),r=t.slice().sort();return t.join(",")===r.join(",")}We()&&N.sort();function Q(t){let r=t.split("."),c="";for(let u=0;u<r.length;u++){if(u!==0){let m=r.slice(0,u+1).join("."),d=J.get(m)===!0;c+=d?"?.":"."}c+=r[u]}return c}function ee(t,r,c,u){return t.size===0?null:(t.size>1?"":r+" ")+c+" "+(t.size>1?"dependencies":"dependency")+": "+Be(Array.from(t).sort().map(m=>"'"+Q(m)+"'"))+`. Either ${u} ${t.size>1?"them":"it"} or remove the dependency array.`}let W="";if(K.size>0){let t=null;if(Array.from(K.keys()).forEach(r=>{t===null&&r.endsWith(".current")&&(t=r)}),t!==null)W=` Mutable values like '${t}' aren't valid dependencies because mutating them doesn't re-render the component.`;else if(G.size>0){let r=Array.from(G)[0];x.set.has(r)||(W=` Outer scope values like '${r}' aren't valid dependencies because mutating them doesn't re-render the component.`)}}if(!W&&V.has("props")){let t=F.get("props");if(t==null)return;let r=t.references;if(!Array.isArray(r))return;let c=!0;for(let u=0;u<r.length;u++){let m=r[u],d=re(S.block,m.identifier);if(!d){c=!1;break}let b=d.parent;if(b==null){c=!1;break}if(b.type!=="MemberExpression"&&b.type!=="OptionalMemberExpression"){c=!1;break}}c&&(W=` However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the ${I} call and refer to those specific props inside ${n(k)}.`)}if(!W&&V.size>0){let t=null;V.forEach(r=>{if(t)return;let c=S.set.get(r),u=F.get(r);if(u.references[0].resolved!==c)return;let m=c.defs[0];if(m==null||m.name==null||m.type!=="Parameter")return;let d=!1,b;for(let T=0;T<u.references.length;T++)if(b=u.references[T].identifier,b!=null&&b.parent!=null&&(b.parent.type==="CallExpression"||b.parent.type==="OptionalCallExpression")&&b.parent.callee===b){d=!0;break}d&&(t=r)}),t!==null&&(W=` If '${t}' changes too often, find the parent component that defines it and wrap that definition in useCallback.`)}if(!W&&V.size>0){let t=null;if(V.forEach(r=>{if(t!==null)return;let u=F.get(r).references,m,d;for(let b=0;b<u.length;b++){for(m=u[b].identifier,d=m.parent;d!=null&&d!==S.block;){if(d.type==="CallExpression"){let T=s.get(d.callee);if(T!=null){if(T.name===r)t={missingDep:r,setter:d.callee.name,form:"updater"};else if(a.has(m))t={missingDep:r,setter:d.callee.name,form:"reducer"};else{let j=u[b].resolved;if(j!=null){let _=j.defs[0];_!=null&&_.type==="Parameter"&&(t={missingDep:r,setter:d.callee.name,form:"inlineReducer"})}}break}}d=d.parent}if(t!==null)break}}),t!==null)switch(t.form){case"reducer":W=` You can also replace multiple useState variables with useReducer if '${t.setter}' needs the current value of '${t.missingDep}'.`;break;case"inlineReducer":W=` If '${t.setter}' needs the current value of '${t.missingDep}', you can also switch to useReducer instead of useState and read '${t.missingDep}' in the reducer.`;break;case"updater":W=` You can also do a functional update '${t.setter}(${t.missingDep.slice(0,1)} => ...)' if you only need '${t.missingDep}' in the '${t.setter}' call.`;break;default:throw new Error("Unknown case.")}}l({node:v,message:`React Hook ${n(k)} has `+(ee(V,"a","missing","include")||ee(K,"an","unnecessary","exclude")||ee(ue,"a","duplicate","omit"))+W,suggest:[{desc:`Update the dependencies array to be: [${N.map(Q).join(", ")}]`,fix(t){return t.replaceText(v,`[${N.map(Q).join(", ")}]`)}}]})}function $(h){let v=ze(h.callee,f);if(v===-1)return;let k=h.arguments[v],I=h.callee,o=ge(I).name,x=h.arguments[v+1],A=/Effect($|[^a-z])/g.test(o);if(!k){l({node:I,message:`React Hook ${o} requires an effect callback. Did you forget to pass a callback to the hook?`});return}if(!x&&!A){(o==="useMemo"||o==="useCallback")&&l({node:I,message:`React Hook ${o} does nothing when called with only one argument. Did you forget to pass an array of dependencies?`});return}switch(k.type){case"FunctionExpression":case"ArrowFunctionExpression":P(k,x,I,o,A);return;case"Identifier":if(!x||x.elements&&x.elements.some(E=>E&&E.type==="Identifier"&&E.name===k.name))return;let S=i(h).set.get(k.name);if(S==null||S.defs==null)return;let M=S.defs[0];if(!M||!M.node||M.type!=="Variable"&&M.type!=="FunctionName")break;switch(M.node.type){case"FunctionDeclaration":P(M.node,x,I,o,A);return;case"VariableDeclarator":let E=M.node.init;if(!E)break;switch(E.type){case"ArrowFunctionExpression":case"FunctionExpression":P(E,x,I,o,A);return}break}break;default:l({node:I,message:`React Hook ${o} received a function whose dependencies are unknown. Pass an inline function instead.`});return}l({node:I,message:`React Hook ${o} has a missing dependency: '${k.name}'. Either include it or remove the dependency array.`,suggest:[{desc:`Update the dependencies array to be: [${k.name}]`,fix(S){return S.replaceText(x,`[${k.name}]`)}}]})}return{CallExpression:$}}};function te({dependencies:e,declaredDependencies:n,stableDependencies:i,externalDependencies:y,isEffect:g}){let f=l();function l(){return{isUsed:!1,isSatisfiedRecursively:!1,isSubtreeUsed:!1,children:new Map}}e.forEach(($,h)=>{let v=p(f,h);v.isUsed=!0,s(f,h,k=>{k.isSubtreeUsed=!0})}),n.forEach(({key:$})=>{let h=p(f,$);h.isSatisfiedRecursively=!0}),i.forEach($=>{let h=p(f,$);h.isSatisfiedRecursively=!0});function p($,h){let v=h.split("."),k=$;for(let I of v){let o=k.children.get(I);o||(o=l(),k.children.set(I,o)),k=o}return k}function s($,h,v){let k=h.split("."),I=$;for(let o of k){let x=I.children.get(o);if(!x)return;v(x),I=x}}let a=new Set,w=new Set;R(f,a,w,$=>$);function R($,h,v,k){$.children.forEach((I,o)=>{let x=k(o);if(I.isSatisfiedRecursively){I.isSubtreeUsed&&v.add(x);return}if(I.isUsed){h.add(x);return}R(I,h,v,A=>x+"."+A)})}let D=[],O=new Set,P=new Set;return n.forEach(({key:$})=>{w.has($)?D.indexOf($)===-1?D.push($):P.add($):O.add($)}),a.forEach($=>{D.push($)}),{suggestedDependencies:D,unnecessaryDependencies:O,duplicateDependencies:P,missingDependencies:a}}function z(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 z(e.consequent)!=null||z(e.alternate)!=null?"conditional":null;case"LogicalExpression":return z(e.left)!=null||z(e.right)!=null?"logical expression":null;case"JSXFragment":return"JSX fragment";case"JSXElement":return"JSX element";case"AssignmentExpression":return z(e.right)!=null?"assignment expression":null;case"NewExpression":return"object construction";case"Literal":return e.value instanceof RegExp?"regular expression":null;case"TypeCastExpression":return z(e.expression);case"TSAsExpression":return z(e.expression)}return null}function Ve({declaredDependencies:e,declaredDependenciesNode:n,componentScope:i,scope:y}){let g=e.map(({key:l})=>{let p=i.variables.find(a=>a.name===l);if(p==null)return null;let s=p.defs[0];if(s==null)return null;if(s.type==="Variable"&&s.node.type==="VariableDeclarator"&&s.node.id.type==="Identifier"&&s.node.init!=null){let a=z(s.node.init);if(a!=null)return[p,a]}return s.type==="FunctionName"&&s.node.type==="FunctionDeclaration"?[p,"function"]:s.type==="ClassName"&&s.node.type==="ClassDeclaration"?[p,"class"]:null}).filter(Boolean);function f(l){let p=!1;for(let s=0;s<l.references.length;s++){let a=l.references[s];if(a.writeExpr){if(p)return!0;p=!0;continue}let w=a.from;for(;w!==y&&w!=null;)w=w.upper;if(w!==y&&!be(n,a.identifier))return!0}return!1}return g.map(([l,p])=>({construction:l.defs[0],depType:p,isUsedOutsideOfHook:f(l)}))}function he(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)?he(e.parent):e.type==="MemberExpression"&&e.parent&&e.parent.type==="AssignmentExpression"&&e.parent.left===e?e.object:e}function ne(e,n,i){n&&(e.optional?n.has(i)||n.set(i,!0):n.has(i)||n.set(i,!1))}function U(e,n){if(e.type==="Identifier"||e.type==="JSXIdentifier"){let i=e.name;return n&&n.set(i,!1),i}else if(e.type==="MemberExpression"&&!e.computed){let i=U(e.object,n),y=U(e.property,null),g=`${i}.${y}`;return ne(e,n,g),g}else if(e.type==="OptionalMemberExpression"&&!e.computed){let i=U(e.object,n),y=U(e.property,null),g=`${i}.${y}`;return ne(e,n,g),g}else if(e.type==="ChainExpression"&&!e.computed){let i=e.expression;if(i.type==="CallExpression")throw new Error(`Unsupported node type: ${i.type}`);let y=U(i.object,n),g=U(i.property,null),f=`${y}.${g}`;return ne(i,n,f),f}else throw new Error(`Unsupported node type: ${e.type}`)}function ge(e,n){return e.type==="MemberExpression"&&e.object.type==="Identifier"&&e.object.name==="React"&&e.property.type==="Identifier"&&!e.computed?e.property:e}function ze(e,n){let i=ge(e);if(i.type!=="Identifier")return-1;switch(i.name){case"useEffect":case"useLayoutEffect":case"useCallback":case"useMemo":return 0;case"useImperativeHandle":return 1;default:if(i===e&&n&&n.additionalHooks){let y;try{y=U(i,null)}catch(g){if(/Unsupported node type/.test(g.message))return 0;throw g}return n.additionalHooks.test(y)?0:-1}else return-1}}function re(e,n){let i=[e],y=null;for(;i.length;){if(y=i.shift(),Ge(y,n))return y;if(be(y,n))for(let[g,f]of Object.entries(y))g!=="parent"&&(me(f)?(f.parent=y,i.push(f)):Array.isArray(f)&&f.forEach(l=>{me(l)&&(l.parent=y,i.push(l))}))}return null}function Be(e){let n="";for(let i=0;i<e.length;i++)n+=e[i],i===0&&e.length===2?n+=" and ":i===e.length-2&&e.length>2?n+=", and ":i<e.length-1&&(n+=", ");return n}function me(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function Ge(e,n){return(e.type==="Identifier"||e.type==="JSXIdentifier")&&e.type===n.type&&e.name===n.name&&e.range[0]===n.range[0]&&e.range[1]===n.range[1]}function be(e,n){return e.range[0]<=n.range[0]&&e.range[1]>=n.range[1]}function Xe(e){return!1}import{AST_NODE_TYPES as Y,ESLintUtils as Ke}from"@typescript-eslint/utils";var Ne=Ke.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Se="no-call-with-infered-generics",Ye=Ne({name:Se,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){let n=e.options[0],i=new Map(n.functions.map(y=>[y.name,y]));return{CallExpression(y){let{callee:g}=y;if(g.type!==Y.Identifier)return;let f=i.get(g.name);if(!f)return;let{minGenerics:l=1,allowAny:p,disallowTypes:s=n.disallowTypes}=f;(y.typeArguments?.params.length||0)<(l||0)&&e.report({node:y,messageId:"missingGenericDeclaration",data:{functionName:g.name,minGenerics:l||0}}),!(p&&!s)&&y.typeArguments?.params?.some(w=>!p&&w.type===Y.TSAnyKeyword||s&&w.type===Y.TSTypeReference&&w.typeName.type===Y.Identifier&&s.includes(w.typeName.name))&&e.report({node:y,messageId:"anyUsedInGenerics",data:{functionName:g.name}})}}}}),se={name:Se,rule:Ye};import{ESLintUtils as qe,TSESTree as Ee}from"@typescript-eslint/utils";var Je=qe.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`),Te="no-commented-out-code",Ze=["function ","class ","interface ","type ","enum ","namespace ","import ","export ","const ","let ","var ","return "],Qe=[") {","return;","if (","else {","for (","switch (","/>","</","},",": {"," } = ","={",/\w=("|')/,");"],et=Je({name:Te,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:function(e){function n(i){if(i.startsWith("/"))return!1;let y=i.trimStart();if(i.startsWith("*")||y.startsWith("INFO:")||y.startsWith("TODO:")||y.startsWith("FIX:")||y.startsWith("eslint-disable")||i.includes("@deprecated")||i.includes("@example"))return!1;for(let g of Ze)if(y.startsWith(g))return{wrongPattern:g};for(let g of Qe)if(typeof g=="string"){if(i.includes(g))return{wrongPattern:g}}else if(g.test(i))return{wrongPattern:`regex(${g.toString()})`};return!1}return{Program(){let y=e.sourceCode.getAllComments();for(let g of y)if(g.type===Ee.AST_TOKEN_TYPES.Line||g.type===Ee.AST_TOKEN_TYPES.Block){let f=n(g.value);f&&e.report({node:g,messageId:"commentedOutCode",data:{wrongPattern:f.wrongPattern}})}}}}}),ie={name:Te,rule:et};import{AST_NODE_TYPES as C,ESLintUtils as tt}from"@typescript-eslint/utils";var nt=tt.RuleCreator(e=>`https://github.com/lucasols/extended-lint#${e}`);function ke(e){let n=[];for(let i of e.members)i.type===C.TSPropertySignature&&i.key.type===C.Identifier&&n.push([i.key.name,i]);return n}function we(e,...n){for(let i of n)e.set(...i);return e}var xe="no-unused-type-props-in-args",rt=nt({name:xe,meta:{type:"problem",docs:{description:"Disallow unused undestructured object type properties"},messages:{unusedObjectTypeProperty:"Object type property '{{ propertyName }}' is defined but never used"},schema:[],fixable:"code"},defaultOptions:[],create:function(e){function n(f,l,p,s=!0){let a=l.name,w=e.sourceCode.getScope(f).references.find(D=>D.identifier.name===a)?.resolved;if(!w||w.references.filter(D=>D.isTypeReference).length>1)return;let R=w?.defs[0]?.node;if(!(s&&R?.parent?.type===C.ExportNamedDeclaration)){if(R?.type===C.TSTypeAliasDeclaration){i(f,p,R.typeAnnotation,!0);return}if(R?.type===C.TSInterfaceDeclaration){i(f,p,R.body,!0);return}}}function i(f,l,p,s){if(p.type===C.TSInterfaceBody){for(let a of p.body)a.type===C.TSPropertySignature&&a.key.type===C.Identifier&&l.set(a.key.name,a);return}if(p.type===C.TSTypeLiteral){we(l,...ke(p));return}if(p.type===C.TSIntersectionType){for(let a of p.types)i(f,l,a,!0);return}s||p.type===C.TSTypeReference&&p.typeName.type===C.Identifier&&n(f,p.typeName,l)}function y(f,l){for(let p of l)if(p.type==="ObjectPattern"&&p.typeAnnotation){let s=new Map;if(i(f,s,p.typeAnnotation.typeAnnotation,!1),s.size===0)continue;g(p,s)}else p.type===C.AssignmentPattern&&p.left.type===C.ObjectPattern&&y(f,[p.left])}function g(f,l){let p=[];if(f.properties.at(-1)?.type===C.RestElement)return;for(let R of f.properties)R.type===C.Property&&R.key.type===C.Identifier&&p.push(R.key.name);let a=[],w=[];for(let[R,D]of l)p.includes(R)||(w.push(R),a.push({node:D,messageId:"unusedObjectTypeProperty",data:{propertyName:R}}));for(let[R,D]of a.entries())e.report({...D,fix:R===a.length-1?O=>{let P=f.properties.at(-1),$=w.join(", ");return P?P?.type===C.RestElement?null:O.insertTextAfter(P,`, ${$}`):O.insertTextBeforeRange([f.range[0]+1,f.range[1]],`${$}`)}:void 0})}return{VariableDeclaration:function(f){let l=f.declarations[0];if(!l)return;let p=new Map,s=l.id.type===C.Identifier&&l.id.typeAnnotation?.typeAnnotation.type===C.TSTypeReference&&l.id.typeAnnotation.typeAnnotation.typeName.type===C.Identifier&&l.id.typeAnnotation.typeAnnotation.typeName.name==="FC"&&l.id.typeAnnotation.typeAnnotation.typeArguments?.params[0];if(s){if(s.type===C.TSTypeReference&&s.typeName.type===C.Identifier)n(f,s.typeName,p,!1);else if(s.type===C.TSTypeLiteral)we(p,...ke(s));else if(s.type===C.TSIntersectionType)for(let a of s.types)a.type===C.TSTypeReference&&a.typeName.type===C.Identifier?n(f,a.typeName,p,!1):i(f,p,a,!0);if(p.size!==0&&l.init?.type===C.ArrowFunctionExpression){let a=l.init.params[0];a&&a.type===C.ObjectPattern&&g(a,p)}}},FunctionDeclaration:function(f){y(f,f.params)},ArrowFunctionExpression:function(f){y(f,f.params)}}}}),oe={name:xe,rule:rt};function Ae(e){return/^use[A-Z0-9]/.test(e)}function q(e){return e.type==="Identifier"?Ae(e.name):e.type==="MemberExpression"&&!e.computed&&q(e.property)?e.object.type==="Identifier":!1}function Ce(e){return e.type==="Identifier"&&/^[A-Z]/.test(e.name)}function $e(e,n){return e.name===n||e.type==="MemberExpression"&&e.object.name==="React"&&e.property.name===n}function ve(e){return!!(e.parent&&e.parent.callee&&$e(e.parent.callee,"forwardRef"))}function Me(e){return!!(e.parent&&e.parent.callee&&$e(e.parent.callee,"memo"))}function ae(e){for(;e;){let n=Pe(e);if(n&&(Ce(n)||q(n))||ve(e)||Me(e))return!0;e=e.parent}return!1}function Ie(e){return!1}function ce(e){return!1}var De={meta:{type:"problem",docs:{description:"enforces the Rules of Hooks",recommended:!0,url:"https://reactjs.org/docs/hooks-rules.html"}},create(e){let n=typeof e.getSource=="function"?s=>n(s):s=>e.sourceCode.getText(s),i=typeof e.getScope=="function"?()=>i():s=>e.sourceCode.getScope(s),y=null,g=[],f=[],l=new WeakSet;function p(s){for(let a of s.references){let w=a.identifier.parent;if(w.type==="VariableDeclarator"&&w.init&&w.init.type==="CallExpression"&&w.init.callee&&Ie(w.init.callee))for(let R of a.resolved.references)R!==a&&l.add(R.identifier)}}return{onCodePathSegmentStart:s=>f.push(s),onCodePathSegmentEnd:()=>f.pop(),onCodePathStart:()=>g.push(new Map),onCodePathEnd(s,a){let w=g.pop();if(w.size===0)return;let R=new Set;function D(o,x){let{cache:A}=D,S=A.get(o.id),M=new Set(x);if(M.has(o.id)){let E=[...M],H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(M.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.prevSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.prevSegments)S+=D(E,M)}return o.reachable&&S===BigInt("0")?A.delete(o.id):A.set(o.id,S),S}function O(o,x){let{cache:A}=O,S=A.get(o.id),M=new Set(x);if(M.has(o.id)){let E=Array.from(M),H=E.slice(E.indexOf(o.id)+1);for(let L of H)R.add(L);return BigInt("0")}if(M.add(o.id),S!==void 0)return S;if(s.thrownSegments.includes(o))S=BigInt("0");else if(o.nextSegments.length===0)S=BigInt("1");else{S=BigInt("0");for(let E of o.nextSegments)S+=O(E,M)}return A.set(o.id,S),S}function P(o){let{cache:x}=P,A=x.get(o.id);if(A===null)return 1/0;if(A!==void 0)return A;if(x.set(o.id,null),o.prevSegments.length===0)A=1;else{A=1/0;for(let S of o.prevSegments){let M=P(S);M<A&&(A=M)}A+=1}return x.set(o.id,A),A}D.cache=new Map,O.cache=new Map,P.cache=new Map;let $=O(s.initialSegment),h=Pe(a),v=ae(a),k=h?Ce(h)||q(h):ve(a)||Me(a),I=1/0;for(let o of s.finalSegments){if(!o.reachable)continue;let x=P(o);x<I&&(I=x)}for(let[o,x]of w){if(!o.reachable)continue;let A=o.nextSegments.length===0?I<=P(o):I<P(o),S=D(o)*O(o),M=R.has(o.id);for(let E of x)if(M&&!ce(E)&&e.report({node:E,message:`React Hook "${n(E)}" 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.`}),k){if(a.async&&e.report({node:E,message:`React Hook "${n(E)}" cannot be called in an async function.`}),!M&&S!==$&&!ce(E)){let L=`React Hook "${n(E)}" is called conditionally. React Hooks must be called in the exact same order in every component render.`+(A?" Did you accidentally call a React Hook after an early return?":"");e.report({node:E,message:L})}}else if(a.parent&&(a.parent.type==="MethodDefinition"||a.parent.type==="ClassProperty")&&a.parent.value===a){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(h){let H=`React Hook "${n(E)}" is called in function "${n(h)}" 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:E,message:H})}else if(a.type==="Program"){let H=`React Hook "${n(E)}" 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:E,message:H})}else if(v&&!ce(E)){if(a.parent.type==="CallExpression"&&a.parent.callee.type==="Identifier"&&a.parent.callee.name==="useCallback"){let L=a.parent;if(L.parent.type==="VariableDeclarator"&&Ae(L.parent.id.name))return}let H=`React Hook "${n(E)}" 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:E,message:H})}}},CallExpression(s){if(q(s.callee)){let a=Re(g),w=Re(f),R=a.get(w);R||(R=[],a.set(w,R)),R.push(s.callee)}s.callee.type==="Identifier"&&(s.callee.name==="useEffect"||Ie(s.callee))&&s.arguments.length>0&&(y=s)},Identifier(s){y==null&&l.has(s)&&s.parent.type!=="CallExpression"&&e.report({node:s,message:`\`${n(s)}\` 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"(s){s===y&&(y=null)},FunctionDeclaration(s){ae(s)&&p(i(s))},ArrowFunctionExpression(s){ae(s)&&p(i(s))}}}};function Pe(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 Re(e){return e[e.length-1]}var Oe={[oe.name]:oe.rule,[ie.name]:ie.rule,[se.name]:se.rule,"rules-of-hooks":De,"exhaustive-deps":ye};var kt={rules:Oe};export{kt as extendedLintPlugin};
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@ls-stack/extended-lint",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "scripts": {
6
+ "test": "vitest run",
7
+ "test:ui": "vitest --ui",
8
+ "build": "vitest run && pnpm run build:no-test",
9
+ "build:no-test": "tsup --minify --dts",
10
+ "npm-publish": "scripts/check-if-is-sync.sh && pnpm build && npm publish --access=public"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "repository": "github:lucaslos/eslint-plugin-extended-lint",
16
+ "author": "Lucas Santos",
17
+ "main": "./dist/extended-lint.js",
18
+ "module": "./dist/extended-lint.mjs",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/extended-lint.mjs",
22
+ "require": "./dist/extended-lint.js"
23
+ }
24
+ },
25
+ "engines": {
26
+ "node": ">=20.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@ls-stack/utils": "^1.8.0",
30
+ "@types/eslint": "^9.6.1",
31
+ "@types/node": "^22.5.0",
32
+ "@typescript-eslint/parser": "^8.2.0",
33
+ "@typescript-eslint/rule-tester": "^8.2.0",
34
+ "@vitest/ui": "^2.0.5",
35
+ "eslint": "^9.9.1",
36
+ "tsm": "^2.3.0",
37
+ "tsup": "^8.2.4",
38
+ "typescript": "^5.5.4",
39
+ "vite": "^5.4.2",
40
+ "vitest": "^2.0.5"
41
+ },
42
+ "dependencies": {
43
+ "@typescript-eslint/utils": "^8.2.0",
44
+ "escape-string-regexp": "^5.0.0",
45
+ "espree": "^10.1.0",
46
+ "esutils": "^2.0.3"
47
+ },
48
+ "peerDependencies": {
49
+ "eslint": "^9.9.1"
50
+ }
51
+ }