Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 54695d8

Browse files
committedJan 2, 2025··
chore: enable ESLint's recommended JS rules
1 parent 3c191c0 commit 54695d8

21 files changed

+50
-59
lines changed
 

‎docs/_data/supporters.js

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const getAllOrders = async (slug = 'mochajs') => {
139139
const variables = {limit: GRAPHQL_PAGE_SIZE, offset: 0, slug};
140140

141141
// Handling pagination if necessary (2 pages for ~1400 results in May 2019)
142+
// eslint-disable-next-line no-constant-condition
142143
while (true) {
143144
const result = await needle(
144145
'post',

‎eslint.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const messages = {
99
};
1010

1111
module.exports = [
12+
js.configs.recommended,
1213
{
13-
...js.configs.recommended,
1414
languageOptions: {
1515
ecmaVersion: 2020,
1616
globals: {
@@ -20,6 +20,8 @@ module.exports = [
2020
sourceType: 'script'
2121
},
2222
rules: {
23+
'no-empty': 'off',
24+
'no-redeclare': 'off',
2325
'no-var': 'off',
2426
strict: ['error', 'global']
2527
}

‎lib/cli/collect-files.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const fs = require('fs');
43
const path = require('path');
54
const ansi = require('ansi-colors');
65
const debug = require('debug')('mocha:cli:run:helpers');

‎lib/cli/run-helpers.js

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const {format} = require('util');
1717
const {createInvalidLegacyPluginError} = require('../errors');
1818
const {requireOrImport} = require('../nodejs/esm-utils');
1919
const PluginLoader = require('../plugin-loader');
20-
const {UnmatchedFile} = require('./collect-files');
2120

2221
/**
2322
* Exits Mocha when tests + code under test has finished execution (default)

‎lib/errors.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,9 @@ function createTimeoutError(msg, timeout, file) {
507507
* @public
508508
* @static
509509
* @param {string} message - Error message to be displayed.
510-
* @param {string} filename - File name
511510
* @returns {Error} Error with code {@link constants.UNPARSABLE_FILE}
512511
*/
513-
function createUnparsableFileError(message, filename) {
512+
function createUnparsableFileError(message) {
514513
var err = new Error(message);
515514
err.code = constants.UNPARSABLE_FILE;
516515
return err;

‎lib/reporters/html.js

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ function HTML(runner, options) {
9292
items[progressIndex].getElementsByClassName('ring-flatlight')[0],
9393
items[progressIndex].getElementsByClassName('ring-highlight')[0]
9494
];
95-
var progressRingRadius = null; // computed CSS unavailable now, so set later
9695
var root = document.getElementById('mocha');
9796

9897
if (!root) {

‎lib/reporters/tap.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ function title(test) {
9494
* Writes newline-terminated formatted string to reporter output stream.
9595
*
9696
* @private
97-
* @param {string} format - `printf`-like format string
9897
* @param {...*} [varArgs] - Format string arguments
9998
*/
100-
function println(format, varArgs) {
99+
function println() {
101100
var vargs = Array.from(arguments);
102101
vargs[0] += '\n';
103102
process.stdout.write(sprintf.apply(null, vargs));
@@ -184,9 +183,8 @@ TAPProducer.prototype.writePending = function (n, test) {
184183
* @abstract
185184
* @param {number} n - Index of test that failed.
186185
* @param {Test} test - Instance containing test information.
187-
* @param {Error} err - Reason the test failed.
188186
*/
189-
TAPProducer.prototype.writeFail = function (n, test, err) {
187+
TAPProducer.prototype.writeFail = function (n, test) {
190188
println('not ok %d %s', n, title(test));
191189
};
192190

‎lib/runner.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ Runner.prototype.run = function (fn, opts = {}) {
11101110
* unique ID's. Does nothing in serial mode, because the object references already exist.
11111111
* Subclasses can implement this (e.g., `ParallelBufferedRunner`)
11121112
* @abstract
1113-
* @param {boolean} [value] - If `true`, enable partial object linking, otherwise disable
11141113
* @returns {Runner}
11151114
* @chainable
11161115
* @public
@@ -1128,7 +1127,7 @@ Runner.prototype.run = function (fn, opts = {}) {
11281127
* }
11291128
* }
11301129
*/
1131-
Runner.prototype.linkPartialObjects = function (value) {
1130+
Runner.prototype.linkPartialObjects = function () {
11321131
return this;
11331132
};
11341133

‎lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ exports.noop = function () {};
543543
* @param {...*} [obj] - Arguments to `Object.assign()`.
544544
* @returns {Object} An object with no prototype, having `...obj` properties
545545
*/
546-
exports.createMap = function (obj) {
546+
exports.createMap = function () {
547547
return Object.assign.apply(
548548
null,
549549
[Object.create(null)].concat(Array.prototype.slice.call(arguments))

‎test/integration/hook-err.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function onlyConsoleOutput() {
292292
};
293293
}
294294

295-
function onlyErrorTitle(line) {
295+
function onlyErrorTitle() {
296296
let foundErrorTitle = false;
297297
let foundError = false;
298298
return line => {

‎test/integration/init.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ describe('init command', function () {
1313
tmpdir = path.join(os.tmpdir(), 'mocha-init');
1414
try {
1515
fs.mkdirSync(tmpdir);
16-
} catch (ignored) {}
16+
} catch {}
1717
expect(fs.existsSync(tmpdir), 'to be true');
1818
});
1919

2020
afterEach(function () {
2121
try {
2222
rimraf.sync(tmpdir);
23-
} catch (ignored) {}
23+
} catch {}
2424
});
2525

2626
describe('when no path is supplied', function () {

‎test/integration/options/parallel.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ describe('--parallel', function () {
510510
let pids = null;
511511
try {
512512
pids = await pidtree(childPid, {root: true});
513-
} catch (ignored) {}
513+
} catch {}
514514
return pids;
515515
})
516516
),
@@ -536,7 +536,7 @@ describe('--parallel', function () {
536536
let pids = null;
537537
try {
538538
pids = await pidtree(childPid, {root: true});
539-
} catch (ignored) {}
539+
} catch {}
540540
return pids;
541541
})
542542
),

‎test/integration/reporters.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('reporters', function () {
4949
'</testsuite>'
5050
];
5151

52-
run('passing.fixture.js', args, function (err, result) {
52+
run('passing.fixture.js', args, function (err) {
5353
if (err) return done(err);
5454

5555
var xml = fs.readFileSync(tmpFile, 'utf8');

‎test/node-unit/cli/options.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,14 @@ describe('options', function () {
344344
it('should not look for a config', function () {
345345
try {
346346
loadOptions(`--config ${config}`);
347-
} catch (ignored) {}
347+
} catch {}
348348
expect(findConfig, 'was not called');
349349
});
350350

351351
it('should attempt to load file at path', function () {
352352
try {
353353
loadOptions(`--config ${config}`);
354-
} catch (ignored) {}
354+
} catch {}
355355
expect(loadConfig, 'to have a call satisfying', [config]);
356356
});
357357

‎test/reporters/base.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Base reporter', function () {
3737
return diffStr;
3838
}
3939

40-
var gather = function (chunk, encoding, cb) {
40+
var gather = function (chunk) {
4141
stdout.push(chunk);
4242
};
4343

@@ -524,14 +524,14 @@ describe('Base reporter', function () {
524524
var err1 = {
525525
message: 'Error',
526526
stack: 'Error\nfoo\nbar',
527-
showDiff: false,
527+
showDiff: false
528528
};
529529
var err2 = {
530530
message: 'Cause1',
531531
stack: 'Cause1\nbar\nfoo',
532532
showDiff: false,
533533
cause: err1
534-
}
534+
};
535535
err1.cause = err2;
536536

537537
var test = makeTest(err1);
@@ -552,7 +552,7 @@ describe('Base reporter', function () {
552552
stack: 'Error\nfoo\nbar',
553553
showDiff: false,
554554
cause: {
555-
showDiff: false,
555+
showDiff: false
556556
}
557557
};
558558

‎test/reporters/helpers.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ function makeExpectedTest(
165165
expectedFullTitle,
166166
expectedFile,
167167
expectedDuration,
168-
currentRetry,
169-
expectedBody
168+
currentRetry
170169
) {
171170
return {
172171
title: expectedTitle,
@@ -203,7 +202,7 @@ function createRunReporterFunction(ctor) {
203202
var stdoutWriteStub = sinon.stub(process.stdout, 'write');
204203
var stdout = [];
205204

206-
var gather = function (chunk, enc, callback) {
205+
var gather = function (chunk) {
207206
stdout.push(chunk);
208207
if (tee) {
209208
origStdoutWrite.call(process.stdout, chunk);

‎test/reporters/nyan.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('Nyan reporter', function () {
161161

162162
beforeEach(function () {
163163
stdoutWriteStub = sinon.stub(process.stdout, 'write');
164-
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
164+
stdoutWriteStub.callsFake(function (chunk) {
165165
stdout.push(chunk);
166166
});
167167
stdout = [];
@@ -260,7 +260,7 @@ describe('Nyan reporter', function () {
260260

261261
beforeEach(function () {
262262
stdoutWriteStub = sinon.stub(process.stdout, 'write');
263-
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
263+
stdoutWriteStub.callsFake(function (chunk) {
264264
stdout.push(chunk);
265265
});
266266
stdout = [];
@@ -289,7 +289,7 @@ describe('Nyan reporter', function () {
289289

290290
beforeEach(function () {
291291
stdoutWriteStub = sinon.stub(process.stdout, 'write');
292-
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
292+
stdoutWriteStub.callsFake(function (chunk) {
293293
stdout.push(chunk);
294294
});
295295
stdout = [];
@@ -452,7 +452,7 @@ describe('Nyan reporter', function () {
452452
return type + n;
453453
});
454454
var stdoutWriteStub = sinon.stub(process.stdout, 'write');
455-
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
455+
stdoutWriteStub.callsFake(function (chunk) {
456456
stdout.push(chunk);
457457
});
458458
stdout = [];
@@ -521,7 +521,7 @@ describe('Nyan reporter', function () {
521521

522522
beforeEach(function () {
523523
var stdoutWriteStub = sinon.stub(process.stdout, 'write');
524-
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
524+
stdoutWriteStub.callsFake(function (chunk) {
525525
stdout.push(chunk);
526526
});
527527
stdout = [];

‎test/reporters/xunit.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('XUnit reporter', function () {
225225
}
226226
cb();
227227
}),
228-
write: function (chunk, encoding, cb) {}
228+
write: function () {}
229229
}
230230
};
231231
});
@@ -544,7 +544,7 @@ describe('XUnit reporter', function () {
544544

545545
before(function () {
546546
fileStream = {
547-
write: function (chunk, encoding, cb) {
547+
write: function (chunk) {
548548
lines.push(chunk);
549549
}
550550
};

‎test/unit/runnable.spec.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('Runnable(title, fn)', function () {
173173
var run;
174174

175175
beforeEach(function () {
176-
run = new Runnable('foo', function (done) {});
176+
run = new Runnable('foo', function () {});
177177
});
178178

179179
it('should be .async', function () {
@@ -387,7 +387,7 @@ describe('Runnable(title, fn)', function () {
387387
});
388388

389389
it('should not throw its own exception if passed a non-object', function (done) {
390-
var runnable = new Runnable('foo', function (done) {
390+
var runnable = new Runnable('foo', function () {
391391
/* eslint no-throw-literal: off */
392392
throw null;
393393
});
@@ -401,7 +401,7 @@ describe('Runnable(title, fn)', function () {
401401

402402
describe('when an exception is thrown and is allowed to remain uncaught', function () {
403403
it('throws an error when it is allowed', function (done) {
404-
var runnable = new Runnable('foo', function (done) {
404+
var runnable = new Runnable('foo', function () {
405405
throw new Error('fail');
406406
});
407407
runnable.allowUncaught = true;
@@ -465,7 +465,7 @@ describe('Runnable(title, fn)', function () {
465465

466466
it('should allow updating the timeout', function (done) {
467467
var spy = sinon.spy();
468-
var runnable = new Runnable('foo', function (done) {
468+
var runnable = new Runnable('foo', function () {
469469
setTimeout(spy, 1);
470470
setTimeout(spy, 100);
471471
});
@@ -509,7 +509,7 @@ describe('Runnable(title, fn)', function () {
509509

510510
describe('when the promise is fulfilled with a value', function () {
511511
var fulfilledPromise = {
512-
then: function (fulfilled, rejected) {
512+
then: function (fulfilled) {
513513
setTimeout(function () {
514514
fulfilled({});
515515
});
@@ -531,7 +531,7 @@ describe('Runnable(title, fn)', function () {
531531
describe('when the promise is rejected', function () {
532532
var expectedErr = new Error('fail');
533533
var rejectedPromise = {
534-
then: function (fulfilled, rejected) {
534+
then: function (_fulfilled, rejected) {
535535
setTimeout(function () {
536536
rejected(expectedErr);
537537
});
@@ -553,7 +553,7 @@ describe('Runnable(title, fn)', function () {
553553
describe('when the promise is rejected without a reason', function () {
554554
var expectedErr = new Error('Promise rejected with no or falsy reason');
555555
var rejectedPromise = {
556-
then: function (fulfilled, rejected) {
556+
then: function (_fulfilled, rejected) {
557557
setTimeout(function () {
558558
rejected();
559559
});
@@ -623,7 +623,7 @@ describe('Runnable(title, fn)', function () {
623623

624624
describe('if async', function () {
625625
it('this.skip() should set runnable to pending', function (done) {
626-
var runnable = new Runnable('foo', function (done) {
626+
var runnable = new Runnable('foo', function () {
627627
// normally "this" but it gets around having to muck with a context
628628
runnable.skip();
629629
});
@@ -636,7 +636,7 @@ describe('Runnable(title, fn)', function () {
636636

637637
it('this.skip() should halt synchronous execution', function (done) {
638638
var aborted = true;
639-
var runnable = new Runnable('foo', function (done) {
639+
var runnable = new Runnable('foo', function () {
640640
// normally "this" but it gets around having to muck with a context
641641
runnable.skip();
642642
/* istanbul ignore next */

‎test/unit/runner.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ describe('Runner', function () {
879879
it('async - should allow unhandled errors in hooks to propagate through', function (done) {
880880
// the `done` argument, although unused, it triggers the async path
881881
// see this.async in the Runnable constructor
882-
suite.beforeEach(function (done) {
882+
suite.beforeEach(function () {
883883
throw new Error('allow unhandled errors in async hooks');
884884
});
885885
var runner = new Runner(suite);
@@ -1045,7 +1045,7 @@ describe('Runner', function () {
10451045
function () {
10461046
try {
10471047
runner.uncaught(err);
1048-
} catch (ignored) {}
1048+
} catch {}
10491049
},
10501050
'not to emit from',
10511051
runner,

‎test/unit/throw.spec.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('a test that throws', function () {
3030
uncaughtHandlers.forEach(function (listener) {
3131
process.on('uncaughtException', listener);
3232
});
33-
sinon.restore();
33+
sinon.restore();
3434
});
3535

3636
describe('non-extensible', function () {
@@ -49,7 +49,7 @@ describe('a test that throws', function () {
4949
});
5050

5151
it('should not pass if throwing sync and test is async', function (done) {
52-
var test = new Test('im async and throw string sync', function (done2) {
52+
var test = new Test('im async and throw string sync', function () {
5353
throw 'non-extensible';
5454
});
5555
suite.addTest(test);
@@ -63,7 +63,7 @@ describe('a test that throws', function () {
6363
});
6464

6565
it('should not pass if throwing async and test is async', function (done) {
66-
var test = new Test('im async and throw string async', function (done2) {
66+
var test = new Test('im async and throw string async', function () {
6767
process.nextTick(function () {
6868
throw 'non-extensible';
6969
});
@@ -95,9 +95,7 @@ describe('a test that throws', function () {
9595
});
9696

9797
it('should not pass if throwing sync and test is async', function (done) {
98-
var test = new Test('im async and throw undefined sync', function (
99-
done2
100-
) {
98+
var test = new Test('im async and throw undefined sync', function () {
10199
throw undefined;
102100
});
103101
suite.addTest(test);
@@ -111,9 +109,7 @@ describe('a test that throws', function () {
111109
});
112110

113111
it('should not pass if throwing async and test is async', function (done) {
114-
var test = new Test('im async and throw undefined async', function (
115-
done2
116-
) {
112+
var test = new Test('im async and throw undefined async', function () {
117113
process.nextTick(function () {
118114
throw undefined;
119115
});
@@ -145,7 +141,7 @@ describe('a test that throws', function () {
145141
});
146142

147143
it('should not pass if throwing sync and test is async', function (done) {
148-
var test = new Test('im async and throw null sync', function (done2) {
144+
var test = new Test('im async and throw null sync', function () {
149145
throw null;
150146
});
151147
suite.addTest(test);
@@ -159,7 +155,7 @@ describe('a test that throws', function () {
159155
});
160156

161157
it('should not pass if throwing async and test is async', function (done) {
162-
var test = new Test('im async and throw null async', function (done2) {
158+
var test = new Test('im async and throw null async', function () {
163159
process.nextTick(function () {
164160
throw null;
165161
});
@@ -175,9 +171,9 @@ describe('a test that throws', function () {
175171
});
176172
});
177173

178-
describe('stack', function() {
174+
describe('stack', function () {
179175
it('should include the stack when throwing async', function(done) {
180-
var test = new Test('im async and throw null async', function(done2) {
176+
var test = new Test('im async and throw null async', function() {
181177
process.nextTick(function throwError() {
182178
throw new Error('test error');
183179
});

0 commit comments

Comments
 (0)
Please sign in to comment.