-
Notifications
You must be signed in to change notification settings - Fork 244
Closed
Labels
PRs WelcomeIf a high-quality PR is created for this it will be acceptedIf a high-quality PR is created for this it will be acceptedpackage: eslint-pluginAngular-specific TypeScript rulesAngular-specific TypeScript rules
Description
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 (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() }}
dartzki, ekrapfl, KevinKelchen, PowerKiKi, stas-digisol and 21 moreBengejd
Metadata
Metadata
Assignees
Labels
PRs WelcomeIf a high-quality PR is created for this it will be acceptedIf a high-quality PR is created for this it will be acceptedpackage: eslint-pluginAngular-specific TypeScript rulesAngular-specific TypeScript rules