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
+6 -6
View File
@@ -8,9 +8,9 @@ import _ol_tilegrid_ from '../../../../src/ol/tilegrid.js';
describe('ol.control.Attribution', function() {
var map;
let map;
beforeEach(function() {
var target = document.createElement('div');
const target = document.createElement('div');
target.style.width = target.style.height = '100px';
document.body.appendChild(target);
map = new Map({
@@ -48,11 +48,11 @@ describe('ol.control.Attribution', function() {
})
});
map.getLayers().forEach(function(layer) {
var source = layer.getSource();
const source = layer.getSource();
source.getTile = function() {
var tile = new Tile([0, 0, -1], 2 /* LOADED */);
const tile = new Tile([0, 0, -1], 2 /* LOADED */);
tile.getImage = function() {
var image = new Image();
const image = new Image();
image.width = 256;
image.height = 256;
return image;
@@ -69,7 +69,7 @@ describe('ol.control.Attribution', function() {
it('does not add duplicate attributions', function() {
map.renderSync();
var attribution = map.getTarget().querySelectorAll('.ol-attribution li');
const attribution = map.getTarget().querySelectorAll('.ol-attribution li');
expect(attribution.length).to.be(2);
});
+7 -7
View File
@@ -2,13 +2,13 @@ import Map from '../../../../src/ol/Map.js';
import Control from '../../../../src/ol/control/Control.js';
describe('ol.control.Control', function() {
var map, control;
let map, control;
beforeEach(function() {
map = new Map({
target: document.createElement('div')
});
var element = document.createElement('DIV');
const element = document.createElement('DIV');
control = new Control({element: element});
control.setMap(map);
});
@@ -30,25 +30,25 @@ describe('ol.control.Control', function() {
describe('ol.control.Control\'s target', function() {
describe('target as string or element', function() {
it('transforms target from string to element', function() {
var target = document.createElement('div');
const target = document.createElement('div');
target.id = 'mycontrol';
document.body.appendChild(target);
var ctrl = new Control({target: 'mycontrol'});
const ctrl = new Control({target: 'mycontrol'});
expect(ctrl.target_.id).to.equal('mycontrol');
ctrl.dispose();
target.parentNode.removeChild(target);
});
it('accepts element for target', function() {
var target = document.createElement('div');
const target = document.createElement('div');
target.id = 'mycontrol';
document.body.appendChild(target);
var ctrl = new Control({target: target});
const ctrl = new Control({target: target});
expect(ctrl.target_.id).to.equal('mycontrol');
ctrl.dispose();
target.parentNode.removeChild(target);
});
it('ignores non-existing target id', function() {
var ctrl = new Control({target: 'doesnotexist'});
const ctrl = new Control({target: 'doesnotexist'});
expect(ctrl.target_).to.equal(null);
ctrl.dispose();
});
+1 -1
View File
@@ -5,7 +5,7 @@ describe('ol.control.FullScreen', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var instance = new FullScreen();
const instance = new FullScreen();
expect(instance).to.be.an(FullScreen);
});
+3 -3
View File
@@ -5,14 +5,14 @@ describe('ol.control.MousePosition', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var instance = new MousePosition();
const instance = new MousePosition();
expect(instance).to.be.an(MousePosition);
expect(instance.element.className).to.be('ol-mouse-position');
});
it('creates the element with the provided class name', function() {
var className = 'foobar';
var instance = new MousePosition({
const className = 'foobar';
const instance = new MousePosition({
className: className
});
expect(instance.element.className).to.be(className);
+12 -12
View File
@@ -4,7 +4,7 @@ import Control from '../../../../src/ol/control/Control.js';
import OverviewMap from '../../../../src/ol/control/OverviewMap.js';
describe('ol.control.OverviewMap', function() {
var map, target;
let map, target;
beforeEach(function() {
target = document.createElement('div');
@@ -23,7 +23,7 @@ describe('ol.control.OverviewMap', function() {
describe('constructor', function() {
it('creates an overview map with the default options', function() {
var control = new OverviewMap();
const control = new OverviewMap();
expect(control).to.be.a(OverviewMap);
expect(control).to.be.a(Control);
});
@@ -32,16 +32,16 @@ describe('ol.control.OverviewMap', function() {
describe('setMap()', function() {
it('keeps ovmap view rotation in sync with map view rotation', function() {
var view = new View({
const view = new View({
center: [0, 0],
zoom: 0,
rotation: 0
});
map.setView(view);
var control = new OverviewMap();
const control = new OverviewMap();
map.addControl(control);
var ovView = control.ovmap_.getView();
const ovView = control.ovmap_.getView();
expect(ovView.getRotation()).to.be(0);
view.setRotation(Math.PI / 4);
@@ -49,12 +49,12 @@ describe('ol.control.OverviewMap', function() {
});
it('maintains rotation in sync if view added later', function() {
var control = new OverviewMap();
const control = new OverviewMap();
map.addControl(control);
var ovView = control.ovmap_.getView();
const ovView = control.ovmap_.getView();
expect(ovView.getRotation()).to.be(0);
var view = new View({
const view = new View({
center: [0, 0],
zoom: 0,
rotation: 0
@@ -65,10 +65,10 @@ describe('ol.control.OverviewMap', function() {
});
it('stops listening to old maps', function() {
var control = new OverviewMap();
var ovView = control.ovmap_.getView();
const control = new OverviewMap();
const ovView = control.ovmap_.getView();
var view = new View({
const view = new View({
center: [0, 0],
zoom: 0,
rotation: 0
@@ -86,7 +86,7 @@ describe('ol.control.OverviewMap', function() {
});
it('set target to null', function() {
var control = new OverviewMap();
const control = new OverviewMap();
map.addControl(control);
+1 -1
View File
@@ -5,7 +5,7 @@ describe('ol.control.Rotate', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var instance = new Rotate();
const instance = new Rotate();
expect(instance).to.be.an(Rotate);
});
+51 -51
View File
@@ -5,9 +5,9 @@ import {fromLonLat} from '../../../../src/ol/proj.js';
import Projection from '../../../../src/ol/proj/Projection.js';
describe('ol.control.ScaleLine', function() {
var map;
let map;
beforeEach(function() {
var target = document.createElement('div');
const target = document.createElement('div');
document.body.appendChild(target);
map = new Map({
target: target
@@ -20,7 +20,7 @@ describe('ol.control.ScaleLine', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
expect(ctrl).to.be.an(ScaleLine);
});
});
@@ -29,23 +29,23 @@ describe('ol.control.ScaleLine', function() {
describe('className', function() {
it('defaults to "ol-scale-line"', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
ctrl.setMap(map);
var element = document.querySelector('.ol-scale-line', map.getTarget());
const element = document.querySelector('.ol-scale-line', map.getTarget());
expect(element).to.not.be(null);
expect(element).to.be.a(HTMLDivElement);
});
it('can be configured', function() {
var ctrl = new ScaleLine({
const ctrl = new ScaleLine({
className: 'humpty-dumpty'
});
ctrl.setMap(map);
// check that the default was not chosen
var element1 = document.querySelector('.ol-scale-line', map.getTarget());
const element1 = document.querySelector('.ol-scale-line', map.getTarget());
expect(element1).to.be(null);
// check if the configured classname was chosen
var element2 = document.querySelector('.humpty-dumpty', map.getTarget());
const element2 = document.querySelector('.humpty-dumpty', map.getTarget());
expect(element2).to.not.be(null);
expect(element2).to.be.a(HTMLDivElement);
});
@@ -53,11 +53,11 @@ describe('ol.control.ScaleLine', function() {
describe('minWidth', function() {
it('defaults to 64', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
expect(ctrl.minWidth_).to.be(64);
});
it('can be configured', function() {
var ctrl = new ScaleLine({
const ctrl = new ScaleLine({
minWidth: 4711
});
expect(ctrl.minWidth_).to.be(4711);
@@ -66,14 +66,14 @@ describe('ol.control.ScaleLine', function() {
describe('render', function() {
it('defaults to `ol.control.ScaleLine.render`', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
expect(ctrl.render).to.be(ScaleLine.render);
});
it('can be configured', function() {
var myRender = function() {
const myRender = function() {
};
var ctrl = new ScaleLine({
const ctrl = new ScaleLine({
render: myRender
});
expect(ctrl.render).to.be(myRender);
@@ -84,8 +84,8 @@ describe('ol.control.ScaleLine', function() {
describe('synchronisation with map view', function() {
it('calls `render` as soon as the map is rendered', function(done) {
var renderSpy = sinon.spy();
var ctrl = new ScaleLine({
const renderSpy = sinon.spy();
const ctrl = new ScaleLine({
render: renderSpy
});
expect(renderSpy.called).to.be(false);
@@ -103,8 +103,8 @@ describe('ol.control.ScaleLine', function() {
});
});
it('calls `render` as often as the map is rendered', function() {
var renderSpy = sinon.spy();
var ctrl = new ScaleLine({
const renderSpy = sinon.spy();
const ctrl = new ScaleLine({
render: renderSpy
});
ctrl.setMap(map);
@@ -120,8 +120,8 @@ describe('ol.control.ScaleLine', function() {
expect(renderSpy.callCount).to.be(3);
});
it('calls `render` as when the view changes', function(done) {
var renderSpy = sinon.spy();
var ctrl = new ScaleLine({
const renderSpy = sinon.spy();
const ctrl = new ScaleLine({
render: renderSpy
});
ctrl.setMap(map);
@@ -140,7 +140,7 @@ describe('ol.control.ScaleLine', function() {
describe('static method `render`', function() {
it('updates the rendered text', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
expect(ctrl.element.innerText).to.be('');
ctrl.setMap(map);
map.setView(new View({
@@ -154,17 +154,17 @@ describe('ol.control.ScaleLine', function() {
describe('#getUnits', function() {
it('returns "metric" by default', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
expect(ctrl.getUnits()).to.be('metric');
});
it('returns what is configured via `units` property', function() {
var ctrl = new ScaleLine({
const ctrl = new ScaleLine({
units: 'nautical'
});
expect(ctrl.getUnits()).to.be('nautical');
});
it('returns what is configured `setUnits` method', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
ctrl.setUnits('nautical');
expect(ctrl.getUnits()).to.be('nautical');
});
@@ -172,7 +172,7 @@ describe('ol.control.ScaleLine', function() {
describe('#setUnits', function() {
it('triggers rerendering', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
map.setView(new View({
center: [0, 0],
zoom: 0
@@ -189,12 +189,12 @@ describe('ol.control.ScaleLine', function() {
});
describe('different units result in different contents', function() {
var ctrl;
var metricHtml;
var nauticalHtml;
var degreesHtml;
var imperialHtml;
var usHtml;
let ctrl;
let metricHtml;
let nauticalHtml;
let degreesHtml;
let imperialHtml;
let usHtml;
beforeEach(function(done) {
ctrl = new ScaleLine();
ctrl.setMap(map);
@@ -246,7 +246,7 @@ describe('ol.control.ScaleLine', function() {
describe('projections affect the scaleline', function() {
it('is rendered differently for different projections', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: fromLonLat([7, 52]),
@@ -254,19 +254,19 @@ describe('ol.control.ScaleLine', function() {
projection: 'EPSG:3857'
}));
map.renderSync();
var innerHtml3857 = ctrl.element_.innerHTML;
const innerHtml3857 = ctrl.element_.innerHTML;
map.setView(new View({
center: [7, 52],
zoom: 2,
projection: 'EPSG:4326'
}));
map.renderSync();
var innerHtml4326 = ctrl.element_.innerHTML;
const innerHtml4326 = ctrl.element_.innerHTML;
expect(innerHtml4326).to.not.be(innerHtml3857);
});
it('Projection\'s metersPerUnit affect scale for non-degree units', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: [0, 0],
@@ -303,7 +303,7 @@ describe('ol.control.ScaleLine', function() {
describe('latitude may affect scale line in EPSG:4326', function() {
it('is rendered differently at different latitudes for metric', function() {
var ctrl = new ScaleLine();
const ctrl = new ScaleLine();
ctrl.setMap(map);
map.setView(new View({
center: fromLonLat([7, 0]),
@@ -311,15 +311,15 @@ describe('ol.control.ScaleLine', function() {
projection: 'EPSG:4326'
}));
map.renderSync();
var innerHtml0 = ctrl.element_.innerHTML;
const innerHtml0 = ctrl.element_.innerHTML;
map.getView().setCenter([7, 52]);
map.renderSync();
var innerHtml52 = ctrl.element_.innerHTML;
const innerHtml52 = ctrl.element_.innerHTML;
expect(innerHtml0).to.not.be(innerHtml52);
});
it('is rendered the same at different latitudes for degrees', function() {
var ctrl = new ScaleLine({
const ctrl = new ScaleLine({
units: 'degrees'
});
ctrl.setMap(map);
@@ -329,22 +329,22 @@ describe('ol.control.ScaleLine', function() {
projection: 'EPSG:4326'
}));
map.renderSync();
var innerHtml0 = ctrl.element_.innerHTML;
const innerHtml0 = ctrl.element_.innerHTML;
map.getView().setCenter([7, 52]);
map.renderSync();
var innerHtml52 = ctrl.element_.innerHTML;
const innerHtml52 = ctrl.element_.innerHTML;
expect(innerHtml0).to.be(innerHtml52);
});
});
describe('zoom affects the scaleline', function() {
var currentZoom;
var ctrl;
var renderedHtmls;
var mapView;
let currentZoom;
let ctrl;
let renderedHtmls;
let mapView;
var getMetricUnit = function(zoom) {
const getMetricUnit = function(zoom) {
if (zoom > 30) {
return 'μm';
} else if (zoom > 20) {
@@ -384,11 +384,11 @@ describe('ol.control.ScaleLine', function() {
while (--currentZoom >= 0) {
mapView.setZoom(currentZoom);
map.renderSync();
var currentHtml = ctrl.element_.innerHTML;
const currentHtml = ctrl.element_.innerHTML;
expect(currentHtml in renderedHtmls).to.be(false);
renderedHtmls[currentHtml] = true;
var unit = ctrl.innerElement_.textContent.match(/\d+ (.+)/)[1];
const unit = ctrl.innerElement_.textContent.match(/\d+ (.+)/)[1];
expect(unit).to.eql(getMetricUnit(currentZoom));
}
});
@@ -399,7 +399,7 @@ describe('ol.control.ScaleLine', function() {
while (--currentZoom >= 0) {
mapView.setZoom(currentZoom);
map.renderSync();
var currentHtml = ctrl.element_.innerHTML;
const currentHtml = ctrl.element_.innerHTML;
expect(currentHtml in renderedHtmls).to.be(false);
renderedHtmls[currentHtml] = true;
}
@@ -411,7 +411,7 @@ describe('ol.control.ScaleLine', function() {
while (--currentZoom >= 0) {
mapView.setZoom(currentZoom);
map.renderSync();
var currentHtml = ctrl.element_.innerHTML;
const currentHtml = ctrl.element_.innerHTML;
expect(currentHtml in renderedHtmls).to.be(false);
renderedHtmls[currentHtml] = true;
}
@@ -423,7 +423,7 @@ describe('ol.control.ScaleLine', function() {
while (--currentZoom >= 0) {
mapView.setZoom(currentZoom);
map.renderSync();
var currentHtml = ctrl.element_.innerHTML;
const currentHtml = ctrl.element_.innerHTML;
expect(currentHtml in renderedHtmls).to.be(false);
renderedHtmls[currentHtml] = true;
}
@@ -435,7 +435,7 @@ describe('ol.control.ScaleLine', function() {
while (--currentZoom >= 0) {
mapView.setZoom(currentZoom);
map.renderSync();
var currentHtml = ctrl.element_.innerHTML;
const currentHtml = ctrl.element_.innerHTML;
expect(currentHtml in renderedHtmls).to.be(false);
renderedHtmls[currentHtml] = true;
}
+1 -1
View File
@@ -5,7 +5,7 @@ describe('ol.control.Zoom', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var instance = new Zoom();
const instance = new Zoom();
expect(instance).to.be.an(Zoom);
});
+17 -17
View File
@@ -4,7 +4,7 @@ import ZoomSlider from '../../../../src/ol/control/ZoomSlider.js';
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
describe('ol.control.ZoomSlider', function() {
var map, target, zoomslider;
let map, target, zoomslider;
beforeEach(function() {
target = document.createElement('div');
@@ -27,20 +27,20 @@ describe('ol.control.ZoomSlider', function() {
describe('DOM creation', function() {
it('creates the expected DOM elements', function() {
var zoomSliderContainers = target.querySelectorAll('.ol-zoomslider');
const zoomSliderContainers = target.querySelectorAll('.ol-zoomslider');
expect(zoomSliderContainers.length).to.be(1);
var zoomSliderContainer = zoomSliderContainers[0];
const zoomSliderContainer = zoomSliderContainers[0];
expect(zoomSliderContainer instanceof HTMLDivElement).to.be(true);
var hasUnselectableCls = zoomSliderContainer.classList.contains('ol-unselectable');
let hasUnselectableCls = zoomSliderContainer.classList.contains('ol-unselectable');
expect(hasUnselectableCls).to.be(true);
var zoomSliderThumbs = zoomSliderContainer.querySelectorAll('.ol-zoomslider-thumb');
const zoomSliderThumbs = zoomSliderContainer.querySelectorAll('.ol-zoomslider-thumb');
expect(zoomSliderThumbs.length).to.be(1);
var zoomSliderThumb = zoomSliderThumbs[0];
const zoomSliderThumb = zoomSliderThumbs[0];
expect(zoomSliderThumb instanceof HTMLButtonElement).to.be(true);
hasUnselectableCls = zoomSliderThumb.classList.contains('ol-unselectable');
@@ -59,26 +59,26 @@ describe('ol.control.ZoomSlider', function() {
describe('#direction_', function() {
it('is horizontal for wide containers', function() {
var control = new ZoomSlider({});
const control = new ZoomSlider({});
control.element.style.width = '1000px';
control.element.style.height = '10px';
control.setMap(map);
control.initSlider_();
var horizontal = 1;
const horizontal = 1;
expect(control.direction_).to.be(horizontal);
control.dispose();
});
it('is vertical for tall containers', function() {
var control = new ZoomSlider({});
const control = new ZoomSlider({});
control.element.style.width = '10px';
control.element.style.height = '1000px';
control.setMap(map);
var vertical = 0;
const vertical = 0;
expect(control.direction_).to.be(vertical);
control.dispose();
@@ -86,7 +86,7 @@ describe('ol.control.ZoomSlider', function() {
});
describe('Pointer event handling', function() {
var map;
let map;
beforeEach(function() {
map = new Map({
@@ -102,7 +102,7 @@ describe('ol.control.ZoomSlider', function() {
});
it('[horizontal] handles a drag sequence', function() {
var control = new ZoomSlider();
const control = new ZoomSlider();
map.addControl(control);
map.getView().setZoom(0);
control.element.style.width = '500px';
@@ -110,8 +110,8 @@ describe('ol.control.ZoomSlider', function() {
control.element.firstChild.style.width = '100px';
control.element.firstChild.style.height = '10px';
map.renderSync();
var dragger = control.dragger_;
var event = new PointerEvent('pointerdown', {
const dragger = control.dragger_;
const event = new PointerEvent('pointerdown', {
target: control.element.firstElementChild
});
event.clientX = control.widthLimit_;
@@ -134,7 +134,7 @@ describe('ol.control.ZoomSlider', function() {
expect(control.dragging_).to.be(false);
});
it('[vertical] handles a drag sequence', function() {
var control = new ZoomSlider();
const control = new ZoomSlider();
control.element.style.width = '10px';
control.element.style.height = '100px';
control.element.firstChild.style.width = '10px';
@@ -142,8 +142,8 @@ describe('ol.control.ZoomSlider', function() {
map.addControl(control);
map.getView().setZoom(8);
map.renderSync();
var dragger = control.dragger_;
var event = new PointerEvent('pointerdown', {
const dragger = control.dragger_;
const event = new PointerEvent('pointerdown', {
target: control.element.firstElementChild
});
event.clientX = 0;
+1 -1
View File
@@ -5,7 +5,7 @@ describe('ol.control.ZoomToExtent', function() {
describe('constructor', function() {
it('can be constructed without arguments', function() {
var instance = new ZoomToExtent();
const instance = new ZoomToExtent();
expect(instance).to.be.an(ZoomToExtent);
});