@blumintinc/eslint-plugin-blumint 1.14.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -14
- package/lib/index.js +20 -12
- package/lib/rules/avoid-utils-directory.js +0 -4
- package/lib/rules/consistent-callback-naming.js +68 -3
- package/lib/rules/dynamic-https-errors.d.ts +1 -1
- package/lib/rules/dynamic-https-errors.js +119 -49
- package/lib/rules/enforce-boolean-naming-prefixes.d.ts +1 -0
- package/lib/rules/enforce-boolean-naming-prefixes.js +86 -331
- package/lib/rules/enforce-date-ttime.d.ts +1 -0
- package/lib/rules/enforce-date-ttime.js +156 -0
- package/lib/rules/enforce-dynamic-firebase-imports.d.ts +2 -1
- package/lib/rules/enforce-dynamic-firebase-imports.js +3 -2
- package/lib/rules/enforce-dynamic-imports.d.ts +2 -1
- package/lib/rules/enforce-dynamic-imports.js +42 -21
- package/lib/rules/enforce-f-extension-for-entry-points.d.ts +8 -0
- package/lib/rules/enforce-f-extension-for-entry-points.js +283 -0
- package/lib/rules/enforce-global-constants.js +3 -3
- package/lib/rules/enforce-id-capitalization.js +1 -1
- package/lib/rules/enforce-memoize-async.js +66 -15
- package/lib/rules/enforce-mui-rounded-icons.js +42 -1
- package/lib/rules/enforce-props-argument-name.js +42 -16
- package/lib/rules/enforce-stable-hash-spread-props.js +3 -3
- package/lib/rules/enforce-transform-memoization.js +1 -1
- package/lib/rules/enforce-verb-noun-naming.js +3817 -4641
- package/lib/rules/global-const-style.js +25 -4
- package/lib/rules/logical-top-to-bottom-grouping.js +80 -2
- package/lib/rules/memo-compare-deeply-complex-props.js +183 -6
- package/lib/rules/memo-nested-react-components.js +243 -103
- package/lib/rules/no-array-length-in-deps.js +74 -3
- package/lib/rules/no-async-foreach.js +7 -2
- package/lib/rules/no-circular-references.d.ts +2 -1
- package/lib/rules/no-circular-references.js +150 -489
- package/lib/rules/no-compositing-layer-props.js +31 -0
- package/lib/rules/no-console-error.js +12 -10
- package/lib/rules/no-empty-dependency-use-callbacks.js +1 -1
- package/lib/rules/no-entire-object-hook-deps.js +147 -65
- package/lib/rules/no-excessive-parent-chain.js +3 -0
- package/lib/rules/no-explicit-return-type.js +6 -0
- package/lib/rules/no-hungarian.js +119 -24
- package/lib/rules/no-inline-component-prop.js +16 -7
- package/lib/rules/no-margin-properties.js +7 -38
- package/lib/rules/no-passthrough-getters.d.ts +2 -2
- package/lib/rules/no-passthrough-getters.js +83 -1
- package/lib/rules/no-redundant-this-params.js +50 -1
- package/lib/rules/no-unmemoized-memo-without-props.js +1 -1
- package/lib/rules/no-unnecessary-destructuring-rename.js +2 -5
- package/lib/rules/no-unnecessary-verb-suffix.js +79 -0
- package/lib/rules/no-unused-props.js +215 -37
- package/lib/rules/no-useless-fragment.js +10 -2
- package/lib/rules/parallelize-async-operations.js +117 -54
- package/lib/rules/prefer-nullish-coalescing-boolean-props.js +109 -4
- package/lib/rules/prefer-params-over-parent-id.js +1 -1
- package/lib/rules/prefer-settings-object.js +27 -10
- package/lib/rules/prefer-type-alias-over-typeof-constant.js +75 -4
- package/lib/rules/prefer-use-deep-compare-memo.js +8 -14
- package/lib/rules/prefer-usememo-over-useeffect-usestate.js +1 -1
- package/lib/rules/prevent-children-clobber.js +9 -5
- package/lib/rules/react-memoize-literals.js +218 -13
- package/lib/rules/require-https-error-cause.js +30 -11
- package/lib/rules/require-memo.js +17 -9
- package/lib/rules/require-migration-script-metadata.d.ts +9 -0
- package/lib/rules/require-migration-script-metadata.js +206 -0
- package/lib/rules/warn-https-error-message-user-friendly.d.ts +1 -0
- package/lib/rules/warn-https-error-message-user-friendly.js +239 -0
- package/lib/utils/ASTHelpers.d.ts +49 -1
- package/lib/utils/ASTHelpers.js +394 -112
- package/package.json +7 -6
- package/release-manifest.json +166 -0
|
@@ -31,6 +31,21 @@ exports.default = (0, createRule_1.createRule)({
|
|
|
31
31
|
}
|
|
32
32
|
return target;
|
|
33
33
|
};
|
|
34
|
+
const isDynamicValue = (node) => {
|
|
35
|
+
const target = unwrapAssertions(node);
|
|
36
|
+
if (target.type === utils_1.AST_NODE_TYPES.CallExpression ||
|
|
37
|
+
target.type === utils_1.AST_NODE_TYPES.NewExpression ||
|
|
38
|
+
target.type === utils_1.AST_NODE_TYPES.BinaryExpression) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (target.type === utils_1.AST_NODE_TYPES.ChainExpression) {
|
|
42
|
+
return isDynamicValue(target.expression);
|
|
43
|
+
}
|
|
44
|
+
if (target.type === utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
45
|
+
return isDynamicValue(target.object);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
34
49
|
const describeValueKind = (node) => {
|
|
35
50
|
const target = unwrapAssertions(node);
|
|
36
51
|
if (target.type === utils_1.AST_NODE_TYPES.ArrayExpression) {
|
|
@@ -102,10 +117,7 @@ exports.default = (0, createRule_1.createRule)({
|
|
|
102
117
|
const { name } = declaration.id;
|
|
103
118
|
const init = declaration.init;
|
|
104
119
|
// Skip if no initializer or if it's a dynamic value or class instance
|
|
105
|
-
if (!init ||
|
|
106
|
-
init.type === utils_1.AST_NODE_TYPES.CallExpression ||
|
|
107
|
-
init.type === utils_1.AST_NODE_TYPES.BinaryExpression ||
|
|
108
|
-
init.type === utils_1.AST_NODE_TYPES.NewExpression) {
|
|
120
|
+
if (!init || isDynamicValue(init)) {
|
|
109
121
|
return;
|
|
110
122
|
}
|
|
111
123
|
const sourceCode = context.sourceCode;
|
|
@@ -146,6 +158,15 @@ exports.default = (0, createRule_1.createRule)({
|
|
|
146
158
|
if (target.type === utils_1.AST_NODE_TYPES.Literal && 'regex' in target) {
|
|
147
159
|
return false;
|
|
148
160
|
}
|
|
161
|
+
// Skip null and boolean literals. `null as const` is invalid
|
|
162
|
+
// TypeScript (TS1355), so the autofix would produce uncompilable
|
|
163
|
+
// code; `true`/`false` already have literal types, so `as const`
|
|
164
|
+
// is redundant. (`undefined` is an Identifier, not a Literal, so
|
|
165
|
+
// it never reaches the literal branch below.)
|
|
166
|
+
if (target.type === utils_1.AST_NODE_TYPES.Literal &&
|
|
167
|
+
(target.value === null || typeof target.value === 'boolean')) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
149
170
|
return (target.type === utils_1.AST_NODE_TYPES.Literal ||
|
|
150
171
|
target.type === utils_1.AST_NODE_TYPES.ArrayExpression ||
|
|
151
172
|
target.type === utils_1.AST_NODE_TYPES.ObjectExpression);
|
|
@@ -760,18 +760,26 @@ function handleGuardHoists(ruleContext, body, parent) {
|
|
|
760
760
|
}
|
|
761
761
|
function handleDerivedGrouping(ruleContext, body, parent) {
|
|
762
762
|
const declaredIndices = new Map();
|
|
763
|
+
/**
|
|
764
|
+
* Each binding name → the declarator that introduced it. Sibling bindings of
|
|
765
|
+
* one multi-target declarator (e.g. `const [a, b] = ...`) share one node, so
|
|
766
|
+
* a statement deriving from `a` is recognizable as a sibling of one deriving
|
|
767
|
+
* from `b` even though `a` separates `b` from its declaration.
|
|
768
|
+
*/
|
|
769
|
+
const sourceDeclarators = new Map();
|
|
763
770
|
const { sourceCode } = ruleContext;
|
|
764
771
|
body.forEach((statement, index) => {
|
|
765
772
|
if (isVariableDeclaration(statement)) {
|
|
766
|
-
processVariableDeclaration(ruleContext, statement, index, body, declaredIndices, parent, sourceCode);
|
|
773
|
+
processVariableDeclaration(ruleContext, statement, index, body, declaredIndices, sourceDeclarators, parent, sourceCode);
|
|
767
774
|
}
|
|
768
775
|
trackDeclaredNames(statement, index, declaredIndices);
|
|
776
|
+
trackSourceDeclarators(statement, sourceDeclarators);
|
|
769
777
|
});
|
|
770
778
|
}
|
|
771
779
|
function isVariableDeclaration(statement) {
|
|
772
780
|
return statement.type === utils_1.AST_NODE_TYPES.VariableDeclaration;
|
|
773
781
|
}
|
|
774
|
-
function processVariableDeclaration(ruleContext, statement, index, body, declaredIndices, parent, sourceCode) {
|
|
782
|
+
function processVariableDeclaration(ruleContext, statement, index, body, declaredIndices, sourceDeclarators, parent, sourceCode) {
|
|
775
783
|
const dependencies = collectDependencies(statement);
|
|
776
784
|
const priorDependencies = findPriorDependencies(dependencies, declaredIndices);
|
|
777
785
|
if (priorDependencies.length === 0 ||
|
|
@@ -784,6 +792,9 @@ function processVariableDeclaration(ruleContext, statement, index, body, declare
|
|
|
784
792
|
}
|
|
785
793
|
const declaredNames = getDeclaredNames(statement);
|
|
786
794
|
const priorDependencySet = new Set(priorDependencies);
|
|
795
|
+
if (interveningAreSiblingDerivations(body, lastDependencyIndex, index, priorDependencySet, sourceDeclarators)) {
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
787
798
|
if (hasBlockers(body, lastDependencyIndex, index, priorDependencySet, declaredNames)) {
|
|
788
799
|
return;
|
|
789
800
|
}
|
|
@@ -829,6 +840,73 @@ function trackDeclaredNames(statement, index, declaredIndices) {
|
|
|
829
840
|
const declared = getDeclaredNames(statement);
|
|
830
841
|
declared.forEach((name) => declaredIndices.set(name, index));
|
|
831
842
|
}
|
|
843
|
+
function trackSourceDeclarators(statement, sourceDeclarators) {
|
|
844
|
+
if (statement.type !== utils_1.AST_NODE_TYPES.VariableDeclaration) {
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
statement.declarations.forEach((declarator) => {
|
|
848
|
+
const names = new Set();
|
|
849
|
+
collectDeclaredNamesFromPattern(declarator.id, names);
|
|
850
|
+
names.forEach((name) => sourceDeclarators.set(name, declarator));
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* True when every statement between a dependency and the statement deriving from
|
|
855
|
+
* it is itself a pure derivation from a *sibling binding of the same declarator*.
|
|
856
|
+
*
|
|
857
|
+
* `const [a, b] = await Promise.all([...]); const x = a; const y = b;` is already
|
|
858
|
+
* grouped: `x` and `y` unpack one source declaration in order, so the `x` line is
|
|
859
|
+
* not "unrelated" separation between `b` and `y`. Suppressing here keeps such
|
|
860
|
+
* cohesive sibling-destructure groups intact instead of reordering them.
|
|
861
|
+
*/
|
|
862
|
+
function interveningAreSiblingDerivations(body, lastDependencyIndex, currentIndex, priorDependencySet, sourceDeclarators) {
|
|
863
|
+
const sourceNodes = new Set();
|
|
864
|
+
priorDependencySet.forEach((name) => {
|
|
865
|
+
const declarator = sourceDeclarators.get(name);
|
|
866
|
+
if (declarator) {
|
|
867
|
+
sourceNodes.add(declarator);
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
if (sourceNodes.size === 0) {
|
|
871
|
+
return false;
|
|
872
|
+
}
|
|
873
|
+
const intervening = body.slice(lastDependencyIndex + 1, currentIndex);
|
|
874
|
+
if (intervening.length === 0) {
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
return intervening.every((between) => isSiblingSourceDerivation(between, sourceNodes, sourceDeclarators));
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* A statement is a sibling-source derivation when it is a pure declaration whose
|
|
881
|
+
* every prior-declared dependency was introduced by one of `sourceNodes` — i.e.
|
|
882
|
+
* it unpacks a sibling binding of the same multi-target declaration the dependent
|
|
883
|
+
* statement derives from.
|
|
884
|
+
*/
|
|
885
|
+
function isSiblingSourceDerivation(statement, sourceNodes, sourceDeclarators) {
|
|
886
|
+
if (statement.type !== utils_1.AST_NODE_TYPES.VariableDeclaration ||
|
|
887
|
+
!isPureDeclaration(statement, { allowHooks: false })) {
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
const dependencies = collectDependencies(statement);
|
|
891
|
+
const siblingSourced = Array.from(dependencies).filter((name) => {
|
|
892
|
+
const declarator = sourceDeclarators.get(name);
|
|
893
|
+
return Boolean(declarator && sourceNodes.has(declarator));
|
|
894
|
+
});
|
|
895
|
+
if (siblingSourced.length === 0) {
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Reject when the statement also pulls in any prior-declared name from outside
|
|
900
|
+
* the sibling source: that would be genuine extra coupling, not a clean sibling
|
|
901
|
+
* unpack.
|
|
902
|
+
*/
|
|
903
|
+
return Array.from(dependencies).every((name) => {
|
|
904
|
+
if (siblingSourced.includes(name)) {
|
|
905
|
+
return true;
|
|
906
|
+
}
|
|
907
|
+
return !sourceDeclarators.has(name);
|
|
908
|
+
});
|
|
909
|
+
}
|
|
832
910
|
function handleLateDeclarations(ruleContext, body, parent) {
|
|
833
911
|
const { sourceCode } = ruleContext;
|
|
834
912
|
body.forEach((statement, index) => {
|
|
@@ -6,6 +6,29 @@ const createRule_1 = require("../utils/createRule");
|
|
|
6
6
|
function isUtilMemoModulePath(path) {
|
|
7
7
|
return /(?:^|\/|\\)util\/memo$/.test(path);
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Reserved React slots that never reach a component's props object at runtime.
|
|
11
|
+
* React extracts `ref` and `key` before invoking the memo equality function, so
|
|
12
|
+
* a deep comparator can never observe them. Some prop-type sources (notably the
|
|
13
|
+
* `forwardRef<T, P>` exotic-component signature, whose params include the
|
|
14
|
+
* synthetic `RefAttributes<T> = { ref?: Ref<T> }` member) surface them as
|
|
15
|
+
* structural members anyway; flagging them would emit dead `compareDeeply('ref')`
|
|
16
|
+
* advice. Excluded the same way `children` is.
|
|
17
|
+
*/
|
|
18
|
+
const RESERVED_REACT_PROP_NAMES = new Set(['ref', 'key', 'children']);
|
|
19
|
+
function isReservedReactPropName(name) {
|
|
20
|
+
return RESERVED_REACT_PROP_NAMES.has(name);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Checks if a property name is handled by the default deep equality logic
|
|
24
|
+
* in our custom memo implementation (blumintAreEqual).
|
|
25
|
+
*/
|
|
26
|
+
function isDefaultDeepCompareProp(name) {
|
|
27
|
+
return (name === 'sx' ||
|
|
28
|
+
name.endsWith('Sx') ||
|
|
29
|
+
name === 'style' ||
|
|
30
|
+
name.endsWith('Style'));
|
|
31
|
+
}
|
|
9
32
|
function unwrapExpression(expression) {
|
|
10
33
|
let node = expression;
|
|
11
34
|
// Unwrap harmless wrappers so detection treats casted/parenthesized expressions the same.
|
|
@@ -286,6 +309,91 @@ function ensureCompareDeeplyImportFixes(sourceCode, fixer, usedNames, preferredS
|
|
|
286
309
|
localName: preferredLocalName,
|
|
287
310
|
};
|
|
288
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Names of React types that represent renderable UI or component references.
|
|
314
|
+
* Props typed as any of these are stable references (JSX elements, component
|
|
315
|
+
* constructors, render-prop functions) and do NOT benefit from deep value
|
|
316
|
+
* comparison — flagging them would produce false positives.
|
|
317
|
+
*/
|
|
318
|
+
const REACT_RENDER_TYPE_NAMES = new Set([
|
|
319
|
+
'ReactNode',
|
|
320
|
+
'ReactChild',
|
|
321
|
+
'ReactElement',
|
|
322
|
+
'ReactPortal',
|
|
323
|
+
'ReactFragment',
|
|
324
|
+
// JSX.Element resolves to a global symbol named 'Element' in the JSX namespace
|
|
325
|
+
'Element',
|
|
326
|
+
'Component',
|
|
327
|
+
'PureComponent',
|
|
328
|
+
'ComponentClass',
|
|
329
|
+
'FunctionComponent',
|
|
330
|
+
'FC',
|
|
331
|
+
'ComponentType',
|
|
332
|
+
'ExoticComponent',
|
|
333
|
+
'NamedExoticComponent',
|
|
334
|
+
'MemoExoticComponent',
|
|
335
|
+
'ForwardRefExoticComponent',
|
|
336
|
+
'LazyExoticComponent',
|
|
337
|
+
'JSXElementConstructor',
|
|
338
|
+
'RefObject',
|
|
339
|
+
'RefCallback',
|
|
340
|
+
'Ref',
|
|
341
|
+
]);
|
|
342
|
+
/**
|
|
343
|
+
* Returns true when `sym` is declared inside a `.d.ts` file whose path
|
|
344
|
+
* contains "react" — indicating it originates from @types/react rather than
|
|
345
|
+
* from user code that happens to use the same name.
|
|
346
|
+
*
|
|
347
|
+
* Also returns true when the symbol has NO declarations at all: this happens
|
|
348
|
+
* when TypeScript resolves the type as `any` because the source module (e.g.
|
|
349
|
+
* @types/react) is not included in the tsconfig `types` array. A symbol with
|
|
350
|
+
* no declarations cannot be a user-defined type, so treating it as "from
|
|
351
|
+
* React" is safe — it avoids flagging props that would otherwise be excluded
|
|
352
|
+
* once the types are properly wired.
|
|
353
|
+
*/
|
|
354
|
+
function isSymbolFromReactDeclarationFile(sym) {
|
|
355
|
+
const declarations = sym.declarations;
|
|
356
|
+
// No declarations ⟹ the type was resolved from an unresolvable external
|
|
357
|
+
// module (common when @types/react is absent from the tsconfig types list).
|
|
358
|
+
// User-defined types always have at least one declaration.
|
|
359
|
+
if (!declarations || declarations.length === 0)
|
|
360
|
+
return true;
|
|
361
|
+
return declarations.some((decl) => {
|
|
362
|
+
const fileName = decl.getSourceFile?.()?.fileName ?? '';
|
|
363
|
+
return fileName.endsWith('.d.ts') && /react/i.test(fileName);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Returns true when `type` is a React render-related type that should be
|
|
368
|
+
* excluded from the "complex prop" check. Detects by matching the type's
|
|
369
|
+
* alias symbol or own symbol name against a known React-type allowlist AND
|
|
370
|
+
* verifying the matched symbol's declaration originates from a React `.d.ts`
|
|
371
|
+
* file to avoid false negatives for user types that coincidentally share the
|
|
372
|
+
* same name.
|
|
373
|
+
*/
|
|
374
|
+
function isReactRenderType(type) {
|
|
375
|
+
// Check the aliasSymbol first (covers type aliases like ReactNode, FC, etc.)
|
|
376
|
+
const aliasSymbol = type
|
|
377
|
+
.aliasSymbol;
|
|
378
|
+
if (aliasSymbol) {
|
|
379
|
+
const name = aliasSymbol.escapedName;
|
|
380
|
+
if (REACT_RENDER_TYPE_NAMES.has(name) &&
|
|
381
|
+
isSymbolFromReactDeclarationFile(aliasSymbol)) {
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// Check the type's own symbol (covers interfaces / classes like ReactElement,
|
|
386
|
+
// ComponentClass, ForwardRefExoticComponent, etc.)
|
|
387
|
+
const sym = type.symbol;
|
|
388
|
+
if (sym) {
|
|
389
|
+
const name = sym.escapedName;
|
|
390
|
+
if (REACT_RENDER_TYPE_NAMES.has(name) &&
|
|
391
|
+
isSymbolFromReactDeclarationFile(sym)) {
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
289
397
|
function isComplexType(ts, type, checker) {
|
|
290
398
|
return isComplexTypeInternal(ts, type, checker, new Set());
|
|
291
399
|
}
|
|
@@ -293,6 +401,13 @@ function isComplexTypeInternal(ts, type, checker, visited) {
|
|
|
293
401
|
if (visited.has(type))
|
|
294
402
|
return false;
|
|
295
403
|
visited.add(type);
|
|
404
|
+
// Exclude React render-related types before any structural checks.
|
|
405
|
+
// This must come early so that ReactElement (an object type) and ReactNode
|
|
406
|
+
// (a union containing ReactElement) are both short-circuited here rather
|
|
407
|
+
// than being caught by the isObjectType / checkUnionType branches below.
|
|
408
|
+
if (isReactRenderType(type)) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
296
411
|
const flags = type.flags ?? 0;
|
|
297
412
|
if (isUnionType(ts, flags)) {
|
|
298
413
|
return checkUnionType(ts, type, checker, visited);
|
|
@@ -379,13 +494,72 @@ function extractAnnotationType(propDeclaration) {
|
|
|
379
494
|
}
|
|
380
495
|
return undefined;
|
|
381
496
|
}
|
|
382
|
-
|
|
497
|
+
/**
|
|
498
|
+
* Returns true when an annotation TypeNode (the explicit type written in
|
|
499
|
+
* source, e.g. `React.ComponentType` or `React.ReactNode | null`) resolves to
|
|
500
|
+
* a React render type that must be excluded from the complex-prop check.
|
|
501
|
+
*
|
|
502
|
+
* This path is taken when the prop type resolves to `any` (common when
|
|
503
|
+
* @types/react is not listed in the tsconfig `types` array) but the
|
|
504
|
+
* annotation still carries the original alias name via the TypeScript
|
|
505
|
+
* type-checker.
|
|
506
|
+
*
|
|
507
|
+
* For union annotation nodes (e.g. `ReactNode | null`), all non-null /
|
|
508
|
+
* non-undefined members must themselves be React render types for the whole
|
|
509
|
+
* union to be considered a React render type.
|
|
510
|
+
*/
|
|
511
|
+
function isAnnotationReactRenderType(annotationType, checker, ts) {
|
|
512
|
+
try {
|
|
513
|
+
const tsModule = ts;
|
|
514
|
+
// Handle union annotation nodes like `React.ReactNode | null`.
|
|
515
|
+
if (tsModule.isUnionTypeNode?.(annotationType)) {
|
|
516
|
+
const nonNullishMembers = annotationType.types.filter((member) => {
|
|
517
|
+
// Nullish keywords appearing directly (older TypeScript AST forms)
|
|
518
|
+
if (member.kind === tsModule.SyntaxKind.NullKeyword ||
|
|
519
|
+
member.kind === tsModule.SyntaxKind.UndefinedKeyword ||
|
|
520
|
+
member.kind === tsModule.SyntaxKind.VoidKeyword) {
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
// `null` and `undefined` appear as LiteralTypeNode wrapping the
|
|
524
|
+
// corresponding keyword in modern TypeScript AST.
|
|
525
|
+
if (tsModule.isLiteralTypeNode?.(member)) {
|
|
526
|
+
const lit = member.literal;
|
|
527
|
+
if (lit.kind === tsModule.SyntaxKind.NullKeyword ||
|
|
528
|
+
lit.kind === tsModule.SyntaxKind.UndefinedKeyword) {
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return true;
|
|
533
|
+
});
|
|
534
|
+
// If every non-nullish member is a React render type, the union is too.
|
|
535
|
+
return (nonNullishMembers.length > 0 &&
|
|
536
|
+
nonNullishMembers.every((member) => isAnnotationReactRenderType(member, checker, ts)));
|
|
537
|
+
}
|
|
538
|
+
// For plain TypeReference nodes (the common case), resolve via the checker.
|
|
539
|
+
const resolvedType = checker.getTypeFromTypeNode?.(annotationType);
|
|
540
|
+
if (!resolvedType)
|
|
541
|
+
return false;
|
|
542
|
+
return isReactRenderType(resolvedType);
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
function shouldTreatAnyAsComplex(prop, propType, ts, treatAnyAsComplex, parentTypeFlags, checker) {
|
|
383
549
|
if (!(propType.flags & ts.TypeFlags.Any))
|
|
384
550
|
return false;
|
|
385
551
|
if (treatAnyAsComplex)
|
|
386
552
|
return true;
|
|
387
553
|
const propDeclaration = extractPropertyDeclaration(prop);
|
|
388
554
|
const annotationType = extractAnnotationType(propDeclaration);
|
|
555
|
+
// When the annotation resolves to a React render type, the prop is a
|
|
556
|
+
// stable component/render-prop reference that does not benefit from deep
|
|
557
|
+
// value comparison — exclude it regardless of the any-as-complex heuristic.
|
|
558
|
+
if (annotationType &&
|
|
559
|
+
checker &&
|
|
560
|
+
isAnnotationReactRenderType(annotationType, checker, ts)) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
389
563
|
return ((annotationType && annotationType.kind !== ts.SyntaxKind.AnyKeyword) ||
|
|
390
564
|
(!annotationType && Boolean(parentTypeFlags & ts.TypeFlags.Object)));
|
|
391
565
|
}
|
|
@@ -394,13 +568,13 @@ function isPropertyComplex(prop, checker, tsNode, ts, treatAnyAsComplex, parentT
|
|
|
394
568
|
if (isComplexType(ts, propType, checker)) {
|
|
395
569
|
return true;
|
|
396
570
|
}
|
|
397
|
-
return shouldTreatAnyAsComplex(prop, propType, ts, treatAnyAsComplex, parentTypeFlags);
|
|
571
|
+
return shouldTreatAnyAsComplex(prop, propType, ts, treatAnyAsComplex, parentTypeFlags, checker);
|
|
398
572
|
}
|
|
399
573
|
function getComplexPropertiesFromType(type, checker, tsNode, ts, treatAnyAsComplex = false, parentTypeFlags = 0) {
|
|
400
574
|
const properties = checker.getPropertiesOfType(type);
|
|
401
575
|
const complexProps = [];
|
|
402
576
|
for (const prop of properties) {
|
|
403
|
-
if (prop.name
|
|
577
|
+
if (isReservedReactPropName(prop.name))
|
|
404
578
|
continue;
|
|
405
579
|
if (isPropertyComplex(prop, checker, tsNode, ts, treatAnyAsComplex, parentTypeFlags)) {
|
|
406
580
|
complexProps.push(prop.name);
|
|
@@ -733,13 +907,16 @@ exports.memoCompareDeeplyComplexProps = (0, createRule_1.createRule)({
|
|
|
733
907
|
const comparatorArg = node.arguments[1];
|
|
734
908
|
return { memoCall, componentArg, comparatorArg };
|
|
735
909
|
}
|
|
736
|
-
function analyzeComponentAndProps(componentArg, comparatorArg, currentScope) {
|
|
910
|
+
function analyzeComponentAndProps(componentArg, comparatorArg, currentScope, memoSource) {
|
|
737
911
|
const componentTargets = findComponentAnalysisTargets(componentArg, (name) => initializerTracking.getInitializer(name, currentScope));
|
|
738
912
|
if (!componentTargets)
|
|
739
913
|
return null;
|
|
740
914
|
if (isComparatorProvided(comparatorArg, currentScope))
|
|
741
915
|
return null;
|
|
742
|
-
|
|
916
|
+
let complexProps = collectComplexPropsForTargets(componentTargets, (expr) => collectComplexProps(expr, sourceCode, complexPropsCache));
|
|
917
|
+
if (isUtilMemoModulePath(memoSource)) {
|
|
918
|
+
complexProps = complexProps.filter((prop) => !isDefaultDeepCompareProp(prop));
|
|
919
|
+
}
|
|
743
920
|
if (complexProps.length === 0)
|
|
744
921
|
return null;
|
|
745
922
|
const componentName = resolveComponentName(componentTargets, componentArg);
|
|
@@ -763,7 +940,7 @@ exports.memoCompareDeeplyComplexProps = (0, createRule_1.createRule)({
|
|
|
763
940
|
return;
|
|
764
941
|
const { memoCall, componentArg, comparatorArg } = validationResult;
|
|
765
942
|
const currentScope = context.getScope();
|
|
766
|
-
const analysisResult = analyzeComponentAndProps(componentArg, comparatorArg, currentScope);
|
|
943
|
+
const analysisResult = analyzeComponentAndProps(componentArg, comparatorArg, currentScope, memoCall.source);
|
|
767
944
|
if (!analysisResult)
|
|
768
945
|
return;
|
|
769
946
|
const { complexProps, componentName } = analysisResult;
|