Skip to content
Permalink
Browse files

test,lib,doc: use function declarations

Replace function expressions with function declarations in preparation
for a lint rule requiring function declarations.

PR-URL: #12711
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information...
Trott committed Apr 28, 2017
1 parent dd20e68 commit a180259e428fbc3e220abdceb74d941482b87d40
Showing with 127 additions and 131 deletions.
  1. +1 −1 doc/api/util.md
  2. +2 −2 lib/_tls_legacy.js
  3. +2 −2 lib/crypto.js
  4. +2 −2 lib/internal/util.js
  5. +2 −3 test/addons-napi/test_async/test.js
  6. +3 −3 test/addons-napi/test_exception/test.js
  7. +2 −2 test/addons-napi/test_instanceof/test.js
  8. +2 −2 test/addons/make-callback/test.js
  9. +4 −4 test/inspector/inspector-helper.js
  10. +2 −1 test/parallel/test-assert.js
  11. +2 −2 test/parallel/test-child-process-fork-dgram.js
  12. +6 −6 test/parallel/test-child-process-fork-net.js
  13. +2 −2 test/parallel/test-child-process-fork-net2.js
  14. +1 −1 test/parallel/test-child-process-spawn-typeerror.js
  15. +4 −4 test/parallel/test-cluster-disconnect.js
  16. +1 −1 test/parallel/test-cluster-master-error.js
  17. +1 −1 test/parallel/test-cluster-master-kill.js
  18. +1 −1 test/parallel/test-cluster-message.js
  19. +1 −1 test/parallel/test-cluster-worker-exit.js
  20. +1 −1 test/parallel/test-console-not-call-toString.js
  21. +2 −2 test/parallel/test-event-emitter-add-listeners.js
  22. +2 −2 test/parallel/test-event-emitter-once.js
  23. +2 −2 test/parallel/test-fs-access.js
  24. +2 −2 test/parallel/test-fs-link.js
  25. +2 −2 test/parallel/test-fs-read-stream-fd-leak.js
  26. +47 −47 test/parallel/test-http-parser.js
  27. +2 −2 test/parallel/test-http-response-status-message.js
  28. +1 −1 test/parallel/test-https-simple.js
  29. +4 −4 test/parallel/test-net-server-max-connections-close-makes-more-available.js
  30. +2 −2 test/parallel/test-net-server-pause-on-connect.js
  31. +2 −2 test/parallel/test-os.js
  32. +2 −4 test/parallel/test-preload.js
  33. +1 −1 test/parallel/test-querystring.js
  34. +1 −3 test/parallel/test-readline-interface.js
  35. +4 −4 test/parallel/test-stream2-pipe-error-once-listener.js
  36. +2 −2 test/parallel/test-timers-ordering.js
  37. +1 −1 test/parallel/test-util-inspect.js
  38. +3 −3 test/pummel/test-dtrace-jsstack.js
  39. +3 −3 test/pummel/test-tls-session-timeout.js
