-
Notifications
You must be signed in to change notification settings - Fork 237
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
disable no-lone-blocks rule in tests #8203
Conversation
My quick take on this one is I don't like it. The lone blocks in |
I prefer that we not use #region markers. They do nothing helpful in my IDE.
I agree with this. |
Ok, I've updated the PR to allow them in tests.
We don't really know that it's not preventing a problem. We may have no evidence of a problem because it's working. I didn't disable it across the board because I think in production code (as opposed to tests) it's more important that it's clear whether the block was necessary or not. |
I don't know why it's important to know if a block was necessary or not, which feels to me like asking if whitespace was necessary or not. Can you articulate an argument why anyone would ever care? One important place where this can happen legitimately are switch cases. Are switch cases in regular code exempt from this rule? |
If I'm reading some contract code and I see (contrived), let foo = 0;
{
const tempValue = 1;
foo += tempValue;
}
{
const tempValue = 1;
foo += tempValue;
} I can understand why they used blocks. The rule allows that. Now if I see, let foo = 0;
{
foo += 1;
}
{
foo += 1;
} then as the reader I'll be scratching my head why blocks were used. I'll suspect it's a bug because they were completely unnecessary, as if wrapping a parenthetical in an extra pair. I will waste time investigating whether there's really a bug.
I don't know exactly what you have in mind, but all the switch statements in the repo have no errors are warnings related to this. |
With respect to
In this example, case 2 and the default case are "lone blocks" but getting rid of the blocks (and associated braces) for those two cases but not case 1 or case 3 would disrupt the rhythm of the code and make it harder to read. And if we later needed to introduce a name into the scope of, say, case 2, we'd have to remember to add the braces. This is the same reason we require loop bodies and |
Ok, so stuff that's already in the repo. The rule isn't erroring on any of that. I've confirmed with the specific example above. No changes requested? |
Looks like we're good then. |
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.
I suppose relaxing the rule in tests is improvement. I'd relax it everywhere, but this is a step in that direction.
Description
prompted by #4981 (comment)
We've decided to allow blocks even when they are redundant because it makes for more consistency with cases in which they're necessary. One could argue it's better to be able to tell from reading the code whether the block is necessary (i.e. that there's a new binding that should not escape the block). This allows it in tests only because in production code it is important that it's clear whether the block was necessary or not.
Security Considerations
Scaling Considerations
Documentation Considerations
Testing Considerations
Upgrade Considerations