Skip to content

Commit 095c0de

Browse files
committed
benchmark,lib,test: use braces for multiline block
For if/else and loops where the bodies span more than one line, use curly braces. PR-URL: #13828 Ref: #13623 (comment) Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e3ea0fc commit 095c0de

22 files changed

+103
-60
lines changed

benchmark/buffers/buffer-iterate.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@ function main(conf) {
2929
function benchFor(buffer, n) {
3030
bench.start();
3131

32-
for (var k = 0; k < n; k++)
33-
for (var i = 0; i < buffer.length; i++)
32+
for (var k = 0; k < n; k++) {
33+
for (var i = 0; i < buffer.length; i++) {
3434
assert(buffer[i] === 0);
35+
}
36+
}
3537

3638
bench.end(n);
3739
}
3840

3941
function benchForOf(buffer, n) {
4042
bench.start();
4143

42-
for (var k = 0; k < n; k++)
43-
for (var b of buffer)
44+
for (var k = 0; k < n; k++) {
45+
for (var b of buffer) {
4446
assert(b === 0);
45-
47+
}
48+
}
4649
bench.end(n);
4750
}
4851

benchmark/dgram/array-vs-concat.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ function server() {
4646
var onsend = type === 'concat' ? onsendConcat : onsendMulti;
4747

4848
function onsendConcat() {
49-
if (sent++ % num === 0)
49+
if (sent++ % num === 0) {
5050
for (var i = 0; i < num; i++) {
5151
socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend);
5252
}
53+
}
5354
}
5455

5556
function onsendMulti() {
56-
if (sent++ % num === 0)
57+
if (sent++ % num === 0) {
5758
for (var i = 0; i < num; i++) {
5859
socket.send(chunk, PORT, '127.0.0.1', onsend);
5960
}
61+
}
6062
}
6163

6264
socket.on('listening', function() {

benchmark/dgram/multi-buffer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ function server() {
4545
var socket = dgram.createSocket('udp4');
4646

4747
function onsend() {
48-
if (sent++ % num === 0)
49-
for (var i = 0; i < num; i++)
48+
if (sent++ % num === 0) {
49+
for (var i = 0; i < num; i++) {
5050
socket.send(chunk, PORT, '127.0.0.1', onsend);
51+
}
52+
}
5153
}
5254

5355
socket.on('listening', function() {

benchmark/dgram/offset-length.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ function server() {
3737
var socket = dgram.createSocket('udp4');
3838

3939
function onsend() {
40-
if (sent++ % num === 0)
41-
for (var i = 0; i < num; i++)
40+
if (sent++ % num === 0) {
41+
for (var i = 0; i < num; i++) {
4242
socket.send(chunk, 0, chunk.length, PORT, '127.0.0.1', onsend);
43+
}
44+
}
4345
}
4446

4547
socket.on('listening', function() {

benchmark/dgram/single-buffer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ function server() {
3737
var socket = dgram.createSocket('udp4');
3838

3939
function onsend() {
40-
if (sent++ % num === 0)
41-
for (var i = 0; i < num; i++)
40+
if (sent++ % num === 0) {
41+
for (var i = 0; i < num; i++) {
4242
socket.send(chunk, PORT, '127.0.0.1', onsend);
43+
}
44+
}
4345
}
4446

4547
socket.on('listening', function() {

benchmark/url/url-searchparams-iteration.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ function iterator(n) {
3232
const noDead = [];
3333

3434
bench.start();
35-
for (var i = 0; i < n; i += 1)
35+
for (var i = 0; i < n; i += 1) {
3636
for (var pair of params) {
3737
noDead[0] = pair[0];
3838
noDead[1] = pair[1];
3939
}
40+
}
4041
bench.end(n);
4142

4243
assert.strictEqual(noDead[0], 'three');

lib/_http_client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,13 @@ ClientRequest.prototype.abort = function abort() {
319319
this.aborted = Date.now();
320320

321321
// If we're aborting, we don't care about any more response data.
322-
if (this.res)
322+
if (this.res) {
323323
this.res._dump();
324-
else
324+
} else {
325325
this.once('response', function(res) {
326326
res._dump();
327327
});
328+
}
328329

329330
// In the event that we don't have a socket, we will pop out of
330331
// the request queue through handling in onSocket.

lib/_http_outgoing.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,13 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
219219
// any messages, before ever calling this. In that case, just skip
220220
// it, since something else is destroying this connection anyway.
221221
OutgoingMessage.prototype.destroy = function destroy(error) {
222-
if (this.socket)
222+
if (this.socket) {
223223
this.socket.destroy(error);
224-
else
224+
} else {
225225
this.once('socket', function(socket) {
226226
socket.destroy(error);
227227
});
228+
}
228229
};
229230

230231

@@ -505,8 +506,7 @@ function matchHeader(self, state, field, value) {
505506

506507
function validateHeader(msg, name, value) {
507508
if (typeof name !== 'string' || !name || !checkIsHttpToken(name))
508-
throw new TypeError(
509-
'Header name must be a valid HTTP Token ["' + name + '"]');
509+
throw new TypeError(`Header name must be a valid HTTP Token ["${name}"]`);
510510
if (value === undefined)
511511
throw new Error('"value" required in setHeader("' + name + '", value)');
512512
if (msg._header)

lib/_http_server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ function writeHead(statusCode, reason, obj) {
185185
var originalStatusCode = statusCode;
186186

187187
statusCode |= 0;
188-
if (statusCode < 100 || statusCode > 999)
188+
if (statusCode < 100 || statusCode > 999) {
189189
throw new errors.RangeError('ERR_HTTP_INVALID_STATUS_CODE',
190190
originalStatusCode);
191+
}
191192

192193

193194
if (typeof reason === 'string') {
@@ -224,9 +225,10 @@ function writeHead(statusCode, reason, obj) {
224225
headers = obj;
225226
}
226227

227-
if (common._checkInvalidHeaderChar(this.statusMessage))
228+
if (common._checkInvalidHeaderChar(this.statusMessage)) {
228229
throw new errors.Error('ERR_HTTP_INVALID_CHAR',
229230
'Invalid character in statusMessage.');
231+
}
230232

231233
var statusLine = 'HTTP/1.1 ' + statusCode + ' ' + this.statusMessage + CRLF;
232234

lib/buffer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,14 @@ Object.setPrototypeOf(Buffer, Uint8Array);
207207
function assertSize(size) {
208208
let err = null;
209209

210-
if (typeof size !== 'number')
210+
if (typeof size !== 'number') {
211211
err = new TypeError('"size" argument must be a number');
212-
else if (size < 0)
212+
} else if (size < 0) {
213213
err = new RangeError('"size" argument must not be negative');
214-
else if (size > binding.kMaxLength)
214+
} else if (size > binding.kMaxLength) {
215215
err = new RangeError('"size" argument must not be larger ' +
216216
'than ' + binding.kMaxLength);
217+
}
217218

218219
if (err) {
219220
Error.captureStackTrace(err, assertSize);

0 commit comments

Comments
 (0)