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
Follow identifiers to their declaration in no-constant-condition
#13776
Comments
An interesting idea for sure. As long as we don’t go too far down this path (evaluating expressions rather than just checking for single truthy values), I’m in favor. |
TSC Summary: This proposal seeks to have TSC Question: Shall we accept this proposal? |
Marking this as accepted after discussion in today's TSC meeting. Since there are some complex parts here, we'd like to discuss the implementation details in a new RFC before starting work on a PR. It should help us decide where we draw the line on the extended checks and whether the implementation belongs in this rule or |
Oops! It looks like we lost track of this issue. @eslint/eslint-tsc what do we want to do here? This issue will auto-close in 7 days without an update. |
Just waiting for an RFC here |
I can work on an RFC for this once I finish making a PR for #13752. |
I would like to work on this issue. |
@Gautam-Arora24 awesome! The next step here is to create an RFC. |
Sure! |
@Gautam-Arora24 If you're still working on this, it would be worth including the proposed new |
@Gautam-Arora24 do you still have interest in contributing a RFC? |
no-constant-condition
How will the change be implemented? (New option, new default behavior, etc.)?: New default behavior
Please provide some example code that this change will affect:
This proposal has been split out of #13752
Currently
no-constant-condition
triggers onif(true){}
but not onconst foo = true; if(foo){}
. In this case we could use theScopeManager
to attempt to followfoo
to its declaration/assignment. If the variable is in scope and only assigned once, then we could check if the assigned value is constant.In addition to assignments, we could also check other types of declarations. For example a function declaration could trigger an error:
Additionally, @mdjermanovic pointed out that there may be other rules which could be employing a similar technique.
I've done a simple version of this for a rule I wrote (as mentioned in #13752) which could be used as a starting place.
Shout out to @bradzacher who first suggested this approach while we were iterating on my
no-useless-null-checks
rule.The text was updated successfully, but these errors were encountered: