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,9 +1,9 @@
const { app, BrowserWindow, ipcMain, nativeImage, NativeImage } = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const fs = require('fs')
const https = require('https')
function createWindow() {
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
@ -15,23 +15,23 @@ function createWindow() {
win.loadFile('index.html')
}
const iconName = path.join(__dirname, 'iconForDragAndDrop.png');
const icon = fs.createWriteStream(iconName);
const iconName = path.join(__dirname, 'iconForDragAndDrop.png')
const icon = fs.createWriteStream(iconName)
// 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-2.md'), '# Second file to test drag and drop')
https.get('https://img.icons8.com/ios/452/drag-and-drop.png', (response) => {
response.pipe(icon);
});
response.pipe(icon)
})
app.whenReady().then(createWindow)
ipcMain.on('ondragstart', (event, filePath) => {
event.sender.startDrag({
file: path.join(__dirname, filePath),
icon: iconName,
icon: iconName
})
})

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
function handleKeyPress (event) {
// 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}`)
}

View file

@ -3,7 +3,7 @@ const { app, BrowserWindow, Menu } = require('electron')
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
height: 600
})
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!'
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 os = require('os');
const os = require('os')
function createWindow () {
const win = new BrowserWindow({

View file

@ -1,4 +1,4 @@
const {app, BrowserWindow, ipcMain} = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
let bluetoothPinCallback
@ -38,7 +38,6 @@ function createWindow () {
})
mainWindow.webContents.session.setBluetoothPairingHandler((details, callback) => {
bluetoothPinCallback = callback
// Send a message to the renderer to prompt the user to confirm the pairing.
mainWindow.webContents.send('bluetooth-pairing-request', details)

View file

@ -4,4 +4,4 @@ contextBridge.exposeInMainWorld('electronAPI', {
cancelBluetoothRequest: (callback) => ipcRenderer.send('cancel-bluetooth-request', callback),
bluetoothPairingRequest: (callback) => ipcRenderer.on('bluetooth-pairing-request', callback),
bluetoothPairingResponse: (response) => ipcRenderer.send('bluetooth-pairing-response', response)
})
})

View file

@ -1,11 +1,11 @@
async function testIt() {
async function testIt () {
const device = await navigator.bluetooth.requestDevice({
acceptAllDevices: true
})
document.getElementById('device-name').innerHTML = device.name || `ID: ${device.id}`
}
document.getElementById('clickme').addEventListener('click',testIt)
document.getElementById('clickme').addEventListener('click', testIt)
function cancelRequest() {
window.electronAPI.cancelBluetoothRequest()
@ -37,4 +37,4 @@ window.electronAPI.bluetoothPairingRequest((event, details) => {
}
window.electronAPI.bluetoothPairingResponse(response)
})
})

View file

@ -1,5 +1,4 @@
const {app, BrowserWindow} = require('electron')
const path = require('path')
const { app, BrowserWindow } = require('electron')
function createWindow () {
const mainWindow = new BrowserWindow({
@ -8,16 +7,16 @@ function createWindow () {
})
mainWindow.webContents.session.on('select-hid-device', (event, details, callback) => {
//Add events to handle devices being added or removed before the callback on
//`select-hid-device` is called.
// Add events to handle devices being added or removed before the callback on
// `select-hid-device` is called.
mainWindow.webContents.session.on('hid-device-added', (event, device) => {
console.log('hid-device-added FIRED WITH', device)
//Optionally update details.deviceList
// Optionally update details.deviceList
})
mainWindow.webContents.session.on('hid-device-removed', (event, device) => {
console.log('hid-device-removed FIRED WITH', device)
//Optionally update details.deviceList
// Optionally update details.deviceList
})
event.preventDefault()

View file

@ -1,4 +1,4 @@
async function testIt() {
async function testIt () {
const grantedDevices = await navigator.hid.getDevices()
let grantedDeviceList = ''
grantedDevices.forEach(device => {
@ -10,10 +10,10 @@ async function testIt() {
})
grantedDeviceList = ''
grantedDevices2.forEach(device => {
grantedDevices2.forEach(device => {
grantedDeviceList += `<hr>${device.productName}</hr>`
})
document.getElementById('granted-devices2').innerHTML = grantedDeviceList
}
document.getElementById('clickme').addEventListener('click',testIt)
document.getElementById('clickme').addEventListener('click', testIt)

View file

@ -1,5 +1,4 @@
const {app, BrowserWindow} = require('electron')
const path = require('path')
const { app, BrowserWindow } = require('electron')
function createWindow () {
const mainWindow = new BrowserWindow({
@ -8,24 +7,23 @@ function createWindow () {
})
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`
//is called.
// Add listeners to handle ports being added or removed before the callback for `select-serial-port`
// is called.
mainWindow.webContents.session.on('serial-port-added', (event, port) => {
console.log('serial-port-added FIRED WITH', port)
//Optionally update portList to add the new port
// Optionally update portList to add the new port
})
mainWindow.webContents.session.on('serial-port-removed', (event, port) => {
console.log('serial-port-removed FIRED WITH', port)
//Optionally update portList to remove the port
// Optionally update portList to remove the port
})
event.preventDefault()
if (portList && portList.length > 0) {
callback(portList[0].portId)
} else {
callback('') //Could not find any matching devices
callback('') // Could not find any matching devices
}
})

View file

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

View file

@ -1,5 +1,4 @@
const {app, BrowserWindow} = require('electron')
const path = require('path')
const { app, BrowserWindow } = require('electron')
function createWindow () {
const mainWindow = new BrowserWindow({
@ -10,22 +9,22 @@ function createWindow () {
let grantedDeviceThroughPermHandler
mainWindow.webContents.session.on('select-usb-device', (event, details, callback) => {
//Add events to handle devices being added or removed before the callback on
//`select-usb-device` is called.
// Add events to handle devices being added or removed before the callback on
// `select-usb-device` is called.
mainWindow.webContents.session.on('usb-device-added', (event, device) => {
console.log('usb-device-added FIRED WITH', device)
//Optionally update details.deviceList
// Optionally update details.deviceList
})
mainWindow.webContents.session.on('usb-device-removed', (event, device) => {
console.log('usb-device-removed FIRED WITH', device)
//Optionally update details.deviceList
// Optionally update details.deviceList
})
event.preventDefault()
if (details.deviceList && details.deviceList.length > 0) {
const deviceToReturn = details.deviceList.find((device) => {
if (!grantedDeviceThroughPermHandler || (device.deviceId != grantedDeviceThroughPermHandler.deviceId)) {
const deviceToReturn = details.deviceList.find((device) => {
if (!grantedDeviceThroughPermHandler || (device.deviceId !== grantedDeviceThroughPermHandler.deviceId)) {
return true
}
})

View file

@ -1,8 +1,8 @@
function getDeviceDetails(device) {
function getDeviceDetails (device) {
return device.productName || `Unknown device ${device.deviceId}`
}
async function testIt() {
async function testIt () {
const noDevicesFoundMsg = 'No devices found'
const grantedDevices = await navigator.usb.getDevices()
let grantedDeviceList = ''
@ -21,7 +21,6 @@ async function testIt() {
filters: []
})
grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`
} catch (ex) {
if (ex.name === 'NotFoundError') {
grantedDeviceList = noDevicesFoundMsg
@ -30,4 +29,4 @@ async function testIt() {
document.getElementById('granted-devices2').innerHTML = grantedDeviceList
}
document.getElementById('clickme').addEventListener('click',testIt)
document.getElementById('clickme').addEventListener('click', testIt)

View file

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

View file

@ -1,5 +1,5 @@
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
setTitle: (title) => ipcRenderer.send('set-title', title)
setTitle: (title) => ipcRenderer.send('set-title', title)
})

View file

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

View file

@ -1,10 +1,10 @@
const {app, BrowserWindow, ipcMain, dialog} = require('electron')
const { app, BrowserWindow, ipcMain, dialog } = require('electron')
const path = require('path')
async function handleFileOpen() {
async function handleFileOpen () {
const { canceled, filePaths } = await dialog.showOpenDialog()
if (canceled) {
return
} else {
return filePaths[0]
}

View file

@ -1,5 +1,5 @@
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI',{
contextBridge.exposeInMainWorld('electronAPI', {
openFile: () => ipcRenderer.invoke('dialog:openFile')
})

View file

@ -1,4 +1,4 @@
const {app, BrowserWindow, Menu, ipcMain} = require('electron')
const { app, BrowserWindow, Menu, ipcMain } = require('electron')
const path = require('path')
function createWindow () {
@ -12,14 +12,14 @@ function createWindow () {
{
label: app.name,
submenu: [
{
click: () => mainWindow.webContents.send('update-counter', 1),
label: 'Increment',
},
{
click: () => mainWindow.webContents.send('update-counter', -1),
label: 'Decrement',
}
{
click: () => mainWindow.webContents.send('update-counter', 1),
label: 'Increment'
},
{
click: () => mainWindow.webContents.send('update-counter', -1),
label: 'Decrement'
}
]
}

View file

@ -1,8 +1,8 @@
const counter = document.getElementById('counter')
window.electronAPI.handleCounter((event, value) => {
const oldValue = Number(counter.innerText)
const newValue = oldValue + value
counter.innerText = newValue
event.sender.send('counter-value', newValue)
const oldValue = Number(counter.innerText)
const newValue = oldValue + value
counter.innerText = newValue
event.sender.send('counter-value', newValue)
})

View file

@ -15,4 +15,4 @@ Array.prototype.forEach.call(links, (link) => {
shell.openExternal(url)
})
}
})
})

View file

@ -52,7 +52,6 @@ app.on('activate', function () {
}
})
ipcMain.on('open-information-dialog', event => {
const options = {
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
// code. You can also put them in separate files and require them here.

View file

@ -22,4 +22,4 @@ Array.prototype.forEach.call(links, (link) => {
shell.openExternal(url)
})
}
})
})

View file

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

View file

@ -20,4 +20,4 @@ Array.prototype.forEach.call(links, (link) => {
shell.openExternal(url)
})
}
})
})

View file

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

View file

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

View file

@ -2,14 +2,14 @@
const { app, BrowserWindow, ipcMain, shell, dialog } = require('electron')
const path = require('path')
let mainWindow;
let mainWindow
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient('electron-fiddle', process.execPath, [path.resolve(process.argv[1])])
}
} else {
app.setAsDefaultProtocolClient('electron-fiddle')
app.setAsDefaultProtocolClient('electron-fiddle')
}
const gotTheLock = app.requestSingleInstanceLock()
@ -24,7 +24,7 @@ if (!gotTheLock) {
mainWindow.focus()
}
dialog.showErrorBox('Welcome Back', `You arrived from: ${commandLine.pop().slice(0,-1)}`)
dialog.showErrorBox('Welcome Back', `You arrived from: ${commandLine.pop().slice(0, -1)}`)
})
// Create mainWindow, load the rest of the app, etc...
@ -43,7 +43,7 @@ function createWindow () {
width: 800,
height: 600,
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(
'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.
document.getElementById('open-in-browser').addEventListener('click', () => {
shell.open();
});
window.shell.open()
})

