Browse Source

chore: always lint JS in docs/fiddles (#38108)

* chore: always lint JS in docs/fiddles

Co-authored-by: David Sanders <[email protected]>

* chore: update patches

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: David Sanders <[email protected]>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
trop[bot] 2 years ago
parent
commit
9f028cc45c

+ 2 - 2
docs/fiddles/features/notifications/renderer/renderer.js

@@ -2,5 +2,5 @@ const NOTIFICATION_TITLE = 'Title'
 const NOTIFICATION_BODY = 'Notification from the Renderer process. Click to log to console.'
 const CLICK_MESSAGE = 'Notification clicked!'
 
-new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY })
-  .onclick = () => document.getElementById('output').innerText = CLICK_MESSAGE
+new window.Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY })
+  .onclick = () => { document.getElementById('output').innerText = CLICK_MESSAGE }

+ 18 - 9
docs/fiddles/features/offscreen-rendering/main.js

@@ -4,16 +4,31 @@ const path = require('path')
 
 app.disableHardwareAcceleration()
 
-let win
+function createWindow () {
+  const win = new BrowserWindow({
+    width: 800,
+    height: 600,
+    webPreferences: {
+      offscreen: true
+    }
+  })
 
-app.whenReady().then(() => {
-  win = new BrowserWindow({ webPreferences: { offscreen: true } })
   win.loadURL('https://github.com')
   win.webContents.on('paint', (event, dirty, image) => {
     fs.writeFileSync('ex.png', image.toPNG())
   })
   win.webContents.setFrameRate(60)
   console.log(`The screenshot has been successfully saved to ${path.join(process.cwd(), 'ex.png')}`)
+}
+
+app.whenReady().then(() => {
+  createWindow()
+
+  app.on('activate', () => {
+    if (BrowserWindow.getAllWindows().length === 0) {
+      createWindow()
+    }
+  })
 })
 
 app.on('window-all-closed', () => {
@@ -21,9 +36,3 @@ app.on('window-all-closed', () => {
     app.quit()
   }
 })
-
-app.on('activate', () => {
-  if (BrowserWindow.getAllWindows().length === 0) {
-    createWindow()
-  }
-})

+ 2 - 3
docs/fiddles/features/web-bluetooth/main.js

@@ -1,7 +1,7 @@
 const { app, BrowserWindow, ipcMain } = require('electron')
 const path = require('path')
 
-let bluetoothPinCallback 
+let bluetoothPinCallback
 let selectBluetoothCallback
 
 function createWindow () {
@@ -24,13 +24,12 @@ function createWindow () {
     } else {
       // The device wasn't found so we need to either wait longer (eg until the
       // device is turned on) or until the user cancels the request
-    }     
+    }
   })
 
   ipcMain.on('cancel-bluetooth-request', (event) => {
     selectBluetoothCallback('')
   })
-  
 
   // Listen for a message from the renderer to get the response for the Bluetooth pairing.
   ipcMain.on('bluetooth-pairing-response', (event, response) => {

+ 4 - 4
docs/fiddles/features/web-bluetooth/renderer.js

@@ -7,7 +7,7 @@ async function testIt () {
 
 document.getElementById('clickme').addEventListener('click', testIt)
 
-function cancelRequest() {
+function cancelRequest () {
   window.electronAPI.cancelBluetoothRequest()
 }
 
@@ -18,15 +18,15 @@ window.electronAPI.bluetoothPairingRequest((event, details) => {
 
   switch (details.pairingKind) {
     case 'confirm': {
-      response.confirmed = confirm(`Do you want to connect to device ${details.deviceId}?`)
+      response.confirmed = window.confirm(`Do you want to connect to device ${details.deviceId}?`)
       break
     }
     case 'confirmPin': {
-      response.confirmed = confirm(`Does the pin ${details.pin} match the pin displayed on device ${details.deviceId}?`)
+      response.confirmed = window.confirm(`Does the pin ${details.pin} match the pin displayed on device ${details.deviceId}?`)
       break
     }
     case 'providePin': {
-      const pin = prompt(`Please provide a pin for ${details.deviceId}.`)
+      const pin = window.prompt(`Please provide a pin for ${details.deviceId}.`)
       if (pin) {
         response.pin = pin
         response.confirmed = true

+ 1 - 0
docs/fiddles/features/web-serial/main.js

@@ -23,6 +23,7 @@ function createWindow () {
     if (portList && portList.length > 0) {
       callback(portList[0].portId)
     } else {
+      // eslint-disable-next-line standard/no-callback-literal
       callback('') // Could not find any matching devices
     }
   })

+ 1 - 1
docs/fiddles/features/web-usb/renderer.js

@@ -20,7 +20,7 @@ async function testIt () {
     const grantedDevice = await navigator.usb.requestDevice({
       filters: []
     })
-    grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`
+    grantedDeviceList += `<hr>${getDeviceDetails(grantedDevice)}</hr>`
   } catch (ex) {
     if (ex.name === 'NotFoundError') {
       grantedDeviceList = noDevicesFoundMsg

+ 0 - 14
docs/fiddles/native-ui/external-links-file-manager/external-links/renderer.js

@@ -5,17 +5,3 @@ const exLinksBtn = document.getElementById('open-ex-links')
 exLinksBtn.addEventListener('click', (event) => {
   shell.openExternal('https://electronjs.org')
 })
-
-const OpenAllOutboundLinks = () => {
-  const links = document.querySelectorAll('a[href]')
-
-  Array.prototype.forEach.call(links, (link) => {
-    const url = link.getAttribute('href')
-    if (url.indexOf('http') === 0) {
-      link.addEventListener('click', (e) => {
-        e.preventDefault()
-        shell.openExternal(url)
-      })
-    }
-  })
-}

+ 1 - 1
docs/fiddles/system/clipboard/copy/renderer.js

@@ -4,5 +4,5 @@ const copyInput = document.getElementById('copy-to-input')
 copyBtn.addEventListener('click', () => {
   if (copyInput.value !== '') copyInput.value = ''
   copyInput.placeholder = 'Copied! Paste here to see.'
-  clipboard.writeText('Electron Demo!')
+  window.clipboard.writeText('Electron Demo!')
 })

+ 2 - 2
docs/fiddles/system/clipboard/paste/renderer.js

@@ -1,7 +1,7 @@
 const pasteBtn = document.getElementById('paste-to')
 
 pasteBtn.addEventListener('click', async () => {
-  await clipboard.writeText('What a demo!')
-  const message = `Clipboard contents: ${await clipboard.readText()}`
+  await window.clipboard.writeText('What a demo!')
+  const message = `Clipboard contents: ${await window.clipboard.readText()}`
   document.getElementById('paste-from').innerHTML = message
 })

+ 4 - 3
docs/fiddles/system/system-app-user-information/app-information/renderer.js

@@ -1,7 +1,7 @@
-const { ipcRenderer } = require('electron')
+const { ipcRenderer, shell } = require('electron')
 
 const appInfoBtn = document.getElementById('app-info')
-const electron_doc_link = document.querySelectorAll('a[href]')
+const electronDocLink = document.querySelectorAll('a[href]')
 
 appInfoBtn.addEventListener('click', () => {
   ipcRenderer.send('get-app-path')
@@ -12,7 +12,8 @@ ipcRenderer.on('got-app-path', (event, path) => {
   document.getElementById('got-app-info').innerHTML = message
 })
 
-electron_doc_link.addEventListener('click', (e) => {
+electronDocLink.addEventListener('click', (e) => {
   e.preventDefault()
+  const url = e.target.getAttribute('href')
   shell.openExternal(url)
 })

+ 1 - 1
docs/fiddles/tutorial-preload/renderer.js

@@ -1,2 +1,2 @@
 const information = document.getElementById('info')
-information.innerText = `This app is using Chrome (v${versions.chrome()}), Node.js (v${versions.node()}), and Electron (v${versions.electron()})`
+information.innerText = `This app is using Chrome (v${window.versions.chrome()}), Node.js (v${window.versions.node()}), and Electron (v${window.versions.electron()})`

+ 12 - 14
docs/fiddles/windows/manage-windows/frameless-window/main.js

@@ -23,23 +23,21 @@ function createWindow () {
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 // Some APIs can only be used after this event occurs.
-app.whenReady().then(createWindow)
+app.whenReady().then(() => {
+  createWindow()
 
-// Quit when all windows are closed.
-app.on('window-all-closed', function () {
-  // On macOS it is common for applications and their menu bar
-  // to stay active until the user quits explicitly with Cmd + Q
-  if (process.platform !== 'darwin') {
-    app.quit()
-  }
+  app.on('activate', function () {
+    // On macOS it's common to re-create a window in the app when the
+    // dock icon is clicked and there are no other windows open.
+    if (BrowserWindow.getAllWindows().length === 0) createWindow()
+  })
 })
 
-app.on('activate', function () {
-  // On macOS it is common to re-create a window in the app when the
-  // dock icon is clicked and there are no other windows open.
-  if (mainWindow === null) {
-    createWindow()
-  }
+// Quit when all windows are closed, except on macOS. There, it's common
+// for applications and their menu bar to stay active until the user quits
+// explicitly with Cmd + Q.
+app.on('window-all-closed', function () {
+  if (process.platform !== 'darwin') app.quit()
 })
 
 // In this file you can include the rest of your app's specific main process

+ 13 - 15
docs/fiddles/windows/manage-windows/manage-window-state/main.js

@@ -18,7 +18,7 @@ ipcMain.on('create-demo-window', (event) => {
 
 function createWindow () {
   // Create the browser window.
-  mainWindow = new BrowserWindow({
+  const mainWindow = new BrowserWindow({
     width: 800,
     height: 600,
     webPreferences: {
@@ -33,23 +33,21 @@ function createWindow () {
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 // Some APIs can only be used after this event occurs.
-app.whenReady().then(createWindow)
+app.whenReady().then(() => {
+  createWindow()
 
-// Quit when all windows are closed.
-app.on('window-all-closed', function () {
-  // On macOS it is common for applications and their menu bar
-  // to stay active until the user quits explicitly with Cmd + Q
-  if (process.platform !== 'darwin') {
-    app.quit()
-  }
+  app.on('activate', function () {
+    // On macOS it's common to re-create a window in the app when the
+    // dock icon is clicked and there are no other windows open.
+    if (BrowserWindow.getAllWindows().length === 0) createWindow()
+  })
 })
 
-app.on('activate', function () {
-  // On macOS it is common to re-create a window in the app when the
-  // dock icon is clicked and there are no other windows open.
-  if (mainWindow === null) {
-    createWindow()
-  }
+// Quit when all windows are closed, except on macOS. There, it's common
+// for applications and their menu bar to stay active until the user quits
+// explicitly with Cmd + Q.
+app.on('window-all-closed', function () {
+  if (process.platform !== 'darwin') app.quit()
 })
 
 // In this file you can include the rest of your app's specific main process

+ 12 - 14
docs/fiddles/windows/manage-windows/new-window/main.js

@@ -23,23 +23,21 @@ function createWindow () {
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 // Some APIs can only be used after this event occurs.
-app.whenReady().then(createWindow)
+app.whenReady().then(() => {
+  createWindow()
 
-// Quit when all windows are closed.
-app.on('window-all-closed', function () {
-  // On macOS it is common for applications and their menu bar
-  // to stay active until the user quits explicitly with Cmd + Q
-  if (process.platform !== 'darwin') {
-    app.quit()
-  }
+  app.on('activate', function () {
+    // On macOS it's common to re-create a window in the app when the
+    // dock icon is clicked and there are no other windows open.
+    if (BrowserWindow.getAllWindows().length === 0) createWindow()
+  })
 })
 
-app.on('activate', function () {
-  // On macOS it is common to re-create a window in the app when the
-  // dock icon is clicked and there are no other windows open.
-  if (mainWindow === null) {
-    createWindow()
-  }
+// Quit when all windows are closed, except on macOS. There, it's common
+// for applications and their menu bar to stay active until the user quits
+// explicitly with Cmd + Q.
+app.on('window-all-closed', function () {
+  if (process.platform !== 'darwin') app.quit()
 })
 
 // In this file you can include the rest of your app's specific main process

+ 12 - 14
docs/fiddles/windows/manage-windows/window-events/main.js

@@ -41,23 +41,21 @@ function createWindow () {
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
 // Some APIs can only be used after this event occurs.
-app.whenReady().then(createWindow)
+app.whenReady().then(() => {
+  createWindow()
 
-// Quit when all windows are closed.
-app.on('window-all-closed', function () {
-  // On macOS it is common for applications and their menu bar
-  // to stay active until the user quits explicitly with Cmd + Q
-  if (process.platform !== 'darwin') {
-    app.quit()
-  }
+  app.on('activate', function () {
+    // On macOS it's common to re-create a window in the app when the
+    // dock icon is clicked and there are no other windows open.
+    if (BrowserWindow.getAllWindows().length === 0) createWindow()
+  })
 })
 
-app.on('activate', function () {
-  // On macOS it is common to re-create a window in the app when the
-  // dock icon is clicked and there are no other windows open.
-  if (mainWindow === null) {
-    createWindow()
-  }
+// Quit when all windows are closed, except on macOS. There, it's common
+// for applications and their menu bar to stay active until the user quits
+// explicitly with Cmd + Q.
+app.on('window-all-closed', function () {
+  if (process.platform !== 'darwin') app.quit()
 })
 
 // In this file you can include the rest of your app's specific main process

+ 1 - 1
package.json

@@ -94,7 +94,7 @@
     "lint:objc": "node ./script/lint.js --objc",
     "lint:py": "node ./script/lint.js --py",
     "lint:gn": "node ./script/lint.js --gn",
-    "lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run create-typescript-definitions && npm run lint:docs-relative-links && npm run lint:markdownlint",
+    "lint:docs": "remark docs -qf && npm run lint:js-in-markdown && npm run create-typescript-definitions && npm run lint:docs-fiddles && npm run lint:docs-relative-links && npm run lint:markdownlint",
     "lint:docs-fiddles": "standard \"docs/fiddles/**/*.js\"",
     "lint:docs-relative-links": "ts-node script/lint-docs-links.ts",
     "lint:markdownlint": "markdownlint -r ./script/markdownlint-emd001.js \"*.md\" \"docs/**/*.md\"",

+ 1 - 1
patches/chromium/cherry-pick-ec53103cc72d.patch

@@ -38,7 +38,7 @@ Bot-Commit: chromium-autoroll <[email protected]
 Cr-Commit-Position: refs/heads/main@{#1129520}
 
 diff --git a/DEPS b/DEPS
-index 9977dd1a5f299d13d833e7bf266ebd5f3090ac22..1054192d132f42be5130bcc11a2aa9023fbb615a 100644
+index 14b54b64292172381b677f0166f9d530c48d7b65..67300d129c39a5dfe89cb5a015afa203a291ad36 100644
 --- a/DEPS
 +++ b/DEPS
 @@ -299,7 +299,7 @@ vars = {