-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add warning message empty THEN clause #5375
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
Conversation
I'm at loss how my pull request managed to break |
~ | ||
!!! warning TS20000: Potentially wrong empty statement in THEN clause. | ||
x = 1; | ||
} |
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.
Can you add a test that shows that
if(someComplexConditionICantBeBotheredToInvert) {
}
else {
// some code ...
}
does not warn? It's not good style, but it's intended, so I want to document that it will not warn.
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.
Sure, if you guys decide that you want to merge this feature - #5375 (comment)
the fourslash test likely failed because of violating incremental parsing assumptions. i would move the check to cheker.ts. |
After thinking about this more, I'm starting to wonder whether or not this is a good idea. We say many other errors can be taken care of by a linter. It sets a slightly odd precedent if we pick this case specially. |
@DanielRosenwasser This pull request would add a very first warning to |
I think the line is fairly subjective, e.g. the rechability checks. but my reasoning is that this is an issue that is wrong 99.9% of the time, and not just a matter of best practices. @MartyIX please let us know if you are still interested in perusing this PR, and if so, please move the check to the checker as i noted earlier, and update the tests. |
@mhegazy Yes, I'm still interested in this PR, so I'll modify it. :) |
1c7f74f
to
ef5b0d8
Compare
@mhegazy I have updated the PR. |
@@ -2469,5 +2469,9 @@ | |||
"A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": { | |||
"category": "Error", | |||
"code": 17007 | |||
}, | |||
"The body of an 'if' statement cannot be the empty statement.": { | |||
"category": "Warning", |
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.
Just make this an error the same as any other (probably in the 1xxx category); we don't need to introduce a new concept of a "warning" right now
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.
Do you mean a new concept for users? I can see Warning
here: https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts#L2043 ...
Interesting... I'll sometimes write code with just a I agree with @DanielRosenwasser . Seems firmly in the realm of linter-land. There is absolutely nothing wrong syntactically, semantically, or in the use of types by having an empty block. |
@billti I'm not sure how your code looks like exactly, but the idea was that for the following script
the compiler should return:
To clarify further, |
Ah, right. Fair enough then. Yes, almost certainly a bug to warn on :-) |
@RyanCavanaugh I have made the modification as you requested. |
thanks! |
👍 |
Add warning message empty THEN clause
thanks @MartyIX! |
Proposed patch for issue #5109.