Skip to content
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

[Fix]: only detect functions that return JSX somewhere as components #2707

Conversation

jzabala
Copy link
Contributor

@jzabala jzabala commented Jul 10, 2020

Registering all functions that return JSX + null as components has bring a lot of false positives for normal functions that just happen to return null somewhere.

In this PR I propose a new approach to detecting components by finding all return statements in a function and only marking the function as a component if one of them returns JSX.

Fixes #2010

@jzabala jzabala force-pushed the fix/only-functions-returning-jsx-are-detected-as-components branch 2 times, most recently from b5e82ea to c58c414 Compare July 10, 2020 21:59
@ljharb
Copy link
Member

ljharb commented Jul 10, 2020

In React 16, returning an array, a string, or a number (and I think a boolean) are all valid components.

@jzabala
Copy link
Contributor Author

jzabala commented Jul 10, 2020

In React 16, returning an array, a string, or a number (and I think a boolean) are all valid components.

Yeah, but adding those types in my opinion will bring even more false positives that the null case.

By the way the only meaningful thing that this PR those is to remove the null check and collect all return statements from functions. The isReturningJSX algorithm is the same. That is why almost no test was broken.

@jzabala
Copy link
Contributor Author

jzabala commented Jul 10, 2020

Closed based in #2707 (comment)

@jzabala jzabala closed this Jul 10, 2020
@jzabala jzabala deleted the fix/only-functions-returning-jsx-are-detected-as-components branch July 11, 2020 00:27
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.

Non sfc function shows "react/no-this-in-sfc"
2 participants