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

Enable a lint rule not to define after return and fix existing callsites #17885

Closed
sebmarkbage opened this issue Jan 21, 2020 · 14 comments · Fixed by #19733
Closed

Enable a lint rule not to define after return and fix existing callsites #17885

sebmarkbage opened this issue Jan 21, 2020 · 14 comments · Fixed by #19733

Comments

@sebmarkbage
Copy link
Collaborator

https://twitter.com/therealyashsriv/status/1219691914523545601

We shouldn't generate code that might cause browser or linting to complain.

function getPooledWarningPropertyDefinition(propName, getVal) {

It's also just a confusing pattern at best.

@M-Izadmehr
Copy link
Contributor

Hey,
If possible I would like to take a look into this issue:)

@bvaughn
Copy link
Contributor

bvaughn commented Jan 21, 2020

@M-Izadmehr This issue is all yours! 😄

We've added the "good first issue (taken)" label so that others will know not to start work on the issue. If you change your mind about the issue, no worries! Just let us know so that we can remove the label and free it up for someone else to claim.

Cheers!

@sebmarkbage
Copy link
Collaborator Author

@M-Izadmehr Great! Thanks for taking a look. I think the first step is to look at our es-lint config and enable a canonical lint rule that already exists upstream.

After that you should be able to open a PR which should fail the lint rule. After that you could do a separate commit that contains the code fixes. I wouldn't start by fixing the code though as that risks rebase issues.

@M-Izadmehr
Copy link
Contributor

@sebmarkbage @bvaughn
I tried to check this issue and here are my findings:
First of all, we are never violating no-unreachable linting rule.
Based on MDN firefox never shows a warning, if a function declaration statement is following return. Also, based on ESLint it is also a valid code. As a result react code is safe, and never causes a warning.

Secondly, after a small search through the project, I see that we are using this approach in at least a dozen places. I can suggest two things, if we are on the same page, then continue with the PR:

  1. Explicitly add no-unreachable to eslint config (this is already a part of default config, so adding it will have no effect, just helps with explicitly showing the purpose)
  2. Although this pattern does not cause a warning (in either eslint/or browser), it can be confusing at times (however, it also results in cleaner functions, e.g. check below image)

Either way, if you agree with refactoring such cases I can move on with submitting the PR.

image

@flexhard69
Copy link

Bind

@bpernick
Copy link
Contributor

bpernick commented Jul 23, 2020

@M-Izadmehr @bvaughn Hello all! is this still being worked on?

@mnindrazaka
Copy link

Hi, everyone, is there any update about this issue ?
@bvaughn @M-Izadmehr @sebmarkbage

@bhumijgupta
Copy link
Contributor

Hey @bvaughn @sebmarkbage , I recently created an ES-Lint plugin (eslint-plugin-no-function-declare-after-return) to ensure there are no function declaration after return. I can :-

  1. Add the plugin to the repo
    or
  2. Extract logic out of the plugin and add a new rule to the repo
    and then make changes to fix it.

P.S. I added the plugin to the local fork of the repo and tested it. It was able to detect 6 places in codebase where there is a function declaration after return.
test

@bvaughn
Copy link
Contributor

bvaughn commented Aug 31, 2020

Extract logic out of the plugin and add a new rule to the repo

I'm not sure what "extract logic out of the plugin" mean. Is this option just adding the eslint-plugin-no-function-declare-after-return plugin to our .eslintrc.js? If so, sounds reasonable to me.

@bhumijgupta
Copy link
Contributor

bhumijgupta commented Aug 31, 2020

Yup, I can just add the plugin to .eslintrc.js and it will work just fine.
If this looks good, can you assign the issue to me, so I can start working on the PR?

@bvaughn
Copy link
Contributor

bvaughn commented Aug 31, 2020

Great. Send a PR and I'll take a look :)

@bvaughn
Copy link
Contributor

bvaughn commented Sep 1, 2020

Thanks @bhumijgupta

@bhumijgupta
Copy link
Contributor

Looking for more opportunities to contribute

@bvaughn
Copy link
Contributor

bvaughn commented Sep 1, 2020

I see 452 open issues at the moment 😅 Maybe there's another one you find interesting

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

Successfully merging a pull request may close this issue.

7 participants