Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Bump standard from 14.x to 16.x
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Apr 17, 2021
1 parent 43c1544 commit 7cb4c10
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 76 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ updates:
- dependency-name: dependency-check
- dependency-name: cross-env
- dependency-name: node-gyp
- dependency-name: standard
- dependency-name: tempy
2 changes: 2 additions & 0 deletions chained-batch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const util = require('util')
const AbstractChainedBatch = require('abstract-leveldown').AbstractChainedBatch
const binding = require('./binding')
Expand Down
12 changes: 6 additions & 6 deletions iterator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const util = require('util')
const AbstractIterator = require('abstract-leveldown').AbstractIterator
const binding = require('./binding')
Expand All @@ -23,19 +25,17 @@ Iterator.prototype._seek = function (target) {
}

Iterator.prototype._next = function (callback) {
var that = this

if (this.cache && this.cache.length) {
process.nextTick(callback, null, this.cache.pop(), this.cache.pop())
} else if (this.finished) {
process.nextTick(callback)
} else {
binding.iterator_next(this.context, function (err, array, finished) {
binding.iterator_next(this.context, (err, array, finished) => {
if (err) return callback(err)

that.cache = array
that.finished = finished
that._next(callback)
this.cache = array
this.finished = finished
this._next(callback)
})
}

Expand Down
2 changes: 2 additions & 0 deletions leveldown.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const util = require('util')
const AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
const binding = require('./binding')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"prebuildify-cross": "^4.0.0",
"readfiletree": "^1.0.0",
"rimraf": "^3.0.0",
"standard": "^14.0.0",
"standard": "^16.0.3",
"tape": "^5.0.1",
"tempy": "^0.3.0"
},
Expand Down
6 changes: 3 additions & 3 deletions test/approximate-size-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const test = require('tape')
const testCommon = require('./common')

var db
let db

test('setUp common for approximate size', testCommon.setUp)

Expand Down Expand Up @@ -66,7 +66,7 @@ test('test 1-arg + callback approximateSize() throws', function (t) {

test('test custom _serialize*', function (t) {
t.plan(4)
var db = testCommon.factory()
const db = testCommon.factory()
db._serializeKey = function (data) { return data }
db.approximateSize = function (start, end, callback) {
t.deepEqual(start, { foo: 'bar' })
Expand All @@ -82,7 +82,7 @@ test('test custom _serialize*', function (t) {
})

test('test approximateSize()', function (t) {
var data = Array.apply(null, Array(10000)).map(function () {
const data = Array.apply(null, Array(10000)).map(function () {
return 'aaaaaaaaaa'
}).join('')

Expand Down
10 changes: 5 additions & 5 deletions test/cleanup-hanging-iterators-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const repeats = 200

makeTest('test ended iterator', function (db, t, done) {
// First test normal and proper usage: calling it.end() before db.close()
var it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false })
const it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false })

it.next(function (err, key, value) {
t.ifError(err, 'no error from next()')
Expand All @@ -19,7 +19,7 @@ makeTest('test ended iterator', function (db, t, done) {
makeTest('test likely-ended iterator', function (db, t, done) {
// Test improper usage: not calling it.end() before db.close(). Cleanup of the
// database will crash Node if not handled properly.
var it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false })
const it = db.iterator({ keyAsBuffer: false, valueAsBuffer: false })

it.next(function (err, key, value) {
t.ifError(err, 'no error from next()')
Expand All @@ -33,7 +33,7 @@ makeTest('test non-ended iterator', function (db, t, done) {
// Same as the test above but with a highWaterMark of 0 so that we don't
// preemptively fetch all records, to ensure that the iterator is still
// active when we (attempt to) close the database.
var it = db.iterator({
const it = db.iterator({
highWaterMark: 0,
keyAsBuffer: false,
valueAsBuffer: false
Expand Down Expand Up @@ -84,10 +84,10 @@ global.gc && makeTest('test multiple non-ended iterators with forced gc', functi

makeTest('test ending iterators', function (db, t, done) {
// At least one end() should be in progress when we try to close the db.
var it1 = db.iterator().next(function () {
const it1 = db.iterator().next(function () {
it1.end(function () {})
})
var it2 = db.iterator().next(function () {
const it2 = db.iterator().next(function () {
it2.end(function () {})
done()
})
Expand Down
12 changes: 6 additions & 6 deletions test/compact-range-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ test('setUp db', function (t) {
})

test('test compactRange() frees disk space after key deletion', function (t) {
var key1 = '000000'
var key2 = '000001'
var val1 = Buffer.allocUnsafe(64).fill(1)
var val2 = Buffer.allocUnsafe(64).fill(1)
const key1 = '000000'
const key2 = '000001'
const val1 = Buffer.allocUnsafe(64).fill(1)
const val2 = Buffer.allocUnsafe(64).fill(1)

db.batch().put(key1, val1).put(key2, val2).write(function (err) {
t.ifError(err, 'no batch put error')
Expand Down Expand Up @@ -46,8 +46,8 @@ test('test compactRange() frees disk space after key deletion', function (t) {
test('test compactRange() serializes start and end', function (t) {
t.plan(3)

var clone = Object.create(db)
var count = 0
const clone = Object.create(db)
let count = 0

clone._serializeKey = function (key) {
t.is(key, count++)
Expand Down
8 changes: 4 additions & 4 deletions test/compression-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const verify = function (location, compression, t) {

// close, open, close again.. 'compaction' is also performed on open()s
const cycle = function (db, compression, t, callback) {
var location = db.location
const location = db.location
db.close(function (err) {
t.error(err)
db = leveldown(location)
Expand All @@ -45,7 +45,7 @@ test('compression', function (t) {
t.test('set up', testCommon.setUp)

t.test('test data is compressed by default (db.put())', function (t) {
var db = testCommon.factory()
const db = testCommon.factory()
db.open(function (err) {
t.error(err)
each(
Expand All @@ -59,7 +59,7 @@ test('compression', function (t) {
})

t.test('test data is not compressed with compression=false on open() (db.put())', function (t) {
var db = testCommon.factory()
const db = testCommon.factory()
db.open({ compression: false }, function (err) {
t.error(err)
each(
Expand All @@ -73,7 +73,7 @@ test('compression', function (t) {
})

t.test('test data is compressed by default (db.batch())', function (t) {
var db = testCommon.factory()
const db = testCommon.factory()
db.open(function (err) {
t.error(err)
db.batch(
Expand Down
14 changes: 7 additions & 7 deletions test/destroy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ test('test callback-less, 1-arg, destroy() throws', function (t) {
test('test destroy non-existent directory', function (t) {
t.plan(4)

var location = tempy.directory()
var parent = path.dirname(location)
const location = tempy.directory()
const parent = path.dirname(location)

// For symmetry with the opposite test below.
t.ok(fs.existsSync(parent), 'parent exists before')
Expand All @@ -51,8 +51,8 @@ test('test destroy non-existent directory', function (t) {
test('test destroy non-existent parent directory', function (t) {
t.plan(3)

var location = '/1/2/3/4'
var parent = path.dirname(location)
const location = '/1/2/3/4'
const parent = path.dirname(location)

t.notOk(fs.existsSync(parent), 'parent does not exist before')

Expand All @@ -64,7 +64,7 @@ test('test destroy non-existent parent directory', function (t) {
})

test('test destroy non leveldb directory', function (t) {
var tree = {
const tree = {
foo: 'FOO',
bar: { one: 'ONE', two: 'TWO', three: 'THREE' }
}
Expand All @@ -89,7 +89,7 @@ test('test destroy non leveldb directory', function (t) {
})

makeTest('test destroy() cleans and removes leveldb-only dir', function (db, t, done) {
var location = db.location
const location = db.location
db.close(function (err) {
t.ifError(err, 'no error from close()')

Expand All @@ -103,7 +103,7 @@ makeTest('test destroy() cleans and removes leveldb-only dir', function (db, t,
})

makeTest('test destroy() cleans and removes only leveldb parts of a dir', function (db, t, done) {
var location = db.location
const location = db.location
fs.writeFileSync(path.join(location, 'foo'), 'FOO')

db.close(function (err) {
Expand Down
4 changes: 2 additions & 2 deletions test/getproperty-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('test invalid getProperty() returns empty string', function (t) {
})

test('test invalid getProperty("rocksdb.num-files-at-levelN") returns numbers', function (t) {
for (var i = 0; i < 7; i++) {
for (let i = 0; i < 7; i++) {
t.equal(db.getProperty('rocksdb.num-files-at-level' + i),
'0', '"rocksdb.num-files-at-levelN" === "0"')
}
Expand All @@ -46,7 +46,7 @@ test('test invalid getProperty("rocksdb.stats")', function (t) {
})

test('test invalid getProperty("rocksdb.sstables")', function (t) {
var expected = [0, 1, 2, 3, 4, 5, 6].map(function (l) {
const expected = [0, 1, 2, 3, 4, 5, 6].map(function (l) {
return '--- level ' + l + ' --- version# 2 ---'
}).join('\n') + '\n'
t.equal(db.getProperty('rocksdb.sstables'), expected, 'rocksdb.sstables')
Expand Down
14 changes: 7 additions & 7 deletions test/iterator-recursion-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const path = require('path')
let db

const sourceData = (function () {
var d = []
var i = 0
var k
const d = []
let i = 0
let k
for (; i < 100000; i++) {
k = (i < 10 ? '0' : '') + i
d.push({
Expand Down Expand Up @@ -37,8 +37,8 @@ test.skip('try to create an iterator with a blown stack', function (t) {
// Reducing the stack size down from the default 984 for the child node
// process makes it easier to trigger the bug condition. But making it too low
// causes the child process to die for other reasons.
var opts = { execArgv: ['--stack-size=128'] }
var child = fork(path.join(__dirname, 'stack-blower.js'), ['run'], opts)
const opts = { execArgv: ['--stack-size=128'] }
const child = fork(path.join(__dirname, 'stack-blower.js'), ['run'], opts)

child.on('message', function (m) {
t.ok(true, m)
Expand All @@ -64,10 +64,10 @@ test('setUp db', function (t) {
})

test('iterate over a large iterator with a large watermark', function (t) {
var iterator = db.iterator({
const iterator = db.iterator({
highWaterMark: 10000000
})
var read = function () {
const read = function () {
iterator.next(function () {
if (!arguments.length) {
t.end()
Expand Down
18 changes: 9 additions & 9 deletions test/iterator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const make = require('./make')
// This test isn't included in abstract-leveldown because
// the empty-check is currently performed by leveldown.
make('iterator#seek throws if target is empty', function (db, t, done) {
var targets = ['', Buffer.alloc(0), []]
var pending = targets.length
const targets = ['', Buffer.alloc(0), []]
let pending = targets.length

targets.forEach(function (target) {
var ite = db.iterator()
var error
const ite = db.iterator()
let error

try {
ite.seek(target)
Expand All @@ -27,7 +27,7 @@ make('iterator#seek throws if target is empty', function (db, t, done) {
})

make('iterator optimized for seek', function (db, t, done) {
var batch = db.batch()
const batch = db.batch()
batch.put('a', 1)
batch.put('b', 1)
batch.put('c', 1)
Expand All @@ -36,7 +36,7 @@ make('iterator optimized for seek', function (db, t, done) {
batch.put('f', 1)
batch.put('g', 1)
batch.write(function (err) {
var ite = db.iterator()
const ite = db.iterator()
t.ifError(err, 'no error from batch()')
ite.next(function (err, key, value) {
t.ifError(err, 'no error from next()')
Expand Down Expand Up @@ -65,9 +65,9 @@ make('iterator optimized for seek', function (db, t, done) {
})

make('close db with open iterator', function (db, t, done) {
var ite = db.iterator()
var cnt = 0
var hadError = false
const ite = db.iterator()
let cnt = 0
let hadError = false

ite.next(function loop (err, key, value) {
if (cnt++ === 0) {
Expand Down
30 changes: 15 additions & 15 deletions test/leak-tester-batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ function print () {

const run = CHAINED
? function () {
const batch = db.batch()
const batch = db.batch()

for (let i = 0; i < 100; i++) {
let key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000))
if (BUFFERS) key = Buffer.from(key)
let value = crypto.randomBytes(1024)
if (!BUFFERS) value = value.toString('hex')
batch.put(key, value)
}
for (let i = 0; i < 100; i++) {
let key = 'long key to test memory usage ' + String(Math.floor(Math.random() * 10000000))
if (BUFFERS) key = Buffer.from(key)
let value = crypto.randomBytes(1024)
if (!BUFFERS) value = value.toString('hex')
batch.put(key, value)
}

batch.write(function (err) {
assert(!err)
process.nextTick(run)
})
batch.write(function (err) {
assert(!err)
process.nextTick(run)
})

writeCount++
print()
}
writeCount++
print()
}
: function () {
const batch = []

Expand Down
2 changes: 1 addition & 1 deletion test/leak-tester-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (!global.gc) {
}

function run () {
var it = db.iterator()
const it = db.iterator()

it.next(function (err) {
if (err) throw err
Expand Down
4 changes: 2 additions & 2 deletions test/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const testCommon = require('./common')

function makeTest (name, testFn) {
test(name, function (t) {
var db = testCommon.factory()
var done = function (err, close) {
const db = testCommon.factory()
const done = function (err, close) {
t.ifError(err, 'no error from done()')

if (close === false) {
Expand Down
Loading

0 comments on commit 7cb4c10

Please sign in to comment.