eslint-plugin-react-hooks 7.0.0-canary-58bdc0bb-20251019 → 7.0.0-canary-2bcbf254-20251020

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.
@@ -50387,21 +50387,24 @@ function validateUseMemo(fn) {
50387
50387
  return errors.asResult();
50388
50388
  }
50389
50389
  function validateNoContextVariableAssignment(fn, errors) {
50390
+ const context = new Set(fn.context.map(place => place.identifier.id));
50390
50391
  for (const block of fn.body.blocks.values()) {
50391
50392
  for (const instr of block.instructions) {
50392
50393
  const value = instr.value;
50393
50394
  switch (value.kind) {
50394
50395
  case 'StoreContext': {
50395
- errors.pushDiagnostic(CompilerDiagnostic.create({
50396
- category: ErrorCategory.UseMemo,
50397
- reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50398
- description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50399
- suggestions: null,
50400
- }).withDetails({
50401
- kind: 'error',
50402
- loc: value.lvalue.place.loc,
50403
- message: 'Cannot reassign variable',
50404
- }));
50396
+ if (context.has(value.lvalue.place.identifier.id)) {
50397
+ errors.pushDiagnostic(CompilerDiagnostic.create({
50398
+ category: ErrorCategory.UseMemo,
50399
+ reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50400
+ description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50401
+ suggestions: null,
50402
+ }).withDetails({
50403
+ kind: 'error',
50404
+ loc: value.lvalue.place.loc,
50405
+ message: 'Cannot reassign variable',
50406
+ }));
50407
+ }
50405
50408
  break;
50406
50409
  }
50407
50410
  }
@@ -50214,21 +50214,24 @@ function validateUseMemo(fn) {
50214
50214
  return errors.asResult();
50215
50215
  }
50216
50216
  function validateNoContextVariableAssignment(fn, errors) {
50217
+ const context = new Set(fn.context.map(place => place.identifier.id));
50217
50218
  for (const block of fn.body.blocks.values()) {
50218
50219
  for (const instr of block.instructions) {
50219
50220
  const value = instr.value;
50220
50221
  switch (value.kind) {
50221
50222
  case 'StoreContext': {
50222
- errors.pushDiagnostic(CompilerDiagnostic.create({
50223
- category: ErrorCategory.UseMemo,
50224
- reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50225
- description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50226
- suggestions: null,
50227
- }).withDetails({
50228
- kind: 'error',
50229
- loc: value.lvalue.place.loc,
50230
- message: 'Cannot reassign variable',
50231
- }));
50223
+ if (context.has(value.lvalue.place.identifier.id)) {
50224
+ errors.pushDiagnostic(CompilerDiagnostic.create({
50225
+ category: ErrorCategory.UseMemo,
50226
+ reason: 'useMemo() callbacks may not reassign variables declared outside of the callback',
50227
+ description: 'useMemo() callbacks must be pure functions and cannot reassign variables defined outside of the callback function',
50228
+ suggestions: null,
50229
+ }).withDetails({
50230
+ kind: 'error',
50231
+ loc: value.lvalue.place.loc,
50232
+ message: 'Cannot reassign variable',
50233
+ }));
50234
+ }
50232
50235
  break;
50233
50236
  }
50234
50237
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks",
3
3
  "description": "ESLint rules for React Hooks",
4
- "version": "7.0.0-canary-58bdc0bb-20251019",
4
+ "version": "7.0.0-canary-2bcbf254-20251020",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/facebook/react.git",