chore: initial linting fixes for JS in docs/fiddles (#37689)

This commit is contained in:
David Sanders 2023-04-05 06:42:20 -07:00 committed by GitHub
parent be32740991
commit db27b9f433
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 122 additions and 134 deletions

View file

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, nativeImage, NativeImage } = require('electron') const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path') const path = require('path')
const fs = require('fs') const fs = require('fs')
const https = require('https') const https = require('https')
@ -15,23 +15,23 @@ function createWindow() {
win.loadFile('index.html') win.loadFile('index.html')
} }
const iconName = path.join(__dirname, 'iconForDragAndDrop.png'); const iconName = path.join(__dirname, 'iconForDragAndDrop.png')
const icon = fs.createWriteStream(iconName); const icon = fs.createWriteStream(iconName)
// Create a new file to copy - you can also copy existing files. // Create a new file to copy - you can also copy existing files.
fs.writeFileSync(path.join(__dirname, 'drag-and-drop-1.md'), '# First file to test drag and drop') fs.writeFileSync(path.join(__dirname, 'drag-and-drop-1.md'), '# First file to test drag and drop')
fs.writeFileSync(path.join(__dirname, 'drag-and-drop-2.md'), '# Second file to test drag and drop') fs.writeFileSync(path.join(__dirname, 'drag-and-drop-2.md'), '# Second file to test drag and drop')
https.get('https://img.icons8.com/ios/452/drag-and-drop.png', (response) => { https.get('https://img.icons8.com/ios/452/drag-and-drop.png', (response) => {
response.pipe(icon); response.pipe(icon)
}); })
app.whenReady().then(createWindow) app.whenReady().then(createWindow)
ipcMain.on('ondragstart', (event, filePath) => { ipcMain.on('ondragstart', (event, filePath) => {
event.sender.startDrag({ event.sender.startDrag({
file: path.join(__dirname, filePath), file: path.join(__dirname, filePath),
icon: iconName, icon: iconName
}) })
}) })

View file

@ -3,7 +3,7 @@ const { app, BrowserWindow, globalShortcut } = require('electron')
function createWindow () { function createWindow () {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600
}) })
win.loadFile('index.html') win.loadFile('index.html')

View file

@ -3,7 +3,7 @@ const { app, BrowserWindow, Menu, MenuItem } = require('electron')
function createWindow () { function createWindow () {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600
}) })
win.loadFile('index.html') win.loadFile('index.html')

View file

@ -1,17 +1,15 @@
// Modules to control application life and create native browser window // Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron') const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow () { function createWindow () {
// Create the browser window. // Create the browser window.
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600
}) })
// and load the index.html of the app. // and load the index.html of the app.
mainWindow.loadFile('index.html') mainWindow.loadFile('index.html')
} }
// This method will be called when Electron has finished // This method will be called when Electron has finished

View file

@ -1,6 +1,6 @@
function handleKeyPress (event) { function handleKeyPress (event) {
// You can put code here to handle the keypress. // You can put code here to handle the keypress.
document.getElementById("last-keypress").innerText = event.key document.getElementById('last-keypress').innerText = event.key
console.log(`You pressed ${event.key}`) console.log(`You pressed ${event.key}`)
} }

View file

@ -3,7 +3,7 @@ const { app, BrowserWindow, Menu } = require('electron')
function createWindow () { function createWindow () {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600
}) })
win.loadFile('index.html') win.loadFile('index.html')

View file

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

View file

