From 8d61787f177e3002b87227d71f0b9707c7bb73d6 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 30 Jan 2016 21:46:45 -0800 Subject: [PATCH] test: fix variable redeclarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I'm a fan of small changesets, but even I'm getting a little annoyed at me for opening all these PRs weeding out variable redeclarations. So I'm bundling a bunch of small changes here. PR-URL: https://github.com/nodejs/node/pull/4992 Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell --- test/parallel/test-process-env.js | 4 +- test/parallel/test-querystring.js | 37 ++++++++++--------- test/parallel/test-readline-interface.js | 2 +- test/parallel/test-repl-persistent-history.js | 6 +-- test/parallel/test-stream2-push.js | 2 +- test/parallel/test-string-decoder-end.js | 2 +- test/parallel/test-stringbytes-external.js | 6 +-- test/parallel/test-tls-cipher-list.js | 2 +- test/parallel/test-zlib.js | 2 +- 9 files changed, 31 insertions(+), 32 deletions(-) diff --git a/test/parallel/test-process-env.js b/test/parallel/test-process-env.js index 932bae3f8ff095..b5e62324ac15db 100644 --- a/test/parallel/test-process-env.js +++ b/test/parallel/test-process-env.js @@ -31,12 +31,12 @@ if (process.argv[2] == 'you-are-the-child') { assert.equal(42, process.env.NODE_PROCESS_ENV); assert.equal('asdf', process.env.hasOwnProperty); var hasOwnProperty = Object.prototype.hasOwnProperty; - var has = hasOwnProperty.call(process.env, 'hasOwnProperty'); + const has = hasOwnProperty.call(process.env, 'hasOwnProperty'); assert.equal(true, has); process.exit(0); } else { assert.equal(Object.prototype.hasOwnProperty, process.env.hasOwnProperty); - var has = process.env.hasOwnProperty('hasOwnProperty'); + const has = process.env.hasOwnProperty('hasOwnProperty'); assert.equal(false, has); process.env.hasOwnProperty = 'asdf'; diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index f30d0a3cb2597e..b4388852499ed1 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -148,29 +148,32 @@ assert.strictEqual('foo=', qs.stringify({ foo: NaN })); assert.strictEqual('foo=', qs.stringify({ foo: Infinity })); // nested -var f = qs.stringify({ - a: 'b', - q: qs.stringify({ - x: 'y', - y: 'z' - }) -}); -assert.equal(f, 'a=b&q=x%3Dy%26y%3Dz'); +{ + const f = qs.stringify({ + a: 'b', + q: qs.stringify({ + x: 'y', + y: 'z' + }) + }); + assert.equal(f, 'a=b&q=x%3Dy%26y%3Dz'); +} assert.doesNotThrow(function() { qs.parse(undefined); }); // nested in colon -var f = qs.stringify({ - a: 'b', - q: qs.stringify({ - x: 'y', - y: 'z' - }, ';', ':') -}, ';', ':'); -assert.equal(f, 'a:b;q:x%3Ay%3By%3Az'); - +{ + const f = qs.stringify({ + a: 'b', + q: qs.stringify({ + x: 'y', + y: 'z' + }, ';', ':') + }, ';', ':'); + assert.equal(f, 'a:b;q:x%3Ay%3By%3Az'); +} assert.deepEqual({}, qs.parse()); diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 3ea34a00d1e412..0bdcfe1bc4700f 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -296,7 +296,7 @@ function isWarned(emitter) { rli.question(expectedLines.join('\n'), function() { rli.close(); }); - var cursorPos = rli._getCursorPos(); + cursorPos = rli._getCursorPos(); assert.equal(cursorPos.rows, expectedLines.length - 1); assert.equal(cursorPos.cols, expectedLines.slice(-1)[0].length); rli.close(); diff --git a/test/parallel/test-repl-persistent-history.js b/test/parallel/test-repl-persistent-history.js index 387cef7e97a794..e8b6d416f00ec4 100644 --- a/test/parallel/test-repl-persistent-history.js +++ b/test/parallel/test-repl-persistent-history.js @@ -272,11 +272,7 @@ function runTest(assertCleaned) { }); function onClose() { - if (after) { - var cleaned = after(); - } else { - var cleaned = cleanupTmpFile(); - } + const cleaned = after ? after() : cleanupTmpFile(); try { // Ensure everything that we expected was output diff --git a/test/parallel/test-stream2-push.js b/test/parallel/test-stream2-push.js index 99b73d7277aa52..e4603e688ecf55 100644 --- a/test/parallel/test-stream2-push.js +++ b/test/parallel/test-stream2-push.js @@ -10,7 +10,7 @@ var EE = require('events').EventEmitter; // a mock thing a bit like the net.Socket/tcp_wrap.handle interaction -var stream = new Readable({ +stream = new Readable({ highWaterMark: 16, encoding: 'utf8' }); diff --git a/test/parallel/test-string-decoder-end.js b/test/parallel/test-string-decoder-end.js index c3afb88d778b39..a064250dcdd39f 100644 --- a/test/parallel/test-string-decoder-end.js +++ b/test/parallel/test-string-decoder-end.js @@ -43,7 +43,7 @@ function testBuf(encoding, buf) { // write the whole buffer at once. var res2 = ''; - var s = new SD(encoding); + s = new SD(encoding); res2 += s.write(buf); res2 += s.end(); diff --git a/test/parallel/test-stringbytes-external.js b/test/parallel/test-stringbytes-external.js index 1f03e2be42f577..f9bd78378e3414 100644 --- a/test/parallel/test-stringbytes-external.js +++ b/test/parallel/test-stringbytes-external.js @@ -22,9 +22,9 @@ write_str = Array(size).join(write_str); ucs2_control = Array(size).join(ucs2_control); // check resultant buffer and output string -var b = new Buffer(write_str, 'ucs2'); +b = new Buffer(write_str, 'ucs2'); // check fist Buffer created from write string -for (var i = 0; i < b.length; i += 2) { +for (let i = 0; i < b.length; i += 2) { assert.equal(b[i], 0x61); assert.equal(b[i + 1], 0); } @@ -39,7 +39,7 @@ var c_ucs = new Buffer(b_ucs, 'ucs2'); // make sure they're the same length assert.equal(c_bin.length, c_ucs.length); // make sure Buffers from externals are the same -for (var i = 0; i < c_bin.length; i++) { +for (let i = 0; i < c_bin.length; i++) { assert.equal(c_bin[i], c_ucs[i]); } // check resultant strings diff --git a/test/parallel/test-tls-cipher-list.js b/test/parallel/test-tls-cipher-list.js index f20a0a6a249aed..70c99dd91e439c 100644 --- a/test/parallel/test-tls-cipher-list.js +++ b/test/parallel/test-tls-cipher-list.js @@ -12,7 +12,7 @@ const defaultCoreList = require('constants').defaultCoreCipherList; function doCheck(arg, check) { var out = ''; - var arg = arg.concat([ + arg = arg.concat([ '-pe', 'require("constants").defaultCipherList' ]); diff --git a/test/parallel/test-zlib.js b/test/parallel/test-zlib.js index b3f193d0a60b2c..1256d94a61402d 100644 --- a/test/parallel/test-zlib.js +++ b/test/parallel/test-zlib.js @@ -42,7 +42,7 @@ var testFiles = ['person.jpg', 'elipses.txt', 'empty.txt']; if (process.env.FAST) { zlibPairs = [[zlib.Gzip, zlib.Unzip]]; - var testFiles = ['person.jpg']; + testFiles = ['person.jpg']; } var tests = {};