Skip to content

Commit 4c167b3

Browse files
committed
Update ESLint to v9
1 parent c8a5103 commit 4c167b3

24 files changed

+342
-415
lines changed

.eslintignore

-22
This file was deleted.

.eslintrc.json

-51
This file was deleted.

benchmark/.eslintrc

-5
This file was deleted.

benchmark/console-reporter.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22
/* eslint-disable no-console */
3-
/* eslint-disable no-invalid-this */
43

54
function onError(event) {
65
const bench = event.target;

benchmark/runner.js

-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ if (argv.suites) {
2727
suitesToRun.forEach(consoleReporter);
2828

2929
function runNext() {
30-
/* eslint-disable no-invalid-this */
3130
if (this && this.off) {
3231
// there is no .once()
3332
this.off("complete", runNext);
3433
}
35-
/* eslint-enable no-invalid-this */
3634

3735
const suite = suitesToRun.shift();
3836
if (!suite) {

benchmark/selectors/sizzle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exports.querySelectorAll = function () {
3131
for (const selector of selectors) {
3232
try {
3333
document.querySelectorAll(selector);
34-
} catch (e) {
34+
} catch {
3535
count++;
3636
}
3737
}

eslint.config.mjs

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import domenicConfig from "@domenic/eslint-config";
2+
import globals from "globals";
3+
import html from "eslint-plugin-html";
4+
import jsdomInternal from "./scripts/eslint-plugin/index.mjs";
5+
6+
export default [
7+
{
8+
ignores: [
9+
"benchmark/selectors/sizzle-speed/**",
10+
"lib/jsdom/browser/default-stylesheet.js",
11+
"lib/jsdom/level3/xpath.js",
12+
"lib/jsdom/living/generated/**",
13+
"test/api/fixtures/**",
14+
"test/jquery-fixtures/**",
15+
"test/to-port-to-wpts/files/**",
16+
"test/to-port-to-wpts/frame.js",
17+
"test/to-port-to-wpts/level1/**",
18+
"test/to-port-to-wpts/level2/**",
19+
"test/to-port-to-wpts/level3/**",
20+
"test/to-port-to-wpts/script.js",
21+
"test/web-platform-tests/tests/**",
22+
"test/web-platform-tests/to-upstream/dom/nodes/Document-createComment-createTextNode.js",
23+
"test/web-platform-tests/to-upstream/svg/element-svg.html",
24+
"test/web-platform-tests/to-upstream/svg/svgstringlist.html",
25+
"test/web-platform-tests/to-upstream/**/*dont-upstream*"
26+
]
27+
},
28+
{
29+
files: ["**/*.js"],
30+
languageOptions: {
31+
sourceType: "commonjs",
32+
globals: globals.node
33+
}
34+
},
35+
...domenicConfig,
36+
{
37+
plugins: {
38+
"jsdom-internal": jsdomInternal
39+
},
40+
rules: {
41+
// Overrides for jsdom
42+
"array-element-newline": "off",
43+
"no-implied-eval": "off",
44+
"no-invalid-this": "off",
45+
"require-unicode-regexp": "off",
46+
"prefer-template": "off",
47+
"new-cap": ["error", { capIsNewExceptions: ["ByteString", "USVString", "DOMString"] }],
48+
49+
// Custom rules
50+
"jsdom-internal/hook-super-invocation": [
51+
"error",
52+
{ ancestor: "NodeImpl", hook: "_attach" },
53+
{ ancestor: "NodeImpl", hook: "_detach" },
54+
{ ancestor: "NodeImpl", hook: "_descendantAdded" },
55+
{ ancestor: "NodeImpl", hook: "_descendantRemoved" },
56+
{ ancestor: "NodeImpl", hook: "_childTextContentChangeSteps" },
57+
{ ancestor: "ElementImpl", hook: "_attrModified" }
58+
]
59+
}
60+
},
61+
{
62+
files: ["lib/**"],
63+
rules: {
64+
"no-restricted-properties": [
65+
"error",
66+
{
67+
property: "getAttribute",
68+
message: "Use 'getAttributeNS' with null as the namespace to access attributes within jsdom"
69+
},
70+
{
71+
property: "setAttribute",
72+
message: "Use 'setAttributeNS' with null as the namespace to access attributes within jsdom"
73+
},
74+
{
75+
property: "hasAttribute",
76+
message: "Use 'hasAttributeNS' with null as the namespace to access attributes within jsdom"
77+
},
78+
{
79+
property: "removeAttribute",
80+
message: "Use 'removeAttributeNS' with null as the namespace to access attributes within jsdom"
81+
},
82+
{
83+
property: "toggleAttribute",
84+
message: "Use 'setAttributeNS' and 'removeAttributeNS' with null as the namespace to access attributes " +
85+
"within jsdom"
86+
}
87+
]
88+
}
89+
},
90+
{
91+
files: ["test/api/**"],
92+
rules: {
93+
"no-loop-func": "off"
94+
}
95+
},
96+
{
97+
files: ["test/web-platform-tests/to-upstream/**/*.{js,mjs,html}"],
98+
plugins: { html },
99+
languageOptions: {
100+
sourceType: "script",
101+
globals: {
102+
...globals.browser,
103+
104+
/* eslint-disable camelcase */
105+
EventWatcher: "readonly",
106+
test: "readonly",
107+
async_test: "readonly",
108+
promise_test: "readonly",
109+
promise_rejects: "readonly",
110+
generate_tests: "readonly",
111+
setup: "readonly",
112+
done: "readonly",
113+
on_event: "readonly",
114+
step_timeout: "readonly",
115+
format_value: "readonly",
116+
assert_true: "readonly",
117+
assert_false: "readonly",
118+
assert_equals: "readonly",
119+
assert_not_equals: "readonly",
120+
assert_in_array: "readonly",
121+
assert_object_equals: "readonly",
122+
assert_array_equals: "readonly",
123+
assert_approx_equals: "readonly",
124+
assert_less_than: "readonly",
125+
assert_greater_than: "readonly",
126+
assert_between_exclusive: "readonly",
127+
assert_less_than_equal: "readonly",
128+
assert_greater_than_equal: "readonly",
129+
assert_between_inclusive: "readonly",
130+
assert_regexp_match: "readonly",
131+
assert_class_string: "readonly",
132+
assert_exists: "readonly",
133+
assert_own_property: "readonly",
134+
assert_not_exists: "readonly",
135+
assert_inherits: "readonly",
136+
assert_idl_attribute: "readonly",
137+
assert_readonly: "readonly",
138+
assert_throws_dom: "readonly",
139+
assert_throws_js: "readonly",
140+
assert_unreached: "readonly",
141+
assert_any: "readonly",
142+
fetch_tests_from_worker: "readonly",
143+
timeout: "readonly",
144+
add_start_callback: "readonly",
145+
add_test_state_callback: "readonly",
146+
add_result_callback: "readonly",
147+
add_completion_callback: "readonly"
148+
/* eslint-enable camelcase */
149+
}
150+
},
151+
rules: {
152+
"padded-blocks": "off", // we like to add spaces around the main test block
153+
"camelcase": "off", // setting options like allow_uncaught_exception requires this
154+
"no-implicit-globals": "off", // it doesn't much matter if we use top-level function declarations here
155+
"new-cap": [
156+
"error", {
157+
// window.external
158+
capIsNewExceptions: ["AddSearchProvider", "IsSearchProviderInstalled"]
159+
}
160+
]
161+
}
162+
}
163+
];

lib/jsdom/browser/Window.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ function Window(options) {
758758
this.atob = function (str) {
759759
try {
760760
return atob(str);
761-
} catch (e) {
761+
} catch {
762762
// Convert Node.js DOMException to one from our global.
763763
throw DOMException.create(window, [
764764
"The string to be decoded contains invalid characters.",
@@ -770,7 +770,7 @@ function Window(options) {
770770
this.btoa = function (str) {
771771
try {
772772
return btoa(str);
773-
} catch (e) {
773+
} catch {
774774
// Convert Node.js DOMException to one from our global.
775775
throw DOMException.create(window, [
776776
"The string to be encoded contains invalid characters.",

lib/jsdom/living/helpers/stylesheets.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports.createStylesheet = (sheetText, elementImpl, baseURL) => {
3232
let sheet;
3333
try {
3434
sheet = cssom.parse(sheetText);
35-
} catch (e) {
35+
} catch {
3636
if (elementImpl._ownerDocument._defaultView) {
3737
const error = new Error("Could not parse CSS stylesheet");
3838
error.detail = sheetText;

lib/jsdom/living/interfaces.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable global-require */
21
"use strict";
32

43
const style = require("../level2/style");

lib/jsdom/living/nodes/HTMLInputElement-impl.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ class HTMLInputElementImpl extends HTMLElementImpl {
542542
if (isNaN(value)) { // Empty value is parsed as NaN.
543543
value = 0;
544544
}
545-
} catch (error) {
545+
} catch {
546546
// Step 5. Default value is 0.
547547
}
548548
value = new Decimal(value);
@@ -1027,7 +1027,7 @@ class HTMLInputElementImpl extends HTMLElementImpl {
10271027
// first.
10281028
new RegExp(pattern, "u"); // eslint-disable-line no-new
10291029
regExp = new RegExp("^(?:" + pattern + ")$", "u");
1030-
} catch (e) {
1030+
} catch {
10311031
return false;
10321032
}
10331033
if (this._hasAttributeAndApplies("multiple")) {

lib/jsdom/living/xhr/XMLHttpRequest-impl.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetImpl {
218218

219219
try {
220220
res = parseJSONFromBytes(responseBuffer);
221-
} catch (e) {
221+
} catch {
222222
res = null;
223223
}
224224
break;
@@ -306,7 +306,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetImpl {
306306
});
307307
try {
308308
parseIntoDocument(resText, res);
309-
} catch (e) {
309+
} catch {
310310
properties.responseXMLCache = null;
311311
return null;
312312
}
@@ -457,7 +457,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetImpl {
457457
let urlObj;
458458
try {
459459
urlObj = new URL(uri, documentBaseURLSerialized(_ownerDocument));
460-
} catch (e) {
460+
} catch {
461461
throw DOMException.create(this._globalObject, [
462462
"The string did not match the expected pattern.",
463463
"SyntaxError"

lib/jsdom/living/xhr/xhr-sync-worker.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"use strict";
2-
/* eslint-disable no-process-exit */
32
const util = require("util");
43
const { JSDOM } = require("../../../..");
54
const { READY_STATES } = require("./xhr-utils");

lib/jsdom/utils.js

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ exports.treeOrderSorter = function (a, b) {
107107
return 0;
108108
};
109109

110-
/* eslint-disable global-require */
111110
try {
112111
exports.Canvas = require("canvas");
113112
} catch {

0 commit comments

Comments
 (0)