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:
@@ -1,42 +1,33 @@
|
||||
import RBush from '../../../../src/ol/structs/RBush.js';
|
||||
|
||||
|
||||
describe('ol.structs.RBush', function() {
|
||||
|
||||
describe('ol.structs.RBush', function () {
|
||||
let rBush;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
rBush = new RBush();
|
||||
});
|
||||
|
||||
describe('when empty', function() {
|
||||
|
||||
describe('#getAll', function() {
|
||||
|
||||
it('returns the expected number of objects', function() {
|
||||
describe('when empty', function () {
|
||||
describe('#getAll', function () {
|
||||
it('returns the expected number of objects', function () {
|
||||
expect(rBush.getAll()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns true', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns true', function () {
|
||||
expect(rBush.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a single object', function() {
|
||||
|
||||
describe('with a single object', function () {
|
||||
let obj;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
obj = {};
|
||||
rBush.insert([0, 0, 1, 1], obj);
|
||||
});
|
||||
|
||||
it('can update the object', function() {
|
||||
it('can update the object', function () {
|
||||
expect(rBush.getInExtent([0, 0, 1, 1])).to.eql([obj]);
|
||||
rBush.update([2, 2, 3, 3], obj);
|
||||
expect(rBush.getInExtent([0, 0, 1, 1])).to.be.empty();
|
||||
@@ -44,20 +35,18 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getInExtent([2, 2, 3, 3])).to.eql([obj]);
|
||||
});
|
||||
|
||||
it('don\'t throws an exception if the extent is not modified', function() {
|
||||
expect(function() {
|
||||
rBush.forEach(function(value) {
|
||||
it("don't throws an exception if the extent is not modified", function () {
|
||||
expect(function () {
|
||||
rBush.forEach(function (value) {
|
||||
rBush.update([0, 0, 1, 1], obj);
|
||||
});
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a few objects', function() {
|
||||
|
||||
describe('with a few objects', function () {
|
||||
let objs;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
objs = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
|
||||
rBush.insert([0, 0, 1, 1], objs[0]);
|
||||
rBush.insert([1, 1, 4, 4], objs[1]);
|
||||
@@ -72,30 +61,27 @@ describe('ol.structs.RBush', function() {
|
||||
rBush.insert([-3, -3, -2, -2], objs[10]);
|
||||
});
|
||||
|
||||
describe('#forEach', function() {
|
||||
|
||||
it('called for all the objects', function() {
|
||||
describe('#forEach', function () {
|
||||
it('called for all the objects', function () {
|
||||
let i = 0;
|
||||
rBush.forEach(function() {
|
||||
rBush.forEach(function () {
|
||||
++i;
|
||||
});
|
||||
expect(i).to.be(objs.length);
|
||||
});
|
||||
|
||||
it('stops when the function returns true', function() {
|
||||
it('stops when the function returns true', function () {
|
||||
let i = 0;
|
||||
const result = rBush.forEach(function() {
|
||||
const result = rBush.forEach(function () {
|
||||
return ++i >= 4;
|
||||
});
|
||||
expect(i).to.be(4);
|
||||
expect(result).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getInExtent', function() {
|
||||
|
||||
it('returns the expected objects', function() {
|
||||
describe('#getInExtent', function () {
|
||||
it('returns the expected objects', function () {
|
||||
let result;
|
||||
result = rBush.getInExtent([2, 2, 3, 3]);
|
||||
expect(result).to.contain(objs[1]);
|
||||
@@ -109,23 +95,19 @@ describe('ol.structs.RBush', function() {
|
||||
expect(result.length).to.be(4);
|
||||
});
|
||||
|
||||
it('returns an empty array when given a disjoint extent', function() {
|
||||
it('returns an empty array when given a disjoint extent', function () {
|
||||
expect(rBush.getInExtent([5, 5, 6, 6]).length).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns false', function () {
|
||||
expect(rBush.isEmpty()).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#remove', function() {
|
||||
|
||||
it('can remove each object', function() {
|
||||
describe('#remove', function () {
|
||||
it('can remove each object', function () {
|
||||
let i, ii;
|
||||
for (i = 0, ii = objs.length; i < ii; ++i) {
|
||||
expect(rBush.getAll()).to.contain(objs[i]);
|
||||
@@ -133,15 +115,12 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getAll()).not.to.contain(objs[i]);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with 100 objects', function() {
|
||||
|
||||
describe('with 100 objects', function () {
|
||||
let extents, objs;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
extents = [];
|
||||
objs = [];
|
||||
let i;
|
||||
@@ -152,28 +131,23 @@ describe('ol.structs.RBush', function() {
|
||||
}
|
||||
});
|
||||
|
||||
describe('#getInExtent', function() {
|
||||
|
||||
it('returns the expected objects', function() {
|
||||
describe('#getInExtent', function () {
|
||||
it('returns the expected objects', function () {
|
||||
let i, ii;
|
||||
for (i = 0, ii = objs.length; i < ii; ++i) {
|
||||
expect(rBush.getInExtent(extents[i])).to.eql([objs[i]]);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns false', function () {
|
||||
expect(rBush.isEmpty()).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#remove', function() {
|
||||
|
||||
it('can remove each object in turn', function() {
|
||||
describe('#remove', function () {
|
||||
it('can remove each object in turn', function () {
|
||||
let i, ii;
|
||||
for (i = 0, ii = objs.length; i < ii; ++i) {
|
||||
expect(rBush.getInExtent(extents[i])).to.eql([objs[i]]);
|
||||
@@ -184,7 +158,7 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
it('can remove objects in random order', function() {
|
||||
it('can remove objects in random order', function () {
|
||||
let i, ii, j;
|
||||
// http://en.wikipedia.org/wiki/Random_permutation
|
||||
const indexes = [];
|
||||
@@ -202,45 +176,42 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getAll()).to.be.empty();
|
||||
expect(rBush.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with 1000 objects', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
describe('with 1000 objects', function () {
|
||||
beforeEach(function () {
|
||||
let i;
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
const min = [Math.random() * 10000, Math.random() * 10000];
|
||||
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
|
||||
const max = [
|
||||
min[0] + Math.random() * 500,
|
||||
min[1] + Math.random() * 500,
|
||||
];
|
||||
const extent = [min[0], min[1], max[0], max[1]];
|
||||
rBush.insert(extent, {id: i});
|
||||
}
|
||||
});
|
||||
|
||||
describe('#getAll', function() {
|
||||
|
||||
it('returns the expected number of objects', function() {
|
||||
describe('#getAll', function () {
|
||||
it('returns the expected number of objects', function () {
|
||||
expect(rBush.getAll().length).to.be(1000);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getInExtent', function() {
|
||||
|
||||
it('returns the expected number of objects', function() {
|
||||
describe('#getInExtent', function () {
|
||||
it('returns the expected number of objects', function () {
|
||||
expect(rBush.getInExtent([0, 0, 10600, 10600]).length).to.be(1000);
|
||||
});
|
||||
|
||||
it('can perform 1000 in-extent searches', function() {
|
||||
it('can perform 1000 in-extent searches', function () {
|
||||
let n = 0;
|
||||
let i;
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
const min = [Math.random() * 10000, Math.random() * 10000];
|
||||
const max = [
|
||||
min[0] + Math.random() * 500,
|
||||
min[1] + Math.random() * 500
|
||||
min[1] + Math.random() * 500,
|
||||
];
|
||||
const extent = [min[0], min[1], max[0], max[1]];
|
||||
n += rBush.getInExtent(extent).length;
|
||||
@@ -248,46 +219,49 @@ describe('ol.structs.RBush', function() {
|
||||
expect(n).not.to.be(0);
|
||||
});
|
||||
|
||||
it('can perform 1000 out-of-extent searches', function() {
|
||||
it('can perform 1000 out-of-extent searches', function () {
|
||||
let n = 0;
|
||||
let i;
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
const min = [-(Math.random() * 10000 + 501), -(Math.random() * 10000 + 501)];
|
||||
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
|
||||
const min = [
|
||||
-(Math.random() * 10000 + 501),
|
||||
-(Math.random() * 10000 + 501),
|
||||
];
|
||||
const max = [
|
||||
min[0] + Math.random() * 500,
|
||||
min[1] + Math.random() * 500,
|
||||
];
|
||||
const extent = [min[0], min[1], max[0], max[1]];
|
||||
n += rBush.getInExtent(extent).length;
|
||||
}
|
||||
expect(n).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#insert', function() {
|
||||
|
||||
it('can insert another 1000 objects', function() {
|
||||
describe('#insert', function () {
|
||||
it('can insert another 1000 objects', function () {
|
||||
let i;
|
||||
for (i = 1000; i < 2000; ++i) {
|
||||
const min = [Math.random() * 10000, Math.random() * 10000];
|
||||
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
|
||||
const max = [
|
||||
min[0] + Math.random() * 500,
|
||||
min[1] + Math.random() * 500,
|
||||
];
|
||||
const extent = [min[0], min[1], max[0], max[1]];
|
||||
rBush.insert(extent, {id: i});
|
||||
}
|
||||
expect(rBush.getInExtent([0, 0, 10600, 10600]).length).to.be(2000);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns false', function () {
|
||||
expect(rBush.isEmpty()).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#remove', function() {
|
||||
|
||||
it('can remove all 1000 objects', function() {
|
||||
describe('#remove', function () {
|
||||
it('can remove all 1000 objects', function () {
|
||||
const objs = rBush.getAll();
|
||||
let i, value;
|
||||
for (i = objs.length - 1; i >= 0; --i) {
|
||||
@@ -296,24 +270,19 @@ describe('ol.structs.RBush', function() {
|
||||
}
|
||||
expect(rBush.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getExtent', function() {
|
||||
|
||||
it('gets the extent', function() {
|
||||
describe('#getExtent', function () {
|
||||
it('gets the extent', function () {
|
||||
const obj = {};
|
||||
rBush.insert([0, 0, 1, 1], obj);
|
||||
expect(rBush.getExtent()).to.eql([0, 0, 1, 1]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#concat', function() {
|
||||
|
||||
it('concatenates two RBush objects', function() {
|
||||
describe('#concat', function () {
|
||||
it('concatenates two RBush objects', function () {
|
||||
const obj1 = {};
|
||||
const obj2 = {};
|
||||
const rBush2 = new RBush();
|
||||
@@ -324,7 +293,7 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getAll().length).to.be(2);
|
||||
});
|
||||
|
||||
it('preserves the concatenated object\'s references', function() {
|
||||
it("preserves the concatenated object's references", function () {
|
||||
const obj1 = {};
|
||||
const obj2 = {};
|
||||
const rBush2 = new RBush();
|
||||
@@ -335,5 +304,4 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getExtent()).to.eql([0, 0, 3, 3]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user