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

View File

@@ -13,8 +13,8 @@ import VectorSource from '../../../../src/ol/source/Vector.js';
describe('ol.source.Vector', function() {
var pointFeature;
var infiniteExtent;
let pointFeature;
let infiniteExtent;
beforeEach(function() {
pointFeature = new Feature(new Point([0, 0]));
infiniteExtent = [-Infinity, -Infinity, Infinity, Infinity];
@@ -22,7 +22,7 @@ describe('ol.source.Vector', function() {
describe('when empty', function() {
var vectorSource;
let vectorSource;
beforeEach(function() {
vectorSource = new VectorSource();
});
@@ -30,7 +30,7 @@ describe('ol.source.Vector', function() {
describe('#forEachFeatureInExtent', function() {
it('does not call the callback', function() {
var f = sinon.spy();
const f = sinon.spy();
vectorSource.forEachFeatureInExtent(infiniteExtent, f);
expect(f).not.to.be.called();
});
@@ -40,7 +40,7 @@ describe('ol.source.Vector', function() {
describe('#getFeaturesInExtent', function() {
it('returns an empty array', function() {
var features = vectorSource.getFeaturesInExtent(infiniteExtent);
const features = vectorSource.getFeaturesInExtent(infiniteExtent);
expect(features).to.be.an(Array);
expect(features).to.be.empty();
});
@@ -59,24 +59,24 @@ describe('ol.source.Vector', function() {
it('can add a single point feature', function() {
vectorSource.addFeature(pointFeature);
var features = vectorSource.getFeaturesInExtent(infiniteExtent);
const features = vectorSource.getFeaturesInExtent(infiniteExtent);
expect(features).to.be.an(Array);
expect(features).to.have.length(1);
expect(features[0]).to.be(pointFeature);
});
it('fires a change event', function() {
var listener = sinon.spy();
const listener = sinon.spy();
_ol_events_.listen(vectorSource, 'change', listener);
vectorSource.addFeature(pointFeature);
expect(listener).to.be.called();
});
it('adds same id features only once', function() {
var source = new VectorSource();
var feature1 = new Feature();
const source = new VectorSource();
const feature1 = new Feature();
feature1.setId('1');
var feature2 = new Feature();
const feature2 = new Feature();
feature2.setId('1');
source.addFeature(feature1);
source.addFeature(feature2);
@@ -89,8 +89,8 @@ describe('ol.source.Vector', function() {
describe('when populated with 3 features', function() {
var features = [];
var vectorSource;
const features = [];
let vectorSource;
beforeEach(function() {
features.push(new Feature(new LineString([[0, 0], [10, 10]])));
features.push(new Feature(new Point([0, 10])));
@@ -103,12 +103,12 @@ describe('ol.source.Vector', function() {
describe('#getClosestFeatureToCoordinate', function() {
it('returns the expected feature', function() {
var feature = vectorSource.getClosestFeatureToCoordinate([1, 9]);
const feature = vectorSource.getClosestFeatureToCoordinate([1, 9]);
expect(feature).to.be(features[1]);
});
it('returns the expected feature when a filter is used', function() {
var feature = vectorSource.getClosestFeatureToCoordinate([1, 9], function(feature) {
const feature = vectorSource.getClosestFeatureToCoordinate([1, 9], function(feature) {
return feature.getGeometry().getType() == 'LineString';
});
expect(feature).to.be(features[0]);
@@ -120,11 +120,11 @@ describe('ol.source.Vector', function() {
describe('when populated with 10 random points and a null', function() {
var features;
var vectorSource;
let features;
let vectorSource;
beforeEach(function() {
features = [];
var i;
let i;
for (i = 0; i < 10; ++i) {
features[i] =
new Feature(new Point([Math.random(), Math.random()]));
@@ -138,11 +138,11 @@ describe('ol.source.Vector', function() {
describe('#clear', function() {
it('removes all features using fast path', function() {
var changeSpy = sinon.spy();
const changeSpy = sinon.spy();
_ol_events_.listen(vectorSource, 'change', changeSpy);
var removeFeatureSpy = sinon.spy();
const removeFeatureSpy = sinon.spy();
_ol_events_.listen(vectorSource, 'removefeature', removeFeatureSpy);
var clearSourceSpy = sinon.spy();
const clearSourceSpy = sinon.spy();
_ol_events_.listen(vectorSource, 'clear', clearSourceSpy);
vectorSource.clear(true);
expect(vectorSource.getFeatures()).to.eql([]);
@@ -156,11 +156,11 @@ describe('ol.source.Vector', function() {
});
it('removes all features using slow path', function() {
var changeSpy = sinon.spy();
const changeSpy = sinon.spy();
_ol_events_.listen(vectorSource, 'change', changeSpy);
var removeFeatureSpy = sinon.spy();
const removeFeatureSpy = sinon.spy();
_ol_events_.listen(vectorSource, 'removefeature', removeFeatureSpy);
var clearSourceSpy = sinon.spy();
const clearSourceSpy = sinon.spy();
_ol_events_.listen(vectorSource, 'clear', clearSourceSpy);
vectorSource.clear();
expect(vectorSource.getFeatures()).to.eql([]);
@@ -178,17 +178,17 @@ describe('ol.source.Vector', function() {
describe('#forEachFeatureInExtent', function() {
it('is called the expected number of times', function() {
var f = sinon.spy();
const f = sinon.spy();
vectorSource.forEachFeatureInExtent(infiniteExtent, f);
expect(f.callCount).to.be(10);
});
it('allows breaking out', function() {
var count = 0;
var result = vectorSource.forEachFeatureInExtent(infiniteExtent,
function(f) {
return ++count == 5;
});
let count = 0;
const result = vectorSource.forEachFeatureInExtent(infiniteExtent,
function(f) {
return ++count == 5;
});
expect(result).to.be(true);
expect(count).to.be(5);
});
@@ -199,7 +199,7 @@ describe('ol.source.Vector', function() {
it('returns the expected number of features', function() {
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).
to.have.length(10);
to.have.length(10);
});
});
@@ -215,16 +215,16 @@ describe('ol.source.Vector', function() {
describe('#removeFeature', function() {
it('works as expected', function() {
var i;
let i;
for (i = features.length - 1; i >= 0; --i) {
vectorSource.removeFeature(features[i]);
expect(vectorSource.getFeaturesInExtent(infiniteExtent)).
have.length(i);
have.length(i);
}
});
it('fires a change event', function() {
var listener = sinon.spy();
const listener = sinon.spy();
_ol_events_.listen(vectorSource, 'change', listener);
vectorSource.removeFeature(features[0]);
expect(listener).to.be.called();
@@ -236,13 +236,13 @@ describe('ol.source.Vector', function() {
it('keeps the R-Tree index up to date', function() {
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(10);
to.have.length(10);
features[0].getGeometry().setCoordinates([100, 100]);
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(9);
to.have.length(9);
features[0].getGeometry().setCoordinates([0.5, 0.5]);
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(10);
to.have.length(10);
});
});
@@ -251,10 +251,10 @@ describe('ol.source.Vector', function() {
it('keeps the R-Tree index up to date', function() {
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(10);
to.have.length(10);
features[0].setGeometry(new Point([100, 100]));
expect(vectorSource.getFeaturesInExtent([0, 0, 1, 1])).
to.have.length(9);
to.have.length(9);
});
});
@@ -263,63 +263,63 @@ describe('ol.source.Vector', function() {
describe('tracking changes to features', function() {
var vectorSource;
let vectorSource;
beforeEach(function() {
vectorSource = new VectorSource();
});
it('keeps its index up-to-date', function() {
var feature = new Feature(new Point([1, 1]));
const feature = new Feature(new Point([1, 1]));
vectorSource.addFeature(feature);
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
to.eql([feature]);
to.eql([feature]);
feature.getGeometry().setCoordinates([3, 3]);
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
to.be.empty();
to.be.empty();
expect(vectorSource.getFeaturesInExtent([2, 2, 4, 4])).
to.eql([feature]);
to.eql([feature]);
});
it('handles features with null geometries', function() {
var feature = new Feature(null);
const feature = new Feature(null);
vectorSource.addFeature(feature);
expect(vectorSource.getFeatures()).to.eql([feature]);
});
it('handles features with geometries changing from null', function() {
var feature = new Feature(null);
const feature = new Feature(null);
vectorSource.addFeature(feature);
expect(vectorSource.getFeatures()).to.eql([feature]);
feature.setGeometry(new Point([1, 1]));
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
to.eql([feature]);
to.eql([feature]);
expect(vectorSource.getFeatures()).to.eql([feature]);
});
it('handles features with geometries changing to null', function() {
var feature = new Feature(new Point([1, 1]));
const feature = new Feature(new Point([1, 1]));
vectorSource.addFeature(feature);
expect(vectorSource.getFeatures()).to.eql([feature]);
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).
to.eql([feature]);
to.eql([feature]);
feature.setGeometry(null);
expect(vectorSource.getFeaturesInExtent([0, 0, 2, 2])).to.be.empty();
expect(vectorSource.getFeatures()).to.eql([feature]);
});
it('fires a change event when setting a feature\'s property', function() {
var feature = new Feature(new Point([1, 1]));
const feature = new Feature(new Point([1, 1]));
vectorSource.addFeature(feature);
var listener = sinon.spy();
const listener = sinon.spy();
_ol_events_.listen(vectorSource, 'change', listener);
feature.set('foo', 'bar');
expect(listener).to.be.called();
});
it('fires a changefeature event when updating a feature', function() {
var feature = new Feature(new Point([1, 1]));
const feature = new Feature(new Point([1, 1]));
vectorSource.addFeature(feature);
var listener = sinon.spy(function(event) {
const listener = sinon.spy(function(event) {
expect(event.feature).to.be(feature);
});
vectorSource.on('changefeature', listener);
@@ -330,20 +330,20 @@ describe('ol.source.Vector', function() {
});
describe('#getFeatureById()', function() {
var source;
let source;
beforeEach(function() {
source = new VectorSource();
});
it('returns a feature by id', function() {
var feature = new Feature();
const feature = new Feature();
feature.setId('foo');
source.addFeature(feature);
expect(source.getFeatureById('foo')).to.be(feature);
});
it('returns a feature by id (set after add)', function() {
var feature = new Feature();
const feature = new Feature();
source.addFeature(feature);
expect(source.getFeatureById('foo')).to.be(null);
feature.setId('foo');
@@ -351,14 +351,14 @@ describe('ol.source.Vector', function() {
});
it('returns null when no feature is found', function() {
var feature = new Feature();
const feature = new Feature();
feature.setId('foo');
source.addFeature(feature);
expect(source.getFeatureById('bar')).to.be(null);
});
it('returns null after removing feature', function() {
var feature = new Feature();
const feature = new Feature();
feature.setId('foo');
source.addFeature(feature);
expect(source.getFeatureById('foo')).to.be(feature);
@@ -367,7 +367,7 @@ describe('ol.source.Vector', function() {
});
it('returns null after unsetting id', function() {
var feature = new Feature();
const feature = new Feature();
feature.setId('foo');
source.addFeature(feature);
expect(source.getFeatureById('foo')).to.be(feature);
@@ -376,7 +376,7 @@ describe('ol.source.Vector', function() {
});
it('returns null after clear', function() {
var feature = new Feature();
const feature = new Feature();
feature.setId('foo');
source.addFeature(feature);
expect(source.getFeatureById('foo')).to.be(feature);
@@ -392,13 +392,13 @@ describe('ol.source.Vector', function() {
it('returns correct feature after add/remove/add', function() {
expect(source.getFeatureById('foo')).to.be(null);
var first = new Feature();
const first = new Feature();
first.setId('foo');
source.addFeature(first);
expect(source.getFeatureById('foo')).to.be(first);
source.removeFeature(first);
expect(source.getFeatureById('foo')).to.be(null);
var second = new Feature();
const second = new Feature();
second.setId('foo');
source.addFeature(second);
expect(source.getFeatureById('foo')).to.be(second);
@@ -406,7 +406,7 @@ describe('ol.source.Vector', function() {
it('returns correct feature after add/change', function() {
expect(source.getFeatureById('foo')).to.be(null);
var feature = new Feature();
const feature = new Feature();
feature.setId('foo');
source.addFeature(feature);
expect(source.getFeatureById('foo')).to.be(feature);
@@ -423,22 +423,22 @@ describe('ol.source.Vector', function() {
it('requests the view extent plus render buffer', function(done) {
var center = [-97.6114, 38.8403];
var source = new VectorSource({
const center = [-97.6114, 38.8403];
const source = new VectorSource({
strategy: _ol_loadingstrategy_.bbox,
loader: function(extent) {
setTimeout(function() {
var lonLatExtent = transformExtent(extent, 'EPSG:3857', 'EPSG:4326');
const lonLatExtent = transformExtent(extent, 'EPSG:3857', 'EPSG:4326');
expect(lonLatExtent[0]).to.roughlyEqual(-99.261474609, 1e-9);
expect(lonLatExtent[2]).to.roughlyEqual(-95.965576171, 1e-9);
done();
}, 0);
}
});
var div = document.createElement('div');
const div = document.createElement('div');
div.style.width = div.style.height = '100px';
document.body.appendChild(div);
var map = new Map({
const map = new Map({
target: div,
layers: [
new VectorLayer({
@@ -460,40 +460,40 @@ describe('ol.source.Vector', function() {
describe('with no loader and the "all" strategy', function() {
it('stores the infinity extent in the Rtree', function() {
var source = new VectorSource();
const source = new VectorSource();
source.loadFeatures([-10000, -10000, 10000, 10000], 1,
getProjection('EPSG:3857'));
var loadedExtents = source.loadedExtentsRtree_.getAll();
getProjection('EPSG:3857'));
const loadedExtents = source.loadedExtentsRtree_.getAll();
expect(loadedExtents).to.have.length(1);
expect(loadedExtents[0].extent).to.eql(
[-Infinity, -Infinity, Infinity, Infinity]);
[-Infinity, -Infinity, Infinity, Infinity]);
});
});
describe('with setLoader', function() {
it('it will change the loader function', function() {
var count1 = 0;
var loader1 = function(bbox, resolution, projection) {
let count1 = 0;
const loader1 = function(bbox, resolution, projection) {
count1++;
};
var count2 = 0;
var loader2 = function(bbox, resolution, projection) {
let count2 = 0;
const loader2 = function(bbox, resolution, projection) {
count2++;
};
var source = new VectorSource({loader: loader1});
const source = new VectorSource({loader: loader1});
source.loadFeatures([-10000, -10000, 10000, 10000], 1,
getProjection('EPSG:3857'));
getProjection('EPSG:3857'));
source.setLoader(loader2);
source.clear();
source.loadFeatures([-10000, -10000, 10000, 10000], 1,
getProjection('EPSG:3857'));
getProjection('EPSG:3857'));
expect(count1).to.eql(1);
expect(count2).to.eql(1);
});
it('removes extents with #removeLoadedExtent()', function(done) {
var source = new VectorSource();
const source = new VectorSource();
source.setLoader(function(bbox, resolution, projection) {
setTimeout(function() {
expect(source.loadedExtentsRtree_.getAll()).to.have.length(1);
@@ -509,16 +509,16 @@ describe('ol.source.Vector', function() {
});
describe('the feature id index', function() {
var source;
let source;
beforeEach(function() {
source = new VectorSource();
});
it('ignores features with the same id', function() {
var feature = new Feature();
const feature = new Feature();
feature.setId('foo');
source.addFeature(feature);
var dupe = new Feature();
const dupe = new Feature();
dupe.setId('foo');
source.addFeature(dupe);
expect(source.getFeatures()).to.have.length(1);
@@ -526,10 +526,10 @@ describe('ol.source.Vector', function() {
});
it('allows changing feature and set the same id', function() {
var foo = new Feature();
const foo = new Feature();
foo.setId('foo');
source.addFeature(foo);
var bar = new Feature();
const bar = new Feature();
bar.setId('bar');
source.addFeature(bar);
bar.setId('foo');
@@ -539,13 +539,13 @@ describe('ol.source.Vector', function() {
});
describe('the undefined feature id index', function() {
var source;
let source;
beforeEach(function() {
source = new VectorSource();
});
it('disallows adding the same feature twice', function() {
var feature = new Feature();
const feature = new Feature();
source.addFeature(feature);
expect(function() {
source.addFeature(feature);
@@ -554,7 +554,7 @@ describe('ol.source.Vector', function() {
});
describe('with useSpatialIndex set to false', function() {
var source;
let source;
beforeEach(function() {
source = new VectorSource({useSpatialIndex: false});
});
@@ -565,7 +565,7 @@ describe('ol.source.Vector', function() {
it('#forEachFeatureInExtent loops through all features', function() {
source.addFeatures([new Feature(), new Feature()]);
var spy = sinon.spy();
const spy = sinon.spy();
source.forEachFeatureInExtent([0, 0, 0, 0], spy);
expect(spy.callCount).to.be(2);
});
@@ -573,7 +573,7 @@ describe('ol.source.Vector', function() {
});
describe('with a collection of features', function() {
var collection, source;
let collection, source;
beforeEach(function() {
source = new VectorSource({
useSpatialIndex: false
@@ -586,7 +586,7 @@ describe('ol.source.Vector', function() {
});
it('adding/removing features keeps the collection in sync', function() {
var feature = new Feature();
const feature = new Feature();
source.addFeature(feature);
expect(collection.getLength()).to.be(1);
source.removeFeature(feature);
@@ -594,7 +594,7 @@ describe('ol.source.Vector', function() {
});
it('#clear() features keeps the collection in sync', function() {
var feature = new Feature();
const feature = new Feature();
source.addFeatures([feature]);
expect(collection.getLength()).to.be(1);
source.clear();
@@ -606,7 +606,7 @@ describe('ol.source.Vector', function() {
});
it('keeps the source\'s features in sync with the collection', function() {
var feature = new Feature();
const feature = new Feature();
collection.push(feature);
expect(source.getFeatures().length).to.be(1);
collection.remove(feature);
@@ -620,7 +620,7 @@ describe('ol.source.Vector', function() {
});
describe('with a collection of features plus spatial index', function() {
var collection, source;
let collection, source;
beforeEach(function() {
collection = new Collection();
source = new VectorSource({
@@ -633,7 +633,7 @@ describe('ol.source.Vector', function() {
});
it('adding/removing features keeps the collection in sync', function() {
var feature = new Feature();
const feature = new Feature();
source.addFeature(feature);
expect(collection.getLength()).to.be(1);
source.removeFeature(feature);
@@ -641,7 +641,7 @@ describe('ol.source.Vector', function() {
});
it('#clear() features keeps the collection in sync', function() {
var feature = new Feature();
const feature = new Feature();
source.addFeatures([feature]);
expect(collection.getLength()).to.be(1);
source.clear();
@@ -653,7 +653,7 @@ describe('ol.source.Vector', function() {
});
it('keeps the source\'s features in sync with the collection', function() {
var feature = new Feature();
const feature = new Feature();
collection.push(feature);
expect(source.getFeatures().length).to.be(1);
collection.remove(feature);