diff --git a/docs/_data/supporters.js b/docs/_data/supporters.js index 21d950d1d3..b0e5640d4d 100755 --- a/docs/_data/supporters.js +++ b/docs/_data/supporters.js @@ -139,6 +139,7 @@ const getAllOrders = async (slug = 'mochajs') => { const variables = {limit: GRAPHQL_PAGE_SIZE, offset: 0, slug}; // Handling pagination if necessary (2 pages for ~1400 results in May 2019) + // eslint-disable-next-line no-constant-condition while (true) { const result = await needle( 'post', diff --git a/eslint.config.js b/eslint.config.js index 4448037012..5e8a99cbb3 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -9,8 +9,8 @@ const messages = { }; module.exports = [ + js.configs.recommended, { - ...js.configs.recommended, languageOptions: { ecmaVersion: 2020, globals: { @@ -20,6 +20,8 @@ module.exports = [ sourceType: 'script' }, rules: { + 'no-empty': 'off', + 'no-redeclare': 'off', 'no-var': 'off', strict: ['error', 'global'] } diff --git a/lib/cli/collect-files.js b/lib/cli/collect-files.js index 73f5d2e95a..081267bce7 100644 --- a/lib/cli/collect-files.js +++ b/lib/cli/collect-files.js @@ -1,6 +1,5 @@ 'use strict'; -const fs = require('fs'); const path = require('path'); const ansi = require('ansi-colors'); const debug = require('debug')('mocha:cli:run:helpers'); diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index ec65829f14..ca9e61285a 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -17,7 +17,6 @@ const {format} = require('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) diff --git a/lib/errors.js b/lib/errors.js index bcc7291c99..1c163e449b 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -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; diff --git a/lib/reporters/html.js b/lib/reporters/html.js index 5f57279ec2..12880130e3 100644 --- a/lib/reporters/html.js +++ b/lib/reporters/html.js @@ -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) { diff --git a/lib/reporters/tap.js b/lib/reporters/tap.js index 37fa8b57a0..80e28d9a74 100644 --- a/lib/reporters/tap.js +++ b/lib/reporters/tap.js @@ -94,10 +94,9 @@ function title(test) { * Writes newline-terminated formatted string to reporter output stream. * * @private - * @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)); @@ -184,9 +183,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)); }; diff --git a/lib/runner.js b/lib/runner.js index ad31843444..a3b5d7c1db 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -1110,7 +1110,6 @@ Runner.prototype.run = function (fn, opts = {}) { * unique ID's. Does nothing in serial mode, because the object references already exist. * Subclasses can implement this (e.g., `ParallelBufferedRunner`) * @abstract - * @param {boolean} [value] - If `true`, enable partial object linking, otherwise disable * @returns {Runner} * @chainable * @public @@ -1128,7 +1127,7 @@ Runner.prototype.run = function (fn, opts = {}) { * } * } */ -Runner.prototype.linkPartialObjects = function (value) { +Runner.prototype.linkPartialObjects = function () { return this; }; diff --git a/lib/utils.js b/lib/utils.js index 89b21a32d6..bdedc491f5 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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)) diff --git a/test/integration/hook-err.spec.js b/test/integration/hook-err.spec.js index 373d1b6a61..eee7d98027 100644 --- a/test/integration/hook-err.spec.js +++ b/test/integration/hook-err.spec.js @@ -292,7 +292,7 @@ function onlyConsoleOutput() { }; } -function onlyErrorTitle(line) { +function onlyErrorTitle() { let foundErrorTitle = false; let foundError = false; return line => { diff --git a/test/integration/init.spec.js b/test/integration/init.spec.js index d19f42a0b4..706b861761 100644 --- a/test/integration/init.spec.js +++ b/test/integration/init.spec.js @@ -13,14 +13,14 @@ describe('init command', function () { tmpdir = path.join(os.tmpdir(), 'mocha-init'); try { fs.mkdirSync(tmpdir); - } catch (ignored) {} + } catch {} expect(fs.existsSync(tmpdir), 'to be true'); }); afterEach(function () { try { rimraf.sync(tmpdir); - } catch (ignored) {} + } catch {} }); describe('when no path is supplied', function () { diff --git a/test/integration/options/parallel.spec.js b/test/integration/options/parallel.spec.js index 825ef150be..96e1b09375 100644 --- a/test/integration/options/parallel.spec.js +++ b/test/integration/options/parallel.spec.js @@ -510,7 +510,7 @@ describe('--parallel', function () { let pids = null; try { pids = await pidtree(childPid, {root: true}); - } catch (ignored) {} + } catch {} return pids; }) ), @@ -536,7 +536,7 @@ describe('--parallel', function () { let pids = null; try { pids = await pidtree(childPid, {root: true}); - } catch (ignored) {} + } catch {} return pids; }) ), diff --git a/test/integration/reporters.spec.js b/test/integration/reporters.spec.js index 9285dfe80c..39acce46b7 100644 --- a/test/integration/reporters.spec.js +++ b/test/integration/reporters.spec.js @@ -49,7 +49,7 @@ describe('reporters', function () { '' ]; - 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'); diff --git a/test/node-unit/cli/options.spec.js b/test/node-unit/cli/options.spec.js index f5ce73da15..99467633cb 100644 --- a/test/node-unit/cli/options.spec.js +++ b/test/node-unit/cli/options.spec.js @@ -344,14 +344,14 @@ describe('options', function () { it('should not look for a config', function () { try { loadOptions(`--config ${config}`); - } catch (ignored) {} + } catch {} expect(findConfig, 'was not called'); }); it('should attempt to load file at path', function () { try { loadOptions(`--config ${config}`); - } catch (ignored) {} + } catch {} expect(loadConfig, 'to have a call satisfying', [config]); }); diff --git a/test/reporters/base.spec.js b/test/reporters/base.spec.js index 84778f3693..9a93cb1ab3 100644 --- a/test/reporters/base.spec.js +++ b/test/reporters/base.spec.js @@ -37,7 +37,7 @@ describe('Base reporter', function () { return diffStr; } - var gather = function (chunk, encoding, cb) { + var gather = function (chunk) { stdout.push(chunk); }; @@ -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); @@ -552,7 +552,7 @@ describe('Base reporter', function () { stack: 'Error\nfoo\nbar', showDiff: false, cause: { - showDiff: false, + showDiff: false } }; diff --git a/test/reporters/helpers.js b/test/reporters/helpers.js index 7159824c56..927252042e 100644 --- a/test/reporters/helpers.js +++ b/test/reporters/helpers.js @@ -165,8 +165,7 @@ function makeExpectedTest( expectedFullTitle, expectedFile, expectedDuration, - currentRetry, - expectedBody + currentRetry ) { return { title: expectedTitle, @@ -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); diff --git a/test/reporters/nyan.spec.js b/test/reporters/nyan.spec.js index 7d405e4542..faed258891 100644 --- a/test/reporters/nyan.spec.js +++ b/test/reporters/nyan.spec.js @@ -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 = []; @@ -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 = []; @@ -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 = []; @@ -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 = []; @@ -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 = []; diff --git a/test/reporters/xunit.spec.js b/test/reporters/xunit.spec.js index 4e98cf6002..a8e2d42584 100644 --- a/test/reporters/xunit.spec.js +++ b/test/reporters/xunit.spec.js @@ -225,7 +225,7 @@ describe('XUnit reporter', function () { } cb(); }), - write: function (chunk, encoding, cb) {} + write: function () {} } }; }); @@ -544,7 +544,7 @@ describe('XUnit reporter', function () { before(function () { fileStream = { - write: function (chunk, encoding, cb) { + write: function (chunk) { lines.push(chunk); } }; diff --git a/test/unit/runnable.spec.js b/test/unit/runnable.spec.js index 598f532f80..776a0c294e 100644 --- a/test/unit/runnable.spec.js +++ b/test/unit/runnable.spec.js @@ -173,7 +173,7 @@ describe('Runnable(title, fn)', function () { var run; beforeEach(function () { - run = new Runnable('foo', function (done) {}); + run = new Runnable('foo', function () {}); }); it('should be .async', function () { @@ -387,7 +387,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; }); @@ -401,7 +401,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; @@ -465,7 +465,7 @@ describe('Runnable(title, fn)', function () { it('should allow updating the timeout', function (done) { var spy = sinon.spy(); - var runnable = new Runnable('foo', function (done) { + var runnable = new Runnable('foo', function () { setTimeout(spy, 1); setTimeout(spy, 100); }); @@ -509,7 +509,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({}); }); @@ -531,7 +531,7 @@ describe('Runnable(title, fn)', function () { describe('when the promise is rejected', function () { var expectedErr = new Error('fail'); var rejectedPromise = { - then: function (fulfilled, rejected) { + then: function (_fulfilled, rejected) { setTimeout(function () { rejected(expectedErr); }); @@ -553,7 +553,7 @@ describe('Runnable(title, fn)', function () { describe('when the promise is rejected without a reason', function () { var expectedErr = new Error('Promise rejected with no or falsy reason'); var rejectedPromise = { - then: function (fulfilled, rejected) { + then: function (_fulfilled, rejected) { setTimeout(function () { rejected(); }); @@ -623,7 +623,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(); }); @@ -636,7 +636,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 */ diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js index 66ca6a0532..646b5013c4 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -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); @@ -1045,7 +1045,7 @@ describe('Runner', function () { function () { try { runner.uncaught(err); - } catch (ignored) {} + } catch {} }, 'not to emit from', runner, diff --git a/test/unit/throw.spec.js b/test/unit/throw.spec.js index cafadaa4bc..19e83cb571 100644 --- a/test/unit/throw.spec.js +++ b/test/unit/throw.spec.js @@ -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 () { @@ -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); @@ -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'; }); @@ -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); @@ -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; }); @@ -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); @@ -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; }); @@ -175,9 +171,9 @@ describe('a test that throws', function () { }); }); - describe('stack', 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) { + var test = new Test('im async and throw null async', function() { process.nextTick(function throwError() { throw new Error('test error'); });