Skip to content

Commit

Permalink
chore: enable ESLint's recommended JS rules
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Jan 2, 2025
1 parent 3c191c0 commit 54695d8
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 59 deletions.
1 change: 1 addition & 0 deletions docs/_data/supporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const messages = {
};

module.exports = [
js.configs.recommended,
{
...js.configs.recommended,
languageOptions: {
ecmaVersion: 2020,
globals: {
Expand All @@ -20,6 +20,8 @@ module.exports = [
sourceType: 'script'
},
rules: {
'no-empty': 'off',
'no-redeclare': 'off',
'no-var': 'off',
strict: ['error', 'global']
}
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('fs');
const path = require('path');
const ansi = require('ansi-colors');
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('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
6 changes: 2 additions & 4 deletions lib/reporters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
};

Expand Down
3 changes: 1 addition & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1128,7 +1127,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
4 changes: 2 additions & 2 deletions test/integration/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/options/parallel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ describe('--parallel', function () {
let pids = null;
try {
pids = await pidtree(childPid, {root: true});
} catch (ignored) {}
} catch {}
return pids;
})
),
Expand All @@ -536,7 +536,7 @@ describe('--parallel', function () {
let pids = null;
try {
pids = await pidtree(childPid, {root: true});
} catch (ignored) {}
} catch {}
return pids;
})
),
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
4 changes: 2 additions & 2 deletions test/node-unit/cli/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});

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
18 changes: 9 additions & 9 deletions test/unit/runnable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;
});
Expand All @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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({});
});
Expand All @@ -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);
});
Expand All @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand All @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -1045,7 +1045,7 @@ describe('Runner', function () {
function () {
try {
runner.uncaught(err);
} catch (ignored) {}
} catch {}
},
'not to emit from',
runner,
Expand Down
Loading

0 comments on commit 54695d8

Please sign in to comment.