Skip to content

Commit 95d3613

Browse files
committed
chore: update to standard 13
code changes to follow new rules: https://github.com/standard/standard/blob/master/CHANGELOG.md#1300---2019-07-10
1 parent abdd28d commit 95d3613

17 files changed

+231
-263
lines changed

add-on/src/contentScripts/ipfs-proxy/page.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function createWindowIpfs () {
3232
const proxyClient = createProxyClient()
3333

3434
// Add deprecation warning to window.ipfs.<cmd>
35-
for (let cmd in proxyClient) {
36-
let fn = proxyClient[cmd]
35+
for (const cmd in proxyClient) {
36+
const fn = proxyClient[cmd]
3737
proxyClient[cmd] = function () {
3838
console.warn('Calling commands directly on window.ipfs is deprecated and will be removed on 2019-09-01. Use API instance returned by window.ipfs.enable() instead. More: https://github.com/ipfs-shipyard/ipfs-companion/blob/master/docs/window.ipfs.md')
3939
return fn.apply(this, arguments)

add-on/src/contentScripts/linkifyDOM.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const { default: PQueue } = require('p-queue')
6565
async function linkifyMutation (mutation, linkifyJobs) {
6666
linkifyJobs = linkifyJobs || new PQueue({ concurrency: 1 })
6767
if (mutation.type === 'childList') {
68-
for (let addedNode of mutation.addedNodes) {
68+
for (const addedNode of mutation.addedNodes) {
6969
if (addedNode.nodeType === Node.TEXT_NODE) {
7070
linkifyJobs.add(async () => linkifyTextNode(addedNode))
7171
} else {

add-on/src/contentScripts/normalizeLinksWithUnhandledProtocols.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
new MutationObserver(function (mutations) {
3939
mutations.forEach(function (mutation) {
4040
if (mutation.type === 'childList') {
41-
for (let addedNode of mutation.addedNodes) {
41+
for (const addedNode of mutation.addedNodes) {
4242
if (addedNode.nodeType === Node.ELEMENT_NODE) {
4343
setTimeout(() => normalizeTree(addedNode), 0)
4444
}

add-on/src/lib/context-menus.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ function createContextMenus (getState, runtime, ipfsPathValidator, { onAddFromCo
173173
}
174174
}
175175
const ifApi = getState().peerCount > 0
176-
for (let item of apiMenuItems) {
176+
for (const item of apiMenuItems) {
177177
await browser.contextMenus.update(item, { enabled: ifApi })
178178
}
179-
for (let item of ipfsContextItems) {
179+
for (const item of ipfsContextItems) {
180180
await browser.contextMenus.update(item, { enabled: ipfsContext })
181181
}
182-
for (let item of apiAndIpfsContextItems) {
182+
for (const item of apiAndIpfsContextItems) {
183183
await browser.contextMenus.update(item, { enabled: (ifApi && ipfsContext) })
184184
}
185185
} catch (err) {

add-on/src/lib/ipfs-companion.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module.exports = async function init () {
9696
}
9797

9898
function registerListeners () {
99-
let onBeforeSendInfoSpec = ['blocking', 'requestHeaders']
99+
const onBeforeSendInfoSpec = ['blocking', 'requestHeaders']
100100
if (!runtime.isFirefox) {
101101
// Chrome 72+ requires 'extraHeaders' for access to Referer header (used in cors whitelisting of webui)
102102
onBeforeSendInfoSpec.push('extraHeaders')
@@ -230,7 +230,7 @@ module.exports = async function init () {
230230
currentTab: await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0])
231231
}
232232
try {
233-
let v = await ipfs.version()
233+
const v = await ipfs.version()
234234
if (v) {
235235
info.gatewayVersion = v.commit ? v.version + '/' + v.commit : v.version
236236
}
@@ -321,7 +321,7 @@ module.exports = async function init () {
321321
notify('notify_uploadErrorTitle', 'notify_uploadTrackingProtectionErrorMsg')
322322
console.warn('IPFS upload often fails because remote file can not be downloaded due to Tracking Protection. See details at: https://github.com/ipfs/ipfs-companion/issues/227')
323323
browser.tabs.create({
324-
'url': 'https://github.com/ipfs/ipfs-companion/issues/227'
324+
url: 'https://github.com/ipfs/ipfs-companion/issues/227'
325325
})
326326
} else {
327327
notify('notify_uploadErrorTitle', 'notify_inlineErrorMsg', `${error.message}`)
@@ -345,15 +345,15 @@ module.exports = async function init () {
345345
}
346346

347347
async function uploadResultHandler ({ result, openRootInNewTab = false }) {
348-
for (let file of result) {
348+
for (const file of result) {
349349
if (file && file.hash) {
350350
const { path, url } = getIpfsPathAndNativeAddress(file.hash)
351351
preloadAtPublicGateway(path)
352352
console.info('[ipfs-companion] successfully stored', file)
353353
// open the wrapping directory (or the CID if wrapping was disabled)
354354
if (openRootInNewTab && (result.length === 1 || file.path === '' || file.path === file.hash)) {
355355
await browser.tabs.create({
356-
'url': url
356+
url: url
357357
})
358358
}
359359
}
@@ -464,7 +464,7 @@ module.exports = async function init () {
464464

465465
async function apiStatusUpdate () {
466466
// update peer count
467-
let oldPeerCount = state.peerCount
467+
const oldPeerCount = state.peerCount
468468
state.peerCount = await getSwarmPeerCount()
469469
updatePeerCountDependentStates(oldPeerCount, state.peerCount)
470470
// trigger pending updates
@@ -535,7 +535,7 @@ module.exports = async function init () {
535535
}
536536

537537
async function setBrowserActionIcon (iconPath) {
538-
let iconDefinition = { path: iconPath }
538+
const iconDefinition = { path: iconPath }
539539
try {
540540
// Try SVG first -- Firefox supports it natively
541541
await browser.browserAction.setIcon(iconDefinition)
@@ -553,17 +553,17 @@ module.exports = async function init () {
553553
// - https://bugs.chromium.org/p/chromium/issues/detail?id=647182
554554
// - https://developer.chrome.com/extensions/manifest/icons
555555
return {
556-
'path': {
557-
'19': rasterIconPath(svgPath, 19),
558-
'38': rasterIconPath(svgPath, 38),
559-
'128': rasterIconPath(svgPath, 128)
556+
path: {
557+
19: rasterIconPath(svgPath, 19),
558+
38: rasterIconPath(svgPath, 38),
559+
128: rasterIconPath(svgPath, 128)
560560
}
561561
}
562562
}
563563

564564
function rasterIconPath (iconPath, size) {
565565
// point at precomputed PNG file
566-
let baseName = /\/icons\/(.+)\.svg/.exec(iconPath)[1]
566+
const baseName = /\/icons\/(.+)\.svg/.exec(iconPath)[1]
567567
return `/icons/png/${baseName}_${size}.png`
568568
}
569569

@@ -602,7 +602,7 @@ module.exports = async function init () {
602602
let shouldRestartIpfsClient = false
603603
let shouldStopIpfsClient = false
604604

605-
for (let key in changes) {
605+
for (const key in changes) {
606606
const change = changes[key]
607607
if (change.oldValue === change.newValue) continue
608608

@@ -729,7 +729,7 @@ module.exports = async function init () {
729729
},
730730

731731
destroy () {
732-
let destroyTasks = []
732+
const destroyTasks = []
733733
clearInterval(apiStatusUpdateInterval)
734734
apiStatusUpdateInterval = null
735735
ipfs = null

add-on/src/lib/ipfs-proxy/enable-command.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ function createEnableCommand (getIpfs, getState, getScope, accessControl, reques
2121
// Validate and prompt for any missing permissions in bulk
2222
// if a list of needed commands is announced up front
2323
if (opts.commands) {
24-
let missingAcls = []
25-
let deniedAcls = []
26-
for (let command of opts.commands) {
24+
const missingAcls = []
25+
const deniedAcls = []
26+
for (const command of opts.commands) {
2727
// Fail fast if command is not allowed to be proxied at all
2828
if (!inCommandWhitelist(command)) {
2929
throw createCommandWhitelistError(command)
3030
}
3131
// Get the current access flag to decide if it should be added
3232
// to the list of permissions to be prompted about in the next step
33-
let access = await accessControl.getAccess(scope, command)
33+
const access = await accessControl.getAccess(scope, command)
3434
if (!access) {
3535
missingAcls.push(command)
3636
} else if (access.allow !== true) {
@@ -44,7 +44,7 @@ function createEnableCommand (getIpfs, getState, getScope, accessControl, reques
4444
// Display a single prompt with all missing permissions
4545
if (missingAcls.length) {
4646
const { allow, wildcard } = await requestAccess(scope, missingAcls)
47-
let access = await accessControl.setAccess(scope, wildcard ? '*' : missingAcls, allow)
47+
const access = await accessControl.setAccess(scope, wildcard ? '*' : missingAcls, allow)
4848
if (!access.allow) {
4949
throw createProxyAclError(scope, missingAcls)
5050
}

add-on/src/lib/ipfs-request.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
4545
// To reconstruct originUrl we read full URL from Referer header in onBeforeSendHeaders
4646
// and cache it for short time
4747
// TODO: when request.originUrl is available in Chrome the `originUrls` cache can be removed
48-
let cachedUrl = originUrls.get(request.requestId)
48+
const cachedUrl = originUrls.get(request.requestId)
4949
if (cachedUrl) return cachedUrl
5050
if (request.requestHeaders) {
5151
const referer = request.requestHeaders.find(h => h.name === 'Referer')
@@ -230,7 +230,7 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
230230
let addExpectHeader = true
231231
const expectHeader = { name: 'Expect', value: '100-continue' }
232232
const warningMsg = 'Executing "Expect: 100-continue" workaround for ipfs.add due to https://github.com/ipfs/go-ipfs/issues/5168'
233-
for (let header of request.requestHeaders) {
233+
for (const header of request.requestHeaders) {
234234
// Workaround A: https://github.com/ipfs/go-ipfs/issues/5168#issuecomment-401417420
235235
// (works in Firefox, but Chromium does not expose Connection header)
236236
/* (disabled so we use the workaround B in all browsers)
@@ -335,7 +335,7 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
335335
const notActiveGatewayOrApi = !(url.startsWith(state.pubGwURLString) || url.startsWith(state.gwURLString) || url.startsWith(state.apiURLString))
336336
if (state.detectIpfsPathHeader && request.responseHeaders && notActiveGatewayOrApi) {
337337
// console.log('onHeadersReceived.request', request)
338-
for (let header of request.responseHeaders) {
338+
for (const header of request.responseHeaders) {
339339
if (header.name.toLowerCase() === 'x-ipfs-path' && isSafeToRedirect(request, runtime)) {
340340
// console.log('onHeadersReceived.request.responseHeaders', request.responseHeaders.length)
341341
const xIpfsPath = header.value

add-on/src/lib/options.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function buildDefaultIpfsNodeType () {
4545
}
4646

4747
function buildDefaultIpfsNodeConfig () {
48-
let config = {
48+
const config = {
4949
config: {
5050
Addresses: {
5151
Swarm: []
@@ -88,11 +88,12 @@ function buildDefaultIpfsNodeConfig () {
8888
exports.storeMissingOptions = async (read, defaults, storage) => {
8989
const requiredKeys = Object.keys(defaults)
9090
const changes = {}
91-
for (let key of requiredKeys) {
91+
const has = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key)
92+
for (const key of requiredKeys) {
9293
// limit work to defaults and missing values, skip values other than defaults
93-
if (!read.hasOwnProperty(key) || read[key] === defaults[key]) {
94+
if (!has(read, key) || read[key] === defaults[key]) {
9495
const data = await storage.get(key)
95-
if (!data.hasOwnProperty(key)) { // detect and fix key without value in storage
96+
if (!has(data, key)) { // detect and fix key without value in storage
9697
changes[key] = defaults[key]
9798
}
9899
}

add-on/src/popup/browser-action/store.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module.exports = (state, emitter) => {
167167
try {
168168
let noRedirectHostnames = state.noRedirectHostnames
169169
// if we are on /ipns/fqdn.tld/ then use hostname from DNSLink
170-
let fqdn = state.currentDnslinkFqdn || state.currentFqdn
170+
const fqdn = state.currentDnslinkFqdn || state.currentFqdn
171171
if (noRedirectHostnames.includes(fqdn)) {
172172
noRedirectHostnames = noRedirectHostnames.filter(host => !host.endsWith(fqdn))
173173
} else {

add-on/src/popup/quick-upload.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function processFiles (state, emitter, files) {
6161
}
6262
const { ipfsCompanion } = await browser.runtime.getBackgroundPage()
6363
const uploadTab = await browser.tabs.getCurrent()
64-
let { streams, totalSize } = files2streams(files)
64+
const { streams, totalSize } = files2streams(files)
6565
progressHandler(0, totalSize, state, emitter)
6666
emitter.emit('render')
6767
const wrapFlag = (state.wrapWithDirectory || streams.length > 1)
@@ -113,7 +113,7 @@ function file2buffer (file) {
113113
function files2streams (files) {
114114
const streams = []
115115
let totalSize = 0
116-
for (let file of files) {
116+
for (const file of files) {
117117
if (!file.type && file.size === 0) {
118118
// UX fail-safe:
119119
// at the moment drag&drop of an empty file without an extension

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"simple-progress-webpack-plugin": "1.1.2",
100100
"sinon": "7.3.2",
101101
"sinon-chrome": "3.0.1",
102-
"standard": "12.0.1",
102+
"standard": "13.0.2",
103103
"tar": "4.4.10",
104104
"terser": "4.1.2",
105105
"terser-webpack-plugin": "1.3.0",

test/functional/lib/ipfs-companion.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('init', function () {
3838
browser.storage.local.set.returns(Promise.resolve())
3939
const ipfsCompanion = await init()
4040
const { movedFilesApis } = require('../../../add-on/src/lib/ipfs-client/index.js')
41-
for (let cmd of movedFilesApis) {
41+
for (const cmd of movedFilesApis) {
4242
expect(typeof ipfsCompanion.ipfs[cmd], `ipfs.${cmd} expected to be a function`).to.equal('function')
4343
expect(typeof ipfsCompanion.ipfs.files[cmd], `ipfs.files.${cmd} expected to be a function`).to.equal('function')
4444
}

test/functional/lib/ipfs-protocol.test.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ describe('ipfs-protocol', () => {
1111
const handler = createIpfsUrlProtocolHandler(() => ipfs)
1212
const request = { url }
1313

14-
const res = await new Promise(async (resolve, reject) => {
15-
try {
16-
await handler(request, resolve)
17-
} catch (err) {
18-
reject(err)
19-
}
14+
const res = await new Promise((resolve, reject) => {
15+
handler(request, resolve).catch((err) => reject(err))
2016
})
2117

2218
expect(res.data).to.equal(content)
@@ -36,12 +32,8 @@ describe('ipfs-protocol', () => {
3632
const handler = createIpfsUrlProtocolHandler(() => ipfs)
3733
const request = { url }
3834

39-
const res = await new Promise(async (resolve, reject) => {
40-
try {
41-
await handler(request, resolve)
42-
} catch (err) {
43-
reject(err)
44-
}
35+
const res = await new Promise((resolve, reject) => {
36+
handler(request, resolve).catch((err) => reject(err))
4537
})
4638

4739
expect(res.mimeType).to.equal('text/html')

test/functional/lib/ipfs-proxy/enable-command.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('lib/ipfs-proxy/enable-command', () => {
8484
await enable(permissions)
8585

8686
expect(requestAccess.called).to.equal(true)
87-
let { allow } = await accessControl.getAccess(getScope(), 'version')
87+
const { allow } = await accessControl.getAccess(getScope(), 'version')
8888
expect(allow).to.equal(true)
8989
})
9090

@@ -99,13 +99,13 @@ describe('lib/ipfs-proxy/enable-command', () => {
9999

100100
// ensure partial grant exists
101101
await accessControl.setAccess(getScope(), 'id', true)
102-
let idAcl = await accessControl.getAccess(getScope(), 'id')
102+
const idAcl = await accessControl.getAccess(getScope(), 'id')
103103
expect(idAcl.allow).to.equal(true)
104104

105105
await enable(permissions)
106106

107107
expect(requestAccess.called).to.equal(true)
108-
let versionAcl = await accessControl.getAccess(getScope(), 'version')
108+
const versionAcl = await accessControl.getAccess(getScope(), 'version')
109109
expect(versionAcl.allow).to.equal(true)
110110
})
111111

@@ -120,7 +120,7 @@ describe('lib/ipfs-proxy/enable-command', () => {
120120

121121
// ensure partial deny exists
122122
await accessControl.setAccess(getScope(), 'id', false)
123-
let idAcl = await accessControl.getAccess(getScope(), 'id')
123+
const idAcl = await accessControl.getAccess(getScope(), 'id')
124124
expect(idAcl.allow).to.equal(false)
125125

126126
// main test
@@ -136,7 +136,7 @@ describe('lib/ipfs-proxy/enable-command', () => {
136136
expect(() => { if (error) throw error }).to.throw(`User denied access to selected commands over IPFS proxy: id`)
137137

138138
// ensure explicit version acl is still missing
139-
let versionAcl = await accessControl.getAccess(getScope(), 'version')
139+
const versionAcl = await accessControl.getAccess(getScope(), 'version')
140140
expect(versionAcl).to.equal(null)
141141
})
142142

test/functional/lib/ipfs-request-workarounds.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('modifyRequest processing', function () {
1919
// stub URL.origin in test context to return something other than null
2020
Object.defineProperty(URL.prototype, 'origin', {
2121
get: function () {
22-
let fakeOrigin = this.href.split('/')
22+
const fakeOrigin = this.href.split('/')
2323
if (fakeOrigin.length >= 3) {
2424
return fakeOrigin.slice(0, 3).join('/')
2525
}
@@ -65,7 +65,7 @@ describe('modifyRequest processing', function () {
6565
// test
6666
const bogusOriginHeader = { name: 'Origin', value: 'moz-extension://0f334731-19e3-42f8-85e2-03dbf50026df' }
6767
const request = {
68-
requestHeaders: [ bogusOriginHeader ],
68+
requestHeaders: [bogusOriginHeader],
6969
type: 'xmlhttprequest',
7070
url: `${state.apiURLString}api/v0/id`
7171
}
@@ -85,7 +85,7 @@ describe('modifyRequest processing', function () {
8585
// test
8686
const bogusOriginHeader = { name: 'Origin', value: 'chrome-extension://trolrorlrorlrol' }
8787
const request = {
88-
requestHeaders: [ bogusOriginHeader ],
88+
requestHeaders: [bogusOriginHeader],
8989
type: 'xmlhttprequest',
9090
url: `${state.apiURLString}api/v0/id`
9191
}
@@ -105,7 +105,7 @@ describe('modifyRequest processing', function () {
105105
// test
106106
const bogusOriginHeader = { name: 'Origin', value: 'null' }
107107
const request = {
108-
requestHeaders: [ bogusOriginHeader ],
108+
requestHeaders: [bogusOriginHeader],
109109
type: 'xmlhttprequest',
110110
url: `${state.apiURLString}api/v0/id`
111111
}
@@ -131,7 +131,7 @@ describe('modifyRequest processing', function () {
131131

132132
// Test request
133133
let request = {
134-
requestHeaders: [ webuiOriginHeader, webuiRefererHeader, acrhHeader ],
134+
requestHeaders: [webuiOriginHeader, webuiRefererHeader, acrhHeader],
135135
type: 'xmlhttprequest',
136136
originUrl: state.webuiRootUrl,
137137
url: `${state.apiURLString}api/v0/id`

0 commit comments

Comments
 (0)