-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Restrict let_and_return if the let binding is large #420
Comments
I'm not sure it really is clearer. But perhaps we can split the lint so that if the let-statement is longer than N lines, only the more strict lint (which can be set to But how many lines are too much? |
It's obviously up for debate as to whether it's clearer, we could bikeshed it forever. As for the number of lines, I suspect it's a similar argument to number of columns. I can fit about 49 lines of my fairly small screen, with a fairly small font - I don't know what the average is. I, personally, would try and set the threshold to be "larger than can reasonably fit on one page/screen of code" - since that's the point where I believe the let/return approach becomes clearer. |
IMHO, if the second-to-last statement of your method is that long, you should be refactoring anyway. I have a ~25 line limit for functions I try to hold in 95% of all cases. In any language. Yes, that includes Java. |
I agree, most of the time - that's basically impossible if you've got an enum with a lot of variants to handle though. [As an aside: my code is ugly, and does need refactoring - I probably wouldn't have this issue if I took the time to refactor it, it's not something I have time for just now unfortunately] |
IMO even for large matches we shouldn't let-and-return; and I think this is a case that folks should be At some point it might be interesting to add a |
Currently, the let_and_return lint is always triggered. I have quite a lot of code which looks like:
Here, I believe it is a lot clearer to explicitly have the let binding, since you may have to scroll quite far to see that there's no semi-colon at the end of the match block for it to be obvious that it's the return expression. I don't know what a suitable size threshold would be, or even if it's possible to reasonably make restrictions based on that.
Of course, I'm open to other ways of writing code blocks like this which would also solve the issue!
The text was updated successfully, but these errors were encountered: