Skip to content

[no-signal-compare?] new rule request to prevent comparing signals via < or > #1753

Closed as duplicate
@skyleguy

Description

@skyleguy

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:

sig1 = signal(5)
sig2 = signal(2)

if (sig1 > sig2) // will never be true
if (sig1() > sig2()) // will be true in this case and is most likely always what we'd be going for in this scenario

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?

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: eslint-pluginAngular-specific TypeScript rulestriageThis issue needs to be looked at and categorized by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions