Skip to content

Commit

Permalink
Update ESLint to v9
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Jul 15, 2024
1 parent c8a5103 commit 4c167b3
Show file tree
Hide file tree
Showing 24 changed files with 342 additions and 415 deletions.
22 changes: 0 additions & 22 deletions .eslintignore

This file was deleted.

51 changes: 0 additions & 51 deletions .eslintrc.json

This file was deleted.

5 changes: 0 additions & 5 deletions benchmark/.eslintrc

This file was deleted.

1 change: 0 additions & 1 deletion benchmark/console-reporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";
/* eslint-disable no-console */
/* eslint-disable no-invalid-this */

function onError(event) {
const bench = event.target;
Expand Down
2 changes: 0 additions & 2 deletions benchmark/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ if (argv.suites) {
suitesToRun.forEach(consoleReporter);

function runNext() {
/* eslint-disable no-invalid-this */
if (this && this.off) {
// there is no .once()
this.off("complete", runNext);
}
/* eslint-enable no-invalid-this */

const suite = suitesToRun.shift();
if (!suite) {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/selectors/sizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports.querySelectorAll = function () {
for (const selector of selectors) {
try {
document.querySelectorAll(selector);
} catch (e) {
} catch {
count++;
}
}
Expand Down
163 changes: 163 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import domenicConfig from "@domenic/eslint-config";
import globals from "globals";
import html from "eslint-plugin-html";
import jsdomInternal from "./scripts/eslint-plugin/index.mjs";

export default [
{
ignores: [
"benchmark/selectors/sizzle-speed/**",
"lib/jsdom/browser/default-stylesheet.js",
"lib/jsdom/level3/xpath.js",
"lib/jsdom/living/generated/**",
"test/api/fixtures/**",
"test/jquery-fixtures/**",
"test/to-port-to-wpts/files/**",
"test/to-port-to-wpts/frame.js",
"test/to-port-to-wpts/level1/**",
"test/to-port-to-wpts/level2/**",
"test/to-port-to-wpts/level3/**",
"test/to-port-to-wpts/script.js",
"test/web-platform-tests/tests/**",
"test/web-platform-tests/to-upstream/dom/nodes/Document-createComment-createTextNode.js",
"test/web-platform-tests/to-upstream/svg/element-svg.html",
"test/web-platform-tests/to-upstream/svg/svgstringlist.html",
"test/web-platform-tests/to-upstream/**/*dont-upstream*"
]
},
{
files: ["**/*.js"],
languageOptions: {
sourceType: "commonjs",
globals: globals.node
}
},
...domenicConfig,
{
plugins: {
"jsdom-internal": jsdomInternal
},
rules: {
// Overrides for jsdom
"array-element-newline": "off",
"no-implied-eval": "off",
"no-invalid-this": "off",
"require-unicode-regexp": "off",
"prefer-template": "off",
"new-cap": ["error", { capIsNewExceptions: ["ByteString", "USVString", "DOMString"] }],

// Custom rules
"jsdom-internal/hook-super-invocation": [
"error",
{ ancestor: "NodeImpl", hook: "_attach" },
{ ancestor: "NodeImpl", hook: "_detach" },
{ ancestor: "NodeImpl", hook: "_descendantAdded" },
{ ancestor: "NodeImpl", hook: "_descendantRemoved" },
{ ancestor: "NodeImpl", hook: "_childTextContentChangeSteps" },
{ ancestor: "ElementImpl", hook: "_attrModified" }
]
}
},
{
files: ["lib/**"],
rules: {
"no-restricted-properties": [
"error",
{
property: "getAttribute",
message: "Use 'getAttributeNS' with null as the namespace to access attributes within jsdom"
},
{
property: "setAttribute",
message: "Use 'setAttributeNS' with null as the namespace to access attributes within jsdom"
},
{
property: "hasAttribute",
message: "Use 'hasAttributeNS' with null as the namespace to access attributes within jsdom"
},
{
property: "removeAttribute",
message: "Use 'removeAttributeNS' with null as the namespace to access attributes within jsdom"
},
{
property: "toggleAttribute",
message: "Use 'setAttributeNS' and 'removeAttributeNS' with null as the namespace to access attributes " +
"within jsdom"
}
]
}
},
{
files: ["test/api/**"],
rules: {
"no-loop-func": "off"
}
},
{
files: ["test/web-platform-tests/to-upstream/**/*.{js,mjs,html}"],
plugins: { html },
languageOptions: {
sourceType: "script",
globals: {
...globals.browser,

/* eslint-disable camelcase */
EventWatcher: "readonly",
test: "readonly",
async_test: "readonly",
promise_test: "readonly",
promise_rejects: "readonly",
generate_tests: "readonly",
setup: "readonly",
done: "readonly",
on_event: "readonly",
step_timeout: "readonly",
format_value: "readonly",
assert_true: "readonly",
assert_false: "readonly",
assert_equals: "readonly",
assert_not_equals: "readonly",
assert_in_array: "readonly",
assert_object_equals: "readonly",
assert_array_equals: "readonly",
assert_approx_equals: "readonly",
assert_less_than: "readonly",
assert_greater_than: "readonly",
assert_between_exclusive: "readonly",
assert_less_than_equal: "readonly",
assert_greater_than_equal: "readonly",
assert_between_inclusive: "readonly",
assert_regexp_match: "readonly",
assert_class_string: "readonly",
assert_exists: "readonly",
assert_own_property: "readonly",
assert_not_exists: "readonly",
assert_inherits: "readonly",
assert_idl_attribute: "readonly",
assert_readonly: "readonly",
assert_throws_dom: "readonly",
assert_throws_js: "readonly",
assert_unreached: "readonly",
assert_any: "readonly",
fetch_tests_from_worker: "readonly",
timeout: "readonly",
add_start_callback: "readonly",
add_test_state_callback: "readonly",
add_result_callback: "readonly",
add_completion_callback: "readonly"
/* eslint-enable camelcase */
}
},
rules: {
"padded-blocks": "off", // we like to add spaces around the main test block
"camelcase": "off", // setting options like allow_uncaught_exception requires this
"no-implicit-globals": "off", // it doesn't much matter if we use top-level function declarations here
"new-cap": [
"error", {
// window.external
capIsNewExceptions: ["AddSearchProvider", "IsSearchProviderInstalled"]
}
]
}
}
];
4 changes: 2 additions & 2 deletions lib/jsdom/browser/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ function Window(options) {
this.atob = function (str) {
try {
return atob(str);
} catch (e) {
} catch {
// Convert Node.js DOMException to one from our global.
throw DOMException.create(window, [
"The string to be decoded contains invalid characters.",
Expand All @@ -770,7 +770,7 @@ function Window(options) {
this.btoa = function (str) {
try {
return btoa(str);
} catch (e) {
} catch {
// Convert Node.js DOMException to one from our global.
throw DOMException.create(window, [
"The string to be encoded contains invalid characters.",
Expand Down
2 changes: 1 addition & 1 deletion lib/jsdom/living/helpers/stylesheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.createStylesheet = (sheetText, elementImpl, baseURL) => {
let sheet;
try {
sheet = cssom.parse(sheetText);
} catch (e) {
} catch {
if (elementImpl._ownerDocument._defaultView) {
const error = new Error("Could not parse CSS stylesheet");
error.detail = sheetText;
Expand Down
1 change: 0 additions & 1 deletion lib/jsdom/living/interfaces.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable global-require */
"use strict";

const style = require("../level2/style");
Expand Down
4 changes: 2 additions & 2 deletions lib/jsdom/living/nodes/HTMLInputElement-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class HTMLInputElementImpl extends HTMLElementImpl {
if (isNaN(value)) { // Empty value is parsed as NaN.
value = 0;
}
} catch (error) {
} catch {
// Step 5. Default value is 0.
}
value = new Decimal(value);
Expand Down Expand Up @@ -1027,7 +1027,7 @@ class HTMLInputElementImpl extends HTMLElementImpl {
// first.
new RegExp(pattern, "u"); // eslint-disable-line no-new
regExp = new RegExp("^(?:" + pattern + ")$", "u");
} catch (e) {
} catch {
return false;
}
if (this._hasAttributeAndApplies("multiple")) {
Expand Down
6 changes: 3 additions & 3 deletions lib/jsdom/living/xhr/XMLHttpRequest-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetImpl {

try {
res = parseJSONFromBytes(responseBuffer);
} catch (e) {
} catch {
res = null;
}
break;
Expand Down Expand Up @@ -306,7 +306,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetImpl {
});
try {
parseIntoDocument(resText, res);
} catch (e) {
} catch {
properties.responseXMLCache = null;
return null;
}
Expand Down Expand Up @@ -457,7 +457,7 @@ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetImpl {
let urlObj;
try {
urlObj = new URL(uri, documentBaseURLSerialized(_ownerDocument));
} catch (e) {
} catch {
throw DOMException.create(this._globalObject, [
"The string did not match the expected pattern.",
"SyntaxError"
Expand Down
1 change: 0 additions & 1 deletion lib/jsdom/living/xhr/xhr-sync-worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use strict";
/* eslint-disable no-process-exit */
const util = require("util");
const { JSDOM } = require("../../../..");
const { READY_STATES } = require("./xhr-utils");
Expand Down
1 change: 0 additions & 1 deletion lib/jsdom/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ exports.treeOrderSorter = function (a, b) {
return 0;
};

/* eslint-disable global-require */
try {
exports.Canvas = require("canvas");
} catch {
Expand Down
Loading

0 comments on commit 4c167b3

Please sign in to comment.