-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBlocks.js
More file actions
102 lines (85 loc) · 1.34 KB
/
Blocks.js
File metadata and controls
102 lines (85 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//: 16.1 => /* Use braces with all muliline blocks. eslint: "nonblock-statement-body-position" */
// bad
if (test) return false;
// good
if (test) return false;
// good
if (test) {
return false;
}
// bad
function foo() {
return false;
}
// good
function bar() {
return false;
}
//: 16.2 => /* iF YOU'RE using multline blocks with if and else, put else on the same line as your "if" block closing brace. eslint: "brace-style" */
// bad
if (test) {
thing1();
thing2();
} else {
thing3();
}
// good
if (test) {
thing1();
thing2();
} else {
thing3();
}
//: 16.2 => /* If an "if" block always executes a return statement, the subsequent else block is unnecessary. A return is an "else if" block following an "if" block that contains a return can be separated into multiple "if" blocks. eslint:no-else-return */
// bad
function foo() {
if (x) {
return x;
} else {
return y;
}
}
// bad
function cats() {
if (x) {
return x;
} else if (y) {
return y;
}
}
// bad
function dogs() {
if (x) {
return x;
} else {
if (y) {
return y;
}
}
}
// good
function foo() {
if (x) {
return x;
}
return y;
}
// good
function cats() {
if (x) {
return x;
}
if (y) {
return y;
}
}
// good
function dogs(x) {
if (x) {
if (z) {
return y;
}
} else {
return z;
}
}