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
+486 -208
View File
@@ -1,353 +1,626 @@
import {isEmpty} from '../../../../src/ol/extent.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import MultiLineString from '../../../../src/ol/geom/MultiLineString.js';
import {isEmpty} from '../../../../src/ol/extent.js';
describe('ol.geom.MultiLineString', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.MultiLineString', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new MultiLineString(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let multiLineString;
beforeEach(function() {
beforeEach(function () {
multiLineString = new MultiLineString([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(multiLineString.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(multiLineString.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(multiLineString.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(2);
});
it('can append line strings', function() {
it('can append line strings', function () {
multiLineString.appendLineString(
new LineString([[1, 2], [3, 4]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]]]);
new LineString([
[1, 2],
[3, 4],
])
);
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
]);
multiLineString.appendLineString(
new LineString([[5, 6], [7, 8]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
new LineString([
[5, 6],
[7, 8],
])
);
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 7, 8]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(2);
});
describe('#getFlatMidpoints', function() {
it('returns the expected result', function() {
describe('#getFlatMidpoints', function () {
it('returns the expected result', function () {
expect(multiLineString.getFlatMidpoints()).to.eql([2, 3, 6, 7]);
});
});
describe('#intersectsExtent()', function() {
it('returns true for intersecting part of lineString', function() {
describe('#intersectsExtent()', function () {
it('returns true for intersecting part of lineString', function () {
expect(multiLineString.intersectsExtent([1, 2, 2, 3])).to.be(true);
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
expect(multiLineString.intersectsExtent([1, 7, 2, 8])).to.be(false);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 10, 11]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(3);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let multiLineString;
beforeEach(function() {
beforeEach(function () {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
'XYM');
[
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
],
'XYM'
);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 10, 11]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(3);
});
it('can return individual line strings', function() {
it('can return individual line strings', function () {
const lineString0 = multiLineString.getLineString(0);
expect(lineString0).to.be.an(LineString);
expect(lineString0.getLayout()).to.be('XYM');
expect(lineString0.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
expect(lineString0.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
const lineString1 = multiLineString.getLineString(1);
expect(lineString1).to.be.an(LineString);
expect(lineString1.getLayout()).to.be('XYM');
expect(lineString1.getCoordinates()).to.eql([[7, 8, 9], [10, 11, 12]]);
expect(lineString1.getCoordinates()).to.eql([
[7, 8, 9],
[10, 11, 12],
]);
});
describe('#getCoordinateAtM', function() {
describe('with extrapolation and interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, true, true)).to.eql(
[1, 2, 0]);
expect(multiLineString.getCoordinateAtM(3, true, true)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, true, true)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, true, true)).to.eql(
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, true, true)).to.eql(
[5.5, 6.5, 7.5]);
expect(multiLineString.getCoordinateAtM(9, true, true)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, true, true)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, true, true)).to.eql(
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, true, true)).to.eql(
[10, 11, 15]);
describe('#getCoordinateAtM', function () {
describe('with extrapolation and interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, true, true)).to.eql([
1,
2,
0,
]);
expect(multiLineString.getCoordinateAtM(3, true, true)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, true, true)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, true, true)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, true, true)).to.eql([
5.5,
6.5,
7.5,
]);
expect(multiLineString.getCoordinateAtM(9, true, true)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, true, true)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, true, true)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, true, true)).to.eql([
10,
11,
15,
]);
});
});
describe('with extrapolation and no interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, true, false)).to.eql(
[1, 2, 0]);
expect(multiLineString.getCoordinateAtM(3, true, false)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, true, false)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, true, false)).to.eql(
[4, 5, 6]);
describe('with extrapolation and no interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, true, false)).to.eql([
1,
2,
0,
]);
expect(multiLineString.getCoordinateAtM(3, true, false)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, true, false)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, true, false)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, true, false)).to.be(
null);
expect(multiLineString.getCoordinateAtM(9, true, false)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, true, false)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, true, false)).to.eql(
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, true, false)).to.eql(
[10, 11, 15]);
null
);
expect(multiLineString.getCoordinateAtM(9, true, false)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, true, false)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, true, false)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, true, false)).to.eql([
10,
11,
15,
]);
});
});
describe('with no extrapolation and interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, false, true)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(3, false, true)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, false, true)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, false, true)).to.eql(
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, false, true)).to.eql(
[5.5, 6.5, 7.5]);
expect(multiLineString.getCoordinateAtM(9, false, true)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, false, true)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, false, true)).to.eql(
[10, 11, 12]);
describe('with no extrapolation and interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, false, true)).to.eql(null);
expect(multiLineString.getCoordinateAtM(3, false, true)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, false, true)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, false, true)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, false, true)).to.eql([
5.5,
6.5,
7.5,
]);
expect(multiLineString.getCoordinateAtM(9, false, true)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, false, true)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, false, true)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, false, true)).to.eql(
null);
null
);
});
});
describe('with no extrapolation or interpolation', function() {
it('returns the expected value', function() {
describe('with no extrapolation or interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, false, false)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(3, false, false)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, false, false)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, false, false)).to.eql(
[4, 5, 6]);
null
);
expect(multiLineString.getCoordinateAtM(3, false, false)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, false, false)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, false, false)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, false, false)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(9, false, false)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, false, false)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, false, false)).to.eql(
[10, 11, 12]);
null
);
expect(multiLineString.getCoordinateAtM(9, false, false)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, false, false)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, false, false)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, false, false)).to.eql(
null);
null
);
});
});
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3, 4],
[5, 6, 7, 8],
],
[
[9, 10, 11, 12],
[13, 14, 15, 16],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2, 3, 4],
[5, 6, 7, 8],
],
[
[9, 10, 11, 12],
[13, 14, 15, 16],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 13, 14]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(4);
});
});
describe('#scale()', function() {
it('scales a multi-linestring', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
describe('#scale()', function () {
it('scales a multi-linestring', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-100, -200], [100, 200]], [[50, -100], [-50, 100]]]);
expect(coordinates).to.eql([
[
[-100, -200],
[100, 200],
],
[
[50, -100],
[-50, 100],
],
]);
});
it('accepts sx and sy', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
it('accepts sx and sy', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-20, -60], [20, 60]], [[10, -30], [-10, 30]]]);
expect(coordinates).to.eql([
[
[-20, -60],
[20, 60],
],
[
[10, -30],
[-10, 30],
],
]);
});
it('accepts an anchor', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
it('accepts an anchor', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(3, 2, [10, 20]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-50, -60], [10, 20]], [[-5, -40], [-35, 0]]]);
expect(coordinates).to.eql([
[
[-50, -60],
[10, 20],
],
[
[-5, -40],
[-35, 0],
],
]);
});
});
describe('#setLineStrings', function() {
it('sets the line strings', function() {
const lineString1 = new LineString([[1, 2], [3, 4]]);
const lineString2 = new LineString([[5, 6], [7, 8]]);
describe('#setLineStrings', function () {
it('sets the line strings', function () {
const lineString1 = new LineString([
[1, 2],
[3, 4],
]);
const lineString2 = new LineString([
[5, 6],
[7, 8],
]);
const multiLineString = new MultiLineString([lineString1, lineString2]);
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]);
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
]);
expect(multiLineString.getEnds()).to.eql([4, 8]);
const coordinates = multiLineString.getCoordinates();
expect(coordinates[0]).to.eql(lineString1.getCoordinates());
@@ -355,15 +628,22 @@ describe('ol.geom.MultiLineString', function() {
});
});
describe('#containsXY()', function() {
describe('#containsXY()', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[-1, -1, 9], [2, 2, 12]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3],
[4, 5, 6],
],
[
[-1, -1, 9],
[2, 2, 12],
],
]);
});
it('does contain XY', function() {
it('does contain XY', function () {
expect(multiLineString.containsXY(1, 2)).to.be(true);
expect(multiLineString.containsXY(4, 5)).to.be(true);
expect(multiLineString.containsXY(3, 4)).to.be(true);
@@ -373,12 +653,10 @@ describe('ol.geom.MultiLineString', function() {
expect(multiLineString.containsXY(0, 0)).to.be(true);
});
it('does not contain XY', function() {
it('does not contain XY', function () {
expect(multiLineString.containsXY(1, 3)).to.be(false);
expect(multiLineString.containsXY(2, 11)).to.be(false);
expect(multiLineString.containsXY(-2, 3)).to.be(false);
});
});
});