Skip to content

Commit 3ad3ade

Browse files
miniakMarshallOfSound
authored andcommitted
refactor: add prefer-const to .eslintrc + fix errors (electron#14880)
1 parent 07161a8 commit 3ad3ade

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+239
-238
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"browser": true
55
},
66
"rules": {
7-
"no-var": "error"
7+
"no-var": "error",
8+
"prefer-const": ["error", {
9+
"destructuring": "all"
10+
}]
811
}
912
}

lib/browser/api/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Object.assign(app, {
4242

4343
const nativeFn = app.getAppMetrics
4444
app.getAppMetrics = () => {
45-
let metrics = nativeFn.call(app)
45+
const metrics = nativeFn.call(app)
4646
for (const metric of metrics) {
4747
if ('memory' in metric) {
4848
deprecate.removeProperty(metric, 'memory')
@@ -96,7 +96,7 @@ app.allowNTLMCredentialsForAllDomains = function (allow) {
9696
if (!process.noDeprecations) {
9797
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
9898
}
99-
let domains = allow ? '*' : ''
99+
const domains = allow ? '*' : ''
100100
if (!this.isReady()) {
101101
this.commandLine.appendSwitch('auth-server-whitelist', domains)
102102
} else {
@@ -106,7 +106,7 @@ app.allowNTLMCredentialsForAllDomains = function (allow) {
106106

107107
// Routes the events to webContents.
108108
const events = ['login', 'certificate-error', 'select-client-certificate']
109-
for (let name of events) {
109+
for (const name of events) {
110110
app.on(name, (event, webContents, ...args) => {
111111
webContents.emit(name, event, ...args)
112112
})

lib/browser/api/auto-updater/squirrel-update-win.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const isSameArgs = (args) => args.length === spawnedArgs.length && args.every((e
1717

1818
// Spawn a command and invoke the callback when it completes with an error
1919
// and the output from standard out.
20-
let spawnUpdate = function (args, detached, callback) {
20+
const spawnUpdate = function (args, detached, callback) {
2121
let error, errorEmitted, stderr, stdout
2222

2323
try {

lib/browser/api/browser-window.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ BrowserWindow.prototype._init = function () {
4141
this.webContents.on('-add-new-contents', (event, webContents, disposition,
4242
userGesture, left, top, width,
4343
height) => {
44-
let urlFrameName = v8Util.getHiddenValue(webContents, 'url-framename')
44+
const urlFrameName = v8Util.getHiddenValue(webContents, 'url-framename')
4545
if ((disposition !== 'foreground-tab' && disposition !== 'new-window' &&
4646
disposition !== 'background-tab') || !urlFrameName) {
4747
event.preventDefault()
4848
return
4949
}
5050

51-
let { url, frameName } = urlFrameName
51+
const { url, frameName } = urlFrameName
5252
v8Util.deleteHiddenValue(webContents, 'url-framename')
5353
const options = {
5454
show: true,
@@ -115,7 +115,7 @@ BrowserWindow.prototype._init = function () {
115115
}
116116

117117
const visibilityEvents = ['show', 'hide', 'minimize', 'maximize', 'restore']
118-
for (let event of visibilityEvents) {
118+
for (const event of visibilityEvents) {
119119
this.on(event, visibilityChanged)
120120
}
121121

@@ -145,7 +145,7 @@ BrowserWindow.getAllWindows = () => {
145145
}
146146

147147
BrowserWindow.getFocusedWindow = () => {
148-
for (let window of BrowserWindow.getAllWindows()) {
148+
for (const window of BrowserWindow.getAllWindows()) {
149149
if (window.isFocused() || window.isDevToolsFocused()) return window
150150
}
151151
return null

lib/browser/api/dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ module.exports = {
284284
},
285285

286286
showCertificateTrustDialog: function (...args) {
287-
let [window, options, callback] = parseArgs(...args)
287+
const [window, options, callback] = parseArgs(...args)
288288

289289
if (options == null || typeof options !== 'object') {
290290
throw new TypeError('options must be an object')

lib/browser/api/menu-item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const MenuItem = function (options) {
88
const { Menu } = require('electron')
99

1010
// Preserve extra fields specified by user
11-
for (let key in options) {
11+
for (const key in options) {
1212
if (!(key in this)) this[key] = options[key]
1313
}
1414
if (typeof this.role === 'string' || this.role instanceof String) {

lib/browser/api/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function areValidTemplateItems (template) {
180180

181181
function sortTemplate (template) {
182182
const sorted = sortMenuItems(template)
183-
for (let id in sorted) {
183+
for (const id in sorted) {
184184
const item = sorted[id]
185185
if (Array.isArray(item.submenu)) {
186186
item.submenu = sortTemplate(item.submenu)

lib/browser/api/navigation-controller.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ const NavigationController = (function () {
141141
}
142142

143143
NavigationController.prototype.goToOffset = function (offset) {
144-
let pendingIndex
145144
if (!this.canGoToOffset(offset)) {
146145
return
147146
}
148-
pendingIndex = this.currentIndex + offset
147+
const pendingIndex = this.currentIndex + offset
149148
if (this.inPageIndex > -1 && pendingIndex >= this.inPageIndex) {
150149
this.pendingIndex = pendingIndex
151150
return this.webContents._goToOffset(offset)

lib/browser/api/net.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ClientRequest extends EventEmitter {
119119
let urlStr = options.url
120120

121121
if (!urlStr) {
122-
let urlObj = {}
122+
const urlObj = {}
123123
const protocol = options.protocol || 'http:'
124124
if (!kSupportedProtocols.has(protocol)) {
125125
throw new Error('Protocol "' + protocol + '" not supported. ')
@@ -149,7 +149,7 @@ class ClientRequest extends EventEmitter {
149149
// an invalid request.
150150
throw new TypeError('Request path contains unescaped characters.')
151151
}
152-
let pathObj = url.parse(options.path || '/')
152+
const pathObj = url.parse(options.path || '/')
153153
urlObj.pathname = pathObj.pathname
154154
urlObj.search = pathObj.search
155155
urlObj.hash = pathObj.hash
@@ -161,7 +161,7 @@ class ClientRequest extends EventEmitter {
161161
throw new Error('redirect mode should be one of follow, error or manual')
162162
}
163163

164-
let urlRequestOptions = {
164+
const urlRequestOptions = {
165165
method: method,
166166
url: urlStr,
167167
redirect: redirectPolicy
@@ -180,7 +180,7 @@ class ClientRequest extends EventEmitter {
180180
}
181181
}
182182

183-
let urlRequest = new URLRequest(urlRequestOptions)
183+
const urlRequest = new URLRequest(urlRequestOptions)
184184

185185
// Set back and forward links.
186186
this.urlRequest = urlRequest
@@ -192,7 +192,7 @@ class ClientRequest extends EventEmitter {
192192
this.extraHeaders = {}
193193

194194
if (options.headers) {
195-
for (let key in options.headers) {
195+
for (const key in options.headers) {
196196
this.setHeader(key, options.headers[key])
197197
}
198198
}
@@ -286,8 +286,8 @@ class ClientRequest extends EventEmitter {
286286
}
287287

288288
_write (chunk, encoding, callback, isLast) {
289-
let chunkIsString = typeof chunk === 'string'
290-
let chunkIsBuffer = chunk instanceof Buffer
289+
const chunkIsString = typeof chunk === 'string'
290+
const chunkIsBuffer = chunk instanceof Buffer
291291
if (!chunkIsString && !chunkIsBuffer) {
292292
throw new TypeError('First argument must be a string or Buffer.')
293293
}
@@ -306,7 +306,7 @@ class ClientRequest extends EventEmitter {
306306

307307
// Headers are assumed to be sent on first call to _writeBuffer,
308308
// i.e. after the first call to write or end.
309-
let result = this.urlRequest.write(chunk, isLast)
309+
const result = this.urlRequest.write(chunk, isLast)
310310

311311
// The write callback is fired asynchronously to mimic Node.js.
312312
if (callback) {
@@ -318,7 +318,7 @@ class ClientRequest extends EventEmitter {
318318

319319
write (data, encoding, callback) {
320320
if (this.urlRequest.finished) {
321-
let error = new Error('Write after end.')
321+
const error = new Error('Write after end.')
322322
process.nextTick(writeAfterEndNT, this, error, callback)
323323
return true
324324
}

lib/browser/api/web-contents.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ module.exports = {
317317

318318
getFocusedWebContents () {
319319
let focused = null
320-
for (let contents of binding.getAllWebContents()) {
320+
for (const contents of binding.getAllWebContents()) {
321321
if (!contents.isFocused()) continue
322322
if (focused == null) focused = contents
323323
// Return webview web contents which may be embedded inside another

0 commit comments

Comments
 (0)