-
-
Notifications
You must be signed in to change notification settings - Fork 244
[no-signal-compare?] new rule request to prevent comparing signals via < or > #1753
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
Comments
I wonder if this could be expanded beyond comparison operators and apply to expressions in general. Expressions that evaluate to truthy/falsy would be common scenarios, but the scope would probably go beyond that. A couple of examples: This would flag as an issue: if (this.mySignal) This would also flag as an issue: const myComputed = computed(() => this.mySignal + 1); The rule could be disabled like other lint rules such as for the line that follows or whole sections of code. This could be an opt-out for the unlikely scenarios where we intend to check the signal reference itself instead of its unwrapped value. |
Yes, i have exactly this problem with the if statement. At our company we transfer a lot of components to signals but simply changing the inputs results in a lot of these cases, where the input is simply checkt for truthy/falsy in an if statement. public conditionalSignal = signal(false);
...
// Accidentally using the reference:
if (conditionalSignal) {
...
}
// Instead of something like this:
if (conditionalSignal()) {
...
} This is really dangerous, as it's not easy to spot the wrong behavior while rewriting the components, especially when rewriting lots of components in a row. I'd really like to have an es-lint rule for that. |
I agree with expanding it to more places, similar to what was requested in #1891. |
I've update no-misused-signals proposal. I think this issue can be closed. |
Should be added. can cause a lot bugs ! |
I'll consolidate into #1891, thanks all |
I would like to propose a new rule getting added to angular-eslint that will prevent two signals from being compared via <, <=, >, >= as it does not really make sense. After attending NgConf I noticed that it is very easy for even an expert angular developer to accidentally forgot to unbox two signals when trying to compare their unboxed values like so:
it does seem valid to compare signals with === so it does seem like that should be allowed.
I did open this request to @angular/core and was suggested that I open the feature request here instead. Here is the closed issue from @angular/core
it seems it would be very helpful to get some warning/error feedback when attempts to do this are made and could possibly even have a quickFix option that just adds the calling of the signal instead of using the signal itself as experienced and new devs alike could spend plenty of time trying to figure out why their conditions are not being hit correctly when trying to use signals. The text could be similar to what we see when trying to compare numbers and strings?
The text was updated successfully, but these errors were encountered: