Skip to content

Commit 649a27f

Browse files
committed
Enforce curly braces for multi-line block statements (if, do, while, etc)
1 parent 425c4dc commit 649a27f

File tree

2 files changed

+72
-39
lines changed

2 files changed

+72
-39
lines changed

.eslintrc.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
root: true,
33
parserOptions: {
44
ecmaVersion: 2018,
5-
sourceType: "module"
5+
sourceType: "module",
66
},
77
plugins: ["prettier"],
88
extends: ["eslint:recommended", "plugin:jest/recommended"],
@@ -11,19 +11,20 @@ module.exports = {
1111
node: true,
1212
mocha: true,
1313
jest: true,
14-
es6: true
14+
es6: true,
1515
},
1616
rules: {
1717
"prefer-const": "error",
1818
"no-var": "error",
19-
"prettier/prettier": "error"
19+
"prettier/prettier": "error",
20+
curly: ["error", "multi-line"],
2021
},
2122
overrides: [
2223
{
2324
files: ["test/**/*.js"],
2425
rules: {
25-
"no-console": "off"
26-
}
27-
}
28-
]
26+
"no-console": "off",
27+
},
28+
},
29+
],
2930
};

src/parser/expr.js

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,85 @@ module.exports = {
1818
expr = this.read_expr_item();
1919
}
2020
// binary operations
21-
if (this.token === "|")
21+
if (this.token === "|") {
2222
return result("bin", "|", expr, this.next().read_expr());
23-
if (this.token === "&")
23+
}
24+
if (this.token === "&") {
2425
return result("bin", "&", expr, this.next().read_expr());
25-
if (this.token === "^")
26+
}
27+
if (this.token === "^") {
2628
return result("bin", "^", expr, this.next().read_expr());
27-
if (this.token === ".")
29+
}
30+
if (this.token === ".") {
2831
return result("bin", ".", expr, this.next().read_expr());
29-
if (this.token === "+")
32+
}
33+
if (this.token === "+") {
3034
return result("bin", "+", expr, this.next().read_expr());
31-
if (this.token === "-")
35+
}
36+
if (this.token === "-") {
3237
return result("bin", "-", expr, this.next().read_expr());
33-
if (this.token === "*")
38+
}
39+
if (this.token === "*") {
3440
return result("bin", "*", expr, this.next().read_expr());
35-
if (this.token === "/")
41+
}
42+
if (this.token === "/") {
3643
return result("bin", "/", expr, this.next().read_expr());
37-
if (this.token === "%")
44+
}
45+
if (this.token === "%") {
3846
return result("bin", "%", expr, this.next().read_expr());
39-
if (this.token === this.tok.T_POW)
47+
}
48+
if (this.token === this.tok.T_POW) {
4049
return result("bin", "**", expr, this.next().read_expr());
41-
if (this.token === this.tok.T_SL)
50+
}
51+
if (this.token === this.tok.T_SL) {
4252
return result("bin", "<<", expr, this.next().read_expr());
43-
if (this.token === this.tok.T_SR)
53+
}
54+
if (this.token === this.tok.T_SR) {
4455
return result("bin", ">>", expr, this.next().read_expr());
56+
}
4557
// more binary operations (formerly bool)
46-
if (this.token === this.tok.T_BOOLEAN_OR)
58+
if (this.token === this.tok.T_BOOLEAN_OR) {
4759
return result("bin", "||", expr, this.next().read_expr());
48-
if (this.token === this.tok.T_LOGICAL_OR)
60+
}
61+
if (this.token === this.tok.T_LOGICAL_OR) {
4962
return result("bin", "or", expr, this.next().read_expr());
50-
if (this.token === this.tok.T_BOOLEAN_AND)
63+
}
64+
if (this.token === this.tok.T_BOOLEAN_AND) {
5165
return result("bin", "&&", expr, this.next().read_expr());
52-
if (this.token === this.tok.T_LOGICAL_AND)
66+
}
67+
if (this.token === this.tok.T_LOGICAL_AND) {
5368
return result("bin", "and", expr, this.next().read_expr());
54-
if (this.token === this.tok.T_LOGICAL_XOR)
69+
}
70+
if (this.token === this.tok.T_LOGICAL_XOR) {
5571
return result("bin", "xor", expr, this.next().read_expr());
56-
if (this.token === this.tok.T_IS_IDENTICAL)
72+
}
73+
if (this.token === this.tok.T_IS_IDENTICAL) {
5774
return result("bin", "===", expr, this.next().read_expr());
58-
if (this.token === this.tok.T_IS_NOT_IDENTICAL)
75+
}
76+
if (this.token === this.tok.T_IS_NOT_IDENTICAL) {
5977
return result("bin", "!==", expr, this.next().read_expr());
60-
if (this.token === this.tok.T_IS_EQUAL)
78+
}
79+
if (this.token === this.tok.T_IS_EQUAL) {
6180
return result("bin", "==", expr, this.next().read_expr());
62-
if (this.token === this.tok.T_IS_NOT_EQUAL)
81+
}
82+
if (this.token === this.tok.T_IS_NOT_EQUAL) {
6383
return result("bin", "!=", expr, this.next().read_expr());
64-
if (this.token === "<")
84+
}
85+
if (this.token === "<") {
6586
return result("bin", "<", expr, this.next().read_expr());
66-
if (this.token === ">")
87+
}
88+
if (this.token === ">") {
6789
return result("bin", ">", expr, this.next().read_expr());
68-
if (this.token === this.tok.T_IS_SMALLER_OR_EQUAL)
90+
}
91+
if (this.token === this.tok.T_IS_SMALLER_OR_EQUAL) {
6992
return result("bin", "<=", expr, this.next().read_expr());
70-
if (this.token === this.tok.T_IS_GREATER_OR_EQUAL)
93+
}
94+
if (this.token === this.tok.T_IS_GREATER_OR_EQUAL) {
7195
return result("bin", ">=", expr, this.next().read_expr());
72-
if (this.token === this.tok.T_SPACESHIP)
96+
}
97+
if (this.token === this.tok.T_SPACESHIP) {
7398
return result("bin", "<=>", expr, this.next().read_expr());
99+
}
74100
if (this.token === this.tok.T_INSTANCEOF) {
75101
expr = result(
76102
"bin",
@@ -89,8 +115,9 @@ module.exports = {
89115

90116
// extra operations :
91117
// $username = $_GET['user'] ?? 'nobody';
92-
if (this.token === this.tok.T_COALESCE)
118+
if (this.token === this.tok.T_COALESCE) {
93119
return result("bin", "??", expr, this.next().read_expr());
120+
}
94121

95122
// extra operations :
96123
// $username = $_GET['user'] ? true : false;
@@ -226,14 +253,18 @@ module.exports = {
226253
*/
227254
read_expr_item: function () {
228255
let result, expr;
229-
if (this.token === "+")
256+
if (this.token === "+") {
230257
return this.node("unary")("+", this.next().read_expr());
231-
if (this.token === "-")
258+
}
259+
if (this.token === "-") {
232260
return this.node("unary")("-", this.next().read_expr());
233-
if (this.token === "!")
261+
}
262+
if (this.token === "!") {
234263
return this.node("unary")("!", this.next().read_expr());
235-
if (this.token === "~")
264+
}
265+
if (this.token === "~") {
236266
return this.node("unary")("~", this.next().read_expr());
267+
}
237268

238269
if (this.token === "(") {
239270
expr = this.next().read_expr();
@@ -299,8 +330,9 @@ module.exports = {
299330
}
300331
}
301332

302-
if (this.token === this.tok.T_CLONE)
333+
if (this.token === this.tok.T_CLONE) {
303334
return this.node("clone")(this.next().read_expr());
335+
}
304336

305337
switch (this.token) {
306338
case this.tok.T_INC:

0 commit comments

Comments
 (0)