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
+56 -34
View File
@@ -1,53 +1,72 @@
import ImageWrapper from '../../../../src/ol/Image.js';
import {listen} from '../../../../src/ol/events.js';
import {get as getProjection} from '../../../../src/ol/proj.js';
import ReprojImage from '../../../../src/ol/reproj/Image.js';
import {get as getProjection} from '../../../../src/ol/proj.js';
import {listen} from '../../../../src/ol/events.js';
describe('ol.reproj.Image', function() {
describe('ol.reproj.Image', function () {
function createImage(pixelRatio) {
return new ReprojImage(
getProjection('EPSG:3857'), getProjection('EPSG:4326'),
[-180, -85, 180, 85], 10, pixelRatio,
function(extent, resolution, pixelRatio) {
return new ImageWrapper(extent, resolution, pixelRatio,
getProjection('EPSG:3857'),
getProjection('EPSG:4326'),
[-180, -85, 180, 85],
10,
pixelRatio,
function (extent, resolution, pixelRatio) {
return new ImageWrapper(
extent,
resolution,
pixelRatio,
'data:image/gif;base64,' +
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=', null,
function(image, src) {
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=',
null,
function (image, src) {
image.getImage().src = src;
});
});
}
);
}
);
}
function createTranslucentImage(pixelRatio) {
return new ReprojImage(
getProjection('EPSG:3857'), getProjection('EPSG:4326'),
[-180, -85, 180, 85], 10, pixelRatio,
function(extent, resolution, pixelRatio) {
return new ImageWrapper(extent, resolution, pixelRatio,
getProjection('EPSG:3857'),
getProjection('EPSG:4326'),
[-180, -85, 180, 85],
10,
pixelRatio,
function (extent, resolution, pixelRatio) {
return new ImageWrapper(
extent,
resolution,
pixelRatio,
'data:image/png;base64,' +
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8depePQAIiwMjFXlnJQAAAABJRU5ErkJggg==', null,
function(image, src) {
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8depePQAIiwMjFXlnJQAAAABJRU5ErkJggg==',
null,
function (image, src) {
image.getImage().src = src;
});
});
}
);
}
);
}
it('changes state as expected', function(done) {
it('changes state as expected', function (done) {
const image = createImage(1);
expect(image.getState()).to.be(0); // IDLE
listen(image, 'change', function() {
if (image.getState() == 2) { // LOADED
listen(image, 'change', function () {
if (image.getState() == 2) {
// LOADED
done();
}
});
image.load();
});
it('returns correct canvas size', function(done) {
it('returns correct canvas size', function (done) {
const image = createImage(1);
listen(image, 'change', function() {
if (image.getState() == 2) { // LOADED
listen(image, 'change', function () {
if (image.getState() == 2) {
// LOADED
const canvas = image.getImage();
expect(canvas.width).to.be(36);
expect(canvas.height).to.be(17);
@@ -57,10 +76,11 @@ describe('ol.reproj.Image', function() {
image.load();
});
it('respects pixelRatio', function(done) {
it('respects pixelRatio', function (done) {
const image = createImage(2);
listen(image, 'change', function() {
if (image.getState() == 2) { // LOADED
listen(image, 'change', function () {
if (image.getState() == 2) {
// LOADED
const canvas = image.getImage();
expect(canvas.width).to.be(72);
expect(canvas.height).to.be(34);
@@ -70,14 +90,17 @@ describe('ol.reproj.Image', function() {
image.load();
});
it('has uniform color', function(done) {
it('has uniform color', function (done) {
const image = createTranslucentImage(1);
listen(image, 'change', function() {
if (image.getState() == 2) { // LOADED
listen(image, 'change', function () {
if (image.getState() == 2) {
// LOADED
const canvas = image.getImage();
expect(canvas.width).to.be(36);
expect(canvas.height).to.be(17);
const pixels = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data;
const pixels = canvas
.getContext('2d')
.getImageData(0, 0, canvas.width, canvas.height).data;
for (let i = 0; i < canvas.width * canvas.height * 4; i += 4) {
expect(pixels[i + 0]).to.be.within(pixels[0] - 2, pixels[0] + 2);
@@ -90,5 +113,4 @@ describe('ol.reproj.Image', function() {
});
image.load();
});
});
+32 -12
View File
@@ -1,43 +1,63 @@
import {calculateSourceResolution} from '../../../../src/ol/reproj.js';
import {get as getProjection, transform} from '../../../../src/ol/proj.js';
describe('ol.reproj', function() {
describe('#calculateSourceResolution', function() {
describe('ol.reproj', function () {
describe('#calculateSourceResolution', function () {
const proj3857 = getProjection('EPSG:3857');
const proj4326 = getProjection('EPSG:4326');
const origin = [0, 0];
const point3857 = [50, 40];
const point4326 = transform(point3857, proj3857, proj4326);
it('is identity for identical projection', function() {
it('is identity for identical projection', function () {
let result;
const resolution = 500;
result = calculateSourceResolution(
proj3857, proj3857, origin, resolution);
proj3857,
proj3857,
origin,
resolution
);
expect(result).to.be(resolution);
result = calculateSourceResolution(
proj3857, proj3857, point3857, resolution);
proj3857,
proj3857,
point3857,
resolution
);
expect(result).to.be(resolution);
result = calculateSourceResolution(
proj4326, proj4326, point4326, resolution);
proj4326,
proj4326,
point4326,
resolution
);
expect(result).to.be(resolution);
});
it('calculates correctly', function() {
it('calculates correctly', function () {
const resolution4326 = 5;
const resolution3857 = calculateSourceResolution(
proj3857, proj4326, point4326, resolution4326);
proj3857,
proj4326,
point4326,
resolution4326
);
expect(resolution3857).not.to.be(resolution4326);
expect(resolution3857).to.roughlyEqual(
5 * proj4326.getMetersPerUnit(), 1e-4);
5 * proj4326.getMetersPerUnit(),
1e-4
);
const result = calculateSourceResolution(
proj4326, proj3857, point3857, resolution3857);
proj4326,
proj3857,
point3857,
resolution3857
);
expect(result).to.be(resolution4326);
});
});
+69 -36
View File
@@ -1,84 +1,116 @@
import ImageTile from '../../../../src/ol/ImageTile.js';
import {listen} from '../../../../src/ol/events.js';
import {addCommon, clearAllProjections, get as getProjection} from '../../../../src/ol/proj.js';
import {register} from '../../../../src/ol/proj/proj4.js';
import ReprojTile from '../../../../src/ol/reproj/Tile.js';
import {
addCommon,
clearAllProjections,
get as getProjection,
} from '../../../../src/ol/proj.js';
import {createForProjection} from '../../../../src/ol/tilegrid.js';
import {listen} from '../../../../src/ol/events.js';
import {register} from '../../../../src/ol/proj/proj4.js';
describe('ol.reproj.Tile', function() {
beforeEach(function() {
proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 ' +
describe('ol.reproj.Tile', function () {
beforeEach(function () {
proj4.defs(
'EPSG:27700',
'+proj=tmerc +lat_0=49 +lon_0=-2 ' +
'+k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy ' +
'+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
'+units=m +no_defs');
'+units=m +no_defs'
);
register(proj4);
const proj27700 = getProjection('EPSG:27700');
proj27700.setExtent([0, 0, 700000, 1300000]);
});
afterEach(function() {
afterEach(function () {
delete proj4.defs['EPSG:27700'];
clearAllProjections();
addCommon();
});
function createTile(pixelRatio, opt_tileSize) {
const proj4326 = getProjection('EPSG:4326');
const proj3857 = getProjection('EPSG:3857');
return new ReprojTile(
proj3857, createForProjection(proj3857), proj4326,
proj3857,
createForProjection(proj3857),
proj4326,
createForProjection(proj4326, 3, opt_tileSize),
[3, 2, 1], null, pixelRatio, 0, function(z, x, y, pixelRatio) {
return new ImageTile([z, x, y], 0, // IDLE
[3, 2, 1],
null,
pixelRatio,
0,
function (z, x, y, pixelRatio) {
return new ImageTile(
[z, x, y],
0, // IDLE
'data:image/gif;base64,' +
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=', null,
function(tile, src) {
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=',
null,
function (tile, src) {
tile.getImage().src = src;
});
});
}
);
}
);
}
it('changes state as expected', function(done) {
it('changes state as expected', function (done) {
const tile = createTile(1);
expect(tile.getState()).to.be(0); // IDLE
listen(tile, 'change', function() {
if (tile.getState() == 2) { // LOADED
listen(tile, 'change', function () {
if (tile.getState() == 2) {
// LOADED
done();
}
});
tile.load();
});
it('is empty when outside target tile grid', function() {
it('is empty when outside target tile grid', function () {
const proj4326 = getProjection('EPSG:4326');
const proj3857 = getProjection('EPSG:3857');
const tile = new ReprojTile(
proj3857, createForProjection(proj3857),
proj4326, createForProjection(proj4326),
[0, -1, 0], null, 1, 0, function() {
proj3857,
createForProjection(proj3857),
proj4326,
createForProjection(proj4326),
[0, -1, 0],
null,
1,
0,
function () {
expect().fail('No tiles should be required');
});
}
);
expect(tile.getState()).to.be(4); // EMPTY
});
it('is empty when outside source tile grid', function() {
it('is empty when outside source tile grid', function () {
const proj4326 = getProjection('EPSG:4326');
const proj27700 = getProjection('EPSG:27700');
const tile = new ReprojTile(
proj27700, createForProjection(proj27700),
proj4326, createForProjection(proj4326),
[3, 2, -2], null, 1, 0, function() {
proj27700,
createForProjection(proj27700),
proj4326,
createForProjection(proj4326),
[3, 2, -2],
null,
1,
0,
function () {
expect().fail('No tiles should be required');
});
}
);
expect(tile.getState()).to.be(4); // EMPTY
});
it('respects tile size of target tile grid', function(done) {
it('respects tile size of target tile grid', function (done) {
const tile = createTile(1, [100, 40]);
listen(tile, 'change', function() {
if (tile.getState() == 2) { // LOADED
listen(tile, 'change', function () {
if (tile.getState() == 2) {
// LOADED
const canvas = tile.getImage();
expect(canvas.width).to.be(100);
expect(canvas.height).to.be(40);
@@ -88,10 +120,11 @@ describe('ol.reproj.Tile', function() {
tile.load();
});
it('respects pixelRatio', function(done) {
it('respects pixelRatio', function (done) {
const tile = createTile(3, [60, 20]);
listen(tile, 'change', function() {
if (tile.getState() == 2) { // LOADED
listen(tile, 'change', function () {
if (tile.getState() == 2) {
// LOADED
const canvas = tile.getImage();
expect(canvas.width).to.be(180);
expect(canvas.height).to.be(60);
+39 -18
View File
@@ -1,45 +1,66 @@
import {addCommon, clearAllProjections, get as getProjection} from '../../../../src/ol/proj.js';
import {register} from '../../../../src/ol/proj/proj4.js';
import Triangulation from '../../../../src/ol/reproj/Triangulation.js';
import {
addCommon,
clearAllProjections,
get as getProjection,
} from '../../../../src/ol/proj.js';
import {register} from '../../../../src/ol/proj/proj4.js';
describe('ol.reproj.Triangulation', function() {
beforeEach(function() {
proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 ' +
describe('ol.reproj.Triangulation', function () {
beforeEach(function () {
proj4.defs(
'EPSG:27700',
'+proj=tmerc +lat_0=49 +lon_0=-2 ' +
'+k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy ' +
'+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
'+units=m +no_defs');
'+units=m +no_defs'
);
register(proj4);
const proj27700 = getProjection('EPSG:27700');
proj27700.setExtent([0, 0, 700000, 1300000]);
});
afterEach(function() {
afterEach(function () {
delete proj4.defs['EPSG:27700'];
clearAllProjections();
addCommon();
});
describe('constructor', function() {
it('is trivial for identity', function() {
describe('constructor', function () {
it('is trivial for identity', function () {
const proj4326 = getProjection('EPSG:4326');
const triangulation = new Triangulation(proj4326, proj4326,
[20, 20, 30, 30], [-180, -90, 180, 90], 0);
const triangulation = new Triangulation(
proj4326,
proj4326,
[20, 20, 30, 30],
[-180, -90, 180, 90],
0
);
expect(triangulation.getTriangles().length).to.be(2);
});
it('is empty when outside source extent', function() {
it('is empty when outside source extent', function () {
const proj4326 = getProjection('EPSG:4326');
const proj27700 = getProjection('EPSG:27700');
const triangulation = new Triangulation(proj27700, proj4326,
[0, 0, 10, 10], proj27700.getExtent(), 0);
const triangulation = new Triangulation(
proj27700,
proj4326,
[0, 0, 10, 10],
proj27700.getExtent(),
0
);
expect(triangulation.getTriangles().length).to.be(0);
});
it('can handle null source extent', function() {
it('can handle null source extent', function () {
const proj4326 = getProjection('EPSG:4326');
const triangulation = new Triangulation(proj4326, proj4326,
[20, 20, 30, 30], null, 0);
const triangulation = new Triangulation(
proj4326,
proj4326,
[20, 20, 30, 30],
null,
0
);
expect(triangulation.getTriangles().length).to.be(2);
});
});