Skip to content

[Fix] display-name: avoid false positive when React is shadowed #3926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hyeonbinHur
Copy link

Fixes #3924

Copy link

codecov bot commented May 22, 2025

Codecov Report

Attention: Patch coverage is 97.40260% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.67%. Comparing base (dd2e968) to head (30f0022).

Files with missing lines Patch % Lines
lib/rules/display-name.js 97.40% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3926      +/-   ##
==========================================
- Coverage   97.73%   97.67%   -0.07%     
==========================================
  Files         136      136              
  Lines        9997    10047      +50     
  Branches     3715     3748      +33     
==========================================
+ Hits         9771     9813      +42     
- Misses        226      234       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

can't review til style diffs are reverted

Comment on lines 34 to 35
description:
'Disallow missing displayName in a React component definition',
Copy link
Member

Choose a reason for hiding this comment

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

please don't run prettier on projects that don't use it :-) and please revert all unrelated style changes.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I forgot to disable some style-related settings, which caused unnecessary formatting changes. I’ll remove the unnecessary style edits and commit again soon. Thanks for the review and the feedback!

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion is to keep those always disabled, and only use eslint to format files.

Choose a reason for hiding this comment

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

@ljharb ljharb marked this pull request as draft May 22, 2025 18:42
Comment on lines +46 to +57
code: `
import React, { memo } from 'react'

const TestComponent = function () {
const memo = (cb) => cb()

const Comp = memo(() => {
return <div>shadowed</div>
})

return Comp
}
Copy link
Member

Choose a reason for hiding this comment

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

can we get every "valid" example with shadowing, also added as an invalid example without the shadowing?

Comment on lines +206 to +208
currentNode.type === 'FunctionDeclaration'
|| currentNode.type === 'FunctionExpression'
|| currentNode.type === 'ArrowFunctionExpression'

Choose a reason for hiding this comment

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

Why only these scopes? For example what about BlockStatement:

{
  const memo = (cb) => cb()
  const forwardRef = (cb) => cb()
  const React = { memo, forwardRef }

  const BlockReactShadowedMemo = React.memo(() => {
    return <div>shadowed</div>
  })
}

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the review. Let me take a quick look and try to find a better algorithm to cover all test cases.

hyeonbinHur and others added 2 commits May 23, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: display-name false positive when React is shadowed
3 participants