-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Warn for conditional clauses that are either always true or never true #6277
Comments
For perf reasons this might require a "lint" mode |
Team Triage: Should we consider that if what we're parsing as a property has This could also be expanded to special MSBuildisms like |
I figured just generally warning for clauses that are always true or always false would be much easier as there's no parser work. Basically after parsing, examine any comparison of string/number/bool to string/number/bool where there are no expandable elements (e.g. no $ or % or @ ...I forget whether this falls directly out of the parsing). In fact if it can be done like that it's nearly free and wouldn't need an opt in lint mode. |
I don't understand how we can guarantee whether or not something would always be true or never be true? Unless you mean comparing different types. eg: Is this what you mean? |
Yes, exactly. If your parse tree contains a subtree like
and string isn't expandable, then we can immediately warn because the clause will always have the same result and at best is redundant, at worst is a typo. Similarly for other comparisons between string/bool/number - the key being there's nothing expandable on either side. I don't think it's necessary to consider more than individual clauses, eg to handle cases like If instead you extended the parser to try to catch typos, I would imagine it could be much more costly/fragile. I don't know much about parsers, but I would expect that would be better handled by changing to a parser generator, if there is one, that offers a feature for spotting expressions that are "nearly something else". |
In this case you mean the string on both sides of the equal aren't expanded? My understanding for cases to warn:
|
Right
I don't think the type is relevant as there's coercion . So |
Here's another example from today where a typo caused a condition to always be false (extra space after property name) Ideally MSBuild would flag this. |
The below was a typo we overlooked in our repo. Strictly, the expression is "valid" but the possibility it was intended is zero.
Have you considered warning for conditions or clauses in conditions that will either ALWAYS or NEVER be true? In this case, it will always be true. I am guessing such clauses are very rarely intentional.
The text was updated successfully, but these errors were encountered: