refactor: add prefer-const to .eslintrc + fix errors (#14880)

This commit is contained in:
Milan Burda 2018-10-02 03:56:31 +02:00 committed by Samuel Attard
parent 07161a8452
commit 3ad3ade828
47 changed files with 239 additions and 238 deletions

View file

@ -42,7 +42,7 @@ Object.assign(app, {
const nativeFn = app.getAppMetrics
app.getAppMetrics = () => {
let metrics = nativeFn.call(app)
const metrics = nativeFn.call(app)
for (const metric of metrics) {
if ('memory' in metric) {
deprecate.removeProperty(metric, 'memory')
@ -96,7 +96,7 @@ app.allowNTLMCredentialsForAllDomains = function (allow) {
if (!process.noDeprecations) {
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
}
let domains = allow ? '*' : ''
const domains = allow ? '*' : ''
if (!this.isReady()) {
this.commandLine.appendSwitch('auth-server-whitelist', domains)
} else {
@ -106,7 +106,7 @@ app.allowNTLMCredentialsForAllDomains = function (allow) {
// Routes the events to webContents.
const events = ['login', 'certificate-error', 'select-client-certificate']
for (let name of events) {
for (const name of events) {
app.on(name, (event, webContents, ...args) => {
webContents.emit(name, event, ...args)
})

View file

@ -17,7 +17,7 @@ const isSameArgs = (args) => args.length === spawnedArgs.length && args.every((e
// Spawn a command and invoke the callback when it completes with an error
// and the output from standard out.
let spawnUpdate = function (args, detached, callback) {
const spawnUpdate = function (args, detached, callback) {
let error, errorEmitted, stderr, stdout
try {

View file

@ -41,14 +41,14 @@ BrowserWindow.prototype._init = function () {
this.webContents.on('-add-new-contents', (event, webContents, disposition,
userGesture, left, top, width,
height) => {
let urlFrameName = v8Util.getHiddenValue(webContents, 'url-framename')
const urlFrameName = v8Util.getHiddenValue(webContents, 'url-framename')
if ((disposition !== 'foreground-tab' && disposition !== 'new-window' &&
disposition !== 'background-tab') || !urlFrameName) {
event.preventDefault()
return
}
let { url, frameName } = urlFrameName
const { url, frameName } = urlFrameName
v8Util.deleteHiddenValue(webContents, 'url-framename')
const options = {
show: true,
@ -115,7 +115,7 @@ BrowserWindow.prototype._init = function () {
}
const visibilityEvents = ['show', 'hide', 'minimize', 'maximize', 'restore']
for (let event of visibilityEvents) {
for (const event of visibilityEvents) {
this.on(event, visibilityChanged)
}
@ -145,7 +145,7 @@ BrowserWindow.getAllWindows = () => {
}
BrowserWindow.getFocusedWindow = () => {
for (let window of BrowserWindow.getAllWindows()) {
for (const window of BrowserWindow.getAllWindows()) {
if (window.isFocused() || window.isDevToolsFocused()) return window
}
return null

View file

@ -284,7 +284,7 @@ module.exports = {
},
showCertificateTrustDialog: function (...args) {
let [window, options, callback] = parseArgs(...args)
const [window, options, callback] = parseArgs(...args)
if (options == null || typeof options !== 'object') {
throw new TypeError('options must be an object')

View file

@ -8,7 +8,7 @@ const MenuItem = function (options) {
const { Menu } = require('electron')
// Preserve extra fields specified by user
for (let key in options) {
for (const key in options) {
if (!(key in this)) this[key] = options[key]
}
if (typeof this.role === 'string' || this.role instanceof String) {

View file

@ -180,7 +180,7 @@ function areValidTemplateItems (template) {
function sortTemplate (template) {
const sorted = sortMenuItems(template)
for (let id in sorted) {
for (const id in sorted) {
const item = sorted[id]
if (Array.isArray(item.submenu)) {
item.submenu = sortTemplate(item.submenu)

View file

@ -141,11 +141,10 @@ const NavigationController = (function () {
}
NavigationController.prototype.goToOffset = function (offset) {
let pendingIndex
if (!this.canGoToOffset(offset)) {
return
}
pendingIndex = this.currentIndex + offset
const pendingIndex = this.currentIndex + offset
if (this.inPageIndex > -1 && pendingIndex >= this.inPageIndex) {
this.pendingIndex = pendingIndex
return this.webContents._goToOffset(offset)

View file

@ -119,7 +119,7 @@ class ClientRequest extends EventEmitter {
let urlStr = options.url
if (!urlStr) {
let urlObj = {}
const urlObj = {}
const protocol = options.protocol || 'http:'
if (!kSupportedProtocols.has(protocol)) {
throw new Error('Protocol "' + protocol + '" not supported. ')
@ -149,7 +149,7 @@ class ClientRequest extends EventEmitter {
// an invalid request.
throw new TypeError('Request path contains unescaped characters.')
}
let pathObj = url.parse(options.path || '/')
const pathObj = url.parse(options.path || '/')
urlObj.pathname = pathObj.pathname
urlObj.search = pathObj.search
urlObj.hash = pathObj.hash
@ -161,7 +161,7 @@ class ClientRequest extends EventEmitter {
throw new Error('redirect mode should be one of follow, error or manual')
}
let urlRequestOptions = {
const urlRequestOptions = {
method: method,
url: urlStr,
redirect: redirectPolicy
@ -180,7 +180,7 @@ class ClientRequest extends EventEmitter {
}
}
let urlRequest = new URLRequest(urlRequestOptions)
const urlRequest = new URLRequest(urlRequestOptions)
// Set back and forward links.
this.urlRequest = urlRequest
@ -192,7 +192,7 @@ class ClientRequest extends EventEmitter {
this.extraHeaders = {}
if (options.headers) {
for (let key in options.headers) {
for (const key in options.headers) {
this.setHeader(key, options.headers[key])
}
}
@ -286,8 +286,8 @@ class ClientRequest extends EventEmitter {
}
_write (chunk, encoding, callback, isLast) {
let chunkIsString = typeof chunk === 'string'
let chunkIsBuffer = chunk instanceof Buffer
const chunkIsString = typeof chunk === 'string'
const chunkIsBuffer = chunk instanceof Buffer
if (!chunkIsString && !chunkIsBuffer) {
throw new TypeError('First argument must be a string or Buffer.')
}
@ -306,7 +306,7 @@ class ClientRequest extends EventEmitter {
// Headers are assumed to be sent on first call to _writeBuffer,
// i.e. after the first call to write or end.
let result = this.urlRequest.write(chunk, isLast)
const result = this.urlRequest.write(chunk, isLast)
// The write callback is fired asynchronously to mimic Node.js.
if (callback) {
@ -318,7 +318,7 @@ class ClientRequest extends EventEmitter {
write (data, encoding, callback) {
if (this.urlRequest.finished) {
let error = new Error('Write after end.')
const error = new Error('Write after end.')
process.nextTick(writeAfterEndNT, this, error, callback)
return true
}

View file

@ -317,7 +317,7 @@ module.exports = {
getFocusedWebContents () {
let focused = null
for (let contents of binding.getAllWebContents()) {
for (const contents of binding.getAllWebContents()) {
if (!contents.isFocused()) continue
if (focused == null) focused = contents
// Return webview web contents which may be embedded inside another