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,25 +1,24 @@
import {listen} from '../../../src/ol/events.js';
import Collection from '../../../src/ol/Collection.js';
import CollectionEventType from '../../../src/ol/CollectionEventType.js';
import {listen} from '../../../src/ol/events.js';
describe('ol.collection', function() {
describe('ol.collection', function () {
let collection;
beforeEach(function() {
beforeEach(function () {
collection = new Collection();
});
describe('create an empty collection', function() {
it('creates an empty collection', function() {
describe('create an empty collection', function () {
it('creates an empty collection', function () {
expect(collection.getLength()).to.eql(0);
expect(collection.getArray()).to.be.empty();
expect(collection.item(0)).to.be(undefined);
});
});
describe('create a collection from an array', function() {
it('creates the expected collection', function() {
describe('create a collection from an array', function () {
it('creates the expected collection', function () {
const array = [0, 1, 2];
const collection = new Collection(array);
expect(collection.item(0)).to.eql(0);
@@ -28,16 +27,16 @@ describe('ol.collection', function() {
});
});
describe('push to a collection', function() {
it('adds elements to the collection', function() {
describe('push to a collection', function () {
it('adds elements to the collection', function () {
const length = collection.push(1);
expect(collection.getLength()).to.eql(length);
expect(collection.getArray()).to.eql([1]);
expect(collection.item(0)).to.eql(1);
});
it('returns the correct new length of the collection', function() {
it('returns the correct new length of the collection', function () {
let length;
listen(collection, 'add', function(event) {
listen(collection, 'add', function (event) {
if (event.element === 'remove_me') {
collection.remove(event.element);
}
@@ -49,8 +48,8 @@ describe('ol.collection', function() {
});
});
describe('pop from a collection', function() {
it('removes elements from the collection', function() {
describe('pop from a collection', function () {
it('removes elements from the collection', function () {
collection.push(1);
collection.pop();
expect(collection.getLength()).to.eql(0);
@@ -59,8 +58,8 @@ describe('ol.collection', function() {
});
});
describe('insertAt', function() {
it('inserts elements at the correct location', function() {
describe('insertAt', function () {
it('inserts elements at the correct location', function () {
collection = new Collection([0, 2]);
collection.insertAt(1, 1);
expect(collection.item(0)).to.eql(0);
@@ -69,8 +68,8 @@ describe('ol.collection', function() {
});
});
describe('setAt', function() {
it('sets at the correct location', function() {
describe('setAt', function () {
it('sets at the correct location', function () {
collection.setAt(1, 1);
expect(collection.getLength()).to.eql(2);
expect(collection.item(0)).to.be(undefined);
@@ -78,8 +77,8 @@ describe('ol.collection', function() {
});
});
describe('removeAt', function() {
it('removes elements at the correction', function() {
describe('removeAt', function () {
it('removes elements at the correction', function () {
const collection = new Collection([0, 1, 2]);
collection.removeAt(1);
expect(collection.item(0)).to.eql(0);
@@ -87,19 +86,19 @@ describe('ol.collection', function() {
});
});
describe('forEach', function() {
describe('forEach', function () {
let cb;
beforeEach(function() {
beforeEach(function () {
cb = sinon.spy();
});
describe('on an empty collection', function() {
it('does not call the callback', function() {
describe('on an empty collection', function () {
it('does not call the callback', function () {
collection.forEach(cb);
expect(cb.called).to.be(false);
});
});
describe('on a non-empty collection', function() {
it('does call the callback', function() {
describe('on a non-empty collection', function () {
it('does call the callback', function () {
collection.push(1);
collection.push(2);
collection.forEach(cb);
@@ -108,14 +107,14 @@ describe('ol.collection', function() {
});
});
describe('remove', function() {
it('removes the first matching element', function() {
describe('remove', function () {
it('removes the first matching element', function () {
const collection = new Collection([0, 1, 2]);
expect(collection.remove(1)).to.eql(1);
expect(collection.getArray()).to.eql([0, 2]);
expect(collection.getLength()).to.eql(2);
});
it('fires a remove event', function() {
it('fires a remove event', function () {
const collection = new Collection([0, 1, 2]);
const cb = sinon.spy();
listen(collection, CollectionEventType.REMOVE, cb);
@@ -123,13 +122,13 @@ describe('ol.collection', function() {
expect(cb.called).to.be(true);
expect(cb.lastCall.args[0].element).to.eql(1);
});
it('does not remove more than one matching element', function() {
it('does not remove more than one matching element', function () {
const collection = new Collection([0, 1, 1, 2]);
expect(collection.remove(1)).to.eql(1);
expect(collection.getArray()).to.eql([0, 1, 2]);
expect(collection.getLength()).to.eql(3);
});
it('returns undefined if the element is not found', function() {
it('returns undefined if the element is not found', function () {
const collection = new Collection([0, 1, 2]);
expect(collection.remove(3)).to.be(undefined);
expect(collection.getArray()).to.eql([0, 1, 2]);
@@ -137,15 +136,15 @@ describe('ol.collection', function() {
});
});
describe('setAt and event', function() {
it('does dispatch events', function() {
describe('setAt and event', function () {
it('does dispatch events', function () {
const collection = new Collection(['a', 'b']);
let added, removed, addedIndex, removedIndex;
listen(collection, CollectionEventType.ADD, function(e) {
listen(collection, CollectionEventType.ADD, function (e) {
added = e.element;
addedIndex = e.index;
});
listen(collection, CollectionEventType.REMOVE, function(e) {
listen(collection, CollectionEventType.REMOVE, function (e) {
removed = e.element;
removedIndex = e.index;
});
@@ -157,11 +156,11 @@ describe('ol.collection', function() {
});
});
describe('removeAt and event', function() {
it('does dispatch events', function() {
describe('removeAt and event', function () {
it('does dispatch events', function () {
const collection = new Collection(['a']);
let removed, removedIndex;
listen(collection, CollectionEventType.REMOVE, function(e) {
listen(collection, CollectionEventType.REMOVE, function (e) {
removed = e.element;
removedIndex = e.index;
});
@@ -171,11 +170,11 @@ describe('ol.collection', function() {
});
});
describe('insertAt and event', function() {
it('does dispatch events', function() {
describe('insertAt and event', function () {
it('does dispatch events', function () {
const collection = new Collection([0, 2]);
let added, addedIndex;
listen(collection, CollectionEventType.ADD, function(e) {
listen(collection, CollectionEventType.ADD, function (e) {
added = e.element;
addedIndex = e.index;
});
@@ -185,10 +184,11 @@ describe('ol.collection', function() {
});
});
describe('setAt beyond end', function() {
it('triggers events properly', function() {
const added = [], addedIndexes = [];
listen(collection, CollectionEventType.ADD, function(e) {
describe('setAt beyond end', function () {
it('triggers events properly', function () {
const added = [],
addedIndexes = [];
listen(collection, CollectionEventType.ADD, function (e) {
added.push(e.element);
addedIndexes.push(e.index);
});
@@ -205,41 +205,41 @@ describe('ol.collection', function() {
});
});
describe('change:length event', function() {
describe('change:length event', function () {
let collection, cb;
beforeEach(function() {
beforeEach(function () {
collection = new Collection([0, 1, 2]);
cb = sinon.spy();
listen(collection, 'change:length', cb);
});
describe('insertAt', function() {
it('triggers change:length event', function() {
describe('insertAt', function () {
it('triggers change:length event', function () {
collection.insertAt(2, 3);
expect(cb.called).to.be(true);
});
});
describe('removeAt', function() {
it('triggers change:length event', function() {
describe('removeAt', function () {
it('triggers change:length event', function () {
collection.removeAt(0);
expect(cb.called).to.be(true);
});
});
describe('setAt', function() {
it('does not trigger change:length event', function() {
describe('setAt', function () {
it('does not trigger change:length event', function () {
collection.setAt(1, 1);
expect(cb.called).to.be(false);
});
});
});
describe('add event', function() {
it('triggers add when pushing', function() {
describe('add event', function () {
it('triggers add when pushing', function () {
const collection = new Collection();
let elem, addedIndex;
listen(collection, CollectionEventType.ADD, function(e) {
listen(collection, CollectionEventType.ADD, function (e) {
elem = e.element;
addedIndex = e.index;
});
@@ -249,15 +249,15 @@ describe('ol.collection', function() {
});
});
describe('remove event', function() {
describe('remove event', function () {
let collection, cb1, cb2;
beforeEach(function() {
beforeEach(function () {
collection = new Collection([1]);
cb1 = sinon.spy();
cb2 = sinon.spy();
});
describe('setAt', function() {
it('triggers remove', function() {
describe('setAt', function () {
it('triggers remove', function () {
listen(collection, CollectionEventType.ADD, cb1);
listen(collection, CollectionEventType.REMOVE, cb2);
collection.setAt(0, 2);
@@ -265,8 +265,8 @@ describe('ol.collection', function() {
expect(cb1.lastCall.args[0].element).to.eql(2);
});
});
describe('pop', function() {
it('triggers remove', function() {
describe('pop', function () {
it('triggers remove', function () {
listen(collection, CollectionEventType.REMOVE, cb1);
collection.pop();
expect(cb1.lastCall.args[0].element).to.eql(1);
@@ -274,18 +274,19 @@ describe('ol.collection', function() {
});
});
describe('extending a collection', function() {
it('adds elements to end of the collection', function() {
describe('extending a collection', function () {
it('adds elements to end of the collection', function () {
collection.extend([1, 2]);
expect(collection.getLength()).to.eql(2);
expect(collection.getArray()).to.eql([1, 2]);
expect(collection.item(0)).to.eql(1);
expect(collection.item(1)).to.eql(2);
});
it('fires events', function() {
it('fires events', function () {
const collection = new Collection();
const elems = [], addedIndexes = [];
listen(collection, CollectionEventType.ADD, function(e) {
const elems = [],
addedIndexes = [];
listen(collection, CollectionEventType.ADD, function (e) {
elems.push(e.element);
addedIndexes.push(e.index);
});
@@ -295,74 +296,72 @@ describe('ol.collection', function() {
});
});
describe('unique collection', function() {
it('allows unique items in the constructor', function() {
describe('unique collection', function () {
it('allows unique items in the constructor', function () {
new Collection([{}, {}, {}], {unique: true});
});
it('throws if duplicate items are passed to the constructor', function() {
it('throws if duplicate items are passed to the constructor', function () {
const item = {};
const call = function() {
const call = function () {
new Collection([item, item], {unique: true});
};
expect(call).to.throwException();
});
it('allows unique items to be added via push', function() {
it('allows unique items to be added via push', function () {
const unique = new Collection(undefined, {unique: true});
unique.push({});
unique.push({});
});
it('throws if duplicate items are added via push', function() {
it('throws if duplicate items are added via push', function () {
const unique = new Collection(undefined, {unique: true});
const item = {};
unique.push(item);
const call = function() {
const call = function () {
unique.push(item);
};
expect(call).to.throwException();
});
it('allows unique items to be added via insertAt', function() {
it('allows unique items to be added via insertAt', function () {
const unique = new Collection(undefined, {unique: true});
unique.insertAt(0, {});
unique.insertAt(0, {});
});
it('throws if duplicate items are added via insertAt', function() {
it('throws if duplicate items are added via insertAt', function () {
const unique = new Collection(undefined, {unique: true});
const item = {};
unique.insertAt(0, item);
const call = function() {
const call = function () {
unique.insertAt(0, item);
};
expect(call).to.throwException();
});
it('allows unique items to be added via setAt', function() {
it('allows unique items to be added via setAt', function () {
const unique = new Collection(undefined, {unique: true});
unique.setAt(0, {});
unique.setAt(1, {});
});
it('allows items to be reset via setAt', function() {
it('allows items to be reset via setAt', function () {
const unique = new Collection(undefined, {unique: true});
const item = {};
unique.setAt(0, item);
unique.setAt(0, item);
});
it('throws if duplicate items are added via setAt', function() {
it('throws if duplicate items are added via setAt', function () {
const unique = new Collection(undefined, {unique: true});
const item = {};
unique.setAt(0, item);
const call = function() {
const call = function () {
unique.setAt(1, item);
};
expect(call).to.throwException();
});
});
});