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,12 +1,11 @@
import Tile from '../../../../src/ol/Tile.js';
import TileRange from '../../../../src/ol/TileRange.js';
import {get as getProjection} from '../../../../src/ol/proj.js';
import Projection from '../../../../src/ol/proj/Projection.js';
import Source from '../../../../src/ol/source/Source.js';
import Tile from '../../../../src/ol/Tile.js';
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
import TileRange from '../../../../src/ol/TileRange.js';
import TileSource from '../../../../src/ol/source/Tile.js';
import {getKeyZXY} from '../../../../src/ol/tilecoord.js';
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
import {get as getProjection} from '../../../../src/ol/proj.js';
/**
* Tile source for tests that uses a EPSG:4326 based grid with 4 resolutions and
@@ -20,12 +19,12 @@ class MockTile extends TileSource {
const tileGrid = new TileGrid({
resolutions: [360 / 256, 180 / 256, 90 / 256, 45 / 256],
origin: [-180, -180],
tileSize: 256
tileSize: 256,
});
super({
projection: getProjection('EPSG:4326'),
tileGrid: tileGrid
tileGrid: tileGrid,
});
for (const key in tileStates) {
@@ -34,8 +33,7 @@ class MockTile extends TileSource {
}
}
MockTile.prototype.getTile = function(z, x, y) {
MockTile.prototype.getTile = function (z, x, y) {
const key = getKeyZXY(z, x, y);
if (this.tileCache.containsKey(key)) {
return /** @type {!ol.Tile} */ (this.tileCache.get(key));
@@ -46,38 +44,47 @@ MockTile.prototype.getTile = function(z, x, y) {
}
};
describe('ol.source.Tile', function() {
describe('constructor', function() {
it('returns a tile source', function() {
describe('ol.source.Tile', function () {
describe('constructor', function () {
it('returns a tile source', function () {
const source = new TileSource({
projection: getProjection('EPSG:4326')
projection: getProjection('EPSG:4326'),
});
expect(source).to.be.a(Source);
expect(source).to.be.a(TileSource);
});
it('sets a screen dependent cache size', function() {
it('sets a screen dependent cache size', function () {
const source = new TileSource({});
expect(source.tileCache.highWaterMark).to.be(4 * Math.ceil(screen.availWidth / 256) * Math.ceil(screen.availHeight / 256));
expect(source.tileCache.highWaterMark).to.be(
4 *
Math.ceil(screen.availWidth / 256) *
Math.ceil(screen.availHeight / 256)
);
});
it('ignores a cache size that is too small', function() {
it('ignores a cache size that is too small', function () {
const source = new TileSource({
cacheSize: 1
cacheSize: 1,
});
expect(source.tileCache.highWaterMark).to.be(4 * Math.ceil(screen.availWidth / 256) * Math.ceil(screen.availHeight / 256));
expect(source.tileCache.highWaterMark).to.be(
4 *
Math.ceil(screen.availWidth / 256) *
Math.ceil(screen.availHeight / 256)
);
});
it('sets a custom cache size', function() {
it('sets a custom cache size', function () {
const projection = getProjection('EPSG:4326');
const source = new TileSource({
projection: projection,
cacheSize: 442
cacheSize: 442,
});
expect(source.getTileCacheForProjection(projection).highWaterMark).to.be(442);
expect(source.getTileCacheForProjection(projection).highWaterMark).to.be(
442
);
});
});
describe('#setKey()', function() {
it('sets the source key', function() {
describe('#setKey()', function () {
it('sets the source key', function () {
const source = new TileSource({});
expect(source.getKey()).to.equal('');
@@ -87,26 +94,26 @@ describe('ol.source.Tile', function() {
});
});
describe('#setKey()', function() {
it('dispatches a change event', function(done) {
describe('#setKey()', function () {
it('dispatches a change event', function (done) {
const source = new TileSource({});
const key = 'foo';
source.once('change', function() {
source.once('change', function () {
done();
});
source.setKey(key);
});
it('does not dispatch change if key does not change', function(done) {
it('does not dispatch change if key does not change', function (done) {
const source = new TileSource({});
const key = 'foo';
source.once('change', function() {
source.once('change', function() {
source.once('change', function () {
source.once('change', function () {
done(new Error('Unexpected change event after source.setKey()'));
});
setTimeout(function() {
setTimeout(function () {
done();
}, 10);
source.setKey(key); // this should not result in a change event
@@ -114,17 +121,15 @@ describe('ol.source.Tile', function() {
source.setKey(key); // this should result in a change event
});
});
describe('#forEachLoadedTile()', function() {
describe('#forEachLoadedTile()', function () {
let callback;
beforeEach(function() {
beforeEach(function () {
callback = sinon.spy();
});
it('does not call the callback if no tiles are loaded', function() {
it('does not call the callback if no tiles are loaded', function () {
const source = new MockTile({});
const grid = source.getTileGrid();
const extent = [-180, -180, 180, 180];
@@ -135,7 +140,7 @@ describe('ol.source.Tile', function() {
expect(callback.callCount).to.be(0);
});
it('does not call getTile() if no tiles are loaded', function() {
it('does not call getTile() if no tiles are loaded', function () {
const source = new MockTile({});
sinon.spy(source, 'getTile');
const grid = source.getTileGrid();
@@ -148,13 +153,12 @@ describe('ol.source.Tile', function() {
source.getTile.restore();
});
it('calls callback for each loaded tile', function() {
it('calls callback for each loaded tile', function () {
const source = new MockTile({
'1/0/0': 2, // LOADED
'1/0/1': 2, // LOADED
'1/1/0': 1, // LOADING,
'1/1/1': 2 // LOADED
'1/1/1': 2, // LOADED
});
const zoom = 1;
@@ -164,74 +168,81 @@ describe('ol.source.Tile', function() {
expect(callback.callCount).to.be(3);
});
it('returns true if range is fully loaded', function() {
it('returns true if range is fully loaded', function () {
// a source with no loaded tiles
const source = new MockTile({
'1/0/0': 2, // LOADED,
'1/0/1': 2, // LOADED,
'1/1/0': 2, // LOADED,
'1/1/1': 2 // LOADED
'1/1/1': 2, // LOADED
});
const zoom = 1;
const range = new TileRange(0, 1, 0, 1);
const covered = source.forEachLoadedTile(
source.getProjection(), zoom, range,
function() {
source.getProjection(),
zoom,
range,
function () {
return true;
});
}
);
expect(covered).to.be(true);
});
it('returns false if range is not fully loaded', function() {
it('returns false if range is not fully loaded', function () {
// a source with no loaded tiles
const source = new MockTile({
'1/0/0': 2, // LOADED,
'1/0/1': 2, // LOADED,
'1/1/0': 1, // LOADING,
'1/1/1': 2 // LOADED
'1/1/1': 2, // LOADED
});
const zoom = 1;
const range = new TileRange(0, 1, 0, 1);
const covered = source.forEachLoadedTile(
source.getProjection(), zoom,
range, function() {
source.getProjection(),
zoom,
range,
function () {
return true;
});
}
);
expect(covered).to.be(false);
});
it('allows callback to override loaded check', function() {
it('allows callback to override loaded check', function () {
// a source with no loaded tiles
const source = new MockTile({
'1/0/0': 2, // LOADED,
'1/0/1': 2, // LOADED,
'1/1/0': 2, // LOADED,
'1/1/1': 2 // LOADED
'1/1/1': 2, // LOADED
});
const zoom = 1;
const range = new TileRange(0, 1, 0, 1);
const covered = source.forEachLoadedTile(
source.getProjection(), zoom, range,
function() {
source.getProjection(),
zoom,
range,
function () {
return false;
});
}
);
expect(covered).to.be(false);
});
});
describe('#getTileCoordForTileUrlFunction()', function() {
it('returns the expected tile coordinate - {wrapX: true}', function() {
describe('#getTileCoordForTileUrlFunction()', function () {
it('returns the expected tile coordinate - {wrapX: true}', function () {
const tileSource = new TileSource({
projection: 'EPSG:3857',
wrapX: true
wrapX: true,
});
let tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, 22]);
@@ -244,10 +255,10 @@ describe('ol.source.Tile', function() {
expect(tileCoord).to.eql([6, 33, 22]);
});
it('returns the expected tile coordinate - {wrapX: false}', function() {
it('returns the expected tile coordinate - {wrapX: false}', function () {
const tileSource = new TileSource({
projection: 'EPSG:3857',
wrapX: false
wrapX: false,
});
let tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, 22]);
@@ -260,14 +271,14 @@ describe('ol.source.Tile', function() {
expect(tileCoord).to.eql(null);
});
it('works with wrapX and custom projection without extent', function() {
it('works with wrapX and custom projection without extent', function () {
const tileSource = new TileSource({
projection: new Projection({
code: 'foo',
global: true,
units: 'm'
units: 'm',
}),
wrapX: true
wrapX: true,
});
const tileCoord = tileSource.getTileCoordForTileUrlFunction([6, -31, 22]);
@@ -275,11 +286,11 @@ describe('ol.source.Tile', function() {
});
});
describe('#refresh()', function() {
it('checks clearing of internal state', function() {
describe('#refresh()', function () {
it('checks clearing of internal state', function () {
// create a source with one loaded tile
const source = new MockTile({
'1/0/0': 2 // LOADED
'1/0/0': 2, // LOADED
});
// check the loaded tile is there
const tile = source.getTile(1, 0, 0);
@@ -292,25 +303,22 @@ describe('ol.source.Tile', function() {
expect(source.tileCache.getCount()).to.eql(0);
});
});
});
describe('MockTile', function() {
describe('constructor', function() {
it('creates a tile source', function() {
describe('MockTile', function () {
describe('constructor', function () {
it('creates a tile source', function () {
const source = new MockTile({});
expect(source).to.be.a(TileSource);
expect(source).to.be.a(MockTile);
});
});
describe('#getTile()', function() {
it('returns a tile with state based on constructor arg', function() {
describe('#getTile()', function () {
it('returns a tile with state based on constructor arg', function () {
const source = new MockTile({
'0/0/0': 2, // LOADED,
'1/0/0': 2 // LOADED
'1/0/0': 2, // LOADED
});
let tile;
@@ -328,8 +336,6 @@ describe('MockTile', function() {
tile = source.getTile(1, 0, 0);
expect(tile).to.be.a(Tile);
expect(tile.state).to.be(2); // LOADED
});
});
});