diff options
author | Rich Trott <rtrott@gmail.com> | 2017-06-21 00:37:00 +0300 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-06-24 00:43:20 +0300 |
commit | 095c0de94d818088cacf2c33ad4913768c15024a (patch) | |
tree | 77eb0aaffa2aa80ba1240280a716eb64c4a7ff1d | |
parent | e3ea0fc97bf3a911463275446024b50e8bae865f (diff) |
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: https://github.com/nodejs/node/pull/13828
Ref: https://github.com/nodejs/node/pull/13623#discussion_r123048602
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>
-rw-r--r-- | benchmark/buffers/buffer-iterate.js | 13 | ||||
-rw-r--r-- | benchmark/dgram/array-vs-concat.js | 6 | ||||
-rw-r--r-- | benchmark/dgram/multi-buffer.js | 6 | ||||
-rw-r--r-- | benchmark/dgram/offset-length.js | 6 | ||||
-rw-r--r-- | benchmark/dgram/single-buffer.js | 6 | ||||
-rw-r--r-- | benchmark/url/url-searchparams-iteration.js | 3 | ||||
-rw-r--r-- | lib/_http_client.js | 5 | ||||
-rw-r--r-- | lib/_http_outgoing.js | 8 | ||||
-rw-r--r-- | lib/_http_server.js | 6 | ||||
-rw-r--r-- | lib/buffer.js | 7 | ||||
-rw-r--r-- | lib/child_process.js | 7 | ||||
-rw-r--r-- | lib/fs.js | 9 | ||||
-rw-r--r-- | lib/inspector.js | 12 | ||||
-rw-r--r-- | lib/internal/process.js | 10 | ||||
-rw-r--r-- | lib/net.js | 12 | ||||
-rw-r--r-- | lib/readline.js | 6 | ||||
-rw-r--r-- | lib/tls.js | 3 | ||||
-rw-r--r-- | lib/util.js | 3 | ||||
-rw-r--r-- | test/common/index.js | 21 | ||||
-rw-r--r-- | test/parallel/test-domain-uncaught-exception.js | 5 | ||||
-rw-r--r-- | test/parallel/test-fs-null-bytes.js | 6 | ||||
-rw-r--r-- | test/pummel/test-net-write-callbacks.js | 3 |
22 files changed, 103 insertions, 60 deletions
diff --git a/benchmark/buffers/buffer-iterate.js b/benchmark/buffers/buffer-iterate.js index fb8abc1aee1..7c204442224 100644 --- a/benchmark/buffers/buffer-iterate.js +++ b/benchmark/buffers/buffer-iterate.js @@ -29,9 +29,11 @@ function main(conf) { function benchFor(buffer, n) { bench.start(); - for (var k = 0; k < n; k++) - for (var i = 0; i < buffer.length; i++) + for (var k = 0; k < n; k++) { + for (var i = 0; i < buffer.length; i++) { assert(buffer[i] === 0); + } + } bench.end(n); } @@ -39,10 +41,11 @@ function benchFor(buffer, n) { function benchForOf(buffer, n) { bench.start(); - for (var k = 0; k < n; k++) - for (var b of buffer) + for (var k = 0; k < n; k++) { + for (var b of buffer) { assert(b === 0); - + } + } bench.end(n); } diff --git a/benchmark/dgram/array-vs-concat.js b/benchmark/dgram/array-vs-concat.js index 8b1d34d0e74..681abd6afa1 100644 --- a/benchmark/dgram/array-vs-concat.js +++ b/benchmark/dgram/array-vs-concat.js @@ -46,17 +46,19 @@ function server() { var onsend = type === 'concat' ? onsendConcat : onsendMulti; function onsendConcat() { - if (sent++ % num === 0) + if (sent++ % num === 0) { for (var i = 0; i < num; i++) { socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend); } + } } function onsendMulti() { - if (sent++ % num === 0) + if (sent++ % num === 0) { for (var i = 0; i < num; i++) { socket.send(chunk, PORT, '127.0.0.1', onsend); } + } } socket.on('listening', function() { diff --git a/benchmark/dgram/multi-buffer.js b/benchmark/dgram/multi-buffer.js index 3277547119c..6a7fc9bfaf8 100644 --- a/benchmark/dgram/multi-buffer.js +++ b/benchmark/dgram/multi-buffer.js @@ -45,9 +45,11 @@ function server() { var socket = dgram.createSocket('udp4'); function onsend() { - if (sent++ % num === 0) - for (var i = 0; i < num; i++) + if (sent++ % num === 0) { + for (var i = 0; i < num; i++) { socket.send(chunk, PORT, '127.0.0.1', onsend); + } + } } socket.on('listening', function() { diff --git a/benchmark/dgram/offset-length.js b/benchmark/dgram/offset-length.js index 5b7762b21e7..b897707ded5 100644 --- a/benchmark/dgram/offset-length.js +++ b/benchmark/dgram/offset-length.js @@ -37,9 +37,11 @@ function server() { var socket = dgram.createSocket('udp4'); function onsend() { - if (sent++ % num === 0) - for (var i = 0; i < num; i++) + if (sent++ % num === 0) { + for (var i = 0; i < num; i++) { socket.send(chunk, 0, chunk.length, PORT, '127.0.0.1', onsend); + } + } } socket.on('listening', function() { diff --git a/benchmark/dgram/single-buffer.js b/benchmark/dgram/single-buffer.js index e01b60b4297..8b81d7fbfc0 100644 --- a/benchmark/dgram/single-buffer.js +++ b/benchmark/dgram/single-buffer.js @@ -37,9 +37,11 @@ function server() { var socket = dgram.createSocket('udp4'); function onsend() { - if (sent++ % num === 0) - for (var i = 0; i < num; i++) + if (sent++ % num === 0) { + for (var i = 0; i < num; i++) { socket.send(chunk, PORT, '127.0.0.1', onsend); + } + } } socket.on('listening', function() { diff --git a/benchmark/url/url-searchparams-iteration.js b/benchmark/url/url-searchparams-iteration.js index 833271ef306..89919af7255 100644 --- a/benchmark/url/url-searchparams-iteration.js +++ b/benchmark/url/url-searchparams-iteration.js @@ -32,11 +32,12 @@ function iterator(n) { const noDead = []; bench.start(); - for (var i = 0; i < n; i += 1) + for (var i = 0; i < n; i += 1) { for (var pair of params) { noDead[0] = pair[0]; noDead[1] = pair[1]; } + } bench.end(n); assert.strictEqual(noDead[0], 'three'); diff --git a/lib/_http_client.js b/lib/_http_client.js index e095051270d..29ea688ecb1 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -319,12 +319,13 @@ ClientRequest.prototype.abort = function abort() { this.aborted = Date.now(); // If we're aborting, we don't care about any more response data. - if (this.res) + if (this.res) { this.res._dump(); - else + } else { this.once('response', function(res) { res._dump(); }); + } // In the event that we don't have a socket, we will pop out of // the request queue through handling in onSocket. diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 636afc4e46c..ccb66f742f9 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -219,12 +219,13 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) { // any messages, before ever calling this. In that case, just skip // it, since something else is destroying this connection anyway. OutgoingMessage.prototype.destroy = function destroy(error) { - if (this.socket) + if (this.socket) { this.socket.destroy(error); - else + } else { this.once('socket', function(socket) { socket.destroy(error); }); + } }; @@ -505,8 +506,7 @@ function matchHeader(self, state, field, value) { function validateHeader(msg, name, value) { if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) - throw new TypeError( - 'Header name must be a valid HTTP Token ["' + name + '"]'); + throw new TypeError(`Header name must be a valid HTTP Token ["${name}"]`); if (value === undefined) throw new Error('"value" required in setHeader("' + name + '", value)'); if (msg._header) diff --git a/lib/_http_server.js b/lib/_http_server.js index 854ae56387e..c3a10112ff2 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -185,9 +185,10 @@ function writeHead(statusCode, reason, obj) { var originalStatusCode = statusCode; statusCode |= 0; - if (statusCode < 100 || statusCode > 999) + if (statusCode < 100 || statusCode > 999) { throw new errors.RangeError('ERR_HTTP_INVALID_STATUS_CODE', originalStatusCode); + } if (typeof reason === 'string') { @@ -224,9 +225,10 @@ function writeHead(statusCode, reason, obj) { headers = obj; } - if (common._checkInvalidHeaderChar(this.statusMessage)) + if (common._checkInvalidHeaderChar(this.statusMessage)) { throw new errors.Error('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.'); + } var statusLine = 'HTTP/1.1 ' + statusCode + ' ' + this.statusMessage + CRLF; diff --git a/lib/buffer.js b/lib/buffer.js index bfa8656483f..89bbfd2474d 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -207,13 +207,14 @@ Object.setPrototypeOf(Buffer, Uint8Array); function assertSize(size) { let err = null; - if (typeof size !== 'number') + if (typeof size !== 'number') { err = new TypeError('"size" argument must be a number'); - else if (size < 0) + } else if (size < 0) { err = new RangeError('"size" argument must not be negative'); - else if (size > binding.kMaxLength) + } else if (size > binding.kMaxLength) { err = new RangeError('"size" argument must not be larger ' + 'than ' + binding.kMaxLength); + } if (err) { Error.captureStackTrace(err, assertSize); diff --git a/lib/child_process.js b/lib/child_process.js index c8f844d617c..8f7d2520622 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -533,15 +533,16 @@ function spawnSync(/*file, args, options*/) { var input = options.stdio[i] && options.stdio[i].input; if (input != null) { var pipe = options.stdio[i] = util._extend({}, options.stdio[i]); - if (isUint8Array(input)) + if (isUint8Array(input)) { pipe.input = input; - else if (typeof input === 'string') + } else if (typeof input === 'string') { pipe.input = Buffer.from(input, options.encoding); - else + } else { throw new TypeError(util.format( 'stdio[%d] should be Buffer, Uint8Array or string not %s', i, typeof input)); + } } } diff --git a/lib/fs.js b/lib/fs.js index 61f227423b0..a2401acf31b 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1951,10 +1951,11 @@ ReadStream.prototype.open = function() { }; ReadStream.prototype._read = function(n) { - if (typeof this.fd !== 'number') + if (typeof this.fd !== 'number') { return this.once('open', function() { this._read(n); }); + } if (this.destroyed) return; @@ -2116,10 +2117,11 @@ WriteStream.prototype._write = function(data, encoding, cb) { if (!(data instanceof Buffer)) return this.emit('error', new Error('Invalid data')); - if (typeof this.fd !== 'number') + if (typeof this.fd !== 'number') { return this.once('open', function() { this._write(data, encoding, cb); }); + } var self = this; fs.write(this.fd, data, 0, data.length, this.pos, function(er, bytes) { @@ -2151,10 +2153,11 @@ function writev(fd, chunks, position, callback) { WriteStream.prototype._writev = function(data, cb) { - if (typeof this.fd !== 'number') + if (typeof this.fd !== 'number') { return this.once('open', function() { this._writev(data, cb); }); + } const self = this; const len = data.length; diff --git a/lib/inspector.js b/lib/inspector.js index e4c401a9951..d73d8a23491 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -41,22 +41,26 @@ class Session extends EventEmitter { } post(method, params, callback) { - if (typeof method !== 'string') + if (typeof method !== 'string') { throw new TypeError( `"method" must be a string, got ${typeof method} instead`); + } if (!callback && util.isFunction(params)) { callback = params; params = null; } - if (params && typeof params !== 'object') + if (params && typeof params !== 'object') { throw new TypeError( `"params" must be an object, got ${typeof params} instead`); - if (callback && typeof callback !== 'function') + } + if (callback && typeof callback !== 'function') { throw new TypeError( `"callback" must be a function, got ${typeof callback} instead`); + } - if (!this[connectionSymbol]) + if (!this[connectionSymbol]) { throw new Error('Session is not connected'); + } const id = this[nextIdSymbol]++; const message = {id, method}; if (params) { diff --git a/lib/internal/process.js b/lib/internal/process.js index 5254b5993bd..1636e73b7e0 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -46,10 +46,12 @@ function setup_cpuUsage() { } // If a previous value was passed in, return diff of current from previous. - if (prevValue) return { - user: cpuValues[0] - prevValue.user, - system: cpuValues[1] - prevValue.system - }; + if (prevValue) { + return { + user: cpuValues[0] - prevValue.user, + system: cpuValues[1] - prevValue.system + }; + } // If no previous value passed in, return current value. return { diff --git a/lib/net.js b/lib/net.js index 121757aa108..5f4eec89ec8 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1005,19 +1005,23 @@ function lookupAndConnect(self, options) { var localAddress = options.localAddress; var localPort = options.localPort; - if (localAddress && !cares.isIP(localAddress)) + if (localAddress && !cares.isIP(localAddress)) { throw new TypeError('"localAddress" option must be a valid IP: ' + localAddress); + } - if (localPort && typeof localPort !== 'number') + if (localPort && typeof localPort !== 'number') { throw new TypeError('"localPort" option should be a number: ' + localPort); + } if (typeof port !== 'undefined') { - if (typeof port !== 'number' && typeof port !== 'string') + if (typeof port !== 'number' && typeof port !== 'string') { throw new TypeError('"port" option should be a number or string: ' + port); - if (!isLegalPort(port)) + } + if (!isLegalPort(port)) { throw new RangeError('"port" option should be >= 0 and < 65536: ' + port); + } } port |= 0; diff --git a/lib/readline.js b/lib/readline.js index 51d1da5770e..5e4318e44b6 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -285,16 +285,18 @@ Interface.prototype._onLine = function(line) { }; Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) { - if (typeof stringToWrite !== 'string') + if (typeof stringToWrite !== 'string') { throw new errors.TypeError( 'ERR_INVALID_ARG_TYPE', 'stringToWrite', 'string', stringToWrite ); + } - if (this.output !== null && this.output !== undefined) + if (this.output !== null && this.output !== undefined) { this.output.write(stringToWrite); + } }; Interface.prototype._addHistory = function() { diff --git a/lib/tls.js b/lib/tls.js index 2247bb9ee56..5a03c3c30f8 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -122,9 +122,10 @@ function check(hostParts, pattern, wildcards) { return false; // Check host parts from right to left first. - for (var i = hostParts.length - 1; i > 0; i -= 1) + for (var i = hostParts.length - 1; i > 0; i -= 1) { if (hostParts[i] !== patternParts[i]) return false; + } const hostSubdomain = hostParts[0]; const patternSubdomain = patternParts[0]; diff --git a/lib/util.js b/lib/util.js index c75117b711a..fdc4a9b3b66 100644 --- a/lib/util.js +++ b/lib/util.js @@ -962,9 +962,10 @@ exports.inherits = function(ctor, superCtor) { if (superCtor === undefined || superCtor === null) throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'function'); - if (superCtor.prototype === undefined) + if (superCtor.prototype === undefined) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype', 'function'); + } ctor.super_ = superCtor; Object.setPrototypeOf(ctor.prototype, superCtor.prototype); }; diff --git a/test/common/index.js b/test/common/index.js index 7f008201237..6e910881523 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -429,9 +429,11 @@ function leakedGlobals() { const leaked = []; // eslint-disable-next-line no-var - for (var val in global) - if (!knownGlobals.includes(global[val])) + for (var val in global) { + if (!knownGlobals.includes(global[val])) { leaked.push(val); + } + } if (global.__coverage__) { return leaked.filter((varname) => !/^(?:cov_|__cov)/.test(varname)); @@ -700,9 +702,10 @@ Object.defineProperty(exports, 'hasSmallICU', { exports.expectsError = function expectsError({code, type, message}) { return function(error) { assert.strictEqual(error.code, code); - if (type !== undefined) + if (type !== undefined) { assert(error instanceof type, `${error} is not the expected type ${type}`); + } if (message instanceof RegExp) { assert(message.test(error.message), `${error.message} does not match ${message}`); @@ -758,11 +761,13 @@ exports.getTTYfd = function getTTYfd() { if (!tty.isatty(tty_fd)) tty_fd++; else if (!tty.isatty(tty_fd)) tty_fd++; else if (!tty.isatty(tty_fd)) tty_fd++; - else try { - tty_fd = require('fs').openSync('/dev/tty'); - } catch (e) { - // There aren't any tty fd's available to use. - return -1; + else { + try { + tty_fd = require('fs').openSync('/dev/tty'); + } catch (e) { + // There aren't any tty fd's available to use. + return -1; + } } return tty_fd; }; diff --git a/test/parallel/test-domain-uncaught-exception.js b/test/parallel/test-domain-uncaught-exception.js index 2a157f9398b..0e5548df563 100644 --- a/test/parallel/test-domain-uncaught-exception.js +++ b/test/parallel/test-domain-uncaught-exception.js @@ -182,10 +182,11 @@ if (process.argv[2] === 'child') { // Make sure that all expected messages were sent from the // child process test.expectedMessages.forEach(function(expectedMessage) { - if (test.messagesReceived === undefined || - test.messagesReceived.indexOf(expectedMessage) === -1) + const msgs = test.messagesReceived; + if (msgs === undefined || !msgs.includes(expectedMessage)) { assert.fail(`test ${test.fn.name} should have sent message: ${ expectedMessage} but didn't`); + } }); if (test.messagesReceived) { diff --git a/test/parallel/test-fs-null-bytes.js b/test/parallel/test-fs-null-bytes.js index a21fe516a09..0552801b2de 100644 --- a/test/parallel/test-fs-null-bytes.js +++ b/test/parallel/test-fs-null-bytes.js @@ -33,13 +33,15 @@ function check(async, sync) { assert.strictEqual(er.code, 'ENOENT'); }); - if (sync) + if (sync) { assert.throws(() => { sync.apply(null, argsSync); }, expected); + } - if (async) + if (async) { async.apply(null, argsAsync); + } } check(fs.access, fs.accessSync, 'foo\u0000bar'); diff --git a/test/pummel/test-net-write-callbacks.js b/test/pummel/test-net-write-callbacks.js index 7c3df30f582..10aff090583 100644 --- a/test/pummel/test-net-write-callbacks.js +++ b/test/pummel/test-net-write-callbacks.js @@ -46,9 +46,10 @@ function makeCallback(c) { if (called) throw new Error(`called callback #${c} more than once`); called = true; - if (c < lastCalled) + if (c < lastCalled) { throw new Error( `callbacks out of order. last=${lastCalled} current=${c}`); + } lastCalled = c; cbcount++; }; |