chore: initial linting fixes for JS in docs/fiddles (#37689)
This commit is contained in:
		
					parent
					
						
							
								be32740991
							
						
					
				
			
			
				commit
				
					
						db27b9f433
					
				
			
		
					 45 changed files with 122 additions and 134 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
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')
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,17 +1,15 @@
 | 
			
		|||
// Modules to control application life and create native browser window
 | 
			
		||||
const { app, BrowserWindow } = require('electron')
 | 
			
		||||
const path = require('path')
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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}`)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
const { app, BrowserWindow } = require('electron')
 | 
			
		||||
const os = require('os');
 | 
			
		||||
const os = require('os')
 | 
			
		||||
 | 
			
		||||
function createWindow () {
 | 
			
		||||
  const win = new BrowserWindow({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
const { app, BrowserWindow } = require('electron')
 | 
			
		||||
const path = require('path')
 | 
			
		||||
 | 
			
		||||
function createWindow () {
 | 
			
		||||
  const mainWindow = new BrowserWindow({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
const { app, BrowserWindow } = require('electron')
 | 
			
		||||
const path = require('path')
 | 
			
		||||
 | 
			
		||||
function createWindow () {
 | 
			
		||||
  const mainWindow = new BrowserWindow({
 | 
			
		||||
| 
						 | 
				
			
			@ -8,7 +7,6 @@ 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.
 | 
			
		||||
    mainWindow.webContents.session.on('serial-port-added', (event, port) => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,10 +2,10 @@ 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') {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
const { app, BrowserWindow } = require('electron')
 | 
			
		||||
const path = require('path')
 | 
			
		||||
 | 
			
		||||
function createWindow () {
 | 
			
		||||
  const mainWindow = new BrowserWindow({
 | 
			
		||||
| 
						 | 
				
			
			@ -25,7 +24,7 @@ function createWindow () {
 | 
			
		|||
    event.preventDefault()
 | 
			
		||||
    if (details.deviceList && details.deviceList.length > 0) {
 | 
			
		||||
      const deviceToReturn = details.deviceList.find((device) => {
 | 
			
		||||
        if (!grantedDeviceThroughPermHandler || (device.deviceId != grantedDeviceThroughPermHandler.deviceId)) {
 | 
			
		||||
        if (!grantedDeviceThroughPermHandler || (device.deviceId !== grantedDeviceThroughPermHandler.deviceId)) {
 | 
			
		||||
          return true
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,7 +21,6 @@ async function testIt() {
 | 
			
		|||
      filters: []
 | 
			
		||||
    })
 | 
			
		||||
    grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`
 | 
			
		||||
 | 
			
		||||
  } catch (ex) {
 | 
			
		||||
    if (ex.name === 'NotFoundError') {
 | 
			
		||||
      grantedDeviceList = noDevicesFoundMsg
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,4 +3,4 @@ const titleInput = document.getElementById('title')
 | 
			
		|||
setButton.addEventListener('click', () => {
 | 
			
		||||
  const title = titleInput.value
 | 
			
		||||
  window.electronAPI.setTitle(title)
 | 
			
		||||
});
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,7 +4,7 @@ const path = require('path')
 | 
			
		|||
async function handleFileOpen () {
 | 
			
		||||
  const { canceled, filePaths } = await dialog.showOpenDialog()
 | 
			
		||||
  if (canceled) {
 | 
			
		||||
    return
 | 
			
		||||
 | 
			
		||||
  } else {
 | 
			
		||||
    return filePaths[0]
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,11 +14,11 @@ function createWindow () {
 | 
			
		|||
      submenu: [
 | 
			
		||||
        {
 | 
			
		||||
          click: () => mainWindow.webContents.send('update-counter', 1),
 | 
			
		||||
        label: 'Increment',
 | 
			
		||||
          label: 'Increment'
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          click: () => mainWindow.webContents.send('update-counter', -1),
 | 
			
		||||
        label: 'Decrement',
 | 
			
		||||
          label: 'Decrement'
 | 
			
		||||
        }
 | 
			
		||||
      ]
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,7 +52,6 @@ app.on('activate', function () {
 | 
			
		|||
  }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ipcMain.on('open-file-dialog', event => {
 | 
			
		||||
  dialog.showOpenDialog(
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,4 +28,3 @@ app.on('window-all-closed', () => {
 | 
			
		|||
    app.quit()
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,4 +8,3 @@ window.addEventListener('DOMContentLoaded', () => {
 | 
			
		|||
    replaceText(`${type}-version`, process.versions[type])
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
const { app, BrowserWindow, ipcMain, shell, dialog } = require('electron')
 | 
			
		||||
const path = require('path')
 | 
			
		||||
 | 
			
		||||
let mainWindow;
 | 
			
		||||
let mainWindow
 | 
			
		||||
 | 
			
		||||
if (process.defaultApp) {
 | 
			
		||||
  if (process.argv.length >= 2) {
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +43,7 @@ function createWindow () {
 | 
			
		|||
    width: 800,
 | 
			
		||||
    height: 600,
 | 
			
		||||
    webPreferences: {
 | 
			
		||||
      preload: path.join(__dirname, 'preload.js'),
 | 
			
		||||
      preload: path.join(__dirname, 'preload.js')
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,6 @@ const { contextBridge, ipcRenderer } = require('electron')
 | 
			
		|||
contextBridge.exposeInMainWorld(
 | 
			
		||||
  'shell',
 | 
			
		||||
  {
 | 
			
		||||
    open: () => ipcRenderer.send('shell:open'),
 | 
			
		||||
    open: () => ipcRenderer.send('shell:open')
 | 
			
		||||
  }
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -4,5 +4,5 @@
 | 
			
		|||
 | 
			
		||||
// Binds the buttons to the context bridge API.
 | 
			
		||||
document.getElementById('open-in-browser').addEventListener('click', () => {
 | 
			
		||||
  shell.open();
 | 
			
		||||
});
 | 
			
		||||
  window.shell.open()
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()})`
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
// 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 }) => {
 | 
			
		||||
  const win = new BrowserWindow({ frame: false })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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')
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue