Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit dc4be3f

Browse files
author
Alan Shaw
authored
chore: lint cleanup (#1779)
All that is left is TODO comment warnings License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent 8cd4d54 commit dc4be3f

File tree

9 files changed

+53
-54
lines changed

9 files changed

+53
-54
lines changed

src/cli/commands/cat.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,8 @@ module.exports = {
1818
}
1919
},
2020

21-
handler (argv) {
22-
let path = argv['ipfsPath']
23-
if (path.indexOf('/ipfs/') !== 1) {
24-
path = path.replace('/ipfs/', '')
25-
}
26-
27-
const options = {
28-
offset: argv.offset,
29-
length: argv.length
30-
}
31-
32-
const stream = argv.ipfs.catReadableStream(path, options)
21+
handler ({ ipfs, ipfsPath, offset, length }) {
22+
const stream = ipfs.catReadableStream(ipfsPath, { offset, length })
3323

3424
stream.once('error', (err) => {
3525
throw err

src/cli/commands/dns.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ module.exports = {
1212
}
1313
},
1414

15-
handler (argv) {
16-
argv.ipfs.dns(argv['domain'], (err, path) => {
15+
handler ({ ipfs, domain }) {
16+
ipfs.dns(domain, (err, path) => {
1717
if (err) {
1818
throw err
1919
}

src/cli/commands/get.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ module.exports = {
5858
}
5959
},
6060

61-
handler (argv) {
62-
const ipfsPath = argv['ipfsPath']
63-
64-
const dir = checkArgs(ipfsPath, argv.output)
65-
66-
const stream = argv.ipfs.getReadableStream(ipfsPath)
61+
handler ({ ipfs, ipfsPath, output }) {
62+
const dir = checkArgs(ipfsPath, output)
63+
const stream = ipfs.getReadableStream(ipfsPath)
6764

6865
stream.once('error', (err) => {
6966
if (err) { throw err }

src/cli/commands/stats/bw.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const pull = require('pull-stream')
4+
const print = require('../../utils').print
45

56
module.exports = {
67
command: 'bw',
@@ -26,18 +27,13 @@ module.exports = {
2627
}
2728
},
2829

29-
handler (argv) {
30-
const stream = argv.ipfs.stats.bwPullStream({
31-
peer: argv.peer,
32-
proto: argv.proto,
33-
poll: argv.poll,
34-
interval: argv.interval
35-
})
30+
handler ({ ipfs, peer, proto, poll, interval }) {
31+
const stream = ipfs.stats.bwPullStream({ peer, proto, poll, interval })
3632

3733
pull(
3834
stream,
3935
pull.drain((chunk) => {
40-
console.log(`bandwidth status
36+
print(`bandwidth status
4137
total in: ${chunk.totalIn}B
4238
total out: ${chunk.totalOut}B
4339
rate in: ${chunk.rateIn}B/s

src/core/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class IPFS extends EventEmitter {
127127
this._preload = preload(this)
128128
this._mfsPreload = mfsPreload(this)
129129
this._ipns = undefined
130+
// eslint-disable-next-line no-console
130131
this._print = this._options.silent ? this.log : console.log
131132

132133
// IPFS Core exposed components

src/core/runtime/dns-browser.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
'use strict'
33

44
module.exports = (domain, opts, callback) => {
5+
if (typeof opts === 'function') {
6+
callback = opts
7+
opts = {}
8+
}
9+
10+
opts = opts || {}
11+
512
domain = encodeURIComponent(domain)
613
let url = `https://ipfs.io/api/v0/dns?arg=${domain}`
714

8-
for (const prop in opts) {
9-
url += `&${prop}=${opts[prop]}`
10-
}
15+
Object.keys(opts).forEach(prop => {
16+
url += `&${encodeURIComponent(prop)}=${encodeURIComponent(opts[prop])}`
17+
})
1118

1219
self.fetch(url, { mode: 'cors' })
1320
.then((response) => {

src/http/api/resources/files-regular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ exports.add = {
235235
rawLeaves: request.query['raw-leaves'],
236236
progress: request.query.progress ? progressHandler : null,
237237
onlyHash: request.query['only-hash'],
238-
hashAlg: request.query['hash'],
238+
hashAlg: request.query.hash,
239239
wrapWithDirectory: request.query['wrap-with-directory'],
240240
pin: request.query.pin,
241241
chunker: request.query.chunker

src/http/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,20 @@ function HttpApi (repo, config, cliArgs) {
5353
// Attempt to use any of the WebRTC versions available globally
5454
let electronWebRTC
5555
let wrtc
56-
try { electronWebRTC = require('electron-webrtc')() } catch (err) {}
57-
try { wrtc = require('wrtc') } catch (err) {}
56+
try {
57+
electronWebRTC = require('electron-webrtc')()
58+
} catch (err) {
59+
this.log('failed to load optional electron-webrtc dependency')
60+
}
61+
try {
62+
wrtc = require('wrtc')
63+
} catch (err) {
64+
this.log('failed to load optional webrtc dependency')
65+
}
5866

5967
if (wrtc || electronWebRTC) {
6068
const using = wrtc ? 'wrtc' : 'electron-webrtc'
61-
console.log(`Using ${using} for webrtc support`)
69+
this.log(`Using ${using} for webrtc support`)
6270
const wstar = new WStar({ wrtc: (wrtc || electronWebRTC) })
6371
libp2p.modules.transport = [TCP, WS, wstar]
6472
libp2p.modules.peerDiscovery = [MulticastDNS, Bootstrap, wstar.discovery]
@@ -179,7 +187,7 @@ function HttpApi (repo, config, cliArgs) {
179187
], (err) => {
180188
if (err) {
181189
this.log.error(err)
182-
console.log('There were errors stopping')
190+
console.error('There were errors stopping')
183191
}
184192
callback()
185193
})

test/gateway/index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ describe('HTTP Gateway', function () {
145145
expect(res.statusCode).to.equal(400)
146146
expect(res.result.Message).to.be.a('string')
147147
expect(res.headers['cache-control']).to.equal('no-cache')
148-
expect(res.headers['etag']).to.equal(undefined)
148+
expect(res.headers.etag).to.equal(undefined)
149149
expect(res.headers['x-ipfs-path']).to.equal(undefined)
150-
expect(res.headers['suborigin']).to.equal(undefined)
150+
expect(res.headers.suborigin).to.equal(undefined)
151151
done()
152152
})
153153
})
@@ -160,9 +160,9 @@ describe('HTTP Gateway', function () {
160160
expect(res.statusCode).to.equal(400)
161161
expect(res.result.Message).to.be.a('string')
162162
expect(res.headers['cache-control']).to.equal('no-cache')
163-
expect(res.headers['etag']).to.equal(undefined)
163+
expect(res.headers.etag).to.equal(undefined)
164164
expect(res.headers['x-ipfs-path']).to.equal(undefined)
165-
expect(res.headers['suborigin']).to.equal(undefined)
165+
expect(res.headers.suborigin).to.equal(undefined)
166166
done()
167167
})
168168
})
@@ -176,9 +176,9 @@ describe('HTTP Gateway', function () {
176176
expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n'))
177177
expect(res.payload).to.equal('hello world' + '\n')
178178
expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable')
179-
expect(res.headers['etag']).to.equal('"QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o"')
179+
expect(res.headers.etag).to.equal('"QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o"')
180180
expect(res.headers['x-ipfs-path']).to.equal('/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o')
181-
expect(res.headers['suborigin']).to.equal('ipfs000bafybeicg2rebjoofv4kbyovkw7af3rpiitvnl6i7ckcywaq6xjcxnc2mby')
181+
expect(res.headers.suborigin).to.equal('ipfs000bafybeicg2rebjoofv4kbyovkw7af3rpiitvnl6i7ckcywaq6xjcxnc2mby')
182182

183183
done()
184184
})
@@ -193,9 +193,9 @@ describe('HTTP Gateway', function () {
193193
expect(res.statusCode).to.equal(200)
194194
expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n'))
195195
expect(res.payload).to.equal('hello world' + '\n')
196-
expect(res.headers['etag']).to.equal(TO-DO)
196+
expect(res.headers.etag).to.equal(TO-DO)
197197
expect(res.headers['x-ipfs-path']).to.equal(TO-DO)
198-
expect(res.headers['suborigin']).to.equal(TO-DO)
198+
expect(res.headers.suborigin).to.equal(TO-DO)
199199
expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable')
200200
201201
done()
@@ -227,8 +227,8 @@ describe('HTTP Gateway', function () {
227227
expect(res.headers['content-type']).to.equal('image/jpeg')
228228
expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + kitty)
229229
expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable')
230-
expect(res.headers['etag']).to.equal('"Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u"')
231-
expect(res.headers['suborigin']).to.equal('ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4')
230+
expect(res.headers.etag).to.equal('"Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u"')
231+
expect(res.headers.suborigin).to.equal('ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4')
232232

233233
let fileSignature = fileType(res.rawPayload)
234234
expect(fileSignature.mime).to.equal('image/jpeg')
@@ -277,8 +277,8 @@ describe('HTTP Gateway', function () {
277277
expect(res.headers['content-type']).to.equal('text/html; charset=utf-8')
278278
expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + dir)
279279
expect(res.headers['cache-control']).to.equal('no-cache')
280-
expect(res.headers['etag']).to.equal(undefined)
281-
expect(res.headers['suborigin']).to.equal('ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4')
280+
expect(res.headers.etag).to.equal(undefined)
281+
expect(res.headers.suborigin).to.equal('ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4')
282282

283283
// check if the cat picture is in the payload as a way to check
284284
// if this is an index of this directory
@@ -299,8 +299,8 @@ describe('HTTP Gateway', function () {
299299
expect(res.headers['content-type']).to.equal('text/html; charset=utf-8')
300300
expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + dir)
301301
expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable')
302-
expect(res.headers['etag']).to.equal('"Qma6665X5k3zti8nKy7gmXK2BndNDSkgmANpV6k3FUjUeg"')
303-
expect(res.headers['suborigin']).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe')
302+
expect(res.headers.etag).to.equal('"Qma6665X5k3zti8nKy7gmXK2BndNDSkgmANpV6k3FUjUeg"')
303+
expect(res.headers.suborigin).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe')
304304
expect(res.rawPayload).to.deep.equal(directoryContent['index.html'])
305305
done()
306306
})
@@ -317,8 +317,8 @@ describe('HTTP Gateway', function () {
317317
expect(res.headers['content-type']).to.equal('text/html; charset=utf-8')
318318
expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + dir)
319319
expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable')
320-
expect(res.headers['etag']).to.equal('"QmUBKGqJWiJYMrNed4bKsbo1nGYGmY418WCc2HgcwRvmHc"')
321-
expect(res.headers['suborigin']).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe')
320+
expect(res.headers.etag).to.equal('"QmUBKGqJWiJYMrNed4bKsbo1nGYGmY418WCc2HgcwRvmHc"')
321+
expect(res.headers.suborigin).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe')
322322
expect(res.rawPayload).to.deep.equal(directoryContent['nested-folder/nested.html'])
323323
done()
324324
})
@@ -332,7 +332,7 @@ describe('HTTP Gateway', function () {
332332
url: '/ipfs/' + dir
333333
}, (res) => {
334334
expect(res.statusCode).to.equal(301)
335-
expect(res.headers['location']).to.equal('/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/')
335+
expect(res.headers.location).to.equal('/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/')
336336
expect(res.headers['x-ipfs-path']).to.equal(undefined)
337337
done()
338338
})
@@ -346,7 +346,7 @@ describe('HTTP Gateway', function () {
346346
url: '/ipfs/' + dir
347347
}, (res) => {
348348
expect(res.statusCode).to.equal(302)
349-
expect(res.headers['location']).to.equal('/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html')
349+
expect(res.headers.location).to.equal('/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html')
350350
expect(res.headers['x-ipfs-path']).to.equal(undefined)
351351
done()
352352
})

0 commit comments

Comments
 (0)