From f1b184ef78b9e59a387faae5904cc3f159b3ec3b Mon Sep 17 00:00:00 2001 From: Plusb Preco Date: Wed, 11 May 2016 02:15:09 +0900 Subject: [PATCH] :memo: Fix code style issue * Change `var` to `let`. * Change `function() {}` to `() => {}`. * Use shorthand function syntax on object notation. * Remove spaces between object notation brackets. * Small fixes. --- docs/api/app.md | 4 ++-- docs/api/browser-window.md | 8 ++++---- docs/api/content-tracing.md | 2 +- docs/api/desktop-capturer.md | 2 +- docs/api/dialog.md | 12 ++++++------ docs/api/frameless-window.md | 6 +++--- docs/api/global-shortcut.md | 2 +- docs/api/menu.md | 16 ++++++++-------- docs/api/native-image.md | 4 ++-- docs/api/process.md | 2 +- docs/api/protocol.md | 8 ++++---- docs/api/remote.md | 2 +- docs/api/screen.md | 8 ++++---- docs/api/session.md | 6 +++--- docs/api/system-preferences.md | 2 +- docs/api/tray.md | 13 +++++-------- docs/api/web-contents.md | 6 +++--- docs/api/web-frame.md | 2 +- docs/api/web-view-tag.md | 4 ++-- docs/tutorial/application-packaging.md | 2 +- docs/tutorial/desktop-environment-integration.md | 10 +++++----- docs/tutorial/quick-start.md | 6 +++--- docs/tutorial/using-selenium-and-webdriver.md | 4 ++-- 23 files changed, 64 insertions(+), 67 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index ce3a71975487..7cf301533e26 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -176,7 +176,7 @@ certificate you should prevent the default behavior with `event.preventDefault()` and call `callback(true)`. ```javascript -app.on('certificate-error', function(event, webContents, url, error, certificate, callback) { +app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { if (url === 'https://github.com') { // Verification logic. event.preventDefault(); @@ -207,7 +207,7 @@ and `callback` needs to be called with an entry filtered from the list. Using certificate from the store. ```javascript -app.on('select-client-certificate', function(event, webContents, url, list, callback) { +app.on('select-client-certificate', (event, webContents, url, list, callback) => { event.preventDefault(); callback(list[0]); }); diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index e15c53cdb80f..143c0179428b 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -9,7 +9,7 @@ const {BrowserWindow} = require('electron'); // Or in the renderer process. const {BrowserWindow} = require('electron').remote; -let win = new BrowserWindow({ width: 800, height: 600, show: false }); +let win = new BrowserWindow({width: 800, height: 600, show: false}); win.on('closed', () => { win = null; }); @@ -220,7 +220,7 @@ reloaded. In Electron, returning an empty string or `false` would cancel the close. For example: ```javascript -window.onbeforeunload = function(e) { +window.onbeforeunload = (e) => { console.log('I do not want to be closed'); // Unlike usual browsers, in which a string should be returned and the user is @@ -392,7 +392,7 @@ Objects created with `new BrowserWindow` have the following properties: ```javascript // In this example `win` is our instance -var win = new BrowserWindow({ width: 800, height: 600 }); +let win = new BrowserWindow({width: 800, height: 600}); ``` ### `win.webContents` @@ -689,7 +689,7 @@ attached just below the window frame, but you may want to display them beneath a HTML-rendered toolbar. For example: ```javascript -var toolbarRect = document.getElementById('toolbar').getBoundingClientRect(); +let toolbarRect = document.getElementById('toolbar').getBoundingClientRect(); win.setSheetOffset(toolbarRect.height); ``` diff --git a/docs/api/content-tracing.md b/docs/api/content-tracing.md index 04e7f5a9b5d1..d269d602ef59 100644 --- a/docs/api/content-tracing.md +++ b/docs/api/content-tracing.md @@ -15,7 +15,7 @@ const options = { traceOptions: 'record-until-full,enable-sampling' }; -contentTracing.startRecording(options, function() { +contentTracing.startRecording(options, () => { console.log('Tracing started'); setTimeout(() => { diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index 20e6d8625df0..a72539a7a283 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -9,7 +9,7 @@ const {desktopCapturer} = require('electron'); desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => { if (error) throw error; - for (var i = 0; i < sources.length; ++i) { + for (let i = 0; i < sources.length; ++i) { if (sources[i].name === 'Electron') { navigator.webkitGetUserMedia({ audio: false, diff --git a/docs/api/dialog.md b/docs/api/dialog.md index c5cc0227a602..0ba41df96adf 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -5,10 +5,10 @@ An example of showing a dialog to select multiple files and directories: ```javascript -var win = ...; // BrowserWindow in which to show the dialog +let win = ...; // BrowserWindow in which to show the dialog const {dialog} = require('electron'); -console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]})); +console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']})); ``` The Dialog is opened from Electron's main thread. If you want to use the dialog @@ -43,10 +43,10 @@ selected when you want to limit the user to a specific type. For example: ```javascript { filters: [ - { name: 'Images', extensions: ['jpg', 'png', 'gif'] }, - { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] }, - { name: 'Custom File Type', extensions: ['as'] }, - { name: 'All Files', extensions: ['*'] } + {name: 'Images', extensions: ['jpg', 'png', 'gif']}, + {name: 'Movies', extensions: ['mkv', 'avi', 'mp4']}, + {name: 'Custom File Type', extensions: ['as']}, + {name: 'All Files', extensions: ['*']} ] } ``` diff --git a/docs/api/frameless-window.md b/docs/api/frameless-window.md index fd0f5d4faefe..f3017037210d 100644 --- a/docs/api/frameless-window.md +++ b/docs/api/frameless-window.md @@ -15,7 +15,7 @@ To create a frameless window, you need to set `frame` to `false` in ```javascript const {BrowserWindow} = require('electron'); -let win = new BrowserWindow({ width: 800, height: 600, frame: false }); +let win = new BrowserWindow({width: 800, height: 600, frame: false}); ``` ### Alternatives on OS X @@ -28,7 +28,7 @@ the window controls ("traffic lights") for standard window actions. You can do so by specifying the new `titleBarStyle` option: ```javascript -let win = new BrowserWindow({ 'titleBarStyle': 'hidden' }); +let win = new BrowserWindow({titleBarStyle: 'hidden'}); ``` ## Transparent window @@ -37,7 +37,7 @@ By setting the `transparent` option to `true`, you can also make the frameless window transparent: ```javascript -let win = new BrowserWindow({ transparent: true, frame: false }); +let win = new BrowserWindow({transparent: true, frame: false}); ``` ### Limitations diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index d611423c2a38..d9488a7b7fd9 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -15,7 +15,7 @@ const {app, globalShortcut} = require('electron'); app.on('ready', () => { // Register a 'CommandOrControl+X' shortcut listener. - const ret = globalShortcut.register('CommandOrControl+X', function() { + const ret = globalShortcut.register('CommandOrControl+X', () => { console.log('CommandOrControl+X is pressed'); }); diff --git a/docs/api/menu.md b/docs/api/menu.md index 72bd5edc8f15..1dc2a5af0a1b 100644 --- a/docs/api/menu.md +++ b/docs/api/menu.md @@ -18,9 +18,9 @@ the user right clicks the page: const {Menu, MenuItem} = require('electron').remote; const menu = new Menu(); -menu.append(new MenuItem({ label: 'MenuItem1', click: () => { console.log('item 1 clicked'); } })); -menu.append(new MenuItem({ type: 'separator' })); -menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true })); +menu.append(new MenuItem({label: 'MenuItem1', click() { console.log('item 1 clicked'); }})); +menu.append(new MenuItem({type: 'separator'})); +menu.append(new MenuItem({label: 'MenuItem2', type: 'checkbox', checked: true})); window.addEventListener('contextmenu', (e) => { e.preventDefault(); @@ -78,14 +78,14 @@ const template = [ { label: 'Reload', accelerator: 'CmdOrCtrl+R', - click: (item, focusedWindow) => { + click(item, focusedWindow) { if (focusedWindow) focusedWindow.reload(); } }, { label: 'Toggle Full Screen', accelerator: process.platform === 'darwin' ? 'Ctrl+Command+F' : 'F11', - click: (item, focusedWindow) => { + click(item, focusedWindow) { if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen()); } @@ -93,7 +93,7 @@ const template = [ { label: 'Toggle Developer Tools', accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I', - click: (item, focusedWindow) => { + click(item, focusedWindow) { if (focusedWindow) focusedWindow.webContents.toggleDevTools(); } @@ -122,7 +122,7 @@ const template = [ submenu: [ { label: 'Learn More', - click: () => { require('electron').shell.openExternal('http://electron.atom.io') } + click() { require('electron').shell.openExternal('http://electron.atom.io'); } }, ] }, @@ -168,7 +168,7 @@ if (process.platform === 'darwin') { { label: 'Quit', accelerator: 'Command+Q', - click: () => { app.quit(); } + click() { app.quit(); } }, ] }); diff --git a/docs/api/native-image.md b/docs/api/native-image.md index 7ab08457c860..6d42ca15e9ae 100644 --- a/docs/api/native-image.md +++ b/docs/api/native-image.md @@ -49,7 +49,7 @@ images/ ```javascript -var appIcon = new Tray('/Users/somebody/images/icon.png'); +let appIcon = new Tray('/Users/somebody/images/icon.png'); ``` Following suffixes for DPI are also supported: @@ -118,7 +118,7 @@ The following methods are available on instances of `nativeImage`: ```javascript const nativeImage = require('electron').nativeImage; -var image = nativeImage.createFromPath('/Users/somebody/images/icon.png'); +let image = nativeImage.createFromPath('/Users/somebody/images/icon.png'); ``` ### `image.toPng()` diff --git a/docs/api/process.md b/docs/api/process.md index ab637e8a2b9e..ec982d3d74aa 100644 --- a/docs/api/process.md +++ b/docs/api/process.md @@ -32,7 +32,7 @@ the global scope when node integration is turned off: // preload.js const _setImmediate = setImmediate; const _clearImmediate = clearImmediate; -process.once('loaded', function() { +process.once('loaded', () => { global.setImmediate = _setImmediate; global.clearImmediate = _clearImmediate; }); diff --git a/docs/api/protocol.md b/docs/api/protocol.md index 83481dd6515c..bcea37bd224c 100644 --- a/docs/api/protocol.md +++ b/docs/api/protocol.md @@ -9,11 +9,11 @@ An example of implementing a protocol that has the same effect as the const {app, protocol} = require('electron'); const path = require('path'); -app.on('ready', function () { - protocol.registerFileProtocol('atom', function (request, callback) { +app.on('ready', () => { + protocol.registerFileProtocol('atom', (request, callback) => { const url = request.url.substr(7); callback({path: path.normalize(__dirname + '/' + url)}); - }, function (error) { + }, (error) => { if (error) console.error('Failed to register protocol'); }); @@ -53,7 +53,7 @@ have to register it as standard scheme: ```javascript protocol.registerStandardSchemes(['atom']); -app.on('ready', function () { +app.on('ready', () => { protocol.registerHttpProtocol('atom', ...); }); ``` diff --git a/docs/api/remote.md b/docs/api/remote.md index c95df4369ea8..bf82badca74a 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -16,7 +16,7 @@ renderer process: ```javascript const {BrowserWindow} = require('electron').remote; -var win = new BrowserWindow({ width: 800, height: 600 }); +let win = new BrowserWindow({width: 800, height: 600}); win.loadURL('https://github.com'); ``` diff --git a/docs/api/screen.md b/docs/api/screen.md index adb017bd37f7..258263904b6d 100644 --- a/docs/api/screen.md +++ b/docs/api/screen.md @@ -8,7 +8,7 @@ emitted (by invoking or requiring it). `screen` is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter). **Note:** In the renderer / DevTools, `window.screen` is a reserved DOM -property, so writing `var screen = require('electron').screen` will not work. +property, so writing `let {screen} = require('electron')` will not work. In our examples below, we use `electronScreen` as the variable name instead. An example of creating a window that fills the whole screen: @@ -19,7 +19,7 @@ let mainWindow; app.on('ready', () => { const {width, height} = electronScreen.getPrimaryDisplay().workAreaSize; - mainWindow = new BrowserWindow({ width, height }); + mainWindow = new BrowserWindow({width, height}); }); ``` @@ -31,8 +31,8 @@ const {app, BrowserWindow, screen: electronScreen} = require('electron'); let mainWindow; app.on('ready', () => { - var displays = electronScreen.getAllDisplays(); - var externalDisplay = null; + let displays = electronScreen.getAllDisplays(); + let externalDisplay = null; for (let i in displays) { if (displays[i].bounds.x !== 0 || displays[i].bounds.y !== 0) { externalDisplay = displays[i]; diff --git a/docs/api/session.md b/docs/api/session.md index 94be0656140e..76ba4a611b0f 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -11,7 +11,7 @@ property of [`webContents`](web-contents.md) which is a property of ```javascript const {BrowserWindow} = require('electron'); -let win = new BrowserWindow({ width: 800, height: 600 }); +let win = new BrowserWindow({width: 800, height: 600}); win.loadURL('http://github.com'); const ses = win.webContents.session; @@ -89,13 +89,13 @@ session.defaultSession.cookies.get({}, (error, cookies) => { }); // Query all cookies associated with a specific url. -session.defaultSession.cookies.get({ url : 'http://www.github.com' }, (error, cookies) => { +session.defaultSession.cookies.get({url : 'http://www.github.com'}, (error, cookies) => { console.log(cookies); }); // Set a cookie with the given cookie data; // may overwrite equivalent cookies if they exist. -const cookie = { url : 'http://www.github.com', name : 'dummy_name', value : 'dummy' }; +const cookie = {url : 'http://www.github.com', name : 'dummy_name', value : 'dummy'}; session.defaultSession.cookies.set(cookie, (error) => { if (error) console.error(error); diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index cafb1d3745f3..df7ef89e65c4 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -56,7 +56,7 @@ An example of using it to determine if you should create a transparent window or not (transparent windows won't work correctly when DWM composition is disabled): ```javascript -let browserOptions = { width: 1000, height: 800 }; +let browserOptions = {width: 1000, height: 800}; // Make the window transparent only if the platform supports it. if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) { diff --git a/docs/api/tray.md b/docs/api/tray.md index eaf3f6c42bbd..3fa6f606e90a 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -3,19 +3,16 @@ > Add icons and context menus to the system's notification area. ```javascript -const electron = require('electron'); -const app = electron.app; -const Menu = electron.Menu; -const Tray = electron.Tray; +const {app, Menu, Tray} = require('electron'); let appIcon = null; app.on('ready', () => { appIcon = new Tray('/path/to/my/icon'); const contextMenu = Menu.buildFromTemplate([ - { label: 'Item1', type: 'radio' }, - { label: 'Item2', type: 'radio' }, - { label: 'Item3', type: 'radio', checked: true }, - { label: 'Item4', type: 'radio' } + {label: 'Item1', type: 'radio'}, + {label: 'Item2', type: 'radio'}, + {label: 'Item3', type: 'radio', checked: true}, + {label: 'Item4', type: 'radio'} ]); appIcon.setToolTip('This is my application.'); appIcon.setContextMenu(contextMenu); diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 5cf385dde925..55021945e46d 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -603,7 +603,7 @@ the request can be obtained by subscribing to Stops any `findInPage` request for the `webContents` with the provided `action`. ```javascript -webContents.on('found-in-page', function(event, result) { +webContents.on('found-in-page', (event, result) => { if (result.finalUpdate) webContents.stopFindInPage('clearSelection'); }); @@ -700,7 +700,7 @@ Adds the specified path to DevTools workspace. Must be used after DevTools creation: ```javascript -mainWindow.webContents.on('devtools-opened', function() { +mainWindow.webContents.on('devtools-opened', () => { mainWindow.webContents.addWorkSpace(__dirname); }); ``` @@ -887,7 +887,7 @@ End subscribing for frame presentation events. * `HTMLOnly` - Save only the HTML of the page. * `HTMLComplete` - Save complete-html page. * `MHTML` - Save complete-html page as MHTML. -* `callback` Function - `function(error) {}`. +* `callback` Function - `(error) => {}`. * `error` Error Returns true if the process of saving page has been initiated successfully. diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index f77e2ce7eece..de5a21db3db9 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -59,7 +59,7 @@ An example of using [node-spellchecker][spellchecker] as provider: ```javascript webFrame.setSpellCheckProvider('en-US', true, { - spellCheck: function(text) { + spellCheck(text) { return !(require('spellchecker').isMisspelled(text)); } }); diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 055642c13d3f..aa564b79e1fc 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -600,7 +600,7 @@ The following example code forwards all log messages to the embedder's console without regard for log level or other properties. ```javascript -webview.addEventListener('console-message', function(e) { +webview.addEventListener('console-message', (e) => { console.log('Guest page logged a message:', e.message); }); ``` @@ -620,7 +620,7 @@ Fired when a result is available for [`webview.findInPage`](web-view-tag.md#webviewtagfindinpage) request. ```javascript -webview.addEventListener('found-in-page', function(e) { +webview.addEventListener('found-in-page', (e) => { if (e.result.finalUpdate) webview.stopFindInPage('keepSelection'); }); diff --git a/docs/tutorial/application-packaging.md b/docs/tutorial/application-packaging.md index f1c100e6db99..de61e8bd5e97 100644 --- a/docs/tutorial/application-packaging.md +++ b/docs/tutorial/application-packaging.md @@ -85,7 +85,7 @@ For example, to get a file with `$.get`: ```html