Updated to eslint 9

This isn't officially compatible with the oldest version of Node that
Jasmine supports, but it works. If it stops working, we can always disable
linting in CI builds on older Node versions.
This commit is contained in:
Steve Gravrock
2025-04-07 21:08:29 -07:00
parent 7b2ab822c6
commit 5ff7e7f9a1
20 changed files with 80 additions and 36 deletions
+1 -1
View File
@@ -3,6 +3,6 @@ charset = utf-8
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
[*.{js, json, sh, yml}] [*.{js, mjs, json, sh, yml}]
indent_style = space indent_style = space
indent_size = 2 indent_size = 2
+54
View File
@@ -0,0 +1,54 @@
import { defineConfig } from "eslint/config";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
export default defineConfig([{
extends: compat.extends("plugin:compat/recommended"),
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
ecmaVersion: 2018,
sourceType: "commonjs",
},
rules: {
curly: "error",
quotes: ["error", "single", {
avoidEscape: true,
}],
"no-unused-vars": ["error", {
args: "none",
}],
"no-implicit-globals": "error",
"block-spacing": "error",
"func-call-spacing": ["error", "never"],
"key-spacing": "error",
"no-tabs": "error",
"no-trailing-spaces": "error",
"no-whitespace-before-property": "error",
semi: ["error", "always"],
"space-before-blocks": "error",
"no-eval": "error",
"no-var": "error",
"no-debugger": "error",
"no-console": "error",
},
}]);
+5 -2
View File
@@ -34,9 +34,12 @@
"package.json" "package.json"
], ],
"devDependencies": { "devDependencies": {
"eslint": "^8.36.0", "@eslint/eslintrc": "^3.3.1",
"eslint-plugin-compat": "^4.0.0", "@eslint/js": "^9.24.0",
"eslint": "^9.24.0",
"eslint-plugin-compat": "^6.0.2",
"glob": "^10.2.3", "glob": "^10.2.3",
"globals": "^16.0.0",
"grunt": "^1.0.4", "grunt": "^1.0.4",
"grunt-cli": "^1.3.2", "grunt-cli": "^1.3.2",
"grunt-contrib-compress": "^2.0.0", "grunt-contrib-compress": "^2.0.0",
-1
View File
@@ -205,7 +205,6 @@ describe('Env', function() {
it('throws an error when given arguments', function() { it('throws an error when given arguments', function() {
expect(function() { expect(function() {
// eslint-disable-next-line no-unused-vars
env.describe('done method', function(done) {}); env.describe('done method', function(done) {});
}).toThrowError('describe does not expect any arguments'); }).toThrowError('describe does not expect any arguments');
}); });
-8
View File
@@ -239,7 +239,6 @@ describe('QueueRunner', function() {
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() { it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
const timeout = 3, const timeout = 3,
// eslint-disable-next-line no-unused-vars
beforeFn = { fn: function(done) {}, type: 'before', timeout: timeout }, beforeFn = { fn: function(done) {}, type: 'before', timeout: timeout },
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' }, queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
onComplete = jasmine.createSpy('onComplete'), onComplete = jasmine.createSpy('onComplete'),
@@ -287,7 +286,6 @@ describe('QueueRunner', function() {
}); });
it('by default does not set a timeout for asynchronous functions', function() { it('by default does not set a timeout for asynchronous functions', function() {
// eslint-disable-next-line no-unused-vars
const beforeFn = { fn: function(done) {} }, const beforeFn = { fn: function(done) {} },
queueableFn = { fn: jasmine.createSpy('fn') }, queueableFn = { fn: jasmine.createSpy('fn') },
onComplete = jasmine.createSpy('onComplete'), onComplete = jasmine.createSpy('onComplete'),
@@ -310,7 +308,6 @@ describe('QueueRunner', function() {
it('clears the timeout when an async function throws an exception, to prevent additional exception reporting', function() { it('clears the timeout when an async function throws an exception, to prevent additional exception reporting', function() {
const queueableFn = { const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) { fn: function(done) {
throw new Error('error!'); throw new Error('error!');
} }
@@ -409,7 +406,6 @@ describe('QueueRunner', function() {
it('continues running functions when an exception is thrown in async code without timing out', function() { it('continues running functions when an exception is thrown in async code without timing out', function() {
const queueableFn = { const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) { fn: function(done) {
throwAsync(); throwAsync();
}, },
@@ -461,7 +457,6 @@ describe('QueueRunner', function() {
it('handles a global error event with a message but no error', function() { it('handles a global error event with a message but no error', function() {
const queueableFn = { const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) { fn: function(done) {
const currentHandler = globalErrors.pushListener.calls.mostRecent() const currentHandler = globalErrors.pushListener.calls.mostRecent()
.args[0]; .args[0];
@@ -641,7 +636,6 @@ describe('QueueRunner', function() {
it('issues an error if the function also takes a parameter', function() { it('issues an error if the function also takes a parameter', function() {
const queueableFn = { const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) { fn: function(done) {
return new StubPromise(); return new StubPromise();
} }
@@ -666,7 +660,6 @@ describe('QueueRunner', function() {
}); });
it('issues a more specific error if the function is `async`', function() { it('issues a more specific error if the function is `async`', function() {
// eslint-disable-next-line no-unused-vars
async function fn(done) {} async function fn(done) {}
const onException = jasmine.createSpy('onException'), const onException = jasmine.createSpy('onException'),
queueRunner = new jasmineUnderTest.QueueRunner({ queueRunner = new jasmineUnderTest.QueueRunner({
@@ -720,7 +713,6 @@ describe('QueueRunner', function() {
it('continues running the functions even after an exception is thrown in an async spec', function() { it('continues running the functions even after an exception is thrown in an async spec', function() {
const queueableFn = { const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) { fn: function(done) {
throw new Error('error'); throw new Error('error');
} }
-6
View File
@@ -97,17 +97,11 @@ describe('Spies', function() {
it('preserves arity of original function', function() { it('preserves arity of original function', function() {
const functions = [ const functions = [
function nullary() {}, function nullary() {},
// eslint-disable-next-line no-unused-vars
function unary(arg) {}, function unary(arg) {},
// eslint-disable-next-line no-unused-vars
function binary(arg1, arg2) {}, function binary(arg1, arg2) {},
// eslint-disable-next-line no-unused-vars
function ternary(arg1, arg2, arg3) {}, function ternary(arg1, arg2, arg3) {},
// eslint-disable-next-line no-unused-vars
function quaternary(arg1, arg2, arg3, arg4) {}, function quaternary(arg1, arg2, arg3, arg4) {},
// eslint-disable-next-line no-unused-vars
function quinary(arg1, arg2, arg3, arg4, arg5) {}, function quinary(arg1, arg2, arg3, arg4, arg5) {},
// eslint-disable-next-line no-unused-vars
function senary(arg1, arg2, arg3, arg4, arg5, arg6) {} function senary(arg1, arg2, arg3, arg4, arg5, arg6) {}
]; ];
+5 -9
View File
@@ -1071,7 +1071,6 @@ describe('Env integration', function() {
env.describe('my suite', function() { env.describe('my suite', function() {
env.it('my spec', function() {}); env.it('my spec', function() {});
// eslint-disable-next-line no-unused-vars
env.afterAll(function(afterAllDone) { env.afterAll(function(afterAllDone) {
throw error; throw error;
}); });
@@ -1569,7 +1568,6 @@ describe('Env integration', function() {
env.addReporter(reporter); env.addReporter(reporter);
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 8414; jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 8414;
// eslint-disable-next-line no-unused-vars
env.it("async spec that doesn't call done", function(underTestCallback) { env.it("async spec that doesn't call done", function(underTestCallback) {
env.expect(true).toBeTruthy(); env.expect(true).toBeTruthy();
jasmine.clock().tick(8416); jasmine.clock().tick(8416);
@@ -1642,13 +1640,13 @@ describe('Env integration', function() {
realSetTimeout(function() { realSetTimeout(function() {
try { try {
jasmine.clock().tick(10); jasmine.clock().tick(10);
// eslint-disable-next-line no-unused-vars
} catch (e) { } catch (e) {
// don't worry if the clock is already uninstalled // don't worry if the clock is already uninstalled
} }
}, 100); }, 100);
}); });
env.describe('beforeAll', function() { env.describe('beforeAll', function() {
// eslint-disable-next-line no-unused-vars
env.beforeAll(function(innerDone) { env.beforeAll(function(innerDone) {
realSetTimeout(function() { realSetTimeout(function() {
jasmine.clock().tick(5001); jasmine.clock().tick(5001);
@@ -1664,7 +1662,6 @@ describe('Env integration', function() {
}); });
env.describe('afterAll', function() { env.describe('afterAll', function() {
// eslint-disable-next-line no-unused-vars
env.afterAll(function(innerDone) { env.afterAll(function(innerDone) {
realSetTimeout(function() { realSetTimeout(function() {
jasmine.clock().tick(2001); jasmine.clock().tick(2001);
@@ -1680,7 +1677,6 @@ describe('Env integration', function() {
}); });
env.describe('beforeEach', function() { env.describe('beforeEach', function() {
// eslint-disable-next-line no-unused-vars
env.beforeEach(function(innerDone) { env.beforeEach(function(innerDone) {
realSetTimeout(function() { realSetTimeout(function() {
jasmine.clock().tick(1001); jasmine.clock().tick(1001);
@@ -1696,7 +1692,6 @@ describe('Env integration', function() {
}); });
env.describe('afterEach', function() { env.describe('afterEach', function() {
// eslint-disable-next-line no-unused-vars
env.afterEach(function(innerDone) { env.afterEach(function(innerDone) {
realSetTimeout(function() { realSetTimeout(function() {
jasmine.clock().tick(4001); jasmine.clock().tick(4001);
@@ -1713,7 +1708,6 @@ describe('Env integration', function() {
env.it( env.it(
'it times out', 'it times out',
// eslint-disable-next-line no-unused-vars
function(innerDone) { function(innerDone) {
realSetTimeout(function() { realSetTimeout(function() {
jasmine.clock().tick(6001); jasmine.clock().tick(6001);
@@ -2699,7 +2693,6 @@ describe('Env integration', function() {
env.addReporter(reporter); env.addReporter(reporter);
env.describe('async suite', function() { env.describe('async suite', function() {
// eslint-disable-next-line no-unused-vars
env.afterAll(function(innerDone) { env.afterAll(function(innerDone) {
setTimeout(function() { setTimeout(function() {
throw new Error('suite'); throw new Error('suite');
@@ -2712,7 +2705,6 @@ describe('Env integration', function() {
env.describe('suite', function() { env.describe('suite', function() {
env.it( env.it(
'async spec', 'async spec',
// eslint-disable-next-line no-unused-vars
function(innerDone) { function(innerDone) {
setTimeout(function() { setTimeout(function() {
throw new Error('spec'); throw new Error('spec');
@@ -4362,6 +4354,7 @@ describe('Env integration', function() {
env.it('a spec', function() { env.it('a spec', function() {
try { try {
env.throwUnless(1).toEqual(1); env.throwUnless(1).toEqual(1);
// eslint-disable-next-line no-unused-vars
} catch (e) { } catch (e) {
threw = true; threw = true;
} }
@@ -4375,6 +4368,7 @@ describe('Env integration', function() {
env.it('a spec', function() { env.it('a spec', function() {
try { try {
env.throwUnless(1).toEqual(2); env.throwUnless(1).toEqual(2);
// eslint-disable-next-line no-unused-vars
} catch (e) {} } catch (e) {}
}); });
@@ -4418,6 +4412,7 @@ describe('Env integration', function() {
env.it('a spec', async function() { env.it('a spec', async function() {
try { try {
await env.throwUnlessAsync(Promise.resolve()).toBeResolved(); await env.throwUnlessAsync(Promise.resolve()).toBeResolved();
// eslint-disable-next-line no-unused-vars
} catch (e) { } catch (e) {
threw = true; threw = true;
} }
@@ -4431,6 +4426,7 @@ describe('Env integration', function() {
env.it('a spec', async function() { env.it('a spec', async function() {
try { try {
await env.throwUnlessAsync(Promise.resolve()).toBeRejected(); await env.throwUnlessAsync(Promise.resolve()).toBeRejected();
// eslint-disable-next-line no-unused-vars
} catch (e) {} } catch (e) {}
}); });
-1
View File
@@ -866,7 +866,6 @@ describe('spec running', function() {
const actions = []; const actions = [];
env.describe('Something', function() { env.describe('Something', function() {
// eslint-disable-next-line no-unused-vars
env.beforeEach(function(innerDone) { env.beforeEach(function(innerDone) {
actions.push('beforeEach'); actions.push('beforeEach');
}, 1); }, 1);
-5
View File
@@ -830,9 +830,7 @@ describe('matchersUtil', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil(); const matchersUtil = new jasmineUnderTest.MatchersUtil();
const a1 = new TypedArrayCtor(2); const a1 = new TypedArrayCtor(2);
const a2 = new TypedArrayCtor(2); const a2 = new TypedArrayCtor(2);
// eslint-disable-next-line compat/compat
a1[0] = a2[0] = BigInt(0); a1[0] = a2[0] = BigInt(0);
// eslint-disable-next-line compat/compat
a1[1] = a2[1] = BigInt(1); a1[1] = a2[1] = BigInt(1);
expect(matchersUtil.equals(a1, a2)).toBe(true); expect(matchersUtil.equals(a1, a2)).toBe(true);
} }
@@ -843,7 +841,6 @@ describe('matchersUtil', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil(); const matchersUtil = new jasmineUnderTest.MatchersUtil();
const a1 = new TypedArrayCtor(2); const a1 = new TypedArrayCtor(2);
const a2 = new TypedArrayCtor(1); const a2 = new TypedArrayCtor(1);
// eslint-disable-next-line compat/compat
a1[0] = a1[1] = a2[0] = BigInt(0); a1[0] = a1[1] = a2[0] = BigInt(0);
expect(matchersUtil.equals(a1, a2)).toBe(false); expect(matchersUtil.equals(a1, a2)).toBe(false);
}); });
@@ -855,9 +852,7 @@ describe('matchersUtil', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil(); const matchersUtil = new jasmineUnderTest.MatchersUtil();
const a1 = new TypedArrayCtor(2); const a1 = new TypedArrayCtor(2);
const a2 = new TypedArrayCtor(2); const a2 = new TypedArrayCtor(2);
// eslint-disable-next-line compat/compat
a1[0] = a1[1] = a2[0] = BigInt(0); a1[0] = a1[1] = a2[0] = BigInt(0);
// eslint-disable-next-line compat/compat
a2[1] = BigInt(1); a2[1] = BigInt(1);
expect(matchersUtil.equals(a1, a2)).toBe(false); expect(matchersUtil.equals(a1, a2)).toBe(false);
} }
-1
View File
@@ -1,4 +1,3 @@
/* eslint-disable compat/compat */
describe('toEqual', function() { describe('toEqual', function() {
'use strict'; 'use strict';
@@ -85,7 +85,7 @@ describe('toHaveNoOtherSpyInteractions', function() {
); );
}); });
it(`throws an error if a non-object is passed`, function() { it('throws an error if a non-object is passed', function() {
let matcher = jasmineUnderTest.matchers.toHaveNoOtherSpyInteractions(); let matcher = jasmineUnderTest.matchers.toHaveNoOtherSpyInteractions();
expect(function() { expect(function() {
@@ -70,7 +70,7 @@ describe('toHaveSpyInteractions', function() {
); );
}); });
it(`throws an error if a non-object is passed`, function() { it('throws an error if a non-object is passed', function() {
let matcher = jasmineUnderTest.matchers.toHaveSpyInteractions(); let matcher = jasmineUnderTest.matchers.toHaveSpyInteractions();
expect(function() { expect(function() {
+1
View File
@@ -8,6 +8,7 @@ config.clearReporters = true;
config.jasmineCore = jasmineCore; config.jasmineCore = jasmineCore;
jasmineBrowser.runSpecs(config).catch(function(error) { jasmineBrowser.runSpecs(config).catch(function(error) {
// eslint-disable-next-line no-console
console.error(error); console.error(error);
process.exit(1); process.exit(1);
}); });
+2
View File
@@ -36,6 +36,7 @@ getJasmineRequireObj().Deprecator = function(j$) {
Deprecator.prototype.log_ = function(runnable, deprecation, options) { Deprecator.prototype.log_ = function(runnable, deprecation, options) {
if (j$.isError_(deprecation)) { if (j$.isError_(deprecation)) {
// eslint-disable-next-line no-console
console.error(deprecation); console.error(deprecation);
return; return;
} }
@@ -58,6 +59,7 @@ getJasmineRequireObj().Deprecator = function(j$) {
context += '\n' + verboseNote; context += '\n' + verboseNote;
} }
// eslint-disable-next-line no-console
console.error('DEPRECATION: ' + deprecation + context); console.error('DEPRECATION: ' + deprecation + context);
}; };
+2
View File
@@ -385,7 +385,9 @@ getJasmineRequireObj().Env = function(j$) {
// If we get here, all results have been reported and there's nothing we // If we get here, all results have been reported and there's nothing we
// can do except log the result and hope the user sees it. // can do except log the result and hope the user sees it.
// eslint-disable-next-line no-console
console.error('Jasmine received a result after the suite finished:'); console.error('Jasmine received a result after the suite finished:');
// eslint-disable-next-line no-console
console.error(expectationResult); console.error(expectationResult);
} }
+2
View File
@@ -58,6 +58,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
) { ) {
try { try {
this.emitScalar(value.toString()); this.emitScalar(value.toString());
// eslint-disable-next-line no-unused-vars
} catch (e) { } catch (e) {
this.emitScalar('has-invalid-toString-method'); this.emitScalar('has-invalid-toString-method');
} }
@@ -304,6 +305,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
value.toString !== Object.prototype.toString && value.toString !== Object.prototype.toString &&
value.toString() !== Object.prototype.toString.call(value) value.toString() !== Object.prototype.toString.call(value)
); );
// eslint-disable-next-line no-unused-vars
} catch (e) { } catch (e) {
// The custom toString() threw. // The custom toString() threw.
return true; return true;
+2
View File
@@ -22,6 +22,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
} }
function fallbackOnMultipleDone() { function fallbackOnMultipleDone() {
// eslint-disable-next-line no-console
console.error( console.error(
new Error( new Error(
"An asynchronous function called its 'done' " + "An asynchronous function called its 'done' " +
@@ -135,6 +136,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
// Any error we catch here is probably due to a bug in Jasmine, // Any error we catch here is probably due to a bug in Jasmine,
// and it's not likely to end up anywhere useful if we let it // and it's not likely to end up anywhere useful if we let it
// propagate. Log it so it can at least show up when debugging. // propagate. Log it so it can at least show up when debugging.
// eslint-disable-next-line no-console
console.error(error); console.error(error);
} }
} }
+1
View File
@@ -252,6 +252,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
let value; let value;
try { try {
value = obj[prop]; value = obj[prop];
// eslint-disable-next-line no-unused-vars
} catch (e) { } catch (e) {
return false; return false;
} }
+1
View File
@@ -31,6 +31,7 @@ getJasmineRequireObj().toBeInstanceOf = function(j$) {
try { try {
expectedMatcher = new j$.Any(expected); expectedMatcher = new j$.Any(expected);
pass = expectedMatcher.asymmetricMatch(actual); pass = expectedMatcher.asymmetricMatch(actual);
// eslint-disable-next-line no-unused-vars
} catch (error) { } catch (error) {
throw new Error( throw new Error(
usageError('Expected value is not a constructor function') usageError('Expected value is not a constructor function')
+2
View File
@@ -122,8 +122,10 @@ jasmineRequire.HtmlReporter = function(j$) {
if (noExpectations(result)) { if (noExpectations(result)) {
const noSpecMsg = "Spec '" + result.fullName + "' has no expectations."; const noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
if (result.status === 'failed') { if (result.status === 'failed') {
// eslint-disable-next-line no-console
console.error(noSpecMsg); console.error(noSpecMsg);
} else { } else {
// eslint-disable-next-line no-console
console.warn(noSpecMsg); console.warn(noSpecMsg);
} }
} }