Skip to content

Commit 3d0b66a

Browse files
Trottaddaleax
authored andcommitted
benchmark,lib,test: use braces for multiline block
For if/else and loops where the bodies span more than one line, use curly braces. Original-PR-URL: #13828 Ref: #13623 (comment) Original-Reviewed-By: Anna Henningsen <[email protected]> Original-Reviewed-By: Colin Ihrig <[email protected]> Original-Reviewed-By: Michaël Zasso <[email protected]> Original-Reviewed-By: James M Snell <[email protected]> PR-URL: #13995 Reviewed-By: Anna Henningsen <[email protected]>
1 parent e5d32b8 commit 3d0b66a

21 files changed

+97
-57
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
@@ -218,12 +218,13 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
218218
// any messages, before ever calling this. In that case, just skip
219219
// it, since something else is destroying this connection anyway.
220220
OutgoingMessage.prototype.destroy = function destroy(error) {
221-
if (this.socket)
221+
if (this.socket) {
222222
this.socket.destroy(error);
223-
else
223+
} else {
224224
this.once('socket', function(socket) {
225225
socket.destroy(error);
226226
});
227+
}
227228
};
228229

229230

@@ -496,8 +497,7 @@ function matchHeader(self, state, field, value) {
496497

497498
function validateHeader(msg, name, value) {
498499
if (typeof name !== 'string' || !name || !checkIsHttpToken(name))
499-
throw new TypeError(
500-
'Header name must be a valid HTTP Token ["' + name + '"]');
500+
throw new TypeError(`Header name must be a valid HTTP Token ["${name}"]`);
501501
if (value === undefined)
502502
throw new Error('"value" required in setHeader("' + name + '", value)');
503503
if (msg._header)

lib/buffer.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,14 @@ Object.setPrototypeOf(Buffer, Uint8Array);
206206
function assertSize(size) {
207207
let err = null;
208208

209-
if (typeof size !== 'number')
209+
if (typeof size !== 'number') {
210210
err = new TypeError('"size" argument must be a number');
211-
else if (size < 0)
211+
} else if (size < 0) {
212212
err = new RangeError('"size" argument must not be negative');
213-
else if (size > binding.kMaxLength)
213+
} else if (size > binding.kMaxLength) {
214214
err = new RangeError('"size" argument must not be larger ' +
215215
'than ' + binding.kMaxLength);
216+
}
216217

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

lib/child_process.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -537,15 +537,16 @@ function spawnSync(/*file, args, options*/) {
537537
var input = options.stdio[i] && options.stdio[i].input;
538538
if (input != null) {
539539
var pipe = options.stdio[i] = util._extend({}, options.stdio[i]);
540-
if (isUint8Array(input))
540+
if (isUint8Array(input)) {
541541
pipe.input = input;
542-
else if (typeof input === 'string')
542+
} else if (typeof input === 'string') {
543543
pipe.input = Buffer.from(input, options.encoding);
544-
else
544+
} else {
545545
throw new TypeError(util.format(
546546
'stdio[%d] should be Buffer, Uint8Array or string not %s',
547547
i,
548548
typeof input));
549+
}
549550
}
550551
}
551552

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
@@ -43,10 +43,12 @@ function setup_cpuUsage() {
4343
}
4444

4545
// If a previous value was passed in, return diff of current from previous.
46-
if (prevValue) return {
47-
user: cpuValues[0] - prevValue.user,
48-
system: cpuValues[1] - prevValue.system
49-
};
46+
if (prevValue) {
47+
return {
48+
user: cpuValues[0] - prevValue.user,
49+
system: cpuValues[1] - prevValue.system
50+
};
51+
}
5052

5153
// If no previous value passed in, return current value.
5254
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
283283
if (typeof stringToWrite !== 'string')
284284
throw new TypeError('"stringToWrite" argument must be a string');
285285

286-
if (this.output !== null && this.output !== undefined)
286+
if (this.output !== null && this.output !== undefined) {
287287
this.output.write(stringToWrite);
288+
}
288289
};
289290

290291
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
throw new TypeError('The super constructor to "inherits" must not ' +
963963
'be null or undefined');
964964

965-
if (superCtor.prototype === undefined)
965+
if (superCtor.prototype === undefined) {
966966
throw new TypeError('The super constructor to "inherits" must ' +
967967
'have a prototype');
968+
}
968969

969970
ctor.super_ = superCtor;
970971
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);

test/common/index.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,11 @@ function leakedGlobals() {
429429
const leaked = [];
430430

431431
// eslint-disable-next-line no-var
432-
for (var val in global)
433-
if (!knownGlobals.includes(global[val]))
432+
for (var val in global) {
433+
if (!knownGlobals.includes(global[val])) {
434434
leaked.push(val);
435+
}
436+
}
435437

436438
if (global.__coverage__) {
437439
return leaked.filter((varname) => !/^(?:cov_|__cov)/.test(varname));
@@ -700,9 +702,10 @@ Object.defineProperty(exports, 'hasSmallICU', {
700702
exports.expectsError = function expectsError({code, type, message}) {
701703
return function(error) {
702704
assert.strictEqual(error.code, code);
703-
if (type !== undefined)
705+
if (type !== undefined) {
704706
assert(error instanceof type,
705707
`${error} is not the expected type ${type}`);
708+
}
706709
if (message instanceof RegExp) {
707710
assert(message.test(error.message),
708711
`${error.message} does not match ${message}`);
@@ -758,11 +761,13 @@ exports.getTTYfd = function getTTYfd() {
758761
if (!tty.isatty(tty_fd)) tty_fd++;
759762
else if (!tty.isatty(tty_fd)) tty_fd++;
760763
else if (!tty.isatty(tty_fd)) tty_fd++;
761-
else try {
762-
tty_fd = require('fs').openSync('/dev/tty');
763-
} catch (e) {
764-
// There aren't any tty fd's available to use.
765-
return -1;
764+
else {
765+
try {
766+
tty_fd = require('fs').openSync('/dev/tty');
767+
} catch (e) {
768+
// There aren't any tty fd's available to use.
769+
return -1;
770+
}
766771
}
767772
return tty_fd;
768773
};

test/parallel/test-domain-uncaught-exception.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ if (process.argv[2] === 'child') {
182182
// Make sure that all expected messages were sent from the
183183
// child process
184184
test.expectedMessages.forEach(function(expectedMessage) {
185-
if (test.messagesReceived === undefined ||
186-
test.messagesReceived.indexOf(expectedMessage) === -1)
185+
const msgs = test.messagesReceived;
186+
if (msgs === undefined || !msgs.includes(expectedMessage)) {
187187
assert.fail(`test ${test.fn.name} should have sent message: ${
188188
expectedMessage} but didn't`);
189+
}
189190
});
190191

191192
if (test.messagesReceived) {

0 commit comments

Comments
 (0)