@@ -592,7 +592,7 @@ Returns `true` if the given `object` is a `Function`. Otherwise, returns
const util = require('util');
function Foo() {}
const Bar = function() {};
const Bar = () => {};
util.isFunction({});
// Returns: false
@@ -448,9 +448,9 @@ CryptoStream.prototype.destroySoon = function(err) {
// was written on this side was read from the other side.
var self = this;
var waiting = 1;
var finish = function() {
function finish() {
if (--waiting === 0) self.destroy();
};
}
this._opposite.once('end', finish);
if (!this._finished) {
this.once('finish', finish);
@@ -645,11 +645,11 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
// at this point, we need to handle encodings.
var encoding = exports.DEFAULT_ENCODING;
if (callback) {
var next = function(er, ret) {
function next(er, ret) {
if (ret)
ret = ret.toString(encoding);
callback(er, ret);
};
}
binding.PBKDF2(password, salt, iterations, keylen, digest, next);
} else {
var ret = binding.PBKDF2(password, salt, iterations, keylen, digest);
@@ -143,9 +143,9 @@ function cachedResult(fn) {
// B() instanceof A // true
// B() instanceof B // true
function createClassWrapper(type) {
const fn = function(...args) {
function fn(...args) {
return Reflect.construct(type, args, new.target || type);
};
}
// Mask the wrapper function name and length values
Object.defineProperties(fn, {
name: {value: type.name},
@@ -6,8 +6,7 @@ const test_async = require(`./build/${common.buildType}/test_async`);
test_async.Test(5, common.mustCall(function(err, val) {
assert.strictEqual(err, null);
assert.strictEqual(val, 10);
process.nextTick(common.mustCall(function() {}));
process.nextTick(common.mustCall());
}));

const cancelSuceeded = function() {};
test_async.TestCancel(common.mustCall(cancelSuceeded));
test_async.TestCancel(common.mustCall());
@@ -4,12 +4,12 @@ const common = require('../../common');
const test_exception = require(`./build/${common.buildType}/test_exception`);
const assert = require('assert');
const theError = new Error('Some error');
const throwTheError = function() {
function throwTheError() {
throw theError;
};
}
let caughtError;

const throwNoError = function() {};
const throwNoError = common.noop;

// Test that the native side successfully captures the exception
let returnedError = test_exception.returnException(throwTheError);
@@ -57,14 +57,14 @@ if (typeof Symbol !== 'undefined' && 'hasInstance' in Symbol &&
(theObject instanceof theConstructor));
}

const MyClass = function MyClass() {};
function MyClass() {}
Object.defineProperty(MyClass, Symbol.hasInstance, {
value: function(candidate) {
return 'mark' in candidate;
}
});

const MySubClass = function MySubClass() {};
function MySubClass() {}
MySubClass.prototype = new MyClass();

let x = new MySubClass();
@@ -57,9 +57,9 @@ const forward = vm.runInNewContext(`
})
`);
// Runs in outer context.
const endpoint = function($Object) {
function endpoint($Object) {
if (Object === $Object)
throw new Error('bad');
return Object;
};
}
assert.strictEqual(Object, makeCallback(process, forward, endpoint));
@@ -122,7 +122,7 @@ function timeout(message, multiplicator) {
TIMEOUT * (multiplicator || 1));
}

const TestSession = function(socket, harness) {
function TestSession(socket, harness) {
this.mainScriptPath = harness.mainScriptPath;
this.mainScriptId = null;

@@ -147,7 +147,7 @@ const TestSession = function(socket, harness) {
buffer = buffer.slice(consumed);
} while (consumed);
}).on('close', () => assert(this.expectClose_, 'Socket closed prematurely'));
};
}

TestSession.prototype.scriptUrlForId = function(id) {
return this.scripts_[id];
@@ -304,7 +304,7 @@ TestSession.prototype.testHttpResponse = function(path, check) {
};


const Harness = function(port, childProcess) {
function Harness(port, childProcess) {
this.port = port;
this.mainScriptPath = mainScript;
this.stderrFilters_ = [];
@@ -329,7 +329,7 @@ const Harness = function(port, childProcess) {
this.returnCode_ = code;
this.running_ = false;
});
};
}

Harness.prototype.addStderrFilter = function(regexp, callback) {
this.stderrFilters_.push((message) => {
@@ -449,7 +449,7 @@ a.throws(makeBlock(thrower, TypeError), function(err) {

AnotherErrorType = class extends Error {};

const functionThatThrows = function() {
const functionThatThrows = () => {
throw new AnotherErrorType('foo');
};

@@ -493,6 +493,7 @@ a.throws(makeBlock(a.deepEqual, args, []));

// more checking that arguments objects are handled correctly
{
// eslint-disable-next-line func-style
const returnArguments = function() { return arguments; };

const someArgs = returnArguments('a');
@@ -78,7 +78,7 @@ if (process.argv[2] === 'child') {
});
});

const sendMessages = function() {
function sendMessages() {
const serverPort = parentServer.address().port;

const timer = setInterval(function() {
@@ -102,7 +102,7 @@ if (process.argv[2] === 'child') {
);
}
}, 1);
};
}

parentServer.bind(0, '127.0.0.1');

@@ -87,7 +87,7 @@ if (process.argv[2] === 'child') {
}));

// send net.Server to child and test by connecting
const testServer = function(callback) {
function testServer(callback) {

// destroy server execute callback when done
const progress = new ProgressTracker(2, function() {
@@ -116,7 +116,7 @@ if (process.argv[2] === 'child') {
server.listen(0);

// handle client messages
const messageHandlers = function(msg) {
function messageHandlers(msg) {

if (msg.what === 'listening') {
// make connections
@@ -138,13 +138,13 @@ if (process.argv[2] === 'child') {
child.removeListener('message', messageHandlers);
callback();
}
};
}

child.on('message', messageHandlers);
};
}

// send net.Socket to child
const testSocket = function(callback) {
function testSocket(callback) {

// create a new server and connect to it,
// but the socket will be handled by the child
@@ -179,7 +179,7 @@ if (process.argv[2] === 'child') {
server.close();
});
});
};
}

// create server and send it to child
let serverSuccess = false;
@@ -144,7 +144,7 @@ if (process.argv[2] === 'child') {

server.listen(0, '127.0.0.1');

const closeServer = function() {
function closeServer() {
server.close();

setTimeout(function() {
@@ -153,7 +153,7 @@ if (process.argv[2] === 'child') {
child2.send('close');
child3.disconnect();
}, 200);
};
}

process.on('exit', function() {
assert.strictEqual(disconnected, count);
@@ -89,7 +89,7 @@ assert.throws(function() {
// Argument types for combinatorics
const a = [];
const o = {};
const c = function c() {};
function c() {}
const s = 'string';
const u = undefined;
const n = null;
@@ -38,7 +38,7 @@ if (cluster.isWorker) {
const servers = 2;

// test a single TCP server
const testConnection = function(port, cb) {
const testConnection = (port, cb) => {
const socket = net.connect(port, '127.0.0.1', () => {
// buffer result
let result = '';
@@ -52,7 +52,7 @@ if (cluster.isWorker) {
};

// test both servers created in the cluster
const testCluster = function(cb) {
const testCluster = (cb) => {
let done = 0;

for (let i = 0; i < servers; i++) {
@@ -67,7 +67,7 @@ if (cluster.isWorker) {
};

// start two workers and execute callback when both is listening
const startCluster = function(cb) {
const startCluster = (cb) => {
const workers = 8;
let online = 0;

@@ -81,7 +81,7 @@ if (cluster.isWorker) {
}
};

const test = function(again) {
const test = (again) => {
//1. start cluster
startCluster(common.mustCall(() => {
//2. test cluster
@@ -101,7 +101,7 @@ if (cluster.isWorker) {
// Check that the cluster died accidentally (non-zero exit code)
masterExited = !!code;

const pollWorkers = function() {
const pollWorkers = () => {
// When master is dead all workers should be dead too
let alive = false;
workers.forEach((pid) => alive = common.isAlive(pid));
@@ -68,7 +68,7 @@ if (cluster.isWorker) {
assert.strictEqual(code, 0);

// check worker process status
const pollWorker = function() {
const pollWorker = () => {
alive = common.isAlive(pid);
if (alive) {
setTimeout(pollWorker, 50);
@@ -80,7 +80,7 @@ if (cluster.isWorker) {


let client;
const check = function(type, result) {
const check = (type, result) => {
checks[type].receive = true;
checks[type].correct = result;
console.error('check', checks);
@@ -103,7 +103,7 @@ if (cluster.isWorker) {
}
}));

const finish_test = function() {
const finish_test = () => {
try {
checkResults(expected_results, results);
} catch (exc) {
@@ -23,7 +23,7 @@
require('../common');
const assert = require('assert');

const func = function() {};
function func() {}
let toStringCalled = false;
func.toString = function() {
toStringCalled = true;
@@ -68,8 +68,8 @@ const EventEmitter = require('events');
}

{
const listen1 = function listen1() {};
const listen2 = function listen2() {};
const listen1 = () => {};
const listen2 = () => {};
const ee = new EventEmitter();

ee.once('newListener', function() {
@@ -33,9 +33,9 @@ e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');

const remove = function() {
function remove() {
assert.fail('once->foo should not be emitted');
};
}

e.once('foo', remove);
e.removeListener('foo', remove);
@@ -7,10 +7,10 @@ const doesNotExist = path.join(common.tmpDir, '__this_should_not_exist');
const readOnlyFile = path.join(common.tmpDir, 'read_only_file');
const readWriteFile = path.join(common.tmpDir, 'read_write_file');

const createFileWithPerms = function(file, mode) {
function createFileWithPerms(file, mode) {
fs.writeFileSync(file, '');
fs.chmodSync(file, mode);
};
}

common.refreshTmpDir();
createFileWithPerms(readOnlyFile, 0o444);
@@ -11,11 +11,11 @@ const srcPath = path.join(common.tmpDir, 'hardlink-target.txt');
const dstPath = path.join(common.tmpDir, 'link1.js');
fs.writeFileSync(srcPath, 'hello world');

const callback = function(err) {
function callback(err) {
assert.ifError(err);
const dstContent = fs.readFileSync(dstPath, 'utf8');
assert.strictEqual('hello world', dstContent);
};
}

fs.link(srcPath, dstPath, common.mustCall(callback));

@@ -29,7 +29,7 @@ function testLeak(endFn, callback) {
let i = 0;
let check = 0;

const checkFunction = function() {
function checkFunction() {
if (openCount !== 0 && check < totalCheck) {
check++;
setTimeout(checkFunction, 100);
@@ -44,7 +44,7 @@ function testLeak(endFn, callback) {

openCount = 0;
callback && setTimeout(callback, 100);
};
}

setInterval(function() {
const s = fs.createReadStream(emptyTxt);
Oops, something went wrong.

0 comments on commit a180259

Please sign in to comment.
You can’t perform that action at this time.