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

+8-5
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

+4-2
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

+4-2
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

+4-2
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

+4-2
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

+2-1
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

+3-2
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

+4-4
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

+4-2
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

+4-3
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);

lib/child_process.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,16 @@ function spawnSync(/*file, args, options*/) {
533533
var input = options.stdio[i] && options.stdio[i].input;
534534
if (input != null) {
535535
var pipe = options.stdio[i] = util._extend({}, options.stdio[i]);
536-
if (isUint8Array(input))
536+
if (isUint8Array(input)) {
537537
pipe.input = input;
538-
else if (typeof input === 'string')
538+
} else if (typeof input === 'string') {
539539
pipe.input = Buffer.from(input, options.encoding);
540-
else
540+
} else {
541541
throw new TypeError(util.format(
542542
'stdio[%d] should be Buffer, Uint8Array or string not %s',
543543
i,
544544
typeof input));
545+
}
545546
}
546547
}
547548

lib/fs.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1951,10 +1951,11 @@ ReadStream.prototype.open = function() {
19511951
};
19521952

19531953
ReadStream.prototype._read = function(n) {
1954-
if (typeof this.fd !== 'number')
1954+
if (typeof this.fd !== 'number') {
19551955
return this.once('open', function() {
19561956
this._read(n);
19571957
});
1958+
}
19581959

19591960
if (this.destroyed)
19601961
return;
@@ -2116,10 +2117,11 @@ WriteStream.prototype._write = function(data, encoding, cb) {
21162117
if (!(data instanceof Buffer))
21172118
return this.emit('error', new Error('Invalid data'));
21182119

2119-
if (typeof this.fd !== 'number')
2120+
if (typeof this.fd !== 'number') {
21202121
return this.once('open', function() {
21212122
this._write(data, encoding, cb);
21222123
});
2124+
}
21232125

21242126
var self = this;
21252127
fs.write(this.fd, data, 0, data.length, this.pos, function(er, bytes) {
@@ -2151,10 +2153,11 @@ function writev(fd, chunks, position, callback) {
21512153

21522154

21532155
WriteStream.prototype._writev = function(data, cb) {
2154-
if (typeof this.fd !== 'number')
2156+
if (typeof this.fd !== 'number') {
21552157
return this.once('open', function() {
21562158
this._writev(data, cb);
21572159
});
2160+
}
21582161

21592162
const self = this;
21602163
const len = data.length;

lib/inspector.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,26 @@ class Session extends EventEmitter {
4141
}
4242

4343
post(method, params, callback) {
44-
if (typeof method !== 'string')
44+
if (typeof method !== 'string') {
4545
throw new TypeError(
4646
`"method" must be a string, got ${typeof method} instead`);
47+
}
4748
if (!callback && util.isFunction(params)) {
4849
callback = params;
4950
params = null;
5051
}
51-
if (params && typeof params !== 'object')
52+
if (params && typeof params !== 'object') {
5253
throw new TypeError(
5354
`"params" must be an object, got ${typeof params} instead`);
54-
if (callback && typeof callback !== 'function')
55+
}
56+
if (callback && typeof callback !== 'function') {
5557
throw new TypeError(
5658
`"callback" must be a function, got ${typeof callback} instead`);
59+
}
5760

58-
if (!this[connectionSymbol])
61+
if (!this[connectionSymbol]) {
5962
throw new Error('Session is not connected');
63+
}
6064
const id = this[nextIdSymbol]++;
6165
const message = {id, method};
6266
if (params) {

lib/internal/process.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ function setup_cpuUsage() {
4646
}
4747

4848
// If a previous value was passed in, return diff of current from previous.
49-
if (prevValue) return {
50-
user: cpuValues[0] - prevValue.user,
51-
system: cpuValues[1] - prevValue.system
52-
};
49+
if (prevValue) {
50+
return {
51+
user: cpuValues[0] - prevValue.user,
52+
system: cpuValues[1] - prevValue.system
53+
};
54+
}
5355

5456
// If no previous value passed in, return current value.
5557
return {

lib/net.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1005,19 +1005,23 @@ function lookupAndConnect(self, options) {
10051005
var localAddress = options.localAddress;
10061006
var localPort = options.localPort;
10071007

1008-
if (localAddress && !cares.isIP(localAddress))
1008+
if (localAddress && !cares.isIP(localAddress)) {
10091009
throw new TypeError('"localAddress" option must be a valid IP: ' +
10101010
localAddress);
1011+
}
10111012

1012-
if (localPort && typeof localPort !== 'number')
1013+
if (localPort && typeof localPort !== 'number') {
10131014
throw new TypeError('"localPort" option should be a number: ' + localPort);
1015+
}
10141016

10151017
if (typeof port !== 'undefined') {
1016-
if (typeof port !== 'number' && typeof port !== 'string')
1018+
if (typeof port !== 'number' && typeof port !== 'string') {
10171019
throw new TypeError('"port" option should be a number or string: ' +
10181020
port);
1019-
if (!isLegalPort(port))
1021+
}
1022+
if (!isLegalPort(port)) {
10201023
throw new RangeError('"port" option should be >= 0 and < 65536: ' + port);
1024+
}
10211025
}
10221026
port |= 0;
10231027

lib/readline.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,18 @@ Interface.prototype._onLine = function(line) {
285285
};
286286

287287
Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
288-
if (typeof stringToWrite !== 'string')
288+
if (typeof stringToWrite !== 'string') {
289289
throw new errors.TypeError(
290290
'ERR_INVALID_ARG_TYPE',
291291
'stringToWrite',
292292
'string',
293293
stringToWrite
294294
);
295+
}
295296

296-
if (this.output !== null && this.output !== undefined)
297+
if (this.output !== null && this.output !== undefined) {
297298
this.output.write(stringToWrite);
299+
}
298300
};
299301

300302
Interface.prototype._addHistory = function() {

lib/tls.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ function check(hostParts, pattern, wildcards) {
122122
return false;
123123

124124
// Check host parts from right to left first.
125-
for (var i = hostParts.length - 1; i > 0; i -= 1)
125+
for (var i = hostParts.length - 1; i > 0; i -= 1) {
126126
if (hostParts[i] !== patternParts[i])
127127
return false;
128+
}
128129

129130
const hostSubdomain = hostParts[0];
130131
const patternSubdomain = patternParts[0];

lib/util.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,10 @@ exports.inherits = function(ctor, superCtor) {
962962
if (superCtor === undefined || superCtor === null)
963963
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'function');
964964

965-
if (superCtor.prototype === undefined)
965+
if (superCtor.prototype === undefined) {
966966
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype',
967967
'function');
968+
}
968969
ctor.super_ = superCtor;
969970
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
970971
};

0 commit comments

Comments
 (0)