-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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
lib/rules/display-name.js
Outdated
description: | ||
'Disallow missing displayName in a React component definition', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code: ` | ||
import React, { memo } from 'react' | ||
|
||
const TestComponent = function () { | ||
const memo = (cb) => cb() | ||
|
||
const Comp = memo(() => { | ||
return <div>shadowed</div> | ||
}) | ||
|
||
return Comp | ||
} |
There was a problem hiding this comment.
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?
currentNode.type === 'FunctionDeclaration' | ||
|| currentNode.type === 'FunctionExpression' | ||
|| currentNode.type === 'ArrowFunctionExpression' |
There was a problem hiding this comment.
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>
})
}
There was a problem hiding this comment.
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.
Co-authored-by: Jordan Harband <[email protected]>
Co-authored-by: Jordan Harband <[email protected]>
Fixes #3924