8000 [no-misused-signals] restrict incorrect usage of signals - proposal · Issue #1891 · angular-eslint/angular-eslint · GitHub
[go: up one dir, main page]

Skip to content
[no-misused-signals] restrict incorrect usage of signals - proposal #1891
Closed
@MillerSvt

Description

@MillerSvt

Description of the proposal

This rule forbids providing Signals to logical locations such as if statements in places where the TypeScript compiler allows them but they are not handled properly. It could be about using signals in a nullish check or comparing them using operators like ===, ==, >, <, >=, or <=. These situations can often arise due to a missing call or just a misunderstanding of the way signals are handled.

In some rare cases === or == operators can be valid. So need to add option ignoreNullishCheck to disable higlighting them.

Reference: https://typescript-eslint.io/rules/no-misused-promises/

Incorrect code

const signal = signal(0);
const otherSignal = signal(0);

if (signal) {
  // Do something
}

if (signal === otherSignal) {
  // Do something
}

if (signal > otherSignal) {
  // Do something
}

if (
767E
signal < otherSignal) {
  // Do something
}

const val = signal ? 123 : 456;

while (signal) {
  // Do something
}
@if (signal) {
   something  
}

@if (signal === otherSignal) {
   something  
}

@if (signal > otherSignal) {
   something  
}

@if (signal < otherSignal) {
   something  
}

@switch (signal) {
   something
}

{{ signal }}

Correct code

const signal = signal(0);
const otherSignal = signal(0);

if (signal()) {
  // Do something
}

if (signal() === otherSignal()) {
  // Do something
}

if (signal() > otherSignal()) {
  // Do something
}

if (signal() < otherSignal()) {
  // Do something
}

const val = signal() ? 123 : 456;

while (signal()) {
  // Do something
}
@if (signal()) {
   something  
}

@if (signal() === otherSignal()) {
   something  
}

@if (signal() > otherSignal()) {
   something  
}

@if (signal() < otherSignal()) {
   something  
}

@switch (signal()) {
   something
}

{{ signal() }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    PRs WelcomeIf a high-quality PR is created for this it will be acceptedpackage: eslint-pluginAngular-specific TypeScript rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0