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

View File

@@ -3,6 +3,6 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
[*.{js, json, sh, yml}]
[*.{js, mjs, json, sh, yml}]
indent_style = space
indent_size = 2

54
eslint.config.mjs Normal file
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",
},
}]);

View File

@@ -34,9 +34,12 @@
"package.json"
],
"devDependencies": {
"eslint": "^8.36.0",
"eslint-plugin-compat": "^4.0.0",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.24.0",
"eslint": "^9.24.0",
"eslint-plugin-compat": "^6.0.2",
"glob": "^10.2.3",
"globals": "^16.0.0",
"grunt": "^1.0.4",
"grunt-cli": "^1.3.2",
"grunt-contrib-compress": "^2.0.0",

View File

@@ -205,7 +205,6 @@ describe('Env', function() {
it('throws an error when given arguments', function() {
expect(function() {
// eslint-disable-next-line no-unused-vars
env.describe('done method', function(done) {});
}).toThrowError('describe does not expect any arguments');
});

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() {
const timeout = 3,
// eslint-disable-next-line no-unused-vars
beforeFn = { fn: function(done) {}, type: 'before', timeout: timeout },
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
onComplete = jasmine.createSpy('onComplete'),
@@ -287,7 +286,6 @@ describe('QueueRunner', 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) {} },
queueableFn = { fn: jasmine.createSpy('fn') },
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() {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
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() {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
throwAsync();
},
@@ -461,7 +457,6 @@ describe('QueueRunner', function() {
it('handles a global error event with a message but no error', function() {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
const currentHandler = globalErrors.pushListener.calls.mostRecent()
.args[0];
@@ -641,7 +636,6 @@ describe('QueueRunner', function() {
it('issues an error if the function also takes a parameter', function() {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
return new StubPromise();
}
@@ -666,7 +660,6 @@ describe('QueueRunner', function() {
});
it('issues a more specific error if the function is `async`', function() {
// eslint-disable-next-line no-unused-vars
async function fn(done) {}
const onException = jasmine.createSpy('onException'),
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() {
const queueableFn = {
// eslint-disable-next-line no-unused-vars
fn: function(done) {
throw new Error('error');
}

View File

@@ -97,17 +97,11 @@ describe('Spies', function() {
it('preserves arity of original function', function() {
const functions = [
function nullary() {},
// eslint-disable-next-line no-unused-vars
function unary(arg) {},
// eslint-disable-next-line no-unused-vars
function binary(arg1, arg2) {},
// eslint-disable-next-line no-unused-vars
function ternary(arg1, arg2, arg3) {},
// eslint-disable-next-line no-unused-vars
function quaternary(arg1, arg2, arg3, arg4) {},
// eslint-disable-next-line no-unused-vars
function quinary(arg1, arg2, arg3, arg4, arg5) {},
// eslint-disable-next-line no-unused-vars
function senary(arg1, arg2, arg3, arg4, arg5, arg6) {}
];

View File

@@ -1071,7 +1071,6 @@ describe('Env integration', function() {
env.describe('my suite', function() {
env.it('my spec', function() {});
// eslint-disable-next-line no-unused-vars
env.afterAll(function(afterAllDone) {
throw error;
});
@@ -1569,7 +1568,6 @@ describe('Env integration', function() {
env.addReporter(reporter);
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 8414;
// eslint-disable-next-line no-unused-vars
env.it("async spec that doesn't call done", function(underTestCallback) {
env.expect(true).toBeTruthy();
jasmine.clock().tick(8416);
@@ -1642,13 +1640,13 @@ describe('Env integration', function() {
realSetTimeout(function() {
try {
jasmine.clock().tick(10);
// eslint-disable-next-line no-unused-vars
} catch (e) {
// don't worry if the clock is already uninstalled
}
}, 100);
});
env.describe('beforeAll', function() {
// eslint-disable-next-line no-unused-vars
env.beforeAll(function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(5001);
@@ -1664,7 +1662,6 @@ describe('Env integration', function() {
});
env.describe('afterAll', function() {
// eslint-disable-next-line no-unused-vars
env.afterAll(function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(2001);
@@ -1680,7 +1677,6 @@ describe('Env integration', function() {
});
env.describe('beforeEach', function() {
// eslint-disable-next-line no-unused-vars
env.beforeEach(function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(1001);
@@ -1696,7 +1692,6 @@ describe('Env integration', function() {
});
env.describe('afterEach', function() {
// eslint-disable-next-line no-unused-vars
env.afterEach(function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(4001);
@@ -1713,7 +1708,6 @@ describe('Env integration', function() {
env.it(
'it times out',
// eslint-disable-next-line no-unused-vars
function(innerDone) {
realSetTimeout(function() {
jasmine.clock().tick(6001);
@@ -2699,7 +2693,6 @@ describe('Env integration', function() {
env.addReporter(reporter);
env.describe('async suite', function() {
// eslint-disable-next-line no-unused-vars
env.afterAll(function(innerDone) {
setTimeout(function() {
throw new Error('suite');
@@ -2712,7 +2705,6 @@ describe('Env integration', function() {
env.describe('suite', function() {
env.it(
'async spec',
// eslint-disable-next-line no-unused-vars
function(innerDone) {
setTimeout(function() {
throw new Error('spec');
@@ -4362,6 +4354,7 @@ describe('Env integration', function() {
env.it('a spec', function() {
try {
env.throwUnless(1).toEqual(1);
// eslint-disable-next-line no-unused-vars
} catch (e) {
threw = true;
}
@@ -4375,6 +4368,7 @@ describe('Env integration', function() {
env.it('a spec', function() {
try {
env.throwUnless(1).toEqual(2);
// eslint-disable-next-line no-unused-vars
} catch (e) {}
});
@@ -4418,6 +4412,7 @@ describe('Env integration', function() {
env.it('a spec', async function() {
try {
await env.throwUnlessAsync(Promise.resolve()).toBeResolved();
// eslint-disable-next-line no-unused-vars
} catch (e) {
threw = true;
}
@@ -4431,6 +4426,7 @@ describe('Env integration', function() {
env.it('a spec', async function() {
try {
await env.throwUnlessAsync(Promise.resolve()).toBeRejected();
// eslint-disable-next-line no-unused-vars
} catch (e) {}
});

View File

@@ -866,7 +866,6 @@ describe('spec running', function() {
const actions = [];
env.describe('Something', function() {
// eslint-disable-next-line no-unused-vars
env.beforeEach(function(innerDone) {
actions.push('beforeEach');
}, 1);

View File

@@ -830,9 +830,7 @@ describe('matchersUtil', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil();
const a1 = new TypedArrayCtor(2);
const a2 = new TypedArrayCtor(2);
// eslint-disable-next-line compat/compat
a1[0] = a2[0] = BigInt(0);
// eslint-disable-next-line compat/compat
a1[1] = a2[1] = BigInt(1);
expect(matchersUtil.equals(a1, a2)).toBe(true);
}
@@ -843,7 +841,6 @@ describe('matchersUtil', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil();
const a1 = new TypedArrayCtor(2);
const a2 = new TypedArrayCtor(1);
// eslint-disable-next-line compat/compat
a1[0] = a1[1] = a2[0] = BigInt(0);
expect(matchersUtil.equals(a1, a2)).toBe(false);
});
@@ -855,9 +852,7 @@ describe('matchersUtil', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil();
const a1 = new TypedArrayCtor(2);
const a2 = new TypedArrayCtor(2);
// eslint-disable-next-line compat/compat
a1[0] = a1[1] = a2[0] = BigInt(0);
// eslint-disable-next-line compat/compat
a2[1] = BigInt(1);
expect(matchersUtil.equals(a1, a2)).toBe(false);
}

View File

@@ -1,4 +1,3 @@
/* eslint-disable compat/compat */
describe('toEqual', function() {
'use strict';

View File

@@ -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();
expect(function() {

View File

@@ -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();
expect(function() {

View File

@@ -8,6 +8,7 @@ config.clearReporters = true;
config.jasmineCore = jasmineCore;
jasmineBrowser.runSpecs(config).catch(function(error) {
// eslint-disable-next-line no-console
console.error(error);
process.exit(1);
});

View File

@@ -36,6 +36,7 @@ getJasmineRequireObj().Deprecator = function(j$) {
Deprecator.prototype.log_ = function(runnable, deprecation, options) {
if (j$.isError_(deprecation)) {
// eslint-disable-next-line no-console
console.error(deprecation);
return;
}
@@ -58,6 +59,7 @@ getJasmineRequireObj().Deprecator = function(j$) {
context += '\n' + verboseNote;
}
// eslint-disable-next-line no-console
console.error('DEPRECATION: ' + deprecation + context);
};

View File

@@ -385,7 +385,9 @@ getJasmineRequireObj().Env = function(j$) {
// 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.
// eslint-disable-next-line no-console
console.error('Jasmine received a result after the suite finished:');
// eslint-disable-next-line no-console
console.error(expectationResult);
}

View File

@@ -58,6 +58,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
) {
try {
this.emitScalar(value.toString());
// eslint-disable-next-line no-unused-vars
} catch (e) {
this.emitScalar('has-invalid-toString-method');
}
@@ -304,6 +305,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
value.toString !== Object.prototype.toString &&
value.toString() !== Object.prototype.toString.call(value)
);
// eslint-disable-next-line no-unused-vars
} catch (e) {
// The custom toString() threw.
return true;

View File

@@ -22,6 +22,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
}
function fallbackOnMultipleDone() {
// eslint-disable-next-line no-console
console.error(
new Error(
"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,
// 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.
// eslint-disable-next-line no-console
console.error(error);
}
}

View File

@@ -252,6 +252,7 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
let value;
try {
value = obj[prop];
// eslint-disable-next-line no-unused-vars
} catch (e) {
return false;
}

View File

@@ -31,6 +31,7 @@ getJasmineRequireObj().toBeInstanceOf = function(j$) {
try {
expectedMatcher = new j$.Any(expected);
pass = expectedMatcher.asymmetricMatch(actual);
// eslint-disable-next-line no-unused-vars
} catch (error) {
throw new Error(
usageError('Expected value is not a constructor function')

View File

@@ -122,8 +122,10 @@ jasmineRequire.HtmlReporter = function(j$) {
if (noExpectations(result)) {
const noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
if (result.status === 'failed') {
// eslint-disable-next-line no-console
console.error(noSpecMsg);
} else {
// eslint-disable-next-line no-console
console.warn(noSpecMsg);
}
}