]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-negated-condition.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-negated-condition.md
CommitLineData
eb39fafa
DC
1# disallow negated conditions (no-negated-condition)
2
3Negated conditions are more difficult to understand. Code can be made more readable by inverting the condition instead.
4
5## Rule Details
6
7This rule disallows negated conditions in either of the following:
8
9* `if` statements which have an `else` branch
10* ternary expressions
11
12Examples of **incorrect** code for this rule:
13
14```js
15/*eslint no-negated-condition: "error"*/
16
17if (!a) {
18 doSomething();
19} else {
20 doSomethingElse();
21}
22
23if (a != b) {
24 doSomething();
25} else {
26 doSomethingElse();
27}
28
29if (a !== b) {
30 doSomething();
31} else {
32 doSomethingElse();
33}
34
35!a ? c : b
36```
37
38Examples of **correct** code for this rule:
39
40```js
41/*eslint no-negated-condition: "error"*/
42
43if (!a) {
44 doSomething();
45}
46
47if (!a) {
48 doSomething();
49} else if (b) {
50 doSomething();
51}
52
53if (a != b) {
54 doSomething();
55}
56
57a ? b : c
58```