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,36 +1,35 @@
|
||||
import {listen, listenOnce, unlistenByKey} from '../../../src/ol/events.js';
|
||||
import EventTarget from '../../../src/ol/events/Target.js';
|
||||
import {listen, listenOnce, unlistenByKey} from '../../../src/ol/events.js';
|
||||
|
||||
describe('ol.events', function() {
|
||||
describe('ol.events', function () {
|
||||
let add, target;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
target = new EventTarget();
|
||||
add = sinon.spy(target, 'addEventListener');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
target.addEventListener.restore();
|
||||
});
|
||||
|
||||
|
||||
describe('listen()', function() {
|
||||
it('calls addEventListener on the target', function() {
|
||||
listen(target, 'foo', function() {});
|
||||
describe('listen()', function () {
|
||||
it('calls addEventListener on the target', function () {
|
||||
listen(target, 'foo', function () {});
|
||||
expect(add.callCount).to.be(1);
|
||||
});
|
||||
it('returns a key', function() {
|
||||
const key = listen(target, 'foo', function() {});
|
||||
it('returns a key', function () {
|
||||
const key = listen(target, 'foo', function () {});
|
||||
expect(key).to.be.a(Object);
|
||||
});
|
||||
it('does not add the same listener twice', function() {
|
||||
const listener = function() {};
|
||||
it('does not add the same listener twice', function () {
|
||||
const listener = function () {};
|
||||
listen(target, 'foo', listener);
|
||||
listen(target, 'foo', listener);
|
||||
expect(target.listeners_['foo'].length).to.be(1);
|
||||
});
|
||||
it('only treats listeners as same when all args are equal', function() {
|
||||
const listener = function() {};
|
||||
it('only treats listeners as same when all args are equal', function () {
|
||||
const listener = function () {};
|
||||
listen(target, 'foo', listener, {});
|
||||
listen(target, 'foo', listener, {});
|
||||
listen(target, 'foo', listener, undefined);
|
||||
@@ -38,8 +37,8 @@ describe('ol.events', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('listenOnce()', function() {
|
||||
it('creates a one-off listener', function() {
|
||||
describe('listenOnce()', function () {
|
||||
it('creates a one-off listener', function () {
|
||||
const target = new EventTarget();
|
||||
const listener = sinon.spy();
|
||||
listenOnce(target, 'foo', listener);
|
||||
@@ -48,7 +47,7 @@ describe('ol.events', function() {
|
||||
target.dispatchEvent('foo');
|
||||
expect(listener.callCount).to.be(1);
|
||||
});
|
||||
it('Adds the same listener twice', function() {
|
||||
it('Adds the same listener twice', function () {
|
||||
const listener = sinon.spy();
|
||||
listenOnce(target, 'foo', listener);
|
||||
listenOnce(target, 'foo', listener);
|
||||
@@ -59,40 +58,37 @@ describe('ol.events', function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('unlistenByKey()', function() {
|
||||
it('unregisters previously registered listeners', function() {
|
||||
const key = listen(target, 'foo', function() {});
|
||||
describe('unlistenByKey()', function () {
|
||||
it('unregisters previously registered listeners', function () {
|
||||
const key = listen(target, 'foo', function () {});
|
||||
unlistenByKey(key);
|
||||
expect(target.listeners_['foo']).to.be(undefined);
|
||||
});
|
||||
it('works with multiple types', function() {
|
||||
const key = listen(target, ['foo', 'bar'], function() {});
|
||||
it('works with multiple types', function () {
|
||||
const key = listen(target, ['foo', 'bar'], function () {});
|
||||
unlistenByKey(key);
|
||||
expect(target.listeners_['foo']).to.be(undefined);
|
||||
expect(target.listeners_['bar']).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Listener keys', function() {
|
||||
it('does not register duplicated listeners', function() {
|
||||
describe('Listener keys', function () {
|
||||
it('does not register duplicated listeners', function () {
|
||||
const target = new EventTarget();
|
||||
const listener = function() {};
|
||||
const listener = function () {};
|
||||
const key1 = listen(target, 'foo', listener);
|
||||
expect(target.listeners_['foo']).to.eql([listener]);
|
||||
const key2 = listen(target, 'foo', listener);
|
||||
expect(target.listeners_['foo']).to.eql([listener]);
|
||||
expect(key1.listener).to.equal(key2.listener);
|
||||
});
|
||||
it('registers multiple listeners if this object is different', function() {
|
||||
it('registers multiple listeners if this object is different', function () {
|
||||
const target = new EventTarget();
|
||||
const listener = function() {};
|
||||
const listener = function () {};
|
||||
const key1 = listen(target, 'foo', listener, {});
|
||||
const key2 = listen(target, 'foo', listener, {});
|
||||
expect(key1.listener).to.not.equal(key2.listener);
|
||||
expect(target.listeners_['foo']).to.eql([key1.listener, key2.listener]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user