From 31cfc614be7458af39c564cd2e7b38d5af5df655 Mon Sep 17 00:00:00 2001 From: "L. Pereira" Date: Thu, 30 May 2024 15:24:18 -0700 Subject: [PATCH] Make eslint happy Since this code runs in a browser, we need to tell eslint that it's going to run in a browser enviroment so things like `window` and `document` are defined. Signed-off-by: L. Pereira --- crates/explorer/eslint.config.js | 20 +++++++++++++------- crates/explorer/package-lock.json | 19 ++++++++++++++++--- crates/explorer/package.json | 1 + crates/explorer/src/index.js | 4 ++-- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/crates/explorer/eslint.config.js b/crates/explorer/eslint.config.js index 4ad3b0ddc083..c096122c52fc 100644 --- a/crates/explorer/eslint.config.js +++ b/crates/explorer/eslint.config.js @@ -1,12 +1,18 @@ -import js from "@eslint/js"; +import globals from "globals"; +import pluginJs from "@eslint/js"; -export default [ - js.configs.recommended, +export default [ + { + files: ["**/*.js"], + languageOptions: { + sourceType: "module" + } + }, { - rules: { - "no-unused-vars": "error", - "no-undef": "error", - }, + languageOptions: { + globals: globals.browser + } }, + pluginJs.configs.recommended, ]; diff --git a/crates/explorer/package-lock.json b/crates/explorer/package-lock.json index fe6df36aaae6..c19d40b6392c 100644 --- a/crates/explorer/package-lock.json +++ b/crates/explorer/package-lock.json @@ -11,6 +11,7 @@ "devDependencies": { "@eslint/js": "^9.3.0", "eslint": "^9.3.0", + "globals": "^15.3.0", "prettier": "3.2.5" } }, @@ -73,6 +74,18 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/js": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.3.0.tgz", @@ -569,9 +582,9 @@ } }, "node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "version": "15.3.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.3.0.tgz", + "integrity": "sha512-cCdyVjIUVTtX8ZsPkq1oCsOsLmGIswqnjZYMJJTGaNApj1yHtLSymKhwH51ttirREn75z3p4k051clwg7rvNKA==", "dev": true, "engines": { "node": ">=18" diff --git a/crates/explorer/package.json b/crates/explorer/package.json index 4b3ff9421bb6..bcba10216612 100644 --- a/crates/explorer/package.json +++ b/crates/explorer/package.json @@ -22,6 +22,7 @@ "devDependencies": { "@eslint/js": "^9.3.0", "eslint": "^9.3.0", + "globals": "^15.3.0", "prettier": "3.2.5" }, "type": "module" diff --git a/crates/explorer/src/index.js b/crates/explorer/src/index.js index 34fe148f0141..dc98fc05805a 100644 --- a/crates/explorer/src/index.js +++ b/crates/explorer/src/index.js @@ -1,6 +1,6 @@ /*** LRU Cache *****************************************************************/ -class Cache { +class LruCache { constructor(size, getFunc) { // Maps preserve the insertion order, so we can use it to implement a naïve LRU // cache. @@ -139,7 +139,7 @@ const renderInst = (mnemonic, operands) => { // Connects callbacks to mouse hovering events so elements are properly highlighted when // hovered, and the bridging element is drawn between the instruction lists. -const linkedElementCache = new Cache(256, offset => +const linkedElementCache = new LruCache(256, offset => document.querySelectorAll(`[data-wasm-offset="${offset}"]`), ); const linkElements = element => {