From ef6569b7d3b0dfb8c7dc33b109b573bf7eb55184 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 26 Jun 2023 11:51:54 +0200 Subject: [PATCH] chore: cleanup unusued variables + enable linting (#38898) --- .eslintrc.json | 6 ----- script/download-circleci-artifacts.js | 2 +- script/generate-version-json.js | 1 - script/lib/azput.js | 1 - script/lib/utils.js | 3 ++- script/lint.js | 2 +- script/release/ci-release-build.js | 1 - script/release/notes/notes.js | 2 +- script/release/prepare-release.js | 2 +- script/release/publish-to-npm.js | 1 - script/release/release-artifact-cleanup.js | 3 --- script/release/release.js | 15 +------------ script/release/version-bumper.js | 22 +------------------ script/release/version-utils.js | 5 ----- script/spec-runner.js | 8 ------- .../context-bridge-mutability/preload.js | 2 +- spec/fixtures/api/new-window-preload.js | 2 +- .../api/safe-storage/decrypt-app/main.js | 2 +- .../api/safe-storage/encrypt-app/main.js | 4 ++-- spec/fixtures/api/service-workers/sw-logs.js | 2 +- spec/fixtures/api/service-workers/sw.js | 2 +- spec/fixtures/api/singleton/main.js | 2 +- spec/fixtures/apps/crash/node-extra-args.js | 3 --- spec/fixtures/apps/libuv-hang/renderer.js | 2 -- spec/fixtures/apps/remote-control/main.js | 2 +- spec/fixtures/apps/self-module-paths/main.js | 1 - spec/fixtures/chromium/other-window.js | 2 +- .../fs-promises-renderer-crash/index.js | 2 +- .../worker-multiple-destroy/worklet.js | 1 + .../chrome-webRequest/background.js | 1 + .../get-background-page.js | 2 +- .../runtime-get-background-page.js | 2 +- spec/fixtures/module/preload-context.js | 2 +- spec/fixtures/module/preload-sandbox.js | 1 + spec/fixtures/testsnap.js | 3 ++- spec/lib/video-helpers.js | 6 +++-- 36 files changed, 31 insertions(+), 89 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 7669da186367..74e61c612d61 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -28,12 +28,6 @@ "sourceType": "module" }, "overrides": [ - { - "files": "*.js", - "rules": { - "@typescript-eslint/no-unused-vars": "off" - } - }, { "files": "*.ts", "rules": { diff --git a/script/download-circleci-artifacts.js b/script/download-circleci-artifacts.js index c0593fa01a5e..00e1e9224b1a 100644 --- a/script/download-circleci-artifacts.js +++ b/script/download-circleci-artifacts.js @@ -50,7 +50,7 @@ async function downloadWithRetry (url, directory) { return await downloadFile(downloadURL, directory); } catch (err) { lastError = err; - await new Promise((resolve, reject) => setTimeout(resolve, 30000)); + await new Promise(resolve => setTimeout(resolve, 30000)); } } throw lastError; diff --git a/script/generate-version-json.js b/script/generate-version-json.js index 76dd8c80492f..dcd69e2d11d2 100644 --- a/script/generate-version-json.js +++ b/script/generate-version-json.js @@ -1,5 +1,4 @@ const fs = require('node:fs'); -const path = require('node:path'); const semver = require('semver'); const outputPath = process.argv[2]; diff --git a/script/lib/azput.js b/script/lib/azput.js index 2c0dab15d441..e5e389b0ee42 100644 --- a/script/lib/azput.js +++ b/script/lib/azput.js @@ -1,6 +1,5 @@ /* eslint-disable camelcase */ const { BlobServiceClient } = require('@azure/storage-blob'); -const fs = require('node:fs'); const path = require('node:path'); const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.ELECTRON_ARTIFACTS_BLOB_STORAGE); diff --git a/script/lib/utils.js b/script/lib/utils.js index 7e1db4688186..53398fb0707f 100644 --- a/script/lib/utils.js +++ b/script/lib/utils.js @@ -8,6 +8,7 @@ const ELECTRON_DIR = path.resolve(__dirname, '..', '..'); const SRC_DIR = path.resolve(ELECTRON_DIR, '..'); require('colors'); +// eslint-disable-next-line @typescript-eslint/no-unused-vars const pass = '✓'.green; const fail = '✗'.red; @@ -129,7 +130,7 @@ function chunkFilenames (filenames, offset = 0) { * @returns {Promise} */ async function findMatchingFiles (top, test) { - return new Promise((resolve, reject) => { + return new Promise(resolve => { const matches = []; klaw(top, { filter: f => path.basename(f) !== '.bin' diff --git a/script/lint.js b/script/lint.js index e3508bbb74b8..fdbbbfe1ef40 100755 --- a/script/lint.js +++ b/script/lint.js @@ -272,7 +272,7 @@ function parseCommandLine () { const opts = minimist(process.argv.slice(2), { boolean: ['c++', 'objc', 'javascript', 'python', 'gn', 'patches', 'help', 'changed', 'fix', 'verbose', 'only'], alias: { 'c++': ['cc', 'cpp', 'cxx'], javascript: ['js', 'es'], python: 'py', changed: 'c', help: 'h', verbose: 'v' }, - unknown: arg => { help = true; } + unknown: () => { help = true; } }); if (help || opts.help) { console.log('Usage: script/lint.js [--cc] [--js] [--py] [-c|--changed] [-h|--help] [-v|--verbose] [--fix] [--only -- file1 file2]'); diff --git a/script/release/ci-release-build.js b/script/release/ci-release-build.js index 8d455c1a5e40..fce6510ab1a4 100644 --- a/script/release/ci-release-build.js +++ b/script/release/ci-release-build.js @@ -2,7 +2,6 @@ if (!process.env.CI) require('dotenv-safe').load(); const assert = require('node:assert'); const got = require('got'); -const { Octokit } = require('@octokit/rest'); const BUILD_APPVEYOR_URL = 'https://ci.appveyor.com/api/builds'; const CIRCLECI_PIPELINE_URL = 'https://circleci.com/api/v2/project/gh/electron/electron/pipeline'; diff --git a/script/release/notes/notes.js b/script/release/notes/notes.js index 1aee04b7ec68..9f68d9336d9b 100644 --- a/script/release/notes/notes.js +++ b/script/release/notes/notes.js @@ -256,7 +256,7 @@ async function runRetryable (fn, maxRetries) { try { return await fn(); } catch (error) { - await new Promise((resolve, reject) => setTimeout(resolve, CHECK_INTERVAL)); + await new Promise(resolve => setTimeout(resolve, CHECK_INTERVAL)); lastError = error; } } diff --git a/script/release/prepare-release.js b/script/release/prepare-release.js index e38f93746e41..49e4d1b94727 100755 --- a/script/release/prepare-release.js +++ b/script/release/prepare-release.js @@ -173,7 +173,7 @@ async function verifyNewVersion () { } async function promptForVersion (version) { - return new Promise((resolve, reject) => { + return new Promise(resolve => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout diff --git a/script/release/publish-to-npm.js b/script/release/publish-to-npm.js index e74cc280c95a..fda6db43f889 100644 --- a/script/release/publish-to-npm.js +++ b/script/release/publish-to-npm.js @@ -2,7 +2,6 @@ const temp = require('temp'); const fs = require('node:fs'); const path = require('node:path'); const childProcess = require('node:child_process'); -const got = require('got'); const semver = require('semver'); const { getCurrentBranch, ELECTRON_DIR } = require('../lib/utils'); diff --git a/script/release/release-artifact-cleanup.js b/script/release/release-artifact-cleanup.js index 356512540878..7d64ef0b1661 100755 --- a/script/release/release-artifact-cleanup.js +++ b/script/release/release-artifact-cleanup.js @@ -5,9 +5,6 @@ const args = require('minimist')(process.argv.slice(2), { string: ['tag', 'releaseID'], default: { releaseID: '' } }); -const { execSync } = require('node:child_process'); -const { GitProcess } = require('dugite'); -const { getCurrentBranch, ELECTRON_DIR } = require('../lib/utils.js'); const { Octokit } = require('@octokit/rest'); const octokit = new Octokit({ diff --git a/script/release/release.js b/script/release/release.js index e25cc60286d2..a856cf9d8aed 100755 --- a/script/release/release.js +++ b/script/release/release.js @@ -15,7 +15,6 @@ const got = require('got'); const path = require('node:path'); const semver = require('semver'); const temp = require('temp').track(); -const { URL } = require('node:url'); const { BlobServiceClient } = require('@azure/storage-blob'); const { Octokit } = require('@octokit/rest'); @@ -299,7 +298,7 @@ async function uploadShasumFile (filePath, fileName, releaseId) { } function saveShaSumFile (checksums, fileName) { - return new Promise((resolve, reject) => { + return new Promise(resolve => { temp.open(fileName, (err, info) => { if (err) { console.error(`${fail} Could not create ${fileName} file`); @@ -372,18 +371,6 @@ async function makeRelease (releaseToValidate) { } } -async function makeTempDir () { - return new Promise((resolve, reject) => { - temp.mkdir('electron-publish', (err, dirPath) => { - if (err) { - reject(err); - } else { - resolve(dirPath); - } - }); - }); -} - const SHASUM_256_FILENAME = 'SHASUMS256.txt'; const SHASUM_1_FILENAME = 'SHASUMS.txt'; diff --git a/script/release/version-bumper.js b/script/release/version-bumper.js index 78e5551b321c..f5afcd94638a 100644 --- a/script/release/version-bumper.js +++ b/script/release/version-bumper.js @@ -12,7 +12,7 @@ function parseCommandLine () { string: ['bump', 'version'], boolean: ['dryRun', 'help'], alias: { version: ['v'] }, - unknown: arg => { help = true; } + unknown: () => { help = true; } }); if (help || opts.help || !opts.bump) { console.log(` @@ -33,14 +33,6 @@ async function main () { const currentVersion = getElectronVersion(); const version = await nextVersion(opts.bump, currentVersion); - const parsed = semver.parse(version); - const components = { - major: parsed.major, - minor: parsed.minor, - patch: parsed.patch, - pre: parsed.prerelease - }; - // print would-be new version and exit early if (opts.dryRun) { console.log(`new version number would be: ${version}\n`); @@ -97,18 +89,6 @@ async function nextVersion (bumpType, version) { return version; } -function isMajorStable (bump, currentVersion) { - if (versionUtils.isBeta(currentVersion) && (bump === 'stable')) return true; - return false; -} - -function isMajorNightly (version, currentVersion) { - const parsed = semver.parse(version); - const current = semver.parse(currentVersion); - if (versionUtils.isNightly(currentVersion) && (parsed.major > current.major)) return true; - return false; -} - if (require.main === module) { main().catch((error) => { console.error(error); diff --git a/script/release/version-utils.js b/script/release/version-utils.js index d50fdedaa02c..76979621c7a8 100644 --- a/script/release/version-utils.js +++ b/script/release/version-utils.js @@ -1,13 +1,8 @@ -const path = require('node:path'); -const fs = require('node:fs'); const semver = require('semver'); const { GitProcess } = require('dugite'); -const { promisify } = require('node:util'); const { ELECTRON_DIR } = require('../lib/utils'); -const readFile = promisify(fs.readFile); - const preType = { NONE: 'none', PARTIAL: 'partial', diff --git a/script/spec-runner.js b/script/spec-runner.js index f8a32423b7ad..cf7bfc0c4169 100755 --- a/script/spec-runner.js +++ b/script/spec-runner.js @@ -183,14 +183,6 @@ async function runTestUsingElectron (specDir, testName) { console.log(`${pass} Electron ${testName} process tests passed.`); } -const specFilter = (file) => { - if (!/-spec\.[tj]s$/.test(file)) { - return false; - } else { - return true; - } -}; - async function runNativeElectronTests () { let testTargets = require('./native-test-targets.json'); const outDir = `out/${utils.getOutDir()}`; diff --git a/spec/fixtures/api/context-bridge/context-bridge-mutability/preload.js b/spec/fixtures/api/context-bridge/context-bridge-mutability/preload.js index e3d3d9abfad5..7904beb5696c 100644 --- a/spec/fixtures/api/context-bridge/context-bridge-mutability/preload.js +++ b/spec/fixtures/api/context-bridge/context-bridge-mutability/preload.js @@ -1,4 +1,4 @@ -const { contextBridge, ipcRenderer } = require('electron'); +const { contextBridge } = require('electron'); contextBridge.exposeInMainWorld('str', 'some-text'); contextBridge.exposeInMainWorld('obj', { prop: 'obj-prop' }); diff --git a/spec/fixtures/api/new-window-preload.js b/spec/fixtures/api/new-window-preload.js index 090804a618b1..ab3eb9e19ee7 100644 --- a/spec/fixtures/api/new-window-preload.js +++ b/spec/fixtures/api/new-window-preload.js @@ -1,4 +1,4 @@ -const { ipcRenderer, webFrame } = require('electron'); +const { ipcRenderer } = require('electron'); ipcRenderer.send('answer', { argv: process.argv diff --git a/spec/fixtures/api/safe-storage/decrypt-app/main.js b/spec/fixtures/api/safe-storage/decrypt-app/main.js index 249165fdcd08..72eee87044a5 100644 --- a/spec/fixtures/api/safe-storage/decrypt-app/main.js +++ b/spec/fixtures/api/safe-storage/decrypt-app/main.js @@ -1,4 +1,4 @@ -const { app, safeStorage, ipcMain } = require('electron'); +const { app, safeStorage } = require('electron'); const { promises: fs } = require('node:fs'); const path = require('node:path'); diff --git a/spec/fixtures/api/safe-storage/encrypt-app/main.js b/spec/fixtures/api/safe-storage/encrypt-app/main.js index 5f5bdc0917ef..ae4a11bff891 100644 --- a/spec/fixtures/api/safe-storage/encrypt-app/main.js +++ b/spec/fixtures/api/safe-storage/encrypt-app/main.js @@ -1,4 +1,4 @@ -const { app, safeStorage, ipcMain } = require('electron'); +const { app, safeStorage } = require('electron'); const { promises: fs } = require('node:fs'); const path = require('node:path'); @@ -7,6 +7,6 @@ const writeFile = fs.writeFile; app.whenReady().then(async () => { const encrypted = safeStorage.encryptString('plaintext'); - const encryptedString = await writeFile(pathToEncryptedString, encrypted); + await writeFile(pathToEncryptedString, encrypted); app.quit(); }); diff --git a/spec/fixtures/api/service-workers/sw-logs.js b/spec/fixtures/api/service-workers/sw-logs.js index 04e620f913a4..d8aad425dd56 100644 --- a/spec/fixtures/api/service-workers/sw-logs.js +++ b/spec/fixtures/api/service-workers/sw-logs.js @@ -1,4 +1,4 @@ -self.addEventListener('install', function (event) { +self.addEventListener('install', function () { console.log('log log'); console.info('info log'); console.warn('warn log'); diff --git a/spec/fixtures/api/service-workers/sw.js b/spec/fixtures/api/service-workers/sw.js index 7c3ad71f2bbd..bb8e767728f1 100644 --- a/spec/fixtures/api/service-workers/sw.js +++ b/spec/fixtures/api/service-workers/sw.js @@ -1,3 +1,3 @@ -self.addEventListener('install', function (event) { +self.addEventListener('install', function () { console.log('Installed'); }); diff --git a/spec/fixtures/api/singleton/main.js b/spec/fixtures/api/singleton/main.js index 4bd6433eea21..e4fbb02476dc 100644 --- a/spec/fixtures/api/singleton/main.js +++ b/spec/fixtures/api/singleton/main.js @@ -8,7 +8,7 @@ const gotTheLock = app.requestSingleInstanceLock(); app.on('second-instance', (event, args, workingDirectory) => { setImmediate(() => { - console.log(JSON.stringify(args)); + console.log(JSON.stringify(args), workingDirectory); app.exit(0); }); }); diff --git a/spec/fixtures/apps/crash/node-extra-args.js b/spec/fixtures/apps/crash/node-extra-args.js index cf8837ae09ba..0befee7fb407 100644 --- a/spec/fixtures/apps/crash/node-extra-args.js +++ b/spec/fixtures/apps/crash/node-extra-args.js @@ -1,6 +1,3 @@ -const path = require('node:path'); -const childProcess = require('node:child_process'); - process.on('message', function () { process.send(process.argv); }); diff --git a/spec/fixtures/apps/libuv-hang/renderer.js b/spec/fixtures/apps/libuv-hang/renderer.js index 5f0a2b58b514..cdbc4aab4d07 100644 --- a/spec/fixtures/apps/libuv-hang/renderer.js +++ b/spec/fixtures/apps/libuv-hang/renderer.js @@ -1,5 +1,3 @@ -const count = localStorage.getItem('count'); - const { run, ipcRenderer } = window.api; run().then(async () => { diff --git a/spec/fixtures/apps/remote-control/main.js b/spec/fixtures/apps/remote-control/main.js index d1ac3163faa1..668e9ae6fbcf 100644 --- a/spec/fixtures/apps/remote-control/main.js +++ b/spec/fixtures/apps/remote-control/main.js @@ -1,7 +1,7 @@ const { app } = require('electron'); const http = require('node:http'); const v8 = require('node:v8'); -// eslint-disable-next-line camelcase +// eslint-disable-next-line camelcase,@typescript-eslint/no-unused-vars const promises_1 = require('node:timers/promises'); if (app.commandLine.hasSwitch('boot-eval')) { diff --git a/spec/fixtures/apps/self-module-paths/main.js b/spec/fixtures/apps/self-module-paths/main.js index 6138e7983c64..b99498bf7ae2 100644 --- a/spec/fixtures/apps/self-module-paths/main.js +++ b/spec/fixtures/apps/self-module-paths/main.js @@ -1,6 +1,5 @@ // Modules to control application life and create native browser window const { app, BrowserWindow, ipcMain } = require('electron'); -const path = require('node:path'); function createWindow () { const mainWindow = new BrowserWindow({ diff --git a/spec/fixtures/chromium/other-window.js b/spec/fixtures/chromium/other-window.js index 5e516e9dfabc..9b8f76295350 100644 --- a/spec/fixtures/chromium/other-window.js +++ b/spec/fixtures/chromium/other-window.js @@ -4,7 +4,7 @@ const ints = (...args) => args.map(a => parseInt(a, 10)); const [x, y, width, height] = ints(...process.argv.slice(2)); -let w; +let w; // eslint-disable-line @typescript-eslint/no-unused-vars app.whenReady().then(() => { w = new BrowserWindow({ diff --git a/spec/fixtures/crash-cases/fs-promises-renderer-crash/index.js b/spec/fixtures/crash-cases/fs-promises-renderer-crash/index.js index a3c484be3816..7e997d030f59 100644 --- a/spec/fixtures/crash-cases/fs-promises-renderer-crash/index.js +++ b/spec/fixtures/crash-cases/fs-promises-renderer-crash/index.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow, ipcMain } = require('electron'); +const { app, BrowserWindow } = require('electron'); const path = require('node:path'); app.whenReady().then(() => { diff --git a/spec/fixtures/crash-cases/worker-multiple-destroy/worklet.js b/spec/fixtures/crash-cases/worker-multiple-destroy/worklet.js index 47ff1456f5db..3277dd5b70de 100644 --- a/spec/fixtures/crash-cases/worker-multiple-destroy/worklet.js +++ b/spec/fixtures/crash-cases/worker-multiple-destroy/worklet.js @@ -1,6 +1,7 @@ /* global registerPaint */ class CheckerboardPainter { + // eslint-disable-next-line @typescript-eslint/no-unused-vars paint (ctx, geom, properties) { const colors = ['red', 'green', 'blue']; const size = 32; diff --git a/spec/fixtures/extensions/chrome-webRequest/background.js b/spec/fixtures/extensions/chrome-webRequest/background.js index ba6f9f3f610e..7d53a6be3cd3 100644 --- a/spec/fixtures/extensions/chrome-webRequest/background.js +++ b/spec/fixtures/extensions/chrome-webRequest/background.js @@ -1,6 +1,7 @@ /* global chrome */ chrome.webRequest.onBeforeRequest.addListener( + // eslint-disable-next-line @typescript-eslint/no-unused-vars (details) => { return { cancel: true }; }, diff --git a/spec/fixtures/extensions/lazy-background-page/get-background-page.js b/spec/fixtures/extensions/lazy-background-page/get-background-page.js index a54c8391f513..10aeab0cdfca 100644 --- a/spec/fixtures/extensions/lazy-background-page/get-background-page.js +++ b/spec/fixtures/extensions/lazy-background-page/get-background-page.js @@ -2,6 +2,6 @@ window.completionPromise = new Promise((resolve) => { window.completionPromiseResolve = resolve; }); -chrome.runtime.sendMessage({ some: 'message' }, (response) => { +chrome.runtime.sendMessage({ some: 'message' }, () => { window.completionPromiseResolve(chrome.extension.getBackgroundPage().receivedMessage); }); diff --git a/spec/fixtures/extensions/lazy-background-page/runtime-get-background-page.js b/spec/fixtures/extensions/lazy-background-page/runtime-get-background-page.js index 59716d5501dd..199476999c64 100644 --- a/spec/fixtures/extensions/lazy-background-page/runtime-get-background-page.js +++ b/spec/fixtures/extensions/lazy-background-page/runtime-get-background-page.js @@ -2,7 +2,7 @@ window.completionPromise = new Promise((resolve) => { window.completionPromiseResolve = resolve; }); -chrome.runtime.sendMessage({ some: 'message' }, (response) => { +chrome.runtime.sendMessage({ some: 'message' }, () => { chrome.runtime.getBackgroundPage((bgPage) => { window.completionPromiseResolve(bgPage.receivedMessage); }); diff --git a/spec/fixtures/module/preload-context.js b/spec/fixtures/module/preload-context.js index 8dca8a018ecb..cdbee5398694 100644 --- a/spec/fixtures/module/preload-context.js +++ b/spec/fixtures/module/preload-context.js @@ -1,4 +1,4 @@ -var test = 'test'; // eslint-disable-line no-var +var test = 'test'; // eslint-disable-line no-var,@typescript-eslint/no-unused-vars const types = { require: typeof require, diff --git a/spec/fixtures/module/preload-sandbox.js b/spec/fixtures/module/preload-sandbox.js index d01cf8e0d84b..c0d285e6d8d9 100644 --- a/spec/fixtures/module/preload-sandbox.js +++ b/spec/fixtures/module/preload-sandbox.js @@ -58,6 +58,7 @@ ipcRenderer.on('touch-the-opener', () => { let errorMessage = null; try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars const openerDoc = opener.document; } catch (error) { errorMessage = error.message; diff --git a/spec/fixtures/testsnap.js b/spec/fixtures/testsnap.js index c6e1bd0a2c2e..ab1c3cd69692 100644 --- a/spec/fixtures/testsnap.js +++ b/spec/fixtures/testsnap.js @@ -1,3 +1,4 @@ -// taken from https://chromium.googlesource.com/v8/v8.git/+/HEAD/test/cctest/test-serialize.cc#1127 +// taken from https://chromium.googlesource.com/v8/v8.git/+/HEAD/test/cctest/test-serialize.cc +// eslint-disable-next-line @typescript-eslint/no-unused-vars function f () { return g() * 2; } function g () { return 43; } diff --git a/spec/lib/video-helpers.js b/spec/lib/video-helpers.js index d5538c8eab15..09c47556c9f6 100644 --- a/spec/lib/video-helpers.js +++ b/spec/lib/video-helpers.js @@ -394,8 +394,10 @@ function parseWebP (riff) { const height = tmp & 0x3FFF; const verticalScale = tmp >> 14; return { - width: width, - height: height, + width, + height, + horizontalScale, + verticalScale, data: VP8, riff: riff };