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

Refactor triggerErrorAndCatch function #24181

Closed

Conversation

Jahb
Copy link

@Jahb Jahb commented Mar 27, 2022

Summary

For a university project, we ran some code quality analysis tools on the React repo, namely SonarQuabe .
This PR is fixing some bad code smells it detected in the fixtures/error-handing/index.js.
Code Smells Resolved:

  • Refactored duplicated code.
    • triggerErrorAndCatch() was function identical in 2 places in the file. It's been refactored to a function and called when needed. To improve readability and maintainability.

How did you test this change?

Running the testing suite resulted in no new failed tests.

@sizebot
Copy link

sizebot commented Mar 27, 2022

Comparing: e7d0053...309ceba

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 131.32 kB 131.32 kB = 41.96 kB 41.96 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 136.38 kB 136.38 kB = 43.42 kB 43.42 kB
facebook-www/ReactDOM-prod.classic.js = 432.73 kB 432.73 kB = 79.60 kB 79.60 kB
facebook-www/ReactDOM-prod.modern.js = 417.73 kB 417.73 kB = 77.21 kB 77.22 kB
facebook-www/ReactDOMForked-prod.classic.js = 432.73 kB 432.73 kB = 79.60 kB 79.60 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 309ceba

@rickhanlonii
Copy link
Member

Hey @Jahb, thanks for running this analysis and submitting a PR. I'm going to close this for a couple reasons, I hope the explanations make sense.

First, this code is in our example fixtures, where we expect users may copy/paste from the examples. In that case, we want users to be able to copy code the way that they would write naturally, not artificially refactored because of the duplication we would have by including multiple examples. For example, if you copied just one of the components, you wouldn't typically move the function outside of the class, so you wouldn't want to copy it from our example that way.

Second, even if this wasn't in the examples, as a team we tend to value WET over DRY, so you will see a ton of duplication in the React codebase. I appreciate that this is somewhat controversial, but we've found that this style works well for us.

Finally, we don't tend to merge any sort of PRs that only refactor, because these tend to have a high bug-to-value ratio, introducing subtle bugs that are hard to find for a marginally low value.

Hope this makes sense, thanks again!

@Jahb
Copy link
Author

Jahb commented Mar 27, 2022

Finally, we don't tend to merge any sort of PRs that only refactor, because these tend to have a high bug-to-value ratio, introducing subtle bugs that are hard to find for a marginally low value

I see, most of the PRs I made today were refactors I understand what you mean when you look at it in terms of bug-value ratio. Thanks for letting me know.

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

Successfully merging this pull request may close these issues.

None yet

4 participants