From 77991492d72c88f15c3447a88d81d9eeffbcfcfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 17 Jun 2019 08:51:22 -0700 Subject: [PATCH] fix(standard): standard --fix --- lib/content/path.js | 2 +- lib/content/read.js | 12 +++++----- lib/content/write.js | 6 ++--- lib/entry-index.js | 8 +++---- lib/util/fix-owner.js | 4 ++-- lib/verify.js | 8 +++---- put.js | 4 ++-- test/benchmarks/index.find.js | 4 ++-- test/benchmarks/index.js | 2 +- test/content.read.js | 16 ++++++------- test/index.find.js | 4 ++-- test/index.insert.js | 2 +- test/memoization.js | 42 +++++++++++++++++------------------ test/put.js | 2 +- test/rm.js | 6 ++--- test/util.tmp.js | 2 +- test/verify.js | 4 ++-- 17 files changed, 64 insertions(+), 64 deletions(-) diff --git a/lib/content/path.js b/lib/content/path.js index fa6491b..c67c280 100644 --- a/lib/content/path.js +++ b/lib/content/path.js @@ -12,7 +12,7 @@ const ssri = require('ssri') // module.exports = contentPath function contentPath (cache, integrity) { - const sri = ssri.parse(integrity, {single: true}) + const sri = ssri.parse(integrity, { single: true }) // contentPath is the *strongest* algo given return path.join.apply(path, [ contentDir(cache), diff --git a/lib/content/read.js b/lib/content/read.js index 8f1acc0..7929524 100644 --- a/lib/content/read.js +++ b/lib/content/read.js @@ -54,8 +54,8 @@ function readStream (cache, integrity, opts) { opts = ReadOpts(opts) const stream = new PassThrough() withContentSri(cache, integrity, (cpath, sri) => { - return lstatAsync(cpath).then(stat => ({cpath, sri, stat})) - }).then(({cpath, sri, stat}) => { + return lstatAsync(cpath).then(stat => ({ cpath, sri, stat })) + }).then(({ cpath, sri, stat }) => { return pipe( fs.createReadStream(cpath), ssri.integrityStream({ @@ -95,7 +95,7 @@ module.exports.hasContent = hasContent function hasContent (cache, integrity) { if (!integrity) { return BB.resolve(false) } return withContentSri(cache, integrity, (cpath, sri) => { - return lstatAsync(cpath).then(stat => ({size: stat.size, sri, stat})) + return lstatAsync(cpath).then(stat => ({ size: stat.size, sri, stat })) }).catch(err => { if (err.code === 'ENOENT') { return false } if (err.code === 'EPERM') { @@ -114,7 +114,7 @@ function hasContentSync (cache, integrity) { return withContentSriSync(cache, integrity, (cpath, sri) => { try { const stat = fs.lstatSync(cpath) - return {size: stat.size, sri, stat} + return { size: stat.size, sri, stat } } catch (err) { if (err.code === 'ENOENT') { return false } if (err.code === 'EPERM') { @@ -141,12 +141,12 @@ function withContentSri (cache, integrity, fn) { } else { return BB.any(sri[sri.pickAlgorithm()].map(meta => { return withContentSri(cache, meta, fn) - }, {concurrency: 1})) + }, { concurrency: 1 })) .catch(err => { if ([].some.call(err, e => e.code === 'ENOENT')) { throw Object.assign( new Error('No matching content found for ' + sri.toString()), - {code: 'ENOENT'} + { code: 'ENOENT' } ) } else { throw err[0] diff --git a/lib/content/write.js b/lib/content/write.js index ff0d15a..150371c 100644 --- a/lib/content/write.js +++ b/lib/content/write.js @@ -36,11 +36,11 @@ function write (cache, data, opts) { } return BB.using(makeTmp(cache, opts), tmp => ( writeFileAsync( - tmp.target, data, {flag: 'wx'} + tmp.target, data, { flag: 'wx' } ).then(() => ( moveToDestination(tmp, cache, sri, opts) )) - )).then(() => ({integrity: sri, size: data.length})) + )).then(() => ({ integrity: sri, size: data.length })) } module.exports.stream = writeStream @@ -111,7 +111,7 @@ function pipeToTmp (inputStream, cache, tmpTarget, opts, errCheck) { }) errCheck() return pipe(inputStream, hashStream, outStream).then(() => { - return {integrity, size} + return { integrity, size } }).catch(err => { return rimraf(tmpTarget).then(() => { throw err }) }) diff --git a/lib/entry-index.js b/lib/entry-index.js index 29a688e..d2549e7 100644 --- a/lib/entry-index.js +++ b/lib/entry-index.js @@ -64,7 +64,7 @@ function insert (cache, key, integrity, opts) { ) }).then( () => fixOwner.chownr(bucket, opts.uid, opts.gid) - ).catch({code: 'ENOENT'}, () => { + ).catch({ code: 'ENOENT' }, () => { // There's a class of race conditions that happen when things get deleted // during fixOwner, or between the two mkdirfix/chownr calls. // @@ -178,7 +178,7 @@ function lsStream (cache) { const formatted = formatEntry(cache, entry) formatted && stream.push(formatted) } - }).catch({code: 'ENOENT'}, nop) + }).catch({ code: 'ENOENT' }, nop) }) }) }).then(() => { @@ -282,8 +282,8 @@ function formatEntry (cache, entry) { function readdirOrEmpty (dir) { return readdirAsync(dir) - .catch({code: 'ENOENT'}, () => []) - .catch({code: 'ENOTDIR'}, () => []) + .catch({ code: 'ENOENT' }, () => []) + .catch({ code: 'ENOTDIR' }, () => []) } function nop () { diff --git a/lib/util/fix-owner.js b/lib/util/fix-owner.js index 0c8f9f8..563724c 100644 --- a/lib/util/fix-owner.js +++ b/lib/util/fix-owner.js @@ -27,7 +27,7 @@ function fixOwner (filepath, uid, gid) { filepath, typeof uid === 'number' ? uid : process.getuid(), typeof gid === 'number' ? gid : process.getgid() - ).catch({code: 'ENOENT'}, () => null) + ).catch({ code: 'ENOENT' }, () => null) ) } @@ -65,7 +65,7 @@ function mkdirfix (p, uid, gid, cb) { if (made) { return fixOwner(made, uid, gid).then(() => made) } - }).catch({code: 'EEXIST'}, () => { + }).catch({ code: 'EEXIST' }, () => { // There's a race in mkdirp! return fixOwner(p, uid, gid).then(() => null) }) diff --git a/lib/verify.js b/lib/verify.js index 3468bc6..8eaab0b 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -130,7 +130,7 @@ function garbageCollect (cache, opts) { }) }) } - }, {concurrency: opts.concurrency})) + }, { concurrency: opts.concurrency })) }) }) } @@ -150,7 +150,7 @@ function verifyContent (filepath, sri) { contentInfo.valid = false }) }).then(() => contentInfo) - }).catch({code: 'ENOENT'}, () => ({size: 0, valid: false})) + }).catch({ code: 'ENOENT' }, () => ({ size: 0, valid: false })) } function rebuildIndex (cache, opts) { @@ -183,7 +183,7 @@ function rebuildIndex (cache, opts) { } return BB.map(Object.keys(buckets), key => { return rebuildBucket(cache, buckets[key], stats, opts) - }, {concurrency: opts.concurrency}).then(() => stats) + }, { concurrency: opts.concurrency }).then(() => stats) }) } @@ -200,7 +200,7 @@ function rebuildBucket (cache, bucket, stats, opts) { metadata: entry.metadata, size: entry.size }).then(() => { stats.totalEntries++ }) - }).catch({code: 'ENOENT'}, () => { + }).catch({ code: 'ENOENT' }, () => { stats.rejectedEntries++ stats.missingContent++ }) diff --git a/put.js b/put.js index 01b0dd8..a60cc55 100644 --- a/put.js +++ b/put.js @@ -28,7 +28,7 @@ function putData (cache, key, data, opts) { opts = PutOpts(opts) return write(cache, data, opts).then(res => { return index.insert( - cache, key, res.integrity, opts.concat({size: res.size}) + cache, key, res.integrity, opts.concat({ size: res.size }) ).then(entry => { if (opts.memoize) { memo.put(cache, entry, data, opts) @@ -63,7 +63,7 @@ function putStream (cache, key, opts) { }) }, cb => { contentStream.end(() => { - index.insert(cache, key, integrity, opts.concat({size})).then(entry => { + index.insert(cache, key, integrity, opts.concat({ size })).then(entry => { if (opts.memoize) { memo.put(cache, entry, Buffer.concat(memoData, memoTotal), opts) } diff --git a/test/benchmarks/index.find.js b/test/benchmarks/index.find.js index e237c8e..df08f27 100644 --- a/test/benchmarks/index.find.js +++ b/test/benchmarks/index.find.js @@ -44,8 +44,8 @@ module.exports = (suite, CACHE) => { }, onStart () { const fixture = new Tacks(CacheIndex({ - 'foo': {key: 'foo'}, - 'w/e': {key: 'w/e'} + 'foo': { key: 'foo' }, + 'w/e': { key: 'w/e' } })) fixture.create(CACHE) this.fixture = fixture diff --git a/test/benchmarks/index.js b/test/benchmarks/index.js index 01d729b..1bc7ae6 100644 --- a/test/benchmarks/index.js +++ b/test/benchmarks/index.js @@ -71,5 +71,5 @@ fs.readdir(__dirname, (err, files) => { require('./' + f)(suite, path.join(CACHE, path.basename(f, '.js'))) } }) - suite.run({async: true}) + suite.run({ async: true }) }) diff --git a/test/content.read.js b/test/content.read.js index d55736c..83ca3c7 100644 --- a/test/content.read.js +++ b/test/content.read.js @@ -54,7 +54,7 @@ test('read.stream: returns a stream with cache content data', function (t) { stream.on('data', function (data) { buf += data }) return BB.join( finished(stream).then(() => Buffer.from(buf)), - read(CACHE, INTEGRITY, {size: CONTENT.length}), + read(CACHE, INTEGRITY, { size: CONTENT.length }), (fromStream, fromBulk) => { t.deepEqual(fromStream, CONTENT, 'stream data checks out') t.deepEqual(fromBulk, CONTENT, 'promise data checks out') @@ -65,7 +65,7 @@ test('read.stream: returns a stream with cache content data', function (t) { test('read: allows hashAlgorithm configuration', function (t) { const CONTENT = Buffer.from('foobarbaz') const HASH = 'whirlpool' - const INTEGRITY = ssri.fromData(CONTENT, {algorithms: [HASH]}) + const INTEGRITY = ssri.fromData(CONTENT, { algorithms: [HASH] }) const fixture = new Tacks(CacheContent({ [INTEGRITY]: CONTENT })) @@ -93,8 +93,8 @@ test('read: errors if content missing', function (t) { throw new Error('end was called even though stream errored') }) return BB.join( - finished(stream).catch({code: 'ENOENT'}, err => err), - read(CACHE, 'sha512-whatnot').catch({code: 'ENOENT'}, err => err), + finished(stream).catch({ code: 'ENOENT' }, err => err), + read(CACHE, 'sha512-whatnot').catch({ code: 'ENOENT' }, err => err), (streamErr, bulkErr) => { t.equal(streamErr.code, 'ENOENT', 'stream got the right error') t.equal(bulkErr.code, 'ENOENT', 'bulk got the right error') @@ -114,8 +114,8 @@ test('read: errors if content fails checksum', function (t) { throw new Error('end was called even though stream errored') }) return BB.join( - finished(stream).catch({code: 'EINTEGRITY'}, err => err), - read(CACHE, INTEGRITY).catch({code: 'EINTEGRITY'}, err => err), + finished(stream).catch({ code: 'EINTEGRITY' }, err => err), + read(CACHE, INTEGRITY).catch({ code: 'EINTEGRITY' }, err => err), (streamErr, bulkErr) => { t.equal(streamErr.code, 'EINTEGRITY', 'stream got the right error') t.equal(bulkErr.code, 'EINTEGRITY', 'bulk got the right error') @@ -135,10 +135,10 @@ test('read: errors if content size does not match size option', function (t) { throw new Error('end was called even though stream errored') }) return BB.join( - finished(stream).catch({code: 'EBADSIZE'}, err => err), + finished(stream).catch({ code: 'EBADSIZE' }, err => err), read(CACHE, INTEGRITY, { size: CONTENT.length - }).catch({code: 'EBADSIZE'}, err => err), + }).catch({ code: 'EBADSIZE' }, err => err), (streamErr, bulkErr) => { t.equal(streamErr.code, 'EBADSIZE', 'stream got the right error') t.equal(bulkErr.code, 'EBADSIZE', 'bulk got the right error') diff --git a/test/index.find.js b/test/index.find.js index abe78c0..f5205ce 100644 --- a/test/index.find.js +++ b/test/index.find.js @@ -43,8 +43,8 @@ test('index.find cache hit', function (t) { test('index.find cache miss', function (t) { const fixture = new Tacks(CacheIndex({ - 'foo': {key: 'foo'}, - 'w/e': {key: 'w/e'} + 'foo': { key: 'foo' }, + 'w/e': { key: 'w/e' } })) fixture.create(CACHE) return index.find( diff --git a/test/index.insert.js b/test/index.insert.js index 2055e8b..0d71bc5 100644 --- a/test/index.insert.js +++ b/test/index.insert.js @@ -59,7 +59,7 @@ test('inserts additional entries into existing key', function (t) { return index.insert(CACHE, KEY, INTEGRITY, opts({ metadata: 1 })).then(() => ( - index.insert(CACHE, KEY, INTEGRITY, opts({metadata: 2})) + index.insert(CACHE, KEY, INTEGRITY, opts({ metadata: 2 })) )).then(() => { return fs.readFileAsync(BUCKET, 'utf8') }).then(data => { diff --git a/test/memoization.js b/test/memoization.js index 1a6c8f6..d079824 100644 --- a/test/memoization.js +++ b/test/memoization.js @@ -70,25 +70,25 @@ test('can clear out the memoization cache', t => { test('accepts optional injected cache', t => { memo.clearMemoized() const MEMO = new Map() - memo.put(CACHE, ENTRY, DATA, {memoize: MEMO}) + memo.put(CACHE, ENTRY, DATA, { memoize: MEMO }) t.deepEqual( memo.get(CACHE, ENTRY.key), null, 'entry not in global memo cache' ) t.deepEqual( - memo.get(CACHE, ENTRY.key, {memoize: MEMO}), - {entry: ENTRY, data: DATA}, + memo.get(CACHE, ENTRY.key, { memoize: MEMO }), + { entry: ENTRY, data: DATA }, 'entry fetched from injected memoizer' ) t.deepEqual( - memo.get.byDigest(CACHE, ENTRY.integrity, {memoize: MEMO}), + memo.get.byDigest(CACHE, ENTRY.integrity, { memoize: MEMO }), DATA, 'content entry fetched from injected memoizer' ) t.deepEqual( MEMO.get(`key:${CACHE}:${ENTRY.key}`), - {entry: ENTRY, data: DATA}, + { entry: ENTRY, data: DATA }, 'entry is in the injected memoizer' ) t.deepEqual( @@ -98,62 +98,62 @@ test('accepts optional injected cache', t => { ) MEMO.clear() t.deepEqual( - memo.get(CACHE, ENTRY.key, {memoize: MEMO}), + memo.get(CACHE, ENTRY.key, { memoize: MEMO }), null, 'tried to read from cleared memoizer' ) t.deepEqual( - memo.get.byDigest(CACHE, ENTRY.integrity, {memoize: MEMO}), + memo.get.byDigest(CACHE, ENTRY.integrity, { memoize: MEMO }), null, 'tried to read by digest from cleared memoizer' ) - memo.put.byDigest(CACHE, ENTRY.integrity, DATA, {memoize: MEMO}) + memo.put.byDigest(CACHE, ENTRY.integrity, DATA, { memoize: MEMO }) t.deepEqual( MEMO.get(`digest:${CACHE}:${ENTRY.integrity}`), DATA, 'content entry is in the injected memoizer' ) const obj = {} - memo.put(CACHE, ENTRY, DATA, {memoize: obj}) + memo.put(CACHE, ENTRY, DATA, { memoize: obj }) t.deepEqual( - memo.get(CACHE, ENTRY.key, {memoize: obj}), - {entry: ENTRY, data: DATA}, + memo.get(CACHE, ENTRY.key, { memoize: obj }), + { entry: ENTRY, data: DATA }, 'entry fetched from injected object memoizer' ) t.deepEqual( - memo.get.byDigest(CACHE, ENTRY.integrity, {memoize: MEMO}), + memo.get.byDigest(CACHE, ENTRY.integrity, { memoize: MEMO }), DATA, 'content entry fetched from injected object memoizer' ) memo.clearMemoized() - memo.put(CACHE, ENTRY, DATA, {memoize: 'foo'}) + memo.put(CACHE, ENTRY, DATA, { memoize: 'foo' }) t.deepEqual( - memo.get(CACHE, ENTRY.key, {memoize: 'foo'}), - {entry: ENTRY, data: DATA}, + memo.get(CACHE, ENTRY.key, { memoize: 'foo' }), + { entry: ENTRY, data: DATA }, 'entry fetched from global memoization obj on non-obj option' ) t.deepEqual( - memo.get(CACHE, ENTRY.key, {memoize: 'foo'}), - {entry: ENTRY, data: DATA}, + memo.get(CACHE, ENTRY.key, { memoize: 'foo' }), + { entry: ENTRY, data: DATA }, 'entry fetched from global memoization obj on non-obj option' ) t.deepEqual( - memo.get.byDigest(CACHE, ENTRY.integrity, {memoize: 'foo'}), + memo.get.byDigest(CACHE, ENTRY.integrity, { memoize: 'foo' }), DATA, 'content entry fetched global memoizer obj on non-obj option' ) t.deepEqual( - memo.get.byDigest(CACHE, ENTRY.integrity, {memoize: 'foo'}), + memo.get.byDigest(CACHE, ENTRY.integrity, { memoize: 'foo' }), DATA, 'content entry fetched global memoizer obj on non-obj option' ) t.deepEqual( - memo.get.byDigest(CACHE, ENTRY.integrity, {memoize: false}), + memo.get.byDigest(CACHE, ENTRY.integrity, { memoize: false }), DATA, 'content entry fetched global memoizer obj on non-obj option' ) t.deepEqual( - memo.get.byDigest(CACHE, ENTRY.integrity, {memoize: false}), + memo.get.byDigest(CACHE, ENTRY.integrity, { memoize: false }), DATA, 'content entry fetched global memoizer obj on non-obj option' ) diff --git a/test/put.js b/test/put.js index ac182f9..8658be9 100644 --- a/test/put.js +++ b/test/put.js @@ -46,7 +46,7 @@ test('basic stream insertion', t => { }) test('adds correct entry to index before finishing', t => { - return put(CACHE, KEY, CONTENT, {metadata: METADATA}).then(() => { + return put(CACHE, KEY, CONTENT, { metadata: METADATA }).then(() => { return index.find(CACHE, KEY) }).then(entry => { t.ok(entry, 'got an entry') diff --git a/test/rm.js b/test/rm.js index a5e5439..6d32e2f 100644 --- a/test/rm.js +++ b/test/rm.js @@ -36,7 +36,7 @@ test('rm.entry removes entries, not content', t => { return get(CACHE, KEY) }).then(res => { throw new Error('unexpected success') - }).catch({code: 'ENOENT'}, err => { + }).catch({ code: 'ENOENT' }, err => { t.match(err.message, KEY, 'entry no longer accessible') }).then(() => { return fs.readFileAsync(contentPath(CACHE, INTEGRITY)) @@ -58,13 +58,13 @@ test('rm.content removes content, not entries', t => { return get(CACHE, KEY) }).then(res => { throw new Error('unexpected success') - }).catch({code: 'ENOENT'}, err => { + }).catch({ code: 'ENOENT' }, err => { t.match(err.message, /no such file/, 'entry no longer accessible') }).then(() => { return fs.readFileAsync(contentPath(CACHE, INTEGRITY)) }).then(() => { throw new Error('unexpected success') - }).catch({code: 'ENOENT'}, err => { + }).catch({ code: 'ENOENT' }, err => { t.match(err.message, /no such file/, 'content gone') }) }) diff --git a/test/util.tmp.js b/test/util.tmp.js index 09a1f11..2f42b53 100644 --- a/test/util.tmp.js +++ b/test/util.tmp.js @@ -28,7 +28,7 @@ test('provides a utility that does resource disposal on tmp', t => { return BB.join( fs.statAsync(dir).then(() => { throw new Error('expected fail') - }).catch({code: 'ENOENT'}, () => {}), + }).catch({ code: 'ENOENT' }, () => {}), fs.statAsync(path.join(CACHE, 'tmp')), (nope, yes) => { t.notOk(nope, 'tmp subdir removed') diff --git a/test/verify.js b/test/verify.js index c9134db..57e646f 100644 --- a/test/verify.js +++ b/test/verify.js @@ -143,7 +143,7 @@ test('removes corrupted content', t => { }, 'reported correct collection counts') return fs.statAsync(cpath).then(() => { throw new Error('expected a failure') - }).catch({code: 'ENOENT'}, err => { + }).catch({ code: 'ENOENT' }, err => { t.match(err.message, /no such file/, 'content no longer in cache') }) }) @@ -182,7 +182,7 @@ test('cleans up contents of tmp dir', t => { ) }).then(() => { return BB.join( - fs.statAsync(tmpFile).catch({code: 'ENOENT'}, e => e), + fs.statAsync(tmpFile).catch({ code: 'ENOENT' }, e => e), fs.statAsync(misc), (err, stat) => { t.equal(err.code, 'ENOENT', 'tmp file was blown away')