mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-10-05 05:20:49 +00:00

includes a (minimal) working wrapper Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
42 lines
835 B
Markdown
42 lines
835 B
Markdown
# Disallow Null Comparisons (no-eq-null)
|
|
|
|
Comparing to `null` without a type-checking operator (`==` or `!=`), can have unintended results as the comparison will evaluate to true when comparing to not just a `null`, but also an `undefined` value.
|
|
|
|
```js
|
|
if (foo == null) {
|
|
bar();
|
|
}
|
|
```
|
|
|
|
## Rule Details
|
|
|
|
The `no-eq-null` rule aims reduce potential bug and unwanted behavior by ensuring that comparisons to `null` only match `null`, and not also `undefined`. As such it will flag comparisons to null when using `==` and `!=`.
|
|
|
|
Examples of **incorrect** code for this rule:
|
|
|
|
```js
|
|
/*eslint no-eq-null: "error"*/
|
|
|
|
if (foo == null) {
|
|
bar();
|
|
}
|
|
|
|
while (qux != null) {
|
|
baz();
|
|
}
|
|
```
|
|
|
|
Examples of **correct** code for this rule:
|
|
|
|
```js
|
|
/*eslint no-eq-null: "error"*/
|
|
|
|
if (foo === null) {
|
|
bar();
|
|
}
|
|
|
|
while (qux !== null) {
|
|
baz();
|
|
}
|
|
```
|