@blumintinc/eslint-plugin-blumint 1.19.16 → 1.19.17
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/lib/index.js +1 -1
- package/lib/rules/react-memoize-literals.js +40 -1
- package/package.json +1 -1
- package/release-manifest.json +14 -0
package/lib/index.js
CHANGED
|
@@ -138,6 +138,37 @@ function isIterationMethodCallback(node) {
|
|
|
138
138
|
callee.property.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
139
139
|
ITERATION_METHODS.has(callee.property.name));
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* True when the NEAREST enclosing function of `node` is itself an Array
|
|
143
|
+
* iteration-method callback (`arr.map((x) => ({ … }))`, `.filter`, `.reduce`,
|
|
144
|
+
* `.forEach`, `.sort`, ...). This extends the `isIterationMethodCallback`
|
|
145
|
+
* exemption (issue #1290) from the callback function itself down to the
|
|
146
|
+
* object/array literals created directly inside its body (issue #1319): such a
|
|
147
|
+
* literal is a per-iteration value discarded along with the mapped result, so
|
|
148
|
+
* its identity is never observed. The rule's own remediation is unfollowable at
|
|
149
|
+
* the literal — `useMemo` cannot run per-iteration inside a `.map` loop, and a
|
|
150
|
+
* literal closing over the callback parameter cannot be hoisted to module
|
|
151
|
+
* scope. The memoizable unit is the whole `.map()` call:
|
|
152
|
+
* `const tabs = useMemo(() => arr.map((x) => ({ … })), [arr])`.
|
|
153
|
+
*
|
|
154
|
+
* The walk starts at `node` and stops at the FIRST function encountered
|
|
155
|
+
* (including `node` itself when `node` is a function). Keying on the nearest
|
|
156
|
+
* function — not any ancestor — is what preserves the #1290 scope guard: a
|
|
157
|
+
* nested, non-iteration callback inside the map body (e.g. an `onClick` handler
|
|
158
|
+
* that persists as a JSX prop) is the nearest function for any literal in its
|
|
159
|
+
* body, so those literals stay flagged, and the handler itself (its own nearest
|
|
160
|
+
* function is itself) stays flagged too.
|
|
161
|
+
*/
|
|
162
|
+
function isInsideIterationMethodCallback(node) {
|
|
163
|
+
let current = node;
|
|
164
|
+
while (current) {
|
|
165
|
+
if (isFunctionNode(current)) {
|
|
166
|
+
return isIterationMethodCallback(current);
|
|
167
|
+
}
|
|
168
|
+
current = current.parent;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
141
172
|
/**
|
|
142
173
|
* Type guard for parenthesized expressions to unwrap safely.
|
|
143
174
|
* @param node Node to evaluate.
|
|
@@ -838,7 +869,15 @@ exports.reactMemoizeLiterals = (0, createRule_1.createRule)({
|
|
|
838
869
|
// to module level, and useCallback can't run inside a .map loop. Inline
|
|
839
870
|
// functions passed as JSX-attribute props *inside* the callback body are
|
|
840
871
|
// separate nodes and remain flagged.
|
|
841
|
-
|
|
872
|
+
//
|
|
873
|
+
// The same rationale exempts object/array literals created directly
|
|
874
|
+
// inside such a callback (issue #1319): they are per-iteration values
|
|
875
|
+
// discarded with the mapped result, `useMemo` cannot run inside the loop,
|
|
876
|
+
// and the memoizable unit is the enclosing `.map()` call. The guard keys
|
|
877
|
+
// on the NEAREST enclosing function, so a literal inside a nested,
|
|
878
|
+
// non-iteration callback (e.g. an `onClick` handler) is NOT exempted.
|
|
879
|
+
if (isIterationMethodCallback(node) ||
|
|
880
|
+
isInsideIterationMethodCallback(node)) {
|
|
842
881
|
return;
|
|
843
882
|
}
|
|
844
883
|
// Inline literals that resolve to a style JSX attribute (sx, style),
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "1.19.17",
|
|
4
|
+
"date": "2026-07-18T07:27:36.853Z",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"name": "react-memoize-literals",
|
|
8
|
+
"changeType": "fix",
|
|
9
|
+
"issues": [
|
|
10
|
+
1319
|
|
11
|
+
],
|
|
12
|
+
"summary": "exempt literals inside iteration-method callbacks (closes #1319)"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"version": "1.19.16",
|
|
4
18
|
"date": "2026-07-18T06:29:03.568Z",
|