eslint-plugin-react-hooks 2.3.0 → 2.5.1
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
CHANGED
|
@@ -6,7 +6,7 @@ It is a part of the [Hooks API](https://reactjs.org/docs/hooks-intro.html) for R
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
**Note: If you're using Create React App, please
|
|
9
|
+
**Note: If you're using Create React App, please use `react-scripts` >= 3 instead of adding it directly.**
|
|
10
10
|
|
|
11
11
|
Assuming you already have ESLint installed, run:
|
|
12
12
|
|
package/build-info.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"branch": "
|
|
3
|
-
"buildNumber": "
|
|
4
|
-
"checksum": "
|
|
5
|
-
"commit": "
|
|
2
|
+
"branch": "pull/18344",
|
|
3
|
+
"buildNumber": "106499",
|
|
4
|
+
"checksum": "7fe5a2e",
|
|
5
|
+
"commit": "da834083c",
|
|
6
6
|
"environment": "ci",
|
|
7
|
-
"reactVersion": "16.
|
|
7
|
+
"reactVersion": "16.12.0-da834083c"
|
|
8
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v2.
|
|
1
|
+
/** @license React v2.5.1
|
|
2
2
|
* eslint-plugin-react-hooks.development.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
@@ -16,7 +16,6 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
/* eslint-disable no-for-of-loops/no-for-of-loops */
|
|
19
|
-
|
|
20
19
|
/**
|
|
21
20
|
* Catch all identifiers that begin with "use" followed by an uppercase Latin
|
|
22
21
|
* character to exclude identifiers like "user".
|
|
@@ -58,6 +57,28 @@ function isComponentName(node) {
|
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
|
|
60
|
+
function isReactFunction(node, functionName) {
|
|
61
|
+
return node.name === functionName || node.type === 'MemberExpression' && node.object.name === 'React' && node.property.name === functionName;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Checks if the node is a callback argument of forwardRef. This render function
|
|
65
|
+
* should follow the rules of hooks.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
function isForwardRefCallback(node) {
|
|
70
|
+
return !!(node.parent && node.parent.callee && isReactFunction(node.parent.callee, 'forwardRef'));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Checks if the node is a callback argument of React.memo. This anonymous
|
|
74
|
+
* functional component should follow the rules of hooks.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
function isMemoCallback(node) {
|
|
79
|
+
return !!(node.parent && node.parent.callee && isReactFunction(node.parent.callee, 'memo'));
|
|
80
|
+
}
|
|
81
|
+
|
|
61
82
|
function isInsideComponentOrHook(node) {
|
|
62
83
|
while (node) {
|
|
63
84
|
var functionName = getFunctionName(node);
|
|
@@ -68,6 +89,10 @@ function isInsideComponentOrHook(node) {
|
|
|
68
89
|
}
|
|
69
90
|
}
|
|
70
91
|
|
|
92
|
+
if (isForwardRefCallback(node) || isMemoCallback(node)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
71
96
|
node = node.parent;
|
|
72
97
|
}
|
|
73
98
|
|
|
@@ -125,51 +150,48 @@ var RuleOfHooks = {
|
|
|
125
150
|
* Populates `cyclic` with cyclic segments.
|
|
126
151
|
*/
|
|
127
152
|
|
|
128
|
-
function countPathsFromStart(segment) {
|
|
153
|
+
function countPathsFromStart(segment, pathHistory) {
|
|
129
154
|
var cache = countPathsFromStart.cache;
|
|
130
|
-
var paths = cache.get(segment.id);
|
|
131
|
-
//
|
|
155
|
+
var paths = cache.get(segment.id);
|
|
156
|
+
var pathList = new Set(pathHistory); // If `pathList` includes the current segment then we've found a cycle!
|
|
157
|
+
// We need to fill `cyclic` with all segments inside cycle
|
|
132
158
|
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
var _didIteratorError = false;
|
|
140
|
-
var _iteratorError = undefined;
|
|
159
|
+
if (pathList.has(segment.id)) {
|
|
160
|
+
var pathArray = [].concat(pathList);
|
|
161
|
+
var cyclicSegments = pathArray.slice(pathArray.indexOf(segment.id) + 1);
|
|
162
|
+
var _iteratorNormalCompletion = true;
|
|
163
|
+
var _didIteratorError = false;
|
|
164
|
+
var _iteratorError = undefined;
|
|
141
165
|
|
|
166
|
+
try {
|
|
167
|
+
for (var _iterator = cyclicSegments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
168
|
+
var cyclicSegment = _step.value;
|
|
169
|
+
cyclic.add(cyclicSegment);
|
|
170
|
+
}
|
|
171
|
+
} catch (err) {
|
|
172
|
+
_didIteratorError = true;
|
|
173
|
+
_iteratorError = err;
|
|
174
|
+
} finally {
|
|
142
175
|
try {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
countPathsFromStart(prevSegment);
|
|
176
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
177
|
+
_iterator.return();
|
|
146
178
|
}
|
|
147
|
-
} catch (err) {
|
|
148
|
-
_didIteratorError = true;
|
|
149
|
-
_iteratorError = err;
|
|
150
179
|
} finally {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
_iterator.return();
|
|
154
|
-
}
|
|
155
|
-
} finally {
|
|
156
|
-
if (_didIteratorError) {
|
|
157
|
-
throw _iteratorError;
|
|
158
|
-
}
|
|
180
|
+
if (_didIteratorError) {
|
|
181
|
+
throw _iteratorError;
|
|
159
182
|
}
|
|
160
183
|
}
|
|
161
|
-
|
|
162
|
-
return 0;
|
|
163
184
|
}
|
|
164
|
-
} // We have a cached `paths`. Return it.
|
|
165
185
|
|
|
186
|
+
return 0;
|
|
187
|
+
} // add the current segment to pathList
|
|
166
188
|
|
|
167
|
-
if (paths !== undefined) {
|
|
168
|
-
return paths;
|
|
169
|
-
} // Compute `paths` and cache it. Guarding against cycles.
|
|
170
189
|
|
|
190
|
+
pathList.add(segment.id); // We have a cached `paths`. Return it.
|
|
171
191
|
|
|
172
|
-
|
|
192
|
+
if (paths !== undefined) {
|
|
193
|
+
return paths;
|
|
194
|
+
}
|
|
173
195
|
|
|
174
196
|
if (codePath.thrownSegments.includes(segment)) {
|
|
175
197
|
paths = 0;
|
|
@@ -183,8 +205,8 @@ var RuleOfHooks = {
|
|
|
183
205
|
|
|
184
206
|
try {
|
|
185
207
|
for (var _iterator2 = segment.prevSegments[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
186
|
-
var
|
|
187
|
-
paths += countPathsFromStart(
|
|
208
|
+
var prevSegment = _step2.value;
|
|
209
|
+
paths += countPathsFromStart(prevSegment, pathList);
|
|
188
210
|
}
|
|
189
211
|
} catch (err) {
|
|
190
212
|
_didIteratorError2 = true;
|
|
@@ -235,51 +257,48 @@ var RuleOfHooks = {
|
|
|
235
257
|
*/
|
|
236
258
|
|
|
237
259
|
|
|
238
|
-
function countPathsToEnd(segment) {
|
|
260
|
+
function countPathsToEnd(segment, pathHistory) {
|
|
239
261
|
var cache = countPathsToEnd.cache;
|
|
240
|
-
var paths = cache.get(segment.id);
|
|
241
|
-
//
|
|
262
|
+
var paths = cache.get(segment.id);
|
|
263
|
+
var pathList = new Set(pathHistory); // If `pathList` includes the current segment then we've found a cycle!
|
|
264
|
+
// We need to fill `cyclic` with all segments inside cycle
|
|
242
265
|
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
var _didIteratorError3 = false;
|
|
250
|
-
var _iteratorError3 = undefined;
|
|
266
|
+
if (pathList.has(segment.id)) {
|
|
267
|
+
var pathArray = Array.from(pathList);
|
|
268
|
+
var cyclicSegments = pathArray.slice(pathArray.indexOf(segment.id) + 1);
|
|
269
|
+
var _iteratorNormalCompletion3 = true;
|
|
270
|
+
var _didIteratorError3 = false;
|
|
271
|
+
var _iteratorError3 = undefined;
|
|
251
272
|
|
|
273
|
+
try {
|
|
274
|
+
for (var _iterator3 = cyclicSegments[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
275
|
+
var cyclicSegment = _step3.value;
|
|
276
|
+
cyclic.add(cyclicSegment);
|
|
277
|
+
}
|
|
278
|
+
} catch (err) {
|
|
279
|
+
_didIteratorError3 = true;
|
|
280
|
+
_iteratorError3 = err;
|
|
281
|
+
} finally {
|
|
252
282
|
try {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
countPathsToEnd(nextSegment);
|
|
283
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
284
|
+
_iterator3.return();
|
|
256
285
|
}
|
|
257
|
-
} catch (err) {
|
|
258
|
-
_didIteratorError3 = true;
|
|
259
|
-
_iteratorError3 = err;
|
|
260
286
|
} finally {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
_iterator3.return();
|
|
264
|
-
}
|
|
265
|
-
} finally {
|
|
266
|
-
if (_didIteratorError3) {
|
|
267
|
-
throw _iteratorError3;
|
|
268
|
-
}
|
|
287
|
+
if (_didIteratorError3) {
|
|
288
|
+
throw _iteratorError3;
|
|
269
289
|
}
|
|
270
290
|
}
|
|
271
|
-
|
|
272
|
-
return 0;
|
|
273
291
|
}
|
|
274
|
-
} // We have a cached `paths`. Return it.
|
|
275
292
|
|
|
293
|
+
return 0;
|
|
294
|
+
} // add the current segment to pathList
|
|
276
295
|
|
|
277
|
-
if (paths !== undefined) {
|
|
278
|
-
return paths;
|
|
279
|
-
} // Compute `paths` and cache it. Guarding against cycles.
|
|
280
296
|
|
|
297
|
+
pathList.add(segment.id); // We have a cached `paths`. Return it.
|
|
281
298
|
|
|
282
|
-
|
|
299
|
+
if (paths !== undefined) {
|
|
300
|
+
return paths;
|
|
301
|
+
}
|
|
283
302
|
|
|
284
303
|
if (codePath.thrownSegments.includes(segment)) {
|
|
285
304
|
paths = 0;
|
|
@@ -293,8 +312,8 @@ var RuleOfHooks = {
|
|
|
293
312
|
|
|
294
313
|
try {
|
|
295
314
|
for (var _iterator4 = segment.nextSegments[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
296
|
-
var
|
|
297
|
-
paths += countPathsToEnd(
|
|
315
|
+
var nextSegment = _step4.value;
|
|
316
|
+
paths += countPathsToEnd(nextSegment, pathList);
|
|
298
317
|
}
|
|
299
318
|
} catch (err) {
|
|
300
319
|
_didIteratorError4 = true;
|
|
@@ -403,13 +422,14 @@ var RuleOfHooks = {
|
|
|
403
422
|
// `undefined` then we know either that we have an anonymous function
|
|
404
423
|
// expression or our code path is not in a function. In both cases we
|
|
405
424
|
// will want to error since neither are React function components or
|
|
406
|
-
// hook functions
|
|
425
|
+
// hook functions - unless it is an anonymous function argument to
|
|
426
|
+
// forwardRef or memo.
|
|
407
427
|
|
|
408
428
|
var codePathFunctionName = getFunctionName(codePathNode); // This is a valid code path for React hooks if we are directly in a React
|
|
409
429
|
// function component or we are in a hook function.
|
|
410
430
|
|
|
411
431
|
var isSomewhereInsideComponentOrHook = isInsideComponentOrHook(codePathNode);
|
|
412
|
-
var isDirectlyInsideComponentOrHook = codePathFunctionName ? isComponentName(codePathFunctionName) || isHook(codePathFunctionName) :
|
|
432
|
+
var isDirectlyInsideComponentOrHook = codePathFunctionName ? isComponentName(codePathFunctionName) || isHook(codePathFunctionName) : isForwardRefCallback(codePathNode) || isMemoCallback(codePathNode); // Compute the earliest finalizer level using information from the
|
|
413
433
|
// cache. We expect all reachable final segments to have a cache entry
|
|
414
434
|
// after calling `visitSegment()`.
|
|
415
435
|
|
|
@@ -690,10 +710,8 @@ function last(array) {
|
|
|
690
710
|
|
|
691
711
|
/* eslint-disable no-for-of-loops/no-for-of-loops */
|
|
692
712
|
|
|
693
|
-
|
|
694
713
|
var ExhaustiveDeps = {
|
|
695
714
|
meta: {
|
|
696
|
-
fixable: 'code',
|
|
697
715
|
schema: [{
|
|
698
716
|
type: 'object',
|
|
699
717
|
additionalProperties: false,
|
|
@@ -753,7 +771,7 @@ var ExhaustiveDeps = {
|
|
|
753
771
|
|
|
754
772
|
var reactiveHook = node.parent.callee;
|
|
755
773
|
var reactiveHookName = getNodeWithoutReactNamespace(reactiveHook).name;
|
|
756
|
-
var isEffect =
|
|
774
|
+
var isEffect = /Effect($|[^a-z])/g.test(reactiveHookName); // Get the declared dependencies for this reactive hook. If there is no
|
|
757
775
|
// second argument then the reactive callback will re-run on every render.
|
|
758
776
|
// So no need to check for dependency inclusion.
|
|
759
777
|
|
|
@@ -763,7 +781,7 @@ var ExhaustiveDeps = {
|
|
|
763
781
|
if (!declaredDependenciesNode && !isEffect) {
|
|
764
782
|
// These are only used for optimization.
|
|
765
783
|
if (reactiveHookName === 'useMemo' || reactiveHookName === 'useCallback') {
|
|
766
|
-
// TODO: Can this have
|
|
784
|
+
// TODO: Can this have a suggestion?
|
|
767
785
|
context.report({
|
|
768
786
|
node: node.parent.callee,
|
|
769
787
|
message: "React Hook " + reactiveHookName + " does nothing when called with " + "only one argument. Did you forget to pass an array of " + "dependencies?"
|
|
@@ -1239,9 +1257,12 @@ var ExhaustiveDeps = {
|
|
|
1239
1257
|
context.report({
|
|
1240
1258
|
node: node.parent.callee,
|
|
1241
1259
|
message: "React Hook " + reactiveHookName + " contains a call to '" + setStateInsideEffectWithoutDeps + "'. " + "Without a list of dependencies, this can lead to an infinite chain of updates. " + "To fix this, pass [" + _suggestedDependencies.join(', ') + ("] as a second argument to the " + reactiveHookName + " Hook."),
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1260
|
+
suggest: [{
|
|
1261
|
+
desc: "Add dependencies array: [" + _suggestedDependencies.join(', ') + "]",
|
|
1262
|
+
fix: function (fixer) {
|
|
1263
|
+
return fixer.insertTextAfter(node, ", [" + _suggestedDependencies.join(', ') + "]");
|
|
1264
|
+
}
|
|
1265
|
+
}]
|
|
1245
1266
|
});
|
|
1246
1267
|
}
|
|
1247
1268
|
|
|
@@ -1361,18 +1382,15 @@ var ExhaustiveDeps = {
|
|
|
1361
1382
|
message += " To fix this, " + ("wrap the '" + fn.name.name + "' definition into its own useCallback() Hook.");
|
|
1362
1383
|
} else {
|
|
1363
1384
|
message += " Move it inside the " + reactiveHookName + " callback. " + ("Alternatively, wrap the '" + fn.name.name + "' definition into its own useCallback() Hook.");
|
|
1364
|
-
}
|
|
1365
|
-
// Should we suggest removing effect deps as an appropriate fix too?
|
|
1385
|
+
}
|
|
1366
1386
|
|
|
1387
|
+
var suggest; // Only handle the simple case: arrow functions.
|
|
1388
|
+
// Wrapping function declarations can mess up hoisting.
|
|
1367
1389
|
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
fix: function (fixer) {
|
|
1373
|
-
// Only handle the simple case: arrow functions.
|
|
1374
|
-
// Wrapping function declarations can mess up hoisting.
|
|
1375
|
-
if (suggestUseCallback && fn.type === 'Variable') {
|
|
1390
|
+
if (suggestUseCallback && fn.type === 'Variable') {
|
|
1391
|
+
suggest = [{
|
|
1392
|
+
desc: "Wrap the '" + fn.name.name + "' definition into its own useCallback() Hook.",
|
|
1393
|
+
fix: function (fixer) {
|
|
1376
1394
|
return [// TODO: also add an import?
|
|
1377
1395
|
fixer.insertTextBefore(fn.node.init, 'useCallback('), // TODO: ideally we'd gather deps here but it would require
|
|
1378
1396
|
// restructuring the rule code. This will cause a new lint
|
|
@@ -1380,7 +1398,16 @@ var ExhaustiveDeps = {
|
|
|
1380
1398
|
// not adding [] because would that changes semantics.
|
|
1381
1399
|
fixer.insertTextAfter(fn.node.init, ')')];
|
|
1382
1400
|
}
|
|
1383
|
-
}
|
|
1401
|
+
}];
|
|
1402
|
+
} // TODO: What if the function needs to change on every render anyway?
|
|
1403
|
+
// Should we suggest removing effect deps as an appropriate fix too?
|
|
1404
|
+
|
|
1405
|
+
|
|
1406
|
+
context.report({
|
|
1407
|
+
// TODO: Why not report this at the dependency site?
|
|
1408
|
+
node: fn.node,
|
|
1409
|
+
message: message,
|
|
1410
|
+
suggest: suggest
|
|
1384
1411
|
});
|
|
1385
1412
|
});
|
|
1386
1413
|
return;
|
|
@@ -1644,10 +1671,13 @@ var ExhaustiveDeps = {
|
|
|
1644
1671
|
node: declaredDependenciesNode,
|
|
1645
1672
|
message: "React Hook " + context.getSource(reactiveHook) + " has " + ( // To avoid a long message, show the next actionable item.
|
|
1646
1673
|
getWarningMessage(missingDependencies, 'a', 'missing', 'include') || getWarningMessage(unnecessaryDependencies, 'an', 'unnecessary', 'exclude') || getWarningMessage(duplicateDependencies, 'a', 'duplicate', 'omit')) + extraWarning,
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1674
|
+
suggest: [{
|
|
1675
|
+
desc: "Update the dependencies array to be: [" + suggestedDependencies.join(', ') + "]",
|
|
1676
|
+
fix: function (fixer) {
|
|
1677
|
+
// TODO: consider preserving the comments or formatting?
|
|
1678
|
+
return fixer.replaceText(declaredDependenciesNode, "[" + suggestedDependencies.join(', ') + "]");
|
|
1679
|
+
}
|
|
1680
|
+
}]
|
|
1651
1681
|
});
|
|
1652
1682
|
}
|
|
1653
1683
|
}
|
|
@@ -2113,8 +2143,9 @@ var rules = {
|
|
|
2113
2143
|
'exhaustive-deps': ExhaustiveDeps
|
|
2114
2144
|
};
|
|
2115
2145
|
|
|
2116
|
-
var src = Object.freeze({
|
|
2117
|
-
|
|
2146
|
+
var src = /*#__PURE__*/Object.freeze({
|
|
2147
|
+
__proto__: null,
|
|
2148
|
+
rules: rules
|
|
2118
2149
|
});
|
|
2119
2150
|
|
|
2120
2151
|
var eslintPluginReactHooks = src;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v2.
|
|
1
|
+
/** @license React v2.5.1
|
|
2
2
|
* eslint-plugin-react-hooks.production.min.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
@@ -7,45 +7,46 @@
|
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
'use strict';function
|
|
11
|
-
function
|
|
10
|
+
'use strict';function U(a){return"Identifier"===a.type?/^use[A-Z0-9].*$/.test(a.name):"MemberExpression"===a.type&&!a.computed&&U(a.property)?(a=a.object,"Identifier"===a.type&&"React"===a.name):!1}function ca(a){return"Identifier"===a.type?!/^[a-z]/.test(a.name):!1}function da(a,e){return a.name===e||"MemberExpression"===a.type&&"React"===a.object.name&&a.property.name===e}function ea(a){return!!(a.parent&&a.parent.callee&&da(a.parent.callee,"forwardRef"))}
|
|
11
|
+
function fa(a){return!!(a.parent&&a.parent.callee&&da(a.parent.callee,"memo"))}function ha(a){for(;a;){var e=ia(a);if(e&&(ca(e)||U(e))||ea(a)||fa(a))return!0;a=a.parent}return!1}
|
|
12
|
+
function ia(a){if("FunctionDeclaration"===a.type||"FunctionExpression"===a.type&&a.id)return a.id;if("FunctionExpression"===a.type||"ArrowFunctionExpression"===a.type)return"VariableDeclarator"===a.parent.type&&a.parent.init===a?a.parent.id:"AssignmentExpression"===a.parent.type&&a.parent.right===a&&"="===a.parent.operator?a.parent.left:"Property"!==a.parent.type||a.parent.value!==a||a.parent.computed?"AssignmentPattern"!==a.parent.type||a.parent.right!==a||a.parent.computed?void 0:a.parent.left:
|
|
12
13
|
a.parent.key}
|
|
13
|
-
function
|
|
14
|
-
!0){var
|
|
15
|
-
!0})});
|
|
16
|
-
function
|
|
17
|
-
0;
|
|
18
|
-
function
|
|
19
|
-
function
|
|
20
|
-
function
|
|
21
|
-
function
|
|
22
|
-
module.exports={rules:{"rules-of-hooks":{create:function(a){var e=[],b=[];return{onCodePathSegmentStart:function(a){return b.push(a)},onCodePathSegmentEnd:function(){return b.pop()},onCodePathStart:function(){return e.push(new Map)},onCodePathEnd:function(b,d){function
|
|
23
|
-
f.return()}finally{if(
|
|
24
|
-
d=!0;
|
|
25
|
-
}}}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(
|
|
29
|
-
a.report({node:
|
|
30
|
-
(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var
|
|
14
|
+
function W(a){function e(){return{isRequired:!1,isSatisfiedRecursively:!1,hasRequiredNodesBelow:!1,children:new Map}}function b(a,d){d=d.split(".");var k=!0,l=!1,b=void 0;try{for(var g=d[Symbol.iterator](),q;!(k=(q=g.next()).done);k=!0){var m=q.value,x=a.children.get(m);x||(x=e(),a.children.set(m,x));a=x}}catch(D){l=!0,b=D}finally{try{k||null==g.return||g.return()}finally{if(l)throw b;}}return a}function g(a,d,e){d=d.split(".");var k=!0,l=!1,b=void 0;try{for(var g=d[Symbol.iterator](),x;!(k=(x=g.next()).done);k=
|
|
15
|
+
!0){var m=a.children.get(x.value);if(!m)break;e(m);a=m}}catch(D){l=!0,b=D}finally{try{k||null==g.return||g.return()}finally{if(l)throw b;}}}function d(a,e,l,g){a.children.forEach(function(a,k){var b=g(k);a.isSatisfiedRecursively?a.hasRequiredNodesBelow&&l.add(b):a.isRequired?e.add(b):d(a,e,l,function(a){return b+"."+a})})}var x=a.dependencies,n=a.declaredDependencies,y=a.optionalDependencies,l=a.externalDependencies,E=a.isEffect,F=e();x.forEach(function(a,d){b(F,d).isRequired=!0;g(F,d,function(a){a.hasRequiredNodesBelow=
|
|
16
|
+
!0})});n.forEach(function(a){b(F,a.key).isSatisfiedRecursively=!0});y.forEach(function(a){b(F,a).isSatisfiedRecursively=!0});a=new Set;var m=new Set;d(F,a,m,function(a){return a});var t=[],A=new Set,B=new Set;n.forEach(function(a){a=a.key;m.has(a)?-1===t.indexOf(a)?t.push(a):B.add(a):!E||a.endsWith(".current")||l.has(a)?A.add(a):-1===t.indexOf(a)&&t.push(a)});a.forEach(function(a){t.push(a)});return{suggestedDependencies:t,unnecessaryDependencies:A,duplicateDependencies:B,missingDependencies:a}}
|
|
17
|
+
function ja(a){var e=a.declaredDependenciesNode,b=a.componentScope,g=a.scope;return a.declaredDependencies.map(function(a){a=b.set.get(a.key);if(null==a)return null;var d=a.defs[0];return null==d?null:"Variable"===d.type&&"VariableDeclarator"===d.node.type&&null!=d.node.init&&("ArrowFunctionExpression"===d.node.init.type||"FunctionExpression"===d.node.init.type)||"FunctionName"===d.type&&"FunctionDeclaration"===d.node.type?a:null}).filter(Boolean).map(function(a){var d=a.defs[0];a:{for(var b=!1,y=
|
|
18
|
+
0;y<a.references.length;y++){var l=a.references[y];if(l.writeExpr)if(b){a=!0;break a}else{b=!0;continue}for(var E=l.from;E!==g&&null!=E;)E=E.upper;if(E!==g&&!ka(e,l.identifier)){a=!0;break a}}a=!1}return{fn:d,suggestUseCallback:a}})}function la(a){return"MemberExpression"!==a.parent.type||a.parent.object!==a||"current"===a.parent.property.name||a.parent.computed||null!=a.parent.parent&&"CallExpression"===a.parent.parent.type&&a.parent.parent.callee===a.parent?a:la(a.parent)}
|
|
19
|
+
function Y(a){if("Identifier"===a.type)return a.name;if("MemberExpression"!==a.type||a.computed)throw Error("Unsupported node type: "+a.type);var e=Y(a.object);a=Y(a.property);return e+"."+a}function ma(a){return"MemberExpression"!==a.type||"Identifier"!==a.object.type||"React"!==a.object.name||"Identifier"!==a.property.type||a.computed?a:a.property}
|
|
20
|
+
function na(a,e){var b=ma(a);if("Identifier"!==b.type)return null;switch(b.name){case "useEffect":case "useLayoutEffect":case "useCallback":case "useMemo":return 0;case "useImperativeHandle":return 1;default:if(b===a&&e&&e.additionalHooks){try{var g=Y(b)}catch(d){if(/Unsupported node type/.test(d.message))return 0;throw d;}return e.additionalHooks.test(g)?0:-1}return-1}}
|
|
21
|
+
function Z(a,e){for(var b=[a],g=null;b.length;){g=b.shift();if("Identifier"===g.type&&g.name===e.name&&g.range[0]===e.range[0]&&g.range[1]===e.range[1])return g;if(ka(g,e)){a=0;for(var d=Object.entries(g);a<d.length;a++){var x=d[a],n=x[1];"parent"!==x[0]&&(oa(n)?(n.parent=g,b.push(n)):Array.isArray(n)&&n.forEach(function(a){oa(a)&&(a.parent=g,b.push(a))}))}}}return null}
|
|
22
|
+
function pa(a){for(var e="",b=0;b<a.length;b++)e+=a[b],0===b&&2===a.length?e+=" and ":b===a.length-2&&2<a.length?e+=", and ":b<a.length-1&&(e+=", ");return e}function oa(a){return"object"===typeof a&&null!==a&&!Array.isArray(a)&&"string"===typeof a.type}function ka(a,e){return a.range[0]<=e.range[0]&&a.range[1]>=e.range[1]}
|
|
23
|
+
module.exports={__proto__:null,rules:{"rules-of-hooks":{create:function(a){var e=[],b=[];return{onCodePathSegmentStart:function(a){return b.push(a)},onCodePathSegmentEnd:function(){return b.pop()},onCodePathStart:function(){return e.push(new Map)},onCodePathEnd:function(b,d){function g(a,d){var c=g.cache,h=c.get(a.id);d=new Set(d);if(d.has(a.id)){c=[].concat(d);a=c.slice(c.indexOf(a.id)+1);c=!0;h=!1;var f=void 0;try{for(var r=a[Symbol.iterator](),M;!(c=(M=r.next()).done);c=!0)E.add(M.value)}catch(J){h=
|
|
24
|
+
!0,f=J}finally{try{c||null==r.return||r.return()}finally{if(h)throw f;}}return 0}d.add(a.id);if(void 0!==h)return h;if(b.thrownSegments.includes(a))h=0;else if(0===a.prevSegments.length)h=1;else{h=0;r=!0;M=!1;var e=void 0;try{f=a.prevSegments[Symbol.iterator]();for(var l;!(r=(l=f.next()).done);r=!0)h+=g(l.value,d)}catch(J){M=!0,e=J}finally{try{r||null==f.return||f.return()}finally{if(M)throw e;}}}a.reachable&&0===h?c.delete(a.id):c.set(a.id,h);return h}function n(a,d){var c=n.cache,h=c.get(a.id);
|
|
25
|
+
d=new Set(d);if(d.has(a.id)){c=Array.from(d);a=c.slice(c.indexOf(a.id)+1);c=!0;h=!1;var f=void 0;try{for(var r=a[Symbol.iterator](),e;!(c=(e=r.next()).done);c=!0)E.add(e.value)}catch(J){h=!0,f=J}finally{try{c||null==r.return||r.return()}finally{if(h)throw f;}}return 0}d.add(a.id);if(void 0!==h)return h;if(b.thrownSegments.includes(a))h=0;else if(0===a.nextSegments.length)h=1;else{h=0;r=!0;e=!1;var l=void 0;try{f=a.nextSegments[Symbol.iterator]();for(var g;!(r=(g=f.next()).done);r=!0)h+=n(g.value,
|
|
26
|
+
d)}catch(J){e=!0,l=J}finally{try{r||null==f.return||f.return()}finally{if(e)throw l;}}}c.set(a.id,h);return h}function y(a){var d=y.cache,c=d.get(a.id);if(null===c)return Infinity;if(void 0!==c)return c;d.set(a.id,null);if(0===a.prevSegments.length)c=1;else{c=Infinity;var h=!0,f=!1,r=void 0;try{for(var e=a.prevSegments[Symbol.iterator](),b;!(h=(b=e.next()).done);h=!0){var l=y(b.value);l<c&&(c=l)}}catch(J){f=!0,r=J}finally{try{h||null==e.return||e.return()}finally{if(f)throw r;}}c+=1}d.set(a.id,c);
|
|
27
|
+
return c}var l=e.pop();if(0!==l.size){var E=new Set;g.cache=new Map;n.cache=new Map;y.cache=new Map;var F=n(b.initialSegment),m=ia(d),t=ha(d),A=m?ca(m)||U(m):ea(d)||fa(d),B=Infinity,k=!0,q=!1,I=void 0;try{for(var w=b.finalSegments[Symbol.iterator](),L;!(k=(L=w.next()).done);k=!0){var X=L.value;if(X.reachable){var T=y(X);T<B&&(B=T)}}}catch(G){q=!0,I=G}finally{try{k||null==w.return||w.return()}finally{if(q)throw I;}}k=!0;q=!1;I=void 0;try{for(var z=l[Symbol.iterator](),Q;!(k=(Q=z.next()).done);k=!0){var D=
|
|
28
|
+
Q.value,C=D[0],N=D[1];if(C.reachable){var K=0===C.nextSegments.length?B<=y(C):B<y(C),R=g(C)*n(C),H=E.has(C.id);l=!0;w=!1;L=void 0;try{for(var v=N[Symbol.iterator](),O;!(l=(O=v.next()).done);l=!0){var p=O.value;H&&a.report({node:p,message:'React Hook "'+a.getSource(p)+'" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.'});if(A){if(!H&&R!==F){var V='React Hook "'+a.getSource(p)+'" is called conditionally. React Hooks must be called in the exact same order in every component render.'+
|
|
29
|
+
(K?" Did you accidentally call a React Hook after an early return?":"");a.report({node:p,message:V})}}else if(!d.parent||"MethodDefinition"!==d.parent.type&&"ClassProperty"!==d.parent.type||d.parent.value!==d)if(m){var P='React Hook "'+a.getSource(p)+'" is called in function "'+(a.getSource(m)+'" that is neither a React function component nor a custom React Hook function.');a.report({node:p,message:P})}else if("Program"===d.type){var S='React Hook "'+a.getSource(p)+'" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.';
|
|
30
|
+
a.report({node:p,message:S})}else if(t){var u='React Hook "'+a.getSource(p)+'" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.';a.report({node:p,message:u})}}}catch(G){w=!0,L=G}finally{try{l||null==v.return||v.return()}finally{if(w)throw L;}}}}}catch(G){q=!0,I=G}finally{try{k||null==z.return||z.return()}finally{if(q)throw I;}}}},CallExpression:function(a){if(U(a.callee)){var d=e[e.length-1],g=b[b.length-1],n=d.get(g);n||
|
|
31
|
+
(n=[],d.set(g,n));n.push(a.callee)}}}}},"exhaustive-deps":{meta:{schema:[{type:"object",additionalProperties:!1,properties:{additionalHooks:{type:"string"}}}]},create:function(a){function e(a,d){return function(e){if(d.has(e))return d.get(e);var b=a(e);d.set(e,b);return b}}function b(b){function l(a){var c=!0,f=!1,r=void 0;try{for(var d=a.references[Symbol.iterator](),e;!(c=(e=d.next()).done);c=!0){var g=e.value;if(g.resolved&&I.has(g.resolved.scope)){var m=Z(b,g.identifier),k=la(m),n=Y(k),q;if(q=
|
|
32
|
+
B&&"Identifier"===k.type&&"MemberExpression"===k.parent.type&&!k.parent.computed&&"Identifier"===k.parent.property.type&&"current"===k.parent.property.name){for(var p=g.from,u=!1;p.block!==b;)"function"===p.type&&(u=null!=p.block.parent&&"ReturnStatement"===p.block.parent.type),p=p.upper;q=u}q&&T.set(n,{reference:g,dependencyNode:k});var t=g.resolved.defs[0];if(null!=t&&(null==t.node||t.node.init!==b.parent)&&"TypeParameter"!==t.type)if(z.has(n))z.get(n).references.push(g);else{var w=g.resolved,x=
|
|
33
|
+
L(w)||X(w);z.set(n,{isStatic:x,references:[g]})}}}}catch(ba){f=!0,r=ba}finally{try{c||null==d.return||d.return()}finally{if(f)throw r;}}c=!0;f=!1;r=void 0;try{for(var v=a.childScopes[Symbol.iterator](),y;!(c=(y=v.next()).done);c=!0)l(y.value)}catch(ba){f=!0,r=ba}finally{try{c||null==v.return||v.return()}finally{if(f)throw r;}}}function F(a,h,f,d){return 0===a.size?null:(1<a.size?"":h+" ")+f+" "+(1<a.size?"dependencies":"dependency")+": "+pa(Array.from(a).sort().map(function(a){return"'"+a+"'"}))+
|
|
34
|
+
(". Either "+d+" "+(1<a.size?"them":"it")+" or remove the dependency array.")}if(("FunctionExpression"===b.type||"ArrowFunctionExpression"===b.type)&&"CallExpression"===b.parent.type){var m=na(b.parent.callee,g);if(b.parent.arguments[m]===b){var t=b.parent.callee,A=ma(t).name,B=/Effect($|[^a-z])/g.test(A),k=b.parent.arguments[m+1];if(k||B){B&&b.async&&a.report({node:b,message:"Effect callbacks are synchronous to prevent race conditions. Put the async function inside:\n\nuseEffect(() => {\n async function fetchData() {\n // You can await here\n const response = await MyAPI.getData(someId);\n // ...\n }\n fetchData();\n}, [someId]); // Or [] if effect doesn't need props or state\n\nLearn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching"});
|
|
35
|
+
var q=a.getScope(),I=new Set,w=null;for(m=q.upper;m;){I.add(m);if("function"===m.type)break;m=m.upper}if(m){w=m;var L=e(function(a){if(!Array.isArray(a.defs))return!1;var c=a.defs[0];if(null==c||"VariableDeclarator"!==c.node.type)return!1;var f=c.node.init;if(null==f)return!1;var b=c.node.parent;if(null==b&&(Z(w.block,c.node.id),b=c.node.parent,null==b))return!1;if("const"===b.kind&&"Literal"===f.type&&("string"===typeof f.value||"number"===typeof f.value||null===f.value))return!0;if("CallExpression"!==
|
|
35
36
|
f.type)return!1;f=f.callee;"MemberExpression"!==f.type||"React"!==f.object.name||null==f.property||f.computed||(f=f.property);if("Identifier"!==f.type)return!1;c=c.node.id;f=f.name;if("useRef"===f&&"Identifier"===c.type)return!0;if(("useState"===f||"useReducer"===f)&&"ArrayPattern"===c.type&&2===c.elements.length&&Array.isArray(a.identifiers)){if(c.elements[1]===a.identifiers[0]){if("useState"===f)for(a=a.references,f=0;f<a.length;f++)d.set(a[f].identifier,c.elements[0]);return!0}if(c.elements[0]===
|
|
36
|
-
a.identifiers[0]&&"useState"===f)for(a=a.references,c=0;c<a.length;c++)
|
|
37
|
-
!
|
|
38
|
-
(
|
|
39
|
-
(a.getSource(
|
|
40
|
-
else{try{var b=
|
|
41
|
-
return}throw
|
|
42
|
-
c.fn
|
|
43
|
-
"useCallback("),a.insertTextAfter(b.node.init,")")]}})});else{!
|
|
44
|
-
"' aren't valid dependencies because mutating them doesn't re-render the component.";else if(0<
|
|
45
|
-
|
|
46
|
-
d&&null!=d.parent&&"CallExpression"===d.parent.type&&d.parent.callee===d){c=!0;break}c&&(
|
|
47
|
-
form:"updater"}:
|
|
48
|
-
|
|
49
|
-
"omit"))+
|
|
50
|
-
|
|
51
|
-
new WeakMap;return{FunctionExpression:b,ArrowFunctionExpression:b}}}}};
|
|
37
|
+
a.identifiers[0]&&"useState"===f)for(a=a.references,c=0;c<a.length;c++)x.add(a[c].identifier)}return!1},n),X=e(function(a){if(!Array.isArray(a.defs))return!1;a=a.defs[0];if(null==a||null==a.node||null==a.node.id)return!1;var c=a.node,f=w.childScopes;a=null;var b;for(b=0;b<f.length;b++){var d=f[b],e=d.block;if("FunctionDeclaration"===c.type&&e===c||"VariableDeclarator"===c.type&&e.parent===c){a=d;break}}if(null==a)return!1;for(b=0;b<a.through.length;b++)if(c=a.through[b],null!=c.resolved&&I.has(c.resolved.scope)&&
|
|
38
|
+
!L(c.resolved))return!1;return!0},y),T=new Map,z=new Map;l(q);T.forEach(function(c,b){var f=c.dependencyNode;c=c.reference.resolved.references;for(var d=!1,e=0;e<c.length;e++){var h=c[e].identifier.parent;if(null!=h&&"MemberExpression"===h.type&&!h.computed&&"Identifier"===h.property.type&&"current"===h.property.name&&"AssignmentExpression"===h.parent.type&&h.parent.left===h){d=!0;break}}d||a.report({node:f.parent.property,message:"The ref value '"+b+".current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy '"+
|
|
39
|
+
(b+".current' to a variable inside the effect, and use that variable in the cleanup function.")})});var Q=new Set,D=new Set;z.forEach(function(c,b){var f=c.references;c.isStatic&&D.add(b);f.forEach(function(c){c.writeExpr&&(c=c.writeExpr,Q.has(b)||(Q.add(b),a.report({node:c,message:"Assignments to the '"+b+"' variable from inside React Hook "+(a.getSource(t)+" will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside ")+
|
|
40
|
+
(a.getSource(t)+".")})))})});if(!(0<Q.size))if(k){var C=[],N=new Set;"ArrayExpression"!==k.type?a.report({node:k,message:"React Hook "+a.getSource(t)+" was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies."}):k.elements.forEach(function(c){if(null!==c)if("SpreadElement"===c.type)a.report({node:c,message:"React Hook "+a.getSource(t)+" has a spread element in its dependency array. This means we can't statically verify whether you've passed the correct dependencies."});
|
|
41
|
+
else{try{var b=Y(c)}catch(M){if(/Unsupported node type/.test(M.message)){"Literal"===c.type?z.has(c.value)?a.report({node:c,message:"The "+c.raw+" literal is not a valid dependency because it never changes. Did you mean to include "+(c.value+" in the array instead?")}):a.report({node:c,message:"The "+c.raw+" literal is not a valid dependency because it never changes. You can safely remove it."}):a.report({node:c,message:"React Hook "+a.getSource(t)+" has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked."});
|
|
42
|
+
return}throw M;}for(var f=c;"MemberExpression"===f.type;)f=f.object;var d=!w.through.some(function(a){return a.identifier===f});C.push({key:b,node:c});d||N.add(b)}});var K=W({dependencies:z,declaredDependencies:C,optionalDependencies:D,externalDependencies:N,isEffect:B}),R=K.suggestedDependencies;m=K.unnecessaryDependencies;var H=K.missingDependencies;K=K.duplicateDependencies;if(0===K.size+H.size+m.size)ja({declaredDependencies:C,declaredDependenciesNode:k,componentScope:w,scope:q}).forEach(function(c){var b=
|
|
43
|
+
c.fn;c=c.suggestUseCallback;var f="The '"+b.name.name+"' function makes the dependencies of "+(A+" Hook (at line "+k.loc.start.line+") change on every render.");f=c?f+(" To fix this, wrap the '"+(b.name.name+"' definition into its own useCallback() Hook.")):f+(" Move it inside the "+A+" callback. Alternatively, wrap the '"+(b.name.name+"' definition into its own useCallback() Hook."));var d;c&&"Variable"===b.type&&(d=[{desc:"Wrap the '"+b.name.name+"' definition into its own useCallback() Hook.",
|
|
44
|
+
fix:function(a){return[a.insertTextBefore(b.node.init,"useCallback("),a.insertTextAfter(b.node.init,")")]}}]);a.report({node:b.node,message:f,suggest:d})});else{!B&&0<H.size&&(R=W({dependencies:z,declaredDependencies:[],optionalDependencies:D,externalDependencies:N,isEffect:B}).suggestedDependencies);(function(){if(0===C.length)return!0;var a=C.map(function(a){return a.key}),b=a.slice().sort();return a.join(",")===b.join(",")})()&&R.sort();var v="";if(0<m.size){var O=null;Array.from(m.keys()).forEach(function(a){null===
|
|
45
|
+
O&&a.endsWith(".current")&&(O=a)});if(null!==O)v=" Mutable values like '"+O+"' aren't valid dependencies because mutating them doesn't re-render the component.";else if(0<N.size){var p=Array.from(N)[0];q.set.has(p)||(v=" Outer scope values like '"+p+"' aren't valid dependencies because mutating them doesn't re-render the component.")}}if(!v&&H.has("props")){q=z.get("props");if(null==q)return;q=q.references;if(!Array.isArray(q))return;p=!0;for(var V=0;V<q.length;V++){var P=Z(w.block,q[V].identifier);
|
|
46
|
+
if(!P){p=!1;break}P=P.parent;if(null==P){p=!1;break}if("MemberExpression"!==P.type){p=!1;break}}p&&(v=" However, 'props' will change when *any* prop changes, so the preferred fix is to destructure the 'props' object outside of the "+(A+" call and refer to those specific props inside ")+(a.getSource(t)+"."))}if(!v&&0<H.size){var S=null;H.forEach(function(a){if(!S){var c=w.set.get(a),b=z.get(a);if(b.references[0].resolved===c&&(c=c.defs[0],null!=c&&null!=c.name&&"Parameter"===c.type)){c=!1;for(var d,
|
|
47
|
+
e=0;e<b.references.length;e++)if(d=b.references[e].identifier,null!=d&&null!=d.parent&&"CallExpression"===d.parent.type&&d.parent.callee===d){c=!0;break}c&&(S=a)}}});null!==S&&(v=" If '"+S+"' changes too often, find the parent component that defines it and wrap that definition in useCallback.")}if(!v&&0<H.size){var u=null;H.forEach(function(a){if(null===u)for(var c=z.get(a).references,b,e,g=0;g<c.length;g++){b=c[g].identifier;for(e=b.parent;null!=e&&e!==w.block;){if("CallExpression"===e.type){var k=
|
|
48
|
+
d.get(e.callee);if(null!=k){k.name===a?u={missingDep:a,setter:e.callee.name,form:"updater"}:x.has(b)?u={missingDep:a,setter:e.callee.name,form:"reducer"}:(b=c[g].resolved,null!=b&&(b=b.defs[0],null!=b&&"Parameter"===b.type&&(u={missingDep:a,setter:e.callee.name,form:"inlineReducer"})));break}}e=e.parent}if(null!==u)break}});if(null!==u)switch(u.form){case "reducer":v=" You can also replace multiple useState variables with useReducer if '"+(u.setter+"' needs the current value of '")+(u.missingDep+
|
|
49
|
+
"'.");break;case "inlineReducer":v=" If '"+u.setter+"' needs the current value of '"+(u.missingDep+"', you can also switch to useReducer instead of useState and read '")+(u.missingDep+"' in the reducer.");break;case "updater":v=" You can also do a functional update '"+u.setter+"("+u.missingDep.substring(0,1)+" => ...)' if you only need '"+u.missingDep+"' in the '"+(u.setter+"' call.");break;default:throw Error("Unknown case.");}}a.report({node:k,message:"React Hook "+a.getSource(t)+" has "+(F(H,"a",
|
|
50
|
+
"missing","include")||F(m,"an","unnecessary","exclude")||F(K,"a","duplicate","omit"))+v,suggest:[{desc:"Update the dependencies array to be: ["+R.join(", ")+"]",fix:function(a){return a.replaceText(k,"["+R.join(", ")+"]")}}]})}}else{var G=null;z.forEach(function(a,e){G||a.references.forEach(function(a){if(!G&&d.has(a.identifier)){for(a=a.from;"function"!==a.type;)a=a.upper;a.block===b&&(G=e)}})});if(G){var aa=W({dependencies:z,declaredDependencies:[],optionalDependencies:D,externalDependencies:new Set,
|
|
51
|
+
isEffect:!0}).suggestedDependencies;a.report({node:b.parent.callee,message:"React Hook "+A+" contains a call to '"+G+"'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass ["+aa.join(", ")+("] as a second argument to the "+A+" Hook."),suggest:[{desc:"Add dependencies array: ["+aa.join(", ")+"]",fix:function(a){return a.insertTextAfter(b,", ["+aa.join(", ")+"]")}}]})}}}}else"useMemo"!==A&&"useCallback"!==A||a.report({node:b.parent.callee,message:"React Hook "+
|
|
52
|
+
A+" does nothing when called with only one argument. Did you forget to pass an array of dependencies?"})}}}var g={additionalHooks:a.options&&a.options[0]&&a.options[0].additionalHooks?new RegExp(a.options[0].additionalHooks):void 0},d=new WeakMap,x=new WeakSet,n=new WeakMap,y=new WeakMap;return{FunctionExpression:b,ArrowFunctionExpression:b}}}}};
|