Skip to content

Conversation

@kacper-mikolajczak
Copy link
Contributor

@kacper-mikolajczak kacper-mikolajczak commented Nov 23, 2025

$ Expensify/App#76362

Intro

Create a new ESLint rule no-deep-equal-in-memo that enforces the PERF-5 guideline by detecting deep equality checks in React.memo comparison functions and suggesting shallow comparisons instead.

Key Design Decisions

  1. No Autofix: Cannot automatically determine which properties should be compared, so manual intervention is required
  2. Detect Both Import Styles: Handle both React.memo and memo named imports
  3. Deep Comparison Functions: Focus on deepEqual, isEqual, and _.isEqual as the most common patterns
  4. Clear Error Messages: Include the specific function name in the error message to help developers understand what needs to be changed
  5. AST Traversal: Similar to prefer-narrow-hook-dependencies, use recursive AST traversal to find deep comparison calls within the comparison function body

Rule Logic

  • Detect React.memo() calls (namespace import) and memo() calls (named import from 'react')
  • Check if a second argument (comparison function) is provided
  • Traverse the comparison function body to find calls to deep comparison functions:
    • deepEqual(...) - direct calls
    • isEqual(...) - direct calls or lodash
    • _.isEqual(...) - lodash with underscore
  • Report violations when deep comparison functions are found

@github-actions
Copy link
Contributor

github-actions bot commented Nov 23, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@kacper-mikolajczak kacper-mikolajczak force-pushed the feat/no-deep-equal-in-memo branch from f79b10e to c0744c1 Compare December 1, 2025 09:22
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, how much time does it add to the total eslint time?

@kacper-mikolajczak
Copy link
Contributor Author

kacper-mikolajczak commented Dec 2, 2025

@mountiny Last CI run was about 25 minutes, so it seems there's no much added overhead. However, job was failing - I will report back to you with complete green check run when we deal with all the remaining errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants