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
Update: check template literal in no-constant-condition (fixes #12815) #12816
Update: check template literal in no-constant-condition (fixes #12815) #12816
Conversation
I think this is certainly a correct change in behavior 👍 Just not sure how to label it (bug/enhancement/breaking). |
It might be nice to add a test with a tagged template literal, which would be a constant if there's no tag. |
@mdjermanovic Thanks for commenting! I have a question about it. :)
What is the tagged template literal without a tag? Just mean template literal? tag`template literal ${expression}` |
sorry for closing it, it was mistake. |
Sorry for the confusion! Was thinking of a test case like the one you added now: (tagged template with a constant template literal) |
While at template literals, wondering should the rule also report something like this: if (`a${b}`) {} This is similar to the logic for |
I think this makes sense 👍 |
I agree. thanks for commenting :). I have some questions. /*eslint no-constant-condition: "error"*/
if ("a" + b) {} // no-error |
I think this should be a separate issue or PR. |
@mdjermanovic if (`${"foo"}${foo}`) {};
if("foo" + foo) {}; And I think both cases can be fixed together in another PR. Thanks :) |
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.
LGTM, thanks!
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.
LGTM, thanks!
…#12815) (eslint#12816) * Fix: check template literal in no-constant-condition (fixes eslint#12815) * add test cases * add tagged template test cases * treats truthy cases * check template literal truthy cases * fix typo, add test cases for cooked
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Fixed #12815 by add template literal checking.
This PR will make eslint to warn when a template literal(constant expression) placed in a test condition.
Is there anything you'd like reviewers to focus on?
It needs a consensus of ESlint members.
Marked as an
Update
, as it will generate more warning, but I think it can be accepted as a bug fix.