Skip to content

Commit

Permalink
test,lib,doc: use function declarations
Browse files Browse the repository at this point in the history
Replace function expressions with function declarations in preparation
for a lint rule requiring function declarations.

PR-URL: #12711
Backport-PR-URL: #13774
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
  • Loading branch information
Trott authored and MylesBorins committed Jul 11, 2017
1 parent 6afa5fe commit 7e6a956
Show file tree
Hide file tree
Showing 39 changed files with 130 additions and 133 deletions.
2 changes: 1 addition & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,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
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) {
cb();
}

var onSocket = function() {
var onSocket = () => {
if (self.socket.writable) {
callSocketMethod();
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/_tls_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,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);
Expand Down
4 changes: 2 additions & 2 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,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);
Expand Down
4 changes: 2 additions & 2 deletions test/addons/make-callback/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
8 changes: 4 additions & 4 deletions test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function timeout(message, multiplicator) {
TIMEOUT * (multiplicator || 1));
}

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

Expand All @@ -145,7 +145,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];
Expand Down Expand Up @@ -302,7 +302,7 @@ TestSession.prototype.testHttpResponse = function(path, check) {
};


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

Harness.prototype.addStderrFilter = function(regexp, callback) {
this.stderrFilters_.push((message) => {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ try {

AnotherErrorType = class extends Error {};

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

Expand Down Expand Up @@ -471,6 +471,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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-fork-dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if (process.argv[2] === 'child') {
});
});

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

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

parentServer.bind(0, '127.0.0.1');

Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-child-process-fork-net.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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() {
Expand Down Expand Up @@ -95,7 +95,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
Expand All @@ -117,13 +117,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
Expand Down Expand Up @@ -158,7 +158,7 @@ if (process.argv[2] === 'child') {
server.close();
});
});
};
}

// create server and send it to child
let serverSuccess = false;
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-fork-net2.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if (process.argv[2] === 'child') {

server.listen(0, '127.0.0.1');

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

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

process.on('exit', function() {
assert.strictEqual(disconnected, count);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawn-typeerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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;
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-cluster-disconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 = '';
Expand All @@ -31,7 +31,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++) {
Expand All @@ -46,7 +46,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;

Expand All @@ -60,7 +60,7 @@ if (cluster.isWorker) {
}
};

const test = function(again) {
const test = (again) => {
//1. start cluster
startCluster(common.mustCall(() => {
//2. test cluster
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-master-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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));
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-master-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-worker-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if (cluster.isWorker) {
}
}));

const finish_test = function() {
const finish_test = () => {
try {
checkResults(expected_results, results);
} catch (exc) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-console-not-call-toString.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require('../common');
const assert = require('assert');

const func = function() {};
function func() {}
let toStringCalled = false;
func.toString = function() {
toStringCalled = true;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-pid.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const interfacer = spawn(process.execPath, ['debug', '-p', '655555']);
console.error(process.execPath, 'debug', '-p', '655555');
interfacer.stdout.setEncoding('utf-8');
interfacer.stderr.setEncoding('utf-8');
const onData = function(data) {
const onData = (data) => {
data = (buffer + data).split('\n');
buffer = data.pop();
data.forEach(function(line) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-event-emitter-add-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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() {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-event-emitter-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');

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

e.once('foo', remove);
e.removeListener('foo', remove);
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ 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 removeFile = function(file) {
const removeFile = (file) => {
try {
fs.unlinkSync(file);
} catch (err) {
// Ignore error
}
};

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

common.refreshTmpDir();
createFileWithPerms(readOnlyFile, 0o444);
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-fs-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (err) throw 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));

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-read-stream-fd-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -44,7 +44,7 @@ function testLeak(endFn, callback) {

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

setInterval(function() {
const s = fs.createReadStream(emptyTxt);
Expand Down
Loading

0 comments on commit 7e6a956

Please sign in to comment.