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,11 +1,11 @@
import Event from '../../../src/ol/events/Event.js';
import Map from '../../../src/ol/Map.js';
import MapBrowserEventHandler from '../../../src/ol/MapBrowserEventHandler.js';
import {listen} from '../../../src/ol/events.js';
import {DEVICE_PIXEL_RATIO} from '../../../src/ol/has.js';
import Event from '../../../src/ol/events/Event.js';
import {listen} from '../../../src/ol/events.js';
describe('ol/MapBrowserEventHandler', function() {
describe('#emulateClick_', function() {
describe('ol/MapBrowserEventHandler', function () {
describe('#emulateClick_', function () {
let clock;
let handler;
let clickSpy;
@@ -13,12 +13,14 @@ describe('ol/MapBrowserEventHandler', function() {
let dblclickSpy;
let target;
beforeEach(function() {
beforeEach(function () {
clock = sinon.useFakeTimers();
target = document.createElement('div');
handler = new MapBrowserEventHandler(new Map({
target: target
}));
handler = new MapBrowserEventHandler(
new Map({
target: target,
})
);
clickSpy = sinon.spy();
listen(handler, 'click', clickSpy);
@@ -28,24 +30,22 @@ describe('ol/MapBrowserEventHandler', function() {
dblclickSpy = sinon.spy();
listen(handler, 'dblclick', dblclickSpy);
});
afterEach(function() {
afterEach(function () {
clock.restore();
});
it('emulates click', function() {
it('emulates click', function () {
const event = new Event();
event.type = 'pointerdown';
event.target = target,
event.clientX = 0;
(event.target = target), (event.clientX = 0);
event.clientY = 0;
handler.emulateClick_(event);
expect(clickSpy.called).to.be.ok();
});
it('emulates singleclick', function() {
it('emulates singleclick', function () {
const event = new Event();
event.type = 'pointerdown';
event.target = target;
@@ -64,7 +64,7 @@ describe('ol/MapBrowserEventHandler', function() {
expect(dblclickSpy.called).to.not.be.ok();
});
it('emulates dblclick', function() {
it('emulates dblclick', function () {
const event = new Event();
event.type = 'pointerdown';
event.target = target;
@@ -82,33 +82,30 @@ describe('ol/MapBrowserEventHandler', function() {
expect(singleclickSpy.called).to.not.be.ok();
expect(dblclickSpy.calledOnce).to.be.ok();
});
});
describe('#down_', function() {
describe('#down_', function () {
let handler;
beforeEach(function() {
beforeEach(function () {
handler = new MapBrowserEventHandler(new Map({}));
});
it('is null if no "down" type event has been handled', function() {
it('is null if no "down" type event has been handled', function () {
expect(handler.down_).to.be(null);
});
it('is an event after handlePointerDown_ has been called', function() {
it('is an event after handlePointerDown_ has been called', function () {
const event = new Event('pointerdown');
handler.handlePointerDown_(event);
expect(handler.down_).to.be(event);
});
});
describe('#isMoving_', function() {
describe('#isMoving_', function () {
let defaultHandler;
let moveToleranceHandler;
let pointerdownAt0;
beforeEach(function() {
beforeEach(function () {
defaultHandler = new MapBrowserEventHandler(new Map({}));
moveToleranceHandler = new MapBrowserEventHandler(new Map({}), 8);
pointerdownAt0 = new Event();
@@ -119,7 +116,7 @@ describe('ol/MapBrowserEventHandler', function() {
moveToleranceHandler.handlePointerDown_(pointerdownAt0);
});
it('is not moving if distance is 0', function() {
it('is not moving if distance is 0', function () {
pointerdownAt0 = new Event();
pointerdownAt0.type = 'pointerdown';
pointerdownAt0.clientX = 0;
@@ -127,7 +124,7 @@ describe('ol/MapBrowserEventHandler', function() {
expect(defaultHandler.isMoving_(pointerdownAt0)).to.be(false);
});
it('is moving if distance is 2', function() {
it('is moving if distance is 2', function () {
const pointerdownAt2 = new Event();
pointerdownAt2.type = 'pointerdown';
pointerdownAt2.clientX = DEVICE_PIXEL_RATIO + 1;
@@ -135,7 +132,7 @@ describe('ol/MapBrowserEventHandler', function() {
expect(defaultHandler.isMoving_(pointerdownAt2)).to.be(true);
});
it('is moving with negative distance', function() {
it('is moving with negative distance', function () {
const pointerdownAt2 = new Event();
pointerdownAt2.type = 'pointerdown';
pointerdownAt2.clientX = -(DEVICE_PIXEL_RATIO + 1);
@@ -143,7 +140,7 @@ describe('ol/MapBrowserEventHandler', function() {
expect(defaultHandler.isMoving_(pointerdownAt2)).to.be(true);
});
it('is not moving if distance is less than move tolerance', function() {
it('is not moving if distance is less than move tolerance', function () {
const pointerdownAt2 = new Event();
pointerdownAt2.type = 'pointerdown';
pointerdownAt2.clientX = DEVICE_PIXEL_RATIO + 1;
@@ -151,19 +148,19 @@ describe('ol/MapBrowserEventHandler', function() {
expect(moveToleranceHandler.isMoving_(pointerdownAt2)).to.be(false);
});
it('is moving if distance is greater than move tolerance', function() {
it('is moving if distance is greater than move tolerance', function () {
const pointerdownAt9 = new Event();
pointerdownAt9.type = 'pointerdown';
pointerdownAt9.clientX = (DEVICE_PIXEL_RATIO * 8) + 1;
pointerdownAt9.clientY = (DEVICE_PIXEL_RATIO * 8) + 1;
pointerdownAt9.clientX = DEVICE_PIXEL_RATIO * 8 + 1;
pointerdownAt9.clientY = DEVICE_PIXEL_RATIO * 8 + 1;
expect(moveToleranceHandler.isMoving_(pointerdownAt9)).to.be(true);
});
it('is moving when moving back close to the down pixel', function() {
it('is moving when moving back close to the down pixel', function () {
const pointermoveAt9 = new Event();
pointermoveAt9.type = 'pointermove';
pointermoveAt9.clientX = (DEVICE_PIXEL_RATIO * 8) + 1;
pointermoveAt9.clientY = (DEVICE_PIXEL_RATIO * 8) + 1;
pointermoveAt9.clientX = DEVICE_PIXEL_RATIO * 8 + 1;
pointermoveAt9.clientY = DEVICE_PIXEL_RATIO * 8 + 1;
moveToleranceHandler.handlePointerMove_(pointermoveAt9);
expect(moveToleranceHandler.isMoving_(pointermoveAt9)).to.be(true);
const pointermoveAt2 = new Event();
@@ -175,17 +172,17 @@ describe('ol/MapBrowserEventHandler', function() {
});
});
describe('handleTouchMove_', function() {
describe('handleTouchMove_', function () {
let handler;
beforeEach(function() {
beforeEach(function () {
handler = new MapBrowserEventHandler(new Map({}));
});
it('prevents default on touchmove event', function() {
it('prevents default on touchmove event', function () {
handler.originalPointerMoveEvent_ = {
defaultPrevented: true
defaultPrevented: true,
};
const event = {
preventDefault: sinon.spy()
preventDefault: sinon.spy(),
};
handler.handleTouchMove_(event);
expect(event.preventDefault.callCount).to.be(1);