@eslint-react/core 1.24.0-beta.5 → 1.24.0-beta.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 +86 -92
- package/dist/index.d.ts +86 -92
- package/dist/index.js +63 -61
- package/dist/index.mjs +56 -57
- package/package.json +11 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import * as _eslint_react_eff from '@eslint-react/eff';
|
|
3
|
-
import { _ } from '@eslint-react/eff';
|
|
4
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
5
2
|
import * as _eslint_react_shared from '@eslint-react/shared';
|
|
6
3
|
import { RuleContext, CustomComponentNormalized } from '@eslint-react/shared';
|
|
4
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
7
6
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
7
|
+
import * as birecord from 'birecord';
|
|
8
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';
|
|
@@ -129,14 +129,11 @@ declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, cont
|
|
|
129
129
|
|
|
130
130
|
type ERComponentKind = "classComponent" | "functionComponent";
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
declare
|
|
136
|
-
declare function
|
|
137
|
-
declare function isComponentName(name: string): boolean;
|
|
138
|
-
|
|
139
|
-
declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
|
|
132
|
+
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
133
|
+
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.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;
|
|
140
137
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
141
138
|
/**
|
|
142
139
|
* Check whether given node is declared inside class component's render block
|
|
@@ -153,7 +150,80 @@ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
|
153
150
|
* @param node The AST node being checked
|
|
154
151
|
* @returns `true` if node is inside class component's render block, `false` if not
|
|
155
152
|
*/
|
|
156
|
-
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;
|
|
157
227
|
|
|
158
228
|
/**
|
|
159
229
|
* Check if a node is a React class component
|
|
@@ -168,14 +238,12 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
|
|
|
168
238
|
*/
|
|
169
239
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
170
240
|
|
|
171
|
-
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
172
|
-
|
|
173
241
|
type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
|
|
174
242
|
|
|
175
|
-
declare function
|
|
176
|
-
declare function
|
|
243
|
+
declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean | undefined;
|
|
244
|
+
declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | undefined;
|
|
177
245
|
|
|
178
|
-
declare function
|
|
246
|
+
declare function getElementNameOnJsxAndHtml(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
|
|
179
247
|
|
|
180
248
|
/**
|
|
181
249
|
* Determines whether inside `createElement`'s props.
|
|
@@ -245,85 +313,11 @@ declare const isUseStateCall: (node: TSESTree.CallExpression | undefined, contex
|
|
|
245
313
|
declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
246
314
|
declare const isUseTransitionCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
247
315
|
|
|
248
|
-
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
249
|
-
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
250
|
-
declare function isComponentDidMountFunction(node: TSESTree.Node): boolean;
|
|
251
|
-
declare function isComponentWillUnmountFunction(node: TSESTree.Node): boolean;
|
|
252
|
-
|
|
253
|
-
declare const ERPhaseRelevance: _eslint_react_eff.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,10 +1,10 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import * as _eslint_react_eff from '@eslint-react/eff';
|
|
3
|
-
import { _ } from '@eslint-react/eff';
|
|
4
|
-
import { TSESTree } from '@typescript-eslint/types';
|
|
5
2
|
import * as _eslint_react_shared from '@eslint-react/shared';
|
|
6
3
|
import { RuleContext, CustomComponentNormalized } from '@eslint-react/shared';
|
|
4
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
7
6
|
import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
7
|
+
import * as birecord from 'birecord';
|
|
8
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';
|
|
@@ -129,14 +129,11 @@ declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction, cont
|
|
|
129
129
|
|
|
130
130
|
type ERComponentKind = "classComponent" | "functionComponent";
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
declare
|
|
136
|
-
declare function
|
|
137
|
-
declare function isComponentName(name: string): boolean;
|
|
138
|
-
|
|
139
|
-
declare function isRenderMethodLike(node: TSESTree$1.Node): node is TSESTree$1.MethodDefinition | TSESTree$1.PropertyDefinition;
|
|
132
|
+
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
133
|
+
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.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;
|
|
140
137
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
141
138
|
/**
|
|
142
139
|
* Check whether given node is declared inside class component's render block
|
|
@@ -153,7 +150,80 @@ declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
|
153
150
|
* @param node The AST node being checked
|
|
154
151
|
* @returns `true` if node is inside class component's render block, `false` if not
|
|
155
152
|
*/
|
|
156
|
-
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;
|
|
157
227
|
|
|
158
228
|
/**
|
|
159
229
|
* Check if a node is a React class component
|
|
@@ -168,14 +238,12 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
|
|
|
168
238
|
*/
|
|
169
239
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
170
240
|
|
|
171
|
-
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction, context: RuleContext): boolean;
|
|
172
|
-
|
|
173
241
|
type EREffectKind = "effect" | "insertionEffect" | "layoutEffect";
|
|
174
242
|
|
|
175
|
-
declare function
|
|
176
|
-
declare function
|
|
243
|
+
declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | _): boolean | undefined;
|
|
244
|
+
declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | undefined;
|
|
177
245
|
|
|
178
|
-
declare function
|
|
246
|
+
declare function getElementNameOnJsxAndHtml(node: TSESTree.JSXOpeningElement, context: RuleContext, polymorphicPropName?: string, additionalComponents?: CustomComponentNormalized[]): [string, string];
|
|
179
247
|
|
|
180
248
|
/**
|
|
181
249
|
* Determines whether inside `createElement`'s props.
|
|
@@ -245,85 +313,11 @@ declare const isUseStateCall: (node: TSESTree.CallExpression | undefined, contex
|
|
|
245
313
|
declare const isUseSyncExternalStoreCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
246
314
|
declare const isUseTransitionCall: (node: TSESTree.CallExpression | undefined, context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>) => boolean;
|
|
247
315
|
|
|
248
|
-
declare function isComponentDidMount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
249
|
-
declare function isComponentWillUnmount(node: TSESTree.Node): node is TSESTree.MethodDefinition | TSESTree.PropertyDefinition;
|
|
250
|
-
declare function isComponentDidMountFunction(node: TSESTree.Node): boolean;
|
|
251
|
-
declare function isComponentWillUnmountFunction(node: TSESTree.Node): boolean;
|
|
252
|
-
|
|
253
|
-
declare const ERPhaseRelevance: _eslint_react_eff.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
|
@@ -6,6 +6,9 @@ var JSX4 = require('@eslint-react/jsx');
|
|
|
6
6
|
var types = require('@typescript-eslint/types');
|
|
7
7
|
var VAR = require('@eslint-react/var');
|
|
8
8
|
var shared = require('@eslint-react/shared');
|
|
9
|
+
var birecord = require('birecord');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
12
|
|
|
10
13
|
function _interopNamespace(e) {
|
|
11
14
|
if (e && e.__esModule) return e;
|
|
@@ -28,24 +31,25 @@ function _interopNamespace(e) {
|
|
|
28
31
|
var AST8__namespace = /*#__PURE__*/_interopNamespace(AST8);
|
|
29
32
|
var JSX4__namespace = /*#__PURE__*/_interopNamespace(JSX4);
|
|
30
33
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
34
|
+
var birecord__default = /*#__PURE__*/_interopDefault(birecord);
|
|
31
35
|
|
|
32
36
|
// src/component/component-collector.ts
|
|
33
|
-
function
|
|
37
|
+
function getElementNameOnJsxAndHtml(node, context, polymorphicPropName, additionalComponents = []) {
|
|
34
38
|
const name = JSX4__namespace.getElementName(node);
|
|
35
39
|
if (name === name.toLowerCase()) return [name, name];
|
|
36
40
|
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
37
41
|
if (component != null) return [name, component.as];
|
|
38
42
|
if (polymorphicPropName == null) return [name, name];
|
|
39
43
|
const initialScope = context.sourceCode.getScope(node);
|
|
40
|
-
const
|
|
44
|
+
const attributeNode = JSX4__namespace.getAttributeNode(
|
|
41
45
|
polymorphicPropName,
|
|
42
46
|
initialScope,
|
|
43
47
|
node.attributes
|
|
44
48
|
);
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
47
|
-
if (typeof
|
|
48
|
-
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];
|
|
49
53
|
}
|
|
50
54
|
return [name, name];
|
|
51
55
|
}
|
|
@@ -389,14 +393,6 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
389
393
|
}
|
|
390
394
|
return eff._;
|
|
391
395
|
}
|
|
392
|
-
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
393
|
-
function getComponentNameFromIdentifier(node) {
|
|
394
|
-
if (node == null) return eff._;
|
|
395
|
-
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
396
|
-
}
|
|
397
|
-
function isComponentName(name) {
|
|
398
|
-
return RE_COMPONENT_NAME.test(name);
|
|
399
|
-
}
|
|
400
396
|
function isClassComponent(node) {
|
|
401
397
|
if ("superClass" in node && node.superClass != null) {
|
|
402
398
|
const re = /^(?:Pure)?Component$/u;
|
|
@@ -422,7 +418,19 @@ function isPureComponent(node) {
|
|
|
422
418
|
return false;
|
|
423
419
|
}
|
|
424
420
|
|
|
425
|
-
// 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
|
+
}
|
|
426
434
|
function isRenderMethodLike(node) {
|
|
427
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;
|
|
428
436
|
}
|
|
@@ -435,8 +443,14 @@ function isFunctionOfRenderMethod(node) {
|
|
|
435
443
|
function isInsideRenderMethod(node) {
|
|
436
444
|
return AST8__namespace.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
437
445
|
}
|
|
438
|
-
|
|
439
|
-
|
|
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
|
+
}
|
|
440
454
|
function hasNoneOrValidComponentName(node, context) {
|
|
441
455
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
442
456
|
if (id2 == null) return true;
|
|
@@ -639,49 +653,11 @@ function useComponentCollectorLegacy() {
|
|
|
639
653
|
};
|
|
640
654
|
return { ctx, listeners };
|
|
641
655
|
}
|
|
642
|
-
|
|
643
|
-
if (node == null) return eff._;
|
|
644
|
-
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);
|
|
645
|
-
}
|
|
646
|
-
function isCleanupFunction(node) {
|
|
647
|
-
const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
648
|
-
const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
|
|
649
|
-
const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
|
|
650
|
-
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
651
|
-
}
|
|
652
|
-
function isComponentDidMount(node) {
|
|
653
|
-
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";
|
|
654
|
-
}
|
|
655
|
-
function isComponentWillUnmount(node) {
|
|
656
|
-
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";
|
|
657
|
-
}
|
|
658
|
-
function isComponentDidMountFunction(node) {
|
|
659
|
-
return AST8__namespace.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
660
|
-
}
|
|
661
|
-
function isComponentWillUnmountFunction(node) {
|
|
662
|
-
return AST8__namespace.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
663
|
-
}
|
|
664
|
-
var ERPhaseRelevance = eff.birecord({
|
|
656
|
+
var ERPhaseRelevance = birecord__default.default({
|
|
665
657
|
mount: "unmount",
|
|
666
658
|
setup: "cleanup"
|
|
667
659
|
});
|
|
668
660
|
var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
669
|
-
function isDirectValueOfRenderPropertyLoose(node) {
|
|
670
|
-
const matching = (node2) => {
|
|
671
|
-
return node2.type === types.AST_NODE_TYPES.Property && node2.key.type === types.AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
672
|
-
};
|
|
673
|
-
return matching(node) || node.parent != null && matching(node.parent);
|
|
674
|
-
}
|
|
675
|
-
function isDeclaredInRenderPropLoose(node) {
|
|
676
|
-
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
677
|
-
return true;
|
|
678
|
-
}
|
|
679
|
-
const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
680
|
-
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
|
-
return parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
684
|
-
}
|
|
685
661
|
function isRenderFunctionLoose(node, context) {
|
|
686
662
|
const { body, parent } = node;
|
|
687
663
|
if (AST8__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
@@ -701,10 +677,36 @@ function isRenderPropLoose(node, context) {
|
|
|
701
677
|
}
|
|
702
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);
|
|
703
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
|
+
}
|
|
704
696
|
function isThisSetState(node) {
|
|
705
697
|
const { callee } = node;
|
|
706
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";
|
|
707
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
|
+
}
|
|
708
710
|
|
|
709
711
|
exports.DEFAULT_COMPONENT_HINT = DEFAULT_COMPONENT_HINT;
|
|
710
712
|
exports.ERClassComponentFlag = ERClassComponentFlag;
|
|
@@ -714,7 +716,7 @@ exports.ERPhaseRelevance = ERPhaseRelevance;
|
|
|
714
716
|
exports.RE_COMPONENT_NAME = RE_COMPONENT_NAME;
|
|
715
717
|
exports.RE_HOOK_NAME = RE_HOOK_NAME;
|
|
716
718
|
exports.getComponentNameFromIdentifier = getComponentNameFromIdentifier;
|
|
717
|
-
exports.
|
|
719
|
+
exports.getElementNameOnJsxAndHtml = getElementNameOnJsxAndHtml;
|
|
718
720
|
exports.getFunctionComponentIdentifier = getFunctionComponentIdentifier;
|
|
719
721
|
exports.getId = getId;
|
|
720
722
|
exports.hasNoneOrValidComponentName = hasNoneOrValidComponentName;
|
|
@@ -732,14 +734,11 @@ exports.isChildrenOnlyCall = isChildrenOnlyCall;
|
|
|
732
734
|
exports.isChildrenToArray = isChildrenToArray;
|
|
733
735
|
exports.isChildrenToArrayCall = isChildrenToArrayCall;
|
|
734
736
|
exports.isClassComponent = isClassComponent;
|
|
735
|
-
exports.isCleanupFunction = isCleanupFunction;
|
|
736
737
|
exports.isCloneElement = isCloneElement;
|
|
737
738
|
exports.isCloneElementCall = isCloneElementCall;
|
|
738
739
|
exports.isComponentDidMount = isComponentDidMount;
|
|
739
|
-
exports.isComponentDidMountFunction = isComponentDidMountFunction;
|
|
740
740
|
exports.isComponentName = isComponentName;
|
|
741
741
|
exports.isComponentWillUnmount = isComponentWillUnmount;
|
|
742
|
-
exports.isComponentWillUnmountFunction = isComponentWillUnmountFunction;
|
|
743
742
|
exports.isCreateContext = isCreateContext;
|
|
744
743
|
exports.isCreateContextCall = isCreateContextCall;
|
|
745
744
|
exports.isCreateElement = isCreateElement;
|
|
@@ -752,7 +751,11 @@ exports.isForwardRef = isForwardRef;
|
|
|
752
751
|
exports.isForwardRefCall = isForwardRefCall;
|
|
753
752
|
exports.isFromReact = isFromReact;
|
|
754
753
|
exports.isFromReactMember = isFromReactMember;
|
|
754
|
+
exports.isFunctionOfComponentDidMount = isFunctionOfComponentDidMount;
|
|
755
|
+
exports.isFunctionOfComponentWillUnmount = isFunctionOfComponentWillUnmount;
|
|
755
756
|
exports.isFunctionOfRenderMethod = isFunctionOfRenderMethod;
|
|
757
|
+
exports.isFunctionOfUseEffectCleanup = isFunctionOfUseEffectCleanup;
|
|
758
|
+
exports.isFunctionOfUseEffectSetup = isFunctionOfUseEffectSetup;
|
|
756
759
|
exports.isInitializedFromReact = isInitializedFromReact;
|
|
757
760
|
exports.isInsideCreateElementProps = isInsideCreateElementProps;
|
|
758
761
|
exports.isInsideReactHook = isInsideReactHook;
|
|
@@ -772,7 +775,6 @@ exports.isReactHookName = isReactHookName;
|
|
|
772
775
|
exports.isRenderFunctionLoose = isRenderFunctionLoose;
|
|
773
776
|
exports.isRenderMethodLike = isRenderMethodLike;
|
|
774
777
|
exports.isRenderPropLoose = isRenderPropLoose;
|
|
775
|
-
exports.isSetupFunction = isSetupFunction;
|
|
776
778
|
exports.isThisSetState = isThisSetState;
|
|
777
779
|
exports.isUseCallbackCall = isUseCallbackCall;
|
|
778
780
|
exports.isUseContextCall = isUseContextCall;
|
package/dist/index.mjs
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import * as AST8 from '@eslint-react/ast';
|
|
2
|
-
import { flip,
|
|
2
|
+
import { flip, dual, _, returnFalse } from '@eslint-react/eff';
|
|
3
3
|
import * as JSX4 from '@eslint-react/jsx';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import * as VAR from '@eslint-react/var';
|
|
6
6
|
import { unsafeDecodeSettings } from '@eslint-react/shared';
|
|
7
|
+
import birecord from 'birecord';
|
|
7
8
|
|
|
8
9
|
// src/component/component-collector.ts
|
|
9
|
-
function
|
|
10
|
+
function getElementNameOnJsxAndHtml(node, context, polymorphicPropName, additionalComponents = []) {
|
|
10
11
|
const name = JSX4.getElementName(node);
|
|
11
12
|
if (name === name.toLowerCase()) return [name, name];
|
|
12
13
|
const component = additionalComponents.findLast((c) => c.name === name || c.re.test(name));
|
|
13
14
|
if (component != null) return [name, component.as];
|
|
14
15
|
if (polymorphicPropName == null) return [name, name];
|
|
15
16
|
const initialScope = context.sourceCode.getScope(node);
|
|
16
|
-
const
|
|
17
|
+
const attributeNode = JSX4.getAttributeNode(
|
|
17
18
|
polymorphicPropName,
|
|
18
19
|
initialScope,
|
|
19
20
|
node.attributes
|
|
20
21
|
);
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
if (typeof
|
|
24
|
-
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];
|
|
25
26
|
}
|
|
26
27
|
return [name, name];
|
|
27
28
|
}
|
|
@@ -365,14 +366,6 @@ function getFunctionComponentIdentifier(node, context) {
|
|
|
365
366
|
}
|
|
366
367
|
return _;
|
|
367
368
|
}
|
|
368
|
-
var RE_COMPONENT_NAME = /^_?[A-Z]/u;
|
|
369
|
-
function getComponentNameFromIdentifier(node) {
|
|
370
|
-
if (node == null) return _;
|
|
371
|
-
return Array.isArray(node) ? node.map((n) => n.name).join(".") : node.name;
|
|
372
|
-
}
|
|
373
|
-
function isComponentName(name) {
|
|
374
|
-
return RE_COMPONENT_NAME.test(name);
|
|
375
|
-
}
|
|
376
369
|
function isClassComponent(node) {
|
|
377
370
|
if ("superClass" in node && node.superClass != null) {
|
|
378
371
|
const re = /^(?:Pure)?Component$/u;
|
|
@@ -398,7 +391,19 @@ function isPureComponent(node) {
|
|
|
398
391
|
return false;
|
|
399
392
|
}
|
|
400
393
|
|
|
401
|
-
// 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
|
+
}
|
|
402
407
|
function isRenderMethodLike(node) {
|
|
403
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;
|
|
404
409
|
}
|
|
@@ -411,8 +416,14 @@ function isFunctionOfRenderMethod(node) {
|
|
|
411
416
|
function isInsideRenderMethod(node) {
|
|
412
417
|
return AST8.findParentNode(node, (node2) => isRenderMethodLike(node2) && isClassComponent(node2.parent.parent)) != null;
|
|
413
418
|
}
|
|
414
|
-
|
|
415
|
-
|
|
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
|
+
}
|
|
416
427
|
function hasNoneOrValidComponentName(node, context) {
|
|
417
428
|
const id2 = getFunctionComponentIdentifier(node, context);
|
|
418
429
|
if (id2 == null) return true;
|
|
@@ -615,49 +626,11 @@ function useComponentCollectorLegacy() {
|
|
|
615
626
|
};
|
|
616
627
|
return { ctx, listeners };
|
|
617
628
|
}
|
|
618
|
-
function isSetupFunction(node) {
|
|
619
|
-
if (node == null) return _;
|
|
620
|
-
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);
|
|
621
|
-
}
|
|
622
|
-
function isCleanupFunction(node) {
|
|
623
|
-
const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
|
|
624
|
-
const nearFunction = AST8.findParentNode(node, AST8.isFunction);
|
|
625
|
-
const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
|
|
626
|
-
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
627
|
-
}
|
|
628
|
-
function isComponentDidMount(node) {
|
|
629
|
-
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
630
|
-
}
|
|
631
|
-
function isComponentWillUnmount(node) {
|
|
632
|
-
return AST8.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
|
|
633
|
-
}
|
|
634
|
-
function isComponentDidMountFunction(node) {
|
|
635
|
-
return AST8.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
|
|
636
|
-
}
|
|
637
|
-
function isComponentWillUnmountFunction(node) {
|
|
638
|
-
return AST8.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
|
|
639
|
-
}
|
|
640
629
|
var ERPhaseRelevance = birecord({
|
|
641
630
|
mount: "unmount",
|
|
642
631
|
setup: "cleanup"
|
|
643
632
|
});
|
|
644
633
|
var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
645
|
-
function isDirectValueOfRenderPropertyLoose(node) {
|
|
646
|
-
const matching = (node2) => {
|
|
647
|
-
return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
|
|
648
|
-
};
|
|
649
|
-
return matching(node) || node.parent != null && matching(node.parent);
|
|
650
|
-
}
|
|
651
|
-
function isDeclaredInRenderPropLoose(node) {
|
|
652
|
-
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
653
|
-
return true;
|
|
654
|
-
}
|
|
655
|
-
const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
656
|
-
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
657
|
-
return false;
|
|
658
|
-
}
|
|
659
|
-
return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
|
|
660
|
-
}
|
|
661
634
|
function isRenderFunctionLoose(node, context) {
|
|
662
635
|
const { body, parent } = node;
|
|
663
636
|
if (AST8.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
@@ -677,9 +650,35 @@ function isRenderPropLoose(node, context) {
|
|
|
677
650
|
}
|
|
678
651
|
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST8.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression, context);
|
|
679
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
|
+
}
|
|
680
669
|
function isThisSetState(node) {
|
|
681
670
|
const { callee } = node;
|
|
682
671
|
return callee.type === AST_NODE_TYPES.MemberExpression && AST8.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
683
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
|
+
}
|
|
684
683
|
|
|
685
|
-
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-beta.
|
|
3
|
+
"version": "1.24.0-beta.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,16 +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
|
+
"birecord": "^0.1.1",
|
|
40
41
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/ast": "1.24.0-beta.
|
|
42
|
-
"@eslint-react/
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/var": "1.24.0-beta.
|
|
42
|
+
"@eslint-react/ast": "1.24.0-beta.8",
|
|
43
|
+
"@eslint-react/jsx": "1.24.0-beta.8",
|
|
44
|
+
"@eslint-react/shared": "1.24.0-beta.8",
|
|
45
|
+
"@eslint-react/eff": "1.24.0-beta.8",
|
|
46
|
+
"@eslint-react/var": "1.24.0-beta.8"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"tsup": "^8.3.5",
|