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
-5
View File
@@ -13,12 +13,10 @@
* {@link module:ol/events/Target~Target}.
*/
class BaseEvent {
/**
* @param {string} type Type.
*/
constructor(type) {
/**
* @type {boolean}
*/
@@ -54,10 +52,8 @@ class BaseEvent {
stopPropagation() {
this.propagationStopped = true;
}
}
/**
* @param {Event|import("./Event.js").default} evt Event
*/
@@ -65,7 +61,6 @@ export function stopPropagation(evt) {
evt.stopPropagation();
}
/**
* @param {Event|import("./Event.js").default} evt Event
*/
+1 -1
View File
@@ -35,5 +35,5 @@ export default {
LOAD: 'load',
RESIZE: 'resize',
TOUCHMOVE: 'touchmove',
WHEEL: 'wheel'
WHEEL: 'wheel',
};
+1 -1
View File
@@ -10,5 +10,5 @@ export default {
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40
DOWN: 40,
};
+10 -12
View File
@@ -2,16 +2,14 @@
* @module ol/events/Target
*/
import Disposable from '../Disposable.js';
import {VOID} from '../functions.js';
import Event from './Event.js';
import {VOID} from '../functions.js';
import {clear} from '../obj.js';
/**
* @typedef {EventTarget|Target} EventTargetLike
*/
/**
* @classdesc
* A simplified implementation of the W3C DOM Level 2 EventTarget interface.
@@ -28,12 +26,10 @@ import {clear} from '../obj.js';
* returns false.
*/
class Target extends Disposable {
/**
* @param {*=} opt_target Default event target for dispatched events.
*/
constructor(opt_target) {
super();
/**
@@ -59,7 +55,6 @@ class Target extends Disposable {
* @type {!Object<string, Array<import("../events.js").Listener>>}
*/
this.listeners_ = {};
}
/**
@@ -107,9 +102,13 @@ class Target extends Disposable {
++this.dispatching_[type];
for (let i = 0, ii = listeners.length; i < ii; ++i) {
if ('handleEvent' in listeners[i]) {
propagate = /** @type {import("../events.js").ListenerObject} */ (listeners[i]).handleEvent(evt);
propagate = /** @type {import("../events.js").ListenerObject} */ (listeners[
i
]).handleEvent(evt);
} else {
propagate = /** @type {import("../events.js").ListenerFunction} */ (listeners[i]).call(this, evt);
propagate = /** @type {import("../events.js").ListenerFunction} */ (listeners[
i
]).call(this, evt);
}
if (propagate === false || evt.propagationStopped) {
propagate = false;
@@ -153,9 +152,9 @@ class Target extends Disposable {
* @return {boolean} Has listeners.
*/
hasListener(opt_type) {
return opt_type ?
opt_type in this.listeners_ :
Object.keys(this.listeners_).length > 0;
return opt_type
? opt_type in this.listeners_
: Object.keys(this.listeners_).length > 0;
}
/**
@@ -182,5 +181,4 @@ class Target extends Disposable {
}
}
export default Target;
+43 -50
View File
@@ -2,10 +2,9 @@
* @module ol/events/condition
*/
import MapBrowserEventType from '../MapBrowserEventType.js';
import {FALSE, TRUE} from '../functions.js';
import {MAC, WEBKIT} from '../has.js';
import {assert} from '../asserts.js';
import {TRUE, FALSE} from '../functions.js';
import {WEBKIT, MAC} from '../has.js';
/**
* A function that takes an {@link module:ol/MapBrowserEvent} and returns a
@@ -14,7 +13,6 @@ import {WEBKIT, MAC} from '../has.js';
* @typedef {function(this: ?, import("../MapBrowserEvent.js").default): boolean} Condition
*/
/**
* Return `true` if only the alt-key is pressed, `false` otherwise (e.g. when
* additionally the shift-key is pressed).
@@ -23,15 +21,15 @@ import {WEBKIT, MAC} from '../has.js';
* @return {boolean} True if only the alt key is pressed.
* @api
*/
export const altKeyOnly = function(mapBrowserEvent) {
export const altKeyOnly = function (mapBrowserEvent) {
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return (
originalEvent.altKey &&
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
!originalEvent.shiftKey);
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
!originalEvent.shiftKey
);
};
/**
* Return `true` if only the alt-key and shift-key is pressed, `false` otherwise
* (e.g. when additionally the platform-modifier-key is pressed).
@@ -40,15 +38,15 @@ export const altKeyOnly = function(mapBrowserEvent) {
* @return {boolean} True if only the alt and shift keys are pressed.
* @api
*/
export const altShiftKeysOnly = function(mapBrowserEvent) {
export const altShiftKeysOnly = function (mapBrowserEvent) {
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return (
originalEvent.altKey &&
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
originalEvent.shiftKey);
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
originalEvent.shiftKey
);
};
/**
* Return `true` if the map has the focus. This condition requires a map target
* element with a `tabindex` attribute, e.g. `<div id="map" tabindex="1">`.
@@ -57,11 +55,10 @@ export const altShiftKeysOnly = function(mapBrowserEvent) {
* @return {boolean} The map has the focus.
* @api
*/
export const focus = function(event) {
export const focus = function (event) {
return event.target.getTargetElement().contains(document.activeElement);
};
/**
* Return always true.
*
@@ -71,7 +68,6 @@ export const focus = function(event) {
*/
export const always = TRUE;
/**
* Return `true` if the event is a `click` event, `false` otherwise.
*
@@ -79,11 +75,10 @@ export const always = TRUE;
* @return {boolean} True if the event is a map `click` event.
* @api
*/
export const click = function(mapBrowserEvent) {
export const click = function (mapBrowserEvent) {
return mapBrowserEvent.type == MapBrowserEventType.CLICK;
};
/**
* Return `true` if the event has an "action"-producing mouse button.
*
@@ -93,13 +88,11 @@ export const click = function(mapBrowserEvent) {
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Map browser event.
* @return {boolean} The result.
*/
export const mouseActionButton = function(mapBrowserEvent) {
export const mouseActionButton = function (mapBrowserEvent) {
const originalEvent = /** @type {MouseEvent} */ (mapBrowserEvent.originalEvent);
return originalEvent.button == 0 &&
!(WEBKIT && MAC && originalEvent.ctrlKey);
return originalEvent.button == 0 && !(WEBKIT && MAC && originalEvent.ctrlKey);
};
/**
* Return always false.
*
@@ -109,7 +102,6 @@ export const mouseActionButton = function(mapBrowserEvent) {
*/
export const never = FALSE;
/**
* Return `true` if the browser event is a `pointermove` event, `false`
* otherwise.
@@ -118,11 +110,10 @@ export const never = FALSE;
* @return {boolean} True if the browser event is a `pointermove` event.
* @api
*/
export const pointerMove = function(mapBrowserEvent) {
export const pointerMove = function (mapBrowserEvent) {
return mapBrowserEvent.type == 'pointermove';
};
/**
* Return `true` if the event is a map `singleclick` event, `false` otherwise.
*
@@ -130,11 +121,10 @@ export const pointerMove = function(mapBrowserEvent) {
* @return {boolean} True if the event is a map `singleclick` event.
* @api
*/
export const singleClick = function(mapBrowserEvent) {
export const singleClick = function (mapBrowserEvent) {
return mapBrowserEvent.type == MapBrowserEventType.SINGLECLICK;
};
/**
* Return `true` if the event is a map `dblclick` event, `false` otherwise.
*
@@ -142,11 +132,10 @@ export const singleClick = function(mapBrowserEvent) {
* @return {boolean} True if the event is a map `dblclick` event.
* @api
*/
export const doubleClick = function(mapBrowserEvent) {
export const doubleClick = function (mapBrowserEvent) {
return mapBrowserEvent.type == MapBrowserEventType.DBLCLICK;
};
/**
* Return `true` if no modifier key (alt-, shift- or platform-modifier-key) is
* pressed.
@@ -155,15 +144,15 @@ export const doubleClick = function(mapBrowserEvent) {
* @return {boolean} True only if there no modifier keys are pressed.
* @api
*/
export const noModifierKeys = function(mapBrowserEvent) {
export const noModifierKeys = function (mapBrowserEvent) {
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return (
!originalEvent.altKey &&
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
!originalEvent.shiftKey);
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
!originalEvent.shiftKey
);
};
/**
* Return `true` if only the platform-modifier-key (the meta-key on Mac,
* ctrl-key otherwise) is pressed, `false` otherwise (e.g. when additionally
@@ -173,14 +162,15 @@ export const noModifierKeys = function(mapBrowserEvent) {
* @return {boolean} True if only the platform modifier key is pressed.
* @api
*/
export const platformModifierKeyOnly = function(mapBrowserEvent) {
export const platformModifierKeyOnly = function (mapBrowserEvent) {
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return !originalEvent.altKey &&
return (
!originalEvent.altKey &&
(MAC ? originalEvent.metaKey : originalEvent.ctrlKey) &&
!originalEvent.shiftKey;
!originalEvent.shiftKey
);
};
/**
* Return `true` if only the shift-key is pressed, `false` otherwise (e.g. when
* additionally the alt-key is pressed).
@@ -189,15 +179,15 @@ export const platformModifierKeyOnly = function(mapBrowserEvent) {
* @return {boolean} True if only the shift key is pressed.
* @api
*/
export const shiftKeyOnly = function(mapBrowserEvent) {
export const shiftKeyOnly = function (mapBrowserEvent) {
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
return (
!originalEvent.altKey &&
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
originalEvent.shiftKey);
!(originalEvent.metaKey || originalEvent.ctrlKey) &&
originalEvent.shiftKey
);
};
/**
* Return `true` if the target element is not editable, i.e. not a `<input>`-,
* `<select>`- or `<textarea>`-element, `false` otherwise.
@@ -206,13 +196,12 @@ export const shiftKeyOnly = function(mapBrowserEvent) {
* @return {boolean} True only if the target element is not editable.
* @api
*/
export const targetNotEditable = function(mapBrowserEvent) {
export const targetNotEditable = function (mapBrowserEvent) {
const originalEvent = /** @type {KeyboardEvent|MouseEvent|TouchEvent} */ (mapBrowserEvent.originalEvent);
const tagName = /** @type {Element} */ (originalEvent.target).tagName;
return tagName !== 'INPUT' && tagName !== 'SELECT' && tagName !== 'TEXTAREA';
};
/**
* Return `true` if the event originates from a mouse device.
*
@@ -220,8 +209,9 @@ export const targetNotEditable = function(mapBrowserEvent) {
* @return {boolean} True if the event originates from a mouse device.
* @api
*/
export const mouseOnly = function(mapBrowserEvent) {
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
export const mouseOnly = function (mapBrowserEvent) {
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
.pointerEvent;
assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
return pointerEvent.pointerType == 'mouse';
@@ -234,8 +224,9 @@ export const mouseOnly = function(mapBrowserEvent) {
* @return {boolean} True if the event originates from a touchable device.
* @api
*/
export const touchOnly = function(mapBrowserEvent) {
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
export const touchOnly = function (mapBrowserEvent) {
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
.pointerEvent;
assert(pointerEvt !== undefined, 56); // mapBrowserEvent must originate from a pointer event
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
return pointerEvt.pointerType === 'touch';
@@ -248,8 +239,9 @@ export const touchOnly = function(mapBrowserEvent) {
* @return {boolean} True if the event originates from a digital pen.
* @api
*/
export const penOnly = function(mapBrowserEvent) {
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
export const penOnly = function (mapBrowserEvent) {
const pointerEvt = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
.pointerEvent;
assert(pointerEvt !== undefined, 56); // mapBrowserEvent must originate from a pointer event
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
return pointerEvt.pointerType === 'pen';
@@ -264,8 +256,9 @@ export const penOnly = function(mapBrowserEvent) {
* @return {boolean} True if the event originates from a primary pointer.
* @api
*/
export const primaryAction = function(mapBrowserEvent) {
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
export const primaryAction = function (mapBrowserEvent) {
const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent)
.pointerEvent;
assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
return pointerEvent.isPrimary && pointerEvent.button === 0;
};