Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: enabled ESLint's no-unused-vars
  • Loading branch information
JoshuaKGoldberg committed Jul 3, 2025
commit ae2bb9ce676895ee69d4924db1d51a4353676deb
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ module.exports = [
rules: {
'n/prefer-node-protocol': 'error',
strict: ['error', 'global'],
'no-unused-vars': 'error',

'no-var': 'off',
'n/no-process-exit': 'off',
'n/no-unpublished-require': 'off',
'n/no-unsupported-features/node-builtins': 'off',
Expand Down
1 change: 0 additions & 1 deletion lib/cli/collect-files.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const fs = require('node:fs');
const path = require('node:path');
const pc = require('picocolors');
const debug = require('debug')('mocha:cli:run:helpers');
Expand Down
1 change: 0 additions & 1 deletion lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const {format} = require('node:util');
const {createInvalidLegacyPluginError} = require('../errors');
const {requireOrImport} = require('../nodejs/esm-utils');
const PluginLoader = require('../plugin-loader');
const {UnmatchedFile} = require('./collect-files');

/**
* Exits Mocha when tests + code under test has finished execution (default)
Expand Down
3 changes: 1 addition & 2 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,9 @@ function createTimeoutError(msg, timeout, file) {
* @public
* @static
* @param {string} message - Error message to be displayed.
* @param {string} filename - File name
* @returns {Error} Error with code {@link constants.UNPARSABLE_FILE}
*/
function createUnparsableFileError(message, filename) {
function createUnparsableFileError(message) {
var err = new Error(message);
err.code = constants.UNPARSABLE_FILE;
return err;
Expand Down
1 change: 0 additions & 1 deletion lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ function HTML(runner, options) {
items[progressIndex].getElementsByClassName('ring-flatlight')[0],
items[progressIndex].getElementsByClassName('ring-highlight')[0]
];
var progressRingRadius = null; // computed CSS unavailable now, so set later
var root = document.getElementById('mocha');

if (!root) {
Expand Down
5 changes: 2 additions & 3 deletions lib/reporters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function title(test) {
* @param {string} format - `printf`-like format string
* @param {...*} [varArgs] - Format string arguments
*/
function println(format, varArgs) {
function println() {
var vargs = Array.from(arguments);
vargs[0] += '\n';
process.stdout.write(sprintf.apply(null, vargs));
Expand Down Expand Up @@ -184,9 +184,8 @@ TAPProducer.prototype.writePending = function (n, test) {
* @abstract
* @param {number} n - Index of test that failed.
* @param {Test} test - Instance containing test information.
* @param {Error} err - Reason the test failed.
*/
TAPProducer.prototype.writeFail = function (n, test, err) {
TAPProducer.prototype.writeFail = function (n, test) {
println('not ok %d %s', n, title(test));
};

Expand Down
2 changes: 1 addition & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ Runner.prototype.run = function (fn, opts = {}) {
* }
* }
*/
Runner.prototype.linkPartialObjects = function (value) {
Runner.prototype.linkPartialObjects = function () {
return this;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ exports.noop = function () {};
* @param {...*} [obj] - Arguments to `Object.assign()`.
* @returns {Object} An object with no prototype, having `...obj` properties
*/
exports.createMap = function (obj) {
exports.createMap = function () {
return Object.assign.apply(
null,
[Object.create(null)].concat(Array.prototype.slice.call(arguments))
Expand Down
2 changes: 1 addition & 1 deletion test/integration/hook-err.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function onlyConsoleOutput() {
};
}

function onlyErrorTitle(line) {
function onlyErrorTitle() {
let foundErrorTitle = false;
let foundError = false;
return line => {
Expand Down
1 change: 0 additions & 1 deletion test/integration/options/posixExitCodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var helpers = require('../helpers');
var runMocha = helpers.runMocha;
var os = require('node:os');

const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;
const SIGNAL_OFFSET = 128;

Expand Down
2 changes: 1 addition & 1 deletion test/integration/reporters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('reporters', function () {
'</testsuite>'
];

run('passing.fixture.js', args, function (err, result) {
run('passing.fixture.js', args, function (err) {
if (err) return done(err);

var xml = fs.readFileSync(tmpFile, 'utf8');
Expand Down
8 changes: 4 additions & 4 deletions test/reporters/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Base reporter', function () {
return diffStr;
}

var gather = function (chunk, encoding, cb) {
var gather = function (chunk) {
stdout.push(chunk);
};

Expand Down Expand Up @@ -524,14 +524,14 @@ describe('Base reporter', function () {
var err1 = {
message: 'Error',
stack: 'Error\nfoo\nbar',
showDiff: false,
showDiff: false
};
var err2 = {
message: 'Cause1',
stack: 'Cause1\nbar\nfoo',
showDiff: false,
cause: err1
}
};
err1.cause = err2;

var test = makeTest(err1);
Expand All @@ -552,7 +552,7 @@ describe('Base reporter', function () {
stack: 'Error\nfoo\nbar',
showDiff: false,
cause: {
showDiff: false,
showDiff: false
}
};

Expand Down
5 changes: 2 additions & 3 deletions test/reporters/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ function makeExpectedTest(
expectedFullTitle,
expectedFile,
expectedDuration,
currentRetry,
expectedBody
currentRetry
) {
return {
title: expectedTitle,
Expand Down Expand Up @@ -203,7 +202,7 @@ function createRunReporterFunction(ctor) {
var stdoutWriteStub = sinon.stub(process.stdout, 'write');
var stdout = [];

var gather = function (chunk, enc, callback) {
var gather = function (chunk) {
stdout.push(chunk);
if (tee) {
origStdoutWrite.call(process.stdout, chunk);
Expand Down
10 changes: 5 additions & 5 deletions test/reporters/nyan.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('Nyan reporter', function () {

beforeEach(function () {
stdoutWriteStub = sinon.stub(process.stdout, 'write');
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
stdoutWriteStub.callsFake(function (chunk) {
stdout.push(chunk);
});
stdout = [];
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('Nyan reporter', function () {

beforeEach(function () {
stdoutWriteStub = sinon.stub(process.stdout, 'write');
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
stdoutWriteStub.callsFake(function (chunk) {
stdout.push(chunk);
});
stdout = [];
Expand Down Expand Up @@ -289,7 +289,7 @@ describe('Nyan reporter', function () {

beforeEach(function () {
stdoutWriteStub = sinon.stub(process.stdout, 'write');
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
stdoutWriteStub.callsFake(function (chunk) {
stdout.push(chunk);
});
stdout = [];
Expand Down Expand Up @@ -452,7 +452,7 @@ describe('Nyan reporter', function () {
return type + n;
});
var stdoutWriteStub = sinon.stub(process.stdout, 'write');
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
stdoutWriteStub.callsFake(function (chunk) {
stdout.push(chunk);
});
stdout = [];
Expand Down Expand Up @@ -521,7 +521,7 @@ describe('Nyan reporter', function () {

beforeEach(function () {
var stdoutWriteStub = sinon.stub(process.stdout, 'write');
stdoutWriteStub.callsFake(function (chunk, encoding, cb) {
stdoutWriteStub.callsFake(function (chunk) {
stdout.push(chunk);
});
stdout = [];
Expand Down
4 changes: 2 additions & 2 deletions test/reporters/xunit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('XUnit reporter', function () {
}
cb();
}),
write: function (chunk, encoding, cb) {}
write: function () {}
}
};
});
Expand Down Expand Up @@ -544,7 +544,7 @@ describe('XUnit reporter', function () {

before(function () {
fileStream = {
write: function (chunk, encoding, cb) {
write: function (chunk) {
lines.push(chunk);
}
};
Expand Down
14 changes: 9 additions & 5 deletions test/unit/runnable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ describe('Runnable(title, fn)', function () {
var run;

beforeEach(function () {
// Runnable knows whether it's provided a 'done' parameter
// eslint-disable-next-line no-unused-vars
run = new Runnable('foo', function (done) {});
});

Expand Down Expand Up @@ -387,7 +389,7 @@ describe('Runnable(title, fn)', function () {
});

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

describe('when an exception is thrown and is allowed to remain uncaught', function () {
it('throws an error when it is allowed', function (done) {
var runnable = new Runnable('foo', function (done) {
var runnable = new Runnable('foo', function () {
throw new Error('fail');
});
runnable.allowUncaught = true;
Expand Down Expand Up @@ -465,6 +467,8 @@ describe('Runnable(title, fn)', function () {

it('should allow updating the timeout', function (done) {
var spy = sinon.spy();
// Runnable knows whether it's provided a 'done' parameter
// eslint-disable-next-line no-unused-vars
var runnable = new Runnable('foo', function (done) {
setTimeout(spy, 1);
setTimeout(spy, 100);
Expand Down Expand Up @@ -509,7 +513,7 @@ describe('Runnable(title, fn)', function () {

describe('when the promise is fulfilled with a value', function () {
var fulfilledPromise = {
then: function (fulfilled, rejected) {
then: function (fulfilled) {
setTimeout(function () {
fulfilled({});
});
Expand Down Expand Up @@ -623,7 +627,7 @@ describe('Runnable(title, fn)', function () {

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

it('this.skip() should halt synchronous execution', function (done) {
var aborted = true;
var runnable = new Runnable('foo', function (done) {
var runnable = new Runnable('foo', function () {
// normally "this" but it gets around having to muck with a context
runnable.skip();
/* istanbul ignore next */
Expand Down
2 changes: 1 addition & 1 deletion test/unit/runner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ describe('Runner', function () {
it('async - should allow unhandled errors in hooks to propagate through', function (done) {
// the `done` argument, although unused, it triggers the async path
// see this.async in the Runnable constructor
suite.beforeEach(function (done) {
suite.beforeEach(function () {
throw new Error('allow unhandled errors in async hooks');
});
var runner = new Runner(suite);
Expand Down
26 changes: 11 additions & 15 deletions test/unit/throw.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('a test that throws', function () {
uncaughtHandlers.forEach(function (listener) {
process.on('uncaughtException', listener);
});
sinon.restore();
sinon.restore();
});

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

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

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

it('should not pass if throwing sync and test is async', function (done) {
var test = new Test('im async and throw undefined sync', function (
done2
) {
var test = new Test('im async and throw undefined sync', function () {
throw undefined;
});
suite.addTest(test);
Expand All @@ -111,9 +109,7 @@ describe('a test that throws', function () {
});

it('should not pass if throwing async and test is async', function (done) {
var test = new Test('im async and throw undefined async', function (
done2
) {
var test = new Test('im async and throw undefined async', function () {
process.nextTick(function () {
throw undefined;
});
Expand Down Expand Up @@ -145,7 +141,7 @@ describe('a test that throws', function () {
});

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

it('should not pass if throwing async and test is async', function (done) {
var test = new Test('im async and throw null async', function (done2) {
var test = new Test('im async and throw null async', function () {
process.nextTick(function () {
throw null;
});
Expand All @@ -175,9 +171,9 @@ describe('a test that throws', function () {
});
});

describe('stack', function() {
it('should include the stack when throwing async', function(done) {
var test = new Test('im async and throw null async', function(done2) {
describe('stack', function () {
it('should include the stack when throwing async', function (done) {
var test = new Test('im async and throw null async', function () {
process.nextTick(function throwError() {
throw new Error('test error');
});
Expand All @@ -186,7 +182,7 @@ describe('a test that throws', function () {
runner = new Runner(suite);
sinon.stub(runner, 'fail');

runner.on(EVENT_RUN_END, function() {
runner.on(EVENT_RUN_END, function () {
try {
expect(runner.fail, 'to have all calls satisfying', [
expect.it('to be a', Runnable),
Expand Down