View file

@ -1,5 +1,5 @@
const {app, ipcMain} = require('electron')
const { app, ipcMain } = require('electron')
ipcMain.on('get-app-path', (event) => {
event.sender.send('got-app-path', app.getAppPath())
})
})

View file

@ -1,4 +1,4 @@
const {ipcRenderer} = require('electron')
const { ipcRenderer } = require('electron')
const appInfoBtn = document.getElementById('app-info')
const electron_doc_link = document.querySelectorAll('a[href]')
@ -15,4 +15,4 @@ ipcRenderer.on('got-app-path', (event, path) => {
electron_doc_link.addEventListener('click', (e) => {
e.preventDefault()
shell.openExternal(url)
})
})

View file

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

View file

@ -1,30 +1,30 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
const { app, BrowserWindow } = require('electron')
const path = require('path')
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
});
preload: path.join(__dirname, 'preload.js')
}
})
win.loadFile('index.html');
};
win.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow();
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
createWindow()
}
});
});
})
})
app.on('window-all-closed', () => {
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', {
node: () => process.versions.node,
chrome: () => process.versions.chrome,
electron: () => process.versions.electron,
});
electron: () => process.versions.electron
})

View file

@ -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()})`;
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()})`

View file

@ -1,6 +1,6 @@
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 })
win.loadURL(url)
})

View file

@ -1,7 +1,7 @@
// 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 })
win.loadURL(url)
})

View file

@ -4,7 +4,7 @@ const { app, BrowserWindow, ipcMain } = require('electron')
ipcMain.on('create-demo-window', (event) => {
const win = new BrowserWindow({ width: 400, height: 275 })
function updateReply() {
function updateReply () {
event.sender.send('bounds-changed', {
size: win.getSize(),
position: win.getPosition()

View file

@ -5,10 +5,10 @@ const link = document.getElementById('browser-window-link')
newWindowBtn.addEventListener('click', (event) => {
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) => {
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: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-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\"",
"lint:js-in-markdown": "standard-markdown docs",