@ -1,5 +1,5 @@
const { app, BrowserWindow } = require('electron') const { app, BrowserWindow } = require('electron')
const os = require('os'); const os = require('os')
function createWindow () { function createWindow () {
const win = new BrowserWindow({ const win = new BrowserWindow({

View file

@ -38,7 +38,6 @@ function createWindow () {
}) })
mainWindow.webContents.session.setBluetoothPairingHandler((details, callback) => { mainWindow.webContents.session.setBluetoothPairingHandler((details, callback) => {
bluetoothPinCallback = callback bluetoothPinCallback = callback
// Send a message to the renderer to prompt the user to confirm the pairing. // Send a message to the renderer to prompt the user to confirm the pairing.
mainWindow.webContents.send('bluetooth-pairing-request', details) mainWindow.webContents.send('bluetooth-pairing-request', details)

View file

@ -1,5 +1,4 @@
const { app, BrowserWindow } = require('electron') const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow () { function createWindow () {
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({

View file

@ -1,5 +1,4 @@
const { app, BrowserWindow } = require('electron') const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow () { function createWindow () {
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
@ -8,7 +7,6 @@ function createWindow () {
}) })
mainWindow.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => { mainWindow.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
// Add listeners to handle ports being added or removed before the callback for `select-serial-port` // Add listeners to handle ports being added or removed before the callback for `select-serial-port`
// is called. // is called.
mainWindow.webContents.session.on('serial-port-added', (event, port) => { mainWindow.webContents.session.on('serial-port-added', (event, port) => {

View file

@ -2,10 +2,10 @@ async function testIt() {
const filters = [ const filters = [
{ usbVendorId: 0x2341, usbProductId: 0x0043 }, { usbVendorId: 0x2341, usbProductId: 0x0043 },
{ usbVendorId: 0x2341, usbProductId: 0x0001 } { usbVendorId: 0x2341, usbProductId: 0x0001 }
]; ]
try { try {
const port = await navigator.serial.requestPort({filters}); const port = await navigator.serial.requestPort({ filters })
const portInfo = port.getInfo(); const portInfo = port.getInfo()
document.getElementById('device-name').innerHTML = `vendorId: ${portInfo.usbVendorId} | productId: ${portInfo.usbProductId} ` document.getElementById('device-name').innerHTML = `vendorId: ${portInfo.usbVendorId} | productId: ${portInfo.usbProductId} `
} catch (ex) { } catch (ex) {
if (ex.name === 'NotFoundError') { if (ex.name === 'NotFoundError') {

View file

@ -1,5 +1,4 @@
const { app, BrowserWindow } = require('electron') const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow () { function createWindow () {
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
@ -25,7 +24,7 @@ function createWindow () {
event.preventDefault() event.preventDefault()
if (details.deviceList && details.deviceList.length > 0) { if (details.deviceList && details.deviceList.length > 0) {
const deviceToReturn = details.deviceList.find((device) => { const deviceToReturn = details.deviceList.find((device) => {
if (!grantedDeviceThroughPermHandler || (device.deviceId != grantedDeviceThroughPermHandler.deviceId)) { if (!grantedDeviceThroughPermHandler || (device.deviceId !== grantedDeviceThroughPermHandler.deviceId)) {
return true return true
} }
}) })

View file

@ -21,7 +21,6 @@ async function testIt() {
filters: [] filters: []
}) })
grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>` grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`
} catch (ex) { } catch (ex) {
if (ex.name === 'NotFoundError') { if (ex.name === 'NotFoundError') {
grantedDeviceList = noDevicesFoundMsg grantedDeviceList = noDevicesFoundMsg

View file

@ -3,4 +3,4 @@ const titleInput = document.getElementById('title')
setButton.addEventListener('click', () => { setButton.addEventListener('click', () => {
const title = titleInput.value const title = titleInput.value
window.electronAPI.setTitle(title) window.electronAPI.setTitle(title)
}); })

View file

@ -4,7 +4,7 @@ const path = require('path')
async function handleFileOpen () { async function handleFileOpen () {
const { canceled, filePaths } = await dialog.showOpenDialog() const { canceled, filePaths } = await dialog.showOpenDialog()
if (canceled) { if (canceled) {
return
} else { } else {
return filePaths[0] return filePaths[0]
} }

View file

@ -14,11 +14,11 @@ function createWindow () {
submenu: [ submenu: [
{ {
click: () => mainWindow.webContents.send('update-counter', 1), click: () => mainWindow.webContents.send('update-counter', 1),
label: 'Increment', label: 'Increment'
}, },
{ {
click: () => mainWindow.webContents.send('update-counter', -1), click: () => mainWindow.webContents.send('update-counter', -1),
label: 'Decrement', label: 'Decrement'
} }
] ]
} }

View file

@ -52,7 +52,6 @@ app.on('activate', function () {
} }
}) })
ipcMain.on('open-information-dialog', event => { ipcMain.on('open-information-dialog', event => {
const options = { const options = {
type: 'info', type: 'info',
@ -65,6 +64,5 @@ ipcMain.on('open-information-dialog', event => {
}) })
}) })
// In this file you can include the rest of your app's specific main process // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here. // code. You can also put them in separate files and require them here.

View file

@ -52,7 +52,6 @@ app.on('activate', function () {
} }
}) })
ipcMain.on('open-file-dialog', event => { ipcMain.on('open-file-dialog', event => {
dialog.showOpenDialog( dialog.showOpenDialog(
{ {

View file

@ -28,4 +28,3 @@ app.on('window-all-closed', () => {
app.quit() app.quit()
} }
}) })

View file

@ -8,4 +8,3 @@ window.addEventListener('DOMContentLoaded', () => {
replaceText(`${type}-version`, process.versions[type]) replaceText(`${type}-version`, process.versions[type])
} }
}) })

View file

@ -2,7 +2,7 @@
const { app, BrowserWindow, ipcMain, shell, dialog } = require('electron') const { app, BrowserWindow, ipcMain, shell, dialog } = require('electron')
const path = require('path') const path = require('path')
let mainWindow; let mainWindow
if (process.defaultApp) { if (process.defaultApp) {
if (process.argv.length >= 2) { if (process.argv.length >= 2) {
@ -43,7 +43,7 @@ function createWindow () {
width: 800, width: 800,
height: 600, height: 600,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js')
} }
}) })

View file

@ -6,6 +6,6 @@ const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld( contextBridge.exposeInMainWorld(
'shell', 'shell',
{ {
open: () => ipcRenderer.send('shell:open'), open: () => ipcRenderer.send('shell:open')
} }
) )

View file

@ -4,5 +4,5 @@
// Binds the buttons to the context bridge API. // Binds the buttons to the context bridge API.
document.getElementById('open-in-browser').addEventListener('click', () => { document.getElementById('open-in-browser').addEventListener('click', () => {
shell.open(); window.shell.open()
}); })

View file

@ -1,26 +1,26 @@
const { app, BrowserWindow } = require('electron'); const { app, BrowserWindow } = require('electron')
const createWindow = () => { const createWindow = () => {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600
}); })
win.loadFile('index.html'); win.loadFile('index.html')
}; }
app.whenReady().then(() => { app.whenReady().then(() => {
createWindow(); createWindow()
app.on('activate', () => { app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) { if (BrowserWindow.getAllWindows().length === 0) {
createWindow(); createWindow()
} }
}); })
}); })
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit(); app.quit()
} }
}); })

View file

@ -1,30 +1,30 @@
const { app, BrowserWindow } = require('electron'); const { app, BrowserWindow } = require('electron')
const path = require('path'); const path = require('path')
const createWindow = () => { const createWindow = () => {
const win = new BrowserWindow({ const win = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js')
}, }
}); })
win.loadFile('index.html'); win.loadFile('index.html')
}; }
app.whenReady().then(() => { app.whenReady().then(() => {
createWindow(); createWindow()
app.on('activate', () => { app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) { if (BrowserWindow.getAllWindows().length === 0) {
createWindow(); createWindow()
} }
}); })
}); })
app.on('window-all-closed', () => { app.on('window-all-closed', () => {
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit(); app.quit()
} }
}); })

