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,48 +1,49 @@
|
||||
import Event, {preventDefault, stopPropagation} from '../../../../src/ol/events/Event.js';
|
||||
import Event, {
|
||||
preventDefault,
|
||||
stopPropagation,
|
||||
} from '../../../../src/ol/events/Event.js';
|
||||
|
||||
describe('ol.events.Event', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('takes a type as argument', function() {
|
||||
describe('ol.events.Event', function () {
|
||||
describe('constructor', function () {
|
||||
it('takes a type as argument', function () {
|
||||
const event = new Event('foo');
|
||||
expect(event.type).to.be('foo');
|
||||
});
|
||||
it('does not set the propagationStopped flag', function() {
|
||||
it('does not set the propagationStopped flag', function () {
|
||||
const event = new Event('foo');
|
||||
expect(event.propagationStopped).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#preventDefault', function() {
|
||||
it('sets the propagationStopped flag', function() {
|
||||
describe('#preventDefault', function () {
|
||||
it('sets the propagationStopped flag', function () {
|
||||
const event = new Event('foo');
|
||||
event.preventDefault();
|
||||
expect(event.propagationStopped).to.be(true);
|
||||
});
|
||||
it('does the same as #stopPropagation', function() {
|
||||
it('does the same as #stopPropagation', function () {
|
||||
const event = new Event('foo');
|
||||
expect(event.stopPropagation()).to.equal(event.preventDefault());
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.events.Event.preventDefault', function() {
|
||||
it('calls preventDefault on the event object', function() {
|
||||
describe('ol.events.Event.preventDefault', function () {
|
||||
it('calls preventDefault on the event object', function () {
|
||||
const event = {
|
||||
preventDefault: sinon.spy()
|
||||
preventDefault: sinon.spy(),
|
||||
};
|
||||
preventDefault(event);
|
||||
expect(event.preventDefault.called).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.events.Event.stopPropagation', function() {
|
||||
it('calls preventDefault on the event object', function() {
|
||||
describe('ol.events.Event.stopPropagation', function () {
|
||||
it('calls preventDefault on the event object', function () {
|
||||
const event = {
|
||||
stopPropagation: sinon.spy()
|
||||
stopPropagation: sinon.spy(),
|
||||
};
|
||||
stopPropagation(event);
|
||||
expect(event.stopPropagation.called).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import Disposable from '../../../../src/ol/Disposable.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
import Event from '../../../../src/ol/events/Event.js';
|
||||
import EventTarget from '../../../../src/ol/events/Target.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
|
||||
|
||||
describe('ol.events.EventTarget', function() {
|
||||
describe('ol.events.EventTarget', function () {
|
||||
let called, events, eventTarget, spy1, spy2, spy3;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
called = [];
|
||||
events = [];
|
||||
function spy(evt) {
|
||||
@@ -20,18 +19,18 @@ describe('ol.events.EventTarget', function() {
|
||||
eventTarget = new EventTarget();
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates an instance', function() {
|
||||
describe('constructor', function () {
|
||||
it('creates an instance', function () {
|
||||
expect(eventTarget).to.be.a(EventTarget);
|
||||
expect(eventTarget).to.be.a(Disposable);
|
||||
});
|
||||
it('creates an empty listeners_ object', function() {
|
||||
it('creates an empty listeners_ object', function () {
|
||||
expect(Object.keys(eventTarget.listeners_)).to.have.length(0);
|
||||
});
|
||||
it('accepts a default target', function(done) {
|
||||
it('accepts a default target', function (done) {
|
||||
const defaultTarget = {};
|
||||
const target = new EventTarget(defaultTarget);
|
||||
target.addEventListener('my-event', function(event) {
|
||||
target.addEventListener('my-event', function (event) {
|
||||
expect(event.target).to.eql(defaultTarget);
|
||||
done();
|
||||
});
|
||||
@@ -39,21 +38,21 @@ describe('ol.events.EventTarget', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#hasListener', function() {
|
||||
it('reports any listeners when called without argument', function() {
|
||||
describe('#hasListener', function () {
|
||||
it('reports any listeners when called without argument', function () {
|
||||
expect(eventTarget.hasListener()).to.be(false);
|
||||
eventTarget.listeners_['foo'] = [function() {}];
|
||||
eventTarget.listeners_['foo'] = [function () {}];
|
||||
expect(eventTarget.hasListener()).to.be(true);
|
||||
});
|
||||
it('reports listeners for the type passed as argument', function() {
|
||||
eventTarget.listeners_['foo'] = [function() {}];
|
||||
it('reports listeners for the type passed as argument', function () {
|
||||
eventTarget.listeners_['foo'] = [function () {}];
|
||||
expect(eventTarget.hasListener('foo')).to.be(true);
|
||||
expect(eventTarget.hasListener('bar')).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addEventListener()', function() {
|
||||
it('has listeners for each registered type', function() {
|
||||
describe('#addEventListener()', function () {
|
||||
it('has listeners for each registered type', function () {
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
eventTarget.addEventListener('bar', spy2);
|
||||
expect(eventTarget.hasListener('foo')).to.be(true);
|
||||
@@ -61,19 +60,19 @@ describe('ol.events.EventTarget', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeEventListener()', function() {
|
||||
it('keeps the listeners registry clean', function() {
|
||||
describe('#removeEventListener()', function () {
|
||||
it('keeps the listeners registry clean', function () {
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
eventTarget.removeEventListener('foo', spy1);
|
||||
expect(eventTarget.hasListener('foo')).to.be(false);
|
||||
});
|
||||
it('removes added listeners from the listeners registry', function() {
|
||||
it('removes added listeners from the listeners registry', function () {
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
eventTarget.addEventListener('foo', spy2);
|
||||
eventTarget.removeEventListener('foo', spy1, false);
|
||||
expect(eventTarget.listeners_['foo']).to.have.length(1);
|
||||
});
|
||||
it('does not remove listeners when the specified listener is not found', function() {
|
||||
it('does not remove listeners when the specified listener is not found', function () {
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
eventTarget.addEventListener('foo', spy2);
|
||||
eventTarget.removeEventListener('foo', undefined);
|
||||
@@ -83,25 +82,29 @@ describe('ol.events.EventTarget', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#dispatchEvent()', function() {
|
||||
it('calls listeners in the correct order', function() {
|
||||
describe('#dispatchEvent()', function () {
|
||||
it('calls listeners in the correct order', function () {
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
eventTarget.addEventListener('foo', spy2);
|
||||
eventTarget.dispatchEvent('foo');
|
||||
expect(called).to.eql([1, 2]);
|
||||
});
|
||||
it('stops propagation when listeners return false', function() {
|
||||
it('stops propagation when listeners return false', function () {
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
eventTarget.addEventListener('foo', function(evt) {
|
||||
spy2();
|
||||
return false;
|
||||
}, false);
|
||||
eventTarget.addEventListener(
|
||||
'foo',
|
||||
function (evt) {
|
||||
spy2();
|
||||
return false;
|
||||
},
|
||||
false
|
||||
);
|
||||
eventTarget.addEventListener('foo', spy3);
|
||||
eventTarget.dispatchEvent('foo');
|
||||
expect(called).to.eql([1, 2]);
|
||||
});
|
||||
it('stops propagation when listeners call preventDefault()', function() {
|
||||
eventTarget.addEventListener('foo', function(evt) {
|
||||
it('stops propagation when listeners call preventDefault()', function () {
|
||||
eventTarget.addEventListener('foo', function (evt) {
|
||||
spy2();
|
||||
evt.preventDefault();
|
||||
});
|
||||
@@ -109,38 +112,38 @@ describe('ol.events.EventTarget', function() {
|
||||
eventTarget.dispatchEvent('foo');
|
||||
expect(called).to.eql([2]);
|
||||
});
|
||||
it('passes a default ol.events.Event object to listeners', function() {
|
||||
it('passes a default ol.events.Event object to listeners', function () {
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
eventTarget.dispatchEvent('foo');
|
||||
expect(events[0]).to.be.a(Event);
|
||||
expect(events[0].type).to.be('foo');
|
||||
expect(events[0].target).to.equal(eventTarget);
|
||||
});
|
||||
it('passes a custom event object with target to listeners', function() {
|
||||
it('passes a custom event object with target to listeners', function () {
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
const event = {
|
||||
type: 'foo'
|
||||
type: 'foo',
|
||||
};
|
||||
eventTarget.dispatchEvent(event);
|
||||
expect(events[0]).to.equal(event);
|
||||
expect(events[0].target).to.equal(eventTarget);
|
||||
});
|
||||
it('is safe to remove listeners in listeners', function() {
|
||||
it('is safe to remove listeners in listeners', function () {
|
||||
eventTarget.addEventListener('foo', spy3);
|
||||
eventTarget.addEventListener('foo', function() {
|
||||
eventTarget.addEventListener('foo', function () {
|
||||
eventTarget.removeEventListener('foo', spy1);
|
||||
eventTarget.removeEventListener('foo', spy2);
|
||||
eventTarget.removeEventListener('foo', spy3);
|
||||
});
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
eventTarget.addEventListener('foo', spy2);
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
eventTarget.dispatchEvent('foo');
|
||||
}).not.to.throwException();
|
||||
expect(called).to.eql([3]);
|
||||
expect(eventTarget.listeners_['foo']).to.have.length(1);
|
||||
});
|
||||
it('is safe to do weird things in listeners', function() {
|
||||
it('is safe to do weird things in listeners', function () {
|
||||
eventTarget.addEventListener('foo', spy2);
|
||||
eventTarget.addEventListener('foo', function weird(evt) {
|
||||
eventTarget.removeEventListener('foo', weird);
|
||||
@@ -151,7 +154,7 @@ describe('ol.events.EventTarget', function() {
|
||||
evt.preventDefault();
|
||||
});
|
||||
eventTarget.addEventListener('foo', spy1);
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
eventTarget.dispatchEvent('foo');
|
||||
}).not.to.throwException();
|
||||
expect(called).to.eql([2, 2]);
|
||||
@@ -159,8 +162,8 @@ describe('ol.events.EventTarget', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#dispose()', function() {
|
||||
it('cleans up foreign references', function() {
|
||||
describe('#dispose()', function () {
|
||||
it('cleans up foreign references', function () {
|
||||
listen(eventTarget, 'foo', spy1, document);
|
||||
expect(eventTarget.hasListener('foo')).to.be(true);
|
||||
eventTarget.dispose();
|
||||
|
||||
Reference in New Issue
Block a user