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
+107 -128
View File
@@ -1,10 +1,9 @@
import Feature from '../../../../src/ol/Feature.js';
import Polyline, * as polyline from '../../../../src/ol/format/Polyline.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import Polyline, * as polyline from '../../../../src/ol/format/Polyline.js';
import {get as getProjection, transform} from '../../../../src/ol/proj.js';
describe('ol.format.Polyline', function() {
describe('ol.format.Polyline', function () {
let format;
let points;
let flatPoints, encodedFlatPoints, flippedFlatPoints;
@@ -16,29 +15,21 @@ describe('ol.format.Polyline', function() {
function resetTestingData() {
format = new Polyline();
points = [
[-120.20000, 38.50000],
[-120.95000, 40.70000],
[-126.45300, 43.25200]
];
flatPoints = [
-120.20000, 38.50000,
-120.95000, 40.70000,
-126.45300, 43.25200
];
flippedFlatPoints = [
38.50000, -120.20000,
40.70000, -120.95000,
43.25200, -126.45300
[-120.2, 38.5],
[-120.95, 40.7],
[-126.453, 43.252],
];
flatPoints = [-120.2, 38.5, -120.95, 40.7, -126.453, 43.252];
flippedFlatPoints = [38.5, -120.2, 40.7, -120.95, 43.252, -126.453];
encodedFlatPoints = '_p~iF~ps|U_ulLnnqC_mqNvxq`@';
points3857 = [
transform([-120.20000, 38.50000], 'EPSG:4326', 'EPSG:3857'),
transform([-120.95000, 40.70000], 'EPSG:4326', 'EPSG:3857'),
transform([-126.45300, 43.25200], 'EPSG:4326', 'EPSG:3857')
transform([-120.2, 38.5], 'EPSG:4326', 'EPSG:3857'),
transform([-120.95, 40.7], 'EPSG:4326', 'EPSG:3857'),
transform([-126.453, 43.252], 'EPSG:4326', 'EPSG:3857'),
];
floats = [0.00, 0.15, -0.01, -0.16, 0.16, 0.01];
smallFloats = [0.00000, 0.00015, -0.00001, -0.00016, 0.00016, 0.00001];
floats = [0.0, 0.15, -0.01, -0.16, 0.16, 0.01];
smallFloats = [0.0, 0.00015, -0.00001, -0.00016, 0.00016, 0.00001];
encodedFloats = '?]@^_@A';
signedIntegers = [0, 15, -1, -16, 16, 1];
@@ -51,32 +42,31 @@ describe('ol.format.Polyline', function() {
// Reset testing data
beforeEach(resetTestingData);
describe('#readProjectionFromText', function() {
it('returns the default projection', function() {
describe('#readProjectionFromText', function () {
it('returns the default projection', function () {
const projection = format.readProjectionFromText(encodedFlatPoints);
expect(projection).to.eql(getProjection('EPSG:4326'));
});
});
describe('encodeDeltas', function() {
it('returns expected value', function() {
describe('encodeDeltas', function () {
it('returns expected value', function () {
const encodeDeltas = polyline.encodeDeltas;
expect(encodeDeltas(flippedFlatPoints, 2)).to.eql(encodedFlatPoints);
});
});
describe('decodeDeltas', function() {
it('returns expected value', function() {
describe('decodeDeltas', function () {
it('returns expected value', function () {
const decodeDeltas = polyline.decodeDeltas;
expect(decodeDeltas(encodedFlatPoints, 2)).to.eql(flippedFlatPoints);
});
});
describe('encodeFloats', function() {
it('returns expected value', function() {
describe('encodeFloats', function () {
it('returns expected value', function () {
const encodeFloats = polyline.encodeFloats;
expect(encodeFloats(smallFloats)).to.eql(encodedFloats);
@@ -88,8 +78,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('decodeFloats', function() {
it('returns expected value', function() {
describe('decodeFloats', function () {
it('returns expected value', function () {
const decodeFloats = polyline.decodeFloats;
expect(decodeFloats(encodedFloats)).to.eql(smallFloats);
@@ -98,50 +88,51 @@ describe('ol.format.Polyline', function() {
});
});
describe('encodeSignedIntegers', function() {
it('returns expected value', function() {
describe('encodeSignedIntegers', function () {
it('returns expected value', function () {
const encodeSignedIntegers = polyline.encodeSignedIntegers;
expect(encodeSignedIntegers(
signedIntegers)).to.eql(encodedSignedIntegers);
expect(encodeSignedIntegers(signedIntegers)).to.eql(
encodedSignedIntegers
);
});
});
describe('decodeSignedIntegers', function() {
it('returns expected value', function() {
describe('decodeSignedIntegers', function () {
it('returns expected value', function () {
const decodeSignedIntegers = polyline.decodeSignedIntegers;
expect(decodeSignedIntegers(
encodedSignedIntegers)).to.eql(signedIntegers);
expect(decodeSignedIntegers(encodedSignedIntegers)).to.eql(
signedIntegers
);
});
});
describe('encodeUnsignedIntegers', function() {
it('returns expected value', function() {
describe('encodeUnsignedIntegers', function () {
it('returns expected value', function () {
const encodeUnsignedIntegers = polyline.encodeUnsignedIntegers;
expect(encodeUnsignedIntegers(
unsignedIntegers)).to.eql(encodedUnsignedIntegers);
expect(encodeUnsignedIntegers(unsignedIntegers)).to.eql(
encodedUnsignedIntegers
);
});
});
describe('decodeUnsignedIntegers', function() {
it('returns expected value', function() {
describe('decodeUnsignedIntegers', function () {
it('returns expected value', function () {
const decodeUnsignedIntegers = polyline.decodeUnsignedIntegers;
expect(decodeUnsignedIntegers(
encodedUnsignedIntegers)).to.eql(unsignedIntegers);
expect(decodeUnsignedIntegers(encodedUnsignedIntegers)).to.eql(
unsignedIntegers
);
});
});
describe('encodeFloat', function() {
it('returns expected value', function() {
describe('encodeFloat', function () {
it('returns expected value', function () {
const encodeFloats = polyline.encodeFloats;
expect(encodeFloats([0.00000])).to.eql('?');
expect(encodeFloats([0.0])).to.eql('?');
expect(encodeFloats([-0.00001])).to.eql('@');
expect(encodeFloats([0.00001])).to.eql('A');
expect(encodeFloats([-0.00002])).to.eql('B');
@@ -152,19 +143,19 @@ describe('ol.format.Polyline', function() {
expect(encodeFloats([-0.1], 10)).to.eql('@');
expect(encodeFloats([0.1], 10)).to.eql('A');
expect(encodeFloats([16 * 32 / 1e5])).to.eql('__@');
expect(encodeFloats([16 * 32 * 32 / 1e5])).to.eql('___@');
expect(encodeFloats([(16 * 32) / 1e5])).to.eql('__@');
expect(encodeFloats([(16 * 32 * 32) / 1e5])).to.eql('___@');
// from the "Encoded Polyline Algorithm Format" page at Google
expect(encodeFloats([-179.9832104])).to.eql('`~oia@');
});
});
describe('decodeFloat', function() {
it('returns expected value', function() {
describe('decodeFloat', function () {
it('returns expected value', function () {
const decodeFloats = polyline.decodeFloats;
expect(decodeFloats('?')).to.eql([0.00000]);
expect(decodeFloats('?')).to.eql([0.0]);
expect(decodeFloats('@')).to.eql([-0.00001]);
expect(decodeFloats('A')).to.eql([0.00001]);
expect(decodeFloats('B')).to.eql([-0.00002]);
@@ -175,17 +166,16 @@ describe('ol.format.Polyline', function() {
expect(decodeFloats('@', 10)).to.eql([-0.1]);
expect(decodeFloats('A', 10)).to.eql([0.1]);
expect(decodeFloats('__@')).to.eql([16 * 32 / 1e5]);
expect(decodeFloats('___@')).to.eql([16 * 32 * 32 / 1e5]);
expect(decodeFloats('__@')).to.eql([(16 * 32) / 1e5]);
expect(decodeFloats('___@')).to.eql([(16 * 32 * 32) / 1e5]);
// from the "Encoded Polyline Algorithm Format" page at Google
expect(decodeFloats('`~oia@')).to.eql([-179.98321]);
});
});
describe('encodeSignedInteger', function() {
it('returns expected value', function() {
describe('encodeSignedInteger', function () {
it('returns expected value', function () {
const encodeSignedIntegers = polyline.encodeSignedIntegers;
expect(encodeSignedIntegers([0])).to.eql('?');
@@ -202,8 +192,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('decodeSignedInteger', function() {
it('returns expected value', function() {
describe('decodeSignedInteger', function () {
it('returns expected value', function () {
const decodeSignedIntegers = polyline.decodeSignedIntegers;
expect(decodeSignedIntegers('?')).to.eql([0]);
@@ -220,9 +210,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('encodeUnsignedInteger', function() {
it('returns expected value', function() {
describe('encodeUnsignedInteger', function () {
it('returns expected value', function () {
const encodeUnsignedInteger = polyline.encodeUnsignedInteger;
expect(encodeUnsignedInteger(0)).to.eql('?');
@@ -241,8 +230,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('decodeUnsignedInteger', function() {
it('returns expected value', function() {
describe('decodeUnsignedInteger', function () {
it('returns expected value', function () {
const decodeUnsignedIntegers = polyline.decodeUnsignedIntegers;
expect(decodeUnsignedIntegers('?')).to.eql([0]);
@@ -261,9 +250,8 @@ describe('ol.format.Polyline', function() {
});
});
describe('#readFeature', function() {
it('returns the expected feature', function() {
describe('#readFeature', function () {
it('returns the expected feature', function () {
const feature = format.readFeature(encodedFlatPoints);
expect(feature).to.be.an(Feature);
const geometry = feature.getGeometry();
@@ -271,21 +259,19 @@ describe('ol.format.Polyline', function() {
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
});
it('transforms and returns the expected feature', function() {
it('transforms and returns the expected feature', function () {
const feature = format.readFeature(encodedFlatPoints, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(feature).to.be.an(Feature);
const geometry = feature.getGeometry();
expect(geometry).to.be.an(LineString);
expect(geometry.getCoordinates()).to.eql(points3857);
});
});
describe('#readFeatures', function() {
it('returns the expected feature', function() {
describe('#readFeatures', function () {
it('returns the expected feature', function () {
const features = format.readFeatures(encodedFlatPoints);
expect(features).to.be.an(Array);
expect(features).to.have.length(1);
@@ -296,9 +282,9 @@ describe('ol.format.Polyline', function() {
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
});
it('transforms and returns the expected features', function() {
it('transforms and returns the expected features', function () {
const features = format.readFeatures(encodedFlatPoints, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(features).to.be.an(Array);
expect(features).to.have.length(1);
@@ -308,101 +294,94 @@ describe('ol.format.Polyline', function() {
expect(geometry).to.be.an(LineString);
expect(geometry.getCoordinates()).to.eql(points3857);
});
});
describe('#readGeometry', function() {
it('returns the expected geometry', function() {
describe('#readGeometry', function () {
it('returns the expected geometry', function () {
const geometry = format.readGeometry(encodedFlatPoints);
expect(geometry).to.be.an(LineString);
expect(geometry.getFlatCoordinates()).to.eql(flatPoints);
});
it('parses XYZ linestring', function() {
const xyz = polyline.encodeDeltas([
38.500, -120.200, 100,
40.700, -120.950, 200,
43.252, -126.453, 20
], 3);
it('parses XYZ linestring', function () {
const xyz = polyline.encodeDeltas(
[38.5, -120.2, 100, 40.7, -120.95, 200, 43.252, -126.453, 20],
3
);
const format = new Polyline({
geometryLayout: 'XYZ'
geometryLayout: 'XYZ',
});
const geometry = format.readGeometry(xyz);
expect(geometry.getLayout()).to.eql('XYZ');
expect(geometry.getCoordinates()).to.eql([
[-120.200, 38.500, 100],
[-120.950, 40.700, 200],
[-126.453, 43.252, 20]
[-120.2, 38.5, 100],
[-120.95, 40.7, 200],
[-126.453, 43.252, 20],
]);
});
it('transforms and returns the expected geometry', function() {
it('transforms and returns the expected geometry', function () {
const geometry = format.readGeometry(encodedFlatPoints, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(geometry).to.be.an(LineString);
expect(geometry.getCoordinates()).to.eql(points3857);
});
});
describe('#readProjection', function() {
it('returns the expected projection', function() {
describe('#readProjection', function () {
it('returns the expected projection', function () {
const projection = format.readProjection(encodedFlatPoints);
expect(projection).to.be(getProjection('EPSG:4326'));
});
});
describe('#writeFeature', function() {
it('returns the expected text', function() {
describe('#writeFeature', function () {
it('returns the expected text', function () {
const feature = new Feature(new LineString(points));
expect(format.writeFeature(feature)).to.be(encodedFlatPoints);
});
it('transforms and returns the expected text', function() {
it('transforms and returns the expected text', function () {
const feature = new Feature(new LineString(points3857));
expect(format.writeFeature(feature, {
featureProjection: 'EPSG:3857'
})).to.be(encodedFlatPoints);
expect(
format.writeFeature(feature, {
featureProjection: 'EPSG:3857',
})
).to.be(encodedFlatPoints);
});
});
describe('#writeFeature', function() {
it('returns the expected text', function() {
describe('#writeFeature', function () {
it('returns the expected text', function () {
const features = [new Feature(new LineString(points))];
expect(format.writeFeatures(features)).to.be(encodedFlatPoints);
});
it('transforms and returns the expected text', function() {
it('transforms and returns the expected text', function () {
const features = [new Feature(new LineString(points3857))];
expect(format.writeFeatures(features, {
featureProjection: 'EPSG:3857'
})).to.be(encodedFlatPoints);
expect(
format.writeFeatures(features, {
featureProjection: 'EPSG:3857',
})
).to.be(encodedFlatPoints);
});
});
describe('#writeGeometry', function() {
it('returns the expected text', function() {
describe('#writeGeometry', function () {
it('returns the expected text', function () {
const geometry = new LineString(points);
expect(format.writeGeometry(geometry)).to.be(encodedFlatPoints);
});
it('transforms and returns the expected text', function() {
it('transforms and returns the expected text', function () {
const geometry = new LineString(points3857);
expect(format.writeGeometry(geometry, {
featureProjection: 'EPSG:3857'
})).to.be(encodedFlatPoints);
expect(
format.writeGeometry(geometry, {
featureProjection: 'EPSG:3857',
})
).to.be(encodedFlatPoints);
});
});
});