Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions

View File

@@ -1,18 +1,15 @@
import TileSource from '../../../../src/ol/source/Tile.js';
import TileLayer from '../../../../src/ol/layer/Tile.js';
import Map from '../../../../src/ol/Map.js';
import TileImage from '../../../../src/ol/source/TileImage.js';
import TileLayer from '../../../../src/ol/layer/Tile.js';
import TileSource from '../../../../src/ol/source/Tile.js';
import UrlTile from '../../../../src/ol/source/UrlTile.js';
import View from '../../../../src/ol/View.js';
import XYZ from '../../../../src/ol/source/XYZ.js';
import {createXYZ} from '../../../../src/ol/tilegrid.js';
import View from '../../../../src/ol/View.js';
import Map from '../../../../src/ol/Map.js';
describe('ol.source.XYZ', function() {
describe('constructor', function() {
it('can be constructed without options', function() {
describe('ol.source.XYZ', function () {
describe('constructor', function () {
it('can be constructed without options', function () {
const source = new XYZ();
expect(source).to.be.an(XYZ);
expect(source).to.be.an(TileImage);
@@ -20,190 +17,188 @@ describe('ol.source.XYZ', function() {
expect(source).to.be.an(TileSource);
});
it('can be constructed with a custom zDirection', function() {
it('can be constructed with a custom zDirection', function () {
const source = new XYZ({
zDirection: -1
zDirection: -1,
});
expect(source.zDirection).to.be(-1);
});
it('can be constructed with a custom tile grid', function() {
it('can be constructed with a custom tile grid', function () {
const tileGrid = createXYZ();
const tileSource = new XYZ({
tileGrid: tileGrid
tileGrid: tileGrid,
});
expect(tileSource.getTileGrid()).to.be(tileGrid);
});
it('can be constructed with a custom tile size', function() {
it('can be constructed with a custom tile size', function () {
const tileSource = new XYZ({
tileSize: 512
tileSize: 512,
});
expect(tileSource.getTileGrid().getTileSize(0)).to.be(512);
});
it('can be constructed with a custom min zoom', function() {
it('can be constructed with a custom min zoom', function () {
const tileSource = new XYZ({
minZoom: 2
minZoom: 2,
});
expect(tileSource.getTileGrid().getMinZoom()).to.be(2);
});
});
describe('tileUrlFunction', function() {
describe('tileUrlFunction', function () {
let xyzTileSource, tileGrid;
beforeEach(function() {
beforeEach(function () {
xyzTileSource = new XYZ({
maxZoom: 6,
url: '{z}/{x}/{y}'
url: '{z}/{x}/{y}',
});
tileGrid = xyzTileSource.getTileGrid();
});
it('returns the expected URL', function() {
it('returns the expected URL', function () {
const coordinate = [829330.2064098881, 5933916.615134273];
let tileUrl;
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
tileGrid.getTileCoordForCoordAndZ(coordinate, 0)
);
expect(tileUrl).to.eql('0/0/0');
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
tileGrid.getTileCoordForCoordAndZ(coordinate, 1)
);
expect(tileUrl).to.eql('1/1/0');
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
tileGrid.getTileCoordForCoordAndZ(coordinate, 2)
);
expect(tileUrl).to.eql('2/2/1');
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
tileGrid.getTileCoordForCoordAndZ(coordinate, 3)
);
expect(tileUrl).to.eql('3/4/2');
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
tileGrid.getTileCoordForCoordAndZ(coordinate, 4)
);
expect(tileUrl).to.eql('4/8/5');
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
tileGrid.getTileCoordForCoordAndZ(coordinate, 5)
);
expect(tileUrl).to.eql('5/16/11');
tileUrl = xyzTileSource.tileUrlFunction(
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
tileGrid.getTileCoordForCoordAndZ(coordinate, 6)
);
expect(tileUrl).to.eql('6/33/22');
});
describe('wrap x', function() {
it('returns the expected URL', function() {
describe('wrap x', function () {
it('returns the expected URL', function () {
const projection = xyzTileSource.getProjection();
let tileUrl = xyzTileSource.tileUrlFunction(
xyzTileSource.getTileCoordForTileUrlFunction([6, -31, 22], projection));
xyzTileSource.getTileCoordForTileUrlFunction([6, -31, 22], projection)
);
expect(tileUrl).to.eql('6/33/22');
tileUrl = xyzTileSource.tileUrlFunction(
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection));
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection)
);
expect(tileUrl).to.eql('6/33/22');
tileUrl = xyzTileSource.tileUrlFunction(
xyzTileSource.getTileCoordForTileUrlFunction([6, 97, 22], projection));
xyzTileSource.getTileCoordForTileUrlFunction([6, 97, 22], projection)
);
expect(tileUrl).to.eql('6/33/22');
});
});
describe('crop y', function() {
it('returns the expected URL', function() {
describe('crop y', function () {
it('returns the expected URL', function () {
const projection = xyzTileSource.getProjection();
let tileUrl = xyzTileSource.tileUrlFunction(
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, -1], projection));
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, -1], projection)
);
expect(tileUrl).to.be(undefined);
tileUrl = xyzTileSource.tileUrlFunction(
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection));
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 22], projection)
);
expect(tileUrl).to.eql('6/33/22');
tileUrl = xyzTileSource.tileUrlFunction(
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 64], projection));
xyzTileSource.getTileCoordForTileUrlFunction([6, 33, 64], projection)
);
expect(tileUrl).to.be(undefined);
});
});
});
describe('#getUrls', function() {
describe('#getUrls', function () {
let sourceOptions;
let source;
const url = 'http://geo.nls.uk/maps/towns/glasgow1857/{z}/{x}/{-y}.png';
beforeEach(function() {
beforeEach(function () {
sourceOptions = {
projection: 'EPSG:4326'
projection: 'EPSG:4326',
};
});
describe('using a "url" option', function() {
beforeEach(function() {
describe('using a "url" option', function () {
beforeEach(function () {
sourceOptions.url = url;
source = new XYZ(sourceOptions);
});
it('returns the XYZ URL', function() {
it('returns the XYZ URL', function () {
const urls = source.getUrls();
expect(urls).to.be.eql([url]);
});
});
describe('using a "urls" option', function() {
beforeEach(function() {
describe('using a "urls" option', function () {
beforeEach(function () {
sourceOptions.urls = ['some_xyz_url1', 'some_xyz_url2'];
source = new XYZ(sourceOptions);
});
it('returns the XYZ URLs', function() {
it('returns the XYZ URLs', function () {
const urls = source.getUrls();
expect(urls).to.be.eql(['some_xyz_url1', 'some_xyz_url2']);
});
});
describe('using a "tileUrlFunction"', function() {
beforeEach(function() {
sourceOptions.tileUrlFunction = function() {
describe('using a "tileUrlFunction"', function () {
beforeEach(function () {
sourceOptions.tileUrlFunction = function () {
return 'some_xyz_url';
};
source = new XYZ(sourceOptions);
});
it('returns null', function() {
it('returns null', function () {
const urls = source.getUrls();
expect(urls).to.be(null);
});
});
});
describe('clear and refresh', function() {
describe('clear and refresh', function () {
let map, source;
let callCount = 0;
beforeEach(function(done) {
beforeEach(function (done) {
source = new XYZ({
url: 'spec/ol/data/osm-{z}-{x}-{y}.png',
tileLoadFunction: function(image, src) {
tileLoadFunction: function (image, src) {
++callCount;
image.getImage().src = src;
}
},
});
const target = document.createElement('div');
target.style.width = '100px';
@@ -213,43 +208,41 @@ describe('ol.source.XYZ', function() {
target: target,
layers: [
new TileLayer({
source: source
})
source: source,
}),
],
view: new View({
center: [0, 0],
zoom: 0
})
zoom: 0,
}),
});
map.once('rendercomplete', function() {
map.once('rendercomplete', function () {
callCount = 0;
done();
});
});
afterEach(function() {
afterEach(function () {
document.body.removeChild(map.getTargetElement());
map.setTarget(null);
});
it('#refresh() reloads from server', function(done) {
map.once('rendercomplete', function() {
it('#refresh() reloads from server', function (done) {
map.once('rendercomplete', function () {
expect(callCount).to.be(1);
done();
});
source.refresh();
});
it('#clear() clears the tile cache', function(done) {
map.once('rendercomplete', function() {
it('#clear() clears the tile cache', function (done) {
map.once('rendercomplete', function () {
done(new Error('should not re-render'));
});
source.clear();
setTimeout(function() {
setTimeout(function () {
done();
}, 1000);
});
});
});