Skip to content

Commit a180259

Browse files
committed
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 <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent dd20e68 commit a180259

39 files changed

+127
-131
lines changed

doc/api/util.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ Returns `true` if the given `object` is a `Function`. Otherwise, returns
592592
const util = require('util');
593593

594594
function Foo() {}
595-
const Bar = function() {};
595+
const Bar = () => {};
596596

597597
util.isFunction({});
598598
// Returns: false

lib/_tls_legacy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ CryptoStream.prototype.destroySoon = function(err) {
448448
// was written on this side was read from the other side.
449449
var self = this;
450450
var waiting = 1;
451-
var finish = function() {
451+
function finish() {
452452
if (--waiting === 0) self.destroy();
453-
};
453+
}
454454
this._opposite.once('end', finish);
455455
if (!this._finished) {
456456
this.once('finish', finish);

lib/crypto.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,11 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
645645
// at this point, we need to handle encodings.
646646
var encoding = exports.DEFAULT_ENCODING;
647647
if (callback) {
648-
var next = function(er, ret) {
648+
function next(er, ret) {
649649
if (ret)
650650
ret = ret.toString(encoding);
651651
callback(er, ret);
652-
};
652+
}
653653
binding.PBKDF2(password, salt, iterations, keylen, digest, next);
654654
} else {
655655
var ret = binding.PBKDF2(password, salt, iterations, keylen, digest);

lib/internal/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ function cachedResult(fn) {
143143
// B() instanceof A // true
144144
// B() instanceof B // true
145145
function createClassWrapper(type) {
146-
const fn = function(...args) {
146+
function fn(...args) {
147147
return Reflect.construct(type, args, new.target || type);
148-
};
148+
}
149149
// Mask the wrapper function name and length values
150150
Object.defineProperties(fn, {
151151
name: {value: type.name},

test/addons-napi/test_async/test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const test_async = require(`./build/${common.buildType}/test_async`);
66
test_async.Test(5, common.mustCall(function(err, val) {
77
assert.strictEqual(err, null);
88
assert.strictEqual(val, 10);
9-
process.nextTick(common.mustCall(function() {}));
9+
process.nextTick(common.mustCall());
1010
}));
1111

12-
const cancelSuceeded = function() {};
13-
test_async.TestCancel(common.mustCall(cancelSuceeded));
12+
test_async.TestCancel(common.mustCall());

test/addons-napi/test_exception/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const common = require('../../common');
44
const test_exception = require(`./build/${common.buildType}/test_exception`);
55
const assert = require('assert');
66
const theError = new Error('Some error');
7-
const throwTheError = function() {
7+
function throwTheError() {
88
throw theError;
9-
};
9+
}
1010
let caughtError;
1111

12-
const throwNoError = function() {};
12+
const throwNoError = common.noop;
1313

1414
// Test that the native side successfully captures the exception
1515
let returnedError = test_exception.returnException(throwTheError);

test/addons-napi/test_instanceof/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ if (typeof Symbol !== 'undefined' && 'hasInstance' in Symbol &&
5757
(theObject instanceof theConstructor));
5858
}
5959

60-
const MyClass = function MyClass() {};
60+
function MyClass() {}
6161
Object.defineProperty(MyClass, Symbol.hasInstance, {
6262
value: function(candidate) {
6363
return 'mark' in candidate;
6464
}
6565
});
6666

67-
const MySubClass = function MySubClass() {};
67+
function MySubClass() {}
6868
MySubClass.prototype = new MyClass();
6969

7070
let x = new MySubClass();

test/addons/make-callback/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ const forward = vm.runInNewContext(`
5757
})
5858
`);
5959
// Runs in outer context.
60-
const endpoint = function($Object) {
60+
function endpoint($Object) {
6161
if (Object === $Object)
6262
throw new Error('bad');
6363
return Object;
64-
};
64+
}
6565
assert.strictEqual(Object, makeCallback(process, forward, endpoint));

test/inspector/inspector-helper.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function timeout(message, multiplicator) {
122122
TIMEOUT * (multiplicator || 1));
123123
}
124124

125-
const TestSession = function(socket, harness) {
125+
function TestSession(socket, harness) {
126126
this.mainScriptPath = harness.mainScriptPath;
127127
this.mainScriptId = null;
128128

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

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

306306

307-
const Harness = function(port, childProcess) {
307+
function Harness(port, childProcess) {
308308
this.port = port;
309309
this.mainScriptPath = mainScript;
310310
this.stderrFilters_ = [];
@@ -329,7 +329,7 @@ const Harness = function(port, childProcess) {
329329
this.returnCode_ = code;
330330
this.running_ = false;
331331
});
332-
};
332+
}
333333

334334
Harness.prototype.addStderrFilter = function(regexp, callback) {
335335
this.stderrFilters_.push((message) => {

test/parallel/test-assert.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
449449

450450
AnotherErrorType = class extends Error {};
451451

452-
const functionThatThrows = function() {
452+
const functionThatThrows = () => {
453453
throw new AnotherErrorType('foo');
454454
};
455455

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

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

498499
const someArgs = returnArguments('a');

0 commit comments

Comments
 (0)