View file

@ -1,7 +1,7 @@
const { contextBridge } = require('electron'); const { contextBridge } = require('electron')
contextBridge.exposeInMainWorld('versions', { contextBridge.exposeInMainWorld('versions', {
node: () => process.versions.node, node: () => process.versions.node,
chrome: () => process.versions.chrome, chrome: () => process.versions.chrome,
electron: () => process.versions.electron, electron: () => process.versions.electron
}); })

View file

@ -1,2 +1,2 @@
const information = document.getElementById('info'); 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${versions.chrome()}), Node.js (v${versions.node()}), and Electron (v${versions.electron()})`

View file

@ -1,5 +1,5 @@
// Modules to control application life and create native browser window // Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron') const { app, BrowserWindow, ipcMain } = require('electron')
ipcMain.on('create-frameless-window', (event, { url }) => { ipcMain.on('create-frameless-window', (event, { url }) => {
const win = new BrowserWindow({ frame: false }) const win = new BrowserWindow({ frame: false })

View file

@ -5,10 +5,10 @@ const link = document.getElementById('browser-window-link')
newWindowBtn.addEventListener('click', (event) => { newWindowBtn.addEventListener('click', (event) => {
const url = 'https://electronjs.org' const url = 'https://electronjs.org'
ipcRenderer.send('new-window', { url, width: 400, height: 320 }); ipcRenderer.send('new-window', { url, width: 400, height: 320 })
}) })
link.addEventListener('click', (e) => { link.addEventListener('click', (e) => {
e.preventDefault() e.preventDefault()
shell.openExternal("https://electronjs.org/docs/api/browser-window") shell.openExternal('https://electronjs.org/docs/api/browser-window')
}) })

View file

@ -95,6 +95,7 @@
"lint:py": "node ./script/lint.js --py", "lint:py": "node ./script/lint.js --py",
"lint:gn": "node ./script/lint.js --gn", "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-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:docs-relative-links": "ts-node script/lint-docs-links.ts",
"lint:markdownlint": "markdownlint -r ./script/markdownlint-emd001.js \"*.md\" \"docs/**/*.md\"", "lint:markdownlint": "markdownlint -r ./script/markdownlint-emd001.js \"*.md\" \"docs/**/*.md\"",
"lint:js-in-markdown": "standard-markdown docs", "lint:js-in-markdown": "standard-markdown docs",