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,70 +1,69 @@
import {get as getProjection, transformExtent, fromLonLat} from '../../../../src/ol/proj.js';
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
import TileSource from '../../../../src/ol/source/Tile.js';
import UTFGrid, {CustomTile} from '../../../../src/ol/source/UTFGrid.js';
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
describe('ol.source.UTFGrid', function() {
import {
fromLonLat,
get as getProjection,
transformExtent,
} from '../../../../src/ol/proj.js';
describe('ol.source.UTFGrid', function () {
const url = 'spec/ol/data/utfgrid.json';
let tileJson = null;
// Load and parse the UTFGrid fixture
before(function(done) {
before(function (done) {
const client = new XMLHttpRequest();
client.addEventListener('load', function() {
client.addEventListener('load', function () {
tileJson = JSON.parse(this.responseText);
done();
});
client.addEventListener('error', function() {
client.addEventListener('error', function () {
done(new Error('Failed to fetch ' + url));
});
client.open('GET', url);
client.send();
});
after(function() {
after(function () {
tileJson = null;
});
function getUTFGrid() {
return new UTFGrid({
url: url
url: url,
});
}
describe('constructor', function() {
it('needs to be constructed with url option', function() {
describe('constructor', function () {
it('needs to be constructed with url option', function () {
const source = new UTFGrid({url: url});
expect(source).to.be.an(UTFGrid);
expect(source).to.be.an(TileSource);
expect(function() {
expect(function () {
// no options: will throw
return new UTFGrid();
}).to.throwException();
expect(function() {
expect(function () {
// no url-option: will throw
return new UTFGrid({});
}).to.throwException();
expect(getUTFGrid()).to.be.an(UTFGrid);
});
});
describe('change event (ready)', function() {
it('is fired when the source is ready', function(done) {
describe('change event (ready)', function () {
it('is fired when the source is ready', function (done) {
const source = new UTFGrid({
url: url
url: url,
});
expect(source.getState()).to.be('loading');
expect(source.tileGrid).to.be(null);
source.on('change', function(event) {
source.on('change', function (event) {
if (source.getState() === 'ready') {
expect(source.tileGrid).to.be.an(TileGrid);
done();
@@ -73,15 +72,15 @@ describe('ol.source.UTFGrid', function() {
});
});
describe('change event (error)', function(done) {
it('is fired when the source fails to initialize', function(done) {
describe('change event (error)', function (done) {
it('is fired when the source fails to initialize', function (done) {
const source = new UTFGrid({
url: 'Bogus UTFGrid URL'
url: 'Bogus UTFGrid URL',
});
expect(source.getState()).to.be('loading');
expect(source.tileGrid).to.be(null);
source.on('change', function(event) {
source.on('change', function (event) {
if (source.getState() === 'error') {
expect(source.tileGrid).to.be(null);
done();
@@ -90,9 +89,8 @@ describe('ol.source.UTFGrid', function() {
});
});
describe('#handleTileJSONResponse', function() {
it('sets up a tileGrid', function() {
describe('#handleTileJSONResponse', function () {
it('sets up a tileGrid', function () {
const source = getUTFGrid();
expect(source.getTileGrid()).to.be(null);
// call the handleTileJSONResponse method with our
@@ -104,7 +102,7 @@ describe('ol.source.UTFGrid', function() {
expect(tileGrid).to.be.an(TileGrid);
});
it('sets up a tilegrid with expected extent', function() {
it('sets up a tilegrid with expected extent', function () {
const source = getUTFGrid();
// call the handleTileJSONResponse method with our
// locally available tileJson (from `before`)
@@ -117,7 +115,9 @@ describe('ol.source.UTFGrid', function() {
const proj3857 = getProjection('EPSG:3857');
const expectedExtent4326 = tileJson.bounds;
const expectedExtent3857 = transformExtent(
expectedExtent4326, proj4326, proj3857
expectedExtent4326,
proj4326,
proj3857
);
expect(extent).to.eql(proj3857.getExtent());
expect(extent[0]).to.roughlyEqual(expectedExtent3857[0], 1e-8);
@@ -126,7 +126,7 @@ describe('ol.source.UTFGrid', function() {
expect(extent[3]).to.roughlyEqual(expectedExtent3857[3], 1e-8);
});
it('sets up a tilegrid with expected minZoom', function() {
it('sets up a tilegrid with expected minZoom', function () {
const source = getUTFGrid();
// call the handleTileJSONResponse method with our
// locally available tileJson (from `before`)
@@ -137,7 +137,7 @@ describe('ol.source.UTFGrid', function() {
expect(minZoom).to.eql(tileJson.minzoom);
});
it('sets up a tilegrid with expected maxZoom', function() {
it('sets up a tilegrid with expected maxZoom', function () {
const source = getUTFGrid();
// call the handleTileJSONResponse method with our
// locally available tileJson (from `before`)
@@ -148,7 +148,7 @@ describe('ol.source.UTFGrid', function() {
expect(maxZoom).to.eql(tileJson.maxzoom);
});
it('sets up a template', function() {
it('sets up a template', function () {
const source = getUTFGrid();
expect(source.getTemplate()).to.be(undefined);
@@ -161,7 +161,7 @@ describe('ol.source.UTFGrid', function() {
expect(template).to.be(tileJson.template);
});
it('sets up correct attribution', function() {
it('sets up correct attribution', function () {
const source = getUTFGrid();
expect(source.getAttributions()).to.be(null);
@@ -174,7 +174,7 @@ describe('ol.source.UTFGrid', function() {
expect(typeof attributions).to.be('function');
});
it('sets correct state', function() {
it('sets correct state', function () {
const source = getUTFGrid();
expect(source.getState()).to.be('loading');
@@ -184,10 +184,9 @@ describe('ol.source.UTFGrid', function() {
expect(source.getState()).to.be('ready');
});
});
describe('#forDataAtCoordinateAndResolution', function() {
describe('#forDataAtCoordinateAndResolution', function () {
let source = null;
const bonn3857 = fromLonLat([7.099814, 50.733992]);
const noState3857 = [0, 0];
@@ -198,23 +197,23 @@ describe('ol.source.UTFGrid', function() {
// grid for one tile (1/1/0) and store the result in a variable. This allows
// us to overwrite getTile in a way that removes the dependency on an
// external service. See below in the `beforeEach`-method.
before(function(done) {
before(function (done) {
const client = new XMLHttpRequest();
client.addEventListener('load', function() {
client.addEventListener('load', function () {
gridJson110 = JSON.parse(this.responseText);
done();
});
client.addEventListener('error', function() {
client.addEventListener('error', function () {
done(new Error('Failed to fetch local grid.json'));
});
client.open('GET', 'spec/ol/data/mapbox-geography-class-1-1-0.grid.json');
client.send();
});
after(function() {
after(function () {
gridJson110 = null;
});
beforeEach(function() {
beforeEach(function () {
source = getUTFGrid();
// call the handleTileJSONResponse method with our
// locally available tileJson (from `before`)
@@ -223,29 +222,35 @@ describe('ol.source.UTFGrid', function() {
// Override getTile method to not depend on the external service. The
// signature of the method is kept the same, but the returned tile will
// always be for [1, 1, 0].
source.getTile = function(z, x, y, pixelRatio, projection) {
source.getTile = function (z, x, y, pixelRatio, projection) {
const tileCoord = [1, 1, 0]; // overwritten to match our stored JSON
const urlTileCoord =
this.getTileCoordForTileUrlFunction(tileCoord, projection);
const tileUrl = this.tileUrlFunction_(urlTileCoord, pixelRatio, projection);
const urlTileCoord = this.getTileCoordForTileUrlFunction(
tileCoord,
projection
);
const tileUrl = this.tileUrlFunction_(
urlTileCoord,
pixelRatio,
projection
);
const tile = new CustomTile(
tileCoord,
tileUrl !== undefined ? 0 : 4, // IDLE : EMPTY
tileUrl !== undefined ? tileUrl : '',
this.tileGrid.getTileCoordExtent(tileCoord),
true); // always preemptive, so loading doesn't happen automatically
true
); // always preemptive, so loading doesn't happen automatically
// manually call handleLoad_ with our local JSON data
tile.handleLoad_(gridJson110);
return tile;
};
});
afterEach(function() {
afterEach(function () {
source = null;
});
it('calls callback with data if found', function(done) {
const callback = function(data) {
it('calls callback with data if found', function (done) {
const callback = function (data) {
expect(arguments).to.have.length(1);
expect(data).to.not.be(null);
expect('admin' in data).to.be(true);
@@ -253,21 +258,25 @@ describe('ol.source.UTFGrid', function() {
done();
};
source.forDataAtCoordinateAndResolution(
bonn3857, resolutionZoom1, callback, true
bonn3857,
resolutionZoom1,
callback,
true
);
});
it('calls callback with `null` if not found', function(done) {
const callback = function(data) {
it('calls callback with `null` if not found', function (done) {
const callback = function (data) {
expect(arguments).to.have.length(1);
expect(data).to.be(null);
done();
};
source.forDataAtCoordinateAndResolution(
noState3857, resolutionZoom1, callback, true
noState3857,
resolutionZoom1,
callback,
true
);
});
});
});