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,30 +1,40 @@
import Feature from '../../../../src/ol/Feature.js';
import FeatureFormat from '../../../../src/ol/format/Feature.js';
import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
import FeatureFormat from '../../../../src/ol/format/Feature.js';
import {transform} from '../../../../src/ol/proj.js';
import TopoJSON from '../../../../src/ol/format/TopoJSON.js';
import {transform} from '../../../../src/ol/proj.js';
const aruba = {
type: 'Topology',
transform: {
scale: [0.036003600360036005, 0.017361589674592462],
translate: [-180, -89.99892578124998]
translate: [-180, -89.99892578124998],
},
objects: {
aruba: {
type: 'Polygon',
properties: {
prop0: 'value0'
prop0: 'value0',
},
arcs: [[0]],
id: 533
}
id: 533,
},
},
arcs: [
[[3058, 5901], [0, -2], [-2, 1], [-1, 3], [-2, 3], [0, 3], [1, 1], [1, -3],
[2, -5], [1, -1]]
]
[
[3058, 5901],
[0, -2],
[-2, 1],
[-1, 3],
[-2, 3],
[0, 3],
[1, 1],
[1, -3],
[2, -5],
[1, -1],
],
],
};
const zeroId = {
@@ -33,28 +43,26 @@ const zeroId = {
foobar: {
type: 'Point',
id: 0,
coordinates: [0, 42]
}
}
coordinates: [0, 42],
},
},
};
describe('ol.format.TopoJSON', function() {
describe('ol.format.TopoJSON', function () {
let format;
before(function() {
before(function () {
format = new TopoJSON();
});
describe('constructor', function() {
it('creates a new format', function() {
describe('constructor', function () {
it('creates a new format', function () {
expect(format).to.be.a(FeatureFormat);
expect(format).to.be.a(TopoJSON);
});
});
describe('#readFeaturesFromTopology_()', function() {
it('creates an array of features from a topology', function() {
describe('#readFeaturesFromTopology_()', function () {
it('creates an array of features from a topology', function () {
const features = format.readFeaturesFromObject(aruba);
expect(features).to.have.length(1);
@@ -70,12 +78,14 @@ describe('ol.format.TopoJSON', function() {
expect(feature.get('prop0')).to.be('value0');
expect(geometry.getExtent()).to.eql([
-70.08100810081008, 12.417091709170947,
-69.9009900990099, 12.608069195591469
-70.08100810081008,
12.417091709170947,
-69.9009900990099,
12.608069195591469,
]);
});
it('can read a feature with id equal to 0', function() {
it('can read a feature with id equal to 0', function () {
const features = format.readFeaturesFromObject(zeroId);
expect(features).to.have.length(1);
@@ -83,13 +93,11 @@ describe('ol.format.TopoJSON', function() {
expect(feature).to.be.a(Feature);
expect(feature.getId()).to.be(0);
});
});
describe('#readFeatures()', function() {
it('parses simple.json', function(done) {
afterLoadText('spec/ol/format/topojson/simple.json', function(text) {
describe('#readFeatures()', function () {
it('parses simple.json', function (done) {
afterLoadText('spec/ol/format/topojson/simple.json', function (text) {
const features = format.readFeatures(text);
expect(features.length).to.be(3);
@@ -100,30 +108,47 @@ describe('ol.format.TopoJSON', function() {
const line = features[1].getGeometry();
expect(line.getType()).to.be('LineString');
expect(line.getFlatCoordinates()).to.eql([
102, 0, 103, 1, 104, 0, 105, 1
102,
0,
103,
1,
104,
0,
105,
1,
]);
const polygon = features[2].getGeometry();
expect(polygon.getType()).to.be('Polygon');
expect(polygon.getFlatCoordinates()).to.eql([
100, 0, 100, 1, 101, 1, 101, 0, 100, 0
100,
0,
100,
1,
101,
1,
101,
0,
100,
0,
]);
done();
});
});
it('parses simple.json and transforms', function(done) {
afterLoadText('spec/ol/format/topojson/simple.json', function(text) {
it('parses simple.json and transforms', function (done) {
afterLoadText('spec/ol/format/topojson/simple.json', function (text) {
const features = format.readFeatures(text, {
featureProjection: 'EPSG:3857'
featureProjection: 'EPSG:3857',
});
expect(features.length).to.be(3);
const point = features[0].getGeometry();
expect(point.getType()).to.be('Point');
expect(features[0].getGeometry().getCoordinates()).to.eql(
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857')
);
const line = features[1].getGeometry();
expect(line.getType()).to.be('LineString');
@@ -131,26 +156,27 @@ describe('ol.format.TopoJSON', function() {
transform([102.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([103.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([104.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([105.0, 1.0], 'EPSG:4326', 'EPSG:3857')
transform([105.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
]);
const polygon = features[2].getGeometry();
expect(polygon.getType()).to.be('Polygon');
expect(polygon.getCoordinates()).to.eql([[
transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([100.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([101.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([101.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857')
]]);
expect(polygon.getCoordinates()).to.eql([
[
transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([100.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([101.0, 1.0], 'EPSG:4326', 'EPSG:3857'),
transform([101.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
transform([100.0, 0.0], 'EPSG:4326', 'EPSG:3857'),
],
]);
done();
});
});
it('parses world-110m.json', function(done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
it('parses world-110m.json', function (done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function (text) {
const features = format.readFeatures(text);
expect(features.length).to.be(178);
@@ -158,26 +184,32 @@ describe('ol.format.TopoJSON', function() {
expect(first).to.be.a(Feature);
const firstGeom = first.getGeometry();
expect(firstGeom).to.be.a(MultiPolygon);
expect(firstGeom.getExtent()).to.eql(
[-180, -85.60903777459777, 180, 83.64513000000002]);
expect(firstGeom.getExtent()).to.eql([
-180,
-85.60903777459777,
180,
83.64513000000002,
]);
const last = features[177];
expect(last).to.be.a(Feature);
const lastGeom = last.getGeometry();
expect(lastGeom).to.be.a(Polygon);
expect(lastGeom.getExtent()).to.eql([
25.26325263252633, -22.271802279310577,
32.848528485284874, -15.50833810039586
25.26325263252633,
-22.271802279310577,
32.848528485284874,
-15.50833810039586,
]);
done();
});
});
it('sets the topology\'s child names as feature property', function(done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
it("sets the topology's child names as feature property", function (done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function (text) {
const format = new TopoJSON({
layerName: 'layer'
layerName: 'layer',
});
const features = format.readFeatures(text);
expect(features[0].get('layer')).to.be('land');
@@ -186,17 +218,15 @@ describe('ol.format.TopoJSON', function() {
});
});
it('only parses features from specified topology\'s children', function(done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
it("only parses features from specified topology's children", function (done) {
afterLoadText('spec/ol/format/topojson/world-110m.json', function (text) {
const format = new TopoJSON({
layers: ['land']
layers: ['land'],
});
const features = format.readFeatures(text);
expect(features.length).to.be(1);
done();
});
});
});
});