@eslint-react/core 1.24.0-next.6 → 1.24.0-next.8
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/index.d.mts +84 -90
- package/dist/index.d.ts +84 -90
- package/dist/index.js +58 -60
- package/dist/index.mjs +54 -56
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import { _ } from '@eslint-react/eff';
|
|
3
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
4
2
|
import * as _eslint_react_shared from '@eslint-react/shared';
|
|
5
3
|
import { RuleContext, CustomComponentNormalized } from '@eslint-react/shared';
|
|
4
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
6
6
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
7
|
-
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
8
7
|
import * as birecord from 'birecord';
|
|
8
|
+
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
9
9
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
10
10
|
import { SyntaxKind } from 'typescript';
|
|
11
11
|
|
|
@@ -131,17 +131,9 @@ type ERComponentKind = "classComponent" | "functionComponent";
|
|
|
131
131
|
|
|
132
132
|
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
133
133
|
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
134
|
-
declare function
|
|
135
|
-
declare function
|
|
136
|
-
|
|
137
|
-
type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
|
|
138
|
-
type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
|
|
139
|
-
|
|
140
|
-
declare const RE_COMPONENT_NAME: RegExp;
|
|
141
|
-
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
142
|
-
declare function isComponentName(name: string): boolean;
|
|
143
|
-
|
|
144
|
-
declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
|
|
134
|
+
declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
|
|
135
|
+
declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
136
|
+
declare function isRenderMethodLike(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
145
137
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
146
138
|
/**
|
|
147
139
|
* Check whether given node is declared inside class component's render block
|
|
@@ -158,7 +150,80 @@ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
|
158
150
|
* @param node The AST node being checked
|
|
159
151
|
* @returns `true` if node is inside class component's render block, `false` if not
|
|
160
152
|
*/
|
|
161
|
-
declare function isInsideRenderMethod(node: TSESTree
|
|
153
|
+
declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
|
|
154
|
+
|
|
155
|
+
type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
|
|
156
|
+
type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
|
|
157
|
+
|
|
158
|
+
declare const RE_COMPONENT_NAME: RegExp;
|
|
159
|
+
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
160
|
+
declare function isComponentName(name: string): boolean;
|
|
161
|
+
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
162
|
+
|
|
163
|
+
type EREffectPhaseKind = "cleanup" | "setup";
|
|
164
|
+
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
165
|
+
type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
|
|
166
|
+
declare const ERPhaseRelevance: birecord.BiRecord<{
|
|
167
|
+
readonly mount: "unmount";
|
|
168
|
+
readonly setup: "cleanup";
|
|
169
|
+
}>;
|
|
170
|
+
declare const isInversePhase: {
|
|
171
|
+
(a: ERPhaseKind): (b: ERPhaseKind) => boolean;
|
|
172
|
+
(a: ERPhaseKind, b: ERPhaseKind): boolean;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Unsafe check whether given node is a render function
|
|
177
|
+
* ```jsx
|
|
178
|
+
* const renderRow = () => <div />
|
|
179
|
+
* ` ^^^^^^^^^^^^`
|
|
180
|
+
* _ = <Component renderRow={() => <div />} />
|
|
181
|
+
* ` ^^^^^^^^^^^^^ `
|
|
182
|
+
* ```
|
|
183
|
+
* @param node The AST node to check
|
|
184
|
+
* @param context The rule context
|
|
185
|
+
* @returns `true` if node is a render function, `false` if not
|
|
186
|
+
*/
|
|
187
|
+
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Unsafe check whether given JSXAttribute is a render prop
|
|
190
|
+
* ```jsx
|
|
191
|
+
* _ = <Component renderRow={() => <div />} />
|
|
192
|
+
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
193
|
+
* ```
|
|
194
|
+
* @param node The AST node to check
|
|
195
|
+
* @param context The rule context
|
|
196
|
+
* @returns `true` if node is a render prop, `false` if not
|
|
197
|
+
*/
|
|
198
|
+
declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Unsafe check whether given node is declared directly inside a render property
|
|
201
|
+
* ```jsx
|
|
202
|
+
* const rows = { render: () => <div /> }
|
|
203
|
+
* ` ^^^^^^^^^^^^^ `
|
|
204
|
+
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
205
|
+
* ` ^^^^^^^^^^^^^ `
|
|
206
|
+
* ```
|
|
207
|
+
* @internal
|
|
208
|
+
* @param node The AST node to check
|
|
209
|
+
* @returns `true` if component is declared inside a render property, `false` if not
|
|
210
|
+
*/
|
|
211
|
+
declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Unsafe check whether given node is declared inside a render prop
|
|
214
|
+
* ```jsx
|
|
215
|
+
* _ = <Component renderRow={"node"} />
|
|
216
|
+
* ` ^^^^^^ `
|
|
217
|
+
* _ = <Component rows={ [{ render: "node" }] } />
|
|
218
|
+
* ` ^^^^^^ `
|
|
219
|
+
* ```
|
|
220
|
+
* @param node The AST node to check
|
|
221
|
+
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
222
|
+
*/
|
|
223
|
+
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
224
|
+
|
|
225
|
+
type ERStateKind = "actionState" | "state";
|
|
226
|
+
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
162
227
|
|
|
163
228
|
/**
|
|
164
229
|
* Check if a node is a React class component
|
|
@@ -173,14 +238,12 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
|
|
|
173
238
|
*/
|
|
174
239
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
175
240
|
|
|
176
|
-
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
177
|
-
|
|
178
241
|
type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
|
|
179
242
|
|
|
180
|
-
declare function
|
|
181
|
-
declare function
|
|
243
|
+
declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean | undefined;
|
|
244
|
+
declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | undefined;
|
|
182
245
|
|
|
183
|
-
declare function
|
|
246
|
+
declare function getElementNameOnJsxAndHtml(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
|
|
184
247
|
|
|
185
248
|
/**
|
|
186
249
|
* Determines whether inside `createElement`'s props.
|
|
@@ -250,80 +313,11 @@ declare const isUseStateCall: (node: TSESTree.CallExpression | undefined, contex
|
|
|
250
313
|
declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
251
314
|
declare const isUseTransitionCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
252
315
|
|
|
253
|
-
declare const ERPhaseRelevance: birecord.BiRecord<{
|
|
254
|
-
readonly mount: "unmount";
|
|
255
|
-
readonly setup: "cleanup";
|
|
256
|
-
}>;
|
|
257
|
-
|
|
258
|
-
type EREffectPhaseKind = "cleanup" | "setup";
|
|
259
|
-
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
260
|
-
type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
|
|
261
|
-
|
|
262
|
-
declare const isInversePhase: {
|
|
263
|
-
(a: ERPhaseKind): (b: ERPhaseKind) => boolean;
|
|
264
|
-
(a: ERPhaseKind, b: ERPhaseKind): boolean;
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Unsafe check whether given node is declared directly inside a render property
|
|
269
|
-
* ```jsx
|
|
270
|
-
* const rows = { render: () => <div /> }
|
|
271
|
-
* ` ^^^^^^^^^^^^^ `
|
|
272
|
-
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
273
|
-
* ` ^^^^^^^^^^^^^ `
|
|
274
|
-
* ```
|
|
275
|
-
* @internal
|
|
276
|
-
* @param node The AST node to check
|
|
277
|
-
* @returns `true` if component is declared inside a render property, `false` if not
|
|
278
|
-
*/
|
|
279
|
-
declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
|
|
280
|
-
/**
|
|
281
|
-
* Unsafe check whether given node is declared inside a render prop
|
|
282
|
-
* ```jsx
|
|
283
|
-
* _ = <Component renderRow={"node"} />
|
|
284
|
-
* ` ^^^^^^ `
|
|
285
|
-
* _ = <Component rows={ [{ render: "node" }] } />
|
|
286
|
-
* ` ^^^^^^ `
|
|
287
|
-
* ```
|
|
288
|
-
* @param node The AST node to check
|
|
289
|
-
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
290
|
-
*/
|
|
291
|
-
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Unsafe check whether given node is a render function
|
|
295
|
-
* ```jsx
|
|
296
|
-
* const renderRow = () => <div />
|
|
297
|
-
* ` ^^^^^^^^^^^^`
|
|
298
|
-
* _ = <Component renderRow={() => <div />} />
|
|
299
|
-
* ` ^^^^^^^^^^^^^ `
|
|
300
|
-
* ```
|
|
301
|
-
* @param node The AST node to check
|
|
302
|
-
* @param context The rule context
|
|
303
|
-
* @returns `true` if node is a render function, `false` if not
|
|
304
|
-
*/
|
|
305
|
-
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
306
|
-
/**
|
|
307
|
-
* Unsafe check whether given JSXAttribute is a render prop
|
|
308
|
-
* ```jsx
|
|
309
|
-
* _ = <Component renderRow={() => <div />} />
|
|
310
|
-
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
311
|
-
* ```
|
|
312
|
-
* @param node The AST node to check
|
|
313
|
-
* @param context The rule context
|
|
314
|
-
* @returns `true` if node is a render prop, `false` if not
|
|
315
|
-
*/
|
|
316
|
-
declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
|
|
317
|
-
|
|
318
316
|
interface ERSemanticEntry {
|
|
319
317
|
node: TSESTree.Node;
|
|
320
318
|
phase: ERPhaseKind;
|
|
321
319
|
}
|
|
322
320
|
|
|
323
|
-
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
324
|
-
|
|
325
|
-
type ERStateKind = "actionState" | "state";
|
|
326
|
-
|
|
327
321
|
declare const getId: () => string;
|
|
328
322
|
|
|
329
323
|
/**
|
|
@@ -2578,4 +2572,4 @@ declare const isMemoCall: {
|
|
|
2578
2572
|
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2579
2573
|
};
|
|
2580
2574
|
|
|
2581
|
-
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier,
|
|
2575
|
+
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import { _ } from '@eslint-react/eff';
|
|
3
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
4
2
|
import * as _eslint_react_shared from '@eslint-react/shared';
|
|
5
3
|
import { RuleContext, CustomComponentNormalized } from '@eslint-react/shared';
|
|
4
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
6
6
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
7
|
-
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
8
7
|
import * as birecord from 'birecord';
|
|
8
|
+
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
9
9
|
import { Scope } from '@typescript-eslint/scope-manager';
|
|
10
10
|
import { SyntaxKind } from 'typescript';
|
|
11
11
|
|
|
@@ -131,17 +131,9 @@ type ERComponentKind = "classComponent" | "functionComponent";
|
|
|
131
131
|
|
|
132
132
|
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
133
133
|
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
134
|
-
declare function
|
|
135
|
-
declare function
|
|
136
|
-
|
|
137
|
-
type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
|
|
138
|
-
type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
|
|
139
|
-
|
|
140
|
-
declare const RE_COMPONENT_NAME: RegExp;
|
|
141
|
-
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
142
|
-
declare function isComponentName(name: string): boolean;
|
|
143
|
-
|
|
144
|
-
declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
|
|
134
|
+
declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
|
|
135
|
+
declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
|
|
136
|
+
declare function isRenderMethodLike(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
145
137
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
146
138
|
/**
|
|
147
139
|
* Check whether given node is declared inside class component's render block
|
|
@@ -158,7 +150,80 @@ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
|
158
150
|
* @param node The AST node being checked
|
|
159
151
|
* @returns `true` if node is inside class component's render block, `false` if not
|
|
160
152
|
*/
|
|
161
|
-
declare function isInsideRenderMethod(node: TSESTree
|
|
153
|
+
declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
|
|
154
|
+
|
|
155
|
+
type EREffectMethodKind = "useEffect" | "useInsertionEffect" | "useLayoutEffect";
|
|
156
|
+
type ERLifecycleMethodKind = "componentDidMount" | "componentWillUnmount";
|
|
157
|
+
|
|
158
|
+
declare const RE_COMPONENT_NAME: RegExp;
|
|
159
|
+
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
160
|
+
declare function isComponentName(name: string): boolean;
|
|
161
|
+
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
162
|
+
|
|
163
|
+
type EREffectPhaseKind = "cleanup" | "setup";
|
|
164
|
+
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
165
|
+
type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
|
|
166
|
+
declare const ERPhaseRelevance: birecord.BiRecord<{
|
|
167
|
+
readonly mount: "unmount";
|
|
168
|
+
readonly setup: "cleanup";
|
|
169
|
+
}>;
|
|
170
|
+
declare const isInversePhase: {
|
|
171
|
+
(a: ERPhaseKind): (b: ERPhaseKind) => boolean;
|
|
172
|
+
(a: ERPhaseKind, b: ERPhaseKind): boolean;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Unsafe check whether given node is a render function
|
|
177
|
+
* ```jsx
|
|
178
|
+
* const renderRow = () => <div />
|
|
179
|
+
* ` ^^^^^^^^^^^^`
|
|
180
|
+
* _ = <Component renderRow={() => <div />} />
|
|
181
|
+
* ` ^^^^^^^^^^^^^ `
|
|
182
|
+
* ```
|
|
183
|
+
* @param node The AST node to check
|
|
184
|
+
* @param context The rule context
|
|
185
|
+
* @returns `true` if node is a render function, `false` if not
|
|
186
|
+
*/
|
|
187
|
+
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Unsafe check whether given JSXAttribute is a render prop
|
|
190
|
+
* ```jsx
|
|
191
|
+
* _ = <Component renderRow={() => <div />} />
|
|
192
|
+
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
193
|
+
* ```
|
|
194
|
+
* @param node The AST node to check
|
|
195
|
+
* @param context The rule context
|
|
196
|
+
* @returns `true` if node is a render prop, `false` if not
|
|
197
|
+
*/
|
|
198
|
+
declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Unsafe check whether given node is declared directly inside a render property
|
|
201
|
+
* ```jsx
|
|
202
|
+
* const rows = { render: () => <div /> }
|
|
203
|
+
* ` ^^^^^^^^^^^^^ `
|
|
204
|
+
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
205
|
+
* ` ^^^^^^^^^^^^^ `
|
|
206
|
+
* ```
|
|
207
|
+
* @internal
|
|
208
|
+
* @param node The AST node to check
|
|
209
|
+
* @returns `true` if component is declared inside a render property, `false` if not
|
|
210
|
+
*/
|
|
211
|
+
declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Unsafe check whether given node is declared inside a render prop
|
|
214
|
+
* ```jsx
|
|
215
|
+
* _ = <Component renderRow={"node"} />
|
|
216
|
+
* ` ^^^^^^ `
|
|
217
|
+
* _ = <Component rows={ [{ render: "node" }] } />
|
|
218
|
+
* ` ^^^^^^ `
|
|
219
|
+
* ```
|
|
220
|
+
* @param node The AST node to check
|
|
221
|
+
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
222
|
+
*/
|
|
223
|
+
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
224
|
+
|
|
225
|
+
type ERStateKind = "actionState" | "state";
|
|
226
|
+
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
162
227
|
|
|
163
228
|
/**
|
|
164
229
|
* Check if a node is a React class component
|
|
@@ -173,14 +238,12 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
|
|
|
173
238
|
*/
|
|
174
239
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
175
240
|
|
|
176
|
-
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
177
|
-
|
|
178
241
|
type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
|
|
179
242
|
|
|
180
|
-
declare function
|
|
181
|
-
declare function
|
|
243
|
+
declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean | undefined;
|
|
244
|
+
declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | undefined;
|
|
182
245
|
|
|
183
|
-
declare function
|
|
246
|
+
declare function getElementNameOnJsxAndHtml(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
|
|
184
247
|
|
|
185
248
|
/**
|
|
186
249
|
* Determines whether inside `createElement`'s props.
|
|
@@ -250,80 +313,11 @@ declare const isUseStateCall: (node: TSESTree.CallExpression | undefined, contex
|
|
|
250
313
|
declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
251
314
|
declare const isUseTransitionCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
252
315
|
|
|
253
|
-
declare const ERPhaseRelevance: birecord.BiRecord<{
|
|
254
|
-
readonly mount: "unmount";
|
|
255
|
-
readonly setup: "cleanup";
|
|
256
|
-
}>;
|
|
257
|
-
|
|
258
|
-
type EREffectPhaseKind = "cleanup" | "setup";
|
|
259
|
-
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
260
|
-
type ERPhaseKind = EREffectPhaseKind | ERLifecyclePhaseKind;
|
|
261
|
-
|
|
262
|
-
declare const isInversePhase: {
|
|
263
|
-
(a: ERPhaseKind): (b: ERPhaseKind) => boolean;
|
|
264
|
-
(a: ERPhaseKind, b: ERPhaseKind): boolean;
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Unsafe check whether given node is declared directly inside a render property
|
|
269
|
-
* ```jsx
|
|
270
|
-
* const rows = { render: () => <div /> }
|
|
271
|
-
* ` ^^^^^^^^^^^^^ `
|
|
272
|
-
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
273
|
-
* ` ^^^^^^^^^^^^^ `
|
|
274
|
-
* ```
|
|
275
|
-
* @internal
|
|
276
|
-
* @param node The AST node to check
|
|
277
|
-
* @returns `true` if component is declared inside a render property, `false` if not
|
|
278
|
-
*/
|
|
279
|
-
declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolean;
|
|
280
|
-
/**
|
|
281
|
-
* Unsafe check whether given node is declared inside a render prop
|
|
282
|
-
* ```jsx
|
|
283
|
-
* _ = <Component renderRow={"node"} />
|
|
284
|
-
* ` ^^^^^^ `
|
|
285
|
-
* _ = <Component rows={ [{ render: "node" }] } />
|
|
286
|
-
* ` ^^^^^^ `
|
|
287
|
-
* ```
|
|
288
|
-
* @param node The AST node to check
|
|
289
|
-
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
290
|
-
*/
|
|
291
|
-
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Unsafe check whether given node is a render function
|
|
295
|
-
* ```jsx
|
|
296
|
-
* const renderRow = () => <div />
|
|
297
|
-
* ` ^^^^^^^^^^^^`
|
|
298
|
-
* _ = <Component renderRow={() => <div />} />
|
|
299
|
-
* ` ^^^^^^^^^^^^^ `
|
|
300
|
-
* ```
|
|
301
|
-
* @param node The AST node to check
|
|
302
|
-
* @param context The rule context
|
|
303
|
-
* @returns `true` if node is a render function, `false` if not
|
|
304
|
-
*/
|
|
305
|
-
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
306
|
-
/**
|
|
307
|
-
* Unsafe check whether given JSXAttribute is a render prop
|
|
308
|
-
* ```jsx
|
|
309
|
-
* _ = <Component renderRow={() => <div />} />
|
|
310
|
-
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
311
|
-
* ```
|
|
312
|
-
* @param node The AST node to check
|
|
313
|
-
* @param context The rule context
|
|
314
|
-
* @returns `true` if node is a render prop, `false` if not
|
|
315
|
-
*/
|
|
316
|
-
declare function isRenderPropLoose(node: TSESTree.JSXAttribute, context: RuleContext): boolean;
|
|
317
|
-
|
|
318
316
|
interface ERSemanticEntry {
|
|
319
317
|
node: TSESTree.Node;
|
|
320
318
|
phase: ERPhaseKind;
|
|
321
319
|
}
|
|
322
320
|
|
|
323
|
-
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
324
|
-
|
|
325
|
-
type ERStateKind = "actionState" | "state";
|
|
326
|
-
|
|
327
321
|
declare const getId: () => string;
|
|
328
322
|
|
|
329
323
|
/**
|
|
@@ -2578,4 +2572,4 @@ declare const isMemoCall: {
|
|
|
2578
2572
|
(node: Node, context: _eslint_react_shared.RuleContext): node is CallExpression;
|
|
2579
2573
|
};
|
|
2580
2574
|
|
|
2581
|
-
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier,
|
|
2575
|
+
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -34,22 +34,22 @@ var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
|
34
34
|
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
35
35
|
|
|
36
36
|
// src/component/component-collector.ts
|
|
37
|
-
function
|
|
37
|
+
function getElementNameOnJsxAndHtml(node, context, polymorphicPropName, additionalComponents = []) {
|
|
38
38
|
const name = JSX4__namespace.getElementName(node);
|
|
39
39
|
if (name === name.toLowerCase()) return [name, name];
|
|
40
40
|
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
41
41
|
if (component != null) return [name, component.as];
|
|
42
42
|
if (polymorphicPropName == null) return [name, name];
|
|
43
43
|
const initialScope = context.sourceCode.getScope(node);
|
|
44
|
-
const
|
|
44
|
+
const attributeNode = JSX4__namespace.getAttributeNode(
|
|
45
45
|
polymorphicPropName,
|
|
46
46
|
initialScope,
|
|
47
47
|
node.attributes
|
|
48
48
|
);
|
|
49
|
-
if (
|
|
50
|
-
const
|
|
51
|
-
if (typeof
|
|
52
|
-
return [name,
|
|
49
|
+
if (attributeNode == null) return [name, name];
|
|
50
|
+
const polymorphicPropValue = VAR__namespace.toResolved(JSX4__namespace.getAttributeStaticValue(attributeNode, initialScope)).value;
|
|
51
|
+
if (typeof polymorphicPropValue === "string") {
|
|
52
|
+
return [name, polymorphicPropValue];
|
|
53
53
|
}
|
|
54
54
|
return [name, name];
|
|
55
55
|
}
|
|
@@ -393,14 +393,6 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
393
393
|
}
|
|
394
394
|
return eff._;
|
|
395
395
|
}
|
|
396
|
-
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
397
|
-
function getComponentNameFromIdentifier(node) {
|
|
398
|
-
if (node == null) return eff._;
|
|
399
|
-
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
400
|
-
}
|
|
401
|
-
function isComponentName(name) {
|
|
402
|
-
return RE_COMPONENT_NAME.test(name);
|
|
403
|
-
}
|
|
404
396
|
function isClassComponent(node) {
|
|
405
397
|
if ("superClass" in node && node.superClass != null) {
|
|
406
398
|
const re = /^(?:Pure)?Component$/u;
|
|
@@ -426,7 +418,19 @@ function isPureComponent(node) {
|
|
|
426
418
|
return false;
|
|
427
419
|
}
|
|
428
420
|
|
|
429
|
-
// src/component/component-
|
|
421
|
+
// src/component/component-lifecycle.ts
|
|
422
|
+
function isComponentDidMount(node) {
|
|
423
|
+
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
424
|
+
}
|
|
425
|
+
function isComponentWillUnmount(node) {
|
|
426
|
+
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
427
|
+
}
|
|
428
|
+
function isFunctionOfComponentDidMount(node) {
|
|
429
|
+
return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
430
|
+
}
|
|
431
|
+
function isFunctionOfComponentWillUnmount(node) {
|
|
432
|
+
return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
433
|
+
}
|
|
430
434
|
function isRenderMethodLike(node) {
|
|
431
435
|
return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration;
|
|
432
436
|
}
|
|
@@ -439,8 +443,14 @@ function isFunctionOfRenderMethod(node) {
|
|
|
439
443
|
function isInsideRenderMethod(node) {
|
|
440
444
|
return AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
441
445
|
}
|
|
442
|
-
|
|
443
|
-
|
|
446
|
+
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
447
|
+
function getComponentNameFromIdentifier(node) {
|
|
448
|
+
if (node == null) return eff._;
|
|
449
|
+
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
450
|
+
}
|
|
451
|
+
function isComponentName(name) {
|
|
452
|
+
return RE_COMPONENT_NAME.test(name);
|
|
453
|
+
}
|
|
444
454
|
function hasNoneOrValidComponentName(node, context) {
|
|
445
455
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
446
456
|
if (id2 == null) return true;
|
|
@@ -643,49 +653,11 @@ function useComponentCollectorLegacy() {
|
|
|
643
653
|
};
|
|
644
654
|
return { ctx, listeners };
|
|
645
655
|
}
|
|
646
|
-
function isComponentDidMount(node) {
|
|
647
|
-
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
648
|
-
}
|
|
649
|
-
function isComponentWillUnmount(node) {
|
|
650
|
-
return AST8__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
651
|
-
}
|
|
652
|
-
function isComponentDidMountFunction(node) {
|
|
653
|
-
return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
654
|
-
}
|
|
655
|
-
function isComponentWillUnmountFunction(node) {
|
|
656
|
-
return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
657
|
-
}
|
|
658
|
-
function isSetupFunction(node) {
|
|
659
|
-
if (node == null) return eff._;
|
|
660
|
-
return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
661
|
-
}
|
|
662
|
-
function isCleanupFunction(node) {
|
|
663
|
-
const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
664
|
-
const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
|
|
665
|
-
const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
|
|
666
|
-
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
667
|
-
}
|
|
668
656
|
var ERPhaseRelevance = birecord__default.default({
|
|
669
657
|
mount: "unmount",
|
|
670
658
|
setup: "cleanup"
|
|
671
659
|
});
|
|
672
660
|
var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
673
|
-
function isDirectValueOfRenderPropertyLoose(node) {
|
|
674
|
-
const matching = (node2) => {
|
|
675
|
-
return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
676
|
-
};
|
|
677
|
-
return matching(node) || node.parent != null && matching(node.parent);
|
|
678
|
-
}
|
|
679
|
-
function isDeclaredInRenderPropLoose(node) {
|
|
680
|
-
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
681
|
-
return true;
|
|
682
|
-
}
|
|
683
|
-
const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
684
|
-
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
688
|
-
}
|
|
689
661
|
function isRenderFunctionLoose(node, context) {
|
|
690
662
|
const { body, parent } = node;
|
|
691
663
|
if (AST8__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
@@ -705,10 +677,36 @@ function isRenderPropLoose(node, context) {
|
|
|
705
677
|
}
|
|
706
678
|
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST8__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
|
|
707
679
|
}
|
|
680
|
+
function isDirectValueOfRenderPropertyLoose(node) {
|
|
681
|
+
const matching = (node2) => {
|
|
682
|
+
return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
683
|
+
};
|
|
684
|
+
return matching(node) || node.parent != null && matching(node.parent);
|
|
685
|
+
}
|
|
686
|
+
function isDeclaredInRenderPropLoose(node) {
|
|
687
|
+
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
691
|
+
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
695
|
+
}
|
|
708
696
|
function isThisSetState(node) {
|
|
709
697
|
const { callee } = node;
|
|
710
698
|
return callee.type === types.AST_NODE_TYPES.MemberExpression && AST8__namespace.isThisExpression(callee.object) && callee.property.type === types.AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
711
699
|
}
|
|
700
|
+
function isFunctionOfUseEffectSetup(node) {
|
|
701
|
+
if (node == null) return eff._;
|
|
702
|
+
return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
703
|
+
}
|
|
704
|
+
function isFunctionOfUseEffectCleanup(node) {
|
|
705
|
+
const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
706
|
+
const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
|
|
707
|
+
const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
|
|
708
|
+
return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
|
|
709
|
+
}
|
|
712
710
|
|
|
713
711
|
exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
|
|
714
712
|
exports.ERClassComponentFlag = ERClassComponentFlag;
|
|
@@ -718,7 +716,7 @@ exports.ERPhaseRelevance = ERPhaseRelevance;
|
|
|
718
716
|
exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
719
717
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
720
718
|
exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
|
|
721
|
-
exports.
|
|
719
|
+
exports.getElementNameOnJsxAndHtml = getElementNameOnJsxAndHtml;
|
|
722
720
|
exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
723
721
|
exports.getId = getId;
|
|
724
722
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
@@ -736,14 +734,11 @@ exports.isChildrenOnlyCall = isChildrenOnlyCall;
|
|
|
736
734
|
exports.isChildrenToArray = isChildrenToArray;
|
|
737
735
|
exports.isChildrenToArrayCall = isChildrenToArrayCall;
|
|
738
736
|
exports.isClassComponent = isClassComponent;
|
|
739
|
-
exports.isCleanupFunction = isCleanupFunction;
|
|
740
737
|
exports.isCloneElement = isCloneElement;
|
|
741
738
|
exports.isCloneElementCall = isCloneElementCall;
|
|
742
739
|
exports.isComponentDidMount = isComponentDidMount;
|
|
743
|
-
exports.isComponentDidMountFunction = isComponentDidMountFunction;
|
|
744
740
|
exports.isComponentName = isComponentName;
|
|
745
741
|
exports.isComponentWillUnmount = isComponentWillUnmount;
|
|
746
|
-
exports.isComponentWillUnmountFunction = isComponentWillUnmountFunction;
|
|
747
742
|
exports.isCreateContext = isCreateContext;
|
|
748
743
|
exports.isCreateContextCall = isCreateContextCall;
|
|
749
744
|
exports.isCreateElement = isCreateElement;
|
|
@@ -756,7 +751,11 @@ exports.isForwardRef = isForwardRef;
|
|
|
756
751
|
exports.isForwardRefCall = isForwardRefCall;
|
|
757
752
|
exports.isFromReact = isFromReact;
|
|
758
753
|
exports.isFromReactMember = isFromReactMember;
|
|
754
|
+
exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
|
|
755
|
+
exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
|
|
759
756
|
exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
|
|
757
|
+
exports.isFunctionOfUseEffectCleanup = isFunctionOfUseEffectCleanup;
|
|
758
|
+
exports.isFunctionOfUseEffectSetup = isFunctionOfUseEffectSetup;
|
|
760
759
|
exports.isInitializedFromReact = isInitializedFromReact;
|
|
761
760
|
exports.isInsideCreateElementProps = isInsideCreateElementProps;
|
|
762
761
|
exports.isInsideReactHook = isInsideReactHook;
|
|
@@ -776,7 +775,6 @@ exports.isReactHookName = isReactHookName;
|
|
|
776
775
|
exports.isRenderFunctionLoose = isRenderFunctionLoose;
|
|
777
776
|
exports.isRenderMethodLike = isRenderMethodLike;
|
|
778
777
|
exports.isRenderPropLoose = isRenderPropLoose;
|
|
779
|
-
exports.isSetupFunction = isSetupFunction;
|
|
780
778
|
exports.isThisSetState = isThisSetState;
|
|
781
779
|
exports.isUseCallbackCall = isUseCallbackCall;
|
|
782
780
|
exports.isUseContextCall = isUseContextCall;
|
package/dist/index.mjs
CHANGED
|
@@ -7,22 +7,22 @@ import { unsafeDecodeSettings } from '@eslint-react/shared';
|
|
|
7
7
|
import birecord from 'birecord';
|
|
8
8
|
|
|
9
9
|
// src/component/component-collector.ts
|
|
10
|
-
function
|
|
10
|
+
function getElementNameOnJsxAndHtml(node, context, polymorphicPropName, additionalComponents = []) {
|
|
11
11
|
const name = JSX4.getElementName(node);
|
|
12
12
|
if (name === name.toLowerCase()) return [name, name];
|
|
13
13
|
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
14
14
|
if (component != null) return [name, component.as];
|
|
15
15
|
if (polymorphicPropName == null) return [name, name];
|
|
16
16
|
const initialScope = context.sourceCode.getScope(node);
|
|
17
|
-
const
|
|
17
|
+
const attributeNode = JSX4.getAttributeNode(
|
|
18
18
|
polymorphicPropName,
|
|
19
19
|
initialScope,
|
|
20
20
|
node.attributes
|
|
21
21
|
);
|
|
22
|
-
if (
|
|
23
|
-
const
|
|
24
|
-
if (typeof
|
|
25
|
-
return [name,
|
|
22
|
+
if (attributeNode == null) return [name, name];
|
|
23
|
+
const polymorphicPropValue = VAR.toResolved(JSX4.getAttributeStaticValue(attributeNode, initialScope)).value;
|
|
24
|
+
if (typeof polymorphicPropValue === "string") {
|
|
25
|
+
return [name, polymorphicPropValue];
|
|
26
26
|
}
|
|
27
27
|
return [name, name];
|
|
28
28
|
}
|
|
@@ -366,14 +366,6 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
366
366
|
}
|
|
367
367
|
return _;
|
|
368
368
|
}
|
|
369
|
-
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
370
|
-
function getComponentNameFromIdentifier(node) {
|
|
371
|
-
if (node == null) return _;
|
|
372
|
-
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
373
|
-
}
|
|
374
|
-
function isComponentName(name) {
|
|
375
|
-
return RE_COMPONENT_NAME.test(name);
|
|
376
|
-
}
|
|
377
369
|
function isClassComponent(node) {
|
|
378
370
|
if ("superClass" in node && node.superClass != null) {
|
|
379
371
|
const re = /^(?:Pure)?Component$/u;
|
|
@@ -399,7 +391,19 @@ function isPureComponent(node) {
|
|
|
399
391
|
return false;
|
|
400
392
|
}
|
|
401
393
|
|
|
402
|
-
// src/component/component-
|
|
394
|
+
// src/component/component-lifecycle.ts
|
|
395
|
+
function isComponentDidMount(node) {
|
|
396
|
+
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
397
|
+
}
|
|
398
|
+
function isComponentWillUnmount(node) {
|
|
399
|
+
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
400
|
+
}
|
|
401
|
+
function isFunctionOfComponentDidMount(node) {
|
|
402
|
+
return AST8.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
403
|
+
}
|
|
404
|
+
function isFunctionOfComponentWillUnmount(node) {
|
|
405
|
+
return AST8.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
406
|
+
}
|
|
403
407
|
function isRenderMethodLike(node) {
|
|
404
408
|
return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
|
|
405
409
|
}
|
|
@@ -412,8 +416,14 @@ function isFunctionOfRenderMethod(node) {
|
|
|
412
416
|
function isInsideRenderMethod(node) {
|
|
413
417
|
return AST8.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
414
418
|
}
|
|
415
|
-
|
|
416
|
-
|
|
419
|
+
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
420
|
+
function getComponentNameFromIdentifier(node) {
|
|
421
|
+
if (node == null) return _;
|
|
422
|
+
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
423
|
+
}
|
|
424
|
+
function isComponentName(name) {
|
|
425
|
+
return RE_COMPONENT_NAME.test(name);
|
|
426
|
+
}
|
|
417
427
|
function hasNoneOrValidComponentName(node, context) {
|
|
418
428
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
419
429
|
if (id2 == null) return true;
|
|
@@ -616,49 +626,11 @@ function useComponentCollectorLegacy() {
|
|
|
616
626
|
};
|
|
617
627
|
return { ctx, listeners };
|
|
618
628
|
}
|
|
619
|
-
function isComponentDidMount(node) {
|
|
620
|
-
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
621
|
-
}
|
|
622
|
-
function isComponentWillUnmount(node) {
|
|
623
|
-
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
624
|
-
}
|
|
625
|
-
function isComponentDidMountFunction(node) {
|
|
626
|
-
return AST8.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
627
|
-
}
|
|
628
|
-
function isComponentWillUnmountFunction(node) {
|
|
629
|
-
return AST8.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
630
|
-
}
|
|
631
|
-
function isSetupFunction(node) {
|
|
632
|
-
if (node == null) return _;
|
|
633
|
-
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
634
|
-
}
|
|
635
|
-
function isCleanupFunction(node) {
|
|
636
|
-
const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
|
|
637
|
-
const nearFunction = AST8.findParentNode(node, AST8.isFunction);
|
|
638
|
-
const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
|
|
639
|
-
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
640
|
-
}
|
|
641
629
|
var ERPhaseRelevance = birecord({
|
|
642
630
|
mount: "unmount",
|
|
643
631
|
setup: "cleanup"
|
|
644
632
|
});
|
|
645
633
|
var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
646
|
-
function isDirectValueOfRenderPropertyLoose(node) {
|
|
647
|
-
const matching = (node2) => {
|
|
648
|
-
return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
649
|
-
};
|
|
650
|
-
return matching(node) || node.parent != null && matching(node.parent);
|
|
651
|
-
}
|
|
652
|
-
function isDeclaredInRenderPropLoose(node) {
|
|
653
|
-
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
654
|
-
return true;
|
|
655
|
-
}
|
|
656
|
-
const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
657
|
-
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
658
|
-
return false;
|
|
659
|
-
}
|
|
660
|
-
return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
661
|
-
}
|
|
662
634
|
function isRenderFunctionLoose(node, context) {
|
|
663
635
|
const { body, parent } = node;
|
|
664
636
|
if (AST8.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
@@ -678,9 +650,35 @@ function isRenderPropLoose(node, context) {
|
|
|
678
650
|
}
|
|
679
651
|
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST8.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
|
|
680
652
|
}
|
|
653
|
+
function isDirectValueOfRenderPropertyLoose(node) {
|
|
654
|
+
const matching = (node2) => {
|
|
655
|
+
return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
656
|
+
};
|
|
657
|
+
return matching(node) || node.parent != null && matching(node.parent);
|
|
658
|
+
}
|
|
659
|
+
function isDeclaredInRenderPropLoose(node) {
|
|
660
|
+
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
664
|
+
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
668
|
+
}
|
|
681
669
|
function isThisSetState(node) {
|
|
682
670
|
const { callee } = node;
|
|
683
671
|
return callee.type === AST_NODE_TYPES.MemberExpression && AST8.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
684
672
|
}
|
|
673
|
+
function isFunctionOfUseEffectSetup(node) {
|
|
674
|
+
if (node == null) return _;
|
|
675
|
+
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
676
|
+
}
|
|
677
|
+
function isFunctionOfUseEffectCleanup(node) {
|
|
678
|
+
const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
|
|
679
|
+
const nearFunction = AST8.findParentNode(node, AST8.isFunction);
|
|
680
|
+
const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
|
|
681
|
+
return nearFunction === nearFunctionOfReturn && isFunctionOfUseEffectSetup(nearFunction);
|
|
682
|
+
}
|
|
685
683
|
|
|
686
|
-
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier,
|
|
684
|
+
export { DEFAULT_COMPONENT_HINT, ERClassComponentFlag, ERComponentHint, ERFunctionComponentFlag, ERPhaseRelevance, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameOnJsxAndHtml, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentName, isComponentWillUnmount, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfComponentDidMount, isFunctionOfComponentWillUnmount, isFunctionOfRenderMethod, isFunctionOfUseEffectCleanup, isFunctionOfUseEffectSetup, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.24.0-next.
|
|
3
|
+
"version": "1.24.0-next.8",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"./package.json"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
37
|
-
"@typescript-eslint/type-utils": "^8.
|
|
38
|
-
"@typescript-eslint/types": "^8.
|
|
39
|
-
"@typescript-eslint/utils": "^8.
|
|
36
|
+
"@typescript-eslint/scope-manager": "^8.20.0",
|
|
37
|
+
"@typescript-eslint/type-utils": "^8.20.0",
|
|
38
|
+
"@typescript-eslint/types": "^8.20.0",
|
|
39
|
+
"@typescript-eslint/utils": "^8.20.0",
|
|
40
40
|
"birecord": "^0.1.1",
|
|
41
41
|
"ts-pattern": "^5.6.0",
|
|
42
|
-
"@eslint-react/eff": "1.24.0-next.
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/shared": "1.24.0-next.
|
|
46
|
-
"@eslint-react/var": "1.24.0-next.
|
|
42
|
+
"@eslint-react/eff": "1.24.0-next.8",
|
|
43
|
+
"@eslint-react/ast": "1.24.0-next.8",
|
|
44
|
+
"@eslint-react/jsx": "1.24.0-next.8",
|
|
45
|
+
"@eslint-react/shared": "1.24.0-next.8",
|
|
46
|
+
"@eslint-react/var": "1.24.0-next.8"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.3.5",
|