Use blocked scoped variables

In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
Tim Schaub
2018-01-11 23:32:36 -07:00
parent 0bf2b04dee
commit ad62739a6e
684 changed files with 18120 additions and 18184 deletions
+24 -24
View File
@@ -1,9 +1,9 @@
import LinkedList from '../../../../src/ol/structs/LinkedList.js';
describe('ol.structs.LinkedList', function() {
var ll;
var item = {};
var item2 = {};
let ll;
const item = {};
const item2 = {};
beforeEach(function() {
ll = new LinkedList();
});
@@ -40,7 +40,7 @@ describe('ol.structs.LinkedList', function() {
});
describe('#removeItem', function() {
var item3 = {};
const item3 = {};
beforeEach(function() {
ll.insertItem(item);
ll.insertItem(item2);
@@ -82,13 +82,13 @@ describe('ol.structs.LinkedList', function() {
it('sets the cursor to the first item and returns its data', function() {
ll.insertItem(item);
ll.insertItem(item2);
var i = ll.firstItem();
const i = ll.firstItem();
expect(i).to.be(item);
expect(ll.head_.data).to.be(item);
});
it('returns undefined on empty list', function() {
var i = ll.firstItem();
const i = ll.firstItem();
expect(i).to.be(undefined);
});
});
@@ -98,13 +98,13 @@ describe('ol.structs.LinkedList', function() {
ll.insertItem(item);
ll.insertItem(item2);
ll.firstItem();
var i = ll.lastItem();
const i = ll.lastItem();
expect(i).to.be(item2);
expect(ll.head_.data).to.be(item2);
});
it('returns undefined on empty list', function() {
var i = ll.lastItem();
const i = ll.lastItem();
expect(i).to.be(undefined);
});
});
@@ -114,13 +114,13 @@ describe('ol.structs.LinkedList', function() {
ll.insertItem(item);
ll.insertItem(item2);
ll.firstItem();
var i = ll.nextItem();
const i = ll.nextItem();
expect(i).to.be(item2);
expect(ll.head_.data).to.be(item2);
});
it('returns undefined on empty list', function() {
var i = ll.nextItem();
const i = ll.nextItem();
expect(i).to.be(undefined);
});
});
@@ -129,13 +129,13 @@ describe('ol.structs.LinkedList', function() {
it('sets the cursor to the previous item and returns its data', function() {
ll.insertItem(item);
ll.insertItem(item2);
var i = ll.prevItem();
const i = ll.prevItem();
expect(i).to.be(item);
expect(ll.head_.data).to.be(item);
});
it('returns undefined on empty list', function() {
var i = ll.prevItem();
const i = ll.prevItem();
expect(i).to.be(undefined);
});
});
@@ -145,13 +145,13 @@ describe('ol.structs.LinkedList', function() {
ll.insertItem(item);
ll.insertItem(item2);
ll.firstItem();
var i = ll.getNextItem();
const i = ll.getNextItem();
expect(i).to.be(item2);
expect(ll.head_.data).to.be(item);
});
it('returns undefined on empty list', function() {
var i = ll.getNextItem();
const i = ll.getNextItem();
expect(i).to.be(undefined);
});
});
@@ -160,31 +160,31 @@ describe('ol.structs.LinkedList', function() {
it('returns the data of the previous item without stepping the cursor', function() {
ll.insertItem(item);
ll.insertItem(item2);
var i = ll.getPrevItem();
const i = ll.getPrevItem();
expect(i).to.be(item);
expect(ll.head_.data).to.be(item2);
});
it('returns undefined on empty list', function() {
var i = ll.getPrevItem();
const i = ll.getPrevItem();
expect(i).to.be(undefined);
});
});
describe('#getCurrItem', function() {
it('returns the data of the current item', function() {
var item3 = {};
const item3 = {};
ll.insertItem(item);
ll.insertItem(item2);
ll.insertItem(item3);
ll.prevItem();
var i = ll.getCurrItem();
const i = ll.getCurrItem();
expect(i).to.be(item2);
expect(ll.head_.data).to.be(item2);
});
it('returns undefined on empty list', function() {
var i = ll.getCurrItem();
const i = ll.getCurrItem();
expect(i).to.be(undefined);
});
});
@@ -193,13 +193,13 @@ describe('ol.structs.LinkedList', function() {
it('returns the length of the list', function() {
ll.insertItem(item);
ll.insertItem(item2);
var l = ll.getLength();
const l = ll.getLength();
expect(l).to.be(2);
});
});
describe('#concat', function() {
var ll2, item3;
let ll2, item3;
beforeEach(function() {
item3 = {};
ll2 = new LinkedList();
@@ -209,9 +209,9 @@ describe('ol.structs.LinkedList', function() {
});
it('concatenates a second list with the current one', function() {
var item4 = {};
var item5 = {};
var item6 = {};
const item4 = {};
const item5 = {};
const item6 = {};
ll.insertItem(item4);
ll.insertItem(item5);
ll.insertItem(item6);
+12 -12
View File
@@ -3,7 +3,7 @@ import LRUCache from '../../../../src/ol/structs/LRUCache.js';
describe('ol.structs.LRUCache', function() {
var lruCache;
let lruCache;
function fillLRUCache(lruCache) {
lruCache.set('a', 0);
@@ -164,7 +164,7 @@ describe('ol.structs.LRUCache', function() {
describe('#peekFirstKey()', function() {
it('returns the newest key in the cache', function() {
var cache = new LRUCache();
const cache = new LRUCache();
cache.set('oldest', 'oldest');
cache.set('oldish', 'oldish');
cache.set('newish', 'newish');
@@ -173,13 +173,13 @@ describe('ol.structs.LRUCache', function() {
});
it('works if the cache has one item', function() {
var cache = new LRUCache();
const cache = new LRUCache();
cache.set('key', 'value');
expect(cache.peekFirstKey()).to.eql('key');
});
it('throws if the cache is empty', function() {
var cache = new LRUCache();
const cache = new LRUCache();
expect(function() {
cache.peekFirstKey();
}).to.throwException();
@@ -212,7 +212,7 @@ describe('ol.structs.LRUCache', function() {
describe('#remove()', function() {
it('removes an item from the cache', function() {
var cache = new LRUCache();
const cache = new LRUCache();
cache.set('oldest', 'oldest');
cache.set('oldish', 'oldish');
cache.set('newish', 'newish');
@@ -224,7 +224,7 @@ describe('ol.structs.LRUCache', function() {
});
it('works when removing the oldest item', function() {
var cache = new LRUCache();
const cache = new LRUCache();
cache.set('oldest', 'oldest');
cache.set('oldish', 'oldish');
cache.set('newish', 'newish');
@@ -237,7 +237,7 @@ describe('ol.structs.LRUCache', function() {
});
it('works when removing the newest item', function() {
var cache = new LRUCache();
const cache = new LRUCache();
cache.set('oldest', 'oldest');
cache.set('oldish', 'oldish');
cache.set('newish', 'newish');
@@ -250,20 +250,20 @@ describe('ol.structs.LRUCache', function() {
});
it('returns the removed item', function() {
var cache = new LRUCache();
var item = {};
const cache = new LRUCache();
const item = {};
cache.set('key', item);
var returned = cache.remove('key');
const returned = cache.remove('key');
expect(returned).to.be(item);
});
it('throws if the key does not exist', function() {
var cache = new LRUCache();
const cache = new LRUCache();
cache.set('foo', 'foo');
cache.set('bar', 'bar');
var call = function() {
const call = function() {
cache.remove('bam');
};
expect(call).to.throwException();
+19 -19
View File
@@ -3,13 +3,13 @@ import PriorityQueue from '../../../../src/ol/structs/PriorityQueue.js';
describe('ol.structs.PriorityQueue', function() {
var identity = function(a) {
const identity = function(a) {
return a;
};
describe('when empty', function() {
var pq;
let pq;
beforeEach(function() {
pq = new PriorityQueue(identity, identity);
});
@@ -19,14 +19,14 @@ describe('ol.structs.PriorityQueue', function() {
});
it('enqueue adds an element', function() {
var added = pq.enqueue(0);
const added = pq.enqueue(0);
expect(added).to.be(true);
expect(pq.elements_).to.eql([0]);
expect(pq.priorities_).to.eql([0]);
});
it('do not enqueue element with DROP priority', function() {
var added = pq.enqueue(Infinity);
const added = pq.enqueue(Infinity);
expect(added).to.be(false);
expect(pq.elements_).to.eql([]);
expect(pq.priorities_).to.eql([]);
@@ -36,11 +36,11 @@ describe('ol.structs.PriorityQueue', function() {
describe('when populated', function() {
var elements, pq;
let elements, pq;
beforeEach(function() {
elements = [];
pq = new PriorityQueue(identity, identity);
var element, i;
let element, i;
for (i = 0; i < 32; ++i) {
element = Math.random();
pq.enqueue(element);
@@ -50,7 +50,7 @@ describe('ol.structs.PriorityQueue', function() {
it('dequeues elements in the correct order', function() {
elements.sort();
var i;
let i;
for (i = 0; i < elements.length; ++i) {
expect(pq.dequeue()).to.be(elements[i]);
}
@@ -61,21 +61,21 @@ describe('ol.structs.PriorityQueue', function() {
describe('with an impure priority function', function() {
var pq, target;
let pq, target;
beforeEach(function() {
target = 0.5;
pq = new PriorityQueue(function(element) {
return Math.abs(element - target);
}, identity);
var i;
let i;
for (i = 0; i < 32; ++i) {
pq.enqueue(Math.random());
}
});
it('dequeue elements in the correct order', function() {
var lastDelta = 0;
var delta;
let lastDelta = 0;
let delta;
while (!pq.isEmpty()) {
delta = Math.abs(pq.dequeue() - target);
expect(lastDelta <= delta).to.be(true);
@@ -84,10 +84,10 @@ describe('ol.structs.PriorityQueue', function() {
});
it('allows reprioritization', function() {
var target = 0.5;
const target = 0.5;
pq.reprioritize();
var lastDelta = 0;
var delta;
let lastDelta = 0;
let delta;
while (!pq.isEmpty()) {
delta = Math.abs(pq.dequeue() - target);
expect(lastDelta <= delta).to.be(true);
@@ -96,8 +96,8 @@ describe('ol.structs.PriorityQueue', function() {
});
it('allows dropping during reprioritization', function() {
var target = 0.5;
var i = 0;
const target = 0.5;
let i = 0;
pq.priorityFunction_ = function(element) {
if (i++ % 2 === 0) {
return Math.abs(element - target);
@@ -107,8 +107,8 @@ describe('ol.structs.PriorityQueue', function() {
};
pq.reprioritize();
expect(pq.getCount()).to.be(16);
var lastDelta = 0;
var delta;
let lastDelta = 0;
let delta;
while (!pq.isEmpty()) {
delta = Math.abs(pq.dequeue() - target);
expect(lastDelta <= delta).to.be(true);
@@ -120,7 +120,7 @@ describe('ol.structs.PriorityQueue', function() {
describe('tracks elements in the queue', function() {
var pq;
let pq;
beforeEach(function() {
pq = new PriorityQueue(identity, identity);
pq.enqueue('a');
+42 -42
View File
@@ -3,7 +3,7 @@ import RBush from '../../../../src/ol/structs/RBush.js';
describe('ol.structs.RBush', function() {
var rBush;
let rBush;
beforeEach(function() {
rBush = new RBush();
});
@@ -30,7 +30,7 @@ describe('ol.structs.RBush', function() {
describe('with a single object', function() {
var obj;
let obj;
beforeEach(function() {
obj = {};
rBush.insert([0, 0, 1, 1], obj);
@@ -56,7 +56,7 @@ describe('ol.structs.RBush', function() {
describe('with a few objects', function() {
var objs;
let objs;
beforeEach(function() {
objs = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
rBush.insert([0, 0, 1, 1], objs[0]);
@@ -75,7 +75,7 @@ describe('ol.structs.RBush', function() {
describe('#forEach', function() {
it('called for all the objects', function() {
var i = 0;
let i = 0;
rBush.forEach(function() {
++i;
});
@@ -83,8 +83,8 @@ describe('ol.structs.RBush', function() {
});
it('stops when the function returns true', function() {
var i = 0;
var result = rBush.forEach(function() {
let i = 0;
const result = rBush.forEach(function() {
return ++i >= 4;
});
expect(i).to.be(4);
@@ -96,7 +96,7 @@ describe('ol.structs.RBush', function() {
describe('#getInExtent', function() {
it('returns the expected objects', function() {
var result;
let result;
result = rBush.getInExtent([2, 2, 3, 3]);
expect(result).to.contain(objs[1]);
expect(result).to.contain(objs[2]);
@@ -126,7 +126,7 @@ describe('ol.structs.RBush', function() {
describe('#remove', function() {
it('can remove each object', function() {
var i, ii;
let i, ii;
for (i = 0, ii = objs.length; i < ii; ++i) {
expect(rBush.getAll()).to.contain(objs[i]);
rBush.remove(objs[i]);
@@ -140,11 +140,11 @@ describe('ol.structs.RBush', function() {
describe('with 100 objects', function() {
var extents, objs;
let extents, objs;
beforeEach(function() {
extents = [];
objs = [];
var i;
let i;
for (i = 0; i < 100; ++i) {
extents[i] = [i - 0.1, i - 0.1, i + 0.1, i + 0.1];
objs[i] = {id: i};
@@ -155,7 +155,7 @@ describe('ol.structs.RBush', function() {
describe('#getInExtent', function() {
it('returns the expected objects', function() {
var i, ii;
let i, ii;
for (i = 0, ii = objs.length; i < ii; ++i) {
expect(rBush.getInExtent(extents[i])).to.eql([objs[i]]);
}
@@ -174,7 +174,7 @@ describe('ol.structs.RBush', function() {
describe('#remove', function() {
it('can remove each object in turn', function() {
var i, ii;
let i, ii;
for (i = 0, ii = objs.length; i < ii; ++i) {
expect(rBush.getInExtent(extents[i])).to.eql([objs[i]]);
rBush.remove(objs[i]);
@@ -185,16 +185,16 @@ describe('ol.structs.RBush', function() {
});
it('can remove objects in random order', function() {
var i, ii, j;
let i, ii, j;
// http://en.wikipedia.org/wiki/Random_permutation
var indexes = [];
const indexes = [];
for (i = 0, ii = objs.length; i < ii; ++i) {
j = Math.floor(Math.random() * (i + 1));
indexes[i] = indexes[j];
indexes[j] = i;
}
for (i = 0, ii = objs.length; i < ii; ++i) {
var index = indexes[i];
const index = indexes[i];
expect(rBush.getInExtent(extents[index])).to.eql([objs[index]]);
rBush.remove(objs[index]);
expect(rBush.getInExtent(extents[index])).to.be.empty();
@@ -210,11 +210,11 @@ describe('ol.structs.RBush', function() {
describe('with 1000 objects', function() {
beforeEach(function() {
var i;
let i;
for (i = 0; i < 1000; ++i) {
var min = [Math.random() * 10000, Math.random() * 10000];
var max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
var extent = [min[0], min[1], max[0], max[1]];
const min = [Math.random() * 10000, Math.random() * 10000];
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
const extent = [min[0], min[1], max[0], max[1]];
rBush.insert(extent, {id: i});
}
});
@@ -234,27 +234,27 @@ describe('ol.structs.RBush', function() {
});
it('can perform 1000 in-extent searches', function() {
var n = 0;
var i;
let n = 0;
let i;
for (i = 0; i < 1000; ++i) {
var min = [Math.random() * 10000, Math.random() * 10000];
var max = [
const min = [Math.random() * 10000, Math.random() * 10000];
const max = [
min[0] + Math.random() * 500,
min[1] + Math.random() * 500
];
var extent = [min[0], min[1], max[0], max[1]];
const extent = [min[0], min[1], max[0], max[1]];
n += rBush.getInExtent(extent).length;
}
expect(n).not.to.be(0);
});
it('can perform 1000 out-of-extent searches', function() {
var n = 0;
var i;
let n = 0;
let i;
for (i = 0; i < 1000; ++i) {
var min = [-(Math.random() * 10000 + 501), -(Math.random() * 10000 + 501)];
var max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
var extent = [min[0], min[1], max[0], max[1]];
const min = [-(Math.random() * 10000 + 501), -(Math.random() * 10000 + 501)];
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
const extent = [min[0], min[1], max[0], max[1]];
n += rBush.getInExtent(extent).length;
}
expect(n).to.be(0);
@@ -265,11 +265,11 @@ describe('ol.structs.RBush', function() {
describe('#insert', function() {
it('can insert another 1000 objects', function() {
var i;
let i;
for (i = 1000; i < 2000; ++i) {
var min = [Math.random() * 10000, Math.random() * 10000];
var max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
var extent = [min[0], min[1], max[0], max[1]];
const min = [Math.random() * 10000, Math.random() * 10000];
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
const extent = [min[0], min[1], max[0], max[1]];
rBush.insert(extent, {id: i});
}
expect(rBush.getInExtent([0, 0, 10600, 10600]).length).to.be(2000);
@@ -288,8 +288,8 @@ describe('ol.structs.RBush', function() {
describe('#remove', function() {
it('can remove all 1000 objects', function() {
var objs = rBush.getAll();
var i, value;
const objs = rBush.getAll();
let i, value;
for (i = objs.length - 1; i >= 0; --i) {
value = objs[i];
rBush.remove(value);
@@ -304,7 +304,7 @@ describe('ol.structs.RBush', function() {
describe('#getExtent', function() {
it('gets the extent', function() {
var obj = {};
const obj = {};
rBush.insert([0, 0, 1, 1], obj);
expect(rBush.getExtent()).to.eql([0, 0, 1, 1]);
});
@@ -314,9 +314,9 @@ describe('ol.structs.RBush', function() {
describe('#concat', function() {
it('concatenates two RBush objects', function() {
var obj1 = {};
var obj2 = {};
var rBush2 = new RBush();
const obj1 = {};
const obj2 = {};
const rBush2 = new RBush();
rBush.insert([0, 0, 1, 1], obj1);
rBush2.insert([0, 0, 2, 2], obj2);
rBush.concat(rBush2);
@@ -325,9 +325,9 @@ describe('ol.structs.RBush', function() {
});
it('preserves the concatenated object\'s references', function() {
var obj1 = {};
var obj2 = {};
var rBush2 = new RBush();
const obj1 = {};
const obj2 = {};
const rBush2 = new RBush();
rBush.insert([0, 0, 1, 1], obj1);
rBush2.insert([0, 0, 2, 2], obj2);
rBush.concat(rBush2);